3 import jalview.jbgui.GUserDefinedColours;
\r
4 import jalview.datamodel.*;
\r
6 import javax.swing.*;
\r
8 import java.awt.event.*;
\r
9 import javax.swing.event.*;
\r
10 import jalview.schemes.*;
\r
15 public class UserDefinedColours extends GUserDefinedColours implements ChangeListener
\r
19 SequenceGroup seqGroup;
\r
20 JButton selectedButton;
\r
21 Vector oldColours = new Vector();
\r
22 ColourSchemeI oldColourScheme;
\r
23 JInternalFrame frame;
\r
25 public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
\r
28 frame = new JInternalFrame();
\r
29 frame.setContentPane(this);
\r
30 Desktop.addInternalFrame(frame, "User defined colours", 450,530, false );
\r
31 if(System.getProperty("os.name").startsWith("Mac"))
\r
32 frame.setSize(450,560);
\r
35 frame.setTitle( frame.getTitle()+ " ("+sg.getName()+")");
\r
37 colorChooser.getSelectionModel().addChangeListener(this);
\r
43 if (seqGroup != null)
\r
44 oldColourScheme = seqGroup.cs;
\r
46 oldColourScheme = ap.av.getGlobalColourScheme();
\r
48 for (int i = 0; i < 20; i++)
\r
49 makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i]) +
\r
50 "", ResidueProperties.aa[i]);
\r
52 makeButton("B", "B");
\r
53 makeButton("Z", "Z");
\r
54 makeButton("X", "X");
\r
55 makeButton("Gap", "'.','-',' '");
\r
57 if(jalview.bin.Cache.getProperty("USER_DEFINED_COLOUR")!=null)
\r
59 loadColour(jalview.bin.Cache.getProperty("USER_DEFINED_COLOUR"));
\r
63 public void stateChanged(ChangeEvent evt)
\r
65 if(selectedButton!=null)
\r
66 selectedButton.setBackground( colorChooser.getColor() );
\r
69 public void colourButtonPressed(MouseEvent e)
\r
71 selectedButton = (JButton)e.getSource();
\r
72 colorChooser.setColor(selectedButton.getBackground());
\r
75 void makeButton(String label, String aa)
\r
77 final JButton button = new JButton();
\r
78 Color col = Color.white;
\r
82 col = oldColourScheme.findColour(aa, -1);
\r
83 }catch(Exception ex){}
\r
85 button.setBackground( col );
\r
86 oldColours.addElement( col );
\r
87 button.setText( label );
\r
88 button.setForeground( col.darker().darker().darker() );
\r
89 button.setFont(new java.awt.Font("Verdana", 1, 10));
\r
90 button.addMouseListener(new java.awt.event.MouseAdapter()
\r
92 public void mouseClicked(MouseEvent e)
\r
94 colourButtonPressed(e);
\r
98 buttonPanel.add(button, null);
\r
102 protected void okButton_actionPerformed(ActionEvent e)
\r
104 applyButton_actionPerformed(null);
\r
106 frame.setClosed(true);
\r
107 }catch(Exception ex){}
\r
110 protected void applyButton_actionPerformed(ActionEvent e)
\r
113 Color [] newColours = new Color[24];
\r
114 for(int i=0; i<24; i++)
\r
116 JButton button = (JButton)buttonPanel.getComponent(i);
\r
117 newColours[i] = button.getBackground();
\r
120 UserColourScheme ucs = new UserColourScheme();
\r
121 ucs.setThreshold(0);
\r
122 ucs.setColourScheme( newColours );
\r
127 ap.av.setGlobalColourScheme(ucs);
\r
132 protected void loadbutton_actionPerformed(ActionEvent e)
\r
134 JalviewFileChooser chooser = new JalviewFileChooser(
\r
135 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
\r
136 new String[]{".jc"},
\r
137 new String[]{"Jalview User Colours"},
\r
138 "Jalview User Colours");
\r
139 chooser.setFileView(new jalview.io.JalviewFileView());
\r
140 chooser.setDialogTitle("Load colour scheme");
\r
141 chooser.setToolTipText("Load");
\r
142 int value = chooser.showOpenDialog(this);
\r
143 if (value == JalviewFileChooser.APPROVE_OPTION)
\r
145 File choice = chooser.getSelectedFile();
\r
146 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
\r
147 loadColour(choice.getAbsolutePath());
\r
152 public static UserColourScheme loadDefaultColours(String file)
\r
154 UserColourScheme ucs = null;
\r
157 BufferedReader in = new BufferedReader(new FileReader(file));
\r
158 Color [] newColours = new Color[24];
\r
159 for (int i = 0; i < 24; i++)
\r
161 newColours[i] = new Color(Integer.parseInt(in.readLine()));
\r
164 ucs = new UserColourScheme();
\r
165 ucs.setThreshold(0);
\r
166 ucs.setColourScheme(newColours);
\r
169 catch (Exception ex)
\r
175 void loadColour(String file)
\r
179 BufferedReader in = new BufferedReader(new FileReader(file));
\r
180 for (int i = 0; i < 24; i++)
\r
182 JButton button = (JButton) buttonPanel.getComponent(i);
\r
183 Color c = new Color(Integer.parseInt(in.readLine()));
\r
184 button.setBackground(c);
\r
187 jalview.bin.Cache.setProperty("USER_DEFINED_COLOUR", file);
\r
189 catch (Exception ex)
\r
194 protected void savebutton_actionPerformed(ActionEvent e)
\r
196 JalviewFileChooser chooser = new JalviewFileChooser(
\r
197 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
\r
198 new String[]{".jc"},
\r
199 new String[]{"Jalview User Colours"},
\r
200 "Jalview User Colours");
\r
202 chooser.setFileView(new jalview.io.JalviewFileView());
\r
203 chooser.setDialogTitle("Save colour scheme");
\r
204 chooser.setToolTipText("Save");
\r
205 int value = chooser.showSaveDialog(this);
\r
206 if (value == JalviewFileChooser.APPROVE_OPTION)
\r
208 String choice = chooser.getSelectedFile().getPath();
\r
209 jalview.bin.Cache.setProperty("USER_DEFINED_COLOUR", choice);
\r
212 PrintWriter out = new PrintWriter(new FileWriter(choice));
\r
213 for(int i=0; i<24; i++)
\r
215 JButton button = (JButton)buttonPanel.getComponent(i);
\r
216 out.println(button.getBackground().getRGB() + "");
\r
221 catch(Exception ex)
\r
222 {ex.printStackTrace();}
\r
227 protected void cancelButton_actionPerformed(ActionEvent e)
\r
229 UserColourScheme ucs = new UserColourScheme();
\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 ucs.setColourScheme( newColours );
\r
238 if (seqGroup != null)
\r
241 ap.av.setGlobalColourScheme(ucs);
\r
246 frame.setClosed(true);
\r
247 }catch(Exception ex){}
\r