X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FUserDefinedColours.java;h=6e14146846376e4fdc85cc50a6316bcb5850c33a;hb=56ad3ae1c8b2fefd7af371049e344acfc1f23944;hp=71bcacaf856b588c404407b843c27c86e15d6fbc;hpb=dfb45c8f874124d3ff3caac2902ed0c4a0e87cf5;p=jalview.git diff --git a/src/jalview/appletgui/UserDefinedColours.java b/src/jalview/appletgui/UserDefinedColours.java index 71bcaca..6e14146 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 @@ -28,7 +28,7 @@ import jalview.datamodel.*; import jalview.schemes.*; public class UserDefinedColours - extends Panel + extends Panel implements ActionListener, AdjustmentListener { AlignmentPanel ap; @@ -38,6 +38,12 @@ public class UserDefinedColours ColourSchemeI oldColourScheme; Frame frame; MCview.AppletPDBCanvas pdbcanvas; + AppletJmol jmol; + + Dialog dialog; + Object caller; + String originalLabel; + Color originalColour; int R = 0, G = 0, B = 0; @@ -70,6 +76,117 @@ public class UserDefinedColours init(); } + public UserDefinedColours(AppletJmol jmol) + { + this.jmol = jmol; + init(); + } + + public UserDefinedColours(FeatureRenderer fr, Frame alignframe) + { + caller = fr; + originalColour = fr.colourPanel.getBackground(); + originalLabel = "Feature Colour"; + setForDialog("Select Feature Colour", alignframe); + setTargetColour(fr.colourPanel.getBackground()); + dialog.setVisible(true); + } + + public UserDefinedColours(Component caller, + Color col1, + Frame alignframe) + { + this.caller = caller; + originalColour = col1; + originalLabel = "Select Colour"; + setForDialog("Select Colour", alignframe); + setTargetColour(col1); + dialog.setVisible(true); + } + + + public UserDefinedColours(Object 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); + } + + void setForDialog(String title, Frame alignframe) + { + init(); + frame.setVisible(false); + remove(buttonPanel); + dialog = new Dialog(alignframe, title, true); + + dialog.add(this); + this.setSize(400,123); + okcancelPanel.setBounds(new Rectangle(0, 123, 400, 35)); + int height = 160 + alignframe.getInsets().top + getInsets().bottom; + int width = 400; + + dialog.setBounds(alignframe.getBounds().x + + (alignframe.getSize().width - width) / 2, + alignframe.getBounds().y + + (alignframe.getSize().height - height) / 2, + width, height); + + } + + 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 @@ -102,59 +219,60 @@ public class UserDefinedColours validate(); } - protected void rText_actionPerformed(ActionEvent e) + + protected void rText_actionPerformed() { try { int i = Integer.parseInt(rText.getText()); rScroller.setValue(i); - rScroller_adjustmentValueChanged(null); + 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(null); + 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(null); + 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 + ""); @@ -174,23 +292,27 @@ public class UserDefinedColours } } - 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(); + rScroller.setValue(R); gScroller.setValue(G); bScroller.setValue(B); 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(); @@ -198,7 +320,7 @@ public class UserDefinedColours try { - col = oldColourScheme.findColour(aa, -1); + col = oldColourScheme.findColour(aa.charAt(0), -1); } catch (Exception ex) {} @@ -219,14 +341,50 @@ public class UserDefinedColours buttonPanel.add(button, null); } - protected void okButton_actionPerformed(ActionEvent e) + protected void okButton_actionPerformed() { - applyButton_actionPerformed(null); + applyButton_actionPerformed(); + if (dialog != null) + dialog.setVisible(false); + frame.setVisible(false); } - protected void applyButton_actionPerformed(ActionEvent e) + public Color getColor() { + return new Color(R, G, B); + } + + protected void applyButton_actionPerformed() + { + if (caller != null) + { + if (caller instanceof FeatureSettings) + { + ( (FeatureSettings) caller).setUserColour + (originalLabel, getColor()); + } + else if (caller instanceof AnnotationColourChooser) + { + if (originalLabel.equals("Min Colour")) + { + ( (AnnotationColourChooser) caller).minColour_actionPerformed + (getColor()); + } + else + { + ( (AnnotationColourChooser) caller).maxColour_actionPerformed + (getColor()); + } + } + else if(caller instanceof FeatureRenderer) + { + ((FeatureRenderer)caller).colourPanel.setBackground(getColor()); + } + + return; + } + Color[] newColours = new Color[24]; for (int i = 0; i < 24; i++) { @@ -235,10 +393,12 @@ public class UserDefinedColours } UserColourScheme ucs = new UserColourScheme(newColours); - if(ap!=null) + if (ap != null) + { ucs.setThreshold(0, ap.av.getIgnoreGapsConsensus()); + } - if(ap!=null) + if (ap != null) { if (seqGroup != null) { @@ -249,18 +409,52 @@ public class UserDefinedColours ap.av.setGlobalColourScheme(ucs); } ap.seqPanel.seqCanvas.img = null; - ap.repaint(); + ap.paintAlignment(true); } - else if(pdbcanvas!=null) + else if(jmol!=null) { - pdbcanvas.pdb.setColours(ucs); - pdbcanvas.updateSeqColours(); + jmol.setJalviewColourScheme(ucs); + } + else if (pdbcanvas != null) + { + pdbcanvas.setColours(ucs); } } - - protected void cancelButton_actionPerformed(ActionEvent e) + protected void cancelButton_actionPerformed() { + if (caller != null) + { + if (caller instanceof FeatureSettings) + { + ( (FeatureSettings) caller).setUserColour + (originalLabel, originalColour); + } + else if (caller instanceof AnnotationColourChooser) + { + if (originalLabel.equals("Min Colour")) + { + ( (AnnotationColourChooser) caller).minColour_actionPerformed + (originalColour); + } + else + { + ( (AnnotationColourChooser) caller).maxColour_actionPerformed + (originalColour); + } + } + else if (caller instanceof FeatureRenderer) + { + ( (FeatureRenderer) caller).colourPanel.setBackground(originalColour); + + } + + if(dialog!=null) + dialog.setVisible(false); + + frame.setVisible(false); + return; + } Color[] newColours = new Color[24]; for (int i = 0; i < 24; i++) @@ -271,7 +465,7 @@ public class UserDefinedColours UserColourScheme ucs = new UserColourScheme(newColours); - if(ap!=null) + if (ap != null) { if (seqGroup != null) { @@ -281,9 +475,13 @@ public class UserDefinedColours { ap.av.setGlobalColourScheme(ucs); } - ap.repaint(); + ap.paintAlignment(true); } - else if(pdbcanvas!=null) + else if(jmol !=null) + { + jmol.setJalviewColourScheme(ucs); + } + else if (pdbcanvas != null) { pdbcanvas.pdb.setColours(ucs); } @@ -291,10 +489,9 @@ public class UserDefinedColours frame.setVisible(false); } - protected Panel buttonPanel = new Panel(); protected GridLayout gridLayout = new GridLayout(); - Panel jPanel2 = new Panel(); + Panel okcancelPanel = new Panel(); protected Button okButton = new Button(); protected Button applyButton = new Button(); protected Button cancelButton = new Button(); @@ -309,118 +506,84 @@ public class UserDefinedColours 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(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { - okButton_actionPerformed(e); - } - }); - applyButton.setFont(new java.awt.Font("Verdana", 0, 11)); - applyButton.setLabel("Apply"); - applyButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { - applyButton_actionPerformed(e); - } - }); - cancelButton.setFont(new java.awt.Font("Verdana", 0, 11)); - cancelButton.setLabel("Cancel"); - cancelButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { - cancelButton_actionPerformed(e); - } - }); - this.setBackground(new Color(212, 208, 223)); - jPanel2.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(new java.awt.event.AdjustmentListener() { - public void adjustmentValueChanged(AdjustmentEvent e) { - rScroller_adjustmentValueChanged(e); - } - }); - 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(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { - rText_actionPerformed(e); - } - }); - 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(new java.awt.event.AdjustmentListener() { - public void adjustmentValueChanged(AdjustmentEvent e) { - gScroller_adjustmentValueChanged(e); - } - }); - gText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10)); - gText.setText("0 "); - gText.setBounds(new Rectangle(156, 52, 53, 20)); - gText.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { - gText_actionPerformed(e); - } - }); - 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(new java.awt.event.AdjustmentListener() { - public void adjustmentValueChanged(AdjustmentEvent e) { - bScroller_adjustmentValueChanged(e); - } - }); - bText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10)); - bText.setText("0 "); - bText.setBounds(new Rectangle(157, 78, 52, 20)); - bText.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { - bText_actionPerformed(e); - } - }); - target.setBackground(Color.black); - target.setBounds(new Rectangle(229, 26, 134, 79)); - this.add(jPanel2, null); - jPanel2.add(okButton, null); - jPanel2.add(applyButton, null); - jPanel2.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); -} + 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); + } }