From: Charles Ofoegbu Date: Tue, 13 Jan 2015 15:21:45 +0000 (+0000) Subject: Refactored AnnotationColumnChoser and AnnotationColorChooser to apply the DRY principle X-Git-Tag: Jalview_2_9~119^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=ead72caff9aef9b7103dbb15907aeae777200832;p=jalview.git Refactored AnnotationColumnChoser and AnnotationColorChooser to apply the DRY principle --- diff --git a/src/jalview/api/AnnotationRowFilterI.java b/src/jalview/api/AnnotationRowFilterI.java new file mode 100644 index 0000000..b8d4706 --- /dev/null +++ b/src/jalview/api/AnnotationRowFilterI.java @@ -0,0 +1,16 @@ +package jalview.api; + +import java.util.Vector; + +public interface AnnotationRowFilterI +{ + public Vector getAnnotationItems(boolean isSeqAssociated); + + public void modelChanged(); + + public void valueChanged(boolean updateAllAnnotation); + + public void updateView(); + + public void reset(); +} diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index af3b0fb..34ccf9c 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -3327,7 +3327,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void annotationColumn_actionPerformed(ActionEvent e) { - new AnnotationColumnSelection(viewport, alignPanel); + new AnnotationColumnChooser(viewport, alignPanel); } @Override diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 10e14d1..cff9e94 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -151,7 +151,7 @@ public class AlignViewport extends AlignmentViewport implements private boolean rightAlignIds = false; - private AnnotationColumnSelection currentAnnotationColumnSelectionState; + private AnnotationColumnChooser currentAnnotationColumnSelectionState; /** * Creates a new AlignViewport object. * @@ -1320,13 +1320,13 @@ public class AlignViewport extends AlignmentViewport implements this.rightAlignIds = rightAlignIds; } - public AnnotationColumnSelection getCurrentAnnotationColumnSelectionState() + public AnnotationColumnChooser getCurrentAnnotationColumnSelectionState() { return currentAnnotationColumnSelectionState; } public void setCurrentAnnotationColumnSelectionState( - AnnotationColumnSelection currentAnnotationColumnSelectionState) + AnnotationColumnChooser currentAnnotationColumnSelectionState) { this.currentAnnotationColumnSelectionState = currentAnnotationColumnSelectionState; } diff --git a/src/jalview/gui/AnnotationColourChooser.java b/src/jalview/gui/AnnotationColourChooser.java index b8996b6..699b560 100644 --- a/src/jalview/gui/AnnotationColourChooser.java +++ b/src/jalview/gui/AnnotationColourChooser.java @@ -21,8 +21,6 @@ package jalview.gui; import jalview.bin.Cache; -import jalview.datamodel.AlignmentAnnotation; -import jalview.datamodel.GraphLine; import jalview.datamodel.SequenceGroup; import jalview.schemes.AnnotationColourGradient; import jalview.schemes.ColourSchemeI; @@ -37,51 +35,53 @@ import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.Hashtable; -import java.util.Vector; import javax.swing.BorderFactory; import javax.swing.JButton; -import javax.swing.JCheckBox; import javax.swing.JColorChooser; import javax.swing.JComboBox; import javax.swing.JInternalFrame; import javax.swing.JLayeredPane; import javax.swing.JPanel; -import javax.swing.JSlider; -import javax.swing.JTextField; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; import net.miginfocom.swing.MigLayout; -public class AnnotationColourChooser extends JPanel +@SuppressWarnings("serial") +public class AnnotationColourChooser extends AnnotationRowFilter { - JInternalFrame frame; - - AlignViewport av; - - AlignmentPanel ap; ColourSchemeI oldcs; - Hashtable oldgroupColours; - - jalview.datamodel.AlignmentAnnotation currentAnnotation; - - boolean adjusting = false; + Hashtable oldgroupColours; /** * enabled if the user is dragging the slider - try to keep updates to a * minimun */ - boolean sliderDragging = false; + + JComboBox annotations; + + JButton defColours = new JButton(); + + JButton ok = new JButton(); + + JButton cancel = new JButton(); + + JPanel jPanel1 = new JPanel(); + + JPanel jPanel2 = new JPanel(); + + BorderLayout borderLayout1 = new BorderLayout(); + + private JComboBox threshold = new JComboBox(); public AnnotationColourChooser(AlignViewport av, final AlignmentPanel ap) { + super(av, ap); oldcs = av.getGlobalColourScheme(); if (av.getAlignment().getGroups() != null) { - oldgroupColours = new Hashtable(); + oldgroupColours = new Hashtable(); for (SequenceGroup sg : ap.av.getAlignment().getGroups()) { if (sg.cs != null) @@ -90,8 +90,6 @@ public class AnnotationColourChooser extends JPanel } } } - this.av = av; - this.ap = ap; frame = new JInternalFrame(); frame.setContentPane(this); frame.setLayer(JLayeredPane.PALETTE_LAYER); @@ -99,45 +97,8 @@ public class AnnotationColourChooser extends JPanel MessageManager.getString("label.colour_by_annotation"), 520, 215); - slider.addChangeListener(new ChangeListener() - { - @Override - public void stateChanged(ChangeEvent evt) - { - if (!adjusting) - { - thresholdValue.setText((slider.getValue() / 1000f) + ""); - valueChanged(!sliderDragging); - } - } - }); - slider.addMouseListener(new MouseAdapter() - { - @Override - public void mousePressed(MouseEvent e) - { - sliderDragging = true; - super.mousePressed(e); - } - - @Override - public void mouseDragged(MouseEvent e) - { - sliderDragging = true; - super.mouseDragged(e); - } - - @Override - public void mouseReleased(MouseEvent evt) - { - if (sliderDragging) - { - sliderDragging = false; - valueChanged(true); - } - ap.paintAlignment(true); - } - }); + addSliderChangeListener(); + addSliderMouseListeners(); if (av.getAlignment().getAlignmentAnnotation() == null) { @@ -161,15 +122,10 @@ public class AnnotationColourChooser extends JPanel seqAssociated.setSelected(acg.isSeqAssociated()); } - annotations = new JComboBox( + annotations = new JComboBox( getAnnotationItems(seqAssociated.isSelected())); - 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")); + populateThresholdComboBox(threshold); if (oldcs instanceof AnnotationColourGradient) { @@ -178,13 +134,13 @@ public class AnnotationColourChooser extends JPanel switch (acg.getAboveThreshold()) { case AnnotationColourGradient.NO_THRESHOLD: - threshold.setSelectedIndex(0); + getThreshold().setSelectedIndex(0); break; case AnnotationColourGradient.ABOVE_THRESHOLD: - threshold.setSelectedIndex(1); + getThreshold().setSelectedIndex(1); break; case AnnotationColourGradient.BELOW_THRESHOLD: - threshold.setSelectedIndex(2); + getThreshold().setSelectedIndex(2); break; default: throw new Error(MessageManager.getString("error.implementation_error_dont_know_about_thereshold_setting")); @@ -199,62 +155,11 @@ public class AnnotationColourChooser extends JPanel } catch (Exception ex) { } - adjusting = false; - changeColour(); + updateView(); frame.invalidate(); frame.pack(); - - } - - private Vector getAnnotationItems(boolean isSeqAssociated) - { - Vector list = new Vector(); - int index = 1; - int[] anmap = new int[av.getAlignment().getAlignmentAnnotation().length]; - boolean enableSeqAss = false; - for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++) - { - if (av.getAlignment().getAlignmentAnnotation()[i].sequenceRef == null) - { - if (isSeqAssociated) - { - continue; - } - } - else - { - enableSeqAss = true; - } - String label = av.getAlignment().getAlignmentAnnotation()[i].label; - if (!list.contains(label)) - { - anmap[list.size()] = i; - list.add(label); - - } - else - { - if (!isSeqAssociated) - { - anmap[list.size()] = i; - list.add(label + "_" + (index++)); - } - } - } - seqAssociated.setEnabled(enableSeqAss); - this.annmap = new int[list.size()]; - System.arraycopy(anmap, 0, this.annmap, 0, this.annmap.length); - return list; - } - - private void setDefaultMinMax() - { - minColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", - Color.orange)); - maxColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", - Color.red)); } public AnnotationColourChooser() @@ -342,7 +247,7 @@ public class AnnotationColourChooser extends JPanel annotations_actionPerformed(e); } }); - threshold.addActionListener(new ActionListener() + getThreshold().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) @@ -400,7 +305,7 @@ public class AnnotationColourChooser extends JPanel @Override public void actionPerformed(ActionEvent arg0) { - seqAssociated_actionPerformed(arg0); + seqAssociated_actionPerformed(arg0, annotations, seqAssociated); } }); @@ -419,7 +324,7 @@ public class AnnotationColourChooser extends JPanel colpanel.add(minColour); colpanel.add(maxColour); jPanel2.add(colpanel, "wrap"); - jPanel2.add(threshold); + jPanel2.add(getThreshold()); jPanel2.add(defColours, "skip 1, wrap"); jPanel2.add(thresholdIsMin); jPanel2.add(slider, "grow"); @@ -429,72 +334,19 @@ public class AnnotationColourChooser extends JPanel this.validate(); } - protected void seqAssociated_actionPerformed(ActionEvent arg0) - { - adjusting = true; - String cursel = (String) annotations.getSelectedItem(); - boolean isvalid = false, isseqs = seqAssociated.isSelected(); - this.annotations.removeAllItems(); - for (String anitem : getAnnotationItems(seqAssociated.isSelected())) - { - if (anitem.equals(cursel) || (isseqs && cursel.startsWith(anitem))) - { - isvalid = true; - cursel = anitem; - } - this.annotations.addItem(anitem); - } - adjusting = false; - if (isvalid) - { - this.annotations.setSelectedItem(cursel); - } - else - { - if (annotations.getItemCount() > 0) - { - annotations.setSelectedIndex(0); - } - } - } - protected void resetColours_actionPerformed(ActionEvent arg0) { setDefaultMinMax(); - changeColour(); + updateView(); } - JComboBox annotations; - - int[] annmap; - - JPanel minColour = new JPanel(); - - JPanel maxColour = new JPanel(); - - JButton defColours = new JButton(); - - JButton ok = new JButton(); - - JButton cancel = new JButton(); - - JPanel jPanel1 = new JPanel(); - - JPanel jPanel2 = new JPanel(); - - BorderLayout borderLayout1 = new BorderLayout(); - - JComboBox threshold = new JComboBox(); - - JSlider slider = new JSlider(); - - JTextField thresholdValue = new JTextField(20); - - JCheckBox currentColours = new JCheckBox(); - - JCheckBox thresholdIsMin = new JCheckBox(); - - JCheckBox seqAssociated = new JCheckBox(); + private void setDefaultMinMax() + { + minColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", + Color.orange)); + maxColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", + Color.red)); + } public void minColour_actionPerformed() { @@ -505,7 +357,7 @@ public class AnnotationColourChooser extends JPanel minColour.setBackground(col); } minColour.repaint(); - changeColour(); + updateView(); } public void maxColour_actionPerformed() @@ -517,247 +369,116 @@ public class AnnotationColourChooser extends JPanel maxColour.setBackground(col); } maxColour.repaint(); - changeColour(); + updateView(); } - void changeColour() + public void reset() { - // Check if combobox is still adjusting - if (adjusting) - { - return; - } - - currentAnnotation = av.getAlignment().getAlignmentAnnotation()[annmap[annotations - .getSelectedIndex()]]; - - int aboveThreshold = -1; - if (threshold.getSelectedIndex() == 1) - { - aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD; - } - else if (threshold.getSelectedIndex() == 2) - { - aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD; - } - - slider.setEnabled(true); - thresholdValue.setEnabled(true); - thresholdIsMin.setEnabled(true); - - if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD) - { - slider.setEnabled(false); - thresholdValue.setEnabled(false); - thresholdValue.setText(""); - thresholdIsMin.setEnabled(false); - } - else if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD - && currentAnnotation.threshold == null) - { - currentAnnotation - .setThreshold(new jalview.datamodel.GraphLine( - (currentAnnotation.graphMax - currentAnnotation.graphMin) / 2f, - "Threshold", Color.black)); - } - - if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD) - { - adjusting = true; - float range = currentAnnotation.graphMax * 1000 - - currentAnnotation.graphMin * 1000; - - slider.setMinimum((int) (currentAnnotation.graphMin * 1000)); - slider.setMaximum((int) (currentAnnotation.graphMax * 1000)); - slider.setValue((int) (currentAnnotation.threshold.value * 1000)); - thresholdValue.setText(currentAnnotation.threshold.value + ""); - slider.setMajorTickSpacing((int) (range / 10f)); - slider.setEnabled(true); - thresholdValue.setEnabled(true); - adjusting = false; - } - - AnnotationColourGradient acg = null; - if (currentColours.isSelected()) - { - acg = new AnnotationColourGradient(currentAnnotation, - av.getGlobalColourScheme(), aboveThreshold); - } - else - { - acg = new AnnotationColourGradient(currentAnnotation, - minColour.getBackground(), maxColour.getBackground(), - aboveThreshold); - } - acg.setSeqAssociated(seqAssociated.isSelected()); - - if (currentAnnotation.graphMin == 0f - && currentAnnotation.graphMax == 0f) - { - acg.setPredefinedColours(true); - } - - acg.thresholdIsMinMax = thresholdIsMin.isSelected(); - - av.setGlobalColourScheme(acg); - + av.setGlobalColourScheme(oldcs); if (av.getAlignment().getGroups() != null) { for (SequenceGroup sg : ap.av.getAlignment().getGroups()) { - if (sg.cs == null) - { - continue; - } - - if (currentColours.isSelected()) - { - sg.cs = new AnnotationColourGradient(currentAnnotation, sg.cs, - aboveThreshold); - ((AnnotationColourGradient) sg.cs).setSeqAssociated(seqAssociated - .isSelected()); - - } - else - { - sg.cs = new AnnotationColourGradient(currentAnnotation, - minColour.getBackground(), maxColour.getBackground(), - aboveThreshold); - ((AnnotationColourGradient) sg.cs).setSeqAssociated(seqAssociated - .isSelected()); - } - + sg.cs = oldgroupColours.get(sg); } } - ap.alignmentChanged(); - // ensure all associated views (overviews, structures, etc) are notified of - // updated colours. - ap.paintAlignment(true); - } - - public void ok_actionPerformed(ActionEvent e) - { - changeColour(); - try - { - frame.setClosed(true); - } catch (Exception ex) - { - } } - public void cancel_actionPerformed(ActionEvent e) + public void valueChanged(boolean updateAllAnnotation) { - reset(); - // ensure all original colouring is propagated to listeners. - ap.paintAlignment(true); - try - { - frame.setClosed(true); - } catch (Exception ex) + if (currentColours.isSelected() + && !(av.getGlobalColourScheme() instanceof AnnotationColourGradient)) { + updateView(); } + getCurrentAnnotation().threshold.value = slider.getValue() / 1000f; + propagateSeqAssociatedThreshold(updateAllAnnotation, + getCurrentAnnotation()); + ap.paintAlignment(false); } - void reset() - { - av.setGlobalColourScheme(oldcs); - if (av.getAlignment().getGroups() != null) - { - - for (SequenceGroup sg : ap.av.getAlignment().getGroups()) - { - sg.cs = (ColourSchemeI) oldgroupColours.get(sg); - } - } - } - - public void thresholdCheck_actionPerformed(ActionEvent e) - { - changeColour(); - } - - public void annotations_actionPerformed(ActionEvent e) + public JComboBox getThreshold() { - changeColour(); + return threshold; } - public void threshold_actionPerformed(ActionEvent e) + public void setThreshold(JComboBox threshold) { - changeColour(); + this.threshold = threshold; } - public void thresholdValue_actionPerformed(ActionEvent e) + public void currentColours_actionPerformed(ActionEvent e) { - try - { - float f = Float.parseFloat(thresholdValue.getText()); - slider.setValue((int) (f * 1000)); - } catch (NumberFormatException ex) + if (currentColours.isSelected()) { + reset(); } + maxColour.setEnabled(!currentColours.isSelected()); + minColour.setEnabled(!currentColours.isSelected()); + updateView(); } - public void valueChanged(boolean updateAllAnnotation) + @Override + public void updateView() { - if (currentColours.isSelected() - && !(av.getGlobalColourScheme() instanceof AnnotationColourGradient)) - { - changeColour(); - } - currentAnnotation.threshold.value = slider.getValue() / 1000f; - propagateSeqAssociatedThreshold(updateAllAnnotation); - ap.paintAlignment(false); + changeColour(); } - - private void propagateSeqAssociatedThreshold(boolean allAnnotation) + void changeColour() { - if (currentAnnotation.sequenceRef == null - || currentAnnotation.threshold == null) + // Check if combobox is still adjusting + if (adjusting) { return; } - // TODO: JAL-1327 only update visible annotation thresholds if allAnnotation - // is false, since we only need to provide a quick visual indicator - float thr = currentAnnotation.threshold.value; - for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++) + setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[annmap[annotations + .getSelectedIndex()]]); + + int selectedThresholdItem = getSelectedThresholdItem(getThreshold() + .getSelectedIndex()); + + slider.setEnabled(true); + thresholdValue.setEnabled(true); + thresholdIsMin.setEnabled(true); + + if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD) { - AlignmentAnnotation aa = av.getAlignment().getAlignmentAnnotation()[i]; - if (aa.label.equals(currentAnnotation.label) - && (currentAnnotation.getCalcId() == null ? aa.getCalcId() == null - : currentAnnotation.getCalcId() - .equals(aa.getCalcId()))) - { - if (aa.threshold == null) - { - aa.threshold = new GraphLine(currentAnnotation.threshold); - } - else - { - aa.threshold.value = thr; - } - } + slider.setEnabled(false); + thresholdValue.setEnabled(false); + thresholdValue.setText(""); + thresholdIsMin.setEnabled(false); } - } - - public void currentColours_actionPerformed(ActionEvent e) - { - if (currentColours.isSelected()) + else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD + && getCurrentAnnotation().threshold == null) { - reset(); + getCurrentAnnotation() + .setThreshold(new jalview.datamodel.GraphLine( + (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f, + "Threshold", Color.black)); } - maxColour.setEnabled(!currentColours.isSelected()); - minColour.setEnabled(!currentColours.isSelected()); + if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD) + { + adjusting = true; + float range = getCurrentAnnotation().graphMax * 1000 + - getCurrentAnnotation().graphMin * 1000; - changeColour(); - } + slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000)); + slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000)); + slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000)); + thresholdValue.setText(getCurrentAnnotation().threshold.value + ""); + slider.setMajorTickSpacing((int) (range / 10f)); + slider.setEnabled(true); + thresholdValue.setEnabled(true); + adjusting = false; + } + colorAlignmContaining(getCurrentAnnotation(), selectedThresholdItem); - public void thresholdIsMin_actionPerformed(ActionEvent actionEvent) - { - changeColour(); + ap.alignmentChanged(); + // ensure all associated views (overviews, structures, etc) are notified of + // updated colours. + ap.paintAlignment(true); } } diff --git a/src/jalview/gui/AnnotationColumnChooser.java b/src/jalview/gui/AnnotationColumnChooser.java new file mode 100644 index 0000000..4abf49d --- /dev/null +++ b/src/jalview/gui/AnnotationColumnChooser.java @@ -0,0 +1,291 @@ +package jalview.gui; + +import jalview.schemes.AnnotationColourGradient; +import jalview.util.MessageManager; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JInternalFrame; +import javax.swing.JLayeredPane; +import javax.swing.JPanel; + +import net.miginfocom.swing.MigLayout; + +@SuppressWarnings("serial") +public class AnnotationColumnChooser extends AnnotationRowFilter +{ + + private JComboBox annotations; + + JButton ok = new JButton(); + + JButton cancel = new JButton(); + + JPanel jPanel1 = new JPanel(); + + JPanel jPanel2 = new JPanel(); + + BorderLayout borderLayout1 = new BorderLayout(); + + private JComboBox threshold = new JComboBox(); + + + public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap) + { + super(av, ap); + frame = new JInternalFrame(); + frame.setContentPane(this); + frame.setLayer(JLayeredPane.PALETTE_LAYER); + Desktop.addInternalFrame(frame, "Select By Annotation", 520, 215); + + addSliderChangeListener(); + addSliderMouseListeners(); + + if (av.getAlignment().getAlignmentAnnotation() == null) + { + return; + } + + adjusting = true; + + setAnnotations(new JComboBox( + getAnnotationItems(seqAssociated.isSelected()))); + populateThresholdComboBox(threshold); + + if (av.getCurrentAnnotationColumnSelectionState() != null) + { + annotations.setSelectedIndex(av + .getCurrentAnnotationColumnSelectionState().getAnnotations() + .getSelectedIndex()); + threshold.setSelectedIndex(av + .getCurrentAnnotationColumnSelectionState().getThreshold() + .getSelectedIndex()); + } + + try + { + jbInit(); + } catch (Exception ex) + { + } + adjusting = false; + + updateView(); + frame.invalidate(); + frame.pack(); + } + + + public AnnotationColumnChooser() + { + try + { + jbInit(); + } catch (Exception ex) + { + ex.printStackTrace(); + } + } + + private void jbInit() throws Exception + { + ok.setOpaque(false); + ok.setText(MessageManager.getString("action.ok")); + ok.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + ok_actionPerformed(e); + } + }); + cancel.setOpaque(false); + cancel.setText(MessageManager.getString("action.cancel")); + cancel.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + cancel_actionPerformed(e); + } + }); + + getAnnotations().addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + annotations_actionPerformed(e); + } + }); + getThreshold().addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + threshold_actionPerformed(e); + } + }); + thresholdValue.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + thresholdValue_actionPerformed(e); + } + }); + slider.setPaintLabels(false); + slider.setPaintTicks(true); + slider.setBackground(Color.white); + slider.setEnabled(false); + slider.setOpaque(false); + slider.setPreferredSize(new Dimension(100, 32)); + thresholdValue.setEnabled(false); + thresholdValue.setColumns(7); + thresholdIsMin.setBackground(Color.white); + thresholdIsMin.setFont(JvSwingUtils.getLabelFont()); + thresholdIsMin.setText(MessageManager + .getString("label.threshold_minmax")); + thresholdIsMin.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent actionEvent) + { + thresholdIsMin_actionPerformed(actionEvent); + } + }); + seqAssociated.setBackground(Color.white); + seqAssociated.setFont(JvSwingUtils.getLabelFont()); + seqAssociated.setText(MessageManager + .getString("label.per_sequence_only")); + seqAssociated.addActionListener(new ActionListener() + { + + @Override + public void actionPerformed(ActionEvent arg0) + { + seqAssociated_actionPerformed(arg0, annotations, seqAssociated); + } + }); + + this.setLayout(borderLayout1); + jPanel2.setLayout(new MigLayout("", "[left][center][right]", "[][][]")); + jPanel1.setBackground(Color.white); + jPanel2.setBackground(Color.white); + + jPanel1.add(ok); + jPanel1.add(cancel); + jPanel2.add(getAnnotations(), "grow, wrap"); + jPanel2.add(seqAssociated, "wrap"); + jPanel2.add(getThreshold(), "grow, wrap"); + jPanel2.add(thresholdIsMin, "wrap"); + jPanel2.add(slider, "grow"); + jPanel2.add(thresholdValue, "grow"); + this.add(jPanel1, java.awt.BorderLayout.SOUTH); + this.add(jPanel2, java.awt.BorderLayout.CENTER); + this.validate(); + } + + + public void reset() + { + av.getColumnSelection().clear(); + } + + public void valueChanged(boolean updateAllAnnotation) + { + getCurrentAnnotation().threshold.value = slider.getValue() / 1000f; + updateView(); + propagateSeqAssociatedThreshold(updateAllAnnotation, + getCurrentAnnotation()); + ap.paintAlignment(false); + } + + public JComboBox getThreshold() + { + return threshold; + } + + public void setThreshold(JComboBox threshold) + { + this.threshold = threshold; + } + + public JComboBox getAnnotations() + { + return annotations; + } + + public void setAnnotations(JComboBox annotations) + { + this.annotations = annotations; + } + + @Override + public void updateView() + { + changeColumnSelection(); + } + void changeColumnSelection() + { + // Check if combobox is still adjusting + if (adjusting) + { + return; + } + + setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations() + .getSelectedIndex()]]); + + + int selectedThresholdItem = getSelectedThresholdItem(getThreshold() + .getSelectedIndex()); + + slider.setEnabled(true); + thresholdValue.setEnabled(true); + thresholdIsMin.setEnabled(true); + + if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD) + { + slider.setEnabled(false); + thresholdValue.setEnabled(false); + thresholdValue.setText(""); + thresholdIsMin.setEnabled(false); + } + else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD + && getCurrentAnnotation().threshold == null) + { + getCurrentAnnotation() + .setThreshold(new jalview.datamodel.GraphLine( + (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f, + "Threshold", Color.black)); + } + + if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD) + { + adjusting = true; + 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)); + thresholdValue.setText(getCurrentAnnotation().threshold.value + ""); + slider.setMajorTickSpacing((int) (range / 10f)); + slider.setEnabled(true); + thresholdValue.setEnabled(true); + adjusting = false; + } + + markColumnsContaining(getCurrentAnnotation(), selectedThresholdItem); + av.setCurrentAnnotationColumnSelectionState(this); + ap.alignmentChanged(); + ap.paintAlignment(true); + } +} diff --git a/src/jalview/gui/AnnotationColumnSelection.java b/src/jalview/gui/AnnotationColumnSelection.java deleted file mode 100644 index ee8f03a..0000000 --- a/src/jalview/gui/AnnotationColumnSelection.java +++ /dev/null @@ -1,660 +0,0 @@ -package jalview.gui; - -import jalview.bin.Cache; -import jalview.datamodel.AlignmentAnnotation; -import jalview.datamodel.Annotation; -import jalview.datamodel.ColumnSelection; -import jalview.datamodel.GraphLine; -import jalview.schemes.AnnotationColourGradient; -import jalview.schemes.ColourSchemeI; -import jalview.util.MessageManager; - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.Hashtable; -import java.util.Vector; - -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JInternalFrame; -import javax.swing.JLayeredPane; -import javax.swing.JPanel; -import javax.swing.JSlider; -import javax.swing.JTextField; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; - -import net.miginfocom.swing.MigLayout; - -public class AnnotationColumnSelection extends JPanel -{ - JInternalFrame frame; - - AlignViewport av; - - AlignmentPanel ap; - - ColourSchemeI oldcs; - - Hashtable oldgroupColours; - - private JComboBox annotations; - - int[] annmap; - - JPanel minColour = new JPanel(); - - JPanel maxColour = new JPanel(); - - JButton defColours = new JButton(); - - JButton ok = new JButton(); - - JButton cancel = new JButton(); - - JPanel jPanel1 = new JPanel(); - - JPanel jPanel2 = new JPanel(); - - BorderLayout borderLayout1 = new BorderLayout(); - - private JComboBox threshold = new JComboBox(); - - JSlider slider = new JSlider(); - - JTextField thresholdValue = new JTextField(20); - - JCheckBox currentColours = new JCheckBox(); - - JCheckBox thresholdIsMin = new JCheckBox(); - - JCheckBox seqAssociated = new JCheckBox(); - - private jalview.datamodel.AlignmentAnnotation currentAnnotation; - - boolean adjusting = false; - - /** - * enabled if the user is dragging the slider - try to keep updates to a - * minimun - */ - boolean sliderDragging = false; - - public AnnotationColumnSelection(AlignViewport av, final AlignmentPanel ap) - { - - this.av = av; - this.ap = ap; - frame = new JInternalFrame(); - frame.setContentPane(this); - frame.setLayer(JLayeredPane.PALETTE_LAYER); - Desktop.addInternalFrame(frame, "Select By Annotation", 520, 215); - - slider.addChangeListener(new ChangeListener() - { - @Override - public void stateChanged(ChangeEvent evt) - { - if (!adjusting) - { - thresholdValue.setText((slider.getValue() / 1000f) + ""); - valueChanged(!sliderDragging); - } - } - }); - slider.addMouseListener(new MouseAdapter() - { - @Override - public void mousePressed(MouseEvent e) - { - sliderDragging = true; - super.mousePressed(e); - } - - @Override - public void mouseDragged(MouseEvent e) - { - sliderDragging = true; - super.mouseDragged(e); - } - - @Override - public void mouseReleased(MouseEvent evt) - { - if (sliderDragging) - { - sliderDragging = false; - valueChanged(true); - } - ap.paintAlignment(true); - } - }); - - if (av.getAlignment().getAlignmentAnnotation() == null) - { - return; - } - - // Always get default shading from preferences. - setDefaultMinMax(); - - adjusting = true; - - setAnnotations(new JComboBox( - getAnnotationItems(seqAssociated.isSelected()))); - - 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")); - - if (av.getCurrentAnnotationColumnSelectionState() != null) - { - annotations.setSelectedIndex(av - .getCurrentAnnotationColumnSelectionState().getAnnotations() - .getSelectedIndex()); - threshold.setSelectedIndex(av - .getCurrentAnnotationColumnSelectionState().getThreshold() - .getSelectedIndex()); - System.out.println("selected annotation : " - + av.getCurrentAnnotationColumnSelectionState() - .getAnnotations().getSelectedIndex()); - System.out.println("selected threshold : " - + av.getCurrentAnnotationColumnSelectionState() - .getThreshold().getSelectedIndex()); - } - - try - { - jbInit(); - } catch (Exception ex) - { - } - - adjusting = false; - - changeColumnSelection(); - frame.invalidate(); - frame.pack(); - - } - - private Vector getAnnotationItems(boolean isSeqAssociated) - { - Vector list = new Vector(); - int index = 1; - int[] anmap = new int[av.getAlignment().getAlignmentAnnotation().length]; - boolean enableSeqAss = false; - for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++) - { - if (av.getAlignment().getAlignmentAnnotation()[i].sequenceRef == null) - { - if (isSeqAssociated) - { - continue; - } - } - else - { - enableSeqAss = true; - } - String label = av.getAlignment().getAlignmentAnnotation()[i].label; - if (!list.contains(label)) - { - anmap[list.size()] = i; - list.add(label); - - } - else - { - if (!isSeqAssociated) - { - anmap[list.size()] = i; - list.add(label + "_" + (index++)); - } - } - } - seqAssociated.setEnabled(enableSeqAss); - this.annmap = new int[list.size()]; - System.arraycopy(anmap, 0, this.annmap, 0, this.annmap.length); - return list; - } - - private void setDefaultMinMax() - { - minColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", - Color.orange)); - maxColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", - Color.red)); - } - - public AnnotationColumnSelection() - { - try - { - jbInit(); - } catch (Exception ex) - { - ex.printStackTrace(); - } - } - - private void jbInit() throws Exception - { - ok.setOpaque(false); - ok.setText(MessageManager.getString("action.ok")); - ok.addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - ok_actionPerformed(e); - } - }); - cancel.setOpaque(false); - cancel.setText(MessageManager.getString("action.cancel")); - cancel.addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - cancel_actionPerformed(e); - } - }); - - getAnnotations().addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - annotations_actionPerformed(e); - } - }); - getThreshold().addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - threshold_actionPerformed(e); - } - }); - thresholdValue.addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - thresholdValue_actionPerformed(e); - } - }); - slider.setPaintLabels(false); - slider.setPaintTicks(true); - slider.setBackground(Color.white); - slider.setEnabled(false); - slider.setOpaque(false); - slider.setPreferredSize(new Dimension(100, 32)); - thresholdValue.setEnabled(false); - thresholdValue.setColumns(7); - thresholdIsMin.setBackground(Color.white); - thresholdIsMin.setFont(JvSwingUtils.getLabelFont()); - thresholdIsMin.setText(MessageManager - .getString("label.threshold_minmax")); - thresholdIsMin.addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent actionEvent) - { - thresholdIsMin_actionPerformed(actionEvent); - } - }); - seqAssociated.setBackground(Color.white); - seqAssociated.setFont(JvSwingUtils.getLabelFont()); - seqAssociated.setText(MessageManager - .getString("label.per_sequence_only")); - seqAssociated.addActionListener(new ActionListener() - { - - @Override - public void actionPerformed(ActionEvent arg0) - { - seqAssociated_actionPerformed(arg0); - } - }); - - this.setLayout(borderLayout1); - jPanel2.setLayout(new MigLayout("", "[left][center][right]", "[][][]")); - jPanel1.setBackground(Color.white); - jPanel2.setBackground(Color.white); - - jPanel1.add(ok); - jPanel1.add(cancel); - jPanel2.add(getAnnotations(), "grow, wrap"); - jPanel2.add(seqAssociated, "wrap"); - jPanel2.add(getThreshold(), "grow, wrap"); - jPanel2.add(thresholdIsMin, "wrap"); - jPanel2.add(slider, "grow"); - jPanel2.add(thresholdValue, "grow"); - this.add(jPanel1, java.awt.BorderLayout.SOUTH); - this.add(jPanel2, java.awt.BorderLayout.CENTER); - this.validate(); - } - - protected void seqAssociated_actionPerformed(ActionEvent arg0) - { - adjusting = true; - String cursel = (String) getAnnotations().getSelectedItem(); - boolean isvalid = false, isseqs = seqAssociated.isSelected(); - this.getAnnotations().removeAllItems(); - for (String anitem : getAnnotationItems(seqAssociated.isSelected())) - { - if (anitem.equals(cursel) || (isseqs && cursel.startsWith(anitem))) - { - isvalid = true; - cursel = anitem; - } - this.getAnnotations().addItem(anitem); - } - adjusting = false; - if (isvalid) - { - this.getAnnotations().setSelectedItem(cursel); - } - else - { - if (getAnnotations().getItemCount() > 0) - { - getAnnotations().setSelectedIndex(0); - } - } - } - - - void changeColumnSelection() - { - // Check if combobox is still adjusting - if (adjusting) - { - return; - } - - setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations() - .getSelectedIndex()]]); - - int aboveThreshold = -1; - if (getThreshold().getSelectedIndex() == 1) - { - aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD; - } - else if (getThreshold().getSelectedIndex() == 2) - { - aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD; - } - - slider.setEnabled(true); - thresholdValue.setEnabled(true); - thresholdIsMin.setEnabled(true); - - if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD) - { - slider.setEnabled(false); - thresholdValue.setEnabled(false); - thresholdValue.setText(""); - thresholdIsMin.setEnabled(false); - } - else if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD - && getCurrentAnnotation().threshold == null) - { - getCurrentAnnotation() - .setThreshold(new jalview.datamodel.GraphLine( - (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f, - "Threshold", Color.black)); - } - - if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD) - { - adjusting = true; - 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)); - thresholdValue.setText(getCurrentAnnotation().threshold.value + ""); - slider.setMajorTickSpacing((int) (range / 10f)); - slider.setEnabled(true); - thresholdValue.setEnabled(true); - adjusting = false; - } - - markColumnsContaining(getCurrentAnnotation(), aboveThreshold); - av.setCurrentAnnotationColumnSelectionState(this); - ap.alignmentChanged(); - // ensure all associated views (overviews, structures, etc) are notified of - // updated colours. - ap.paintAlignment(true); - } - - public boolean markColumnsContaining( - AlignmentAnnotation currentAnnotation, int thresholdComparisonType) - { - try - { - if (currentAnnotation != null) - { - Annotation[] annotations = currentAnnotation.annotations; - ColumnSelection cs = av.getColumnSelection(); - cs.clear(); - if (thresholdComparisonType == AnnotationColourGradient.NO_THRESHOLD) - { - int count = 0; - do - { - if (annotations[count] != null) - { - if (currentAnnotation.label.equals("Secondary Structure") - && annotations[count].secondaryStructure != ' ') - { - cs.addElement(count); - } - else if (currentAnnotation.label - .equals("Iron Sulphur Contacts")) - { - cs.addElement(count); - } - else if (annotations[count].value != 0.0) - { - cs.addElement(count); - } - - } - count++; - } while (count < annotations.length); - } - else - { - int count = 0; - do - { - if (annotations[count] != null) - { - if (thresholdComparisonType == AnnotationColourGradient.ABOVE_THRESHOLD) - { - if (annotations[count].value > currentAnnotation.threshold.value) - { - cs.addElement(count); - } - } - else if (thresholdComparisonType == AnnotationColourGradient.BELOW_THRESHOLD) - { - if (annotations[count].value < currentAnnotation.threshold.value) - { - cs.addElement(count); - } - } - - } - count++; - } while (count < annotations.length); - } - } - - return true; - } catch (Exception e) - { - e.printStackTrace(); - return false; - } - } - - public void ok_actionPerformed(ActionEvent e) - { - changeColumnSelection(); - try - { - frame.setClosed(true); - } catch (Exception ex) - { - } - } - - public void cancel_actionPerformed(ActionEvent e) - { - reset(); - // ensure all original colouring is propagated to listeners. - ap.paintAlignment(true); - try - { - frame.setClosed(true); - } catch (Exception ex) - { - } - } - - void reset() - { - av.getColumnSelection().clear(); - } - - public void thresholdCheck_actionPerformed(ActionEvent e) - { - changeColumnSelection(); - } - - public void annotations_actionPerformed(ActionEvent e) - { - changeColumnSelection(); - } - - public void threshold_actionPerformed(ActionEvent e) - { - changeColumnSelection(); - } - - public void thresholdValue_actionPerformed(ActionEvent e) - { - try - { - float f = Float.parseFloat(thresholdValue.getText()); - slider.setValue((int) (f * 1000)); - changeColumnSelection(); - } catch (NumberFormatException ex) - { - } - } - - public void valueChanged(boolean updateAllAnnotation) - { - getCurrentAnnotation().threshold.value = slider.getValue() / 1000f; - changeColumnSelection(); - // propagateSeqAssociatedThreshold(updateAllAnnotation); - ap.paintAlignment(false); - } - - private void propagateSeqAssociatedThreshold(boolean allAnnotation) - { - if (getCurrentAnnotation().sequenceRef == null - || getCurrentAnnotation().threshold == null) - { - return; - } - - - float thr = getCurrentAnnotation().threshold.value; - for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++) - { - AlignmentAnnotation aa = av.getAlignment().getAlignmentAnnotation()[i]; - if (aa.label.equals(getCurrentAnnotation().label) - && (getCurrentAnnotation().getCalcId() == null ? aa - .getCalcId() == null : getCurrentAnnotation() - .getCalcId() - .equals(aa.getCalcId()))) - { - if (aa.threshold == null) - { - aa.threshold = new GraphLine(getCurrentAnnotation().threshold); - } - else - { - aa.threshold.value = thr; - } - } - } - } - - public void currentColours_actionPerformed(ActionEvent e) - { - if (currentColours.isSelected()) - { - reset(); - } - - maxColour.setEnabled(!currentColours.isSelected()); - minColour.setEnabled(!currentColours.isSelected()); - - changeColumnSelection(); - } - - public void thresholdIsMin_actionPerformed(ActionEvent actionEvent) - { - changeColumnSelection(); - } - - public jalview.datamodel.AlignmentAnnotation getCurrentAnnotation() - { - return currentAnnotation; - } - - public void setCurrentAnnotation( - jalview.datamodel.AlignmentAnnotation currentAnnotation) - { - this.currentAnnotation = currentAnnotation; - } - - public JComboBox getThreshold() - { - return threshold; - } - - public void setThreshold(JComboBox threshold) - { - this.threshold = threshold; - } - - public JComboBox getAnnotations() - { - return annotations; - } - - public void setAnnotations(JComboBox annotations) - { - this.annotations = annotations; - } - -} diff --git a/src/jalview/gui/AnnotationRowFilter.java b/src/jalview/gui/AnnotationRowFilter.java new file mode 100644 index 0000000..9e205c4 --- /dev/null +++ b/src/jalview/gui/AnnotationRowFilter.java @@ -0,0 +1,450 @@ +package jalview.gui; + +import jalview.api.AnnotationRowFilterI; +import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.Annotation; +import jalview.datamodel.ColumnSelection; +import jalview.datamodel.GraphLine; +import jalview.datamodel.SequenceGroup; +import jalview.schemes.AnnotationColourGradient; +import jalview.util.MessageManager; + +import java.awt.event.ActionEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.Vector; + +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JInternalFrame; +import javax.swing.JPanel; +import javax.swing.JSlider; +import javax.swing.JTextField; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +@SuppressWarnings("serial") +public abstract class AnnotationRowFilter extends JPanel implements + AnnotationRowFilterI +{ + protected AlignViewport av; + + protected AlignmentPanel ap; + + 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 JSlider slider = new JSlider(); + + protected JTextField thresholdValue = new JTextField(20); + + protected JInternalFrame frame; + /** + * enabled if the user is dragging the slider - try to keep updates to a + * minimun + */ + protected boolean sliderDragging = false; + + protected void addSliderChangeListener() + { + + slider.addChangeListener(new ChangeListener() + { + @Override + public void stateChanged(ChangeEvent evt) + { + if (!adjusting) + { + thresholdValue.setText((slider.getValue() / 1000f) + ""); + valueChanged(!sliderDragging); + } + } + }); + } + + protected void addSliderMouseListeners() + { + + slider.addMouseListener(new MouseAdapter() + { + @Override + public void mousePressed(MouseEvent e) + { + sliderDragging = true; + super.mousePressed(e); + } + + @Override + public void mouseDragged(MouseEvent e) + { + sliderDragging = true; + super.mouseDragged(e); + } + + @Override + public void mouseReleased(MouseEvent evt) + { + if (sliderDragging) + { + sliderDragging = false; + valueChanged(true); + } + ap.paintAlignment(true); + } + }); + } + + + public AnnotationRowFilter(AlignViewport av, final AlignmentPanel ap) + { + this.av = av; + this.ap = ap; + } + + public AnnotationRowFilter() + { + + } + + @Override + public Vector getAnnotationItems(boolean isSeqAssociated) + { + 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++) + { + if (av.getAlignment().getAlignmentAnnotation()[i].sequenceRef == null) + { + if (isSeqAssociated) + { + continue; + } + } + else + { + enableSeqAss = true; + } + String label = av.getAlignment().getAlignmentAnnotation()[i].label; + if (!list.contains(label)) + { + anmap[list.size()] = i; + list.add(label); + + } + else + { + if (!isSeqAssociated) + { + anmap[list.size()] = i; + list.add(label + "_" + (index++)); + } + } + } + // seqAssociated.setEnabled(enableSeqAss); + this.annmap = new int[list.size()]; + System.arraycopy(anmap, 0, this.annmap, 0, this.annmap.length); + return list; + } + + protected int getSelectedThresholdItem(int indexValue) + { + int selectedThresholdItem = -1; + if (indexValue == 1) + { + selectedThresholdItem = AnnotationColourGradient.ABOVE_THRESHOLD; + } + else if (indexValue == 2) + { + selectedThresholdItem = AnnotationColourGradient.BELOW_THRESHOLD; + } + return selectedThresholdItem; + } + + public void modelChanged() + { + seqAssociated.setEnabled(enableSeqAss); + } + + public void ok_actionPerformed(ActionEvent e) + { + updateView(); + try + { + frame.setClosed(true); + } catch (Exception ex) + { + } + } + + public void cancel_actionPerformed(ActionEvent e) + { + reset(); + ap.paintAlignment(true); + try + { + frame.setClosed(true); + } catch (Exception ex) + { + } + } + + public void thresholdCheck_actionPerformed(ActionEvent e) + { + updateView(); + } + + public void annotations_actionPerformed(ActionEvent e) + { + updateView(); + } + + public void threshold_actionPerformed(ActionEvent e) + { + updateView(); + } + + public void thresholdValue_actionPerformed(ActionEvent e) + { + try + { + float f = Float.parseFloat(thresholdValue.getText()); + slider.setValue((int) (f * 1000)); + updateView(); + } catch (NumberFormatException ex) + { + } + } + + public void thresholdIsMin_actionPerformed(ActionEvent actionEvent) + { + updateView(); + } + + protected void populateThresholdComboBox(JComboBox threshold) + { + 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")); + } + + protected void seqAssociated_actionPerformed(ActionEvent arg0, + JComboBox annotations, JCheckBox seqAssociated) + { + adjusting = true; + String cursel = (String) annotations.getSelectedItem(); + boolean isvalid = false, isseqs = seqAssociated.isSelected(); + annotations.removeAllItems(); + for (String anitem : getAnnotationItems(seqAssociated.isSelected())) + { + if (anitem.equals(cursel) || (isseqs && cursel.startsWith(anitem))) + { + isvalid = true; + cursel = anitem; + } + annotations.addItem(anitem); + } + adjusting = false; + if (isvalid) + { + annotations.setSelectedItem(cursel); + } + else + { + if (annotations.getItemCount() > 0) + { + annotations.setSelectedIndex(0); + } + } + } + + protected void propagateSeqAssociatedThreshold(boolean allAnnotation, + AlignmentAnnotation annotation) + { + if (annotation.sequenceRef == null || annotation.threshold == null) + { + return; + } + + float thr = annotation.threshold.value; + for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++) + { + AlignmentAnnotation aa = av.getAlignment().getAlignmentAnnotation()[i]; + if (aa.label.equals(annotation.label) + && (annotation.getCalcId() == null ? aa.getCalcId() == null + : annotation.getCalcId().equals(aa.getCalcId()))) + { + if (aa.threshold == null) + { + aa.threshold = new GraphLine(annotation.threshold); + } + else + { + aa.threshold.value = thr; + } + } + } + } + + protected boolean colorAlignmContaining( + AlignmentAnnotation currentAnnotation, int selectedThresholdItem) + { + + 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()); + + if (currentAnnotation.graphMin == 0f + && currentAnnotation.graphMax == 0f) + { + acg.setPredefinedColours(true); + } + + acg.thresholdIsMinMax = thresholdIsMin.isSelected(); + + av.setGlobalColourScheme(acg); + + if (av.getAlignment().getGroups() != null) + { + + for (SequenceGroup sg : ap.av.getAlignment().getGroups()) + { + if (sg.cs == null) + { + continue; + } + + if (currentColours.isSelected()) + { + sg.cs = new AnnotationColourGradient(currentAnnotation, sg.cs, + selectedThresholdItem); + ((AnnotationColourGradient) sg.cs).setSeqAssociated(seqAssociated + .isSelected()); + + } + else + { + sg.cs = new AnnotationColourGradient(currentAnnotation, + minColour.getBackground(), maxColour.getBackground(), + selectedThresholdItem); + ((AnnotationColourGradient) sg.cs).setSeqAssociated(seqAssociated + .isSelected()); + } + + } + } + return false; + } + + protected boolean markColumnsContaining( + AlignmentAnnotation currentAnnotation, int thresholdComparisonType) + { + try + { + if (currentAnnotation != null) + { + Annotation[] annotations = currentAnnotation.annotations; + ColumnSelection cs = av.getColumnSelection(); + cs.clear(); + if (thresholdComparisonType == AnnotationColourGradient.NO_THRESHOLD) + { + int count = 0; + do + { + if (annotations[count] != null) + { + if (currentAnnotation.label.equals("Secondary Structure") + && annotations[count].secondaryStructure != ' ') + { + cs.addElement(count); + } + else if (currentAnnotation.label + .equals("Iron Sulphur Contacts")) + { + cs.addElement(count); + } + else if (annotations[count].value != 0.0) + { + cs.addElement(count); + } + + } + count++; + } while (count < annotations.length); + } + else + { + int count = 0; + do + { + if (annotations[count] != null) + { + if (thresholdComparisonType == AnnotationColourGradient.ABOVE_THRESHOLD) + { + if (annotations[count].value > currentAnnotation.threshold.value) + { + cs.addElement(count); + } + } + else if (thresholdComparisonType == AnnotationColourGradient.BELOW_THRESHOLD) + { + if (annotations[count].value < currentAnnotation.threshold.value) + { + cs.addElement(count); + } + } + + } + count++; + } while (count < annotations.length); + } + } + + return true; + } catch (Exception e) + { + e.printStackTrace(); + return false; + } + } + + public jalview.datamodel.AlignmentAnnotation getCurrentAnnotation() + { + return currentAnnotation; + } + + public void setCurrentAnnotation( + jalview.datamodel.AlignmentAnnotation currentAnnotation) + { + this.currentAnnotation = currentAnnotation; + } + +}