X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FUserDefinedColours.java;h=af08b7529b6ac4bf1ef49123d03a88603992e25e;hb=7bc226b58110fa26d9dbd3f0c78095d06909ffc3;hp=80d91efdfcdbac60c4c1e7148c21b2c6f138fb1a;hpb=588042b69abf8e60bcc950b24c283933c7dd422f;p=jalview.git diff --git a/src/jalview/appletgui/UserDefinedColours.java b/src/jalview/appletgui/UserDefinedColours.java index 80d91ef..af08b75 100755 --- a/src/jalview/appletgui/UserDefinedColours.java +++ b/src/jalview/appletgui/UserDefinedColours.java @@ -1,6 +1,6 @@ /* * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -19,18 +19,16 @@ package jalview.appletgui; -import java.io.*; import java.util.*; import java.awt.*; import java.awt.event.*; import jalview.datamodel.*; -import jalview.jbappletgui.*; import jalview.schemes.*; public class UserDefinedColours - extends GUserDefinedColours + extends Panel implements ActionListener, AdjustmentListener { AlignmentPanel ap; @@ -39,6 +37,11 @@ public class UserDefinedColours Vector oldColours = new Vector(); ColourSchemeI oldColourScheme; Frame frame; + MCview.AppletPDBCanvas pdbcanvas; + + Component caller; + String originalLabel; + Color originalColour; int R = 0, G = 0, B = 0; @@ -50,16 +53,6 @@ public class UserDefinedColours public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg) { - super(); - frame = new Frame(); - frame.add(this); - jalview.bin.JalviewLite.addFrame(frame, "User defined colours", 420, 345); - - if (sg != null) - { - frame.setTitle(frame.getTitle() + " (" + sg.getName() + ")"); - } - this.ap = ap; seqGroup = sg; @@ -72,6 +65,95 @@ public class UserDefinedColours oldColourScheme = ap.av.getGlobalColourScheme(); } + init(); + } + + public UserDefinedColours(MCview.AppletPDBCanvas pdb) + { + this.pdbcanvas = pdb; + init(); + } + + public UserDefinedColours(Component caller, + String label, + Color colour) + { + this.caller = caller; + originalColour = colour; + originalLabel = label; + init(); + remove(buttonPanel); + + setTargetColour(colour); + + okcancelPanel.setBounds(new Rectangle(0, 113, 400, 35)); + frame.setTitle("User Defined Colours - " + label); + frame.setSize(420, 200); + } + + public void actionPerformed(ActionEvent evt) + { + if (evt.getSource() == okButton) + { + okButton_actionPerformed(); + } + else if (evt.getSource() == applyButton) + { + applyButton_actionPerformed(); + } + else if (evt.getSource() == cancelButton) + { + cancelButton_actionPerformed(); + } + else if (evt.getSource() == rText) + { + rText_actionPerformed(); + } + else if (evt.getSource() == gText) + { + gText_actionPerformed(); + } + else if (evt.getSource() == bText) + { + bText_actionPerformed(); + } + } + + public void adjustmentValueChanged(AdjustmentEvent evt) + { + if (evt.getSource() == rScroller) + { + rScroller_adjustmentValueChanged(); + } + else if (evt.getSource() == gScroller) + { + gScroller_adjustmentValueChanged(); + } + else if (evt.getSource() == bScroller) + { + bScroller_adjustmentValueChanged(); + } + } + + void init() + { + try + { + jbInit(); + } + catch (Exception e) + { + e.printStackTrace(); + } + frame = new Frame(); + frame.add(this); + jalview.bin.JalviewLite.addFrame(frame, "User defined colours", 420, 345); + + if (seqGroup != null) + { + frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")"); + } + for (int i = 0; i < 20; i++) { makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i]) + @@ -83,58 +165,62 @@ public class UserDefinedColours makeButton("X", "X"); makeButton("Gap", "'.','-',' '"); + validate(); } - protected void rText_actionPerformed(ActionEvent e) + protected void rText_actionPerformed() { try { int i = Integer.parseInt(rText.getText()); rScroller.setValue(i); + rScroller_adjustmentValueChanged(); } catch (NumberFormatException ex) {} } - protected void gText_actionPerformed(ActionEvent e) + protected void gText_actionPerformed() { try { int i = Integer.parseInt(gText.getText()); gScroller.setValue(i); + gScroller_adjustmentValueChanged(); } catch (NumberFormatException ex) {} } - protected void bText_actionPerformed(ActionEvent e) + protected void bText_actionPerformed() { try { int i = Integer.parseInt(bText.getText()); bScroller.setValue(i); + bScroller_adjustmentValueChanged(); } catch (NumberFormatException ex) {} } - protected void rScroller_adjustmentValueChanged(AdjustmentEvent e) + protected void rScroller_adjustmentValueChanged() { R = rScroller.getValue(); rText.setText(R + ""); colourChanged(); } - protected void gScroller_adjustmentValueChanged(AdjustmentEvent e) + protected void gScroller_adjustmentValueChanged() { G = gScroller.getValue(); gText.setText(G + ""); colourChanged(); } - protected void bScroller_adjustmentValueChanged(AdjustmentEvent e) + protected void bScroller_adjustmentValueChanged() { B = bScroller.getValue(); bText.setText(B + ""); @@ -145,17 +231,17 @@ public class UserDefinedColours { Color col = new Color(R, G, B); target.setBackground(col); + target.repaint(); if (selectedButton != null) { selectedButton.setBackground(col); + selectedButton.repaint(); } } - public void colourButtonPressed(MouseEvent e) + void setTargetColour(Color col) { - selectedButton = (Button) e.getSource(); - Color col = selectedButton.getBackground(); R = col.getRed(); G = col.getGreen(); B = col.getBlue(); @@ -165,10 +251,15 @@ public class UserDefinedColours rText.setText(R + ""); gText.setText(G + ""); bText.setText(B + ""); - colourChanged(); } + public void colourButtonPressed(MouseEvent e) + { + selectedButton = (Button) e.getSource(); + setTargetColour(selectedButton.getBackground()); + } + void makeButton(String label, String aa) { final Button button = new Button(); @@ -176,7 +267,7 @@ public class UserDefinedColours try { - col = oldColourScheme.findColour(aa, -1); + col = oldColourScheme.findColour(aa.charAt(0), -1); } catch (Exception ex) {} @@ -188,7 +279,7 @@ public class UserDefinedColours button.setFont(new java.awt.Font("Verdana", 1, 10)); button.addMouseListener(new java.awt.event.MouseAdapter() { - public void mouseClicked(MouseEvent e) + public void mousePressed(MouseEvent e) { colourButtonPressed(e); } @@ -197,14 +288,36 @@ public class UserDefinedColours buttonPanel.add(button, null); } - protected void okButton_actionPerformed(ActionEvent e) + protected void okButton_actionPerformed() { - applyButton_actionPerformed(null); + applyButton_actionPerformed(); frame.setVisible(false); } - protected void applyButton_actionPerformed(ActionEvent e) + protected void applyButton_actionPerformed() { + if (caller != null) + { + if (caller instanceof FeatureSettings) + { + ( (FeatureSettings) caller).setUserColour + (originalLabel, new Color(R, G, B)); + } + else if (caller instanceof AnnotationColourChooser) + { + if (originalLabel.equals("Min Colour")) + { + ( (AnnotationColourChooser) caller).minColour_actionPerformed + (new Color(R, G, B)); + } + else + { + ( (AnnotationColourChooser) caller).maxColour_actionPerformed + (new Color(R, G, B)); + } + } + return; + } Color[] newColours = new Color[24]; for (int i = 0; i < 24; i++) @@ -214,44 +327,56 @@ public class UserDefinedColours } UserColourScheme ucs = new UserColourScheme(newColours); - ucs.setThreshold(0); + if (ap != null) + { + ucs.setThreshold(0, ap.av.getIgnoreGapsConsensus()); + } - if (seqGroup != null) + if (ap != null) { - seqGroup.cs = ucs; + if (seqGroup != null) + { + seqGroup.cs = ucs; + } + else + { + ap.av.setGlobalColourScheme(ucs); + } + ap.seqPanel.seqCanvas.img = null; + ap.repaint(); } - else + else if (pdbcanvas != null) { - ap.av.setGlobalColourScheme(ucs); + pdbcanvas.pdb.setColours(ucs); + pdbcanvas.updateSeqColours(); } - - ap.repaint(); } - public static UserColourScheme loadDefaultColours(String file) + protected void cancelButton_actionPerformed() { - UserColourScheme ucs = null; - try + if (caller != null) { - BufferedReader in = new BufferedReader(new FileReader(file)); - Color[] newColours = new Color[24]; - for (int i = 0; i < 24; i++) + if (caller instanceof FeatureSettings) { - newColours[i] = new Color(Integer.parseInt(in.readLine())); + ( (FeatureSettings) caller).setUserColour + (originalLabel, originalColour); } - - ucs = new UserColourScheme(newColours); - ucs.setThreshold(0); - + else if (caller instanceof AnnotationColourChooser) + { + if (originalLabel.equals("Min Colour")) + { + ( (AnnotationColourChooser) caller).minColour_actionPerformed + (originalColour); + } + else + { + ( (AnnotationColourChooser) caller).maxColour_actionPerformed + (originalColour); + } + } + frame.setVisible(false); + return; } - catch (Exception ex) - {} - - return ucs; - } - - protected void cancelButton_actionPerformed(ActionEvent e) - { Color[] newColours = new Color[24]; for (int i = 0; i < 24; i++) @@ -262,18 +387,121 @@ public class UserDefinedColours UserColourScheme ucs = new UserColourScheme(newColours); - if (seqGroup != null) + if (ap != null) { - seqGroup.cs = ucs; + if (seqGroup != null) + { + seqGroup.cs = ucs; + } + else + { + ap.av.setGlobalColourScheme(ucs); + } + ap.repaint(); } - else + else if (pdbcanvas != null) { - ap.av.setGlobalColourScheme(ucs); + pdbcanvas.pdb.setColours(ucs); } - ap.repaint(); - frame.setVisible(false); } + protected Panel buttonPanel = new Panel(); + protected GridLayout gridLayout = new GridLayout(); + Panel okcancelPanel = new Panel(); + protected Button okButton = new Button(); + protected Button applyButton = new Button(); + protected Button cancelButton = new Button(); + protected Scrollbar rScroller = new Scrollbar(); + Label label1 = new Label(); + protected TextField rText = new TextField(); + Label label4 = new Label(); + protected Scrollbar gScroller = new Scrollbar(); + protected TextField gText = new TextField(); + Label label5 = new Label(); + protected Scrollbar bScroller = new Scrollbar(); + protected TextField bText = new TextField(); + protected Panel target = new Panel(); + + private void jbInit() + throws Exception + { + this.setLayout(null); + buttonPanel.setLayout(gridLayout); + gridLayout.setColumns(6); + gridLayout.setRows(4); + okButton.setFont(new java.awt.Font("Verdana", 0, 11)); + okButton.setLabel("OK"); + okButton.addActionListener(this); + applyButton.setFont(new java.awt.Font("Verdana", 0, 11)); + applyButton.setLabel("Apply"); + applyButton.addActionListener(this); + cancelButton.setFont(new java.awt.Font("Verdana", 0, 11)); + cancelButton.setLabel("Cancel"); + cancelButton.addActionListener(this); + this.setBackground(new Color(212, 208, 223)); + okcancelPanel.setBounds(new Rectangle(0, 265, 400, 35)); + buttonPanel.setBounds(new Rectangle(0, 123, 400, 142)); + rScroller.setMaximum(256); + rScroller.setMinimum(0); + rScroller.setOrientation(0); + rScroller.setUnitIncrement(1); + rScroller.setVisibleAmount(1); + rScroller.setBounds(new Rectangle(36, 27, 119, 19)); + rScroller.addAdjustmentListener(this); + label1.setAlignment(Label.RIGHT); + label1.setText("R"); + label1.setBounds(new Rectangle(19, 30, 16, 15)); + rText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10)); + rText.setText("0 "); + rText.setBounds(new Rectangle(156, 27, 53, 19)); + rText.addActionListener(this); + label4.setAlignment(Label.RIGHT); + label4.setText("G"); + label4.setBounds(new Rectangle(15, 56, 20, 15)); + gScroller.setMaximum(256); + gScroller.setMinimum(0); + gScroller.setOrientation(0); + gScroller.setUnitIncrement(1); + gScroller.setVisibleAmount(1); + gScroller.setBounds(new Rectangle(35, 52, 120, 20)); + gScroller.addAdjustmentListener(this); + gText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10)); + gText.setText("0 "); + gText.setBounds(new Rectangle(156, 52, 53, 20)); + gText.addActionListener(this); + label5.setAlignment(Label.RIGHT); + label5.setText("B"); + label5.setBounds(new Rectangle(14, 82, 20, 15)); + bScroller.setMaximum(256); + bScroller.setMinimum(0); + bScroller.setOrientation(0); + bScroller.setUnitIncrement(1); + bScroller.setVisibleAmount(1); + bScroller.setBounds(new Rectangle(35, 78, 120, 20)); + bScroller.addAdjustmentListener(this); + bText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10)); + bText.setText("0 "); + bText.setBounds(new Rectangle(157, 78, 52, 20)); + bText.addActionListener(this); + target.setBackground(Color.black); + target.setBounds(new Rectangle(229, 26, 134, 79)); + this.add(okcancelPanel, null); + okcancelPanel.add(okButton, null); + okcancelPanel.add(applyButton, null); + okcancelPanel.add(cancelButton, null); + this.add(buttonPanel, null); + this.add(target, null); + this.add(gScroller); + this.add(rScroller); + this.add(bScroller); + this.add(label5); + this.add(label4); + this.add(label1); + this.add(gText); + this.add(rText); + this.add(bText); + } + }