X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAnnotationColourChooser.java;h=31c7ba7cad7912d4c2948227eea17f08babda588;hb=c54ce58a000089a3f45f5978dd10ed41bfedfc4f;hp=49e835de3420d933ef681eb44592c9465041c521;hpb=09003bd97d75ad14cd000fc581d6ec93b7a08bcb;p=jalview.git diff --git a/src/jalview/gui/AnnotationColourChooser.java b/src/jalview/gui/AnnotationColourChooser.java index 49e835d..31c7ba7 100755 --- a/src/jalview/gui/AnnotationColourChooser.java +++ b/src/jalview/gui/AnnotationColourChooser.java @@ -1,31 +1,32 @@ /* -* Jalview - A Sequence Alignment Editor and Viewer -* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle -* -* This program 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 2 -* of the License, or (at your option) any later version. -* -* This program 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 this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -*/ + * Jalview - A Sequence Alignment Editor and Viewer + * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * + * This program 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 2 + * of the License, or (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ package jalview.gui; -import javax.swing.*; -import java.awt.event.*; +import java.util.*; + import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.event.*; +import jalview.datamodel.*; import jalview.schemes.*; -import javax.swing.event.*; -import java.util.*; -import jalview.datamodel.SequenceGroup; public class AnnotationColourChooser extends JPanel @@ -36,8 +37,9 @@ public class AnnotationColourChooser ColourSchemeI oldcs; Hashtable oldgroupColours; jalview.datamodel.AlignmentAnnotation currentAnnotation; + boolean adjusting = false; - public AnnotationColourChooser(AlignViewport av, AlignmentPanel ap) + public AnnotationColourChooser(AlignViewport av, final AlignmentPanel ap) { oldcs = av.getGlobalColourScheme(); if (av.alignment.getGroups() != null) @@ -48,7 +50,10 @@ public class AnnotationColourChooser for (int g = 0; g < allGroups.size(); g++) { sg = (SequenceGroup) allGroups.get(g); - oldgroupColours.put(sg, sg.cs); + if (sg.cs != null) + { + oldgroupColours.put(sg, sg.cs); + } } } this.av = av; @@ -56,7 +61,7 @@ public class AnnotationColourChooser frame = new JInternalFrame(); frame.setContentPane(this); frame.setLayer(JLayeredPane.PALETTE_LAYER); - Desktop.addInternalFrame(frame, "Colour by Annotation", 480, 145, false); + Desktop.addInternalFrame(frame, "Colour by Annotation", 480, 145); try { @@ -69,13 +74,25 @@ public class AnnotationColourChooser { public void stateChanged(ChangeEvent evt) { - thresholdValue.setText( ( (float) slider.getValue() / 1000f) + ""); - valueChanged(); + if (!adjusting) + { + thresholdValue.setText( ( (float) slider.getValue() / 1000f) + ""); + valueChanged(); + } } }); + slider.addMouseListener(new MouseAdapter() + { + public void mouseReleased(MouseEvent evt) + { + ap.paintAlignment(true); + } + }); if (av.alignment.getAlignmentAnnotation() == null) + { return; + } if (oldcs instanceof AnnotationColourGradient) { @@ -89,16 +106,23 @@ public class AnnotationColourChooser maxColour.setBackground(Color.red); } + adjusting = true; for (int i = 0; i < av.alignment.getAlignmentAnnotation().length; i++) { if (av.alignment.getAlignmentAnnotation()[i].graph > 0) + { annotations.addItem(av.alignment.getAlignmentAnnotation()[i].label); + } } threshold.addItem("No Threshold"); threshold.addItem("Above Threshold"); threshold.addItem("Below Threshold"); + adjusting = false; + + changeColour(); + } public AnnotationColourChooser() @@ -117,24 +141,31 @@ public class AnnotationColourChooser throws Exception { minColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); - minColour.setToolTipText(""); - minColour.setMargin(new Insets(2, 2, 2, 2)); - minColour.setText("Min Colour"); - minColour.addActionListener(new ActionListener() + minColour.setBorder(BorderFactory.createEtchedBorder()); + minColour.setPreferredSize(new Dimension(40, 20)); + minColour.setToolTipText("Minimum Colour"); + minColour.addMouseListener(new MouseAdapter() { - public void actionPerformed(ActionEvent e) + public void mousePressed(MouseEvent e) { - minColour_actionPerformed(e); + if (minColour.isEnabled()) + { + minColour_actionPerformed(); + } } }); maxColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); - maxColour.setMargin(new Insets(2, 2, 2, 2)); - maxColour.setText("Max Colour"); - maxColour.addActionListener(new ActionListener() + maxColour.setBorder(BorderFactory.createEtchedBorder()); + maxColour.setPreferredSize(new Dimension(40, 20)); + maxColour.setToolTipText("Maximum Colour"); + maxColour.addMouseListener(new MouseAdapter() { - public void actionPerformed(ActionEvent e) + public void mousePressed(MouseEvent e) { - maxColour_actionPerformed(e); + if (maxColour.isEnabled()) + { + maxColour_actionPerformed(); + } } }); ok.setOpaque(false); @@ -181,10 +212,12 @@ public class AnnotationColourChooser thresholdValue_actionPerformed(e); } }); + slider.setPaintLabels(false); slider.setPaintTicks(true); slider.setBackground(Color.white); slider.setEnabled(false); slider.setOpaque(false); + slider.setPreferredSize(new Dimension(150, 32)); thresholdValue.setEnabled(false); thresholdValue.setColumns(10); jPanel3.setBackground(Color.white); @@ -213,8 +246,8 @@ public class AnnotationColourChooser } JComboBox annotations = new JComboBox(); - JButton minColour = new JButton(); - JButton maxColour = new JButton(); + JPanel minColour = new JPanel(); + JPanel maxColour = new JPanel(); JButton ok = new JButton(); JButton cancel = new JButton(); JPanel jPanel1 = new JPanel(); @@ -228,24 +261,28 @@ public class AnnotationColourChooser JTextField thresholdValue = new JTextField(20); JCheckBox currentColours = new JCheckBox(); - public void minColour_actionPerformed(ActionEvent e) + public void minColour_actionPerformed() { Color col = JColorChooser.showDialog(this, "Select Colour for Minimum Value", minColour.getBackground()); if (col != null) + { minColour.setBackground(col); + } minColour.repaint(); changeColour(); } - public void maxColour_actionPerformed(ActionEvent e) + public void maxColour_actionPerformed() { Color col = JColorChooser.showDialog(this, "Select Colour for Maximum Value", maxColour.getBackground()); if (col != null) + { maxColour.setBackground(col); + } maxColour.repaint(); changeColour(); } @@ -253,8 +290,10 @@ public class AnnotationColourChooser void changeColour() { // Check if combobox is still adjusting - if (threshold.getSelectedIndex() == -1) + if (adjusting) + { return; + } // We removed the non-graph annotations when filling the combobox // so allow for them again here @@ -262,25 +301,37 @@ public class AnnotationColourChooser 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]; int aboveThreshold = -1; if (threshold.getSelectedItem().equals("Above Threshold")) + { aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD; + } else if (threshold.getSelectedItem().equals("Below Threshold")) + { aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD; + } + + slider.setEnabled(true); + thresholdValue.setEnabled(true); if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD) { - currentAnnotation.threshold = null; slider.setEnabled(false); thresholdValue.setEnabled(false); thresholdValue.setText(""); @@ -293,6 +344,11 @@ public class AnnotationColourChooser currentAnnotation.graphMin) / 2f, "Threshold", Color.black)); + } + + if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD) + { + adjusting = true; float range = currentAnnotation.graphMax * 1000 - currentAnnotation.graphMin * 1000; @@ -301,23 +357,27 @@ public class AnnotationColourChooser slider.setValue( (int) (currentAnnotation.threshold.value * 1000)); thresholdValue.setText(currentAnnotation.threshold.value + ""); slider.setMajorTickSpacing( (int) (range / 10f)); - slider.setMinorTickSpacing( (int) (range / 100f)); 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); + } av.setGlobalColourScheme(acg); @@ -335,20 +395,24 @@ public class AnnotationColourChooser } if (currentColours.isSelected()) + { sg.cs = new AnnotationColourGradient( currentAnnotation, sg.cs, aboveThreshold); + } else + { sg.cs = new AnnotationColourGradient( currentAnnotation, minColour.getBackground(), maxColour.getBackground(), aboveThreshold); + } } } - ap.repaint(); + ap.paintAlignment(false); } public void ok_actionPerformed(ActionEvent e) @@ -373,7 +437,6 @@ public class AnnotationColourChooser {} } - void reset() { av.setGlobalColourScheme(oldcs); @@ -384,7 +447,7 @@ public class AnnotationColourChooser for (int g = 0; g < allGroups.size(); g++) { sg = (SequenceGroup) allGroups.get(g); - sg.cs = (ColourSchemeI)oldgroupColours.get(sg); + sg.cs = (ColourSchemeI) oldgroupColours.get(sg); } } } @@ -396,8 +459,6 @@ public class AnnotationColourChooser public void annotations_actionPerformed(ActionEvent e) { - if(currentAnnotation!=null) - currentAnnotation.threshold = null; changeColour(); } @@ -419,13 +480,19 @@ public class AnnotationColourChooser public void valueChanged() { - currentAnnotation.threshold.value = (float)slider.getValue()/1000f; - ap.repaint(); + if (currentColours.isSelected() + && ! (av.getGlobalColourScheme() instanceof AnnotationColourGradient)) + { + changeColour(); + } + + currentAnnotation.threshold.value = (float) slider.getValue() / 1000f; + ap.paintAlignment(false); } public void currentColours_actionPerformed(ActionEvent e) { - if(currentColours.isSelected()) + if (currentColours.isSelected()) { reset(); }