X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAnnotationColourChooser.java;h=ba76858d39d049f526df041f1b5393585365fa8b;hb=d704670a936df11fbaf75abbb6d07493d70993a9;hp=0b6f8d8fcc6fc033605ccb70526889940e511958;hpb=7f70774817cb744dea926205d2d9c2e7f381e827;p=jalview.git diff --git a/src/jalview/gui/AnnotationColourChooser.java b/src/jalview/gui/AnnotationColourChooser.java index 0b6f8d8..ba76858 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 @@ -49,8 +50,10 @@ public class AnnotationColourChooser for (int g = 0; g < allGroups.size(); g++) { sg = (SequenceGroup) allGroups.get(g); - if(sg.cs!=null) + if (sg.cs != null) + { oldgroupColours.put(sg, sg.cs); + } } } this.av = av; @@ -71,7 +74,7 @@ public class AnnotationColourChooser { public void stateChanged(ChangeEvent evt) { - if(!adjusting) + if (!adjusting) { thresholdValue.setText( ( (float) slider.getValue() / 1000f) + ""); valueChanged(); @@ -80,7 +83,9 @@ public class AnnotationColourChooser }); if (av.alignment.getAlignmentAnnotation() == null) + { return; + } if (oldcs instanceof AnnotationColourGradient) { @@ -98,7 +103,9 @@ public class AnnotationColourChooser 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"); @@ -127,24 +134,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); @@ -225,8 +239,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(); @@ -240,24 +254,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(); } @@ -266,7 +284,9 @@ public class AnnotationColourChooser { // Check if combobox is still adjusting if (adjusting) + { return; + } // We removed the non-graph annotations when filling the combobox // so allow for them again here @@ -274,21 +294,31 @@ 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); @@ -309,7 +339,7 @@ public class AnnotationColourChooser Color.black)); } - if(aboveThreshold != AnnotationColourGradient.NO_THRESHOLD) + if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD) { adjusting = true; float range = currentAnnotation.graphMax * 1000 - @@ -327,16 +357,20 @@ public class AnnotationColourChooser 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); @@ -354,15 +388,19 @@ 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); + } } } @@ -392,7 +430,6 @@ public class AnnotationColourChooser {} } - void reset() { av.setGlobalColourScheme(oldcs); @@ -403,7 +440,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); } } } @@ -437,18 +474,18 @@ public class AnnotationColourChooser public void valueChanged() { if (currentColours.isSelected() - && !(av.getGlobalColourScheme() instanceof AnnotationColourGradient)) + && ! (av.getGlobalColourScheme() instanceof AnnotationColourGradient)) { changeColour(); } - currentAnnotation.threshold.value = (float)slider.getValue()/1000f; + currentAnnotation.threshold.value = (float) slider.getValue() / 1000f; ap.repaint(); } public void currentColours_actionPerformed(ActionEvent e) { - if(currentColours.isSelected()) + if (currentColours.isSelected()) { reset(); }