418e4132178c295b016144e256db43fbdcd1a143
[jalview.git] / src / jalview / jbgui / GStructureViewer.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.jbgui;
22
23 import jalview.api.structures.JalviewStructureDisplayI;
24 import jalview.gui.ColourMenuHelper.ColourChangeListener;
25 import jalview.util.MessageManager;
26
27 import java.awt.BorderLayout;
28 import java.awt.GridLayout;
29 import java.awt.event.ActionEvent;
30 import java.awt.event.ActionListener;
31 import java.util.ArrayList;
32 import java.util.List;
33
34 import javax.swing.JCheckBoxMenuItem;
35 import javax.swing.JInternalFrame;
36 import javax.swing.JLabel;
37 import javax.swing.JMenu;
38 import javax.swing.JMenuBar;
39 import javax.swing.JMenuItem;
40 import javax.swing.JPanel;
41 import javax.swing.JRadioButtonMenuItem;
42
43 public abstract class GStructureViewer extends JInternalFrame
44         implements JalviewStructureDisplayI, ColourChangeListener
45 {
46   // private AAStructureBindingModel bindingModel;
47
48   protected JMenu savemenu;
49
50   protected JMenu viewMenu;
51
52   protected JMenu colourMenu;
53
54   protected JMenu chainMenu;
55
56   protected JMenu viewerActionMenu;
57
58   protected JMenuItem alignStructs;
59
60   protected JCheckBoxMenuItem showAlignmentOnly;
61
62   protected JMenuItem fitToWindow;
63
64   protected JRadioButtonMenuItem seqColour;
65
66   protected JRadioButtonMenuItem chainColour;
67
68   protected JRadioButtonMenuItem chargeColour;
69
70   protected JRadioButtonMenuItem viewerColour;
71
72   protected JMenuItem helpItem;
73
74   protected JLabel statusBar;
75
76   protected JPanel statusPanel;
77
78   /**
79    * Constructor
80    */
81   public GStructureViewer()
82   {
83     try
84     {
85       jbInit();
86     } catch (Exception ex)
87     {
88       ex.printStackTrace();
89     }
90   }
91
92   private void jbInit() throws Exception
93   {
94     JMenuBar menuBar = new JMenuBar();
95     this.setJMenuBar(menuBar);
96
97     JMenu fileMenu = new JMenu();
98     fileMenu.setText(MessageManager.getString("action.file"));
99
100     savemenu = new JMenu();
101     savemenu.setActionCommand(
102             MessageManager.getString("action.save_image"));
103     savemenu.setText(MessageManager.getString("action.save_as"));
104
105     JMenuItem pdbFile = new JMenuItem();
106     pdbFile.setText(MessageManager.getString("label.pdb_file"));
107     pdbFile.addActionListener(new ActionListener()
108     {
109       @Override
110       public void actionPerformed(ActionEvent actionEvent)
111       {
112         pdbFile_actionPerformed(actionEvent);
113       }
114     });
115
116     JMenuItem png = new JMenuItem();
117     png.setText("PNG");
118     png.addActionListener(new ActionListener()
119     {
120       @Override
121       public void actionPerformed(ActionEvent actionEvent)
122       {
123         png_actionPerformed(actionEvent);
124       }
125     });
126
127     JMenuItem eps = new JMenuItem();
128     eps.setText("EPS");
129     eps.addActionListener(new ActionListener()
130     {
131       @Override
132       public void actionPerformed(ActionEvent actionEvent)
133       {
134         eps_actionPerformed(actionEvent);
135       }
136     });
137
138     JMenuItem viewMapping = new JMenuItem();
139     viewMapping.setText(MessageManager.getString("label.view_mapping"));
140     viewMapping.addActionListener(new ActionListener()
141     {
142       @Override
143       public void actionPerformed(ActionEvent actionEvent)
144       {
145         viewMapping_actionPerformed(actionEvent);
146       }
147     });
148
149     viewMenu = new JMenu();
150     viewMenu.setText(MessageManager.getString("action.view"));
151
152     chainMenu = new JMenu();
153     chainMenu.setText(MessageManager.getString("action.show_chain"));
154
155     fitToWindow = new JMenuItem();
156     fitToWindow.setText(MessageManager.getString("label.fit_to_window"));
157     fitToWindow.addActionListener(new ActionListener()
158     {
159       @Override
160       public void actionPerformed(ActionEvent actionEvent)
161       {
162         fitToWindow_actionPerformed();
163       }
164     });
165
166     JMenu helpMenu = new JMenu();
167     helpMenu.setText(MessageManager.getString("action.help"));
168     helpItem = new JMenuItem();
169     helpItem.setText(MessageManager.getString("label.jmol_help"));
170     helpItem.addActionListener(new ActionListener()
171     {
172       @Override
173       public void actionPerformed(ActionEvent actionEvent)
174       {
175         showHelp_actionPerformed(actionEvent);
176       }
177     });
178     alignStructs = new JMenuItem();
179     alignStructs.setText(
180             MessageManager.getString("label.superpose_structures"));
181     alignStructs.addActionListener(new ActionListener()
182     {
183       @Override
184       public void actionPerformed(ActionEvent actionEvent)
185       {
186         alignStructs_actionPerformed(actionEvent);
187       }
188     });
189
190     viewerActionMenu = new JMenu(); // text set in sub-classes
191     viewerActionMenu.setVisible(false);
192     viewerActionMenu.add(alignStructs);
193     colourMenu = new JMenu();
194     colourMenu.setText(MessageManager.getString("label.colours"));
195     fileMenu.add(savemenu);
196     fileMenu.add(viewMapping);
197     savemenu.add(pdbFile);
198     savemenu.add(png);
199     savemenu.add(eps);
200     viewMenu.add(chainMenu);
201     helpMenu.add(helpItem);
202
203     menuBar.add(fileMenu);
204     menuBar.add(viewMenu);
205     menuBar.add(colourMenu);
206     menuBar.add(viewerActionMenu);
207     menuBar.add(helpMenu);
208
209     statusPanel = new JPanel();
210     statusPanel.setLayout(new GridLayout());
211     this.getContentPane().add(statusPanel, BorderLayout.SOUTH);
212     statusBar = new JLabel();
213     statusPanel.add(statusBar, null);
214   }
215
216   protected void fitToWindow_actionPerformed()
217   {
218   }
219
220   protected void highlightSelection_actionPerformed()
221   {
222   }
223
224   protected void viewerColour_actionPerformed(ActionEvent actionEvent)
225   {
226   }
227
228   protected abstract String alignStructs_actionPerformed(
229           ActionEvent actionEvent);
230
231   public void pdbFile_actionPerformed(ActionEvent actionEvent)
232   {
233
234   }
235
236   public void png_actionPerformed(ActionEvent actionEvent)
237   {
238
239   }
240
241   public void eps_actionPerformed(ActionEvent actionEvent)
242   {
243
244   }
245
246   public void viewMapping_actionPerformed(ActionEvent actionEvent)
247   {
248
249   }
250
251   public void seqColour_actionPerformed(ActionEvent actionEvent)
252   {
253
254   }
255
256   public void chainColour_actionPerformed(ActionEvent actionEvent)
257   {
258
259   }
260
261   public void chargeColour_actionPerformed(ActionEvent actionEvent)
262   {
263
264   }
265
266   public void background_actionPerformed(ActionEvent actionEvent)
267   {
268
269   }
270
271   public void showHelp_actionPerformed(ActionEvent actionEvent)
272   {
273
274   }
275
276   /**
277    * Saves the selected entries in the 'View Chain' menu into a list. Entries are
278    * formatted as "pdbid:chainid". Only the selected chains should be drawn in the
279    * structure display.
280    */
281   protected void setSelectedChains()
282   {
283     List<String> chains = new ArrayList<>();
284     for (int i = 0; i < chainMenu.getItemCount(); i++)
285     {
286       JMenuItem menuItem = chainMenu.getItem(i);
287       if (menuItem instanceof JCheckBoxMenuItem)
288       {
289         JCheckBoxMenuItem item = (JCheckBoxMenuItem) menuItem;
290         if (item.isSelected())
291         {
292           chains.add(item.getText());
293         }
294       }
295     }
296     getBinding().setChainsToShow(chains);
297   }
298 }