X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FUserDefinedColours.java;h=14f9adff9f867335d612bce4fd2adf758888a231;hb=afe4b88500a5d61bc8d312909cfdde2b7cdd53df;hp=89ddf87b24294c1f9a6ef00a2d00de4bfba53e65;hpb=7534e6f358b2bba0db179cb2f496bd2e5a4da43d;p=jalview.git diff --git a/src/jalview/gui/UserDefinedColours.java b/src/jalview/gui/UserDefinedColours.java index 89ddf87..14f9adf 100755 --- a/src/jalview/gui/UserDefinedColours.java +++ b/src/jalview/gui/UserDefinedColours.java @@ -20,21 +20,6 @@ */ package jalview.gui; -import jalview.bin.Cache; -import jalview.io.JalviewFileChooser; -import jalview.io.JalviewFileView; -import jalview.jbgui.GUserDefinedColours; -import jalview.schemabinding.version2.Colour; -import jalview.schemabinding.version2.JalviewUserColours; -import jalview.schemes.ColourSchemeI; -import jalview.schemes.ColourSchemeLoader; -import jalview.schemes.ColourSchemes; -import jalview.schemes.ResidueProperties; -import jalview.schemes.UserColourScheme; -import jalview.util.ColorUtils; -import jalview.util.Format; -import jalview.util.MessageManager; - import java.awt.Color; import java.awt.Font; import java.awt.Insets; @@ -46,11 +31,31 @@ import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import javax.swing.JButton; import javax.swing.JInternalFrame; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; + +import jalview.bin.Cache; +import jalview.io.JalviewFileChooser; +import jalview.io.JalviewFileView; +import jalview.jbgui.GUserDefinedColours; +import jalview.schemes.ColourSchemeI; +import jalview.schemes.ColourSchemeLoader; +import jalview.schemes.ColourSchemes; +import jalview.schemes.ResidueProperties; +import jalview.schemes.UserColourScheme; +import jalview.util.ColorUtils; +import jalview.util.Format; +import jalview.util.MessageManager; +import jalview.util.Platform; +import jalview.xml.binding.jalview.JalviewUserColours; +import jalview.xml.binding.jalview.JalviewUserColours.Colour; +import jalview.xml.binding.jalview.ObjectFactory; /** * This panel allows the user to assign colours to Amino Acid residue codes, and @@ -87,7 +92,7 @@ public class UserDefinedColours extends GUserDefinedColours * flag is true if the colour scheme has been changed since the * dialog was opened, or the changes last saved to file */ - boolean changed; + boolean changedButNotSaved; JInternalFrame frame; @@ -143,6 +148,7 @@ public class UserDefinedColours extends GUserDefinedColours { colorChooser.getSelectionModel().addChangeListener(this); frame = new JInternalFrame(); + frame.setFrameIcon(null); frame.setContentPane(this); Desktop.addInternalFrame(frame, MessageManager.getString("label.user_defined_colours"), @@ -201,8 +207,10 @@ public class UserDefinedColours extends GUserDefinedColours { int row = i / cols + 1; int index = (row * cols) + i; - JButton button = makeButton(ResidueProperties.aa[i].toLowerCase(), - ResidueProperties.aa[i].toLowerCase(), lowerCaseButtons, i); + JButton button = makeButton( + ResidueProperties.aa[i].toLowerCase(Locale.ROOT), + ResidueProperties.aa[i].toLowerCase(Locale.ROOT), + lowerCaseButtons, i); buttonPanel.add(button, index); } @@ -261,7 +269,7 @@ public class UserDefinedColours extends GUserDefinedColours button.setForeground(ColorUtils.brighterThan(newColour)); } - changed = true; + changedButNotSaved = true; } /** @@ -480,45 +488,50 @@ public class UserDefinedColours extends GUserDefinedColours */ protected void warnIfUnsavedChanges() { - if (!changed) - { - return; - } + // BH 2018 no warning in JavaScript TODO - 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) + if (!Platform.isJS() && changedButNotSaved) + /** + * Java only + * + * @j2sIgnore + */ + { + String name = schemeName.getText().trim(); + if (oldColourScheme != null && !"".equals(name) + && name.equals(oldColourScheme.getSchemeName())) { - /* - * prompt to save changes to file - */ - saved = savebutton_actionPerformed(); - } + 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]); + + if (response == 0) + { + /* + * prompt to save changes to file; if done, + * resets 'changed' flag to false + */ + 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 + * 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 */ - schemeName.setText(""); - applyButton_actionPerformed(); + if (changedButNotSaved) + { + /* + * clear scheme name and re-apply as an anonymous scheme + */ + schemeName.setText(""); + applyButton_actionPerformed(); + } } } } @@ -633,53 +646,49 @@ public class UserDefinedColours extends GUserDefinedColours { upperCaseButtons = new ArrayList<>(); lowerCaseButtons = new ArrayList<>(); - // TODO: JAL-3048 requires Castor dependency for Jalview-JS JalviewFileChooser chooser = new JalviewFileChooser("jc", "Jalview User Colours"); chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle( MessageManager.getString("label.load_colour_scheme")); chooser.setToolTipText(MessageManager.getString("action.load")); + chooser.setResponseHandler(0, () -> { + File choice = chooser.getSelectedFile(); + Cache.setProperty(LAST_DIRECTORY, choice.getParent()); - int value = chooser.showOpenDialog(this); + UserColourScheme ucs = ColourSchemeLoader + .loadColourScheme(choice.getAbsolutePath()); + Color[] colors = ucs.getColours(); + schemeName.setText(ucs.getSchemeName()); - if (value != JalviewFileChooser.APPROVE_OPTION) - { - return; - } - File choice = chooser.getSelectedFile(); - Cache.setProperty(LAST_DIRECTORY, choice.getParent()); - - UserColourScheme ucs = ColourSchemeLoader - .loadColourScheme(choice.getAbsolutePath()); - Color[] colors = ucs.getColours(); - schemeName.setText(ucs.getSchemeName()); + if (ucs.getLowerCaseColours() != null) + { + caseSensitive.setSelected(true); + lcaseColour.setEnabled(true); + resetButtonPanel(true); + for (int i = 0; i < lowerCaseButtons.size(); i++) + { + JButton button = lowerCaseButtons.get(i); + button.setBackground(ucs.getLowerCaseColours()[i]); + } + } + else + { + caseSensitive.setSelected(false); + lcaseColour.setEnabled(false); + resetButtonPanel(false); + } - if (ucs.getLowerCaseColours() != null) - { - caseSensitive.setSelected(true); - lcaseColour.setEnabled(true); - resetButtonPanel(true); - for (int i = 0; i < lowerCaseButtons.size(); i++) + for (int i = 0; i < upperCaseButtons.size(); i++) { - JButton button = lowerCaseButtons.get(i); - button.setBackground(ucs.getLowerCaseColours()[i]); + JButton button = upperCaseButtons.get(i); + button.setBackground(colors[i]); } - } - else - { - caseSensitive.setSelected(false); - lcaseColour.setEnabled(false); - resetButtonPanel(false); - } - for (int i = 0; i < upperCaseButtons.size(); i++) - { - JButton button = upperCaseButtons.get(i); - button.setBackground(colors[i]); - } + addNewColourScheme(choice.getPath()); + }); - addNewColourScheme(choice.getPath()); + chooser.showOpenDialog(this); } /** @@ -723,12 +732,10 @@ public class UserDefinedColours extends GUserDefinedColours *