*/
if (ResidueColourScheme.USER_DEFINED.equals(name))
{
- new UserDefinedColours(alignPanel, null);
+ new UserDefinedColours(alignPanel);
return;
}
public void changeColour(ColourSchemeI cs)
{
// TODO: pull up to controller method
- if (cs != null)
- {
- ColourMenuHelper.setColourSelected(colourMenu, cs.getSchemeName());
- }
+ ColourMenuHelper.setColourSelected(colourMenu, cs);
viewport.setGlobalColourScheme(cs);
colourMenu.add(annotationColour);
ColourSchemeI colourScheme = viewport.getGlobalColourScheme();
- String schemeName = colourScheme == null ? null : colourScheme
- .getSchemeName();
-
- ColourMenuHelper.setColourSelected(colourMenu, schemeName);
+ ColourMenuHelper.setColourSelected(colourMenu, colourScheme);
}
}
{
public interface ColourChangeListener
{
+ /**
+ * Change colour scheme to the selected scheme
+ *
+ * @param name
+ * the registered (unique) name of a colour scheme
+ */
void changeColour_actionPerformed(String name);
}
* <li>Clustal</li>
* <li>...other 'built-in' colours</li>
* <li>...any user-defined colours</li>
- * <li>User Defined..</li>
+ * <li>User Defined..(only for AlignFrame menu)</li>
* </ul>
*
* @param colourMenu
}
/*
- * scan registered colour schemes (built-in or user-defined
+ * scan registered colour schemes (built-in or user-defined)
* and add them to the menu (in the order they were registered)
*/
Iterable<ColourSchemeI> colourSchemes = ColourSchemes.getInstance()
final String label = MessageManager.getString("action.user_defined");
JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem(
label);
+ userDefinedColour.setName(ResidueColourScheme.USER_DEFINED);
userDefinedColour.addActionListener(new ActionListener()
{
@Override
}
/**
- * Marks as selected the colour menu item matching the given name, or the
- * first item ('None') if no match is found
+ * Marks as selected the colour menu item matching the given colour scheme, or
+ * the first item ('None') if no match is found. If the colour scheme is a
+ * user defined scheme, but not in the menu (this arises if a new scheme is
+ * defined and applied but not saved to file), then menu option
+ * "User Defined.." is selected.
*
* @param colourMenu
- * @param colourName
+ * @param cs
*/
- public static void setColourSelected(JMenu colourMenu, String colourName)
+ public static void setColourSelected(JMenu colourMenu, ColourSchemeI cs)
{
- if (colourName == null)
- {
- return;
- }
+ String colourName = cs == null ? ResidueColourScheme.NONE : cs
+ .getSchemeName();
JRadioButtonMenuItem none = null;
+ JRadioButtonMenuItem userDefined = null;
/*
* select the radio button whose name matches the colour name
{
if (menuItem instanceof JRadioButtonMenuItem)
{
- String buttonName = ((JRadioButtonMenuItem) menuItem).getName();
- if (colourName.equals(buttonName))
+ JRadioButtonMenuItem radioButton = (JRadioButtonMenuItem) menuItem;
+ String buttonName = radioButton.getName();
+ if (buttonName.equals(colourName))
{
- ((JRadioButtonMenuItem) menuItem).setSelected(true);
+ radioButton.setSelected(true);
return;
}
if (ResidueColourScheme.NONE.equals(buttonName))
{
- none = (JRadioButtonMenuItem) menuItem;
+ none = radioButton;
+ }
+ if (ResidueColourScheme.USER_DEFINED.equals(buttonName))
+ {
+ userDefined = radioButton;
}
}
}
- if (none != null)
+
+ /*
+ * no match by name; select User Defined.. if current scheme is a
+ * user defined one, else select None
+ */
+ if (cs instanceof UserColourScheme && userDefined != null)
+ {
+ userDefined.setSelected(true);
+ }
+ else if (none != null)
{
none.setSelected(true);
}
}
/**
- * Marks as selected the colour menu item matching the given colour scheme, or
- * the first item ('None') if no match is found
- *
- * @param colourMenu
- * @param cs
- */
- public static void setColourSelected(JMenu colourMenu, ColourSchemeI cs)
- {
- setColourSelected(colourMenu, cs == null ? ResidueColourScheme.NONE
- : cs.getSchemeName());
- }
-
- /**
* Updates the USER_DEFINE_COLOURS preference to remove any de-registered
* colour scheme
*/
import jalview.schemes.ColourSchemeI;
import jalview.schemes.ColourSchemes;
import jalview.schemes.PIDColourScheme;
-import jalview.schemes.ResidueColourScheme;
import jalview.util.GroupUrlLink;
import jalview.util.GroupUrlLink.UrlStringTooLongException;
import jalview.util.MessageManager;
public void changeColour_actionPerformed(String colourSchemeName)
{
SequenceGroup sg = getGroup();
- if (ResidueColourScheme.USER_DEFINED.equals(colourSchemeName))
- {
- /*
- * open a panel to load or configure a user-defined colour scheme
- */
- new UserDefinedColours(ap, sg);
- }
- else
+ /*
+ * switch to the chosen colour scheme (or null for None)
+ */
+ ColourSchemeI colourScheme = ColourSchemes.getInstance()
+ .getColourScheme(colourSchemeName, sg,
+ ap.av.getHiddenRepSequences());
+ sg.setColourScheme(colourScheme);
+ if (colourScheme instanceof Blosum62ColourScheme
+ || colourScheme instanceof PIDColourScheme)
{
- /*
- * switch to the chosen colour scheme (or null for None)
- */
- ColourSchemeI colourScheme = ColourSchemes.getInstance().getColourScheme(
- colourSchemeName, sg, ap.av.getHiddenRepSequences());
- sg.setColourScheme(colourScheme);
- if (colourScheme instanceof Blosum62ColourScheme
- || colourScheme instanceof PIDColourScheme)
- {
- sg.cs.setConsensus(AAFrequency.calculate(
- sg.getSequences(ap.av.getHiddenRepSequences()),
- sg.getStartRes(), sg.getEndRes() + 1));
- }
+ sg.cs.setConsensus(AAFrequency.calculate(
+ sg.getSequences(ap.av.getHiddenRepSequences()),
+ sg.getStartRes(), sg.getEndRes() + 1));
}
refresh();
package jalview.gui;
import jalview.bin.Cache;
-import jalview.datamodel.SequenceGroup;
import jalview.io.JalviewFileChooser;
import jalview.io.JalviewFileView;
import jalview.jbgui.GUserDefinedColours;
AlignmentPanel ap;
- SequenceGroup seqGroup;
-
ColourSchemeI oldColourScheme;
JInternalFrame frame;
List<JButton> lowerCaseButtons;
/**
- * Creates a new UserDefinedColours object.
+ * Creates and displays a new UserDefinedColours panel
*
- * @param ap
- * @param sg
+ * @param alignPanel
*/
- public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
+ public UserDefinedColours(AlignmentPanel alignPanel)
{
this();
lcaseColour.setEnabled(false);
- this.ap = ap;
- seqGroup = sg;
+ this.ap = alignPanel;
- if (seqGroup != null)
- {
- oldColourScheme = seqGroup.getColourScheme();
- }
- else
- {
- oldColourScheme = ap.av.getGlobalColourScheme();
- }
+ oldColourScheme = alignPanel.av.getGlobalColourScheme();
if (oldColourScheme instanceof UserColourScheme)
{
Desktop.addInternalFrame(frame,
MessageManager.getString("label.user_defined_colours"),
MY_FRAME_WIDTH, MY_FRAME_HEIGHT, true);
-
- if (seqGroup != null)
- {
- frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")");
- }
}
/**
}
UserColourScheme ucs = getSchemeFromButtons();
- if (seqGroup != null)
- {
- seqGroup.setColourScheme(ucs);
- ap.paintAlignment(true);
- }
- else if (ap != null)
- {
- ap.alignFrame.changeColour(ucs);
- }
+ ap.alignFrame.changeColour(ucs);
}
/**
{
return;
}
- ColourSchemes.getInstance().removeColourScheme(name);
}
JalviewFileChooser chooser = new JalviewFileChooser("jc",
"Jalview User Colours");
@Override
protected void cancelButton_actionPerformed()
{
- if (ap != null)
- {
- if (seqGroup != null)
- {
- seqGroup.setColourScheme(oldColourScheme);
- }
- else
- {
- ap.alignFrame.changeColour(oldColourScheme);
- }
- ap.paintAlignment(true);
- }
+ ap.alignFrame.changeColour(oldColourScheme);
+ ap.paintAlignment(true);
try
{