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 Jun 30, 2010 021 * Author: ap3 022 * 023 */ 024 025package org.biojava.nbio.structure.gui.util; 026 027import org.biojava.nbio.structure.Structure; 028import org.biojava.nbio.structure.StructureException; 029import org.biojava.nbio.structure.align.gui.autosuggest.AutoSuggestProvider; 030import org.biojava.nbio.structure.align.gui.autosuggest.JAutoSuggest; 031import org.biojava.nbio.structure.align.gui.autosuggest.SCOPAutoSuggestProvider; 032import org.biojava.nbio.structure.align.util.AtomCache; 033import org.biojava.nbio.structure.align.util.UserConfiguration; 034import org.biojava.nbio.structure.align.webstart.WebStartMain; 035 036import javax.swing.*; 037import java.awt.*; 038//import org.slf4j.Logger; 039//import org.slf4j.LoggerFactory; 040 041public class ScopSelectPanel 042extends JPanel 043implements StructurePairSelector 044{ 045 046 /** 047 * 048 */ 049 private static final long serialVersionUID = 757947454156959178L; 050 JAutoSuggest dom1; 051 JAutoSuggest dom2; 052 053 //private static final Logger logger = LoggerFactory.getLogger(ScopSelectPanel.class); 054 055 public ScopSelectPanel(){ 056 057 this(true); 058 } 059 060 public ScopSelectPanel(boolean show2boxes){ 061 Box vBox = Box.createVerticalBox(); 062 063 //dom1 = new JTextField(10); 064 //dom2 = new JTextField(10); 065 066 AutoSuggestProvider autoSuggesP = new SCOPAutoSuggestProvider(); 067 068 dom1 = new JAutoSuggest(10); 069 dom1.setAutoSuggestProvider(autoSuggesP); 070 071 dom2 = new JAutoSuggest(10); 072 dom2.setAutoSuggestProvider(autoSuggesP); 073 074 Box b1 = getDomainPanel(1,dom1); 075 Box b2 = getDomainPanel(2,dom2); 076 077 078 vBox.add(b1); 079 if ( show2boxes) 080 vBox.add(b2); 081 082 this.add(vBox); 083 } 084 085 private Box getDomainPanel(int pos ,JTextField f){ 086 087 //JPanel panel = new JPanel(); 088 //panel.setBorder(BorderFactory.createLineBorder(Color.black)); 089 090 JLabel l01 = new JLabel("SCOP or domain id:"); 091 092 //panel.add(l01); 093 Box hBox = Box.createHorizontalBox(); 094 hBox.add(Box.createGlue()); 095 hBox.add(l01); 096 097 JLabel l11 = new JLabel(pos + ":"); 098 f.setMaximumSize(new Dimension(Short.MAX_VALUE,30)); 099 f.setToolTipText("Provide SCOP ID here. Example: d1zyma1"); 100 hBox.add(l11); 101 hBox.add(Box.createVerticalGlue()); 102 hBox.add(f, BorderLayout.CENTER); 103 hBox.add(Box.createGlue()); 104 105 106 //hBox21.add(Box.createGlue()); 107 108 //panel.add(hBox21); 109 110 111 112 return hBox; 113 } 114 115 @Override 116 public Structure getStructure1() throws StructureException 117 { 118 String scop1 = dom1.getText(); 119 return getStructure(scop1); 120 } 121 122 @Override 123 public Structure getStructure2() throws StructureException 124 { 125 return getStructure(dom2.getText()); 126 } 127 128 private Structure getStructure(String domainID) throws StructureException{ 129 //PDBFileReader reader = new PDBFileReader(); 130 131 if ( domainID == null || domainID.equals("")) 132 return null; 133 134 135 136 UserConfiguration config = WebStartMain.getWebStartConfig(); 137 //String cacheLocation = config.getPdbFilePath(); 138 139 AtomCache cache = new AtomCache(config); 140 141 Structure s = null; 142 try { 143 s = cache.getStructure(domainID); 144 s.setName(domainID); 145 } catch (Exception e){ 146 e.printStackTrace(); 147 } 148 return s; 149 150// AtomCache cache = new AtomCache(cacheLocation ); 151// 152// ScopDatabase scop = ScopInstallationInstance.getInstance().getSCOP(); 153// 154// ScopDomain domain = scop.getDomainByScopID(domainID) ; 155// 156// System.out.println("found scop domain :" + domain); 157// 158// if ( domain == null) 159// return null; 160// 161// 162// Structure s = null; 163// try { 164// s =cache.getStructureForDomain(domain); 165// if ( s.getName() == null || s.getName().equals("")) 166// s.setName(domainID); 167// s.setPDBCode(domainID); 168// } catch (Exception e){ 169// e.printStackTrace(); 170// logger.warning(e.getMessage()); 171// } 172// 173// return s; 174 175 } 176 177}