From: amwaterhouse Date: Wed, 8 Feb 2006 15:22:23 +0000 (+0000) Subject: Colour above or below threshold X-Git-Tag: Root_VamJalview_2_07b+~163 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=df227ed4042d4c9fa2affb391fa09b662f3b8a2a;p=jalview.git Colour above or below threshold --- diff --git a/src/jalview/gui/AnnotationColourChooser.java b/src/jalview/gui/AnnotationColourChooser.java index c3e30fb..06040a6 100755 --- a/src/jalview/gui/AnnotationColourChooser.java +++ b/src/jalview/gui/AnnotationColourChooser.java @@ -69,6 +69,10 @@ public class AnnotationColourChooser annotations.addItem(av.alignment.getAlignmentAnnotation()[i].label); } + threshold.addItem("No Threshold"); + threshold.addItem("Above Threshold"); + threshold.addItem("Below Threshold"); + } public AnnotationColourChooser() @@ -107,19 +111,6 @@ public class AnnotationColourChooser maxColour_actionPerformed(e); } }); - thresholdCheck.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); - thresholdCheck.setOpaque(false); - thresholdCheck.setHorizontalTextPosition(SwingConstants.LEADING); - thresholdCheck.setSelectedIcon(null); - thresholdCheck.setText("Above Threshold"); - thresholdCheck.setBounds(new Rectangle(329, 6, 126, 23)); - thresholdCheck.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - thresholdCheck_actionPerformed(e); - } - }); ok.setOpaque(false); ok.setText("OK"); ok.addActionListener(new ActionListener() @@ -150,12 +141,20 @@ public class AnnotationColourChooser }); jPanel1.setBackground(Color.white); jPanel2.setBackground(Color.white); + threshold.setBounds(new Rectangle(328, 6, 125, 22)); + threshold.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + threshold_actionPerformed(e); + } + }); jPanel1.add(ok); jPanel1.add(cancel); jPanel2.add(annotations); jPanel2.add(minColour); jPanel2.add(maxColour); - jPanel2.add(thresholdCheck); + jPanel2.add(threshold); this.add(jPanel1, java.awt.BorderLayout.SOUTH); this.add(jPanel2, java.awt.BorderLayout.CENTER); } @@ -163,13 +162,12 @@ public class AnnotationColourChooser JComboBox annotations = new JComboBox(); JButton minColour = new JButton(); JButton maxColour = new JButton(); - JCheckBox thresholdCheck = new JCheckBox(); JButton ok = new JButton(); JButton cancel = new JButton(); JPanel jPanel1 = new JPanel(); JPanel jPanel2 = new JPanel(); BorderLayout borderLayout1 = new BorderLayout(); - + JComboBox threshold = new JComboBox(); public void minColour_actionPerformed(ActionEvent e) { @@ -195,6 +193,10 @@ public class AnnotationColourChooser void changeColour() { + // Check if combobox is still adjusting + if(threshold.getSelectedIndex()==-1) + return; + // We removed the non-graph annotations when filling the combobox // so allow for them again here int nograph = 0, graph = -1; @@ -212,16 +214,26 @@ public class AnnotationColourChooser jalview.datamodel.AlignmentAnnotation aa = av.alignment.getAlignmentAnnotation()[graph+nograph]; - AnnotationColourGradient acg = new AnnotationColourGradient(aa, - minColour.getBackground(), - maxColour.getBackground(), - thresholdCheck.isSelected()); - if(thresholdCheck.isSelected() && aa.graphLines==null) + int aboveThreshold = -1; + if(threshold.getSelectedItem().equals("Above Threshold")) + aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD; + else if(threshold.getSelectedItem().equals("Below Threshold")) + aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD; + + if(aboveThreshold!=AnnotationColourGradient.NO_THRESHOLD && aa.graphLines==null) { aa.addGraphLine(new jalview.datamodel.GraphLine((aa.graphMax-aa.graphMin)/2f, "Threshold", Color.black)); } + AnnotationColourGradient acg = new AnnotationColourGradient(aa, + minColour.getBackground(), + maxColour.getBackground(), + aboveThreshold ); + + + + av.setGlobalColourScheme(acg); ap.repaint(); @@ -253,4 +265,9 @@ public class AnnotationColourChooser changeColour(); } + public void threshold_actionPerformed(ActionEvent e) + { + changeColour(); + } + } diff --git a/src/jalview/schemes/AnnotationColourGradient.java b/src/jalview/schemes/AnnotationColourGradient.java index bc44559..5825612 100755 --- a/src/jalview/schemes/AnnotationColourGradient.java +++ b/src/jalview/schemes/AnnotationColourGradient.java @@ -24,8 +24,14 @@ import jalview.datamodel.*; public class AnnotationColourGradient extends ResidueColourScheme { + public static int NO_THRESHOLD = -1; + public static int BELOW_THRESHOLD = 0; + public static int ABOVE_THRESHOLD = 1; + AlignmentAnnotation annotation; - boolean aboveAnnotationThreshold = false; + int aboveAnnotationThreshold = -1; + + GraphLine annotationThreshold; float r1, g1, b1, rr, gg, bb, dr, dg, db; float range; @@ -34,12 +40,15 @@ public class AnnotationColourGradient extends ResidueColourScheme * Creates a new AnnotationColourGradient object. */ public AnnotationColourGradient(AlignmentAnnotation annotation, - Color minColour, Color maxColour, boolean aboveThreshold) + Color minColour, Color maxColour, int aboveThreshold) { this.annotation = annotation; aboveAnnotationThreshold = aboveThreshold; + if(aboveThreshold!=NO_THRESHOLD && annotation.graphLines!=null) + annotationThreshold = annotation.getGraphLine(0); + r1 = minColour.getRed(); g1 = minColour.getGreen(); b1 = minColour.getBlue(); @@ -91,8 +100,9 @@ public class AnnotationColourGradient extends ResidueColourScheme currentColour = Color.white; else { - if(!aboveAnnotationThreshold || (annotation.graphLines!=null - && annotation.annotations[j].value>=annotation.getGraphLine(0).value)) + if( aboveAnnotationThreshold==NO_THRESHOLD + || (annotationThreshold!=null && aboveAnnotationThreshold==ABOVE_THRESHOLD && annotation.annotations[j].value>=annotationThreshold.value) + || (annotationThreshold!=null && aboveAnnotationThreshold==BELOW_THRESHOLD && annotation.annotations[j].value<=annotationThreshold.value)) { dr = rr * ((annotation.annotations[j].value-annotation.graphMin) / range )