JAL-1668 First version JAL-1668
[jalview.git] / src / jalview / jbgui / GStructureChooser.java
1 package jalview.jbgui;
2
3 import jalview.gui.AlignmentPanel;
4 import jalview.gui.Desktop;
5 import jalview.util.MessageManager;
6
7 import java.awt.BorderLayout;
8 import java.awt.CardLayout;
9 import java.awt.Dimension;
10 import java.awt.FlowLayout;
11 import java.awt.event.ActionEvent;
12 import java.awt.event.ItemEvent;
13 import java.awt.event.ItemListener;
14
15 import javax.swing.JButton;
16 import javax.swing.JCheckBox;
17 import javax.swing.JComboBox;
18 import javax.swing.JFrame;
19 import javax.swing.JInternalFrame;
20 import javax.swing.JLabel;
21 import javax.swing.JList;
22 import javax.swing.JPanel;
23 import javax.swing.JScrollPane;
24 import javax.swing.JTextField;
25 import javax.swing.ListSelectionModel;
26
27 @SuppressWarnings("serial")
28 public abstract class GStructureChooser extends JPanel implements
29         ItemListener
30 {
31   protected String frameTitle = "Structure Chooser";
32
33   protected JInternalFrame mainFrame = new JInternalFrame(frameTitle);
34
35
36
37   protected JComboBox filterOptions = new JComboBox();
38
39   protected AlignmentPanel ap;
40
41   protected JLabel resultLabel = new JLabel("View : ");
42
43   protected JButton ok = new JButton();
44
45   protected JButton cancel = new JButton();
46
47   protected JButton selectFile = new JButton();
48
49   protected JTextField search = new JTextField(16);
50
51   protected JPanel actionPanel = new JPanel();
52
53   protected JPanel filterPanel = new JPanel();
54
55   protected JPanel idInputPanel = new JPanel();
56
57   protected JPanel fileChooserPanel = new JPanel();
58
59   protected JPanel switchableViewsPanel = new JPanel(new CardLayout());
60
61   protected CardLayout switchableViewsLayout = (CardLayout) (switchableViewsPanel
62           .getLayout());
63
64   protected BorderLayout mainLayout = new BorderLayout();
65
66   protected BorderLayout idInputPanelLayout = new BorderLayout();
67
68   protected BorderLayout fileChooserPanelLayout = new BorderLayout();
69
70   protected JCheckBox rememberSettings = new JCheckBox("Don't ask me again");
71
72
73   protected static final String VIEWS_AUTO = "auto_view";
74
75   protected static final String VIEWS_FILE = "file_view";
76
77   protected static final String VIEWS_ID = "id_view";
78
79   protected JList jListFoundStructures = new JList();
80
81   protected JScrollPane foundStructuresScroller = new JScrollPane(
82           jListFoundStructures);
83
84   public GStructureChooser()
85   {
86     try
87     {
88       jbInit();
89       mainFrame.invalidate();
90       mainFrame.pack();
91     } catch (Exception e)
92     {
93       e.printStackTrace();
94     }
95   }
96
97   private void jbInit() throws Exception
98   {
99
100     ok.setFont(new java.awt.Font("Verdana", 0, 12));
101     ok.setText(MessageManager.getString("action.ok"));
102     ok.addActionListener(new java.awt.event.ActionListener()
103     {
104       public void actionPerformed(ActionEvent e)
105       {
106         ok_ActionPerformed();
107       }
108     });
109     cancel.setFont(new java.awt.Font("Verdana", 0, 12));
110     cancel.setText(MessageManager.getString("action.cancel"));
111     cancel.addActionListener(new java.awt.event.ActionListener()
112     {
113       public void actionPerformed(ActionEvent e)
114       {
115         mainFrame.dispose();
116       }
117     });
118
119     jListFoundStructures
120             .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
121     jListFoundStructures.setLayoutOrientation(JList.VERTICAL);
122     jListFoundStructures.setVisibleRowCount(-1);
123     foundStructuresScroller.setPreferredSize(new Dimension(500, 300));
124     foundStructuresScroller
125             .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
126
127     actionPanel.add(rememberSettings);
128     actionPanel.add(ok);
129     actionPanel.add(cancel);
130
131     filterOptions.addItemListener(this);
132
133     filterPanel.add(resultLabel);
134     filterPanel.add(filterOptions);
135
136     idInputPanel.setLayout(new FlowLayout());
137     idInputPanel.add(search);
138
139
140     selectFile.setText("                Select File             ");
141     fileChooserPanel.setLayout(new FlowLayout());
142     fileChooserPanel.add(selectFile);
143
144     switchableViewsPanel.add(fileChooserPanel, VIEWS_FILE);
145     switchableViewsPanel.add(idInputPanel, VIEWS_ID);
146     switchableViewsPanel.add(foundStructuresScroller, VIEWS_AUTO);
147
148     
149     this.setLayout(mainLayout);
150     this.add(filterPanel, java.awt.BorderLayout.NORTH);
151     this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
152     this.add(actionPanel, java.awt.BorderLayout.SOUTH);
153     populateFilterOptions();
154     updateCurrentView();
155     mainFrame.setVisible(true);
156     mainFrame.setContentPane(this);
157     mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
158     Desktop.addInternalFrame(mainFrame, frameTitle, 800, 400);
159   }
160
161   @Override
162   public void itemStateChanged(ItemEvent e)
163   {
164     updateCurrentView();
165   }
166
167   protected abstract void updateCurrentView();
168
169   protected abstract void ok_ActionPerformed();
170
171   protected abstract void populateFilterOptions();
172 }