X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fjalview%2Fappletgui%2FUserDefinedColours.java;h=83d6fd6a999db66062e4db1be1c4b2879b2e1d7e;hb=a7169b1c72607f3c9357195b4999869650a2a891;hp=73df35f87be67cd73eee873507c31561a7735d78;hpb=a79f9e113c51c032070c670e45ce3eb464691166;p=jalview.git
diff --git a/src/jalview/appletgui/UserDefinedColours.java b/src/jalview/appletgui/UserDefinedColours.java
old mode 100755
new mode 100644
index 73df35f..83d6fd6
--- a/src/jalview/appletgui/UserDefinedColours.java
+++ b/src/jalview/appletgui/UserDefinedColours.java
@@ -1,27 +1,36 @@
/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
- * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
*
* This file is part of Jalview.
*
* Jalview is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
- *
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
* Jalview is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along with Jalview. If not, see .
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
*/
package jalview.appletgui;
+import jalview.analysis.AAFrequency;
+import jalview.api.FeatureColourI;
import jalview.datamodel.SequenceGroup;
+import jalview.renderer.ResidueShader;
+import jalview.schemes.Blosum62ColourScheme;
import jalview.schemes.ColourSchemeI;
-import jalview.schemes.GraduatedColor;
+import jalview.schemes.FeatureColour;
+import jalview.schemes.PIDColourScheme;
import jalview.schemes.ResidueProperties;
import jalview.schemes.UserColourScheme;
+import jalview.util.MessageManager;
import java.awt.Button;
import java.awt.Color;
@@ -40,11 +49,13 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
import java.awt.event.MouseEvent;
import java.util.Vector;
-public class UserDefinedColours extends Panel implements ActionListener,
- AdjustmentListener
+public class UserDefinedColours extends Panel
+ implements ActionListener, AdjustmentListener, FocusListener
{
AlignmentPanel ap;
@@ -53,13 +64,13 @@ public class UserDefinedColours extends Panel implements ActionListener,
Button selectedButton;
- Vector oldColours = new Vector();
+ Vector oldColours = new Vector<>();
ColourSchemeI oldColourScheme;
Frame frame;
- MCview.AppletPDBCanvas pdbcanvas;
+ mc_view.AppletPDBCanvas pdbcanvas;
AppletJmol jmol;
@@ -69,7 +80,7 @@ public class UserDefinedColours extends Panel implements ActionListener,
String originalLabel;
- Object originalColour;
+ FeatureColourI originalColour;
int R = 0, G = 0, B = 0;
@@ -86,7 +97,7 @@ public class UserDefinedColours extends Panel implements ActionListener,
if (seqGroup != null)
{
- oldColourScheme = seqGroup.cs;
+ oldColourScheme = seqGroup.getColourScheme();
}
else
{
@@ -96,7 +107,7 @@ public class UserDefinedColours extends Panel implements ActionListener,
init();
}
- public UserDefinedColours(MCview.AppletPDBCanvas pdb)
+ public UserDefinedColours(mc_view.AppletPDBCanvas pdb)
{
this.pdbcanvas = pdb;
init();
@@ -111,7 +122,7 @@ public class UserDefinedColours extends Panel implements ActionListener,
public UserDefinedColours(FeatureRenderer fr, Frame alignframe)
{
caller = fr;
- originalColour = fr.colourPanel.getBackground();
+ originalColour = new FeatureColour(fr.colourPanel.getBackground());
originalLabel = "Feature Colour";
setForDialog("Select Feature Colour", alignframe);
setTargetColour(fr.colourPanel.getBackground());
@@ -128,21 +139,21 @@ public class UserDefinedColours extends Panel implements ActionListener,
*
* @param caller
* - handles events
- * @param col1
+ * @param col
* - original colour
* @param alignframe
* - the parent Frame for the dialog
* @param title
* - window title
*/
- public UserDefinedColours(Component caller, Color col1, Frame alignframe,
+ public UserDefinedColours(Component caller, Color col, Frame alignframe,
String title)
{
this.caller = caller;
- originalColour = col1;
+ originalColour = new FeatureColour(col);
originalLabel = title;
setForDialog(title, alignframe);
- setTargetColour(col1);
+ setTargetColour(col);
dialog.setVisible(true);
}
@@ -155,7 +166,7 @@ public class UserDefinedColours extends Panel implements ActionListener,
*/
public UserDefinedColours(Object caller, String label, Color colour)
{
- this(caller, label, colour, colour);
+ this(caller, label, new FeatureColour(colour), colour);
}
/**
@@ -166,13 +177,13 @@ public class UserDefinedColours extends Panel implements ActionListener,
* @param graduatedColor
*/
public UserDefinedColours(FeatureSettings me, String type,
- GraduatedColor graduatedColor)
+ FeatureColourI graduatedColor)
{
- this(me, type, graduatedColor, graduatedColor.getMaxColor());
+ this(me, type, graduatedColor, graduatedColor.getMaxColour());
}
- private UserDefinedColours(Object caller, String label, Object ocolour,
- Color colour)
+ private UserDefinedColours(Object caller, String label,
+ FeatureColourI ocolour, Color colour)
{
this.caller = caller;
originalColour = ocolour;
@@ -183,7 +194,8 @@ public class UserDefinedColours extends Panel implements ActionListener,
setTargetColour(colour);
okcancelPanel.setBounds(new Rectangle(0, 113, 400, 35));
- frame.setTitle("User Defined Colours - " + label);
+ frame.setTitle(MessageManager.getString("label.user_defined_colours")
+ + " - " + label);
frame.setSize(420, 200);
}
@@ -202,7 +214,8 @@ public class UserDefinedColours extends Panel implements ActionListener,
// // not 1.1 compatible!
// dialog = new Dialog(((JVDialog)alignframe), title, true);
// } else {
- throw new Error("Unsupported owner for User Colour scheme dialog.");
+ throw new Error(MessageManager.getString(
+ "label.error_unsupported_owwner_user_colour_scheme"));
}
dialog.add(this);
@@ -211,42 +224,46 @@ public class UserDefinedColours extends Panel implements ActionListener,
int height = 160 + alignframe.getInsets().top + getInsets().bottom;
int width = 400;
- dialog.setBounds(alignframe.getBounds().x
- + (alignframe.getSize().width - width) / 2,
+ dialog.setBounds(
+ alignframe.getBounds().x
+ + (alignframe.getSize().width - width) / 2,
alignframe.getBounds().y
- + (alignframe.getSize().height - height) / 2, width,
- height);
+ + (alignframe.getSize().height - height) / 2,
+ width, height);
}
+ @Override
public void actionPerformed(ActionEvent evt)
{
- if (evt.getSource() == okButton)
+ final Object source = evt.getSource();
+ if (source == okButton)
{
okButton_actionPerformed();
}
- else if (evt.getSource() == applyButton)
+ else if (source == applyButton)
{
applyButton_actionPerformed();
}
- else if (evt.getSource() == cancelButton)
+ else if (source == cancelButton)
{
cancelButton_actionPerformed();
}
- else if (evt.getSource() == rText)
+ else if (source == rText)
{
rText_actionPerformed();
}
- else if (evt.getSource() == gText)
+ else if (source == gText)
{
gText_actionPerformed();
}
- else if (evt.getSource() == bText)
+ else if (source == bText)
{
bText_actionPerformed();
}
}
+ @Override
public void adjustmentValueChanged(AdjustmentEvent evt)
{
if (evt.getSource() == rScroller)
@@ -274,7 +291,8 @@ public class UserDefinedColours extends Panel implements ActionListener,
}
frame = new Frame();
frame.add(this);
- jalview.bin.JalviewLite.addFrame(frame, "User defined colours", 420,
+ jalview.bin.JalviewLite.addFrame(frame,
+ MessageManager.getString("label.user_defined_colours"), 420,
345);
if (seqGroup != null)
@@ -393,14 +411,9 @@ public class UserDefinedColours extends Panel implements ActionListener,
{
final Button button = new Button();
Color col = Color.white;
- if (oldColourScheme != null)
+ if (oldColourScheme != null && oldColourScheme.isSimple())
{
- try
- {
- col = oldColourScheme.findColour(aa.charAt(0), -1, null);
- } catch (Exception ex)
- {
- }
+ col = oldColourScheme.findColour(aa.charAt(0), 0, null, null, 0f);
}
button.setBackground(col);
oldColours.addElement(col);
@@ -409,6 +422,7 @@ public class UserDefinedColours extends Panel implements ActionListener,
button.setFont(new java.awt.Font("Verdana", 1, 10));
button.addMouseListener(new java.awt.event.MouseAdapter()
{
+ @Override
public void mousePressed(MouseEvent e)
{
colourButtonPressed(e);
@@ -422,7 +436,9 @@ public class UserDefinedColours extends Panel implements ActionListener,
{
applyButton_actionPerformed();
if (dialog != null)
+ {
dialog.setVisible(false);
+ }
frame.setVisible(false);
}
@@ -438,7 +454,8 @@ public class UserDefinedColours extends Panel implements ActionListener,
{
if (caller instanceof FeatureSettings)
{
- ((FeatureSettings) caller).setUserColour(originalLabel, getColor());
+ ((FeatureSettings) caller).setUserColour(originalLabel,
+ new FeatureColour(getColor()));
}
else if (caller instanceof AnnotationColourChooser)
{
@@ -455,7 +472,8 @@ public class UserDefinedColours extends Panel implements ActionListener,
}
else if (caller instanceof FeatureRenderer)
{
- ((FeatureRenderer) caller).colourPanel.updateColor(getColor());
+ ((FeatureRenderer) caller).colourPanel
+ .updateColor(new FeatureColour(getColor()));
}
else if (caller instanceof FeatureColourChooser)
{
@@ -482,27 +500,31 @@ public class UserDefinedColours extends Panel implements ActionListener,
}
UserColourScheme ucs = new UserColourScheme(newColours);
- if (ap != null)
- {
- ucs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
- }
+ // if (ap != null)
+ // {
+ // ucs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
+ // }
if (ap != null)
{
if (seqGroup != null)
{
- seqGroup.cs = ucs;
+ seqGroup.cs = new ResidueShader(ucs);
+ seqGroup.getGroupColourScheme().setThreshold(0,
+ ap.av.isIgnoreGapsConsensus());
}
else
{
ap.av.setGlobalColourScheme(ucs);
+ ap.av.getResidueShading().setThreshold(0,
+ ap.av.isIgnoreGapsConsensus());
}
ap.seqPanel.seqCanvas.img = null;
- ap.paintAlignment(true);
+ ap.paintAlignment(true, true);
}
else if (jmol != null)
{
- jmol.setJalviewColourScheme(ucs);
+ jmol.colourByJalviewColourScheme(ucs);
}
else if (pdbcanvas != null)
{
@@ -524,12 +546,12 @@ public class UserDefinedColours extends Panel implements ActionListener,
if (originalLabel.equals("Min Colour"))
{
((AnnotationColourChooser) caller)
- .minColour_actionPerformed((Color) originalColour);
+ .minColour_actionPerformed(originalColour.getColour());
}
else
{
((AnnotationColourChooser) caller)
- .maxColour_actionPerformed((Color) originalColour);
+ .maxColour_actionPerformed(originalColour.getColour());
}
}
else if (caller instanceof FeatureRenderer)
@@ -543,49 +565,41 @@ public class UserDefinedColours extends Panel implements ActionListener,
if (originalLabel.indexOf("inimum") > -1)
{
((FeatureColourChooser) caller)
- .minColour_actionPerformed((Color) originalColour);
+ .minColour_actionPerformed(originalColour.getColour());
}
else
{
((FeatureColourChooser) caller)
- .maxColour_actionPerformed((Color) originalColour);
+ .maxColour_actionPerformed(originalColour.getColour());
}
}
if (dialog != null)
+ {
dialog.setVisible(false);
+ }
frame.setVisible(false);
return;
}
- Color[] newColours = new Color[24];
- for (int i = 0; i < 24; i++)
- {
- newColours[i] = (Color) oldColours.elementAt(i);
- buttonPanel.getComponent(i).setBackground(newColours[i]);
- }
-
- UserColourScheme ucs = new UserColourScheme(newColours);
-
if (ap != null)
{
if (seqGroup != null)
{
- seqGroup.cs = ucs;
+ seqGroup.cs = new ResidueShader(oldColourScheme);
+ if (oldColourScheme instanceof PIDColourScheme
+ || oldColourScheme instanceof Blosum62ColourScheme)
+ {
+ seqGroup.cs.setConsensus(AAFrequency.calculate(
+ seqGroup.getSequences(ap.av.getHiddenRepSequences()), 0,
+ ap.av.getAlignment().getWidth()));
+ }
}
else
{
- ap.av.setGlobalColourScheme(ucs);
+ ap.av.setGlobalColourScheme(oldColourScheme);
}
- ap.paintAlignment(true);
- }
- else if (jmol != null)
- {
- jmol.setJalviewColourScheme(ucs);
- }
- else if (pdbcanvas != null)
- {
- pdbcanvas.pdb.setColours(ucs);
+ ap.paintAlignment(true, true);
}
frame.setVisible(false);
@@ -630,13 +644,13 @@ public class UserDefinedColours extends Panel implements ActionListener,
gridLayout.setColumns(6);
gridLayout.setRows(4);
okButton.setFont(new java.awt.Font("Verdana", 0, 11));
- okButton.setLabel("OK");
+ okButton.setLabel(MessageManager.getString("action.ok"));
okButton.addActionListener(this);
applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
- applyButton.setLabel("Apply");
+ applyButton.setLabel(MessageManager.getString("action.apply"));
applyButton.addActionListener(this);
cancelButton.setFont(new java.awt.Font("Verdana", 0, 11));
- cancelButton.setLabel("Cancel");
+ cancelButton.setLabel(MessageManager.getString("action.cancel"));
cancelButton.addActionListener(this);
this.setBackground(new Color(212, 208, 223));
okcancelPanel.setBounds(new Rectangle(0, 265, 400, 35));
@@ -655,6 +669,7 @@ public class UserDefinedColours extends Panel implements ActionListener,
rText.setText("0 ");
rText.setBounds(new Rectangle(156, 27, 53, 19));
rText.addActionListener(this);
+ rText.addFocusListener(this);
label4.setAlignment(Label.RIGHT);
label4.setText("G");
label4.setBounds(new Rectangle(15, 56, 20, 15));
@@ -669,6 +684,7 @@ public class UserDefinedColours extends Panel implements ActionListener,
gText.setText("0 ");
gText.setBounds(new Rectangle(156, 52, 53, 20));
gText.addActionListener(this);
+ gText.addFocusListener(this);
label5.setAlignment(Label.RIGHT);
label5.setText("B");
label5.setBounds(new Rectangle(14, 82, 20, 15));
@@ -683,12 +699,16 @@ public class UserDefinedColours extends Panel implements ActionListener,
bText.setText("0 ");
bText.setBounds(new Rectangle(157, 78, 52, 20));
bText.addActionListener(this);
+ bText.addFocusListener(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(rText);
+ this.add(gText);
+ this.add(bText);
this.add(buttonPanel, null);
this.add(target, null);
this.add(gScroller);
@@ -697,9 +717,40 @@ public class UserDefinedColours extends Panel implements ActionListener,
this.add(label5);
this.add(label4);
this.add(label1);
- this.add(gText);
- this.add(rText);
- this.add(bText);
+ }
+
+ @Override
+ public void focusGained(FocusEvent e)
+ {
+ // noop
+ }
+
+ /**
+ * This method applies any change to an RGB value if the user tabs out of the
+ * field instead of pressing Enter
+ */
+ @Override
+ public void focusLost(FocusEvent e)
+ {
+ Component c = e.getComponent();
+ if (c == rText)
+ {
+ rText_actionPerformed();
+ }
+ else
+ {
+ if (c == gText)
+ {
+ gText_actionPerformed();
+ }
+ else
+ {
+ if (c == bText)
+ {
+ bText_actionPerformed();
+ }
+ }
+ }
}
}