action.merge_results = Merge Results
action.load_scheme = Load scheme
action.save_scheme = Save scheme
+label.scheme_changed = Changes to scheme {0} have not been saved<br>Save changes, or continue without saving to make a new colour scheme
+label.save_changes = Save Changes
+label.dont_save_changes = Don't Save
action.save_image = Save Image
action.paste = Paste
action.show_html_source = Show HTML Source
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
-import java.awt.MenuShortcut;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
boolean selected = conservationMenuItem.getState();
modifyConservation.setEnabled(selected);
viewport.setConservationSelected(selected);
-
- // viewport.setAbovePIDThreshold(false);
- // abovePIDThreshold.setState(false);
+ viewport.getResidueShading().setConservationApplied(selected);
changeColour(viewport.getGlobalColourScheme());
boolean selected = abovePIDThreshold.getState();
modifyPID.setEnabled(selected);
viewport.setAbovePIDThreshold(selected);
- // conservationMenuItem.setState(false);
- // viewport.setConservationSelected(false);
+ if (!selected)
+ {
+ viewport.getResidueShading().setThreshold(0,
+ viewport.isIgnoreGapsConsensus());
+ }
changeColour(viewport.getGlobalColourScheme());
*/
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()
/*
* user-defined colour scheme loaded on startup or during the
* Jalview session; right-click on this offers the option to
- * remove it as a colour choice
+ * remove it as a colour choice (unless currently selected)
*/
radioItem.addMouseListener(new MouseAdapter()
{
@Override
public void mousePressed(MouseEvent evt)
{
- if (evt.isPopupTrigger()) // Mac
+ if (evt.isPopupTrigger() && !radioItem.isSelected()) // Mac
{
offerRemoval();
}
@Override
public void mouseReleased(MouseEvent evt)
{
- if (evt.isPopupTrigger()) // Windows
+ if (evt.isPopupTrigger() && !radioItem.isSelected()) // Windows
{
offerRemoval();
}
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
*/
private JLabel dbstatus, dbstatex;
+ private JPanel mainPanel = new JPanel(new BorderLayout());
+
public JDatabaseTree(jalview.ws.SequenceFetcher sfetch)
{
- initDialogFrame(this, true, false,
+ mainPanel.add(this);
+ initDialogFrame(mainPanel, true, false,
MessageManager
.getString("label.select_database_retrieval_source"),
650, 490);
}
// and sort the tree
sortTreeNodes(root);
- svp = new JScrollPane();
- // svp.setAutoscrolls(true);
dbviews = new JTree(new DefaultTreeModel(root, false));
dbviews.setCellRenderer(new DbTreeRenderer(this));
dbviews.getSelectionModel().setSelectionMode(
TreeSelectionModel.SINGLE_TREE_SELECTION);
- svp.getViewport().setView(dbviews);
- // svp.getViewport().setMinimumSize(new Dimension(300,200));
- // svp.setSize(300,250);
- // JPanel panel=new JPanel();
- // panel.setSize(new Dimension(350,220));
- // panel.add(svp);
+ svp = new JScrollPane(dbviews);
+ svp.setMinimumSize(new Dimension(100, 200));
+ svp.setPreferredSize(new Dimension(200, 400));
+ svp.setMaximumSize(new Dimension(300, 600));
+
+ JPanel panel = new JPanel(new BorderLayout());
+ panel.setSize(new Dimension(350, 220));
+ panel.add(svp);
dbviews.addTreeSelectionListener(new TreeSelectionListener()
{
dbstat.add(dbstatex);
jc.add(dbstat, BorderLayout.SOUTH);
jc.validate();
- // j.setPreferredSize(new Dimension(300,50));
add(jc, BorderLayout.CENTER);
ok.setEnabled(false);
j.add(ok);
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.api.structures.JalviewStructureDisplayI;
import jalview.bin.Cache;
-import jalview.datamodel.SequenceGroup;
import jalview.io.JalviewFileChooser;
import jalview.io.JalviewFileView;
import jalview.jbgui.GUserDefinedColours;
import java.awt.Color;
import java.awt.Font;
import java.awt.Insets;
-import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
AlignmentPanel ap;
- SequenceGroup seqGroup;
-
- List<JButton> selectedButtons;
-
+ /*
+ * the colour scheme when the dialog was opened, or
+ * the scheme last saved to file
+ */
ColourSchemeI oldColourScheme;
- JInternalFrame frame;
+ /*
+ * flag is true if the colour scheme has been changed since the
+ * dialog was opened, or the changes last saved to file
+ */
+ boolean changed;
- JalviewStructureDisplayI structureViewer;
+ JInternalFrame frame;
List<JButton> upperCaseButtons;
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)
{
showFrame();
}
- public UserDefinedColours(JalviewStructureDisplayI viewer,
- ColourSchemeI oldcs)
- {
- this();
- this.structureViewer = viewer;
-
- colorChooser.getSelectionModel().addChangeListener(this);
-
- oldColourScheme = oldcs;
-
- if (oldColourScheme instanceof UserColourScheme)
- {
- schemeName.setText(((UserColourScheme) oldColourScheme)
- .getSchemeName());
- }
-
- resetButtonPanel(false);
-
- showFrame();
-
- }
-
- public UserDefinedColours()
+ UserDefinedColours()
{
super();
selectedButtons = new ArrayList<JButton>();
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() + ")");
- }
}
/**
button.setBackground(newColour);
button.setForeground(ColorUtils.brighterThan(newColour));
}
+
+ changed = true;
}
/**
}
else
{
+ /*
+ * OK is treated as 'apply colours and close'
+ */
applyButton_actionPerformed();
+ /*
+ * If editing a named colour scheme, warn if changes
+ * have not been saved
+ */
+ warnIfUnsavedChanges();
+
try
{
frame.setClosed(true);
}
/**
+ * If we have made changes to an existing user defined colour scheme but not
+ * saved them, show a dialog with the option to save. If the user chooses to
+ * save, do so, else clear the colour scheme name to indicate a new colour
+ * scheme.
+ */
+ protected void warnIfUnsavedChanges()
+ {
+ if (!changed)
+ {
+ return;
+ }
+
+ String name = schemeName.getText().trim();
+ if (oldColourScheme != null && !"".equals(name)
+ && name.equals(oldColourScheme.getSchemeName()))
+ {
+ String message = MessageManager.formatMessage("label.scheme_changed",
+ name);
+ String title = MessageManager.getString("label.save_changes");
+ String[] options = new String[] { title,
+ MessageManager.getString("label.dont_save_changes"), };
+ final String question = JvSwingUtils.wrapTooltip(true, message);
+ int response = JvOptionPane.showOptionDialog(Desktop.desktop,
+ question, title, JvOptionPane.DEFAULT_OPTION,
+ JvOptionPane.PLAIN_MESSAGE, null, options, options[0]);
+
+ boolean saved = false;
+ if (response == 0)
+ {
+ /*
+ * prompt to save changes to file
+ */
+ saved = savebutton_actionPerformed();
+ }
+
+ /*
+ * if user chooses not to save (either in this dialog or in the
+ * save as dialogs), treat this as a new user defined colour scheme
+ */
+ if (!saved)
+ {
+ /*
+ * clear scheme name and re-apply as an anonymous scheme
+ */
+ schemeName.setText("");
+ applyButton_actionPerformed();
+ }
+ }
+ }
+
+ /**
* Returns true if the user has not made any colour selection (including if
* 'case-sensitive' selected and no lower-case colour chosen).
*
}
/**
- * Applies the current colour scheme to the alignment, sequence group or
- * structure view.
+ * Applies the current colour scheme to the alignment or sequence group
*/
@Override
protected void applyButton_actionPerformed()
}
UserColourScheme ucs = getSchemeFromButtons();
- if (seqGroup != null)
- {
- seqGroup.setColourScheme(ucs);
- ap.paintAlignment(true);
- }
- else if (ap != null)
- {
- ap.alignFrame.changeColour(ucs);
- }
- else if (structureViewer != null)
- {
- structureViewer.setJalviewColourScheme(ucs);
- }
+ ap.alignFrame.changeColour(ucs);
}
+ /**
+ * Constructs an instance of UserColourScheme with the residue colours
+ * currently set on the buttons on the panel
+ *
+ * @return
+ */
UserColourScheme getSchemeFromButtons()
{
}
/**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
+ * Action on clicking Load scheme button.
+ * <ul>
+ * <li>Open a file chooser to browse for files with extension .jc</li>
+ * <li>Load in the colour scheme and transfer it to this panel's buttons</li>
+ * <li>Register the loaded colour scheme</li>
+ * </ul>
*/
@Override
- protected void loadbutton_actionPerformed(ActionEvent e)
+ protected void loadbutton_actionPerformed()
{
upperCaseButtons = new ArrayList<JButton>();
lowerCaseButtons = new ArrayList<JButton>();
}
/**
- * DOCUMENT ME!
+ * Action on pressing the Save button.
+ * <ul>
+ * <li>Check a name has been entered</li>
+ * <li>Warn if the name already exists, remove any existing scheme of the same
+ * name if overwriting</li>
+ * <li>Do the standard file chooser thing to write with extension .jc</li>
+ * <li>If saving changes (possibly not yet applied) to the currently selected
+ * colour scheme, then apply the changes, as it is too late to back out now</li>
+ * <li>Don't apply the changes if the currently selected scheme is different,
+ * to allow a new scheme to be configured and saved but not applied</li>
+ * </ul>
+ * Returns true if the scheme is saved to file, false if it is not
*
- * @param e
- * DOCUMENT ME!
+ * @return
*/
@Override
- protected void savebutton_actionPerformed(ActionEvent e)
+ protected boolean savebutton_actionPerformed()
{
String name = schemeName.getText().trim();
if (name.length() < 1)
.getString("label.user_colour_scheme_must_have_name"),
MessageManager.getString("label.no_name_colour_scheme"),
JvOptionPane.WARNING_MESSAGE);
- return;
+ return false;
}
if (ColourSchemes.getInstance().nameExists(name))
JvOptionPane.YES_NO_OPTION);
if (reply != JvOptionPane.YES_OPTION)
{
- return;
+ return false;
}
- ColourSchemes.getInstance().removeColourScheme(name);
}
JalviewFileChooser chooser = new JalviewFileChooser("jc",
"Jalview User Colours");
int value = chooser.showSaveDialog(this);
- if (value == JalviewFileChooser.APPROVE_OPTION)
+ if (value != JalviewFileChooser.APPROVE_OPTION)
+ {
+ return false;
+ }
+
+ File file = chooser.getSelectedFile();
+ UserColourScheme updatedScheme = addNewColourScheme(file.getPath());
+ saveToFile(file);
+ changed = false;
+
+ /*
+ * changes saved - apply to alignment if we are changing
+ * the currently selected colour scheme; also make the updated
+ * colours the 'backout' scheme on Cancel
+ */
+ if (oldColourScheme != null
+ && name.equals(oldColourScheme.getSchemeName()))
{
- File file = chooser.getSelectedFile();
- addNewColourScheme(file.getPath());
- saveToFile(file);
+ oldColourScheme = updatedScheme;
+ applyButton_actionPerformed();
}
+ return true;
}
/**
* the colour scheme.
*
* @param filePath
+ * @return
*/
- protected void addNewColourScheme(String filePath)
+ protected UserColourScheme addNewColourScheme(String filePath)
{
/*
* update the delimited list of user defined colour files in
{
ap.alignFrame.buildColourMenu();
}
+
+ return ucs;
}
/**
* marshal to file
*/
JalviewUserColours ucs = new JalviewUserColours();
- ucs.setSchemeName(schemeName.getText());
+ String name = schemeName.getText();
+ ucs.setSchemeName(name);
try
{
PrintWriter out = new PrintWriter(new OutputStreamWriter(
}
/**
- * On cancel, restores the colour scheme before the dialogue was opened
- *
- * @param e
+ * On cancel, restores the colour scheme that was selected before the dialogue
+ * was opened
*/
@Override
- protected void cancelButton_actionPerformed(ActionEvent e)
+ protected void cancelButton_actionPerformed()
{
- if (ap != null)
- {
- if (seqGroup != null)
- {
- seqGroup.setColourScheme(oldColourScheme);
- }
- else
- {
- ap.alignFrame.changeColour(oldColourScheme);
- }
- ap.paintAlignment(true);
- }
-
- if (structureViewer != null)
- {
- structureViewer.setJalviewColourScheme(oldColourScheme);
- }
+ ap.alignFrame.changeColour(oldColourScheme);
+ ap.paintAlignment(true);
try
{
}
}
+ /**
+ * Action on selecting or deselecting the Case Sensitive option. When
+ * selected, separate buttons are shown for lower case residues, and the panel
+ * is resized to accommodate them. Also, the checkbox for 'apply colour to all
+ * lower case' is enabled.
+ */
@Override
- public void caseSensitive_actionPerformed(ActionEvent e)
+ public void caseSensitive_actionPerformed()
{
boolean selected = caseSensitive.isSelected();
resetButtonPanel(selected);
gridLayout.setRows(5);
okButton.setFont(new java.awt.Font("Verdana", 0, 11));
okButton.setText(MessageManager.getString("action.ok"));
- okButton.addActionListener(new java.awt.event.ActionListener()
+ okButton.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
});
loadbutton.setFont(new java.awt.Font("Verdana", 0, 11));
loadbutton.setText(MessageManager.getString("action.load_scheme"));
- loadbutton.addActionListener(new java.awt.event.ActionListener()
+ loadbutton.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
- loadbutton_actionPerformed(e);
+ loadbutton_actionPerformed();
}
});
savebutton.setFont(new java.awt.Font("Verdana", 0, 11));
savebutton.setText(MessageManager.getString("action.save_scheme"));
- savebutton.addActionListener(new java.awt.event.ActionListener()
+ savebutton.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
- savebutton_actionPerformed(e);
+ savebutton_actionPerformed();
}
});
cancelButton.setFont(JvSwingUtils.getLabelFont());
cancelButton.setText(MessageManager.getString("action.cancel"));
- cancelButton.addActionListener(new java.awt.event.ActionListener()
+ cancelButton.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
- cancelButton_actionPerformed(e);
+ cancelButton_actionPerformed();
}
});
this.setBackground(new Color(212, 208, 223));
@Override
public void actionPerformed(ActionEvent e)
{
- caseSensitive_actionPerformed(e);
+ caseSensitive_actionPerformed();
}
});
lcaseColour
* @param e
* DOCUMENT ME!
*/
- protected void loadbutton_actionPerformed(ActionEvent e)
+ protected void loadbutton_actionPerformed()
{
}
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- protected void savebutton_actionPerformed(ActionEvent e)
+ protected boolean savebutton_actionPerformed()
{
+ return false;
}
/**
* @param e
* DOCUMENT ME!
*/
- protected void cancelButton_actionPerformed(ActionEvent e)
+ protected void cancelButton_actionPerformed()
{
}
- public void caseSensitive_actionPerformed(ActionEvent e)
+ public void caseSensitive_actionPerformed()
{
}
- public void lcaseColour_actionPerformed(ActionEvent e)
+ public void lcaseColour_actionPerformed()
{
}
private static ColourSchemes instance = new ColourSchemes();
/*
- * a map from scheme name to an instance of it
+ * a map from scheme name (lower-cased) to an instance of it
*/
private Map<String, ColourSchemeI> schemes;
*/
public void removeColourScheme(String name)
{
- schemes.remove(name);
+ if (name != null)
+ {
+ schemes.remove(name.toLowerCase());
+ }
}
/**
{
return false;
}
- name = name.toLowerCase();
- for (ColourSchemeI scheme : getColourSchemes())
- {
- if (name.equals(scheme.getSchemeName().toLowerCase()))
- {
- return true;
- }
- }
- return false;
+ return schemes.containsKey(name.toLowerCase());
}
}