X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fjbgui%2FGStructureChooser.java;fp=src%2Fjalview%2Fjbgui%2FGStructureChooser.java;h=69b1fe69d23160ec54b833570049a3b32b21cf8a;hb=7d76e402efd4e04e179bc9bb264551bc2d3df936;hp=0000000000000000000000000000000000000000;hpb=f09bee67bc24f1e401b4834f8ecb14812620568c;p=jalview.git diff --git a/src/jalview/jbgui/GStructureChooser.java b/src/jalview/jbgui/GStructureChooser.java new file mode 100644 index 0000000..69b1fe6 --- /dev/null +++ b/src/jalview/jbgui/GStructureChooser.java @@ -0,0 +1,172 @@ +package jalview.jbgui; + +import jalview.gui.AlignmentPanel; +import jalview.gui.Desktop; +import jalview.util.MessageManager; + +import java.awt.BorderLayout; +import java.awt.CardLayout; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; + +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JFrame; +import javax.swing.JInternalFrame; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextField; +import javax.swing.ListSelectionModel; + +@SuppressWarnings("serial") +public abstract class GStructureChooser extends JPanel implements + ItemListener +{ + protected String frameTitle = "Structure Chooser"; + + protected JInternalFrame mainFrame = new JInternalFrame(frameTitle); + + + + protected JComboBox filterOptions = new JComboBox(); + + protected AlignmentPanel ap; + + protected JLabel resultLabel = new JLabel("View : "); + + protected JButton ok = new JButton(); + + protected JButton cancel = new JButton(); + + protected JButton selectFile = new JButton(); + + protected JTextField search = new JTextField(16); + + protected JPanel actionPanel = new JPanel(); + + protected JPanel filterPanel = new JPanel(); + + protected JPanel idInputPanel = new JPanel(); + + protected JPanel fileChooserPanel = new JPanel(); + + protected JPanel switchableViewsPanel = new JPanel(new CardLayout()); + + protected CardLayout switchableViewsLayout = (CardLayout) (switchableViewsPanel + .getLayout()); + + protected BorderLayout mainLayout = new BorderLayout(); + + protected BorderLayout idInputPanelLayout = new BorderLayout(); + + protected BorderLayout fileChooserPanelLayout = new BorderLayout(); + + protected JCheckBox rememberSettings = new JCheckBox("Don't ask me again"); + + + protected static final String VIEWS_AUTO = "auto_view"; + + protected static final String VIEWS_FILE = "file_view"; + + protected static final String VIEWS_ID = "id_view"; + + protected JList jListFoundStructures = new JList(); + + protected JScrollPane foundStructuresScroller = new JScrollPane( + jListFoundStructures); + + public GStructureChooser() + { + try + { + jbInit(); + mainFrame.invalidate(); + mainFrame.pack(); + } catch (Exception e) + { + e.printStackTrace(); + } + } + + private void jbInit() throws Exception + { + + ok.setFont(new java.awt.Font("Verdana", 0, 12)); + ok.setText(MessageManager.getString("action.ok")); + ok.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + ok_ActionPerformed(); + } + }); + cancel.setFont(new java.awt.Font("Verdana", 0, 12)); + cancel.setText(MessageManager.getString("action.cancel")); + cancel.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + mainFrame.dispose(); + } + }); + + jListFoundStructures + .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + jListFoundStructures.setLayoutOrientation(JList.VERTICAL); + jListFoundStructures.setVisibleRowCount(-1); + foundStructuresScroller.setPreferredSize(new Dimension(500, 300)); + foundStructuresScroller + .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + + actionPanel.add(rememberSettings); + actionPanel.add(ok); + actionPanel.add(cancel); + + filterOptions.addItemListener(this); + + filterPanel.add(resultLabel); + filterPanel.add(filterOptions); + + idInputPanel.setLayout(new FlowLayout()); + idInputPanel.add(search); + + + selectFile.setText(" Select File "); + fileChooserPanel.setLayout(new FlowLayout()); + fileChooserPanel.add(selectFile); + + switchableViewsPanel.add(fileChooserPanel, VIEWS_FILE); + switchableViewsPanel.add(idInputPanel, VIEWS_ID); + switchableViewsPanel.add(foundStructuresScroller, VIEWS_AUTO); + + + this.setLayout(mainLayout); + this.add(filterPanel, java.awt.BorderLayout.NORTH); + this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER); + this.add(actionPanel, java.awt.BorderLayout.SOUTH); + populateFilterOptions(); + updateCurrentView(); + mainFrame.setVisible(true); + mainFrame.setContentPane(this); + mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + Desktop.addInternalFrame(mainFrame, frameTitle, 800, 400); + } + + @Override + public void itemStateChanged(ItemEvent e) + { + updateCurrentView(); + } + + protected abstract void updateCurrentView(); + + protected abstract void ok_ActionPerformed(); + + protected abstract void populateFilterOptions(); +}