JAL-1588 refactoring prior to 'save Chimera project'
[jalview.git] / src / jalview / jbgui / GStructureViewer.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3  * Copyright (C) 2014 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.AlignmentPanel;
25 import jalview.util.MessageManager;
26
27 import java.awt.event.ActionEvent;
28 import java.awt.event.ActionListener;
29 import java.util.ArrayList;
30 import java.util.Vector;
31
32 import javax.swing.ButtonGroup;
33 import javax.swing.JInternalFrame;
34 import javax.swing.JMenu;
35 import javax.swing.JMenuBar;
36 import javax.swing.JMenuItem;
37 import javax.swing.JRadioButtonMenuItem;
38
39 public abstract class GStructureViewer extends JInternalFrame implements
40         JalviewStructureDisplayI
41 {
42   // private AAStructureBindingModel bindingModel;
43
44   protected JMenu savemenu = new JMenu();
45
46   protected JMenu viewMenu = new JMenu();
47
48   protected JMenu chainMenu = new JMenu();
49
50   protected JMenu viewerActionMenu = new JMenu();
51
52   protected JMenuItem alignStructs = new JMenuItem();
53
54   protected JRadioButtonMenuItem seqColour = new JRadioButtonMenuItem();
55
56   protected JRadioButtonMenuItem chainColour = new JRadioButtonMenuItem();
57
58   protected JRadioButtonMenuItem chargeColour = new JRadioButtonMenuItem();
59
60   protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
61
62   protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
63
64   protected JRadioButtonMenuItem hydroColour = new JRadioButtonMenuItem();
65
66   protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
67
68   protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
69
70   protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
71
72   protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
73
74   protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem();
75
76   protected JRadioButtonMenuItem userColour = new JRadioButtonMenuItem();
77
78   protected JRadioButtonMenuItem viewerColour = new JRadioButtonMenuItem();
79
80   protected JMenuItem helpItem = new JMenuItem();
81
82   /**
83    * list of sequenceSet ids associated with the view
84    */
85   protected ArrayList<String> _aps = new ArrayList<String>();
86
87   /**
88    * list of alignment panels to use for superposition
89    */
90   protected Vector<AlignmentPanel> _alignwith = new Vector<AlignmentPanel>();
91
92   /**
93    * list of alignment panels that are used for colouring structures by aligned
94    * sequences
95    */
96   protected Vector<AlignmentPanel> _colourwith = new Vector<AlignmentPanel>();
97
98   private String viewId = null;
99
100   /**
101    * Constructor
102    */
103   public GStructureViewer()
104   {
105     try
106     {
107       jbInit();
108     } catch (Exception ex)
109     {
110       ex.printStackTrace();
111     }
112   }
113
114   private void jbInit() throws Exception
115   {
116     JMenuBar menuBar = new JMenuBar();
117     this.setJMenuBar(menuBar);
118
119     JMenu fileMenu = new JMenu();
120     fileMenu.setText(MessageManager.getString("action.file"));
121
122     savemenu.setActionCommand(MessageManager.getString("action.save_image"));
123     savemenu.setText(MessageManager.getString("action.save_as"));
124
125     JMenuItem pdbFile = new JMenuItem();
126     pdbFile.setText(MessageManager.getString("label.pdb_file"));
127     pdbFile.addActionListener(new ActionListener()
128     {
129       public void actionPerformed(ActionEvent actionEvent)
130       {
131         pdbFile_actionPerformed(actionEvent);
132       }
133     });
134
135     JMenuItem png = new JMenuItem();
136     png.setText("PNG");
137     png.addActionListener(new ActionListener()
138     {
139       public void actionPerformed(ActionEvent actionEvent)
140       {
141         png_actionPerformed(actionEvent);
142       }
143     });
144
145     JMenuItem eps = new JMenuItem();
146     eps.setText("EPS");
147     eps.addActionListener(new ActionListener()
148     {
149       public void actionPerformed(ActionEvent actionEvent)
150       {
151         eps_actionPerformed(actionEvent);
152       }
153     });
154
155     JMenuItem viewMapping = new JMenuItem();
156     viewMapping.setText(MessageManager.getString("label.view_mapping"));
157     viewMapping.addActionListener(new ActionListener()
158     {
159       public void actionPerformed(ActionEvent actionEvent)
160       {
161         viewMapping_actionPerformed(actionEvent);
162       }
163     });
164     viewMenu.setText(MessageManager.getString("action.view"));
165     chainMenu.setText(MessageManager.getString("action.show_chain"));
166
167     JMenu colourMenu = new JMenu();
168     colourMenu.setText(MessageManager.getString("label.colours"));
169
170     JMenuItem backGround = new JMenuItem();
171     backGround.setText(MessageManager.getString("label.background_colour")
172             + "...");
173     backGround.addActionListener(new ActionListener()
174     {
175       public void actionPerformed(ActionEvent actionEvent)
176       {
177         backGround_actionPerformed(actionEvent);
178       }
179     });
180     seqColour.setSelected(false);
181     seqColour.setText(MessageManager.getString("action.by_sequence"));
182     seqColour.addActionListener(new ActionListener()
183     {
184       public void actionPerformed(ActionEvent actionEvent)
185       {
186         seqColour_actionPerformed(actionEvent);
187       }
188     });
189     chainColour.setText(MessageManager.getString("action.by_chain"));
190     chainColour.addActionListener(new ActionListener()
191     {
192       public void actionPerformed(ActionEvent actionEvent)
193       {
194         chainColour_actionPerformed(actionEvent);
195       }
196     });
197     chargeColour.setText(MessageManager.getString("label.charge_cysteine"));
198     chargeColour.addActionListener(new ActionListener()
199     {
200       public void actionPerformed(ActionEvent actionEvent)
201       {
202         chargeColour_actionPerformed(actionEvent);
203       }
204     });
205     zappoColour.setText(MessageManager.getString("label.zappo"));
206     zappoColour.addActionListener(new ActionListener()
207     {
208       public void actionPerformed(ActionEvent actionEvent)
209       {
210         zappoColour_actionPerformed(actionEvent);
211       }
212     });
213     taylorColour.setText(MessageManager.getString("label.taylor"));
214     taylorColour.addActionListener(new ActionListener()
215     {
216       public void actionPerformed(ActionEvent actionEvent)
217       {
218         taylorColour_actionPerformed(actionEvent);
219       }
220     });
221     hydroColour.setText(MessageManager.getString("label.hydrophobicity"));
222     hydroColour.addActionListener(new ActionListener()
223     {
224       public void actionPerformed(ActionEvent actionEvent)
225       {
226         hydroColour_actionPerformed(actionEvent);
227       }
228     });
229     strandColour.setText(MessageManager
230             .getString("label.strand_propensity"));
231     strandColour.addActionListener(new ActionListener()
232     {
233       public void actionPerformed(ActionEvent actionEvent)
234       {
235         strandColour_actionPerformed(actionEvent);
236       }
237     });
238     helixColour.setText(MessageManager.getString("label.helix_propensity"));
239     helixColour.addActionListener(new ActionListener()
240     {
241       public void actionPerformed(ActionEvent actionEvent)
242       {
243         helixColour_actionPerformed(actionEvent);
244       }
245     });
246     turnColour.setText(MessageManager.getString("label.turn_propensity"));
247     turnColour.addActionListener(new ActionListener()
248     {
249       public void actionPerformed(ActionEvent actionEvent)
250       {
251         turnColour_actionPerformed(actionEvent);
252       }
253     });
254     buriedColour.setText(MessageManager.getString("label.buried_index"));
255     buriedColour.addActionListener(new ActionListener()
256     {
257       public void actionPerformed(ActionEvent actionEvent)
258       {
259         buriedColour_actionPerformed(actionEvent);
260       }
261     });
262     purinePyrimidineColour.setText(MessageManager
263             .getString("label.purine_pyrimidine"));
264     purinePyrimidineColour.addActionListener(new ActionListener()
265     {
266       public void actionPerformed(ActionEvent actionEvent)
267       {
268         purinePyrimidineColour_actionPerformed(actionEvent);
269       }
270     });
271
272     userColour.setText(MessageManager.getString("action.user_defined"));
273     userColour.addActionListener(new ActionListener()
274     {
275       public void actionPerformed(ActionEvent actionEvent)
276       {
277         userColour_actionPerformed(actionEvent);
278       }
279     });
280     viewerColour.setSelected(false);
281     viewerColour
282             .setText(MessageManager.getString("label.colour_with_jmol"));
283     viewerColour.setToolTipText(MessageManager
284             .getString("label.let_jmol_manage_structure_colours"));
285     viewerColour.addActionListener(new ActionListener()
286     {
287       public void actionPerformed(ActionEvent actionEvent)
288       {
289         viewerColour_actionPerformed(actionEvent);
290       }
291     });
292
293     JMenu helpMenu = new JMenu();
294     helpMenu.setText(MessageManager.getString("action.help"));
295     helpItem.setText(MessageManager.getString("label.jmol_help"));
296     helpItem.addActionListener(new ActionListener()
297     {
298       public void actionPerformed(ActionEvent actionEvent)
299       {
300         showHelp_actionPerformed(actionEvent);
301       }
302     });
303     alignStructs
304             .setText(MessageManager.getString("label.align_structures"));
305     alignStructs.addActionListener(new ActionListener()
306     {
307       public void actionPerformed(ActionEvent actionEvent)
308       {
309         alignStructs_actionPerformed(actionEvent);
310       }
311     });
312     viewerActionMenu.setText(MessageManager.getString("label.jmol"));
313     menuBar.add(fileMenu);
314     menuBar.add(viewMenu);
315     menuBar.add(colourMenu);
316     menuBar.add(viewerActionMenu);
317     viewerActionMenu.setVisible(false);
318     menuBar.add(helpMenu);
319     fileMenu.add(savemenu);
320     fileMenu.add(viewMapping);
321     savemenu.add(pdbFile);
322     savemenu.add(png);
323     savemenu.add(eps);
324     viewMenu.add(chainMenu);
325
326     colourMenu.add(seqColour);
327     colourMenu.add(chainColour);
328     colourMenu.add(chargeColour);
329     colourMenu.add(zappoColour);
330     colourMenu.add(taylorColour);
331     colourMenu.add(hydroColour);
332     colourMenu.add(helixColour);
333     colourMenu.add(strandColour);
334     colourMenu.add(turnColour);
335     colourMenu.add(buriedColour);
336     colourMenu.add(purinePyrimidineColour);
337     colourMenu.add(userColour);
338     colourMenu.add(viewerColour);
339     colourMenu.add(backGround);
340
341     ButtonGroup colourButtons = new ButtonGroup();
342
343     colourButtons.add(seqColour);
344     colourButtons.add(chainColour);
345     colourButtons.add(chargeColour);
346     colourButtons.add(zappoColour);
347     colourButtons.add(taylorColour);
348     colourButtons.add(hydroColour);
349     colourButtons.add(helixColour);
350     colourButtons.add(strandColour);
351     colourButtons.add(turnColour);
352     colourButtons.add(buriedColour);
353     colourButtons.add(userColour);
354     colourButtons.add(viewerColour);
355
356     helpMenu.add(helpItem);
357     viewerActionMenu.add(alignStructs);
358   }
359
360   protected void viewerColour_actionPerformed(ActionEvent actionEvent)
361   {
362   }
363
364   protected void alignStructs_actionPerformed(ActionEvent actionEvent)
365   {
366   }
367
368   public void pdbFile_actionPerformed(ActionEvent actionEvent)
369   {
370
371   }
372
373   public void png_actionPerformed(ActionEvent actionEvent)
374   {
375
376   }
377
378   public void eps_actionPerformed(ActionEvent actionEvent)
379   {
380
381   }
382
383   public void viewMapping_actionPerformed(ActionEvent actionEvent)
384   {
385
386   }
387
388   public void seqColour_actionPerformed(ActionEvent actionEvent)
389   {
390
391   }
392
393   public void chainColour_actionPerformed(ActionEvent actionEvent)
394   {
395
396   }
397
398   public void chargeColour_actionPerformed(ActionEvent actionEvent)
399   {
400
401   }
402
403   public void zappoColour_actionPerformed(ActionEvent actionEvent)
404   {
405
406   }
407
408   public void taylorColour_actionPerformed(ActionEvent actionEvent)
409   {
410
411   }
412
413   public void hydroColour_actionPerformed(ActionEvent actionEvent)
414   {
415
416   }
417
418   public void helixColour_actionPerformed(ActionEvent actionEvent)
419   {
420
421   }
422
423   public void strandColour_actionPerformed(ActionEvent actionEvent)
424   {
425
426   }
427
428   public void turnColour_actionPerformed(ActionEvent actionEvent)
429   {
430
431   }
432
433   public void buriedColour_actionPerformed(ActionEvent actionEvent)
434   {
435
436   }
437
438   public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
439   {
440
441   }
442
443   public void userColour_actionPerformed(ActionEvent actionEvent)
444   {
445
446   }
447
448   public void backGround_actionPerformed(ActionEvent actionEvent)
449   {
450
451   }
452
453   public void showHelp_actionPerformed(ActionEvent actionEvent)
454   {
455
456   }
457
458   // {
459   // return bindingModel;
460   // }
461
462   // public void setBindingModel(AAStructureBindingModel bindingModel)
463   // {
464   // this.bindingModel = bindingModel;
465   // }
466
467   /**
468    * 
469    * @param ap2
470    * @return true if this Jmol instance is linked with the given alignPanel
471    */
472   public boolean isLinkedWith(AlignmentPanel ap2)
473   {
474     return _aps.contains(ap2.av.getSequenceSetId());
475   }
476
477   public boolean isUsedforaligment(AlignmentPanel ap2)
478   {
479   
480     return (_alignwith != null) && _alignwith.contains(ap2);
481   }
482
483   public boolean isUsedforcolourby(AlignmentPanel ap2)
484   {
485     return (_colourwith != null) && _colourwith.contains(ap2);
486   }
487
488   /**
489    * 
490    * @return TRUE if the view is NOT being coloured by the alignment colours.
491    */
492   public boolean isColouredByViewer()
493   {
494     return !getBinding().isColourBySequence();
495   }
496
497   public String getViewId()
498   {
499     if (viewId == null)
500     {
501       viewId = System.currentTimeMillis() + "." + this.hashCode();
502     }
503     return viewId;
504   }
505
506   protected void setViewId(String viewId)
507   {
508     this.viewId = viewId;
509   }
510
511   public String getStateInfo()
512   {
513     return null;
514   }
515 }