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 UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
\r
28 frame = new Frame();
\r
30 jalview.bin.JalviewLite.addFrame(frame, "User defined colours", 420,345 );
\r
33 frame.setTitle( frame.getTitle()+ " ("+sg.getName()+")");
\r
40 if (seqGroup != null)
\r
41 oldColourScheme = seqGroup.cs;
\r
43 oldColourScheme = ap.av.getGlobalColourScheme();
\r
45 for (int i = 0; i < 20; i++)
\r
46 makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i]) +
\r
47 "", ResidueProperties.aa[i]);
\r
49 makeButton("B", "B");
\r
50 makeButton("Z", "Z");
\r
51 makeButton("X", "X");
\r
52 makeButton("Gap", "'.','-',' '");
\r
56 protected void rText_actionPerformed(ActionEvent e) {
\r
58 int i = Integer.parseInt(rText.getText());
\r
59 rScroller.setValue(i);
\r
60 }catch(NumberFormatException ex){}
\r
63 protected void gText_actionPerformed(ActionEvent e) {
\r
65 int i = Integer.parseInt(gText.getText());
\r
66 gScroller.setValue(i);
\r
67 }catch(NumberFormatException ex){}
\r
71 protected void bText_actionPerformed(ActionEvent e) {
\r
73 int i = Integer.parseInt(bText.getText());
\r
74 bScroller.setValue(i);
\r
75 }catch(NumberFormatException ex){}
\r
80 protected void rScroller_adjustmentValueChanged(AdjustmentEvent e) {
\r
81 R = rScroller.getValue();
\r
82 rText.setText(R+"");
\r
86 protected void gScroller_adjustmentValueChanged(AdjustmentEvent e) {
\r
87 G = gScroller.getValue();
\r
88 gText.setText(G+"");
\r
92 protected void bScroller_adjustmentValueChanged(AdjustmentEvent e) {
\r
93 B = bScroller.getValue();
\r
94 bText.setText(B+"");
\r
98 public void colourChanged()
\r
100 Color col = new Color(R,G,B);
\r
101 target.setBackground( col );
\r
103 if(selectedButton!=null)
\r
104 selectedButton.setBackground( col );
\r
107 public void colourButtonPressed(MouseEvent e)
\r
109 selectedButton = (Button)e.getSource();
\r
110 Color col = selectedButton.getBackground();
\r
112 G = col.getGreen();
\r
114 rScroller.setValue(R);
\r
115 gScroller.setValue(G);
\r
116 bScroller.setValue(B);
\r
117 rText.setText(R+"");
\r
118 gText.setText(G+"");
\r
119 bText.setText(B+"");
\r
124 void makeButton(String label, String aa)
\r
126 final Button button = new Button();
\r
127 Color col = Color.white;
\r
131 col = oldColourScheme.findColour(aa, -1);
\r
132 }catch(Exception ex){}
\r
134 button.setBackground( col );
\r
135 oldColours.addElement( col );
\r
136 button.setLabel( label );
\r
137 button.setForeground( col.darker().darker().darker() );
\r
138 button.setFont(new java.awt.Font("Verdana", 1, 10));
\r
139 button.addMouseListener(new java.awt.event.MouseAdapter()
\r
141 public void mouseClicked(MouseEvent e)
\r
143 colourButtonPressed(e);
\r
147 buttonPanel.add(button, null);
\r
151 protected void okButton_actionPerformed(ActionEvent e)
\r
153 applyButton_actionPerformed(null);
\r
154 frame.setVisible(false);
\r
157 protected void applyButton_actionPerformed(ActionEvent e)
\r
160 Color [] newColours = new Color[24];
\r
161 for(int i=0; i<24; i++)
\r
163 Button button = (Button)buttonPanel.getComponent(i);
\r
164 newColours[i] = button.getBackground();
\r
167 UserColourScheme ucs = new UserColourScheme();
\r
168 ucs.setThreshold(0);
\r
169 ucs.setColourScheme( newColours );
\r
174 ap.av.setGlobalColourScheme(ucs);
\r
180 public static UserColourScheme loadDefaultColours(String file)
\r
182 UserColourScheme ucs = null;
\r
185 BufferedReader in = new BufferedReader(new FileReader(file));
\r
186 Color [] newColours = new Color[24];
\r
187 for (int i = 0; i < 24; i++)
\r
189 newColours[i] = new Color(Integer.parseInt(in.readLine()));
\r
192 ucs = new UserColourScheme();
\r
193 ucs.setThreshold(0);
\r
194 ucs.setColourScheme(newColours);
\r
197 catch (Exception ex)
\r
204 protected void cancelButton_actionPerformed(ActionEvent e)
\r
206 UserColourScheme ucs = new UserColourScheme();
\r
207 Color [] newColours = new Color[24];
\r
208 for(int i=0; i<24; i++)
\r
210 newColours[i] = (Color)oldColours.elementAt(i);
\r
211 buttonPanel.getComponent(i).setBackground(newColours[i]);
\r
214 ucs.setColourScheme( newColours );
\r
215 if (seqGroup != null)
\r
218 ap.av.setGlobalColourScheme(ucs);
\r
222 frame.setVisible(false);
\r