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.
23 import java.awt.BorderLayout;
24 import java.awt.Component;
25 import java.awt.Dimension;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28 import java.awt.event.KeyAdapter;
29 import java.awt.event.KeyEvent;
30 import java.awt.event.KeyListener;
31 import java.beans.PropertyVetoException;
32 import java.util.Arrays;
33 import java.util.List;
34 import java.util.Map.Entry;
36 import javax.swing.AbstractAction;
37 import javax.swing.InputMap;
38 import javax.swing.JButton;
39 import javax.swing.JComponent;
40 import javax.swing.JDesktopPane;
41 import javax.swing.JInternalFrame;
42 import javax.swing.JLayeredPane;
43 import javax.swing.JMenuItem;
44 import javax.swing.JPanel;
45 import javax.swing.JTabbedPane;
46 import javax.swing.KeyStroke;
47 import javax.swing.event.ChangeEvent;
48 import javax.swing.event.ChangeListener;
49 import javax.swing.event.InternalFrameAdapter;
50 import javax.swing.event.InternalFrameEvent;
52 import jalview.api.AlignViewControllerGuiI;
53 import jalview.api.FeatureSettingsControllerI;
54 import jalview.api.SplitContainerI;
55 import jalview.controller.FeatureSettingsControllerGuiI;
56 import jalview.datamodel.AlignmentI;
57 import jalview.jbgui.GAlignFrame;
58 import jalview.jbgui.GSplitFrame;
59 import jalview.structure.StructureSelectionManager;
60 import jalview.util.MessageManager;
61 import jalview.util.Platform;
62 import jalview.viewmodel.AlignmentViewport;
65 * An internal frame on the desktop that hosts a horizontally split view of
66 * linked DNA and Protein alignments. Additional views can be created in linked
67 * pairs, expanded to separate split frames, or regathered into a single frame.
69 * (Some) operations on each alignment are automatically mirrored on the other.
70 * These include mouseover (highlighting), sequence and column selection,
71 * sequence ordering and sorting, and grouping, colouring and sorting by tree.
76 public class SplitFrame extends GSplitFrame implements SplitContainerI
78 private static final int WINDOWS_INSETS_WIDTH = 28; // tbc
80 private static final int MAC_INSETS_WIDTH = 28;
82 private static final int WINDOWS_INSETS_HEIGHT = 50; // tbc
84 private static final int MAC_INSETS_HEIGHT = 50;
86 private static final int DESKTOP_DECORATORS_HEIGHT = 65;
88 private static final long serialVersionUID = 1L;
91 * geometry for Feature Settings Holder
93 private static final int FS_MIN_WIDTH = 400;
95 private static final int FS_MIN_HEIGHT = 400;
97 public SplitFrame(GAlignFrame top, GAlignFrame bottom)
104 * Initialise this frame.
106 protected void init()
108 getTopFrame().setSplitFrame(this);
109 getBottomFrame().setSplitFrame(this);
110 getTopFrame().setVisible(true);
111 getBottomFrame().setVisible(true);
113 ((AlignFrame) getTopFrame()).getViewport().setCodingComplement(
114 ((AlignFrame) getBottomFrame()).getViewport());
117 * estimate width and height of SplitFrame; this.getInsets() doesn't seem to
118 * give the full additional size (a few pixels short)
120 int widthFudge = Platform.isAMacAndNotJS() ? MAC_INSETS_WIDTH
121 : WINDOWS_INSETS_WIDTH;
122 int heightFudge = Platform.isAMacAndNotJS() ? MAC_INSETS_HEIGHT
123 : WINDOWS_INSETS_HEIGHT;
124 int width = ((AlignFrame) getTopFrame()).getWidth() + widthFudge;
125 int height = ((AlignFrame) getTopFrame()).getHeight()
126 + ((AlignFrame) getBottomFrame()).getHeight() + DIVIDER_SIZE
128 height = fitHeightToDesktop(height);
129 setSize(width, height);
133 addCloseFrameListener();
139 addCommandListeners();
143 * Reduce the height if too large to fit in the Desktop. Also adjust the
144 * divider location in proportion.
148 * @return original or reduced height
150 public int fitHeightToDesktop(int height)
152 // allow about 65 pixels for Desktop decorators on Windows
154 int newHeight = Math.min(height,
155 Desktop.instance.getHeight() - DESKTOP_DECORATORS_HEIGHT);
156 if (newHeight != height)
158 int oldDividerLocation = getDividerLocation();
159 setDividerLocation(oldDividerLocation * newHeight / height);
165 * Set the top and bottom frames to listen to each others Commands (e.g. Edit,
168 protected void addCommandListeners()
170 // TODO if CommandListener is only ever 1:1 for complementary views,
171 // may change broadcast pattern to direct messaging (more efficient)
172 final StructureSelectionManager ssm = StructureSelectionManager
173 .getStructureSelectionManager(Desktop.instance);
174 ssm.addCommandListener(((AlignFrame) getTopFrame()).getViewport());
175 ssm.addCommandListener(((AlignFrame) getBottomFrame()).getViewport());
179 * Do any tweaking and twerking of the layout wanted.
181 public void adjustLayout()
183 final AlignViewport topViewport = ((AlignFrame) getTopFrame()).viewport;
184 final AlignViewport bottomViewport = ((AlignFrame) getBottomFrame()).viewport;
187 * Ensure sequence ids are the same width so sequences line up
189 int w1 = topViewport.getIdWidth();
190 int w2 = bottomViewport.getIdWidth();
191 int w3 = Math.max(w1, w2);
192 topViewport.setIdWidth(w3);
193 bottomViewport.setIdWidth(w3);
196 * Scale protein to either 1 or 3 times character width of dna
198 final AlignmentI topAlignment = topViewport.getAlignment();
199 final AlignmentI bottomAlignment = bottomViewport.getAlignment();
200 AlignmentViewport cdna = topAlignment.isNucleotide() ? topViewport
201 : (bottomAlignment.isNucleotide() ? bottomViewport : null);
202 AlignmentViewport protein = !topAlignment.isNucleotide() ? topViewport
203 : (!bottomAlignment.isNucleotide() ? bottomViewport : null);
204 if (protein != null && cdna != null)
206 int scale = protein.isScaleProteinAsCdna() ? 3 : 1;
207 protein.setCharWidth(scale * cdna.getViewStyle().getCharWidth());
212 * Adjusts the divider for a sensible split of the real estate (for example,
213 * when many transcripts are shown with a single protein). This should only be
214 * called after the split pane has been laid out (made visible) so it has a
215 * height. The aim is to avoid unnecessary vertical scroll bars, while
216 * ensuring that at least 2 sequences are visible in each panel.
218 * Once laid out, the user may choose to customise as they wish, so this
219 * method is not called again after the initial layout.
221 protected void adjustInitialLayout()
223 AlignFrame topFrame = (AlignFrame) getTopFrame();
224 AlignFrame bottomFrame = (AlignFrame) getBottomFrame();
227 * recompute layout of top and bottom panels to reflect their
228 * actual (rather than requested) height
230 topFrame.alignPanel.adjustAnnotationHeight();
231 bottomFrame.alignPanel.adjustAnnotationHeight();
233 final AlignViewport topViewport = topFrame.viewport;
234 final AlignViewport bottomViewport = bottomFrame.viewport;
235 final AlignmentI topAlignment = topViewport.getAlignment();
236 final AlignmentI bottomAlignment = bottomViewport.getAlignment();
237 boolean topAnnotations = topViewport.isShowAnnotation();
238 boolean bottomAnnotations = bottomViewport.isShowAnnotation();
239 // TODO need number of visible sequences here, not #sequences - how?
240 int topCount = topAlignment.getHeight();
241 int bottomCount = bottomAlignment.getHeight();
242 int topCharHeight = topViewport.getViewStyle().getCharHeight();
243 int bottomCharHeight = bottomViewport.getViewStyle().getCharHeight();
246 * calculate the minimum ratio that leaves at least the height
247 * of two sequences (after rounding) visible in the top panel
249 int topPanelHeight = topFrame.getHeight();
250 int bottomPanelHeight = bottomFrame.getHeight();
251 int topSequencesHeight = topFrame.alignPanel.getSeqPanel().seqCanvas
253 int topPanelMinHeight = topPanelHeight
254 - Math.max(0, topSequencesHeight - 3 * topCharHeight);
255 double totalHeight = (double) topPanelHeight + bottomPanelHeight;
256 double minRatio = topPanelMinHeight / totalHeight;
259 * calculate the maximum ratio that leaves at least the height
260 * of two sequences (after rounding) visible in the bottom panel
262 int bottomSequencesHeight = bottomFrame.alignPanel.getSeqPanel().seqCanvas
264 int bottomPanelMinHeight = bottomPanelHeight
265 - Math.max(0, bottomSequencesHeight - 3 * bottomCharHeight);
266 double maxRatio = (totalHeight - bottomPanelMinHeight) / totalHeight;
269 * estimate ratio of (topFrameContent / bottomFrameContent)
271 int insets = Platform.isAMacAndNotJS() ? MAC_INSETS_HEIGHT
272 : WINDOWS_INSETS_HEIGHT;
273 // allow 3 'rows' for scale, scrollbar, status bar
274 int topHeight = insets + (3 + topCount) * topCharHeight
275 + (topAnnotations ? topViewport.calcPanelHeight() : 0);
276 int bottomHeight = insets + (3 + bottomCount) * bottomCharHeight
277 + (bottomAnnotations ? bottomViewport.calcPanelHeight() : 0);
278 double ratio = ((double) topHeight)
279 / (double) (topHeight + bottomHeight);
282 * limit ratio to avoid concealing all sequences
284 ratio = Math.min(ratio, maxRatio);
285 ratio = Math.max(ratio, minRatio);
286 setRelativeDividerLocation(ratio);
290 * Add a listener to tidy up when the frame is closed.
292 protected void addCloseFrameListener()
294 addInternalFrameListener(new InternalFrameAdapter()
297 public void internalFrameClosed(InternalFrameEvent evt)
305 * Add a key listener that delegates to whichever split component the mouse is
306 * in (or does nothing if neither).
308 protected void addKeyListener()
310 addKeyListener(new KeyAdapter()
314 public void keyPressed(KeyEvent e)
316 AlignFrame af = (AlignFrame) getFrameAtMouse();
319 * Intercept and override any keys here if wanted.
321 if (!overrideKey(e, af))
325 for (KeyListener kl : af.getKeyListeners())
334 public void keyReleased(KeyEvent e)
336 Component c = getFrameAtMouse();
339 for (KeyListener kl : c.getKeyListeners())
350 * Returns true if the key event is overriden and actioned (or ignored) here,
351 * else returns false, indicating it should be delegated to the AlignFrame's
354 * We can't handle Cmd-Key combinations here, instead this is done by
355 * overriding key bindings.
357 * @see addKeyOverrides
362 protected boolean overrideKey(KeyEvent e, AlignFrame af)
364 boolean actioned = false;
365 int keyCode = e.getKeyCode();
368 case KeyEvent.VK_DOWN:
369 if (e.isAltDown() || !af.viewport.cursorMode)
372 * Key down (or Alt-key-down in cursor mode) - move selected sequences
374 ((AlignFrame) getTopFrame()).moveSelectedSequences(false);
375 ((AlignFrame) getBottomFrame()).moveSelectedSequences(false);
381 if (e.isAltDown() || !af.viewport.cursorMode)
384 * Key up (or Alt-key-up in cursor mode) - move selected sequences
386 ((AlignFrame) getTopFrame()).moveSelectedSequences(true);
387 ((AlignFrame) getBottomFrame()).moveSelectedSequences(true);
398 * Set key bindings (recommended for Swing over key accelerators).
400 private void addKeyBindings()
402 overrideDelegatedKeyBindings();
404 overrideImplementedKeyBindings();
408 * Override key bindings with alternative action methods implemented in this
411 protected void overrideImplementedKeyBindings()
416 overrideExpandViews();
417 overrideGatherViews();
421 * Replace Cmd-W close view action with our version.
423 protected void overrideCloseView()
425 AbstractAction action;
427 * Ctrl-W / Cmd-W - close view or window
429 KeyStroke key_cmdW = KeyStroke.getKeyStroke(KeyEvent.VK_W,
430 jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false);
431 action = new AbstractAction()
434 public void actionPerformed(ActionEvent e)
436 closeView_actionPerformed();
439 overrideKeyBinding(key_cmdW, action);
443 * Replace Cmd-T new view action with our version.
445 protected void overrideNewView()
448 * Ctrl-T / Cmd-T open new view
450 KeyStroke key_cmdT = KeyStroke.getKeyStroke(KeyEvent.VK_T,
451 jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false);
452 AbstractAction action = new AbstractAction()
455 public void actionPerformed(ActionEvent e)
457 newView_actionPerformed();
460 overrideKeyBinding(key_cmdT, action);
464 * For now, delegates key events to the corresponding key accelerator for the
465 * AlignFrame that the mouse is in. Hopefully can be simplified in future if
466 * AlignFrame is changed to use key bindings rather than accelerators.
468 protected void overrideDelegatedKeyBindings()
470 if (getTopFrame() instanceof AlignFrame)
473 * Get all accelerator keys in the top frame (the bottom should be
474 * identical) and override each one.
476 for (Entry<KeyStroke, JMenuItem> acc : ((AlignFrame) getTopFrame())
477 .getAccelerators().entrySet())
479 overrideKeyBinding(acc);
485 * Overrides an AlignFrame key accelerator with our version which delegates to
486 * the action listener in whichever frame has the mouse (and does nothing if
491 private void overrideKeyBinding(Entry<KeyStroke, JMenuItem> acc)
493 final KeyStroke ks = acc.getKey();
494 InputMap inputMap = this.getInputMap(JComponent.WHEN_FOCUSED);
495 inputMap.put(ks, ks);
496 this.getActionMap().put(ks, new AbstractAction()
499 public void actionPerformed(ActionEvent e)
501 Component c = getFrameAtMouse();
502 if (c != null && c instanceof AlignFrame)
504 for (ActionListener a : ((AlignFrame) c).getAccelerators().get(ks)
505 .getActionListeners())
507 a.actionPerformed(null);
515 * Replace an accelerator key's action with the specified action.
519 protected void overrideKeyBinding(KeyStroke ks, AbstractAction action)
521 this.getActionMap().put(ks, action);
522 overrideMenuItem(ks, action);
526 * Create and link new views (with matching names) in both panes.
528 * Note this is _not_ multiple tabs, each hosting a split pane view, rather it
529 * is a single split pane with each split holding multiple tabs which are
532 * TODO implement instead with a tabbed holder in the SplitView, each tab
533 * holding a single JSplitPane. Would avoid a duplicated tab, at the cost of
534 * some additional coding.
536 protected void newView_actionPerformed()
538 AlignFrame topFrame = (AlignFrame) getTopFrame();
539 AlignFrame bottomFrame = (AlignFrame) getBottomFrame();
540 final boolean scaleProteinAsCdna = topFrame.viewport
541 .isScaleProteinAsCdna();
543 AlignmentPanel newTopPanel = topFrame.newView(null, true);
544 AlignmentPanel newBottomPanel = bottomFrame.newView(null, true);
547 * This currently (for the first new view only) leaves the top pane on tab 0
548 * but the bottom on tab 1. This results from 'setInitialTabVisible' echoing
549 * from the bottom back to the first frame. Next line is a fudge to work
550 * around this. TODO find a better way.
552 if (topFrame.getTabIndex() != bottomFrame.getTabIndex())
554 topFrame.setDisplayedView(newTopPanel);
557 newBottomPanel.av.setViewName(newTopPanel.av.getViewName());
558 newTopPanel.av.setCodingComplement(newBottomPanel.av);
561 * These lines can be removed once scaleProteinAsCdna is added to element
562 * Viewport in jalview.xsd, as Jalview2XML.copyAlignPanel will then take
565 newTopPanel.av.setScaleProteinAsCdna(scaleProteinAsCdna);
566 newBottomPanel.av.setScaleProteinAsCdna(scaleProteinAsCdna);
569 * Line up id labels etc
573 final StructureSelectionManager ssm = StructureSelectionManager
574 .getStructureSelectionManager(Desktop.instance);
575 ssm.addCommandListener(newTopPanel.av);
576 ssm.addCommandListener(newBottomPanel.av);
580 * Close the currently selected view in both panes. If there is only one view,
581 * close this split frame.
583 protected void closeView_actionPerformed()
585 int viewCount = ((AlignFrame) getTopFrame()).getAlignPanels().size();
592 AlignmentPanel topPanel = ((AlignFrame) getTopFrame()).alignPanel;
593 AlignmentPanel bottomPanel = ((AlignFrame) getBottomFrame()).alignPanel;
595 ((AlignFrame) getTopFrame()).closeView(topPanel);
596 ((AlignFrame) getBottomFrame()).closeView(bottomPanel);
601 * Close child frames and this split frame.
605 ((AlignFrame) getTopFrame()).closeMenuItem_actionPerformed(true);
606 ((AlignFrame) getBottomFrame()).closeMenuItem_actionPerformed(true);
609 this.setClosed(true);
610 } catch (PropertyVetoException e)
617 * Replace AlignFrame 'expand views' action with SplitFrame version.
619 protected void overrideExpandViews()
621 KeyStroke key_X = KeyStroke.getKeyStroke(KeyEvent.VK_X, 0, false);
622 AbstractAction action = new AbstractAction()
625 public void actionPerformed(ActionEvent e)
627 expandViews_actionPerformed();
630 overrideMenuItem(key_X, action);
634 * Replace AlignFrame 'gather views' action with SplitFrame version.
636 protected void overrideGatherViews()
638 KeyStroke key_G = KeyStroke.getKeyStroke(KeyEvent.VK_G, 0, false);
639 AbstractAction action = new AbstractAction()
642 public void actionPerformed(ActionEvent e)
644 gatherViews_actionPerformed();
647 overrideMenuItem(key_G, action);
651 * Override the menu action associated with the keystroke in the child frames,
652 * replacing it with the given action.
657 private void overrideMenuItem(KeyStroke ks, AbstractAction action)
659 overrideMenuItem(ks, action, getTopFrame());
660 overrideMenuItem(ks, action, getBottomFrame());
664 * Override the menu action associated with the keystroke in one child frame,
665 * replacing it with the given action. Mwahahahaha.
671 private void overrideMenuItem(KeyStroke key, final AbstractAction action,
674 if (comp instanceof AlignFrame)
676 JMenuItem mi = ((AlignFrame) comp).getAccelerators().get(key);
679 for (ActionListener al : mi.getActionListeners())
681 mi.removeActionListener(al);
683 mi.addActionListener(new ActionListener()
686 public void actionPerformed(ActionEvent e)
688 action.actionPerformed(e);
696 * Expand any multiple views (which are always in pairs) into separate split
699 protected void expandViews_actionPerformed()
701 Desktop.instance.explodeViews(this);
705 * Gather any other SplitFrame views of this alignment back in as multiple
706 * (pairs of) views in this SplitFrame.
708 protected void gatherViews_actionPerformed()
710 Desktop.instance.gatherViews(this);
714 * Returns the alignment in the complementary frame to the one given.
717 public AlignmentI getComplement(Object alignFrame)
719 if (alignFrame == this.getTopFrame())
721 return ((AlignFrame) getBottomFrame()).viewport.getAlignment();
723 else if (alignFrame == this.getBottomFrame())
725 return ((AlignFrame) getTopFrame()).viewport.getAlignment();
731 * Returns the title of the complementary frame to the one given.
734 public String getComplementTitle(Object alignFrame)
736 if (alignFrame == this.getTopFrame())
738 return ((AlignFrame) getBottomFrame()).getTitle();
740 else if (alignFrame == this.getBottomFrame())
742 return ((AlignFrame) getTopFrame()).getTitle();
748 * Set the 'other half' to hidden / revealed.
751 public void setComplementVisible(Object alignFrame, boolean show)
754 * Hiding the AlignPanel suppresses unnecessary repaints
756 if (alignFrame == getTopFrame())
758 ((AlignFrame) getBottomFrame()).alignPanel.setVisible(show);
760 else if (alignFrame == getBottomFrame())
762 ((AlignFrame) getTopFrame()).alignPanel.setVisible(show);
764 super.setComplementVisible(alignFrame, show);
768 * return the AlignFrames held by this container
770 * @return { Top alignFrame (Usually CDS), Bottom AlignFrame (Usually
773 public List<AlignFrame> getAlignFrames()
776 .asList(new AlignFrame[]
777 { (AlignFrame) getTopFrame(), (AlignFrame) getBottomFrame() });
781 public AlignFrame getComplementAlignFrame(
782 AlignViewControllerGuiI alignFrame)
784 if (getTopFrame() == alignFrame)
786 return (AlignFrame) getBottomFrame();
788 if (getBottomFrame() == alignFrame)
790 return (AlignFrame) getTopFrame();
792 // we didn't know anything about this frame...
797 * Replace Cmd-F Find action with our version. This is necessary because the
798 * 'default' Finder searches in the first AlignFrame it finds. We need it to
799 * search in the half of the SplitFrame that has the mouse.
801 protected void overrideFind()
804 * Ctrl-F / Cmd-F open Finder dialog, 'focused' on the right alignment
806 KeyStroke key_cmdF = KeyStroke.getKeyStroke(KeyEvent.VK_F,
807 jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false);
808 AbstractAction action = new AbstractAction()
811 public void actionPerformed(ActionEvent e)
813 Component c = getFrameAtMouse();
814 if (c != null && c instanceof AlignFrame)
816 AlignFrame af = (AlignFrame) c;
817 new Finder(af.alignPanel);
821 overrideKeyBinding(key_cmdF, action);
825 * Override to do nothing if triggered from one of the child frames
828 public void setSelected(boolean selected) throws PropertyVetoException
830 JDesktopPane desktopPane = getDesktopPane();
831 JInternalFrame fr = desktopPane == null ? null
832 : desktopPane.getSelectedFrame();
833 if (fr == getTopFrame() || fr == getBottomFrame())
836 * patch for JAL-3288 (deselecting top/bottom frame closes popup menu);
837 * it may be possible to remove this method in future
838 * if the underlying Java behaviour changes
846 super.setSelected(selected);
850 * holds the frame for feature settings, so Protein and DNA tabs can be managed
852 JInternalFrame featureSettingsUI;
854 JTabbedPane featureSettingsPanels;
857 public void addFeatureSettingsUI(
858 FeatureSettingsControllerGuiI featureSettings)
860 boolean showInternalFrame = false;
861 if (featureSettingsUI == null || featureSettingsPanels == null)
863 showInternalFrame = true;
864 featureSettingsPanels = new JTabbedPane();
865 featureSettingsPanels.addChangeListener(new ChangeListener()
869 public void stateChanged(ChangeEvent e)
871 if (e.getSource() != featureSettingsPanels
872 || featureSettingsUI == null
873 || featureSettingsUI.isClosed()
874 || !featureSettingsUI.isVisible())
876 // not our tabbed pane
879 int tab = featureSettingsPanels.getSelectedIndex();
880 if (tab < 0 || featureSettingsPanels
881 .getSelectedComponent() instanceof FeatureSettingsControllerGuiI)
883 // no tab selected or already showing a feature settings GUI
886 getAlignFrames().get(tab).showFeatureSettingsUI();
889 featureSettingsUI = new JInternalFrame(MessageManager.getString(
890 "label.sequence_feature_settings_for_CDS_and_Protein"));
891 featureSettingsPanels.setOpaque(true);
893 JPanel dialog = new JPanel();
894 dialog.setOpaque(true);
895 dialog.setLayout(new BorderLayout());
896 dialog.add(featureSettingsPanels, BorderLayout.CENTER);
897 JPanel buttons = new JPanel();
898 JButton ok = new JButton(MessageManager.getString("action.ok"));
899 ok.addActionListener(new ActionListener()
903 public void actionPerformed(ActionEvent e)
907 featureSettingsUI.setClosed(true);
908 } catch (PropertyVetoException pv)
910 pv.printStackTrace();
914 JButton cancel = new JButton(
915 MessageManager.getString("action.cancel"));
916 cancel.addActionListener(new ActionListener()
920 public void actionPerformed(ActionEvent e)
924 for (Component fspanel : featureSettingsPanels.getComponents())
926 if (fspanel instanceof FeatureSettingsControllerGuiI)
928 ((FeatureSettingsControllerGuiI) fspanel).revert();
931 featureSettingsUI.setClosed(true);
932 } catch (Exception pv)
934 pv.printStackTrace();
940 dialog.add(buttons, BorderLayout.SOUTH);
941 featureSettingsUI.setContentPane(dialog);
944 if (featureSettingsPanels
945 .indexOfTabComponent((Component) featureSettings) > -1)
947 // just show the feature settings !
948 featureSettingsPanels
949 .setSelectedComponent((Component) featureSettings);
952 // otherwise replace the dummy tab with the given feature settings
953 int pos = getAlignFrames().indexOf(featureSettings.getAlignframe());
954 // if pos==-1 then alignFrame isn't managed by this splitframe
957 featureSettingsPanels.removeTabAt(0);
958 featureSettingsPanels.insertTab(tabName[0], null,
959 (Component) featureSettings,
960 MessageManager.formatMessage(
961 "label.sequence_feature_settings_for", tabName[0]),
966 featureSettingsPanels.removeTabAt(1);
967 featureSettingsPanels.insertTab(tabName[1], null,
968 (Component) featureSettings,
969 MessageManager.formatMessage(
970 "label.sequence_feature_settings_for", tabName[1]),
973 featureSettingsPanels.setSelectedComponent((Component) featureSettings);
975 // TODO: JAL-3535 - construct a feature settings title including names of
976 // currently selected CDS and Protein names
978 if (showInternalFrame)
980 if (Platform.isAMacAndNotJS())
982 Desktop.addInternalFrame(featureSettingsUI,
983 MessageManager.getString(
984 "label.sequence_feature_settings_for_CDS_and_Protein"),
989 Desktop.addInternalFrame(featureSettingsUI,
990 MessageManager.getString(
991 "label.sequence_feature_settings_for_CDS_and_Protein"),
995 .setMinimumSize(new Dimension(FS_MIN_WIDTH, FS_MIN_HEIGHT));
997 featureSettingsUI.addInternalFrameListener(
998 new javax.swing.event.InternalFrameAdapter()
1001 public void internalFrameClosed(
1002 javax.swing.event.InternalFrameEvent evt)
1004 for (int tab = 0; tab < featureSettingsPanels
1007 FeatureSettingsControllerGuiI fsettings = (FeatureSettingsControllerGuiI) featureSettingsPanels
1008 .getTabComponentAt(tab);
1009 if (fsettings != null)
1011 featureSettingsPanels.removeTabAt(tab);
1012 fsettings.featureSettings_isClosed();
1019 featureSettingsPanels = null;
1020 featureSettingsUI = null;
1023 featureSettingsUI.setLayer(JLayeredPane.PALETTE_LAYER);
1028 * tab names for feature settings
1030 private String[] tabName = new String[] {
1031 MessageManager.getString("label.CDS"),
1032 MessageManager.getString("label.protein") };
1035 * create placeholder tabs which materialise the feature settings for a given
1036 * view. Also reinitialises any tabs containing stale feature settings
1038 private void createDummyTabs()
1040 for (int tabIndex = 0; tabIndex < 2; tabIndex++)
1042 JPanel dummyTab = new JPanel();
1043 featureSettingsPanels.addTab(tabName[tabIndex], dummyTab);
1047 private void replaceWithDummyTab(FeatureSettingsControllerI toClose)
1049 Component dummyTab = null;
1050 for (int tabIndex = 0; tabIndex < 2; tabIndex++)
1052 if (featureSettingsPanels.getTabCount() > tabIndex)
1054 dummyTab = featureSettingsPanels.getTabComponentAt(tabIndex);
1055 if (dummyTab instanceof FeatureSettingsControllerGuiI
1056 && !dummyTab.isVisible())
1058 featureSettingsPanels.removeTabAt(tabIndex);
1059 // close the feature Settings tab
1060 ((FeatureSettingsControllerGuiI) dummyTab)
1061 .featureSettings_isClosed();
1062 // create a dummy tab in its place
1063 dummyTab = new JPanel();
1064 featureSettingsPanels.insertTab(tabName[tabIndex], null, dummyTab,
1065 MessageManager.formatMessage(
1066 "label.sequence_feature_settings_for",
1075 public void closeFeatureSettings(
1076 FeatureSettingsControllerI featureSettings,
1077 boolean closeContainingFrame)
1079 if (featureSettingsUI != null)
1081 if (closeContainingFrame)
1085 featureSettingsUI.setClosed(true);
1086 } catch (Exception x)
1089 featureSettingsUI = null;
1093 replaceWithDummyTab(featureSettings);
1099 public boolean isFeatureSettingsOpen()
1101 return featureSettingsUI != null && !featureSettingsUI.isClosed();