From ce82f92de3f0740dd0aeded014bf79862e8a5101 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 4 Jun 2018 09:50:22 +0100 Subject: [PATCH] JAL-3010 action handler for toggle of 'Apply to sub-types'; i18n --- resources/lang/Messages.properties | 4 +- resources/lang/Messages_es.properties | 4 ++ src/jalview/gui/FeatureTypeSettings.java | 72 ++++++++++++++++++++++-------- 3 files changed, 61 insertions(+), 19 deletions(-) diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 6d38b37..dd66340 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -1365,4 +1365,6 @@ label.most_polymer_residues = Most Polymer Residues label.cached_structures = Cached Structures label.free_text_search = Free Text Search label.summary_view = Summary View -label.summary_view_tip = Show only top level ontology terms \ No newline at end of file +label.summary_view_tip = Show only top level ontology terms +label.apply_to_subtypes = Apply changes also to sub-types of ''{0}'' +label.apply_also_to = Apply also to: \ No newline at end of file diff --git a/resources/lang/Messages_es.properties b/resources/lang/Messages_es.properties index 6d0eb67..58c0d88 100644 --- a/resources/lang/Messages_es.properties +++ b/resources/lang/Messages_es.properties @@ -1365,3 +1365,7 @@ label.most_bound_molecules = M label.most_polymer_residues = Más Residuos de Polímeros label.cached_structures = Estructuras en Caché label.free_text_search = Búsqueda de texto libre +label.summary_view = Vista Resumida +label.summary_view_tip = Mostrar solo términos de ontología de nivel mayor +label.apply_to_subtypes = Aplicar cambios también a subtipos de ''{0}'' +label.apply_also_to = Aplicar también a: \ No newline at end of file diff --git a/src/jalview/gui/FeatureTypeSettings.java b/src/jalview/gui/FeatureTypeSettings.java index b938b7a..c71d878 100644 --- a/src/jalview/gui/FeatureTypeSettings.java +++ b/src/jalview/gui/FeatureTypeSettings.java @@ -219,10 +219,12 @@ public class FeatureTypeSettings extends JalviewDialog private final List subTypes; /* - * if selected, colour settings are also applied to any - * feature sub-types in the Sequence Ontology + * if true, filter or colour settings are also applied to + * any feature sub-types in the Sequence Ontology */ - private JCheckBox applyToSubtypes; + private boolean applyFiltersToSubtypes; + + private boolean applyColourToSubtypes; /** * Constructor @@ -781,7 +783,8 @@ public class FeatureTypeSettings extends JalviewDialog */ if (!subTypes.isEmpty()) { - colourByPanel.add(initSubtypesPanel()); + applyColourToSubtypes = false; + colourByPanel.add(initSubtypesPanel(false)); } /* @@ -887,14 +890,37 @@ public class FeatureTypeSettings extends JalviewDialog * * @return */ - protected JPanel initSubtypesPanel() + protected JPanel initSubtypesPanel(final boolean forFilters) { JPanel toSubtypes = new JPanel(new FlowLayout(FlowLayout.LEFT)); toSubtypes.setBackground(Color.WHITE); - applyToSubtypes = new JCheckBox( - "Apply changes also to sub-types of " + featureType); - applyToSubtypes.setToolTipText(getSubtypesTooltip()); - toSubtypes.add(applyToSubtypes); + JCheckBox applyToSubtypesCB = new JCheckBox(MessageManager + .formatMessage("label.apply_to_subtypes", featureType)); + applyToSubtypesCB.setToolTipText(getSubtypesTooltip()); + applyToSubtypesCB.addActionListener(new ActionListener() + { + /* + * reset and reapply settings on toggle of checkbox + */ + @Override + public void actionPerformed(ActionEvent e) + { + if (forFilters) + { + applyFiltersToSubtypes = applyToSubtypesCB.isSelected(); + restoreOriginalFilters(); + filtersChanged(); + } + else + { + applyColourToSubtypes = applyToSubtypesCB.isSelected(); + restoreOriginalColours(); + colourChanged(true); + } + } + }); + toSubtypes.add(applyToSubtypesCB); + return toSubtypes; } @@ -940,7 +966,7 @@ public class FeatureTypeSettings extends JalviewDialog * save the colour, and set on subtypes if selected */ fr.setColour(featureType, acg); - if (applyToSubtypes.isSelected()) + if (applyColourToSubtypes) { for (String child : subTypes) { @@ -1093,17 +1119,26 @@ public class FeatureTypeSettings extends JalviewDialog @Override public void cancelPressed() { - for (Entry entry : originalColours.entrySet()) - { - fr.setColour(entry.getKey(), entry.getValue()); - } + restoreOriginalColours(); + restoreOriginalFilters(); + ap.paintAlignment(true, true); + } + + protected void restoreOriginalFilters() + { for (Entry entry : originalFilters .entrySet()) { fr.setFeatureFilter(entry.getKey(), entry.getValue()); } + } - ap.paintAlignment(true, true); + protected void restoreOriginalColours() + { + for (Entry entry : originalColours.entrySet()) + { + fr.setColour(entry.getKey(), entry.getValue()); + } } /** @@ -1253,7 +1288,8 @@ public class FeatureTypeSettings extends JalviewDialog */ if (!subTypes.isEmpty()) { - outerPanel.add(initSubtypesPanel()); + applyFiltersToSubtypes = false; + outerPanel.add(initSubtypesPanel(true)); } JPanel filtersPanel = new JPanel(); @@ -1323,7 +1359,7 @@ public class FeatureTypeSettings extends JalviewDialog protected String getSubtypesTooltip() { StringBuilder sb = new StringBuilder(20 * subTypes.size()); - sb.append("Apply settings also to" + ":"); // todo i18n + sb.append(MessageManager.getString("label.apply_also_to")); for (String child : subTypes) { sb.append("
").append(child); @@ -1876,7 +1912,7 @@ public class FeatureTypeSettings extends JalviewDialog * (note this might now be an empty filter with no conditions) */ fr.setFeatureFilter(featureType, combined.isEmpty() ? null : combined); - if (applyToSubtypes.isSelected()) + if (applyFiltersToSubtypes) { for (String child : subTypes) { -- 1.7.10.2