1 package jalview.appletgui;
\r
3 import jalview.jbappletgui.GUserDefinedColours;
\r
4 import jalview.datamodel.*;
\r
5 import jalview.schemes.*;
\r
9 import java.awt.event.*;
\r
13 public class UserDefinedColours extends GUserDefinedColours
\r
17 SequenceGroup seqGroup;
\r
18 Button selectedButton;
\r
19 Vector oldColours = new Vector();
\r
20 ColourSchemeI oldColourScheme;
\r
23 int R = 0, G = 0, B = 0;
\r
25 public ColourSchemeI loadDefaultColours()
\r
27 // NOT IMPLEMENTED YET IN APPLET VERSION
\r
31 public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
\r
34 frame = new Frame();
\r
36 jalview.bin.JalviewLite.addFrame(frame, "User defined colours", 420,345 );
\r
39 frame.setTitle( frame.getTitle()+ " ("+sg.getName()+")");
\r
46 if (seqGroup != null)
\r
47 oldColourScheme = seqGroup.cs;
\r
49 oldColourScheme = ap.av.getGlobalColourScheme();
\r
51 for (int i = 0; i < 20; i++)
\r
52 makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i]) +
\r
53 "", ResidueProperties.aa[i]);
\r
55 makeButton("B", "B");
\r
56 makeButton("Z", "Z");
\r
57 makeButton("X", "X");
\r
58 makeButton("Gap", "'.','-',' '");
\r
62 protected void rText_actionPerformed(ActionEvent e) {
\r
64 int i = Integer.parseInt(rText.getText());
\r
65 rScroller.setValue(i);
\r
66 }catch(NumberFormatException ex){}
\r
69 protected void gText_actionPerformed(ActionEvent e) {
\r
71 int i = Integer.parseInt(gText.getText());
\r
72 gScroller.setValue(i);
\r
73 }catch(NumberFormatException ex){}
\r
77 protected void bText_actionPerformed(ActionEvent e) {
\r
79 int i = Integer.parseInt(bText.getText());
\r
80 bScroller.setValue(i);
\r
81 }catch(NumberFormatException ex){}
\r
86 protected void rScroller_adjustmentValueChanged(AdjustmentEvent e) {
\r
87 R = rScroller.getValue();
\r
88 rText.setText(R+"");
\r
92 protected void gScroller_adjustmentValueChanged(AdjustmentEvent e) {
\r
93 G = gScroller.getValue();
\r
94 gText.setText(G+"");
\r
98 protected void bScroller_adjustmentValueChanged(AdjustmentEvent e) {
\r
99 B = bScroller.getValue();
\r
100 bText.setText(B+"");
\r
104 public void colourChanged()
\r
106 Color col = new Color(R,G,B);
\r
107 target.setBackground( col );
\r
109 if(selectedButton!=null)
\r
110 selectedButton.setBackground( col );
\r
113 public void colourButtonPressed(MouseEvent e)
\r
115 selectedButton = (Button)e.getSource();
\r
116 Color col = selectedButton.getBackground();
\r
118 G = col.getGreen();
\r
120 rScroller.setValue(R);
\r
121 gScroller.setValue(G);
\r
122 bScroller.setValue(B);
\r
123 rText.setText(R+"");
\r
124 gText.setText(G+"");
\r
125 bText.setText(B+"");
\r
130 void makeButton(String label, String aa)
\r
132 final Button button = new Button();
\r
133 Color col = Color.white;
\r
137 col = oldColourScheme.findColour(aa, -1);
\r
138 }catch(Exception ex){}
\r
140 button.setBackground( col );
\r
141 oldColours.addElement( col );
\r
142 button.setLabel( label );
\r
143 button.setForeground( col.darker().darker().darker() );
\r
144 button.setFont(new java.awt.Font("Verdana", 1, 10));
\r
145 button.addMouseListener(new java.awt.event.MouseAdapter()
\r
147 public void mouseClicked(MouseEvent e)
\r
149 colourButtonPressed(e);
\r
153 buttonPanel.add(button, null);
\r
157 protected void okButton_actionPerformed(ActionEvent e)
\r
159 applyButton_actionPerformed(null);
\r
160 frame.setVisible(false);
\r
163 protected void applyButton_actionPerformed(ActionEvent e)
\r
166 Color [] newColours = new Color[24];
\r
167 for(int i=0; i<24; i++)
\r
169 Button button = (Button)buttonPanel.getComponent(i);
\r
170 newColours[i] = button.getBackground();
\r
173 UserColourScheme ucs = new UserColourScheme( newColours );
\r
174 ucs.setThreshold(0);
\r
179 ap.av.setGlobalColourScheme(ucs);
\r
185 public static UserColourScheme loadDefaultColours(String file)
\r
187 UserColourScheme ucs = null;
\r
190 BufferedReader in = new BufferedReader(new FileReader(file));
\r
191 Color [] newColours = new Color[24];
\r
192 for (int i = 0; i < 24; i++)
\r
194 newColours[i] = new Color(Integer.parseInt(in.readLine()));
\r
197 ucs = new UserColourScheme(newColours);
\r
198 ucs.setThreshold(0);
\r
201 catch (Exception ex)
\r
208 protected void cancelButton_actionPerformed(ActionEvent e)
\r
211 Color [] newColours = new Color[24];
\r
212 for(int i=0; i<24; i++)
\r
214 newColours[i] = (Color)oldColours.elementAt(i);
\r
215 buttonPanel.getComponent(i).setBackground(newColours[i]);
\r
218 UserColourScheme ucs = new UserColourScheme( newColours );
\r
220 if (seqGroup != null)
\r
223 ap.av.setGlobalColourScheme(ucs);
\r
227 frame.setVisible(false);
\r