X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FAnnotationColourChooser.java;h=2db2bd0f60f0e6ae3bd13c6983bed98e7b88a9b8;hb=ce886100c1eae01eac7d59c961e694f4493d4bcb;hp=1c73f7bfbccea5c67831b02078cebe06a175f580;hpb=dd40a60ce9bc04b00ae69523ccf8385640a82938;p=jalview.git diff --git a/src/jalview/appletgui/AnnotationColourChooser.java b/src/jalview/appletgui/AnnotationColourChooser.java index 1c73f7b..2db2bd0 100755 --- a/src/jalview/appletgui/AnnotationColourChooser.java +++ b/src/jalview/appletgui/AnnotationColourChooser.java @@ -1,32 +1,35 @@ /* -* 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.appletgui; -import java.awt.event.*; +import java.util.*; + import java.awt.*; +import java.awt.event.*; +import jalview.datamodel.*; import jalview.schemes.*; -import java.util.*; -import jalview.datamodel.SequenceGroup; +import java.awt.Rectangle; -public class AnnotationColourChooser extends Panel implements ActionListener, - AdjustmentListener, ItemListener +public class AnnotationColourChooser + extends Panel implements ActionListener, + AdjustmentListener, ItemListener, MouseListener { Frame frame; AlignViewport av; @@ -61,9 +64,12 @@ public class AnnotationColourChooser extends Panel implements ActionListener, this.ap = ap; slider.addAdjustmentListener(this); + slider.addMouseListener(this); if (av.alignment.getAlignmentAnnotation() == null) + { return; + } if (oldcs instanceof AnnotationColourGradient) { @@ -78,10 +84,21 @@ public class AnnotationColourChooser extends Panel implements ActionListener, } 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++)); + } + + for (int i = 0; i < list.size(); i++) + { + annotations.addItem(list.elementAt(i).toString()); } threshold.addItem("No Threshold"); @@ -121,6 +138,7 @@ public class AnnotationColourChooser extends Panel implements ActionListener, maxColour.setLabel("Max Colour"); maxColour.addActionListener(this); + thresholdIsMin.addItemListener(this); ok.setLabel("OK"); ok.addActionListener(this); @@ -139,16 +157,19 @@ public class AnnotationColourChooser extends Panel implements ActionListener, slider.setBackground(Color.white); slider.setEnabled(false); - slider.setBounds(new Rectangle(172, 7, 120, 16)); + slider.setBounds(new Rectangle(153, 3, 93, 21)); thresholdValue.setEnabled(false); - thresholdValue.setBounds(new Rectangle(295, 4, 83, 22)); - thresholdValue.setColumns(10); + thresholdValue.setBounds(new Rectangle(248, 2, 79, 22)); + thresholdValue.setColumns(5); jPanel3.setBackground(Color.white); currentColours.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); currentColours.setLabel("Use Original Colours"); currentColours.addItemListener(this); - threshold.setBounds(new Rectangle(19, 4, 141, 22)); + threshold.setBounds(new Rectangle(11, 3, 139, 22)); + thresholdIsMin.setBackground(Color.white); + thresholdIsMin.setLabel("Threshold is min/max"); + thresholdIsMin.setBounds(new Rectangle(328, 3, 135, 23)); jPanel1.add(ok); jPanel1.add(cancel); jPanel2.add(annotations); @@ -158,6 +179,7 @@ public class AnnotationColourChooser extends Panel implements ActionListener, jPanel3.add(threshold); jPanel3.add(slider); jPanel3.add(thresholdValue); + jPanel3.add(thresholdIsMin); this.add(jPanel2, java.awt.BorderLayout.NORTH); this.add(jPanel3, java.awt.BorderLayout.CENTER); this.add(jPanel1, java.awt.BorderLayout.SOUTH); @@ -177,11 +199,11 @@ public class AnnotationColourChooser extends Panel implements ActionListener, TextField thresholdValue = new TextField(20); Checkbox currentColours = new Checkbox(); BorderLayout borderLayout1 = new BorderLayout(); - + Checkbox thresholdIsMin = new Checkbox(); public void actionPerformed(ActionEvent evt) { - if(evt.getSource() == thresholdValue) + if (evt.getSource() == thresholdValue) { try { @@ -193,9 +215,13 @@ public class AnnotationColourChooser extends Panel implements ActionListener, {} } else if (evt.getSource() == minColour) + { minColour_actionPerformed(null); + } else if (evt.getSource() == maxColour) + { maxColour_actionPerformed(null); + } else if (evt.getSource() == ok) { @@ -205,15 +231,16 @@ public class AnnotationColourChooser extends Panel implements ActionListener, else if (evt.getSource() == cancel) { reset(); - ap.repaint(); + ap.paintAlignment(true); frame.setVisible(false); } else + { changeColour(); + } } - public void itemStateChanged(ItemEvent evt) { if (evt.getSource() == currentColours) @@ -243,7 +270,7 @@ public class AnnotationColourChooser extends Panel implements ActionListener, } currentAnnotation.threshold.value = (float) slider.getValue() / 1000f; - ap.repaint(); + ap.paintAlignment(false); } } @@ -256,8 +283,10 @@ public class AnnotationColourChooser extends Panel implements ActionListener, changeColour(); } else + { new UserDefinedColours(this, "Min Colour", - minColour.getBackground()); + minColour.getBackground()); + } } @@ -270,38 +299,33 @@ public class AnnotationColourChooser extends Panel implements ActionListener, changeColour(); } else + { new UserDefinedColours(this, "Max Colour", - maxColour.getBackground()); + maxColour.getBackground()); + } } - void changeColour() { // 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); @@ -322,7 +346,7 @@ public class AnnotationColourChooser extends Panel implements ActionListener, Color.black)); } - if(aboveThreshold != AnnotationColourGradient.NO_THRESHOLD) + if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD) { adjusting = true; @@ -337,16 +361,27 @@ public class AnnotationColourChooser extends Panel implements ActionListener, AnnotationColourGradient acg = null; if (currentColours.getState()) + { 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.getState(); av.setGlobalColourScheme(acg); @@ -364,23 +399,26 @@ public class AnnotationColourChooser extends Panel implements ActionListener, } if (currentColours.getState()) + { sg.cs = new AnnotationColourGradient( currentAnnotation, sg.cs, aboveThreshold); + } else + { sg.cs = new AnnotationColourGradient( currentAnnotation, minColour.getBackground(), maxColour.getBackground(), aboveThreshold); + } } } - ap.repaint(); + ap.paintAlignment(false); } - void reset() { av.setGlobalColourScheme(oldcs); @@ -391,13 +429,18 @@ public class AnnotationColourChooser extends Panel implements ActionListener, for (int g = 0; g < allGroups.size(); g++) { sg = (SequenceGroup) allGroups.elementAt(g); - sg.cs = (ColourSchemeI)oldgroupColours.get(sg); + sg.cs = (ColourSchemeI) oldgroupColours.get(sg); } } - ap.repaint(); + ap.paintAlignment(true); } + public void mouseClicked(MouseEvent evt){} + public void mousePressed(MouseEvent evt){} + public void mouseReleased(MouseEvent evt){ ap.paintAlignment(true);} + public void mouseEntered(MouseEvent evt){} + public void mouseExited(MouseEvent evt){} }