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);
\r
49 }catch(Exception ex){}
\r
51 if(av.alignment.getAlignmentAnnotation()==null)
\r
54 for(int i=0; i<av.alignment.getAlignmentAnnotation().length; i++)
\r
56 annotations.addItem(av.alignment.getAlignmentAnnotation()[i].label);
\r
59 // if(av.getGlobalColourScheme() instanceof AnnotationColourGradient)
\r
65 minColour.setBackground(Color.orange);
\r
66 maxColour.setBackground(Color.red);
\r
70 public AnnotationColourChooser()
\r
76 catch (Exception ex)
\r
78 ex.printStackTrace();
\r
82 private void jbInit()
\r
85 minColour.setBounds(new Rectangle(145, 5, 85, 25));
\r
86 minColour.setToolTipText("");
\r
87 minColour.setMargin(new Insets(2, 2, 2, 2));
\r
88 minColour.setText("Min Colour");
\r
89 minColour.addActionListener(new ActionListener()
\r
91 public void actionPerformed(ActionEvent e)
\r
93 minColour_actionPerformed(e);
\r
96 maxColour.setBounds(new Rectangle(235, 5, 89, 25));
\r
97 maxColour.setMargin(new Insets(2, 2, 2, 2));
\r
98 maxColour.setText("Max Colour");
\r
99 maxColour.addActionListener(new ActionListener()
\r
101 public void actionPerformed(ActionEvent e)
\r
103 maxColour_actionPerformed(e);
\r
106 thresholdCheck.setOpaque(false);
\r
107 thresholdCheck.setHorizontalTextPosition(SwingConstants.LEADING);
\r
108 thresholdCheck.setSelectedIcon(null);
\r
109 thresholdCheck.setText("Above Threshold");
\r
110 thresholdCheck.setBounds(new Rectangle(329, 6, 109, 23));
\r
111 apply.setOpaque(false);
\r
112 apply.setSelectedIcon(null);
\r
113 apply.setText("Apply");
\r
114 apply.addActionListener(new ActionListener()
\r
116 public void actionPerformed(ActionEvent e)
\r
118 apply_actionPerformed(e);
\r
121 ok.setOpaque(false);
\r
123 ok.addActionListener(new ActionListener()
\r
125 public void actionPerformed(ActionEvent e)
\r
127 ok_actionPerformed(e);
\r
130 cancel.setOpaque(false);
\r
131 cancel.setText("Cancel");
\r
132 cancel.addActionListener(new ActionListener()
\r
134 public void actionPerformed(ActionEvent e)
\r
136 cancel_actionPerformed(e);
\r
139 this.setLayout(borderLayout1);
\r
140 jPanel2.setLayout(null);
\r
141 annotations.setBounds(new Rectangle(5, 7, 135, 21));
\r
142 jPanel1.setBackground(Color.white);
\r
143 jPanel2.setBackground(Color.white);
\r
144 jPanel1.add(apply);
\r
146 jPanel1.add(cancel);
\r
147 jPanel2.add(annotations);
\r
148 jPanel2.add(minColour);
\r
149 jPanel2.add(maxColour);
\r
150 jPanel2.add(thresholdCheck);
\r
151 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
\r
152 this.add(jPanel2, java.awt.BorderLayout.CENTER);
\r
155 JComboBox annotations = new JComboBox();
\r
156 JButton minColour = new JButton();
\r
157 JButton maxColour = new JButton();
\r
158 JCheckBox thresholdCheck = new JCheckBox();
\r
159 JButton apply = new JButton();
\r
160 JButton ok = new JButton();
\r
161 JButton cancel = new JButton();
\r
162 JPanel jPanel1 = new JPanel();
\r
163 JPanel jPanel2 = new JPanel();
\r
164 BorderLayout borderLayout1 = new BorderLayout();
\r
165 public void apply_actionPerformed(ActionEvent e)
\r
170 public void minColour_actionPerformed(ActionEvent e)
\r
172 Color col = JColorChooser.showDialog(this,
\r
173 "Select Colour for Minimum Value",
\r
174 minColour.getBackground());
\r
176 minColour.setBackground(col);
\r
177 minColour.repaint();
\r
180 public void maxColour_actionPerformed(ActionEvent e)
\r
182 Color col = JColorChooser.showDialog(this,
\r
183 "Select Colour for Maximum Value",
\r
184 maxColour.getBackground());
\r
186 maxColour.setBackground(col);
\r
187 maxColour.repaint();
\r
190 void changeColour()
\r
192 jalview.datamodel.AlignmentAnnotation aa = av.alignment.getAlignmentAnnotation()[annotations.getSelectedIndex()];
\r
194 AnnotationColourGradient acg = new AnnotationColourGradient(aa,
\r
195 minColour.getBackground(),
\r
196 maxColour.getBackground(),
\r
197 thresholdCheck.isSelected());
\r
199 if(thresholdCheck.isSelected() && aa.graphLines==null)
\r
201 aa.addGraphLine(new jalview.datamodel.GraphLine((aa.graphMax-aa.graphMin)/2f, "Threshold", Color.black));
\r
204 av.setGlobalColourScheme(acg);
\r
209 public void ok_actionPerformed(ActionEvent e)
\r
213 frame.setClosed(true);
\r
214 }catch(Exception ex){}
\r
217 public void cancel_actionPerformed(ActionEvent e)
\r
219 av.setGlobalColourScheme(oldcs);
\r
221 frame.setClosed(true);
\r
222 }catch(Exception ex){}
\r