/*\r
-* Jalview - A Sequence Alignment Editor and Viewer\r
-* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
-*\r
-* This program is free software; you can redistribute it and/or\r
-* modify it under the terms of the GNU General Public License\r
-* as published by the Free Software Foundation; either version 2\r
-* of the License, or (at your option) any later version.\r
-*\r
-* This program is distributed in the hope that it will be useful,\r
-* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-* GNU General Public License for more details.\r
-*\r
-* You should have received a copy of the GNU General Public License\r
-* along with this program; if not, write to the Free Software\r
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
-*/\r
+ * Jalview - A Sequence Alignment Editor and Viewer\r
+ * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
+ */\r
\r
package jalview.appletgui;\r
\r
-import jalview.jbappletgui.GUserDefinedColours;\r
-import jalview.datamodel.*;\r
-import jalview.schemes.*;\r
-import jalview.io.*;\r
-import java.io.*;\r
+import java.util.*;\r
+\r
import java.awt.*;\r
import java.awt.event.*;\r
-import java.util.*;\r
\r
+import jalview.datamodel.*;\r
+import jalview.schemes.*;\r
\r
-public class UserDefinedColours extends GUserDefinedColours\r
+public class UserDefinedColours\r
+ extends Panel implements ActionListener, AdjustmentListener\r
{\r
\r
AlignmentPanel ap;\r
Vector oldColours = new Vector();\r
ColourSchemeI oldColourScheme;\r
Frame frame;\r
+ MCview.AppletPDBCanvas pdbcanvas;\r
+\r
+ Component caller;\r
+ String originalLabel;\r
+ Color originalColour;\r
\r
int R = 0, G = 0, B = 0;\r
\r
\r
public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)\r
{\r
- super();\r
- frame = new Frame();\r
- frame.add(this);\r
- jalview.bin.JalviewLite.addFrame(frame, "User defined colours", 420,345 );\r
-\r
- if(sg!=null)\r
- frame.setTitle( frame.getTitle()+ " ("+sg.getName()+")");\r
-\r
-\r
this.ap = ap;\r
seqGroup = sg;\r
\r
+ if (seqGroup != null)\r
+ {\r
+ oldColourScheme = seqGroup.cs;\r
+ }\r
+ else\r
+ {\r
+ oldColourScheme = ap.av.getGlobalColourScheme();\r
+ }\r
+\r
+ init();\r
+ }\r
\r
- if (seqGroup != null)\r
- oldColourScheme = seqGroup.cs;\r
- else\r
- oldColourScheme = ap.av.getGlobalColourScheme();\r
+ public UserDefinedColours(MCview.AppletPDBCanvas pdb)\r
+ {\r
+ this.pdbcanvas = pdb;\r
+ init();\r
+ }\r
\r
- for (int i = 0; i < 20; i++)\r
- makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i]) +\r
- "", ResidueProperties.aa[i]);\r
+ public UserDefinedColours(Component caller,\r
+ String label,\r
+ Color colour)\r
+ {\r
+ this.caller = caller;\r
+ originalColour = colour;\r
+ originalLabel = label;\r
+ init();\r
+ remove(buttonPanel);\r
\r
- makeButton("B", "B");\r
- makeButton("Z", "Z");\r
- makeButton("X", "X");\r
- makeButton("Gap", "'.','-',' '");\r
+ setTargetColour(colour);\r
\r
+ okcancelPanel.setBounds(new Rectangle(0, 113, 400, 35));\r
+ frame.setTitle("User Defined Colours - "+label);\r
+ frame.setSize(420, 200);\r
}\r
\r
- protected void rText_actionPerformed(ActionEvent e) {\r
- try{\r
+ public void actionPerformed(ActionEvent evt)\r
+ {\r
+ if(evt.getSource()==okButton)\r
+ okButton_actionPerformed();\r
+ else if(evt.getSource()==applyButton)\r
+ applyButton_actionPerformed();\r
+ else if(evt.getSource()==cancelButton)\r
+ cancelButton_actionPerformed();\r
+ else if(evt.getSource()==rText)\r
+ rText_actionPerformed();\r
+ else if (evt.getSource() == gText)\r
+ gText_actionPerformed();\r
+ else if (evt.getSource() == bText)\r
+ bText_actionPerformed();\r
+}\r
+\r
+ public void adjustmentValueChanged(AdjustmentEvent evt)\r
+ {\r
+ if(evt.getSource()==rScroller)\r
+ rScroller_adjustmentValueChanged();\r
+ else if(evt.getSource()==gScroller)\r
+ gScroller_adjustmentValueChanged();\r
+ else if(evt.getSource()==bScroller)\r
+ bScroller_adjustmentValueChanged();\r
+}\r
+\r
+ void init()\r
+ {\r
+ try\r
+ {\r
+ jbInit();\r
+ }\r
+ catch (Exception e)\r
+ {\r
+ e.printStackTrace();\r
+ }\r
+ frame = new Frame();\r
+ frame.add(this);\r
+ jalview.bin.JalviewLite.addFrame(frame, "User defined colours", 420, 345);\r
+\r
+ if (seqGroup != null)\r
+ {\r
+ frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")");\r
+ }\r
+\r
+ for (int i = 0; i < 20; i++)\r
+ {\r
+ makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i]) +\r
+ "", ResidueProperties.aa[i]);\r
+ }\r
+\r
+ makeButton("B", "B");\r
+ makeButton("Z", "Z");\r
+ makeButton("X", "X");\r
+ makeButton("Gap", "'.','-',' '");\r
+\r
+ validate();\r
+ }\r
+ protected void rText_actionPerformed()\r
+ {\r
+ try\r
+ {\r
int i = Integer.parseInt(rText.getText());\r
rScroller.setValue(i);\r
- }catch(NumberFormatException ex){}\r
+ rScroller_adjustmentValueChanged();\r
+ }\r
+ catch (NumberFormatException ex)\r
+ {}\r
}\r
\r
- protected void gText_actionPerformed(ActionEvent e) {\r
- try{\r
+ protected void gText_actionPerformed()\r
+ {\r
+ try\r
+ {\r
int i = Integer.parseInt(gText.getText());\r
gScroller.setValue(i);\r
- }catch(NumberFormatException ex){}\r
+ gScroller_adjustmentValueChanged();\r
+ }\r
+ catch (NumberFormatException ex)\r
+ {}\r
\r
}\r
\r
- protected void bText_actionPerformed(ActionEvent e) {\r
- try{\r
+ protected void bText_actionPerformed()\r
+ {\r
+ try\r
+ {\r
int i = Integer.parseInt(bText.getText());\r
bScroller.setValue(i);\r
- }catch(NumberFormatException ex){}\r
+ bScroller_adjustmentValueChanged();\r
+ }\r
+ catch (NumberFormatException ex)\r
+ {}\r
\r
}\r
\r
-\r
- protected void rScroller_adjustmentValueChanged(AdjustmentEvent e) {\r
+ protected void rScroller_adjustmentValueChanged()\r
+ {\r
R = rScroller.getValue();\r
- rText.setText(R+"");\r
+ rText.setText(R + "");\r
colourChanged();\r
}\r
\r
- protected void gScroller_adjustmentValueChanged(AdjustmentEvent e) {\r
+ protected void gScroller_adjustmentValueChanged()\r
+ {\r
G = gScroller.getValue();\r
- gText.setText(G+"");\r
+ gText.setText(G + "");\r
colourChanged();\r
}\r
\r
- protected void bScroller_adjustmentValueChanged(AdjustmentEvent e) {\r
+ protected void bScroller_adjustmentValueChanged()\r
+ {\r
B = bScroller.getValue();\r
- bText.setText(B+"");\r
+ bText.setText(B + "");\r
colourChanged();\r
}\r
\r
- public void colourChanged()\r
- {\r
- Color col = new Color(R,G,B);\r
- target.setBackground( col );\r
+ public void colourChanged()\r
+ {\r
+ Color col = new Color(R, G, B);\r
+ target.setBackground(col);\r
+ target.repaint();\r
+\r
+ if (selectedButton != null)\r
+ {\r
+ selectedButton.setBackground(col);\r
+ selectedButton.repaint();\r
+ }\r
+ }\r
\r
- if(selectedButton!=null)\r
- selectedButton.setBackground( col );\r
- }\r
+ void setTargetColour(Color col)\r
+ {\r
+ R = col.getRed();\r
+ G = col.getGreen();\r
+ B = col.getBlue();\r
+ rScroller.setValue(R);\r
+ gScroller.setValue(G);\r
+ bScroller.setValue(B);\r
+ rText.setText(R + "");\r
+ gText.setText(G + "");\r
+ bText.setText(B + "");\r
+ colourChanged();\r
+ }\r
\r
public void colourButtonPressed(MouseEvent e)\r
{\r
- selectedButton = (Button)e.getSource();\r
- Color col = selectedButton.getBackground();\r
- R = col.getRed();\r
- G = col.getGreen();\r
- B = col.getBlue();\r
- rScroller.setValue(R);\r
- gScroller.setValue(G);\r
- bScroller.setValue(B);\r
- rText.setText(R+"");\r
- gText.setText(G+"");\r
- bText.setText(B+"");\r
-\r
- colourChanged();\r
+ selectedButton = (Button) e.getSource();\r
+ setTargetColour(selectedButton.getBackground());\r
}\r
\r
void makeButton(String label, String aa)\r
final Button button = new Button();\r
Color col = Color.white;\r
\r
-\r
- try{\r
+ try\r
+ {\r
col = oldColourScheme.findColour(aa, -1);\r
- }catch(Exception ex){}\r
+ }\r
+ catch (Exception ex)\r
+ {}\r
\r
- button.setBackground( col );\r
- oldColours.addElement( col );\r
- button.setLabel( label );\r
- button.setForeground( col.darker().darker().darker() );\r
+ button.setBackground(col);\r
+ oldColours.addElement(col);\r
+ button.setLabel(label);\r
+ button.setForeground(col.darker().darker().darker());\r
button.setFont(new java.awt.Font("Verdana", 1, 10));\r
button.addMouseListener(new java.awt.event.MouseAdapter()\r
{\r
- public void mouseClicked(MouseEvent e)\r
+ public void mousePressed(MouseEvent e)\r
{\r
colourButtonPressed(e);\r
}\r
buttonPanel.add(button, null);\r
}\r
\r
-\r
- protected void okButton_actionPerformed(ActionEvent e)\r
+ protected void okButton_actionPerformed()\r
{\r
- applyButton_actionPerformed(null);\r
- frame.setVisible(false);\r
+ applyButton_actionPerformed();\r
+ frame.setVisible(false);\r
}\r
\r
- protected void applyButton_actionPerformed(ActionEvent e)\r
+ protected void applyButton_actionPerformed()\r
{\r
-\r
- Color [] newColours = new Color[24];\r
- for(int i=0; i<24; i++)\r
+ if (caller != null)\r
{\r
- Button button = (Button)buttonPanel.getComponent(i);\r
- newColours[i] = button.getBackground();\r
+ if(caller instanceof FeatureSettings)\r
+ ((FeatureSettings)caller).setUserColour\r
+ (originalLabel, new Color(R,G,B));\r
+ else if(caller instanceof AnnotationColourChooser)\r
+ {\r
+ if (originalLabel.equals("Min Colour"))\r
+ ( (AnnotationColourChooser) caller).minColour_actionPerformed\r
+ (new Color(R, G, B));\r
+ else\r
+ ( (AnnotationColourChooser) caller).maxColour_actionPerformed\r
+ (new Color(R, G, B));\r
+ }\r
+ return;\r
}\r
\r
- UserColourScheme ucs = new UserColourScheme( newColours );\r
- ucs.setThreshold(0);\r
-\r
- if(seqGroup!=null)\r
- seqGroup.cs = ucs;\r
- else\r
- ap.av.setGlobalColourScheme(ucs);\r
\r
- ap.repaint();\r
- }\r
+ Color[] newColours = new Color[24];\r
+ for (int i = 0; i < 24; i++)\r
+ {\r
+ Button button = (Button) buttonPanel.getComponent(i);\r
+ newColours[i] = button.getBackground();\r
+ }\r
\r
+ UserColourScheme ucs = new UserColourScheme(newColours);\r
+ if(ap!=null)\r
+ ucs.setThreshold(0, ap.av.getIgnoreGapsConsensus());\r
\r
- public static UserColourScheme loadDefaultColours(String file)\r
- {\r
- UserColourScheme ucs = null;\r
- try\r
+ if(ap!=null)\r
{\r
- BufferedReader in = new BufferedReader(new FileReader(file));\r
- Color [] newColours = new Color[24];\r
- for (int i = 0; i < 24; i++)\r
+ if (seqGroup != null)\r
{\r
- newColours[i] = new Color(Integer.parseInt(in.readLine()));\r
+ seqGroup.cs = ucs;\r
}\r
-\r
- ucs = new UserColourScheme(newColours);\r
- ucs.setThreshold(0);\r
-\r
+ else\r
+ {\r
+ ap.av.setGlobalColourScheme(ucs);\r
+ }\r
+ ap.seqPanel.seqCanvas.img = null;\r
+ ap.repaint();\r
+ }\r
+ else if(pdbcanvas!=null)\r
+ {\r
+ pdbcanvas.pdb.setColours(ucs);\r
+ pdbcanvas.updateSeqColours();\r
}\r
- catch (Exception ex)\r
- {}\r
-\r
- return ucs;\r
}\r
\r
\r
- protected void cancelButton_actionPerformed(ActionEvent e)\r
+ protected void cancelButton_actionPerformed()\r
{\r
-\r
- Color [] newColours = new Color[24];\r
- for(int i=0; i<24; i++)\r
+ if (caller != null)\r
{\r
- newColours[i] = (Color)oldColours.elementAt(i);\r
- buttonPanel.getComponent(i).setBackground(newColours[i]);\r
+ if(caller instanceof FeatureSettings)\r
+ ((FeatureSettings)caller).setUserColour\r
+ (originalLabel, originalColour);\r
+ else if (caller instanceof AnnotationColourChooser)\r
+ {\r
+ if (originalLabel.equals("Min Colour"))\r
+ ( (AnnotationColourChooser) caller).minColour_actionPerformed\r
+ (originalColour);\r
+ else\r
+ ( (AnnotationColourChooser) caller).maxColour_actionPerformed\r
+ (originalColour);\r
+ }\r
+ frame.setVisible(false);\r
+ return;\r
}\r
\r
- UserColourScheme ucs = new UserColourScheme( newColours );\r
+ Color[] newColours = new Color[24];\r
+ for (int i = 0; i < 24; i++)\r
+ {\r
+ newColours[i] = (Color) oldColours.elementAt(i);\r
+ buttonPanel.getComponent(i).setBackground(newColours[i]);\r
+ }\r
\r
- if (seqGroup != null)\r
- seqGroup.cs = ucs;\r
- else\r
- ap.av.setGlobalColourScheme(ucs);\r
+ UserColourScheme ucs = new UserColourScheme(newColours);\r
\r
- ap.repaint();\r
+ if(ap!=null)\r
+ {\r
+ if (seqGroup != null)\r
+ {\r
+ seqGroup.cs = ucs;\r
+ }\r
+ else\r
+ {\r
+ ap.av.setGlobalColourScheme(ucs);\r
+ }\r
+ ap.repaint();\r
+ }\r
+ else if(pdbcanvas!=null)\r
+ {\r
+ pdbcanvas.pdb.setColours(ucs);\r
+ }\r
\r
frame.setVisible(false);\r
}\r
\r
\r
+ protected Panel buttonPanel = new Panel();\r
+ protected GridLayout gridLayout = new GridLayout();\r
+ Panel okcancelPanel = new Panel();\r
+ protected Button okButton = new Button();\r
+ protected Button applyButton = new Button();\r
+ protected Button cancelButton = new Button();\r
+ protected Scrollbar rScroller = new Scrollbar();\r
+ Label label1 = new Label();\r
+ protected TextField rText = new TextField();\r
+ Label label4 = new Label();\r
+ protected Scrollbar gScroller = new Scrollbar();\r
+ protected TextField gText = new TextField();\r
+ Label label5 = new Label();\r
+ protected Scrollbar bScroller = new Scrollbar();\r
+ protected TextField bText = new TextField();\r
+ protected Panel target = new Panel();\r
+\r
+ private void jbInit() throws Exception {\r
+ this.setLayout(null);\r
+ buttonPanel.setLayout(gridLayout);\r
+ gridLayout.setColumns(6);\r
+ gridLayout.setRows(4);\r
+ okButton.setFont(new java.awt.Font("Verdana", 0, 11));\r
+ okButton.setLabel("OK");\r
+ okButton.addActionListener(this);\r
+ applyButton.setFont(new java.awt.Font("Verdana", 0, 11));\r
+ applyButton.setLabel("Apply");\r
+ applyButton.addActionListener(this);\r
+ cancelButton.setFont(new java.awt.Font("Verdana", 0, 11));\r
+ cancelButton.setLabel("Cancel");\r
+ cancelButton.addActionListener(this);\r
+ this.setBackground(new Color(212, 208, 223));\r
+ okcancelPanel.setBounds(new Rectangle(0, 265, 400, 35));\r
+ buttonPanel.setBounds(new Rectangle(0, 123, 400, 142));\r
+ rScroller.setMaximum(256);\r
+ rScroller.setMinimum(0);\r
+ rScroller.setOrientation(0);\r
+ rScroller.setUnitIncrement(1);\r
+ rScroller.setVisibleAmount(1);\r
+ rScroller.setBounds(new Rectangle(36, 27, 119, 19));\r
+ rScroller.addAdjustmentListener(this);\r
+ label1.setAlignment(Label.RIGHT);\r
+ label1.setText("R");\r
+ label1.setBounds(new Rectangle(19, 30, 16, 15));\r
+ rText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));\r
+ rText.setText("0 ");\r
+ rText.setBounds(new Rectangle(156, 27, 53, 19));\r
+ rText.addActionListener(this);\r
+ label4.setAlignment(Label.RIGHT);\r
+ label4.setText("G");\r
+ label4.setBounds(new Rectangle(15, 56, 20, 15));\r
+ gScroller.setMaximum(256);\r
+ gScroller.setMinimum(0);\r
+ gScroller.setOrientation(0);\r
+ gScroller.setUnitIncrement(1);\r
+ gScroller.setVisibleAmount(1);\r
+ gScroller.setBounds(new Rectangle(35, 52, 120, 20));\r
+ gScroller.addAdjustmentListener(this);\r
+ gText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));\r
+ gText.setText("0 ");\r
+ gText.setBounds(new Rectangle(156, 52, 53, 20));\r
+ gText.addActionListener(this);\r
+ label5.setAlignment(Label.RIGHT);\r
+ label5.setText("B");\r
+ label5.setBounds(new Rectangle(14, 82, 20, 15));\r
+ bScroller.setMaximum(256);\r
+ bScroller.setMinimum(0);\r
+ bScroller.setOrientation(0);\r
+ bScroller.setUnitIncrement(1);\r
+ bScroller.setVisibleAmount(1);\r
+ bScroller.setBounds(new Rectangle(35, 78, 120, 20));\r
+ bScroller.addAdjustmentListener(this);\r
+ bText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));\r
+ bText.setText("0 ");\r
+ bText.setBounds(new Rectangle(157, 78, 52, 20));\r
+ bText.addActionListener(this);\r
+ target.setBackground(Color.black);\r
+ target.setBounds(new Rectangle(229, 26, 134, 79));\r
+ this.add(okcancelPanel, null);\r
+ okcancelPanel.add(okButton, null);\r
+ okcancelPanel.add(applyButton, null);\r
+ okcancelPanel.add(cancelButton, null);\r
+ this.add(buttonPanel, null);\r
+ this.add(target, null);\r
+ this.add(gScroller);\r
+ this.add(rScroller);\r
+ this.add(bScroller);\r
+ this.add(label5);\r
+ this.add(label4);\r
+ this.add(label1);\r
+ this.add(gText);\r
+ this.add(rText);\r
+ this.add(bText);\r
+}\r
+\r
}\r