X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAnnotationColourChooser.java;h=83a8a12b0cb1733abe1abc44c00fe9b14d483ccc;hb=6de402db90987d3645f3429d9073c13678d8e980;hp=f4992177c1494dc1c1f6d6c8ae37e7c0b7b69419;hpb=174230b4233d9ce80f94527768d2cd2f76da11ab;p=jalview.git diff --git a/src/jalview/gui/AnnotationColourChooser.java b/src/jalview/gui/AnnotationColourChooser.java index f499217..83a8a12 100755 --- a/src/jalview/gui/AnnotationColourChooser.java +++ b/src/jalview/gui/AnnotationColourChooser.java @@ -1,31 +1,33 @@ /* -* Jalview - A Sequence Alignment Editor and Viewer -* Copyright (C) 2006 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; +import java.awt.Dimension; public class AnnotationColourChooser extends JPanel @@ -38,7 +40,7 @@ public class AnnotationColourChooser 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) @@ -49,8 +51,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; @@ -60,27 +64,30 @@ 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() { public void stateChanged(ChangeEvent evt) { - if(!adjusting) + 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) { @@ -95,16 +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(); @@ -127,24 +148,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); @@ -196,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); @@ -210,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); @@ -220,13 +257,14 @@ 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(); - JButton minColour = new JButton(); - JButton maxColour = new JButton(); + JComboBox annotations; + JPanel minColour = new JPanel(); + JPanel maxColour = new JPanel(); JButton ok = new JButton(); JButton cancel = new JButton(); JPanel jPanel1 = new JPanel(); @@ -239,25 +277,30 @@ public class AnnotationColourChooser JSlider slider = new JSlider(); JTextField thresholdValue = new JTextField(20); JCheckBox currentColours = new JCheckBox(); + JCheckBox thresholdIsMin = 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,29 +309,22 @@ 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 - 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; + return; } - currentAnnotation = av.alignment.getAlignmentAnnotation()[graph + nograph]; + + currentAnnotation = av.alignment.getAlignmentAnnotation()[annotations.getSelectedIndex()]; 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 +345,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 +363,27 @@ 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); + } + + if(currentAnnotation.graphMin==0f&& currentAnnotation.graphMax==0f) + { + acg.predefinedColours = true; + } + + acg.thresholdIsMinMax = thresholdIsMin.isSelected(); av.setGlobalColourScheme(acg); @@ -354,20 +401,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) @@ -392,7 +443,6 @@ public class AnnotationColourChooser {} } - void reset() { av.setGlobalColourScheme(oldcs); @@ -403,7 +453,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 +487,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; - ap.repaint(); + currentAnnotation.threshold.value = (float) slider.getValue() / 1000f; + ap.paintAlignment(false); } public void currentColours_actionPerformed(ActionEvent e) { - if(currentColours.isSelected()) + if (currentColours.isSelected()) { reset(); } @@ -459,4 +509,9 @@ public class AnnotationColourChooser changeColour(); } + public void thresholdIsMin_actionPerformed(ActionEvent actionEvent) + { + changeColour(); + } + }