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