X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FAnnotationRowFilter.java;h=8b2486fd652b5b14ffc9fa45d793e59abd4104e1;hb=6a144c3b2b7f5f04d908c065a017088453bb7fc7;hp=7b2fb36a2d00fc5ad065760ec4de54940c23b82d;hpb=4d7f98a6dd54d9863ba449ec79dcd95d25ed863d;p=jalview.git
diff --git a/src/jalview/gui/AnnotationRowFilter.java b/src/jalview/gui/AnnotationRowFilter.java
index 7b2fb36..8b2486f 100644
--- a/src/jalview/gui/AnnotationRowFilter.java
+++ b/src/jalview/gui/AnnotationRowFilter.java
@@ -1,14 +1,42 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
package jalview.gui;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.GraphLine;
-import jalview.datamodel.SequenceGroup;
import jalview.schemes.AnnotationColourGradient;
import jalview.util.MessageManager;
+import java.awt.Color;
+import java.awt.Dimension;
import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.FocusAdapter;
+import java.awt.event.FocusEvent;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Vector;
import javax.swing.JButton;
@@ -30,21 +58,11 @@ public abstract class AnnotationRowFilter extends JPanel
protected int[] annmap;
- protected boolean enableSeqAss = false;
-
- private jalview.datamodel.AlignmentAnnotation currentAnnotation;
-
protected boolean adjusting = false;
- protected JCheckBox currentColours = new JCheckBox();
-
- protected JPanel minColour = new JPanel();
-
- protected JPanel maxColour = new JPanel();
-
protected JCheckBox seqAssociated = new JCheckBox();
- protected JCheckBox thresholdIsMin = new JCheckBox();
+ protected JCheckBox percentThreshold = new JCheckBox();
protected JSlider slider = new JSlider();
@@ -62,6 +80,39 @@ public abstract class AnnotationRowFilter extends JPanel
*/
protected boolean sliderDragging = false;
+ protected JComboBox threshold = new JComboBox();
+
+ protected JComboBox annotations;
+
+ /*
+ * map from annotation to its menu item display label
+ * - so we know which item to pre-select on restore
+ */
+ private Map annotationLabels;
+
+ private AlignmentAnnotation currentAnnotation;
+
+ /**
+ * Constructor
+ *
+ * @param viewport
+ * @param alignPanel
+ */
+ public AnnotationRowFilter(AlignViewport viewport,
+ final AlignmentPanel alignPanel)
+ {
+ this.av = viewport;
+ this.ap = alignPanel;
+ thresholdValue.addFocusListener(new FocusAdapter()
+ {
+ @Override
+ public void focusLost(FocusEvent e)
+ {
+ thresholdValue_actionPerformed();
+ }
+ });
+ }
+
protected void addSliderChangeListener()
{
@@ -72,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()
{
@@ -111,25 +182,29 @@ public abstract class AnnotationRowFilter extends JPanel
});
}
- public AnnotationRowFilter(AlignViewport av, final AlignmentPanel ap)
- {
- this.av = av;
- this.ap = ap;
- }
-
- public AnnotationRowFilter()
- {
-
- }
-
+ /**
+ * 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();
+
Vector list = new Vector();
int index = 1;
- int[] anmap = new int[av.getAlignment().getAlignmentAnnotation().length];
- for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++)
+ int[] anmap = new int[av.getAlignment()
+ .getAlignmentAnnotation().length];
+ seqAssociated.setEnabled(false);
+ for (int i = 0; i < av.getAlignment()
+ .getAlignmentAnnotation().length; i++)
{
- if (av.getAlignment().getAlignmentAnnotation()[i].sequenceRef == null)
+ AlignmentAnnotation annotation = av.getAlignment()
+ .getAlignmentAnnotation()[i];
+ if (annotation.sequenceRef == null)
{
if (isSeqAssociated)
{
@@ -138,21 +213,29 @@ public abstract class AnnotationRowFilter extends JPanel
}
else
{
- enableSeqAss = true;
+ seqAssociated.setEnabled(true);
}
- String label = av.getAlignment().getAlignmentAnnotation()[i].label;
+ String label = annotation.label;
+ // add associated sequence ID if available
+ if (!isSeqAssociated && annotation.sequenceRef != null)
+ {
+ label = label + "_" + annotation.sequenceRef.getName();
+ }
+ // make label unique
if (!list.contains(label))
{
anmap[list.size()] = i;
list.add(label);
-
+ annotationLabels.put(annotation, label);
}
else
{
if (!isSeqAssociated)
{
anmap[list.size()] = i;
- list.add(label + "_" + (index++));
+ label = label + "_" + (index++);
+ list.add(label);
+ annotationLabels.put(annotation, label);
}
}
}
@@ -175,12 +258,7 @@ public abstract class AnnotationRowFilter extends JPanel
return selectedThresholdItem;
}
- public void modelChanged()
- {
- seqAssociated.setEnabled(enableSeqAss);
- }
-
- public void ok_actionPerformed(ActionEvent e)
+ public void ok_actionPerformed()
{
try
{
@@ -190,7 +268,7 @@ public abstract class AnnotationRowFilter extends JPanel
}
}
- public void cancel_actionPerformed(ActionEvent e)
+ public void cancel_actionPerformed()
{
reset();
ap.paintAlignment(true);
@@ -202,55 +280,74 @@ public abstract class AnnotationRowFilter extends JPanel
}
}
- public void thresholdCheck_actionPerformed(ActionEvent e)
+ protected void thresholdCheck_actionPerformed()
{
updateView();
}
- public void annotations_actionPerformed(ActionEvent e)
+ protected void selectedAnnotationChanged()
{
updateView();
}
- public void threshold_actionPerformed(ActionEvent e)
+ protected void threshold_actionPerformed()
{
updateView();
}
- public void thresholdValue_actionPerformed(ActionEvent e)
+ protected void thresholdValue_actionPerformed()
{
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)
{
}
}
- public void thresholdIsMin_actionPerformed(ActionEvent actionEvent)
+ protected void percentageValue_actionPerformed()
+ {
+ setThresholdValueText();
+ }
+
+ protected void thresholdIsMin_actionPerformed()
{
updateView();
}
- protected void populateThresholdComboBox(JComboBox threshold)
+ protected void populateThresholdComboBox(JComboBox thresh)
{
- threshold.addItem(MessageManager
- .getString("label.threshold_feature_no_thereshold"));
- threshold.addItem(MessageManager
- .getString("label.threshold_feature_above_thereshold"));
- threshold.addItem(MessageManager
- .getString("label.threshold_feature_below_thereshold"));
+ thresh.addItem(MessageManager
+ .getString("label.threshold_feature_no_threshold"));
+ thresh.addItem(MessageManager
+ .getString("label.threshold_feature_above_threshold"));
+ thresh.addItem(MessageManager
+ .getString("label.threshold_feature_below_threshold"));
}
- protected void seqAssociated_actionPerformed(ActionEvent arg0,
- JComboBox annotations, JCheckBox seqAssociated)
+ /**
+ * Rebuilds the drop-down list of annotations to choose from when the 'per
+ * sequence only' checkbox is checked or unchecked.
+ *
+ * @param anns
+ */
+ protected void seqAssociated_actionPerformed(JComboBox anns)
{
adjusting = true;
- String cursel = (String) annotations.getSelectedItem();
- boolean isvalid = false, isseqs = seqAssociated.isSelected();
- annotations.removeAllItems();
+ String cursel = (String) anns.getSelectedItem();
+ boolean isvalid = false;
+ boolean isseqs = seqAssociated.isSelected();
+ anns.removeAllItems();
for (String anitem : getAnnotationItems(seqAssociated.isSelected()))
{
if (anitem.equals(cursel) || (isseqs && cursel.startsWith(anitem)))
@@ -258,20 +355,22 @@ public abstract class AnnotationRowFilter extends JPanel
isvalid = true;
cursel = anitem;
}
- annotations.addItem(anitem);
+ anns.addItem(anitem);
}
- adjusting = false;
if (isvalid)
{
- annotations.setSelectedItem(cursel);
+ anns.setSelectedItem(cursel);
}
else
{
- if (annotations.getItemCount() > 0)
+ if (anns.getItemCount() > 0)
{
- annotations.setSelectedIndex(0);
+ anns.setSelectedIndex(0);
}
}
+ adjusting = false;
+
+ updateView();
}
protected void propagateSeqAssociatedThreshold(boolean allAnnotation,
@@ -283,9 +382,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())))
@@ -302,80 +403,120 @@ public abstract class AnnotationRowFilter extends JPanel
}
}
- protected boolean colorAlignmContaining(
- AlignmentAnnotation currentAnnotation, int selectedThresholdItem)
+ public AlignmentAnnotation getCurrentAnnotation()
{
+ return currentAnnotation;
+ }
- AnnotationColourGradient acg = null;
- if (currentColours.isSelected())
- {
- acg = new AnnotationColourGradient(currentAnnotation,
- av.getGlobalColourScheme(), selectedThresholdItem);
- }
- else
- {
- acg = new AnnotationColourGradient(currentAnnotation,
- minColour.getBackground(), maxColour.getBackground(),
- selectedThresholdItem);
- }
- acg.setSeqAssociated(seqAssociated.isSelected());
+ protected void setCurrentAnnotation(AlignmentAnnotation annotation)
+ {
+ this.currentAnnotation = annotation;
+ }
- if (currentAnnotation.graphMin == 0f
- && currentAnnotation.graphMax == 0f)
- {
- acg.setPredefinedColours(true);
- }
+ protected abstract void valueChanged(boolean updateAllAnnotation);
- acg.thresholdIsMinMax = thresholdIsMin.isSelected();
+ protected abstract void updateView();
- av.setGlobalColourScheme(acg);
+ protected abstract void reset();
+
+ protected String getAnnotationMenuLabel(AlignmentAnnotation ann)
+ {
+ return annotationLabels.get(ann);
+ }
- if (av.getAlignment().getGroups() != null)
+ protected void jbInit()
+ {
+ ok.setOpaque(false);
+ ok.setText(MessageManager.getString("action.ok"));
+ ok.addActionListener(new ActionListener()
{
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ ok_actionPerformed();
+ }
+ });
- for (SequenceGroup sg : ap.av.getAlignment().getGroups())
+ cancel.setOpaque(false);
+ cancel.setText(MessageManager.getString("action.cancel"));
+ cancel.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
{
- if (sg.cs == null)
- {
- continue;
- }
+ cancel_actionPerformed();
+ }
+ });
- if (currentColours.isSelected())
- {
- sg.cs = new AnnotationColourGradient(currentAnnotation, sg.cs,
- selectedThresholdItem);
- ((AnnotationColourGradient) sg.cs).setSeqAssociated(seqAssociated
- .isSelected());
+ annotations.addItemListener(new ItemListener()
+ {
+ @Override
+ public void itemStateChanged(ItemEvent e)
+ {
+ selectedAnnotationChanged();
+ }
+ });
+ annotations.setToolTipText(
+ MessageManager.getString("info.select_annotation_row"));
- }
- else
+ threshold.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ threshold_actionPerformed();
+ }
+ });
+
+ thresholdValue.setEnabled(false);
+ thresholdValue.setColumns(7);
+ thresholdValue.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ thresholdValue_actionPerformed();
+ }
+ });
+
+ percentThreshold
+ .setText(MessageManager.getString("label.as_percentage"));
+ percentThreshold.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ if (!adjusting)
{
- sg.cs = new AnnotationColourGradient(currentAnnotation,
- minColour.getBackground(), maxColour.getBackground(),
- selectedThresholdItem);
- ((AnnotationColourGradient) sg.cs).setSeqAssociated(seqAssociated
- .isSelected());
+ percentageValue_actionPerformed();
}
-
}
- }
- return false;
+ });
+ slider.setPaintLabels(false);
+ slider.setPaintTicks(true);
+ slider.setBackground(Color.white);
+ slider.setEnabled(false);
+ slider.setOpaque(false);
+ slider.setPreferredSize(new Dimension(100, 32));
}
- public jalview.datamodel.AlignmentAnnotation getCurrentAnnotation()
+ public JComboBox getThreshold()
{
- return currentAnnotation;
+ return threshold;
}
- public void setCurrentAnnotation(
- jalview.datamodel.AlignmentAnnotation currentAnnotation)
+ public void setThreshold(JComboBox thresh)
{
- this.currentAnnotation = currentAnnotation;
+ this.threshold = thresh;
}
- public abstract void valueChanged(boolean updateAllAnnotation);
-
- public abstract void updateView();
+ public JComboBox getAnnotations()
+ {
+ return annotations;
+ }
- public abstract void reset();
+ public void setAnnotations(JComboBox anns)
+ {
+ this.annotations = anns;
+ }
}