2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.gui;
\r
21 import javax.swing.*;
\r
22 import java.awt.event.ActionListener;
\r
23 import java.awt.event.ActionEvent;
\r
24 import java.awt.BorderLayout;
\r
27 import jalview.schemes.*;
\r
29 public class AnnotationColourChooser
\r
32 JInternalFrame frame;
\r
35 ColourSchemeI oldcs;
\r
37 public AnnotationColourChooser(AlignViewport av, AlignmentPanel ap)
\r
39 oldcs = av.getGlobalColourScheme();
\r
42 frame = new JInternalFrame();
\r
43 frame.setContentPane(this);
\r
44 frame.setLayer(JLayeredPane.PALETTE_LAYER);
\r
45 Desktop.addInternalFrame(frame, "Colour by Annotation", 480, 110, false);
\r
49 }catch(Exception ex){}
\r
51 if(av.alignment.getAlignmentAnnotation()==null)
\r
54 if(oldcs instanceof AnnotationColourGradient)
\r
56 AnnotationColourGradient acg = (AnnotationColourGradient)oldcs;
\r
57 minColour.setBackground( acg.getMinColour() );
\r
58 maxColour.setBackground( acg.getMaxColour() );
\r
62 minColour.setBackground(Color.orange);
\r
63 maxColour.setBackground(Color.red);
\r
66 for (int i = 0; i < av.alignment.getAlignmentAnnotation().length; i++)
\r
68 if(av.alignment.getAlignmentAnnotation()[i].graph>0)
\r
69 annotations.addItem(av.alignment.getAlignmentAnnotation()[i].label);
\r
72 threshold.addItem("No Threshold");
\r
73 threshold.addItem("Above Threshold");
\r
74 threshold.addItem("Below Threshold");
\r
78 public AnnotationColourChooser()
\r
84 catch (Exception ex)
\r
86 ex.printStackTrace();
\r
90 private void jbInit()
\r
93 minColour.setBounds(new Rectangle(145, 5, 85, 25));
\r
94 minColour.setToolTipText("");
\r
95 minColour.setMargin(new Insets(2, 2, 2, 2));
\r
96 minColour.setText("Min Colour");
\r
97 minColour.addActionListener(new ActionListener()
\r
99 public void actionPerformed(ActionEvent e)
\r
101 minColour_actionPerformed(e);
\r
104 maxColour.setBounds(new Rectangle(235, 5, 89, 25));
\r
105 maxColour.setMargin(new Insets(2, 2, 2, 2));
\r
106 maxColour.setText("Max Colour");
\r
107 maxColour.addActionListener(new ActionListener()
\r
109 public void actionPerformed(ActionEvent e)
\r
111 maxColour_actionPerformed(e);
\r
114 ok.setOpaque(false);
\r
116 ok.addActionListener(new ActionListener()
\r
118 public void actionPerformed(ActionEvent e)
\r
120 ok_actionPerformed(e);
\r
123 cancel.setOpaque(false);
\r
124 cancel.setText("Cancel");
\r
125 cancel.addActionListener(new ActionListener()
\r
127 public void actionPerformed(ActionEvent e)
\r
129 cancel_actionPerformed(e);
\r
132 this.setLayout(borderLayout1);
\r
133 jPanel2.setLayout(null);
\r
134 annotations.setBounds(new Rectangle(5, 7, 135, 21));
\r
135 annotations.addActionListener(new ActionListener()
\r
137 public void actionPerformed(ActionEvent e)
\r
139 annotations_actionPerformed(e);
\r
142 jPanel1.setBackground(Color.white);
\r
143 jPanel2.setBackground(Color.white);
\r
144 threshold.setBounds(new Rectangle(328, 6, 125, 22));
\r
145 threshold.addActionListener(new ActionListener()
\r
147 public void actionPerformed(ActionEvent e)
\r
149 threshold_actionPerformed(e);
\r
153 jPanel1.add(cancel);
\r
154 jPanel2.add(annotations);
\r
155 jPanel2.add(minColour);
\r
156 jPanel2.add(maxColour);
\r
157 jPanel2.add(threshold);
\r
158 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
\r
159 this.add(jPanel2, java.awt.BorderLayout.CENTER);
\r
162 JComboBox annotations = new JComboBox();
\r
163 JButton minColour = new JButton();
\r
164 JButton maxColour = new JButton();
\r
165 JButton ok = new JButton();
\r
166 JButton cancel = new JButton();
\r
167 JPanel jPanel1 = new JPanel();
\r
168 JPanel jPanel2 = new JPanel();
\r
169 BorderLayout borderLayout1 = new BorderLayout();
\r
170 JComboBox threshold = new JComboBox();
\r
172 public void minColour_actionPerformed(ActionEvent e)
\r
174 Color col = JColorChooser.showDialog(this,
\r
175 "Select Colour for Minimum Value",
\r
176 minColour.getBackground());
\r
178 minColour.setBackground(col);
\r
179 minColour.repaint();
\r
183 public void maxColour_actionPerformed(ActionEvent e)
\r
185 Color col = JColorChooser.showDialog(this,
\r
186 "Select Colour for Maximum Value",
\r
187 maxColour.getBackground());
\r
189 maxColour.setBackground(col);
\r
190 maxColour.repaint();
\r
194 void changeColour()
\r
196 // Check if combobox is still adjusting
\r
197 if(threshold.getSelectedIndex()==-1)
\r
200 // We removed the non-graph annotations when filling the combobox
\r
201 // so allow for them again here
\r
202 int nograph = 0, graph = -1;
\r
203 for (int i = 0; i < av.alignment.getAlignmentAnnotation().length; i++)
\r
205 if (av.alignment.getAlignmentAnnotation()[i].graph == 0)
\r
210 if(graph==annotations.getSelectedIndex())
\r
214 jalview.datamodel.AlignmentAnnotation aa
\r
215 = av.alignment.getAlignmentAnnotation()[graph+nograph];
\r
218 int aboveThreshold = -1;
\r
219 if(threshold.getSelectedItem().equals("Above Threshold"))
\r
220 aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;
\r
221 else if(threshold.getSelectedItem().equals("Below Threshold"))
\r
222 aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;
\r
224 if(aboveThreshold!=AnnotationColourGradient.NO_THRESHOLD && aa.threshold==null)
\r
226 aa.setThreshold(new jalview.datamodel.GraphLine((aa.graphMax-aa.graphMin)/2f, "Threshold", Color.black));
\r
229 AnnotationColourGradient acg = new AnnotationColourGradient(aa,
\r
230 minColour.getBackground(),
\r
231 maxColour.getBackground(),
\r
237 av.setGlobalColourScheme(acg);
\r
242 public void ok_actionPerformed(ActionEvent e)
\r
246 frame.setClosed(true);
\r
247 }catch(Exception ex){}
\r
250 public void cancel_actionPerformed(ActionEvent e)
\r
252 av.setGlobalColourScheme(oldcs);
\r
254 frame.setClosed(true);
\r
255 }catch(Exception ex){}
\r
258 public void thresholdCheck_actionPerformed(ActionEvent e)
\r
263 public void annotations_actionPerformed(ActionEvent e)
\r
268 public void threshold_actionPerformed(ActionEvent e)
\r