X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FAnnotationColumnChooser.java;h=7674de716c07744f002c1db8eff18a4e1c3fece7;hb=106a3890f956e2aa7780b2985f4326655912a558;hp=36f8a84ea361433e7acf3a7e1cdba6a92cf9f0fe;hpb=fd67556734bb00cd466b4d0c87473749880c748e;p=jalview.git diff --git a/src/jalview/appletgui/AnnotationColumnChooser.java b/src/jalview/appletgui/AnnotationColumnChooser.java index 36f8a84..7674de716 100644 --- a/src/jalview/appletgui/AnnotationColumnChooser.java +++ b/src/jalview/appletgui/AnnotationColumnChooser.java @@ -21,7 +21,7 @@ package jalview.appletgui; import jalview.datamodel.AlignmentAnnotation; -import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.schemes.AnnotationColourGradient; import jalview.util.MessageManager; import jalview.viewmodel.annotationfilter.AnnotationFilterParameter; @@ -46,7 +46,7 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.TextEvent; import java.awt.event.TextListener; -import java.util.Iterator; +import java.util.ArrayList; import java.util.Vector; //import javax.swing.JPanel; @@ -110,7 +110,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements private int actionOption = ACTION_OPTION_SELECT; - private ColumnSelection oldColumnSelection; + private HiddenColumns oldHiddenColumns; public AnnotationColumnChooser() { @@ -140,9 +140,9 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements { return; } - setOldColumnSelection(av.getColumnSelection()); + setOldHiddenColumns(av.getAlignment().getHiddenColumns()); adjusting = true; - Vector list = new Vector(); + Vector list = new Vector<>(); int index = 1; for (int i = 0; i < anns.length; i++) { @@ -172,16 +172,12 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements // restore Object state from the previous session if one exists if (lastChooser != null) { - currentSearchPanel = lastChooser - .getCurrentSearchPanel(); + currentSearchPanel = lastChooser.getCurrentSearchPanel(); currentStructureFilterPanel = lastChooser .getCurrentStructureFilterPanel(); - annotations.select(lastChooser - .getAnnotations().getSelectedIndex()); - threshold.select(lastChooser - .getThreshold().getSelectedIndex()); - actionOption = lastChooser - .getActionOption(); + annotations.select(lastChooser.getAnnotations().getSelectedIndex()); + threshold.select(lastChooser.getThreshold().getSelectedIndex()); + actionOption = lastChooser.getActionOption(); percentThreshold.setState(lastChooser.percentThreshold.getState()); } @@ -289,28 +285,28 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements @SuppressWarnings("unchecked") public void reset() { - if (this.getOldColumnSelection() != null) + if (this.getOldHiddenColumns() != null) { av.getColumnSelection().clear(); if (av.getAnnotationColumnSelectionState() != null) { - ColumnSelection oldSelection = av - .getAnnotationColumnSelectionState() - .getOldColumnSelection(); - if (oldSelection != null && oldSelection.getHiddenColumns() != null - && !oldSelection.getHiddenColumns().isEmpty()) + HiddenColumns oldHidden = av.getAnnotationColumnSelectionState() + .getOldHiddenColumns(); + if (oldHidden != null) { - for (Iterator itr = oldSelection.getHiddenColumns() - .iterator(); itr.hasNext();) + ArrayList regions = oldHidden.getHiddenColumnsCopy(); + for (int[] positions : regions) { - int positions[] = itr.next(); av.hideColumns(positions[0], positions[1]); } } - av.setColumnSelection(oldSelection); + // TODO not clear why we need to hide all the columns (above) if we are + // going to copy the hidden columns over wholesale anyway + av.getAlignment().setHiddenColumns(oldHidden); } - ap.paintAlignment(true); + av.sendSelection(); + ap.paintAlignment(true, true); } } @@ -320,7 +316,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements { if (!adjusting) { - thresholdValue.setText((slider.getValue() / 1000f) + ""); + setThresholdValueText(); valueChanged(!sliderDragging); } } @@ -352,7 +348,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements sliderDragging = false; valueChanged(true); } - ap.paintAlignment(true); + ap.paintAlignment(true, true); } }); } @@ -363,8 +359,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements if (slider.isEnabled()) { getCurrentAnnotation().threshold.value = slider.getValue() / 1000f; - updateView(); - ap.paintAlignment(false); + updateView(); // this also calls paintAlignment(true,true) } } @@ -398,11 +393,11 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements } AnnotationFilterParameter filterParams = new AnnotationFilterParameter(); - setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[getAnnotations() - .getSelectedIndex()]); + setCurrentAnnotation(av.getAlignment() + .getAlignmentAnnotation()[getAnnotations().getSelectedIndex()]); - int selectedThresholdItem = getSelectedThresholdItem(getThreshold() - .getSelectedIndex()); + int selectedThresholdItem = getSelectedThresholdItem( + getThreshold().getSelectedIndex()); slider.setEnabled(true); thresholdValue.setEnabled(true); @@ -420,20 +415,20 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements { if (getCurrentAnnotation().threshold == null) { - getCurrentAnnotation() - .setThreshold( - new jalview.datamodel.GraphLine( - (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f, - "Threshold", Color.black)); + getCurrentAnnotation().setThreshold(new jalview.datamodel.GraphLine( + (getCurrentAnnotation().graphMax + - getCurrentAnnotation().graphMin) / 2f, + "Threshold", Color.black)); } adjusting = true; - float range = getCurrentAnnotation().graphMax * 1000 - - getCurrentAnnotation().graphMin * 1000; + // float range = getCurrentAnnotation().graphMax * 1000 + // - getCurrentAnnotation().graphMin * 1000; slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000)); slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000)); - slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000)); + slider.setValue( + (int) (getCurrentAnnotation().threshold.value * 1000)); setThresholdValueText(); // slider.setMajorTickSpacing((int) (range / 10f)); slider.setEnabled(true); @@ -442,22 +437,22 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements adjusting = false; // build filter params - filterParams - .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD); - if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH) + filterParams.setThresholdType( + AnnotationFilterParameter.ThresholdType.NO_THRESHOLD); + if (getCurrentAnnotation().isQuantitative()) { filterParams .setThresholdValue(getCurrentAnnotation().threshold.value); if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD) { - filterParams - .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD); + filterParams.setThresholdType( + AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD); } else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD) { - filterParams - .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD); + filterParams.setThresholdType( + AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD); } } } @@ -488,13 +483,13 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements filterParams.setRegexString(currentSearchPanel.searchBox.getText()); if (currentSearchPanel.displayName.getState()) { - filterParams - .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING); + filterParams.addRegexSearchField( + AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING); } if (currentSearchPanel.description.getState()) { - filterParams - .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION); + filterParams.addRegexSearchField( + AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION); } } else @@ -504,10 +499,13 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements } } + // show hidden columns here, before changing the column selection in + // filterAnnotations, because showing hidden columns has the side effect of + // adding them to the selection + av.showAllHiddenColumns(); av.getColumnSelection().filterAnnotations( getCurrentAnnotation().annotations, filterParams); - av.showAllHiddenColumns(); if (getActionOption() == ACTION_OPTION_HIDE) { av.hideSelectedColumns(); @@ -515,19 +513,20 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements filterParams = null; av.setAnnotationColumnSelectionState(this); - ap.paintAlignment(true); + av.sendSelection(); + ap.paintAlignment(true, true); } - public ColumnSelection getOldColumnSelection() + public HiddenColumns getOldHiddenColumns() { - return oldColumnSelection; + return oldHiddenColumns; } - public void setOldColumnSelection(ColumnSelection currentColumnSelection) + public void setOldHiddenColumns(HiddenColumns currentHiddenColumns) { - if (currentColumnSelection != null) + if (currentHiddenColumns != null) { - this.oldColumnSelection = new ColumnSelection(currentColumnSelection); + this.oldHiddenColumns = new HiddenColumns(currentHiddenColumns); } } @@ -598,7 +597,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements { String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW; if (av.getAlignment().getAlignmentAnnotation()[getAnnotations() - .getSelectedIndex()].graph != AlignmentAnnotation.NO_GRAPH) + .getSelectedIndex()].isQuantitative()) { currentView = AnnotationColumnChooser.GRAPH_VIEW; } @@ -637,7 +636,8 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements public void syncState() { - if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE) + if (aColChooser + .getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE) { furtherAction.select("Hide"); } @@ -665,8 +665,8 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements } } - public class StructureFilterPanel extends TitledPanel implements - ItemListener + public class StructureFilterPanel extends TitledPanel + implements ItemListener { private AnnotationColumnChooser aColChooser; @@ -895,19 +895,8 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements @Override public void actionPerformed(ActionEvent evt) { - if (evt.getSource() == thresholdValue) - { - try - { - float f = new Float(thresholdValue.getText()).floatValue(); - slider.setValue((int) (f * 1000)); - adjustmentValueChanged(null); - } catch (NumberFormatException ex) - { - } - } - else if (evt.getSource() == ok) + if (evt.getSource() == ok) { ok_actionPerformed(null); }