001 002/* 003 * BioJava development code 004 * 005 * This code may be freely distributed and modified under the 006 * terms of the GNU Lesser General Public Licence. This should 007 * be distributed with the code. If you do not have a copy, 008 * see: 009 * 010 * http://www.gnu.org/copyleft/lesser.html 011 * 012 * Copyright for this code is held jointly by the individual 013 * authors. These should be listed in @author doc comments. 014 * 015 * For more information on the BioJava project and its aims, 016 * or to join the biojava-l mailing list, visit the home page 017 * at: 018 * 019 * http://www.biojava.org/ 020 * 021 * Created on Feb 9, 2007 022 * 023 */ 024package org.biojava.nbio.structure.gui.util; 025 026import org.biojava.nbio.structure.Chain; 027import org.biojava.nbio.structure.PdbId; 028import org.biojava.nbio.structure.Structure; 029import org.biojava.nbio.structure.StructureException; 030import org.biojava.nbio.structure.StructureImpl; 031import org.biojava.nbio.structure.io.PDBFileReader; 032import org.slf4j.Logger; 033import org.slf4j.LoggerFactory; 034 035import javax.swing.*; 036import java.awt.*; 037import java.io.IOException; 038 039/** A class to define where a structure for the alignment is coming from 040 * 041 * @author Andreas Prlic 042 * @since 1.7 043 * @version %I% %G% 044 */ 045public class PDBServerPanel 046extends JPanel 047implements StructurePairSelector{ 048 049 /** 050 * 051 */ 052 private static final long serialVersionUID = -5682120627824627408L; 053 054 boolean debug = true; 055 JTextField pdbDir; 056 JTextField f1; 057 JTextField f2; 058 JTextField c1; 059 JTextField c2; 060 061 062 private static final Logger logger = LoggerFactory.getLogger(PDBServerPanel.class); 063 064 /** load the PDB files from a local directory 065 * 066 */ 067 public PDBServerPanel() { 068 069 Box vBox = Box.createVerticalBox(); 070 071 int pdbfSize = 4; 072 073 f1 = new JTextField(pdbfSize); 074 c1 = new JTextField(1); 075 JPanel p1 = getPDBFilePanel(1,f1,c1); 076 vBox.add(p1); 077 078 f2 = new JTextField(pdbfSize); 079 c2 = new JTextField(1); 080 JPanel p2 = getPDBFilePanel(2, f2,c2); 081 vBox.add(p2); 082 083 084 this.add(vBox); 085 086 } 087 088 089 private Structure fromPDB(JTextField f, JTextField c) throws StructureException{ 090 String pdbIdString = f.getText(); 091 092 093 if ( pdbIdString.length() < 4) { 094 f.setText("!!!"); 095 return null; 096 } 097 098 String chain = c.getText(); 099 if ( debug ) 100 System.out.println("file :" + pdbIdString + " " + chain); 101 /// prepare structures 102 103 // load them from the file system 104 105 PDBFileReader reader = new PDBFileReader(); 106 107 reader.setPath("."); 108 109 Structure tmp1 = new StructureImpl(); 110 111 try { 112 Structure structure1 = reader.getStructureById(new PdbId(pdbIdString)); 113 114 // no chain has been specified 115 // return whole structure 116 if (( chain == null) || (chain.length()==0)){ 117 return structure1; 118 } 119 if ( debug) 120 System.out.println("using chain " + chain + " for structure " + structure1.getPdbId().getId()); 121 Chain c1 = structure1.getPolyChainByPDB(chain); 122 tmp1.setPDBHeader(structure1.getPDBHeader()); 123 tmp1.setPdbId(structure1.getPdbId()); 124 tmp1.addChain(c1); 125 System.out.println("ok"); 126 127 } catch (IOException e){ 128 logger.warn(e.getMessage()); 129 throw new StructureException(e); 130 } 131 return tmp1; 132 } 133 134 135 136 @Override 137 public Structure getStructure1() throws StructureException{ 138 return fromPDB(f1,c1); 139 } 140 141 @Override 142 public Structure getStructure2() throws StructureException{ 143 return fromPDB(f2,c2); 144 } 145 146 147// private JPanel getPDBDirPanel(JTextField f){ 148// JPanel panel = new JPanel(); 149// panel.setBorder(BorderFactory.createLineBorder(Color.black)); 150// 151// 152// JLabel l01 = new JLabel("Select PDB directory"); 153// panel.add(l01); 154// 155// panel.add(f); 156// 157// Action action = new ChooseDirAction(pdbDir); 158// 159// JButton chooser = new JButton(action); 160// panel.add(chooser); 161// return panel; 162// } 163 164 private JPanel getPDBFilePanel(int pos ,JTextField f, JTextField c){ 165 166 JPanel panel = new JPanel(); 167 panel.setBorder(BorderFactory.createLineBorder(Color.black)); 168 169 170 171 JLabel l01 = new JLabel("PDB code "); 172 173 panel.add(l01); 174 Box hBox11 = Box.createHorizontalBox(); 175 176 JLabel l11 = new JLabel(pos + ":"); 177 178 179 180 f.setMaximumSize(new Dimension(Short.MAX_VALUE,30)); 181 182 183 hBox11.add(l11); 184 hBox11.add(Box.createVerticalGlue()); 185 hBox11.add(f, BorderLayout.CENTER); 186 hBox11.add(Box.createVerticalGlue()); 187 188 panel.add(hBox11); 189 190 Box hBox21 = Box.createHorizontalBox(); 191 JLabel l21 = new JLabel("Chain" + pos + ":"); 192 193 c.setMaximumSize(new Dimension(Short.MAX_VALUE,30)); 194 hBox21.add(l21); 195 hBox21.add(Box.createGlue()); 196 hBox21.add(c, BorderLayout.CENTER); 197 hBox21.add(Box.createGlue()); 198 199 panel.add(hBox21); 200 201 return panel; 202 } 203 204} 205 206