From a2926674d871f1e06760b677c4cc3b171d72902b Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Fri, 14 Feb 2020 09:22:52 +0000 Subject: [PATCH] JAL-3187 alternative solution - gather feature settings for CDS/Protein as tabs in a window managed by SplitFrame --- src/jalview/api/SplitContainerI.java | 17 +++ .../controller/FeatureSettingsControllerGuiI.java | 6 + src/jalview/gui/FeatureSettings.java | 151 +++++++++++-------- src/jalview/gui/SplitFrame.java | 152 +++++++++++++++++++- 4 files changed, 266 insertions(+), 60 deletions(-) diff --git a/src/jalview/api/SplitContainerI.java b/src/jalview/api/SplitContainerI.java index 2a09475..66d8bd1 100644 --- a/src/jalview/api/SplitContainerI.java +++ b/src/jalview/api/SplitContainerI.java @@ -20,6 +20,7 @@ */ package jalview.api; +import jalview.controller.FeatureSettingsControllerGuiI; import jalview.datamodel.AlignmentI; /** @@ -65,4 +66,20 @@ public interface SplitContainerI AlignViewControllerGuiI getComplementAlignFrame( AlignViewControllerGuiI alignFrame); + /** + * add the given UI to the splitframe's feature settings UI holder + * + * @param featureSettings + * @return + */ + void addFeatureSettingsUI( + FeatureSettingsControllerGuiI featureSettings); + + /** + * Request to close all feature settings originating from a particular panel + * + * @param featureSettings + */ + void closeFeatureSettings(FeatureSettingsControllerI featureSettings); + } diff --git a/src/jalview/controller/FeatureSettingsControllerGuiI.java b/src/jalview/controller/FeatureSettingsControllerGuiI.java index 728612e..758df93 100644 --- a/src/jalview/controller/FeatureSettingsControllerGuiI.java +++ b/src/jalview/controller/FeatureSettingsControllerGuiI.java @@ -20,7 +20,13 @@ */ package jalview.controller; +import jalview.api.AlignViewControllerGuiI; + public interface FeatureSettingsControllerGuiI { + AlignViewControllerGuiI getAlignframe(); + + void closeFeatureSettings(); + } diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index 8ce090f..4dca630 100644 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -24,7 +24,9 @@ import jalview.api.AlignViewControllerGuiI; import jalview.api.AlignViewportI; import jalview.api.FeatureColourI; import jalview.api.FeatureSettingsControllerI; +import jalview.api.SplitContainerI; import jalview.api.ViewStyleI; +import jalview.controller.FeatureSettingsControllerGuiI; import jalview.datamodel.AlignmentI; import jalview.datamodel.SequenceI; import jalview.datamodel.features.FeatureMatcher; @@ -48,6 +50,7 @@ import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; +import java.awt.FlowLayout; import java.awt.Font; import java.awt.Graphics; import java.awt.GridLayout; @@ -112,7 +115,7 @@ import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamReader; public class FeatureSettings extends JPanel - implements FeatureSettingsControllerI + implements FeatureSettingsControllerI, FeatureSettingsControllerGuiI { private static final String SEQUENCE_FEATURE_COLOURS = MessageManager .getString("label.sequence_feature_colours"); @@ -356,7 +359,6 @@ public class FeatureSettings extends JPanel } discoverAllFeatureData(); - final PropertyChangeListener change; final FeatureSettings fs = this; fr.addPropertyChangeListener(change = new PropertyChangeListener() { @@ -373,37 +375,60 @@ public class FeatureSettings extends JPanel } }); - - frame = new JInternalFrame(); - frame.setContentPane(this); - if (Platform.isAMac()) + SplitContainerI splitframe = af.getSplitViewContainer(); + if (splitframe != null) { - Desktop.addInternalFrame(frame, - MessageManager.getString("label.sequence_feature_settings"), - 600, 480); + frame = null; // keeps eclipse happy + splitframe.addFeatureSettingsUI(this); } else { - Desktop.addInternalFrame(frame, - MessageManager.getString("label.sequence_feature_settings"), - 600, 450); - } - frame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT)); + frame = new JInternalFrame(); + frame.setContentPane(this); + if (Platform.isAMac()) + { + Desktop.addInternalFrame(frame, + MessageManager.getString("label.sequence_feature_settings"), + 600, 480); + } + else + { + Desktop.addInternalFrame(frame, + MessageManager.getString("label.sequence_feature_settings"), + 600, 450); + } + frame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT)); - frame.addInternalFrameListener( - new javax.swing.event.InternalFrameAdapter() - { - @Override - public void internalFrameClosed( - javax.swing.event.InternalFrameEvent evt) + frame.addInternalFrameListener( + new javax.swing.event.InternalFrameAdapter() { - fr.removePropertyChangeListener(change); - }; - }); - frame.setLayer(JLayeredPane.PALETTE_LAYER); + @Override + public void internalFrameClosed( + javax.swing.event.InternalFrameEvent evt) + { + closeFeatureSettings(); + }; + }); + frame.setLayer(JLayeredPane.PALETTE_LAYER); + } inConstruction = false; } + PropertyChangeListener change; + + @Override + public AlignViewControllerGuiI getAlignframe() + { + return af; + } + + @Override + public void closeFeatureSettings() + { + fr.removePropertyChangeListener(change); + change = null; + } + protected void popupSort(final int rowSelected, final String type, final Object typeCol, final Map minmax, int x, int y) @@ -1083,7 +1108,16 @@ public class FeatureSettings extends JPanel { try { - frame.setClosed(true); + if (frame != null) + { + frame.setClosed(true); + } + else + { + SplitContainerI sc = af.getSplitViewContainer(); + sc.closeFeatureSettings(this); + af.featureSettings = null; + } } catch (Exception exe) { } @@ -1310,38 +1344,38 @@ public class FeatureSettings extends JPanel refreshDisplay(); } }); - JButton viewComplementSettings = new JButton(MessageManager - .formatMessage("label.show_linked_feature_settings", - nucleotide - ? MessageManager.getString("label.protein") - .toLowerCase() - : "CDS")); - viewComplementSettings.addActionListener(new ActionListener() - { - - @Override - public void actionPerformed(ActionEvent e) - { - AlignViewControllerGuiI complAf = af.getSplitViewContainer() - .getComplementAlignFrame(af); - FeatureSettings complFeatureSettings = (FeatureSettings) complAf - .getFeatureSettingsUI(); - if (complFeatureSettings != null) - { - complFeatureSettings.frame.setVisible(true); - try - { - complFeatureSettings.frame.setSelected(true); - return; - } catch (Exception q) - { - } - } - { - complAf.showFeatureSettingsUI(); - } - } - }); + // JButton viewComplementSettings = new JButton(MessageManager + // .formatMessage("label.show_linked_feature_settings", + // nucleotide + // ? MessageManager.getString("label.protein") + // .toLowerCase() + // : "CDS")); + // viewComplementSettings.addActionListener(new ActionListener() + // { + // + // @Override + // public void actionPerformed(ActionEvent e) + // { + // AlignViewControllerGuiI complAf = af.getSplitViewContainer() + // .getComplementAlignFrame(af); + // FeatureSettings complFeatureSettings = (FeatureSettings) complAf + // .getFeatureSettingsUI(); + // if (complFeatureSettings != null) + // { + // complFeatureSettings.frame.setVisible(true); + // try + // { + // complFeatureSettings.frame.setSelected(true); + // return; + // } catch (Exception q) + // { + // } + // } + // { + // complAf.showFeatureSettingsUI(); + // } + // } + // }); JPanel lowerPanel = new JPanel(new GridLayout(1, 2)); bigPanel.add(lowerPanel, BorderLayout.SOUTH); @@ -1359,10 +1393,9 @@ public class FeatureSettings extends JPanel transPanelLeft.add(transparency); if (hasComplement) { - JPanel cp = new JPanel(new GridLayout(3, 2)); + JPanel cp = new JPanel(new FlowLayout(FlowLayout.LEFT)); cp.add(showComplement); cp.add(showComplementOnTop); - cp.add(viewComplementSettings); transPanelLeft.add(cp); } lowerPanel.add(transPanelLeft); diff --git a/src/jalview/gui/SplitFrame.java b/src/jalview/gui/SplitFrame.java index 396e3b3..6d5bd34 100644 --- a/src/jalview/gui/SplitFrame.java +++ b/src/jalview/gui/SplitFrame.java @@ -21,17 +21,23 @@ package jalview.gui; import jalview.api.AlignViewControllerGuiI; +import jalview.api.FeatureSettingsControllerI; import jalview.api.SplitContainerI; +import jalview.controller.FeatureSettingsControllerGuiI; import jalview.datamodel.AlignmentI; import jalview.jbgui.GAlignFrame; import jalview.jbgui.GSplitFrame; import jalview.structure.StructureSelectionManager; +import jalview.util.MessageManager; import jalview.util.Platform; import jalview.viewmodel.AlignmentViewport; import java.awt.Component; +import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; @@ -45,7 +51,10 @@ import javax.swing.InputMap; import javax.swing.JComponent; import javax.swing.JDesktopPane; import javax.swing.JInternalFrame; +import javax.swing.JLayeredPane; import javax.swing.JMenuItem; +import javax.swing.JPanel; +import javax.swing.JTabbedPane; import javax.swing.KeyStroke; import javax.swing.event.InternalFrameAdapter; import javax.swing.event.InternalFrameEvent; @@ -76,6 +85,13 @@ public class SplitFrame extends GSplitFrame implements SplitContainerI private static final long serialVersionUID = 1L; + /** + * geometry for Feature Settings Holder + */ + private static final int FS_MIN_WIDTH = 400; + + private static final int FS_MIN_HEIGHT = 400; + public SplitFrame(GAlignFrame top, GAlignFrame bottom) { super(top, bottom); @@ -832,4 +848,138 @@ public class SplitFrame extends GSplitFrame implements SplitContainerI } super.setSelected(selected); } -} + + /** + * holds the frame for feature settings, so Protein and DNA tabs can be managed + */ + JInternalFrame featureSettingsUI; + + JTabbedPane featureSettingsPanels; + + @Override + public void addFeatureSettingsUI( + FeatureSettingsControllerGuiI featureSettings) + { + boolean showInternalFrame = false; + if (featureSettingsUI == null) + { + showInternalFrame = true; + featureSettingsPanels = new JTabbedPane(); + featureSettingsUI = new JInternalFrame( + "Feature Settings for CDS and Protein Views"); + featureSettingsPanels.setOpaque(true); + featureSettingsUI.setContentPane(featureSettingsPanels); + JPanel dummyDNA = new JPanel(),dummyProtein=new JPanel(); + FocusListener fl1 = new FocusListener() + { + + @Override + public void focusLost(FocusEvent e) + { + // TODO Auto-generated method stub + + } + + @Override + public void focusGained(FocusEvent e) + { + int tab = featureSettingsPanels.getSelectedIndex(); + getAlignFrames().get(tab).showFeatureSettingsUI(); + } + }; + dummyDNA.addFocusListener(fl1); + dummyProtein.addFocusListener(fl1); + + featureSettingsPanels.addTab("CDS", dummyDNA); + featureSettingsPanels.addTab("Protein", dummyProtein); + } + if (featureSettingsPanels + .indexOfTabComponent((Component) featureSettings) > -1) + { + // just show the feature settings ! + featureSettingsPanels + .setSelectedComponent((Component) featureSettings); + return; + } + // otherwise replace the dummy tab with the given feature settings + int pos = getAlignFrames().indexOf(featureSettings.getAlignframe()); + // if pos==-1 then alignFrame isn't managed by this splitframe + if (pos == 0) + { + featureSettingsPanels.removeTabAt(0); + featureSettingsPanels.insertTab("CDS", null, + (Component) featureSettings, "Feature Settings for DNA CDS", + 0); + } + if (pos == 1) + { + featureSettingsPanels.removeTabAt(1); + featureSettingsPanels.insertTab("Protein", null, + (Component) featureSettings, "Feature Settings for Protein", + 1); + } + featureSettingsPanels.setSelectedComponent((Component) featureSettings); + if (showInternalFrame) + { + if (Platform.isAMac()) + { + Desktop.addInternalFrame(featureSettingsUI, + MessageManager.getString( + "Feature Settings for CDS and Protein Views"), + 600, 480); + } + else + { + Desktop.addInternalFrame(featureSettingsUI, + MessageManager.getString( + "Feature Settings for CDS and Protein Views"), + 600, 450); + } + featureSettingsUI + .setMinimumSize(new Dimension(FS_MIN_WIDTH, FS_MIN_HEIGHT)); + + featureSettingsUI.addInternalFrameListener( + new javax.swing.event.InternalFrameAdapter() + { + @Override + public void internalFrameClosed( + javax.swing.event.InternalFrameEvent evt) + { + for (int tab = 0; tab < featureSettingsPanels + .getTabCount();) + { + FeatureSettingsControllerGuiI fsettings = (FeatureSettingsControllerGuiI) featureSettingsPanels + .getTabComponentAt(tab); + if (fsettings != null) + { + featureSettingsPanels.removeTabAt(tab); + fsettings.closeFeatureSettings(); + } + else + { + tab++; + } + } + featureSettingsPanels = null; + }; + }); + featureSettingsUI.setLayer(JLayeredPane.PALETTE_LAYER); + } + } + + @Override + public void closeFeatureSettings( + FeatureSettingsControllerI featureSettings) + { + if (featureSettingsUI != null) + { + try + { + featureSettingsUI.setClosed(true); + } catch (Exception x) + { + } + featureSettingsUI = null; + } + } +} \ No newline at end of file -- 1.7.10.2