X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAnnotationRowFilter.java;h=71ad6a54e709df92a868bb1bc0f24e049465518d;hb=8474476096a0bbce03c7748aa3c267fbf6258249;hp=c2bf41bc479187990e12fe51f4b930cc59a21399;hpb=d5bcc3830eab04e6db816e1c2ad8fce1dc189612;p=jalview.git diff --git a/src/jalview/gui/AnnotationRowFilter.java b/src/jalview/gui/AnnotationRowFilter.java index c2bf41b..71ad6a5 100644 --- a/src/jalview/gui/AnnotationRowFilter.java +++ b/src/jalview/gui/AnnotationRowFilter.java @@ -62,6 +62,8 @@ public abstract class AnnotationRowFilter extends JPanel protected JCheckBox seqAssociated = new JCheckBox(); + protected JCheckBox percentThreshold = new JCheckBox(); + protected JSlider slider = new JSlider(); protected JTextField thresholdValue = new JTextField(20); @@ -78,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; @@ -96,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; @@ -120,13 +123,33 @@ public abstract class AnnotationRowFilter extends JPanel { if (!adjusting) { - thresholdValue.setText((slider.getValue() / 1000f) + ""); + setThresholdValueText(); valueChanged(!sliderDragging); } } }); } + /** + * 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()) + { + thresholdValue.setText("" + (slider.getValue() - slider.getMinimum()) + * 100f / (slider.getMaximum() - slider.getMinimum())); + } + else + { + thresholdValue.setText((slider.getValue() / 1000f) + ""); + } + adjusting = oldadj; + } + protected void addSliderMouseListeners() { @@ -154,28 +177,29 @@ public abstract class AnnotationRowFilter extends JPanel sliderDragging = false; valueChanged(true); } - ap.paintAlignment(true); } }); } -/** - * 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]; @@ -246,7 +270,7 @@ public abstract class AnnotationRowFilter extends JPanel public void cancel_actionPerformed() { reset(); - ap.paintAlignment(true); + ap.paintAlignment(true, true); try { frame.setClosed(true); @@ -275,13 +299,26 @@ public abstract class AnnotationRowFilter extends JPanel try { float f = Float.parseFloat(thresholdValue.getText()); - slider.setValue((int) (f * 1000)); + if (percentThreshold.isSelected()) + { + slider.setValue(slider.getMinimum() + ((int) ((f / 100f) + * (slider.getMaximum() - slider.getMinimum())))); + } + else + { + slider.setValue((int) (f * 1000)); + } updateView(); } catch (NumberFormatException ex) { } } + protected void percentageValue_actionPerformed() + { + setThresholdValueText(); + } + protected void thresholdIsMin_actionPerformed() { updateView(); @@ -344,9 +381,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()))) @@ -373,6 +412,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(); @@ -416,8 +460,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() { @@ -439,6 +483,19 @@ public abstract class AnnotationRowFilter extends JPanel } }); + percentThreshold + .setText(MessageManager.getString("label.as_percentage")); + percentThreshold.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + if (!adjusting) + { + percentageValue_actionPerformed(); + } + } + }); slider.setPaintLabels(false); slider.setPaintTicks(true); slider.setBackground(Color.white);