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 jalview.api.AlignViewportI;
24 import jalview.api.AlignViewControllerGuiI;
25 import jalview.api.FeatureSettingsControllerI;
26 import jalview.api.SplitContainerI;
27 import jalview.controller.FeatureSettingsControllerGuiI;
28 import jalview.datamodel.AlignmentI;
29 import jalview.jbgui.GAlignFrame;
30 import jalview.jbgui.GSplitFrame;
31 import jalview.structure.StructureSelectionManager;
32 import jalview.util.MessageManager;
33 import jalview.util.Platform;
34 import jalview.viewmodel.AlignmentViewport;
35 import java.awt.BorderLayout;
36 import java.awt.Component;
37 import java.awt.Dimension;
38 import java.awt.event.ActionEvent;
39 import java.awt.event.ActionListener;
40 import java.awt.event.KeyAdapter;
41 import java.awt.event.KeyEvent;
42 import java.awt.event.KeyListener;
43 import java.beans.PropertyVetoException;
44 import java.util.Arrays;
45 import java.util.List;
46 import java.util.Map.Entry;
48 import javax.swing.AbstractAction;
49 import javax.swing.InputMap;
50 import javax.swing.JButton;
51 import javax.swing.JComponent;
52 import javax.swing.JDesktopPane;
53 import javax.swing.JInternalFrame;
54 import javax.swing.JLayeredPane;
55 import javax.swing.JMenuItem;
56 import javax.swing.JPanel;
57 import javax.swing.JTabbedPane;
58 import javax.swing.KeyStroke;
59 import javax.swing.event.ChangeEvent;
60 import javax.swing.event.ChangeListener;
61 import javax.swing.event.InternalFrameAdapter;
62 import javax.swing.event.InternalFrameEvent;
66 * An internal frame on the desktop that hosts a horizontally split view of
67 * linked DNA and Protein alignments. Additional views can be created in linked
68 * pairs, expanded to separate split frames, or regathered into a single frame.
70 * (Some) operations on each alignment are automatically mirrored on the other.
71 * These include mouseover (highlighting), sequence and column selection,
72 * sequence ordering and sorting, and grouping, colouring and sorting by tree.
77 public class SplitFrame extends GSplitFrame implements SplitContainerI
79 private static final int WINDOWS_INSETS_WIDTH = 28; // tbc
81 private static final int MAC_INSETS_WIDTH = 28;
83 private static final int WINDOWS_INSETS_HEIGHT = 50; // tbc
85 private static final int MAC_INSETS_HEIGHT = 50;
87 private static final int DESKTOP_DECORATORS_HEIGHT = 65;
89 private static final long serialVersionUID = 1L;
92 * geometry for Feature Settings Holder
94 private static final int FS_MIN_WIDTH = 400;
96 private static final int FS_MIN_HEIGHT = 400;
98 public SplitFrame(GAlignFrame top, GAlignFrame bottom)
105 * Initialise this frame.
107 protected void init()
109 getTopFrame().setSplitFrame(this);
110 getBottomFrame().setSplitFrame(this);
111 getTopFrame().setVisible(true);
112 getBottomFrame().setVisible(true);
114 ((AlignFrame) getTopFrame()).getViewport().setCodingComplement(
115 ((AlignFrame) getBottomFrame()).getViewport());
118 * estimate width and height of SplitFrame; this.getInsets() doesn't seem to
119 * give the full additional size (a few pixels short)
121 int widthFudge = Platform.isAMacAndNotJS() ? MAC_INSETS_WIDTH
122 : WINDOWS_INSETS_WIDTH;
123 int heightFudge = Platform.isAMacAndNotJS() ? MAC_INSETS_HEIGHT
124 : WINDOWS_INSETS_HEIGHT;
125 int width = ((AlignFrame) getTopFrame()).getWidth() + widthFudge;
126 int height = ((AlignFrame) getTopFrame()).getHeight()
127 + ((AlignFrame) getBottomFrame()).getHeight() + DIVIDER_SIZE
129 height = fitHeightToDesktop(height);
130 setSize(width, height);
134 addCloseFrameListener();
140 addCommandListeners();
144 * Reduce the height if too large to fit in the Desktop. Also adjust the
145 * divider location in proportion.
149 * @return original or reduced height
151 public int fitHeightToDesktop(int height)
153 // allow about 65 pixels for Desktop decorators on Windows
155 int newHeight = Math.min(height,
156 Desktop.getInstance().getHeight() - DESKTOP_DECORATORS_HEIGHT);
157 if (newHeight != height)
159 int oldDividerLocation = getDividerLocation();
160 setDividerLocation(oldDividerLocation * newHeight / height);
166 * Set the top and bottom frames to listen to each others Commands (e.g. Edit,
169 protected void addCommandListeners()
171 // TODO if CommandListener is only ever 1:1 for complementary views,
172 // may change broadcast pattern to direct messaging (more efficient)
173 final StructureSelectionManager ssm = StructureSelectionManager
174 .getStructureSelectionManager(Desktop.getInstance());
175 ssm.addCommandListener(((AlignFrame) getTopFrame()).getViewport());
176 ssm.addCommandListener(((AlignFrame) getBottomFrame()).getViewport());
180 * Do any tweaking and twerking of the layout wanted.
182 public void adjustLayout()
184 final AlignViewport topViewport = ((AlignFrame) getTopFrame()).viewport;
185 final AlignViewport bottomViewport = ((AlignFrame) getBottomFrame()).viewport;
188 * Ensure sequence ids are the same width so sequences line up
190 int w1 = topViewport.getIdWidth();
191 int w2 = bottomViewport.getIdWidth();
192 int w3 = Math.max(w1, w2);
193 topViewport.setIdWidth(w3);
194 bottomViewport.setIdWidth(w3);
197 * Scale protein to either 1 or 3 times character width of dna
199 final AlignmentI topAlignment = topViewport.getAlignment();
200 final AlignmentI bottomAlignment = bottomViewport.getAlignment();
201 AlignmentViewport cdna = topAlignment.isNucleotide() ? topViewport
202 : (bottomAlignment.isNucleotide() ? bottomViewport : null);
203 AlignmentViewport protein = !topAlignment.isNucleotide() ? topViewport
204 : (!bottomAlignment.isNucleotide() ? bottomViewport : null);
205 if (protein != null && cdna != null)
207 int scale = protein.isScaleProteinAsCdna() ? 3 : 1;
208 protein.setCharWidth(scale * cdna.getViewStyle().getCharWidth());
213 * Adjusts the divider for a sensible split of the real estate (for example,
214 * when many transcripts are shown with a single protein). This should only be
215 * called after the split pane has been laid out (made visible) so it has a
216 * height. The aim is to avoid unnecessary vertical scroll bars, while
217 * ensuring that at least 2 sequences are visible in each panel.
219 * Once laid out, the user may choose to customise as they wish, so this
220 * method is not called again after the initial layout.
222 protected void adjustInitialLayout()
224 AlignFrame topFrame = (AlignFrame) getTopFrame();
225 AlignFrame bottomFrame = (AlignFrame) getBottomFrame();
228 * recompute layout of top and bottom panels to reflect their
229 * actual (rather than requested) height
231 topFrame.alignPanel.adjustAnnotationHeight();
232 bottomFrame.alignPanel.adjustAnnotationHeight();
234 final AlignViewportI topViewport = topFrame.viewport;
235 final AlignViewportI bottomViewport = bottomFrame.viewport;
236 final AlignmentI topAlignment = topViewport.getAlignment();
237 final AlignmentI bottomAlignment = bottomViewport.getAlignment();
238 boolean topAnnotations = topViewport.isShowAnnotation();
239 boolean bottomAnnotations = bottomViewport.isShowAnnotation();
240 // TODO need number of visible sequences here, not #sequences - how?
241 int topCount = topAlignment.getHeight();
242 int bottomCount = bottomAlignment.getHeight();
243 int topCharHeight = topViewport.getViewStyle().getCharHeight();
244 int bottomCharHeight = bottomViewport.getViewStyle().getCharHeight();
247 * calculate the minimum ratio that leaves at least the height
248 * of two sequences (after rounding) visible in the top panel
250 int topPanelHeight = topFrame.getHeight();
251 int bottomPanelHeight = bottomFrame.getHeight();
252 int topSequencesHeight = topFrame.alignPanel.getSeqPanel().seqCanvas
254 int topPanelMinHeight = topPanelHeight
255 - Math.max(0, topSequencesHeight - 3 * topCharHeight);
256 double totalHeight = (double) topPanelHeight + bottomPanelHeight;
257 double minRatio = topPanelMinHeight / totalHeight;
260 * calculate the maximum ratio that leaves at least the height
261 * of two sequences (after rounding) visible in the bottom panel
263 int bottomSequencesHeight = bottomFrame.alignPanel.getSeqPanel().seqCanvas
265 int bottomPanelMinHeight = bottomPanelHeight
266 - Math.max(0, bottomSequencesHeight - 3 * bottomCharHeight);
267 double maxRatio = (totalHeight - bottomPanelMinHeight) / totalHeight;
270 * estimate ratio of (topFrameContent / bottomFrameContent)
272 int insets = Platform.isAMacAndNotJS() ? MAC_INSETS_HEIGHT
273 : WINDOWS_INSETS_HEIGHT;
274 // allow 3 'rows' for scale, scrollbar, status bar
275 int topHeight = insets + (3 + topCount) * topCharHeight
276 + (topAnnotations ? topViewport.calcPanelHeight() : 0);
277 int bottomHeight = insets + (3 + bottomCount) * bottomCharHeight
278 + (bottomAnnotations ? bottomViewport.calcPanelHeight() : 0);
279 double ratio = ((double) topHeight)
280 / (double) (topHeight + bottomHeight);
283 * limit ratio to avoid concealing all sequences
285 ratio = Math.min(ratio, maxRatio);
286 ratio = Math.max(ratio, minRatio);
287 setRelativeDividerLocation(ratio);
291 * Add a listener to tidy up when the frame is closed.
293 protected void addCloseFrameListener()
295 addInternalFrameListener(new InternalFrameAdapter()
298 public void internalFrameClosed(InternalFrameEvent evt)
306 * Add a key listener that delegates to whichever split component the mouse is
307 * in (or does nothing if neither).
309 protected void addKeyListener()
311 addKeyListener(new KeyAdapter()
315 public void keyPressed(KeyEvent e)
317 AlignFrame af = (AlignFrame) getFrameAtMouse();
320 * Intercept and override any keys here if wanted.
322 if (!overrideKey(e, af))
326 for (KeyListener kl : af.getKeyListeners())
335 public void keyReleased(KeyEvent e)
337 Component c = getFrameAtMouse();
340 for (KeyListener kl : c.getKeyListeners())
351 * Returns true if the key event is overriden and actioned (or ignored) here,
352 * else returns false, indicating it should be delegated to the AlignFrame's
355 * We can't handle Cmd-Key combinations here, instead this is done by
356 * overriding key bindings.
358 * @see addKeyOverrides
363 protected boolean overrideKey(KeyEvent e, AlignFrame af)
365 boolean actioned = false;
366 int keyCode = e.getKeyCode();
369 case KeyEvent.VK_DOWN:
370 if (e.isAltDown() || !af.viewport.cursorMode)
373 * Key down (or Alt-key-down in cursor mode) - move selected sequences
375 ((AlignFrame) getTopFrame()).moveSelectedSequences(false);
376 ((AlignFrame) getBottomFrame()).moveSelectedSequences(false);
382 if (e.isAltDown() || !af.viewport.cursorMode)
385 * Key up (or Alt-key-up in cursor mode) - move selected sequences
387 ((AlignFrame) getTopFrame()).moveSelectedSequences(true);
388 ((AlignFrame) getBottomFrame()).moveSelectedSequences(true);
399 * Set key bindings (recommended for Swing over key accelerators).
401 private void addKeyBindings()
403 overrideDelegatedKeyBindings();
405 overrideImplementedKeyBindings();
409 * Override key bindings with alternative action methods implemented in this
412 protected void overrideImplementedKeyBindings()
417 overrideExpandViews();
418 overrideGatherViews();
422 * Replace Cmd-W close view action with our version.
424 protected void overrideCloseView()
426 AbstractAction action;
428 * Ctrl-W / Cmd-W - close view or window
430 KeyStroke key_cmdW = KeyStroke.getKeyStroke(KeyEvent.VK_W,
431 Platform.SHORTCUT_KEY_MASK, false);
432 action = new AbstractAction()
435 public void actionPerformed(ActionEvent e)
437 closeView_actionPerformed();
440 overrideKeyBinding(key_cmdW, action);
444 * Replace Cmd-T new view action with our version.
446 protected void overrideNewView()
449 * Ctrl-T / Cmd-T open new view
451 KeyStroke key_cmdT = KeyStroke.getKeyStroke(KeyEvent.VK_T,
452 Platform.SHORTCUT_KEY_MASK, false);
453 AbstractAction action = new AbstractAction()
456 public void actionPerformed(ActionEvent e)
458 newView_actionPerformed();
461 overrideKeyBinding(key_cmdT, action);
465 * For now, delegates key events to the corresponding key accelerator for the
466 * AlignFrame that the mouse is in. Hopefully can be simplified in future if
467 * AlignFrame is changed to use key bindings rather than accelerators.
469 protected void overrideDelegatedKeyBindings()
471 if (getTopFrame() instanceof AlignFrame)
474 * Get all accelerator keys in the top frame (the bottom should be
475 * identical) and override each one.
477 for (Entry<KeyStroke, JMenuItem> acc : ((AlignFrame) getTopFrame())
478 .getAccelerators().entrySet())
480 overrideKeyBinding(acc);
486 * Overrides an AlignFrame key accelerator with our version which delegates to
487 * the action listener in whichever frame has the mouse (and does nothing if
492 private void overrideKeyBinding(Entry<KeyStroke, JMenuItem> acc)
494 final KeyStroke ks = acc.getKey();
495 InputMap inputMap = this.getInputMap(JComponent.WHEN_FOCUSED);
496 inputMap.put(ks, ks);
497 this.getActionMap().put(ks, new AbstractAction()
500 public void actionPerformed(ActionEvent e)
502 Component c = getFrameAtMouse();
503 if (c != null && c instanceof AlignFrame)
505 for (ActionListener a : ((AlignFrame) c).getAccelerators().get(ks)
506 .getActionListeners())
508 a.actionPerformed(null);
516 * Replace an accelerator key's action with the specified action.
520 protected void overrideKeyBinding(KeyStroke ks, AbstractAction action)
522 this.getActionMap().put(ks, action);
523 overrideMenuItem(ks, action);
527 * Create and link new views (with matching names) in both panes.
529 * Note this is _not_ multiple tabs, each hosting a split pane view, rather it
530 * is a single split pane with each split holding multiple tabs which are
533 * TODO implement instead with a tabbed holder in the SplitView, each tab
534 * holding a single JSplitPane. Would avoid a duplicated tab, at the cost of
535 * some additional coding.
537 protected void newView_actionPerformed()
539 AlignFrame topFrame = (AlignFrame) getTopFrame();
540 AlignFrame bottomFrame = (AlignFrame) getBottomFrame();
541 final boolean scaleProteinAsCdna = topFrame.viewport
542 .isScaleProteinAsCdna();
544 AlignmentPanel newTopPanel = topFrame.newView(null, true);
545 AlignmentPanel newBottomPanel = bottomFrame.newView(null, true);
548 * This currently (for the first new view only) leaves the top pane on tab 0
549 * but the bottom on tab 1. This results from 'setInitialTabVisible' echoing
550 * from the bottom back to the first frame. Next line is a fudge to work
551 * around this. TODO find a better way.
553 if (topFrame.getTabIndex() != bottomFrame.getTabIndex())
555 topFrame.setDisplayedView(newTopPanel);
558 newBottomPanel.av.setViewName(newTopPanel.av.getViewName());
559 newTopPanel.av.setCodingComplement(newBottomPanel.av);
562 * These lines can be removed once scaleProteinAsCdna is added to element
563 * Viewport in jalview.xsd, as Jalview2XML.copyAlignPanel will then take
566 newTopPanel.av.setScaleProteinAsCdna(scaleProteinAsCdna);
567 newBottomPanel.av.setScaleProteinAsCdna(scaleProteinAsCdna);
570 * Line up id labels etc
574 final StructureSelectionManager ssm = StructureSelectionManager
575 .getStructureSelectionManager(Desktop.getInstance());
576 ssm.addCommandListener(newTopPanel.av);
577 ssm.addCommandListener(newBottomPanel.av);
581 * Close the currently selected view in both panes. If there is only one view,
582 * close this split frame.
584 protected void closeView_actionPerformed()
586 int viewCount = ((AlignFrame) getTopFrame()).getAlignPanels().size();
593 AlignmentPanel topPanel = ((AlignFrame) getTopFrame()).alignPanel;
594 AlignmentPanel bottomPanel = ((AlignFrame) getBottomFrame()).alignPanel;
596 ((AlignFrame) getTopFrame()).closeView(topPanel);
597 ((AlignFrame) getBottomFrame()).closeView(bottomPanel);
602 * Close child frames and this split frame.
606 ((AlignFrame) getTopFrame()).closeMenuItem_actionPerformed(true);
607 ((AlignFrame) getBottomFrame()).closeMenuItem_actionPerformed(true);
610 this.setClosed(true);
611 } catch (PropertyVetoException e)
618 * Replace AlignFrame 'expand views' action with SplitFrame version.
620 protected void overrideExpandViews()
622 KeyStroke key_X = KeyStroke.getKeyStroke(KeyEvent.VK_X, 0, false);
623 AbstractAction action = new AbstractAction()
626 public void actionPerformed(ActionEvent e)
628 expandViews_actionPerformed();
631 overrideMenuItem(key_X, action);
635 * Replace AlignFrame 'gather views' action with SplitFrame version.
637 protected void overrideGatherViews()
639 KeyStroke key_G = KeyStroke.getKeyStroke(KeyEvent.VK_G, 0, false);
640 AbstractAction action = new AbstractAction()
643 public void actionPerformed(ActionEvent e)
645 gatherViews_actionPerformed();
648 overrideMenuItem(key_G, action);
652 * Override the menu action associated with the keystroke in the child frames,
653 * replacing it with the given action.
658 private void overrideMenuItem(KeyStroke ks, AbstractAction action)
660 overrideMenuItem(ks, action, getTopFrame());
661 overrideMenuItem(ks, action, getBottomFrame());
665 * Override the menu action associated with the keystroke in one child frame,
666 * replacing it with the given action. Mwahahahaha.
672 private void overrideMenuItem(KeyStroke key, final AbstractAction action,
675 if (comp instanceof AlignFrame)
677 JMenuItem mi = ((AlignFrame) comp).getAccelerators().get(key);
680 for (ActionListener al : mi.getActionListeners())
682 mi.removeActionListener(al);
684 mi.addActionListener(new ActionListener()
687 public void actionPerformed(ActionEvent e)
689 action.actionPerformed(e);
697 * Expand any multiple views (which are always in pairs) into separate split
700 protected void expandViews_actionPerformed()
702 Desktop.getInstance().explodeViews(this);
706 * Gather any other SplitFrame views of this alignment back in as multiple
707 * (pairs of) views in this SplitFrame.
709 protected void gatherViews_actionPerformed()
711 Desktop.getInstance().gatherViews(this);
715 * Returns the alignment in the complementary frame to the one given.
718 public AlignmentI getComplement(Object alignFrame)
720 if (alignFrame == this.getTopFrame())
722 return ((AlignFrame) getBottomFrame()).viewport.getAlignment();
724 else if (alignFrame == this.getBottomFrame())
726 return ((AlignFrame) getTopFrame()).viewport.getAlignment();
732 * Returns the title of the complementary frame to the one given.
735 public String getComplementTitle(Object alignFrame)
737 if (alignFrame == this.getTopFrame())
739 return ((AlignFrame) getBottomFrame()).getTitle();
741 else if (alignFrame == this.getBottomFrame())
743 return ((AlignFrame) getTopFrame()).getTitle();
749 * Set the 'other half' to hidden / revealed.
752 public void setComplementVisible(Object alignFrame, boolean show)
755 * Hiding the AlignPanel suppresses unnecessary repaints
757 if (alignFrame == getTopFrame())
759 ((AlignFrame) getBottomFrame()).alignPanel.setVisible(show);
761 else if (alignFrame == getBottomFrame())
763 ((AlignFrame) getTopFrame()).alignPanel.setVisible(show);
765 super.setComplementVisible(alignFrame, show);
769 * return the AlignFrames held by this container
771 * @return { Top alignFrame (Usually CDS), Bottom AlignFrame (Usually
774 public List<AlignFrame> getAlignFrames()
777 .asList(new AlignFrame[]
778 { (AlignFrame) getTopFrame(), (AlignFrame) getBottomFrame() });
782 public AlignFrame getComplementAlignFrame(
783 AlignViewControllerGuiI alignFrame)
785 if (getTopFrame() == alignFrame)
787 return (AlignFrame) getBottomFrame();
789 if (getBottomFrame() == alignFrame)
791 return (AlignFrame) getTopFrame();
793 // we didn't know anything about this frame...
798 * Replace Cmd-F Find action with our version. This is necessary because the
799 * 'default' Finder searches in the first AlignFrame it finds. We need it to
800 * search in the half of the SplitFrame that has the mouse.
802 protected void overrideFind()
805 * Ctrl-F / Cmd-F open Finder dialog, 'focused' on the right alignment
807 KeyStroke key_cmdF = KeyStroke.getKeyStroke(KeyEvent.VK_F,
808 Platform.SHORTCUT_KEY_MASK, false);
809 AbstractAction action = new AbstractAction()
812 public void actionPerformed(ActionEvent e)
814 Component c = getFrameAtMouse();
815 if (c != null && c instanceof AlignFrame)
817 AlignFrame af = (AlignFrame) c;
818 boolean dna = af.getViewport().getAlignment().isNucleotide();
819 String scope = MessageManager.getString("label.in") + " "
820 + (dna ? MessageManager.getString("label.nucleotide")
821 : MessageManager.getString("label.protein"));
822 new Finder(af.alignPanel, true, scope);
826 overrideKeyBinding(key_cmdF, action);
830 * Override to do nothing if triggered from one of the child frames
833 public void setSelected(boolean selected) throws PropertyVetoException
835 JDesktopPane desktopPane = getDesktopPane();
836 JInternalFrame fr = desktopPane == null ? null
837 : desktopPane.getSelectedFrame();
838 if (fr == getTopFrame() || fr == getBottomFrame())
841 * patch for JAL-3288 (deselecting top/bottom frame closes popup menu);
842 * it may be possible to remove this method in future
843 * if the underlying Java behaviour changes
851 super.setSelected(selected);
855 * holds the frame for feature settings, so Protein and DNA tabs can be managed
857 JInternalFrame featureSettingsUI;
859 JTabbedPane featureSettingsPanels;
862 public void addFeatureSettingsUI(
863 FeatureSettingsControllerGuiI featureSettings)
865 boolean showInternalFrame = false;
866 if (featureSettingsUI == null || featureSettingsPanels == null)
868 showInternalFrame = true;
869 featureSettingsPanels = new JTabbedPane();
870 featureSettingsPanels.addChangeListener(new ChangeListener()
874 public void stateChanged(ChangeEvent e)
876 if (e.getSource() != featureSettingsPanels
877 || featureSettingsUI == null
878 || featureSettingsUI.isClosed()
879 || !featureSettingsUI.isVisible())
881 // not our tabbed pane
884 int tab = featureSettingsPanels.getSelectedIndex();
885 if (tab < 0 || featureSettingsPanels
886 .getSelectedComponent() instanceof FeatureSettingsControllerGuiI)
888 // no tab selected or already showing a feature settings GUI
891 getAlignFrames().get(tab).showFeatureSettingsUI();
894 featureSettingsUI = new JInternalFrame(MessageManager.getString(
895 "label.sequence_feature_settings_for_CDS_and_Protein"));
896 featureSettingsPanels.setOpaque(true);
898 JPanel dialog = new JPanel();
899 dialog.setOpaque(true);
900 dialog.setLayout(new BorderLayout());
901 dialog.add(featureSettingsPanels, BorderLayout.CENTER);
902 JPanel buttons = new JPanel();
903 JButton ok = new JButton(MessageManager.getString("action.ok"));
904 ok.addActionListener(new ActionListener()
908 public void actionPerformed(ActionEvent e)
912 featureSettingsUI.setClosed(true);
913 } catch (PropertyVetoException pv)
915 pv.printStackTrace();
919 JButton cancel = new JButton(
920 MessageManager.getString("action.cancel"));
921 cancel.addActionListener(new ActionListener()
925 public void actionPerformed(ActionEvent e)
929 for (Component fspanel : featureSettingsPanels.getComponents())
931 if (fspanel instanceof FeatureSettingsControllerGuiI)
933 ((FeatureSettingsControllerGuiI) fspanel).revert();
936 featureSettingsUI.setClosed(true);
937 } catch (Exception pv)
939 pv.printStackTrace();
945 dialog.add(buttons, BorderLayout.SOUTH);
946 featureSettingsUI.setContentPane(dialog);
949 if (featureSettingsPanels
950 .indexOfTabComponent((Component) featureSettings) > -1)
952 // just show the feature settings !
953 featureSettingsPanels
954 .setSelectedComponent((Component) featureSettings);
957 // otherwise replace the dummy tab with the given feature settings
958 int pos = getAlignFrames().indexOf(featureSettings.getAlignframe());
959 // if pos==-1 then alignFrame isn't managed by this splitframe
962 featureSettingsPanels.removeTabAt(0);
963 featureSettingsPanels.insertTab(tabName[0], null,
964 (Component) featureSettings,
965 MessageManager.formatMessage(
966 "label.sequence_feature_settings_for", tabName[0]),
971 featureSettingsPanels.removeTabAt(1);
972 featureSettingsPanels.insertTab(tabName[1], null,
973 (Component) featureSettings,
974 MessageManager.formatMessage(
975 "label.sequence_feature_settings_for", tabName[1]),
978 featureSettingsPanels.setSelectedComponent((Component) featureSettings);
980 // TODO: JAL-3535 - construct a feature settings title including names of
981 // currently selected CDS and Protein names
983 if (showInternalFrame)
985 if (Platform.isAMacAndNotJS())
987 Desktop.addInternalFrame(featureSettingsUI,
988 MessageManager.getString(
989 "label.sequence_feature_settings_for_CDS_and_Protein"),
994 Desktop.addInternalFrame(featureSettingsUI,
995 MessageManager.getString(
996 "label.sequence_feature_settings_for_CDS_and_Protein"),
1000 .setMinimumSize(new Dimension(FS_MIN_WIDTH, FS_MIN_HEIGHT));
1002 featureSettingsUI.addInternalFrameListener(
1003 new javax.swing.event.InternalFrameAdapter()
1006 public void internalFrameClosed(
1007 javax.swing.event.InternalFrameEvent evt)
1009 for (int tab = 0; tab < featureSettingsPanels
1012 FeatureSettingsControllerGuiI fsettings = (FeatureSettingsControllerGuiI) featureSettingsPanels
1013 .getTabComponentAt(tab);
1014 if (fsettings != null)
1016 featureSettingsPanels.removeTabAt(tab);
1017 fsettings.featureSettings_isClosed();
1024 featureSettingsPanels = null;
1025 featureSettingsUI = null;
1028 featureSettingsUI.setLayer(JLayeredPane.PALETTE_LAYER);
1033 * tab names for feature settings
1035 private String[] tabName = new String[] {
1036 MessageManager.getString("label.CDS"),
1037 MessageManager.getString("label.protein") };
1040 * create placeholder tabs which materialise the feature settings for a given
1041 * view. Also reinitialises any tabs containing stale feature settings
1043 private void createDummyTabs()
1045 for (int tabIndex = 0; tabIndex < 2; tabIndex++)
1047 JPanel dummyTab = new JPanel();
1048 featureSettingsPanels.addTab(tabName[tabIndex], dummyTab);
1052 private void replaceWithDummyTab(FeatureSettingsControllerI toClose)
1054 Component dummyTab = null;
1055 for (int tabIndex = 0; tabIndex < 2; tabIndex++)
1057 if (featureSettingsPanels.getTabCount() > tabIndex)
1059 dummyTab = featureSettingsPanels.getTabComponentAt(tabIndex);
1060 if (dummyTab instanceof FeatureSettingsControllerGuiI
1061 && !dummyTab.isVisible())
1063 featureSettingsPanels.removeTabAt(tabIndex);
1064 // close the feature Settings tab
1065 ((FeatureSettingsControllerGuiI) dummyTab)
1066 .featureSettings_isClosed();
1067 // create a dummy tab in its place
1068 dummyTab = new JPanel();
1069 featureSettingsPanels.insertTab(tabName[tabIndex], null, dummyTab,
1070 MessageManager.formatMessage(
1071 "label.sequence_feature_settings_for",
1080 public void closeFeatureSettings(
1081 FeatureSettingsControllerI featureSettings,
1082 boolean closeContainingFrame)
1084 if (featureSettingsUI != null)
1086 if (closeContainingFrame)
1090 featureSettingsUI.setClosed(true);
1091 } catch (Exception x)
1094 featureSettingsUI = null;
1098 replaceWithDummyTab(featureSettings);
1104 public boolean isFeatureSettingsOpen()
1106 return featureSettingsUI != null && !featureSettingsUI.isClosed();