X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FUserDefinedColours.java;h=6e14146846376e4fdc85cc50a6316bcb5850c33a;hb=952ae154954fe87b94cccb765d32718689b9e9a0;hp=6544993bf8a858f982289f7536651bace4ecad76;hpb=a4c90a2c3a3b977a542250e2cfdfb0d8b247d4aa;p=jalview.git diff --git a/src/jalview/appletgui/UserDefinedColours.java b/src/jalview/appletgui/UserDefinedColours.java index 6544993..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 @@ -38,9 +38,12 @@ public class UserDefinedColours ColourSchemeI oldColourScheme; Frame frame; MCview.AppletPDBCanvas pdbcanvas; - FeatureSettings featureSettings; - String feature; - Color originalFeatureCol; + AppletJmol jmol; + + Dialog dialog; + Object caller; + String originalLabel; + Color originalColour; int R = 0, G = 0, B = 0; @@ -73,47 +76,116 @@ public class UserDefinedColours init(); } - public UserDefinedColours(FeatureSettings featureSettings, - String feature, - Color col) + public UserDefinedColours(AppletJmol jmol) { - this.featureSettings = featureSettings; - this.feature = feature; + 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); - originalFeatureCol = col; - setTargetColour(col); + + setTargetColour(colour); okcancelPanel.setBounds(new Rectangle(0, 113, 400, 35)); - frame.setTitle("User Defined Colours - "+feature); + 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) + 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(); -} + } + 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(); -} + if (evt.getSource() == rScroller) + { + rScroller_adjustmentValueChanged(); + } + else if (evt.getSource() == gScroller) + { + gScroller_adjustmentValueChanged(); + } + else if (evt.getSource() == bScroller) + { + bScroller_adjustmentValueChanged(); + } + } void init() { @@ -147,6 +219,7 @@ public class UserDefinedColours validate(); } + protected void rText_actionPerformed() { try @@ -224,6 +297,7 @@ public class UserDefinedColours R = col.getRed(); G = col.getGreen(); B = col.getBlue(); + rScroller.setValue(R); gScroller.setValue(G); bScroller.setValue(B); @@ -246,7 +320,7 @@ public class UserDefinedColours try { - col = oldColourScheme.findColour(aa, -1); + col = oldColourScheme.findColour(aa.charAt(0), -1); } catch (Exception ex) {} @@ -270,14 +344,44 @@ public class UserDefinedColours protected void okButton_actionPerformed() { applyButton_actionPerformed(); + if (dialog != null) + dialog.setVisible(false); + frame.setVisible(false); } + public Color getColor() + { + return new Color(R, G, B); + } + protected void applyButton_actionPerformed() { - if (featureSettings != null) + if (caller != null) { - featureSettings.setUserColour(feature, new Color(R,G,B)); + 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; } @@ -289,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) { @@ -303,21 +409,49 @@ 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() { - if(featureSettings!=null) + if (caller != null) { - featureSettings.setUserColour(feature, originalFeatureCol); + 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; } @@ -331,7 +465,7 @@ public class UserDefinedColours UserColourScheme ucs = new UserColourScheme(newColours); - if(ap!=null) + if (ap != null) { if (seqGroup != null) { @@ -341,9 +475,13 @@ public class UserDefinedColours { ap.av.setGlobalColourScheme(ucs); } - ap.repaint(); + ap.paintAlignment(true); + } + else if(jmol !=null) + { + jmol.setJalviewColourScheme(ucs); } - else if(pdbcanvas!=null) + else if (pdbcanvas != null) { pdbcanvas.pdb.setColours(ucs); } @@ -351,7 +489,6 @@ public class UserDefinedColours frame.setVisible(false); } - protected Panel buttonPanel = new Panel(); protected GridLayout gridLayout = new GridLayout(); Panel okcancelPanel = new Panel(); @@ -369,82 +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(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); -} + 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); + } }