3 import jalview.gui.AlignmentPanel;
4 import jalview.gui.Desktop;
5 import jalview.util.MessageManager;
6 import jalview.ws.uimodel.PDBSearchResponse.PDBResponseSummary;
8 import java.awt.BorderLayout;
9 import java.awt.CardLayout;
10 import java.awt.Dimension;
11 import java.awt.FlowLayout;
12 import java.awt.Image;
13 import java.awt.event.ActionEvent;
14 import java.awt.event.ItemEvent;
15 import java.awt.event.ItemListener;
17 import javax.swing.ImageIcon;
18 import javax.swing.JButton;
19 import javax.swing.JCheckBox;
20 import javax.swing.JComboBox;
21 import javax.swing.JFrame;
22 import javax.swing.JInternalFrame;
23 import javax.swing.JLabel;
24 import javax.swing.JList;
25 import javax.swing.JPanel;
26 import javax.swing.JScrollPane;
27 import javax.swing.JTable;
28 import javax.swing.JTextField;
29 import javax.swing.ListSelectionModel;
31 @SuppressWarnings("serial")
32 public abstract class GStructureChooser extends JPanel implements
35 protected String frameTitle = "Structure Chooser";
37 protected JInternalFrame mainFrame = new JInternalFrame(frameTitle);
41 protected JComboBox<FilterOptions> filterOptionsComboBox = new JComboBox<FilterOptions>();
43 protected AlignmentPanel ap;
45 protected JLabel resultLabel = new JLabel("Select : ");
47 protected JButton ok = new JButton();
49 protected JButton cancel = new JButton();
51 protected JButton pdbFromFile = new JButton();
53 protected JTextField search = new JTextField(16);
55 protected JPanel actionPanel = new JPanel();
57 protected JPanel filterPanel = new JPanel();
59 protected JPanel idInputPanel = new JPanel();
61 protected JPanel fileChooserPanel = new JPanel();
63 protected JPanel switchableViewsPanel = new JPanel(new CardLayout());
65 protected CardLayout switchableViewsLayout = (CardLayout) (switchableViewsPanel
68 protected BorderLayout mainLayout = new BorderLayout();
70 protected BorderLayout idInputPanelLayout = new BorderLayout();
72 protected BorderLayout fileChooserPanelLayout = new BorderLayout();
74 protected JCheckBox rememberSettings = new JCheckBox("Don't ask me again");
76 protected JCheckBox invertFilter = new JCheckBox("Invert");
78 protected ImageIcon loadingImage = new ImageIcon(getClass().getResource(
79 "/images/loading.gif"));
81 protected JLabel loadingImageLabel = new JLabel(loadingImage);
83 protected static final String VIEWS_FILTER = "VIEWS_FILTER";
85 protected static final String VIEWS_FROM_FILE = "VIEWS_FROM_FILE";
87 protected static final String VIEWS_ENTER_ID = "VIEWS_ENTER_ID";
89 protected JList<PDBResponseSummary> jListFoundStructures = new JList<PDBResponseSummary>();
91 // protected JScrollPane foundStructuresScroller = new JScrollPane(
92 // jListFoundStructures);
94 protected JTable summaryTable = new JTable();
95 protected JScrollPane foundStructuresScroller = new JScrollPane(
98 public GStructureChooser()
103 mainFrame.setVisible(false);
104 mainFrame.invalidate();
106 } catch (Exception e)
112 private void jbInit() throws Exception
114 ok.setFont(new java.awt.Font("Verdana", 0, 12));
115 ok.setText(MessageManager.getString("action.view"));
116 ok.addActionListener(new java.awt.event.ActionListener()
118 public void actionPerformed(ActionEvent e)
120 ok_ActionPerformed();
123 cancel.setFont(new java.awt.Font("Verdana", 0, 12));
124 cancel.setText(MessageManager.getString("action.cancel"));
125 cancel.addActionListener(new java.awt.event.ActionListener()
127 public void actionPerformed(ActionEvent e)
133 pdbFromFile.setFont(new java.awt.Font("Verdana", 0, 12));
134 pdbFromFile.setText(" Select PDB File ");
135 pdbFromFile.addActionListener(new java.awt.event.ActionListener()
137 public void actionPerformed(ActionEvent e)
139 pdbFromFile_actionPerformed();
144 .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
145 jListFoundStructures.setLayoutOrientation(JList.VERTICAL);
146 jListFoundStructures.setVisibleRowCount(-1);
147 foundStructuresScroller.setPreferredSize(new Dimension(500, 300));
148 foundStructuresScroller
149 .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
151 filterOptionsComboBox.setFont(new java.awt.Font("Verdana", 0, 12));
152 invertFilter.setFont(new java.awt.Font("Verdana", 0, 12));
153 rememberSettings.setFont(new java.awt.Font("Verdana", 0, 12));
155 filterOptionsComboBox.addItemListener(this);
156 invertFilter.addItemListener(this);
158 actionPanel.add(rememberSettings);
160 actionPanel.add(cancel);
163 filterPanel.add(resultLabel);
164 filterPanel.add(filterOptionsComboBox);
165 loadingImageLabel.setVisible(false);
167 filterPanel.add(loadingImageLabel);
169 filterPanel.add(invertFilter);
171 idInputPanel.setLayout(new FlowLayout());
172 idInputPanel.add(search);
175 fileChooserPanel.setLayout(new FlowLayout());
176 fileChooserPanel.add(pdbFromFile);
178 switchableViewsPanel.add(fileChooserPanel, VIEWS_FROM_FILE);
179 switchableViewsPanel.add(idInputPanel, VIEWS_ENTER_ID);
180 switchableViewsPanel.add(foundStructuresScroller, VIEWS_FILTER);
183 this.setLayout(mainLayout);
184 this.add(filterPanel, java.awt.BorderLayout.NORTH);
185 this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
186 this.add(actionPanel, java.awt.BorderLayout.SOUTH);
188 mainFrame.setVisible(true);
189 mainFrame.setContentPane(this);
190 mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
191 Desktop.addInternalFrame(mainFrame, frameTitle, 800, 400);
195 private ImageIcon scaleImageIcone(ImageIcon imageIcon, int width, int height)
197 Image image = imageIcon.getImage(); // transform it
199 Image newimg = image.getScaledInstance(width, height,
200 java.awt.Image.SCALE_SMOOTH); // scale it the smooth way
202 return new ImageIcon(newimg);
206 public void itemStateChanged(ItemEvent e)
211 public class FilterOptions
215 private String value;
219 public FilterOptions(String name, String value, String view)
226 // public FilterOptions(PDBDocField field, String view)
228 // this.name = "Best " + field.getName();
229 // this.value = field.getCode();
233 public String getName()
238 public void setName(String name)
243 public String getValue()
248 public void setValue(String value)
253 public String getView()
258 public void setView(String view)
263 public String toString()
269 protected abstract void stateChanged(ItemEvent e);
271 protected abstract void updateCurrentView();
273 protected abstract void ok_ActionPerformed();
275 protected abstract void populateFilterOptions();
277 protected abstract void pdbFromFile_actionPerformed();