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