From 24dbffc7cf9323f550875f5c6fe7df025aebbaf1 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Thu, 20 Feb 2020 14:11:06 +0000 Subject: [PATCH] JAL-3187 individual feature settings panel has revert/apply when embedded in a tab, and split frame feature settings has an OK and Cancel. --- .../controller/FeatureSettingsControllerGuiI.java | 6 ++ src/jalview/gui/FeatureSettings.java | 91 ++++++++++++++------ src/jalview/gui/SplitFrame.java | 53 +++++++++++- 3 files changed, 124 insertions(+), 26 deletions(-) diff --git a/src/jalview/controller/FeatureSettingsControllerGuiI.java b/src/jalview/controller/FeatureSettingsControllerGuiI.java index 237e944..92571bc 100644 --- a/src/jalview/controller/FeatureSettingsControllerGuiI.java +++ b/src/jalview/controller/FeatureSettingsControllerGuiI.java @@ -29,4 +29,10 @@ public interface FeatureSettingsControllerGuiI void featureSettings_isClosed(); + /** + * undo any changes made to feature settings whilst the dialog has been visible, + * since the last 'apply' + */ + void revert(); + } diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index 82f6acf..0ab288c 100644 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -82,6 +82,7 @@ import java.util.Map; import java.util.Set; import javax.help.HelpSetException; +import javax.swing.AbstractButton; import javax.swing.AbstractCellEditor; import javax.swing.BorderFactory; import javax.swing.Icon; @@ -183,6 +184,16 @@ public class FeatureSettings extends JPanel */ Map typeWidth = null; + private void storeOriginalSettings() + { + // save transparency for restore on Cancel + originalTransparency = fr.getTransparency(); + int originalTransparencyAsPercent = (int) (originalTransparency * 100); + transparency.setMaximum(100 - originalTransparencyAsPercent); + + originalFilters = new HashMap<>(fr.getFeatureFilters()); // shallow copy + originalViewStyle = new ViewStyle(af.viewport.getViewStyle()); + } /** * Constructor * @@ -192,15 +203,7 @@ public class FeatureSettings extends JPanel { this.af = alignFrame; fr = af.getFeatureRenderer(); - - // save transparency for restore on Cancel - originalTransparency = fr.getTransparency(); - int originalTransparencyAsPercent = (int) (originalTransparency * 100); - transparency.setMaximum(100 - originalTransparencyAsPercent); - - originalFilters = new HashMap<>(fr.getFeatureFilters()); // shallow copy - originalViewStyle = new ViewStyle(af.viewport.getViewStyle()); - + storeOriginalSettings(); try { jbInit(); @@ -435,6 +438,17 @@ public class FeatureSettings extends JPanel PropertyChangeListener change; + private JCheckBox showComplementOnTop; + + private AbstractButton showComplement; + + private void updateComplementButtons() + { + showComplement.setSelected(af.getViewport().isShowComplementFeatures()); + showComplementOnTop + .setSelected(af.getViewport().isShowComplementFeaturesOnTop()); + } + @Override public AlignViewControllerGuiI getAlignframe() { @@ -1205,6 +1219,9 @@ public class FeatureSettings extends JPanel { this.setLayout(new BorderLayout()); + final boolean hasComplement = af.getViewport() + .getCodingComplement() != null; + JPanel settingsPane = new JPanel(); settingsPane.setLayout(new BorderLayout()); @@ -1277,30 +1294,47 @@ public class FeatureSettings extends JPanel } } }); - - JButton cancel = new JButton(MessageManager.getString("action.cancel")); + // Cancel for a SplitFrame should just revert changes to the currently displayed + // settings. May want to do this for either or both - so need a splitview + // feature settings cancel/OK. + JButton cancel = new JButton(MessageManager + .getString(hasComplement ? "action.revert" : "action.cancel")); + cancel.setToolTipText(MessageManager.getString(hasComplement + ? "action.undo_changes_to_feature_settings" + : "action.undo_changes_to_feature_settings_and_close_the_dialog")); cancel.setFont(JvSwingUtils.getLabelFont()); + // TODO: disable cancel until current settings are different cancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - fr.setTransparency(originalTransparency); - fr.setFeatureFilters(originalFilters); - updateFeatureRenderer(originalData); - af.getViewport().setViewStyle(originalViewStyle); - close(); + revert(); + if (!hasComplement) + { + close(); + } } }); - - JButton ok = new JButton(MessageManager.getString("action.ok")); + // Cancel for the whole dialog should cancel both CDS and Protein. + // OK for an individual feature settings just applies changes, but dialog + // remains open + JButton ok = new JButton(MessageManager + .getString(hasComplement ? "action.apply" : "action.ok")); ok.setFont(JvSwingUtils.getLabelFont()); ok.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - close(); + if (!hasComplement) + { + close(); + } + else + { + storeOriginalSettings(); + } } }); @@ -1354,8 +1388,7 @@ public class FeatureSettings extends JPanel ? MessageManager.getString("label.protein") .toLowerCase() : "CDS"); - JCheckBox showComplement = new JCheckBox(text); - showComplement.setSelected(af.getViewport().isShowComplementFeatures()); + showComplement = new JCheckBox(text); showComplement.addActionListener(new ActionListener() { @Override @@ -1367,10 +1400,8 @@ public class FeatureSettings extends JPanel } }); - JCheckBox showComplementOnTop = new JCheckBox( + showComplementOnTop = new JCheckBox( MessageManager.getString("label.on_top")); - showComplementOnTop - .setSelected(af.getViewport().isShowComplementFeaturesOnTop()); showComplementOnTop.addActionListener(new ActionListener() { @Override @@ -1423,7 +1454,6 @@ public class FeatureSettings extends JPanel transbuttons.add(sortByDens); transbuttons.add(help); - boolean hasComplement = af.getViewport().getCodingComplement() != null; JPanel transPanelLeft = new JPanel( new GridLayout(hasComplement ? 4 : 2, 1)); transPanelLeft.add(new JLabel(" Colour transparency" + ":")); @@ -2014,6 +2044,17 @@ public class FeatureSettings extends JPanel } return frame != null && !frame.isClosed(); } + + @Override + public void revert() + { + fr.setTransparency(originalTransparency); + fr.setFeatureFilters(originalFilters); + updateFeatureRenderer(originalData); + af.getViewport().setViewStyle(originalViewStyle); + updateComplementButtons(); + refreshDisplay(); + } } class FeatureIcon implements Icon diff --git a/src/jalview/gui/SplitFrame.java b/src/jalview/gui/SplitFrame.java index 948b73b..8e5c2de 100644 --- a/src/jalview/gui/SplitFrame.java +++ b/src/jalview/gui/SplitFrame.java @@ -32,6 +32,7 @@ import jalview.util.MessageManager; import jalview.util.Platform; import jalview.viewmodel.AlignmentViewport; +import java.awt.BorderLayout; import java.awt.Component; import java.awt.Dimension; import java.awt.event.ActionEvent; @@ -48,6 +49,7 @@ import java.util.Map.Entry; import javax.swing.AbstractAction; import javax.swing.InputMap; +import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JDesktopPane; import javax.swing.JInternalFrame; @@ -868,7 +870,56 @@ public class SplitFrame extends GSplitFrame implements SplitContainerI featureSettingsUI = new JInternalFrame(MessageManager.getString( "label.sequence_feature_settings_for_CDS_and_Protein")); featureSettingsPanels.setOpaque(true); - featureSettingsUI.setContentPane(featureSettingsPanels); + + JPanel dialog = new JPanel(); + dialog.setOpaque(true); + dialog.setLayout(new BorderLayout()); + dialog.add(featureSettingsPanels, BorderLayout.CENTER); + JPanel buttons = new JPanel(); + JButton ok = new JButton(MessageManager.getString("action.ok")); + ok.addActionListener(new ActionListener() + { + + @Override + public void actionPerformed(ActionEvent e) + { + try + { + featureSettingsUI.setClosed(true); + } catch (PropertyVetoException pv) + { + pv.printStackTrace(); + } + } + }); + JButton cancel = new JButton( + MessageManager.getString("action.cancel")); + cancel.addActionListener(new ActionListener() + { + + @Override + public void actionPerformed(ActionEvent e) + { + try + { + for (Component fspanel : featureSettingsPanels.getComponents()) + { + if (fspanel instanceof FeatureSettingsControllerGuiI) + { + ((FeatureSettingsControllerGuiI) fspanel).revert(); + } + } + featureSettingsUI.setClosed(true); + } catch (Exception pv) + { + pv.printStackTrace(); + } + } + }); + buttons.add(ok); + buttons.add(cancel); + dialog.add(buttons, BorderLayout.SOUTH); + featureSettingsUI.setContentPane(dialog); createDummyTabs(); } if (featureSettingsPanels -- 1.7.10.2