From b35507f7bb2af382a19ba88a005ccbb27ffaa802 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Fri, 27 Apr 2007 08:50:06 +0000 Subject: [PATCH] Annotation gradient will use direct colours if no graph exists --- src/jalview/gui/AnnotationColourChooser.java | 77 ++++++++++++--------- src/jalview/schemes/AnnotationColourGradient.java | 2 +- 2 files changed, 45 insertions(+), 34 deletions(-) diff --git a/src/jalview/gui/AnnotationColourChooser.java b/src/jalview/gui/AnnotationColourChooser.java index 31c7ba7..83a8a12 100755 --- a/src/jalview/gui/AnnotationColourChooser.java +++ b/src/jalview/gui/AnnotationColourChooser.java @@ -27,6 +27,7 @@ import javax.swing.event.*; import jalview.datamodel.*; import jalview.schemes.*; +import java.awt.Dimension; public class AnnotationColourChooser extends JPanel @@ -63,12 +64,6 @@ public class AnnotationColourChooser frame.setLayer(JLayeredPane.PALETTE_LAYER); Desktop.addInternalFrame(frame, "Colour by Annotation", 480, 145); - try - { - jbInit(); - } - catch (Exception ex) - {} slider.addChangeListener(new ChangeListener() { @@ -107,18 +102,30 @@ public class AnnotationColourChooser } adjusting = true; + Vector list = new Vector(); + int index = 1; for (int i = 0; i < av.alignment.getAlignmentAnnotation().length; i++) { - if (av.alignment.getAlignmentAnnotation()[i].graph > 0) - { - annotations.addItem(av.alignment.getAlignmentAnnotation()[i].label); - } + String label = av.alignment.getAlignmentAnnotation()[i].label; + if (!list.contains(label)) + list.addElement(label); + else + list.addElement(label+"_"+(index++)); } + annotations = new JComboBox(list); + threshold.addItem("No Threshold"); threshold.addItem("Above Threshold"); threshold.addItem("Below Threshold"); + try + { + jbInit(); + } + catch (Exception ex) + {} + adjusting = false; changeColour(); @@ -217,9 +224,9 @@ public class AnnotationColourChooser slider.setBackground(Color.white); slider.setEnabled(false); slider.setOpaque(false); - slider.setPreferredSize(new Dimension(150, 32)); + slider.setPreferredSize(new Dimension(100, 32)); thresholdValue.setEnabled(false); - thresholdValue.setColumns(10); + thresholdValue.setColumns(7); jPanel3.setBackground(Color.white); currentColours.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); currentColours.setOpaque(false); @@ -231,6 +238,15 @@ public class AnnotationColourChooser currentColours_actionPerformed(e); } }); + thresholdIsMin.setBackground(Color.white); + thresholdIsMin.setText("Threshold is Min/Max"); + thresholdIsMin.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent actionEvent) + { + thresholdIsMin_actionPerformed(actionEvent); + } + }); jPanel1.add(ok); jPanel1.add(cancel); jPanel2.add(annotations); @@ -241,11 +257,12 @@ public class AnnotationColourChooser jPanel3.add(threshold); jPanel3.add(slider); jPanel3.add(thresholdValue); + jPanel3.add(thresholdIsMin); this.add(jPanel1, java.awt.BorderLayout.SOUTH); this.add(jPanel2, java.awt.BorderLayout.NORTH); } - JComboBox annotations = new JComboBox(); + JComboBox annotations; JPanel minColour = new JPanel(); JPanel maxColour = new JPanel(); JButton ok = new JButton(); @@ -260,6 +277,7 @@ public class AnnotationColourChooser JSlider slider = new JSlider(); JTextField thresholdValue = new JTextField(20); JCheckBox currentColours = new JCheckBox(); + JCheckBox thresholdIsMin = new JCheckBox(); public void minColour_actionPerformed() { @@ -295,27 +313,8 @@ public class AnnotationColourChooser return; } - // We removed the non-graph annotations when filling the combobox - // so allow for them again here - int nograph = 0, graph = -1; - for (int i = 0; i < av.alignment.getAlignmentAnnotation().length; i++) - { - if (av.alignment.getAlignmentAnnotation()[i].graph == 0) - { - nograph++; - } - else - { - graph++; - } - - if (graph == annotations.getSelectedIndex()) - { - break; - } - } - currentAnnotation = av.alignment.getAlignmentAnnotation()[graph + nograph]; + currentAnnotation = av.alignment.getAlignmentAnnotation()[annotations.getSelectedIndex()]; int aboveThreshold = -1; if (threshold.getSelectedItem().equals("Above Threshold")) @@ -379,6 +378,13 @@ public class AnnotationColourChooser aboveThreshold); } + if(currentAnnotation.graphMin==0f&& currentAnnotation.graphMax==0f) + { + acg.predefinedColours = true; + } + + acg.thresholdIsMinMax = thresholdIsMin.isSelected(); + av.setGlobalColourScheme(acg); if (av.alignment.getGroups() != null) @@ -503,4 +509,9 @@ public class AnnotationColourChooser changeColour(); } + public void thresholdIsMin_actionPerformed(ActionEvent actionEvent) + { + changeColour(); + } + } diff --git a/src/jalview/schemes/AnnotationColourGradient.java b/src/jalview/schemes/AnnotationColourGradient.java index ff6673a..6a7a3cf 100755 --- a/src/jalview/schemes/AnnotationColourGradient.java +++ b/src/jalview/schemes/AnnotationColourGradient.java @@ -160,7 +160,7 @@ public class AnnotationColourGradient && !jalview.util.Comparison.isGap(c)) { - if (predefinedColours) + if (predefinedColours) { if(annotation.annotations[j].colour != null) return annotation.annotations[j].colour; -- 1.7.10.2