2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.jbgui;
23 import jalview.api.structures.JalviewStructureDisplayI;
24 import jalview.gui.ColourMenuHelper.ColourChangeListener;
25 import jalview.util.MessageManager;
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;
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;
43 public abstract class GStructureViewer extends JInternalFrame
44 implements JalviewStructureDisplayI, ColourChangeListener
46 // private AAStructureBindingModel bindingModel;
48 protected JMenu savemenu;
50 protected JMenu viewMenu;
52 protected JMenu colourMenu;
54 protected JMenu chainMenu;
56 protected JMenu viewerActionMenu;
58 protected JMenuItem alignStructs;
60 protected JCheckBoxMenuItem showAlignmentOnly;
62 protected JCheckBoxMenuItem hideHiddenRegions;
64 protected JMenuItem fitToWindow;
66 protected JRadioButtonMenuItem seqColour;
68 protected JRadioButtonMenuItem chainColour;
70 protected JRadioButtonMenuItem chargeColour;
72 protected JRadioButtonMenuItem viewerColour;
74 protected JMenuItem helpItem;
76 protected JLabel statusBar;
78 protected JPanel statusPanel;
83 public GStructureViewer()
88 } catch (Exception ex)
94 private void jbInit() throws Exception
96 JMenuBar menuBar = new JMenuBar();
97 this.setJMenuBar(menuBar);
99 JMenu fileMenu = new JMenu();
100 fileMenu.setText(MessageManager.getString("action.file"));
102 savemenu = new JMenu();
103 savemenu.setActionCommand(
104 MessageManager.getString("action.save_image"));
105 savemenu.setText(MessageManager.getString("action.save_as"));
107 JMenuItem pdbFile = new JMenuItem();
108 pdbFile.setText(MessageManager.getString("label.pdb_file"));
109 pdbFile.addActionListener(new ActionListener()
112 public void actionPerformed(ActionEvent actionEvent)
114 pdbFile_actionPerformed(actionEvent);
118 JMenuItem png = new JMenuItem();
120 png.addActionListener(new ActionListener()
123 public void actionPerformed(ActionEvent actionEvent)
125 png_actionPerformed(actionEvent);
129 JMenuItem eps = new JMenuItem();
131 eps.addActionListener(new ActionListener()
134 public void actionPerformed(ActionEvent actionEvent)
136 eps_actionPerformed(actionEvent);
140 JMenuItem viewMapping = new JMenuItem();
141 viewMapping.setText(MessageManager.getString("label.view_mapping"));
142 viewMapping.addActionListener(new ActionListener()
145 public void actionPerformed(ActionEvent actionEvent)
147 viewMapping_actionPerformed(actionEvent);
151 viewMenu = new JMenu();
152 viewMenu.setText(MessageManager.getString("action.view"));
154 chainMenu = new JMenu();
155 chainMenu.setText(MessageManager.getString("action.show_chain"));
157 fitToWindow = new JMenuItem();
158 fitToWindow.setText(MessageManager.getString("label.fit_to_window"));
159 fitToWindow.addActionListener(new ActionListener()
162 public void actionPerformed(ActionEvent actionEvent)
164 getBinding().focusView();
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()
175 public void actionPerformed(ActionEvent actionEvent)
177 showHelp_actionPerformed(actionEvent);
180 alignStructs = new JMenuItem();
181 alignStructs.setText(
182 MessageManager.getString("label.superpose_structures"));
183 alignStructs.addActionListener(new ActionListener()
186 public void actionPerformed(ActionEvent actionEvent)
188 alignStructs_actionPerformed(actionEvent);
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);
202 viewMenu.add(chainMenu);
203 helpMenu.add(helpItem);
205 menuBar.add(fileMenu);
206 menuBar.add(viewMenu);
207 menuBar.add(colourMenu);
208 menuBar.add(viewerActionMenu);
209 menuBar.add(helpMenu);
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);
218 protected void highlightSelection_actionPerformed()
222 protected void viewerColour_actionPerformed(ActionEvent actionEvent)
226 protected abstract String alignStructs_actionPerformed(
227 ActionEvent actionEvent);
229 public void pdbFile_actionPerformed(ActionEvent actionEvent)
234 public void png_actionPerformed(ActionEvent actionEvent)
239 public void eps_actionPerformed(ActionEvent actionEvent)
244 public void viewMapping_actionPerformed(ActionEvent actionEvent)
249 public void seqColour_actionPerformed(ActionEvent actionEvent)
254 public void chainColour_actionPerformed(ActionEvent actionEvent)
259 public void chargeColour_actionPerformed(ActionEvent actionEvent)
264 public void background_actionPerformed(ActionEvent actionEvent)
269 public void showHelp_actionPerformed(ActionEvent actionEvent)
275 * Saves the unselected entries in the 'View Chain' menu into a list. Entries
276 * are formatted as "pdbid:chainid". Unselected chains should be hidden in the
279 protected void setChainsToHide()
281 List<String> chains = new ArrayList<>();
282 for (int i = 0; i < chainMenu.getItemCount(); i++)
284 JMenuItem menuItem = chainMenu.getItem(i);
285 if (menuItem instanceof JCheckBoxMenuItem)
287 JCheckBoxMenuItem item = (JCheckBoxMenuItem) menuItem;
288 if (!item.isSelected())
290 chains.add(item.getText().split(" ")[0]);
294 getBinding().setChainsToHide(chains);