X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAnnotationRowFilter.java;h=f13cb10579c79b4690885d4000b059e23723ca7c;hb=a4da7f0f52e97ebb3fb0c42d6ab3a71762c4b899;hp=1035a6c72e6f44ded96ec678e74eed295a240967;hpb=ad69997e7967bae13b30470ca6d1ab74e0bb3046;p=jalview.git diff --git a/src/jalview/gui/AnnotationRowFilter.java b/src/jalview/gui/AnnotationRowFilter.java index 1035a6c..f13cb10 100644 --- a/src/jalview/gui/AnnotationRowFilter.java +++ b/src/jalview/gui/AnnotationRowFilter.java @@ -80,7 +80,7 @@ public abstract class AnnotationRowFilter extends JPanel */ protected boolean sliderDragging = false; - protected JComboBox threshold = new JComboBox(); + protected JComboBox threshold = new JComboBox<>(); protected JComboBox annotations; @@ -98,7 +98,8 @@ public abstract class AnnotationRowFilter extends JPanel * @param viewport * @param alignPanel */ - public AnnotationRowFilter(AlignViewport viewport, final AlignmentPanel alignPanel) + public AnnotationRowFilter(AlignViewport viewport, + final AlignmentPanel alignPanel) { this.av = viewport; this.ap = alignPanel; @@ -129,8 +130,13 @@ public abstract class AnnotationRowFilter extends JPanel }); } + /** + * update the text field from the threshold slider. preserves state of + * 'adjusting' so safe to call in init. + */ protected void setThresholdValueText() { + boolean oldadj = adjusting; adjusting = true; if (percentThreshold.isSelected()) { @@ -141,8 +147,9 @@ public abstract class AnnotationRowFilter extends JPanel { thresholdValue.setText((slider.getValue() / 1000f) + ""); } - adjusting = false; + adjusting = oldadj; } + protected void addSliderMouseListeners() { @@ -165,33 +172,30 @@ public abstract class AnnotationRowFilter extends JPanel @Override public void mouseReleased(MouseEvent evt) { - if (sliderDragging) - { - sliderDragging = false; - valueChanged(true); - } - ap.paintAlignment(true); + sliderDragReleased(); } }); } -/** - * Builds and returns a list of menu items (display text) for choice of - * annotation. Also builds maps between annotations, their positions in the - * list, and their display labels in the list. - * - * @param isSeqAssociated - * @return - */ + /** + * Builds and returns a list of menu items (display text) for choice of + * annotation. Also builds maps between annotations, their positions in the + * list, and their display labels in the list. + * + * @param isSeqAssociated + * @return + */ public Vector getAnnotationItems(boolean isSeqAssociated) { - annotationLabels = new HashMap(); + annotationLabels = new HashMap<>(); - Vector list = new Vector(); + Vector list = new Vector<>(); int index = 1; - int[] anmap = new int[av.getAlignment().getAlignmentAnnotation().length]; + int[] anmap = new int[av.getAlignment() + .getAlignmentAnnotation().length]; seqAssociated.setEnabled(false); - for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++) + for (int i = 0; i < av.getAlignment() + .getAlignmentAnnotation().length; i++) { AlignmentAnnotation annotation = av.getAlignment() .getAlignmentAnnotation()[i]; @@ -262,7 +266,7 @@ public abstract class AnnotationRowFilter extends JPanel public void cancel_actionPerformed() { reset(); - ap.paintAlignment(true); + ap.paintAlignment(true, true); try { frame.setClosed(true); @@ -291,11 +295,10 @@ public abstract class AnnotationRowFilter extends JPanel try { float f = Float.parseFloat(thresholdValue.getText()); - if (percentThreshold.isEnabled()) + if (percentThreshold.isSelected()) { - slider.setValue(slider.getMinimum() - + ((int) ((f / 100f) * (slider.getMaximum() - slider - .getMinimum())))); + slider.setValue(slider.getMinimum() + ((int) ((f / 100f) + * (slider.getMaximum() - slider.getMinimum())))); } else { @@ -374,9 +377,11 @@ public abstract class AnnotationRowFilter extends JPanel } float thr = annotation.threshold.value; - for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++) + for (int i = 0; i < av.getAlignment() + .getAlignmentAnnotation().length; i++) { - AlignmentAnnotation aa = av.getAlignment().getAlignmentAnnotation()[i]; + AlignmentAnnotation aa = av.getAlignment() + .getAlignmentAnnotation()[i]; if (aa.label.equals(annotation.label) && (annotation.getCalcId() == null ? aa.getCalcId() == null : annotation.getCalcId().equals(aa.getCalcId()))) @@ -403,6 +408,11 @@ public abstract class AnnotationRowFilter extends JPanel this.currentAnnotation = annotation; } + /** + * update associated view model and trigger any necessary repaints. + * + * @param updateAllAnnotation + */ protected abstract void valueChanged(boolean updateAllAnnotation); protected abstract void updateView(); @@ -446,8 +456,8 @@ public abstract class AnnotationRowFilter extends JPanel selectedAnnotationChanged(); } }); - annotations.setToolTipText(MessageManager - .getString("info.select_annotation_row")); + annotations.setToolTipText( + MessageManager.getString("info.select_annotation_row")); threshold.addActionListener(new ActionListener() { @@ -469,7 +479,8 @@ public abstract class AnnotationRowFilter extends JPanel } }); - percentThreshold.setText(MessageManager.getString("label.as_percentage")); + percentThreshold + .setText(MessageManager.getString("label.as_percentage")); percentThreshold.addActionListener(new ActionListener() { @Override @@ -508,4 +519,13 @@ public abstract class AnnotationRowFilter extends JPanel { this.annotations = anns; } + + protected void sliderDragReleased() + { + if (sliderDragging) + { + sliderDragging = false; + valueChanged(true); + } + } }