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
26 public UserDefinedColours(JInternalFrame f, AlignmentPanel ap, SequenceGroup sg)
\r
29 colorChooser.getSelectionModel().addChangeListener(this);
\r
35 if (seqGroup != null)
\r
36 oldColourScheme = seqGroup.cs;
\r
38 oldColourScheme = ap.av.getGlobalColourScheme();
\r
40 for (int i = 0; i < 20; i++)
\r
41 makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i]) +
\r
42 "", ResidueProperties.aa[i]);
\r
44 makeButton("B", "B");
\r
45 makeButton("Z", "Z");
\r
46 makeButton("X", "X");
\r
47 makeButton("'.','-',' '", "-");
\r
49 if(jalview.bin.Cache.getProperty("USER_DEFINED_COLOUR")!=null)
\r
51 loadColour(jalview.bin.Cache.getProperty("USER_DEFINED_COLOUR"));
\r
57 public void stateChanged(ChangeEvent evt)
\r
59 if(selectedButton!=null)
\r
60 selectedButton.setBackground( colorChooser.getColor() );
\r
63 public void colourButtonPressed(MouseEvent e)
\r
65 selectedButton = (JButton)e.getSource();
\r
66 colorChooser.setColor(selectedButton.getBackground());
\r
69 void makeButton(String label, String aa)
\r
71 final JButton button = new JButton();
\r
72 Color col = Color.white;
\r
76 col = oldColourScheme.findColour(aa, -1, null);
\r
77 }catch(Exception ex){}
\r
79 button.setBackground( col );
\r
80 oldColours.addElement( col );
\r
81 button.setText( label );
\r
82 button.setForeground( col.darker().darker().darker() );
\r
83 button.setFont(new java.awt.Font("Verdana", 1, 10));
\r
84 button.addMouseListener(new java.awt.event.MouseAdapter()
\r
86 public void mouseClicked(MouseEvent e)
\r
88 colourButtonPressed(e);
\r
92 buttonPanel.add(button);
\r
96 protected void okButton_actionPerformed(ActionEvent e)
\r
98 applyButton_actionPerformed(null);
\r
100 frame.setClosed(true);
\r
101 }catch(Exception ex){}
\r
104 protected void applyButton_actionPerformed(ActionEvent e)
\r
106 UserColourScheme ucs = new UserColourScheme();
\r
107 Color [] newColours = new Color[24];
\r
108 for(int i=0; i<24; i++)
\r
110 JButton button = (JButton)buttonPanel.getComponent(i);
\r
111 newColours[i] = button.getBackground();
\r
114 ucs.setThreshold(0);
\r
115 ucs.setColourScheme( newColours );
\r
120 ap.av.setGlobalColourScheme(ucs);
\r
122 ap.RefreshPanels();
\r
125 protected void loadbutton_actionPerformed(ActionEvent e)
\r
127 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
\r
128 new String[]{".jvuc"}, "Jalview User Colours");
\r
129 chooser.setFileView(new jalview.io.JalviewFileView());
\r
130 chooser.setDialogTitle("Load colour scheme");
\r
131 chooser.setToolTipText("Load");
\r
132 int value = chooser.showOpenDialog(this);
\r
133 if (value == JalviewFileChooser.APPROVE_OPTION)
\r
135 String choice = chooser.getSelectedFile().getPath();
\r
136 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
\r
137 loadColour(choice);
\r
142 void loadColour(String file)
\r
146 BufferedReader in = new BufferedReader(new FileReader(file));
\r
147 for (int i = 0; i < 24; i++)
\r
149 JButton button = (JButton) buttonPanel.getComponent(i);
\r
150 Color c = new Color(Integer.parseInt(in.readLine()));
\r
151 button.setBackground(c);
\r
154 catch (Exception ex)
\r
159 protected void savebutton_actionPerformed(ActionEvent e)
\r
161 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
\r
162 chooser.setFileView(new jalview.io.JalviewFileView());
\r
163 chooser.setDialogTitle("Save colour scheme");
\r
164 chooser.setToolTipText("Save");
\r
165 int value = chooser.showSaveDialog(this);
\r
166 if (value == JalviewFileChooser.APPROVE_OPTION)
\r
168 String choice = chooser.getSelectedFile().getPath();
\r
169 jalview.bin.Cache.setProperty("USER_DEFINED_COLOUR", choice);
\r
172 PrintWriter out = new PrintWriter(new FileWriter(choice));
\r
173 for(int i=0; i<24; i++)
\r
175 JButton button = (JButton)buttonPanel.getComponent(i);
\r
176 out.println(button.getBackground().getRGB() + "");
\r
181 catch(Exception ex)
\r
182 {ex.printStackTrace();}
\r
187 protected void cancelButton_actionPerformed(ActionEvent e)
\r
189 UserColourScheme ucs = new UserColourScheme();
\r
190 Color [] newColours = new Color[24];
\r
191 for(int i=0; i<24; i++)
\r
193 newColours[i] = (Color)oldColours.elementAt(i);
\r
194 buttonPanel.getComponent(i).setBackground(newColours[i]);
\r
197 ucs.setColourScheme( newColours );
\r
198 if (seqGroup != null)
\r
201 ap.av.setGlobalColourScheme(ucs);
\r
203 ap.RefreshPanels();
\r