JAL-3400 include sequence name in View | Show Chain menu
[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 JCheckBoxMenuItem hideHiddenRegions;
63
64   protected JMenuItem fitToWindow;
65
66   protected JRadioButtonMenuItem seqColour;
67
68   protected JRadioButtonMenuItem chainColour;
69
70   protected JRadioButtonMenuItem chargeColour;
71
72   protected JRadioButtonMenuItem viewerColour;
73
74   protected JMenuItem helpItem;
75
76   protected JLabel statusBar;
77
78   protected JPanel statusPanel;
79
80   /**
81    * Constructor
82    */
83   public GStructureViewer()
84   {
85     try
86     {
87       jbInit();
88     } catch (Exception ex)
89     {
90       ex.printStackTrace();
91     }
92   }
93
94   private void jbInit() throws Exception
95   {
96     JMenuBar menuBar = new JMenuBar();
97     this.setJMenuBar(menuBar);
98
99     JMenu fileMenu = new JMenu();
100     fileMenu.setText(MessageManager.getString("action.file"));
101
102     savemenu = new JMenu();
103     savemenu.setActionCommand(
104             MessageManager.getString("action.save_image"));
105     savemenu.setText(MessageManager.getString("action.save_as"));
106
107     JMenuItem pdbFile = new JMenuItem();
108     pdbFile.setText(MessageManager.getString("label.pdb_file"));
109     pdbFile.addActionListener(new ActionListener()
110     {
111       @Override
112       public void actionPerformed(ActionEvent actionEvent)
113       {
114         pdbFile_actionPerformed(actionEvent);
115       }
116     });
117
118     JMenuItem png = new JMenuItem();
119     png.setText("PNG");
120     png.addActionListener(new ActionListener()
121     {
122       @Override
123       public void actionPerformed(ActionEvent actionEvent)
124       {
125         png_actionPerformed(actionEvent);
126       }
127     });
128
129     JMenuItem eps = new JMenuItem();
130     eps.setText("EPS");
131     eps.addActionListener(new ActionListener()
132     {
133       @Override
134       public void actionPerformed(ActionEvent actionEvent)
135       {
136         eps_actionPerformed(actionEvent);
137       }
138     });
139
140     JMenuItem viewMapping = new JMenuItem();
141     viewMapping.setText(MessageManager.getString("label.view_mapping"));
142     viewMapping.addActionListener(new ActionListener()
143     {
144       @Override
145       public void actionPerformed(ActionEvent actionEvent)
146       {
147         viewMapping_actionPerformed(actionEvent);
148       }
149     });
150
151     viewMenu = new JMenu();
152     viewMenu.setText(MessageManager.getString("action.view"));
153
154     chainMenu = new JMenu();
155     chainMenu.setText(MessageManager.getString("action.show_chain"));
156
157     fitToWindow = new JMenuItem();
158     fitToWindow.setText(MessageManager.getString("label.fit_to_window"));
159     fitToWindow.addActionListener(new ActionListener()
160     {
161       @Override
162       public void actionPerformed(ActionEvent actionEvent)
163       {
164         fitToWindow_actionPerformed();
165       }
166     });
167
168     JMenu helpMenu = new JMenu();
169     helpMenu.setText(MessageManager.getString("action.help"));
170     helpItem = new JMenuItem();
171     helpItem.setText(MessageManager.getString("label.jmol_help"));
172     helpItem.addActionListener(new ActionListener()
173     {
174       @Override
175       public void actionPerformed(ActionEvent actionEvent)
176       {
177         showHelp_actionPerformed(actionEvent);
178       }
179     });
180     alignStructs = new JMenuItem();
181     alignStructs.setText(
182             MessageManager.getString("label.superpose_structures"));
183     alignStructs.addActionListener(new ActionListener()
184     {
185       @Override
186       public void actionPerformed(ActionEvent actionEvent)
187       {
188         alignStructs_actionPerformed(actionEvent);
189       }
190     });
191
192     viewerActionMenu = new JMenu(); // text set in sub-classes
193     viewerActionMenu.setVisible(false);
194     viewerActionMenu.add(alignStructs);
195     colourMenu = new JMenu();
196     colourMenu.setText(MessageManager.getString("label.colours"));
197     fileMenu.add(savemenu);
198     fileMenu.add(viewMapping);
199     savemenu.add(pdbFile);
200     savemenu.add(png);
201     savemenu.add(eps);
202     viewMenu.add(chainMenu);
203     helpMenu.add(helpItem);
204
205     menuBar.add(fileMenu);
206     menuBar.add(viewMenu);
207     menuBar.add(colourMenu);
208     menuBar.add(viewerActionMenu);
209     menuBar.add(helpMenu);
210
211     statusPanel = new JPanel();
212     statusPanel.setLayout(new GridLayout());
213     this.getContentPane().add(statusPanel, BorderLayout.SOUTH);
214     statusBar = new JLabel();
215     statusPanel.add(statusBar, null);
216   }
217
218   protected void fitToWindow_actionPerformed()
219   {
220   }
221
222   protected void highlightSelection_actionPerformed()
223   {
224   }
225
226   protected void viewerColour_actionPerformed(ActionEvent actionEvent)
227   {
228   }
229
230   protected abstract String alignStructs_actionPerformed(
231           ActionEvent actionEvent);
232
233   public void pdbFile_actionPerformed(ActionEvent actionEvent)
234   {
235
236   }
237
238   public void png_actionPerformed(ActionEvent actionEvent)
239   {
240
241   }
242
243   public void eps_actionPerformed(ActionEvent actionEvent)
244   {
245
246   }
247
248   public void viewMapping_actionPerformed(ActionEvent actionEvent)
249   {
250
251   }
252
253   public void seqColour_actionPerformed(ActionEvent actionEvent)
254   {
255
256   }
257
258   public void chainColour_actionPerformed(ActionEvent actionEvent)
259   {
260
261   }
262
263   public void chargeColour_actionPerformed(ActionEvent actionEvent)
264   {
265
266   }
267
268   public void background_actionPerformed(ActionEvent actionEvent)
269   {
270
271   }
272
273   public void showHelp_actionPerformed(ActionEvent actionEvent)
274   {
275
276   }
277
278   /**
279    * Saves the selected entries in the 'View Chain' menu into a list. Entries are
280    * formatted as "pdbid:chainid". Only the selected chains should be drawn in the
281    * structure display.
282    */
283   protected void setSelectedChains()
284   {
285     List<String> chains = new ArrayList<>();
286     for (int i = 0; i < chainMenu.getItemCount(); i++)
287     {
288       JMenuItem menuItem = chainMenu.getItem(i);
289       if (menuItem instanceof JCheckBoxMenuItem)
290       {
291         JCheckBoxMenuItem item = (JCheckBoxMenuItem) menuItem;
292         if (item.isSelected())
293         {
294           chains.add(item.getText().split(" ")[0]);
295         }
296       }
297     }
298     getBinding().setChainsToShow(chains);
299   }
300 }