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
74 public AnnotationColourChooser()
\r
80 catch (Exception ex)
\r
82 ex.printStackTrace();
\r
86 private void jbInit()
\r
89 minColour.setBounds(new Rectangle(145, 5, 85, 25));
\r
90 minColour.setToolTipText("");
\r
91 minColour.setMargin(new Insets(2, 2, 2, 2));
\r
92 minColour.setText("Min Colour");
\r
93 minColour.addActionListener(new ActionListener()
\r
95 public void actionPerformed(ActionEvent e)
\r
97 minColour_actionPerformed(e);
\r
100 maxColour.setBounds(new Rectangle(235, 5, 89, 25));
\r
101 maxColour.setMargin(new Insets(2, 2, 2, 2));
\r
102 maxColour.setText("Max Colour");
\r
103 maxColour.addActionListener(new ActionListener()
\r
105 public void actionPerformed(ActionEvent e)
\r
107 maxColour_actionPerformed(e);
\r
110 thresholdCheck.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
\r
111 thresholdCheck.setOpaque(false);
\r
112 thresholdCheck.setHorizontalTextPosition(SwingConstants.LEADING);
\r
113 thresholdCheck.setSelectedIcon(null);
\r
114 thresholdCheck.setText("Above Threshold");
\r
115 thresholdCheck.setBounds(new Rectangle(329, 6, 126, 23));
\r
116 thresholdCheck.addActionListener(new ActionListener()
\r
118 public void actionPerformed(ActionEvent e)
\r
120 thresholdCheck_actionPerformed(e);
\r
123 ok.setOpaque(false);
\r
125 ok.addActionListener(new ActionListener()
\r
127 public void actionPerformed(ActionEvent e)
\r
129 ok_actionPerformed(e);
\r
132 cancel.setOpaque(false);
\r
133 cancel.setText("Cancel");
\r
134 cancel.addActionListener(new ActionListener()
\r
136 public void actionPerformed(ActionEvent e)
\r
138 cancel_actionPerformed(e);
\r
141 this.setLayout(borderLayout1);
\r
142 jPanel2.setLayout(null);
\r
143 annotations.setBounds(new Rectangle(5, 7, 135, 21));
\r
144 annotations.addActionListener(new ActionListener()
\r
146 public void actionPerformed(ActionEvent e)
\r
148 annotations_actionPerformed(e);
\r
151 jPanel1.setBackground(Color.white);
\r
152 jPanel2.setBackground(Color.white);
\r
154 jPanel1.add(cancel);
\r
155 jPanel2.add(annotations);
\r
156 jPanel2.add(minColour);
\r
157 jPanel2.add(maxColour);
\r
158 jPanel2.add(thresholdCheck);
\r
159 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
\r
160 this.add(jPanel2, java.awt.BorderLayout.CENTER);
\r
163 JComboBox annotations = new JComboBox();
\r
164 JButton minColour = new JButton();
\r
165 JButton maxColour = new JButton();
\r
166 JCheckBox thresholdCheck = new JCheckBox();
\r
167 JButton ok = new JButton();
\r
168 JButton cancel = new JButton();
\r
169 JPanel jPanel1 = new JPanel();
\r
170 JPanel jPanel2 = new JPanel();
\r
171 BorderLayout borderLayout1 = new BorderLayout();
\r
174 public void minColour_actionPerformed(ActionEvent e)
\r
176 Color col = JColorChooser.showDialog(this,
\r
177 "Select Colour for Minimum Value",
\r
178 minColour.getBackground());
\r
180 minColour.setBackground(col);
\r
181 minColour.repaint();
\r
185 public void maxColour_actionPerformed(ActionEvent e)
\r
187 Color col = JColorChooser.showDialog(this,
\r
188 "Select Colour for Maximum Value",
\r
189 maxColour.getBackground());
\r
191 maxColour.setBackground(col);
\r
192 maxColour.repaint();
\r
196 void changeColour()
\r
198 // We removed the non-graph annotations when filling the combobox
\r
199 // so allow for them again here
\r
200 int nograph = 0, graph = -1;
\r
201 for (int i = 0; i < av.alignment.getAlignmentAnnotation().length; i++)
\r
203 if (av.alignment.getAlignmentAnnotation()[i].graph == 0)
\r
208 if(graph==annotations.getSelectedIndex())
\r
212 jalview.datamodel.AlignmentAnnotation aa
\r
213 = av.alignment.getAlignmentAnnotation()[graph+nograph];
\r
215 AnnotationColourGradient acg = new AnnotationColourGradient(aa,
\r
216 minColour.getBackground(),
\r
217 maxColour.getBackground(),
\r
218 thresholdCheck.isSelected());
\r
220 if(thresholdCheck.isSelected() && aa.graphLines==null)
\r
222 aa.addGraphLine(new jalview.datamodel.GraphLine((aa.graphMax-aa.graphMin)/2f, "Threshold", Color.black));
\r
225 av.setGlobalColourScheme(acg);
\r
230 public void ok_actionPerformed(ActionEvent e)
\r
234 frame.setClosed(true);
\r
235 }catch(Exception ex){}
\r
238 public void cancel_actionPerformed(ActionEvent e)
\r
240 av.setGlobalColourScheme(oldcs);
\r
242 frame.setClosed(true);
\r
243 }catch(Exception ex){}
\r
246 public void thresholdCheck_actionPerformed(ActionEvent e)
\r
251 public void annotations_actionPerformed(ActionEvent e)
\r