JAL-1667 refactoring to support 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 import jalview.ws.uimodel.PDBSearchResponse.PDBResponseSummary;
7
8 import java.awt.BorderLayout;
9 import java.awt.CardLayout;
10 import java.awt.Dimension;
11 import java.awt.FlowLayout;
12 import java.awt.event.ActionEvent;
13 import java.awt.event.ItemEvent;
14 import java.awt.event.ItemListener;
15
16 import javax.swing.JButton;
17 import javax.swing.JCheckBox;
18 import javax.swing.JComboBox;
19 import javax.swing.JFrame;
20 import javax.swing.JInternalFrame;
21 import javax.swing.JLabel;
22 import javax.swing.JList;
23 import javax.swing.JPanel;
24 import javax.swing.JScrollPane;
25 import javax.swing.JTextField;
26 import javax.swing.ListSelectionModel;
27
28 @SuppressWarnings("serial")
29 public abstract class GStructureChooser extends JPanel implements
30         ItemListener
31 {
32   protected String frameTitle = "Structure Chooser";
33
34   protected JInternalFrame mainFrame = new JInternalFrame(frameTitle);
35
36
37
38   protected JComboBox<FilterOptions> filterOptionsComboBox = new JComboBox<FilterOptions>();
39
40   protected AlignmentPanel ap;
41
42   protected JLabel resultLabel = new JLabel("View : ");
43
44   protected JButton ok = new JButton();
45
46   protected JButton cancel = new JButton();
47
48   protected JButton pdbFromFile = new JButton();
49
50   protected JTextField search = new JTextField(16);
51
52   protected JPanel actionPanel = new JPanel();
53
54   protected JPanel filterPanel = new JPanel();
55
56   protected JPanel idInputPanel = new JPanel();
57
58   protected JPanel fileChooserPanel = new JPanel();
59
60   protected JPanel switchableViewsPanel = new JPanel(new CardLayout());
61
62   protected CardLayout switchableViewsLayout = (CardLayout) (switchableViewsPanel
63           .getLayout());
64
65   protected BorderLayout mainLayout = new BorderLayout();
66
67   protected BorderLayout idInputPanelLayout = new BorderLayout();
68
69   protected BorderLayout fileChooserPanelLayout = new BorderLayout();
70
71   protected JCheckBox rememberSettings = new JCheckBox("Don't ask me again");
72
73
74   protected static final String VIEWS_FILTER = "VIEWS_FILTER";
75
76   protected static final String VIEWS_FROM_FILE = "VIEWS_FROM_FILE";
77
78   protected static final String VIEWS_ENTER_ID = "VIEWS_ENTER_ID";
79
80   protected JList<PDBResponseSummary> jListFoundStructures = new JList<PDBResponseSummary>();
81
82   protected JScrollPane foundStructuresScroller = new JScrollPane(
83           jListFoundStructures);
84
85   public GStructureChooser()
86   {
87     try
88     {
89       jbInit();
90       mainFrame.invalidate();
91       mainFrame.pack();
92     } catch (Exception e)
93     {
94       e.printStackTrace();
95     }
96   }
97
98   private void jbInit() throws Exception
99   {
100
101     ok.setFont(new java.awt.Font("Verdana", 0, 12));
102     ok.setText(MessageManager.getString("action.ok"));
103     ok.addActionListener(new java.awt.event.ActionListener()
104     {
105       public void actionPerformed(ActionEvent e)
106       {
107         ok_ActionPerformed();
108       }
109     });
110     cancel.setFont(new java.awt.Font("Verdana", 0, 12));
111     cancel.setText(MessageManager.getString("action.cancel"));
112     cancel.addActionListener(new java.awt.event.ActionListener()
113     {
114       public void actionPerformed(ActionEvent e)
115       {
116         mainFrame.dispose();
117       }
118     });
119
120     pdbFromFile.setFont(new java.awt.Font("Verdana", 0, 12));
121     pdbFromFile.setText("             Select PDB File             ");
122     pdbFromFile.addActionListener(new java.awt.event.ActionListener()
123     {
124       public void actionPerformed(ActionEvent e)
125       {
126         pdbFromFile_actionPerformed();
127       }
128     });
129
130     jListFoundStructures
131             .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
132     jListFoundStructures.setLayoutOrientation(JList.VERTICAL);
133     jListFoundStructures.setVisibleRowCount(-1);
134     foundStructuresScroller.setPreferredSize(new Dimension(500, 300));
135     foundStructuresScroller
136             .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
137
138     actionPanel.add(rememberSettings);
139     actionPanel.add(ok);
140     actionPanel.add(cancel);
141
142     filterOptionsComboBox.addItemListener(this);
143
144     filterPanel.add(resultLabel);
145     filterPanel.add(filterOptionsComboBox);
146
147     idInputPanel.setLayout(new FlowLayout());
148     idInputPanel.add(search);
149
150
151     fileChooserPanel.setLayout(new FlowLayout());
152     fileChooserPanel.add(pdbFromFile);
153
154     switchableViewsPanel.add(fileChooserPanel, VIEWS_FROM_FILE);
155     switchableViewsPanel.add(idInputPanel, VIEWS_ENTER_ID);
156     switchableViewsPanel.add(foundStructuresScroller, VIEWS_FILTER);
157
158     
159     this.setLayout(mainLayout);
160     this.add(filterPanel, java.awt.BorderLayout.NORTH);
161     this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
162     this.add(actionPanel, java.awt.BorderLayout.SOUTH);
163
164     mainFrame.setVisible(true);
165     mainFrame.setContentPane(this);
166     mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
167     Desktop.addInternalFrame(mainFrame, frameTitle, 800, 400);
168   }
169
170   @Override
171   public void itemStateChanged(ItemEvent e)
172   {
173     stateChanged();
174   }
175
176   public class FilterOptions
177   {
178     private String name;
179
180     private String value;
181
182     private String view;
183
184     public FilterOptions(String name, String value, String view)
185     {
186       this.name = name;
187       this.value = value;
188       this.view = view;
189     }
190
191     public String getName()
192     {
193       return name;
194     }
195
196     public void setName(String name)
197     {
198       this.name = name;
199     }
200
201     public String getValue()
202     {
203       return value;
204     }
205
206     public void setValue(String value)
207     {
208       this.value = value;
209     }
210
211     public String getView()
212     {
213       return view;
214     }
215
216     public void setView(String view)
217     {
218       this.view = view;
219     }
220
221     public String toString()
222     {
223       return this.name;
224     }
225   }
226
227   protected abstract void stateChanged();
228
229   protected abstract void updateCurrentView();
230
231   protected abstract void ok_ActionPerformed();
232
233   protected abstract void populateFilterOptions();
234
235   protected abstract void pdbFromFile_actionPerformed();
236 }