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 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;
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;
39 import jalview.api.structures.JalviewStructureDisplayI;
40 import jalview.gui.ColourMenuHelper.ColourChangeListener;
41 import jalview.util.ImageMaker.TYPE;
42 import jalview.util.MessageManager;
44 @SuppressWarnings("serial")
45 public abstract class GStructureViewer extends JInternalFrame
46 implements JalviewStructureDisplayI, ColourChangeListener
48 // private AAStructureBindingModel bindingModel;
50 protected JMenu savemenu;
52 protected JMenu viewMenu;
54 protected JMenu colourMenu;
56 protected JMenu chainMenu;
58 protected JMenu viewerActionMenu;
60 protected JMenuItem alignStructs;
62 protected JCheckBoxMenuItem showAlignmentOnly;
64 protected JCheckBoxMenuItem hideHiddenRegions;
66 protected JMenuItem fitToWindow;
68 protected JRadioButtonMenuItem seqColour;
70 protected JRadioButtonMenuItem chainColour;
72 protected JRadioButtonMenuItem chargeColour;
74 protected JRadioButtonMenuItem viewerColour;
76 protected JMenuItem helpItem;
78 protected JLabel statusBar;
80 protected JPanel statusPanel;
85 public GStructureViewer()
90 } catch (Exception ex)
96 private void jbInit() throws Exception
99 setName("jalview-structureviewer");
101 JMenuBar menuBar = new JMenuBar();
102 this.setJMenuBar(menuBar);
104 JMenu fileMenu = new JMenu();
105 fileMenu.setText(MessageManager.getString("action.file"));
107 savemenu = new JMenu();
108 savemenu.setActionCommand(
109 MessageManager.getString("action.save_image"));
110 savemenu.setText(MessageManager.getString("action.save_as"));
112 JMenuItem pdbFile = new JMenuItem();
113 pdbFile.setText(MessageManager.getString("label.pdb_file"));
114 pdbFile.addActionListener(new ActionListener()
117 public void actionPerformed(ActionEvent actionEvent)
119 pdbFile_actionPerformed();
123 JMenuItem png = new JMenuItem();
125 png.addActionListener(new ActionListener()
128 public void actionPerformed(ActionEvent actionEvent)
130 makePDBImage(TYPE.PNG);
134 JMenuItem eps = new JMenuItem();
136 eps.addActionListener(new ActionListener()
139 public void actionPerformed(ActionEvent actionEvent)
141 makePDBImage(TYPE.EPS);
145 JMenuItem viewMapping = new JMenuItem();
146 viewMapping.setText(MessageManager.getString("label.view_mapping"));
147 viewMapping.addActionListener(new ActionListener()
150 public void actionPerformed(ActionEvent actionEvent)
152 viewMapping_actionPerformed();
156 viewMenu = new JMenu();
157 viewMenu.setText(MessageManager.getString("action.view"));
159 chainMenu = new JMenu();
160 chainMenu.setText(MessageManager.getString("action.show_chain"));
162 fitToWindow = new JMenuItem();
163 fitToWindow.setText(MessageManager.getString("label.fit_to_window"));
164 fitToWindow.addActionListener(new ActionListener()
167 public void actionPerformed(ActionEvent actionEvent)
169 getBinding().focusView();
173 JMenu helpMenu = new JMenu();
174 helpMenu.setText(MessageManager.getString("action.help"));
175 helpItem = new JMenuItem();
176 helpItem.addActionListener(new ActionListener()
179 public void actionPerformed(ActionEvent actionEvent)
181 showHelp_actionPerformed();
184 alignStructs = new JMenuItem();
185 alignStructs.setText(
186 MessageManager.getString("label.superpose_structures"));
187 alignStructs.addActionListener(new ActionListener()
190 public void actionPerformed(ActionEvent actionEvent)
192 alignStructsWithAllAlignPanels();
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);
206 viewMenu.add(chainMenu);
207 helpMenu.add(helpItem);
209 menuBar.add(fileMenu);
210 menuBar.add(viewMenu);
211 menuBar.add(colourMenu);
212 menuBar.add(viewerActionMenu);
213 menuBar.add(helpMenu);
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);
222 protected void fitToWindow_actionPerformed()
224 getBinding().focusView();
227 protected void highlightSelection_actionPerformed()
231 protected void viewerColour_actionPerformed()
235 protected abstract String alignStructsWithAllAlignPanels();
237 public void pdbFile_actionPerformed()
242 public void makePDBImage(TYPE imageType)
247 public void viewMapping_actionPerformed()
252 public void seqColour_actionPerformed()
257 public void chainColour_actionPerformed()
262 public void chargeColour_actionPerformed()
267 public void background_actionPerformed()
272 public void showHelp_actionPerformed()
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
282 protected void setChainsToHide()
284 List<String> chains = new ArrayList<>();
285 for (int i = 0; i < chainMenu.getItemCount(); i++)
287 JMenuItem menuItem = chainMenu.getItem(i);
288 if (menuItem instanceof JCheckBoxMenuItem)
290 JCheckBoxMenuItem item = (JCheckBoxMenuItem) menuItem;
291 if (!item.isSelected())
293 chains.add(item.getText().split(" ")[0]);
297 getBinding().setChainsToHide(chains);