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
20 package jalview.appletgui;
\r
22 import jalview.jbappletgui.GUserDefinedColours;
\r
23 import jalview.datamodel.*;
\r
24 import jalview.schemes.*;
\r
25 import jalview.io.*;
\r
28 import java.awt.event.*;
\r
32 public class UserDefinedColours extends GUserDefinedColours
\r
36 SequenceGroup seqGroup;
\r
37 Button selectedButton;
\r
38 Vector oldColours = new Vector();
\r
39 ColourSchemeI oldColourScheme;
\r
42 int R = 0, G = 0, B = 0;
\r
44 public ColourSchemeI loadDefaultColours()
\r
46 // NOT IMPLEMENTED YET IN APPLET VERSION
\r
50 public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
\r
53 frame = new Frame();
\r
55 jalview.bin.JalviewLite.addFrame(frame, "User defined colours", 420,345 );
\r
58 frame.setTitle( frame.getTitle()+ " ("+sg.getName()+")");
\r
65 if (seqGroup != null)
\r
66 oldColourScheme = seqGroup.cs;
\r
68 oldColourScheme = ap.av.getGlobalColourScheme();
\r
70 for (int i = 0; i < 20; i++)
\r
71 makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i]) +
\r
72 "", ResidueProperties.aa[i]);
\r
74 makeButton("B", "B");
\r
75 makeButton("Z", "Z");
\r
76 makeButton("X", "X");
\r
77 makeButton("Gap", "'.','-',' '");
\r
81 protected void rText_actionPerformed(ActionEvent e) {
\r
83 int i = Integer.parseInt(rText.getText());
\r
84 rScroller.setValue(i);
\r
85 }catch(NumberFormatException ex){}
\r
88 protected void gText_actionPerformed(ActionEvent e) {
\r
90 int i = Integer.parseInt(gText.getText());
\r
91 gScroller.setValue(i);
\r
92 }catch(NumberFormatException ex){}
\r
96 protected void bText_actionPerformed(ActionEvent e) {
\r
98 int i = Integer.parseInt(bText.getText());
\r
99 bScroller.setValue(i);
\r
100 }catch(NumberFormatException ex){}
\r
105 protected void rScroller_adjustmentValueChanged(AdjustmentEvent e) {
\r
106 R = rScroller.getValue();
\r
107 rText.setText(R+"");
\r
111 protected void gScroller_adjustmentValueChanged(AdjustmentEvent e) {
\r
112 G = gScroller.getValue();
\r
113 gText.setText(G+"");
\r
117 protected void bScroller_adjustmentValueChanged(AdjustmentEvent e) {
\r
118 B = bScroller.getValue();
\r
119 bText.setText(B+"");
\r
123 public void colourChanged()
\r
125 Color col = new Color(R,G,B);
\r
126 target.setBackground( col );
\r
128 if(selectedButton!=null)
\r
129 selectedButton.setBackground( col );
\r
132 public void colourButtonPressed(MouseEvent e)
\r
134 selectedButton = (Button)e.getSource();
\r
135 Color col = selectedButton.getBackground();
\r
137 G = col.getGreen();
\r
139 rScroller.setValue(R);
\r
140 gScroller.setValue(G);
\r
141 bScroller.setValue(B);
\r
142 rText.setText(R+"");
\r
143 gText.setText(G+"");
\r
144 bText.setText(B+"");
\r
149 void makeButton(String label, String aa)
\r
151 final Button button = new Button();
\r
152 Color col = Color.white;
\r
156 col = oldColourScheme.findColour(aa, -1);
\r
157 }catch(Exception ex){}
\r
159 button.setBackground( col );
\r
160 oldColours.addElement( col );
\r
161 button.setLabel( label );
\r
162 button.setForeground( col.darker().darker().darker() );
\r
163 button.setFont(new java.awt.Font("Verdana", 1, 10));
\r
164 button.addMouseListener(new java.awt.event.MouseAdapter()
\r
166 public void mouseClicked(MouseEvent e)
\r
168 colourButtonPressed(e);
\r
172 buttonPanel.add(button, null);
\r
176 protected void okButton_actionPerformed(ActionEvent e)
\r
178 applyButton_actionPerformed(null);
\r
179 frame.setVisible(false);
\r
182 protected void applyButton_actionPerformed(ActionEvent e)
\r
185 Color [] newColours = new Color[24];
\r
186 for(int i=0; i<24; i++)
\r
188 Button button = (Button)buttonPanel.getComponent(i);
\r
189 newColours[i] = button.getBackground();
\r
192 UserColourScheme ucs = new UserColourScheme( newColours );
\r
193 ucs.setThreshold(0);
\r
198 ap.av.setGlobalColourScheme(ucs);
\r
204 public static UserColourScheme loadDefaultColours(String file)
\r
206 UserColourScheme ucs = null;
\r
209 BufferedReader in = new BufferedReader(new FileReader(file));
\r
210 Color [] newColours = new Color[24];
\r
211 for (int i = 0; i < 24; i++)
\r
213 newColours[i] = new Color(Integer.parseInt(in.readLine()));
\r
216 ucs = new UserColourScheme(newColours);
\r
217 ucs.setThreshold(0);
\r
220 catch (Exception ex)
\r
227 protected void cancelButton_actionPerformed(ActionEvent e)
\r
230 Color [] newColours = new Color[24];
\r
231 for(int i=0; i<24; i++)
\r
233 newColours[i] = (Color)oldColours.elementAt(i);
\r
234 buttonPanel.getComponent(i).setBackground(newColours[i]);
\r
237 UserColourScheme ucs = new UserColourScheme( newColours );
\r
239 if (seqGroup != null)
\r
242 ap.av.setGlobalColourScheme(ucs);
\r
246 frame.setVisible(false);
\r