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 */
021package org.biojava.nbio.structure.align.gui;
022
023import java.awt.BorderLayout;
024import java.awt.Dimension;
025import java.io.IOException;
026
027import javax.swing.Box;
028import javax.swing.JLabel;
029import javax.swing.JPanel;
030import javax.swing.JTabbedPane;
031import javax.swing.JTextField;
032
033import org.biojava.nbio.structure.ResidueRange;
034import org.biojava.nbio.structure.Structure;
035import org.biojava.nbio.structure.StructureException;
036import org.biojava.nbio.structure.StructureIdentifier;
037import org.biojava.nbio.structure.SubstructureIdentifier;
038import org.biojava.nbio.structure.align.util.AtomCache;
039import org.biojava.nbio.structure.align.util.UserConfiguration;
040import org.biojava.nbio.structure.align.webstart.WebStartMain;
041import org.biojava.nbio.structure.gui.util.StructurePairSelector;
042
043
044/** A Panel that allows user to specify PDB & chain ID, as well as sub-ranges
045 *
046 * @author Andreas
047 *
048 */
049public class SelectPDBPanel
050extends JPanel
051implements StructurePairSelector{
052
053        boolean debug = true;
054
055        JTextField f1;
056        JTextField f2;
057        JTextField c1;
058        JTextField c2;
059        JTextField r1;
060        JTextField r2;
061
062        UserConfiguration config;
063        JTabbedPane configPane;
064
065        /**
066         *
067         */
068        private static final long serialVersionUID = 4002475313717172193L;
069
070
071
072        public SelectPDBPanel(){
073                this(true);
074        }
075        public SelectPDBPanel(boolean show2PDBs) {
076
077                Box vBox = Box.createVerticalBox();
078
079                JLabel help = new JLabel("Optional: specify chain ID or range.");
080                Box hBox1 = Box.createHorizontalBox();
081                hBox1.add(Box.createGlue());
082                hBox1.add(help);
083                vBox.add(hBox1);
084
085
086                //pdbDir = new JTextField(20);
087
088                int pdbfSize = 4;
089
090                f1 = new JTextField(pdbfSize);
091                c1 = new JTextField(1);
092                r1 = new JTextField(5);
093                Box p1 = getPDBFilePanel(1,f1,c1,r1);
094                vBox.add(p1);
095
096                f2 = new JTextField(pdbfSize);
097                c2 = new JTextField(1);
098                r2 = new JTextField(5);
099                Box p2 = getPDBFilePanel(2, f2,c2,r2);
100
101                if ( show2PDBs)
102                        vBox.add(p2);
103
104                //vBox.setBorder(BorderFactory.createLineBorder(Color.black));
105                this.add(vBox);
106        }
107
108        public StructureIdentifier getName1() {
109                String pdbId = f1.getText().trim();
110                String chainId = c1.getText().trim();
111                String range = r1.getText().trim();
112
113                // Prefer range over chain
114                if( ! range.isEmpty() ) {
115                        return new SubstructureIdentifier(pdbId, ResidueRange.parseMultiple(range));
116                } else if ( ! chainId.isEmpty() ){
117                        return new SubstructureIdentifier(pdbId, ResidueRange.parseMultiple(chainId));
118                }
119                return new SubstructureIdentifier(pdbId);
120        }
121        public StructureIdentifier getName2() {
122                String pdbId = f2.getText().trim();
123                String chainId = c2.getText().trim();
124                String range = r2.getText().trim();
125
126                // Prefer range over chain
127                if( ! range.isEmpty() ) {
128                        return new SubstructureIdentifier(pdbId, ResidueRange.parseMultiple(range));
129                } else if ( ! chainId.isEmpty() ){
130                        return new SubstructureIdentifier(pdbId, ResidueRange.parseMultiple(chainId));
131                }
132                return new SubstructureIdentifier(pdbId);
133        }
134        @Override
135        public Structure getStructure1() throws StructureException, IOException{
136                return getStructure(getName1());
137        }
138
139        @Override
140        public Structure getStructure2() throws StructureException, IOException{
141                return getStructure(getName2());
142        }
143
144        private Structure getStructure(StructureIdentifier name) throws IOException, StructureException {
145                UserConfiguration config = WebStartMain.getWebStartConfig();
146                AtomCache cache = new AtomCache(config);
147                return cache.getStructure(name);
148        }
149
150        private Box getPDBFilePanel(int pos ,JTextField f, JTextField c, JTextField r){
151
152                //JPanel panel = new JPanel();
153                //panel.setBorder(BorderFactory.createLineBorder(Color.black));
154
155                JLabel l01 = new JLabel("PDB code ");
156
157                //panel.add(l01);
158                Box hBox = Box.createHorizontalBox();
159                hBox.add(Box.createGlue());
160                hBox.add(l01);
161
162                JLabel l11 = new JLabel(pos + ":");
163                f.setMaximumSize(new Dimension(Short.MAX_VALUE,30));
164                f.setToolTipText("Provide 4-character PDB code here. Example: 4hhb");
165                hBox.add(l11);
166                hBox.add(Box.createVerticalGlue());
167                hBox.add(f, BorderLayout.CENTER);
168                hBox.add(Box.createGlue());
169
170                //panel.add(hBox11);
171
172                //Box hBox21 = Box.createHorizontalBox();
173                JLabel l21 = new JLabel("Chain" + pos + ":");
174                hBox.add(l21);
175
176                c.setMaximumSize(new Dimension(Short.MAX_VALUE,30));
177                //hBox.add(Box.createGlue());
178                hBox.add(c, BorderLayout.CENTER);
179
180                String msg1 = "Both chainID and range specification are optional. If both are provided, range has preference.";
181                l21.setToolTipText(msg1);
182                c.setToolTipText(msg1);
183
184                JLabel rangeL = new JLabel(" Range " + pos + ":");
185                hBox.add(Box.createGlue());
186                hBox.add(rangeL);
187                r.setMaximumSize(new Dimension(Short.MAX_VALUE,30));
188
189                // set help text:
190                String msg ="Syntax example: A:407-495,A:582-686";
191                rangeL.setToolTipText(msg);
192                r.setToolTipText(msg);
193
194                //hBox.add(Box.createGlue());
195                hBox.add(r,BorderLayout.CENTER);
196
197                //hBox21.add(Box.createGlue());
198
199                //panel.add(hBox21);
200
201
202
203                return hBox;
204        }
205
206
207
208
209
210}