001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 * Created on Nov 3, 2009
021 * Author: Andreas Prlic
022 *
023 */
024
025package org.biojava.nbio.structure.align.gui;
026
027
028import org.biojava.nbio.structure.align.StructureAlignment;
029import org.biojava.nbio.structure.align.util.ResourceManager;
030import org.biojava.nbio.structure.gui.util.PDBUploadPanel;
031import org.biojava.nbio.structure.gui.util.ScopSelectPanel;
032
033import javax.swing.*;
034import java.awt.event.ActionEvent;
035import java.awt.event.ActionListener;
036import java.io.File;
037
038public class DBSearchGUI extends JPanel {
039
040        /**
041         *
042         */
043        private static final long serialVersionUID = -5657960663049062301L;
044
045
046        StructureAlignment algorithm;
047        SelectPDBPanel tab1;
048        JTabbedPane tabPane;
049
050        PDBUploadPanel tab2;
051        ScopSelectPanel tab3;
052
053        JPanel listPane;
054        JButton abortB;
055        AlignmentCalcDB alicalc;
056        JProgressBar progress;
057        ProgressThreadDrawer drawer;
058        JTextField outFileLocation;
059
060        Boolean useDomainSplit = true;
061        static final ResourceManager resourceManager = ResourceManager.getResourceManager("ce");
062
063
064        public DBSearchGUI(){
065
066
067                tab1 = new SelectPDBPanel(false);
068
069                tab2 = new PDBUploadPanel(false);
070                tab3 = new ScopSelectPanel(false);
071
072                tabPane = new JTabbedPane();
073                tabPane.addTab("Select PDB ID", null, tab1,"Select PDB ID to align");
074
075                tabPane.addTab("Domains",null, tab3,"Domains");
076
077                tabPane.addTab("Custom files",null, tab2,"Align your own files.");
078
079                listPane = createListPane();
080
081                // build up UO
082
083                Box vBox = Box.createVerticalBox();
084
085                vBox.add(tabPane);
086
087                vBox.add(listPane);
088
089                //domainSelectPane = createDomainSelectPane();
090
091                //vBox.add(domainSelectPane);
092
093                //vBox.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
094                vBox.add(Box.createGlue());
095
096                this.add(vBox);
097
098                this.setVisible(true);
099
100        }
101
102        public boolean isDomainSplit(){
103                return useDomainSplit;
104        }
105
106        public JTabbedPane getTabPane()
107        {
108                return tabPane;
109        }
110
111        public void setTabPane(JTabbedPane tabPane)
112        {
113                this.tabPane = tabPane;
114        }
115
116        public ScopSelectPanel getScopSelectPanel(){
117                return tab3;
118        }
119
120
121        public SelectPDBPanel getSelectPDBPanel(){
122                return tab1;
123        }
124        public PDBUploadPanel getPDBUploadPanel(){
125                return tab2;
126        }
127        public String getOutFileLocation(){
128                return outFileLocation.getText();
129        }
130
131
132        private JPanel createListPane() {
133                //JTabbedPane tabP = new JTabbedPane();
134
135
136                JLabel lable = new JLabel("Select Output Directory");
137                JPanel dir = new JPanel();
138
139
140                outFileLocation = new JTextField(20);
141                JButton chB = new JButton("Select");
142
143                Box fileSelectBox = Box.createHorizontalBox();
144                fileSelectBox.add(lable);
145                fileSelectBox.add(outFileLocation);
146                fileSelectBox.add(chB);
147                fileSelectBox.add(Box.createGlue());
148
149
150                Box hBox = Box.createVerticalBox();
151                hBox.add(fileSelectBox);
152
153                Box panel =createDomainSelectPane();
154                hBox.add(panel);
155
156                dir.add(hBox);
157
158                chB.addActionListener(new ActionListener() {
159
160                        @Override
161                        public void actionPerformed(ActionEvent e) {
162                                JFileChooser chooser = new JFileChooser();
163                                chooser.setMultiSelectionEnabled(false);
164                                chooser.setDialogTitle("Select Output Directory");
165                                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
166                                //
167                                // disable the "All files" option.
168                                //
169                                chooser.setAcceptAllFileFilterUsed(false);
170                                //
171
172
173                                //                              In response to a button click:
174                                int returnVal = chooser.showSaveDialog(null);
175                                if ( returnVal == JFileChooser.APPROVE_OPTION) {
176                                        File file = chooser.getSelectedFile();
177                                        outFileLocation.setText(file.getPath());
178                                        outFileLocation.repaint();
179                                }
180
181                        }
182                });
183
184                //tabP.addTab("Select Output Directory", null, dir,
185                //              "Configure the folder that will contain the results.");
186
187
188                return dir;
189        }
190
191
192        private Box createDomainSelectPane() {
193
194
195
196
197                useDomainSplit  = true;
198
199                String[] petStrings = { "Split proteins in Domains", "Use whole chains" };
200
201                //Create the combo box, select item at index 4.
202                //Indices start at 0, so 4 specifies the pig.
203                JComboBox domainList = new JComboBox(petStrings);
204                domainList.setSelectedIndex(0);
205                domainList.setToolTipText("Either align whole chains or SCOP domains and domains assigned with PDP, where no SCOP available.");
206                domainList.addActionListener(new ActionListener() {
207
208                        @Override
209                        public void actionPerformed(ActionEvent arg0) {
210                                JComboBox box = (JComboBox)arg0.getSource();
211                                int index = box.getSelectedIndex();
212                                if ( index == 0)
213                                        useDomainSplit = true;
214                                else
215                                        useDomainSplit = false;
216
217                        }
218                });
219
220                JLabel label= new JLabel("Domains:");
221
222                Box domainBox = Box.createHorizontalBox();
223                domainBox.add(label);
224
225                domainBox.add(domainList);
226                domainBox.add(Box.createGlue());
227                //Box hBox = Box.createHorizontalBox();
228
229                //hBox.add(Box.createGlue());
230
231
232
233                return domainBox;
234        }
235
236
237
238        public void notifyCalcFinished(){
239                if ( drawer != null)
240                        drawer.interrupt();
241                abortB.setEnabled(false);
242                progress.setIndeterminate(false);
243
244        }
245
246
247
248        public StructureAlignment getStructureAlignment() {
249
250                return algorithm;
251        }
252}
253