JAL-3463 avoid Thread.sleep() as not supported in SwingJS
[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.ImageMaker.TYPE;
26 import jalview.util.MessageManager;
27
28 import java.awt.BorderLayout;
29 import java.awt.GridLayout;
30 import java.awt.event.ActionEvent;
31 import java.awt.event.ActionListener;
32
33 import javax.swing.JInternalFrame;
34 import javax.swing.JLabel;
35 import javax.swing.JMenu;
36 import javax.swing.JMenuBar;
37 import javax.swing.JMenuItem;
38 import javax.swing.JPanel;
39 import javax.swing.JRadioButtonMenuItem;
40
41 @SuppressWarnings("serial")
42 public abstract class GStructureViewer extends JInternalFrame
43         implements JalviewStructureDisplayI, ColourChangeListener
44 {
45   // private AAStructureBindingModel bindingModel;
46
47   protected JMenu savemenu;
48
49   protected JMenu viewMenu;
50
51   protected JMenu colourMenu;
52
53   protected JMenu chainMenu;
54
55   protected JMenu viewerActionMenu;
56
57   protected JMenuItem alignStructs;
58
59   protected JMenuItem fitToWindow;
60
61   protected JRadioButtonMenuItem seqColour;
62
63   protected JRadioButtonMenuItem chainColour;
64
65   protected JRadioButtonMenuItem chargeColour;
66
67   protected JRadioButtonMenuItem viewerColour;
68
69   protected JMenuItem helpItem;
70
71   protected JLabel statusBar;
72
73   protected JPanel statusPanel;
74
75   /**
76    * Constructor
77    */
78   public GStructureViewer()
79   {
80     try
81     {
82       jbInit();
83     } catch (Exception ex)
84     {
85       ex.printStackTrace();
86     }
87   }
88
89   private void jbInit() throws Exception
90   {
91
92     setName("jalview-structureviewer");
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         makePDBImage(TYPE.PNG);
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         makePDBImage(TYPE.EPS);
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 makePDBImage(TYPE imageType)
237   {
238
239   }
240
241   public void viewMapping_actionPerformed(ActionEvent actionEvent)
242   {
243
244   }
245
246   public void seqColour_actionPerformed(ActionEvent actionEvent)
247   {
248
249   }
250
251   public void chainColour_actionPerformed(ActionEvent actionEvent)
252   {
253
254   }
255
256   public void chargeColour_actionPerformed(ActionEvent actionEvent)
257   {
258
259   }
260
261   public void background_actionPerformed(ActionEvent actionEvent)
262   {
263
264   }
265
266   public void showHelp_actionPerformed(ActionEvent actionEvent)
267   {
268
269   }
270 }