X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FPreferences.java;h=cf80a6d955fafe1d9c33da03085430ea424ebe2b;hb=c355d0f7a994d0d064078d363e612eb8c89581f1;hp=7a24aebea05259e926b2e4ccc229b7de17a4b324;hpb=c25a5c7301fa43bec8da032f93898d6133391f8a;p=jalview.git diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index 7a24aeb..cf80a6d 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -24,16 +24,21 @@ import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; import jalview.bin.Cache; import jalview.gui.Help.HelpId; import jalview.gui.StructureViewer.ViewerType; +import jalview.io.FileFormatI; import jalview.io.JalviewFileChooser; import jalview.io.JalviewFileView; import jalview.jbgui.GPreferences; import jalview.jbgui.GSequenceLink; -import jalview.schemes.ColourSchemeProperty; +import jalview.schemes.ColourSchemeI; +import jalview.schemes.ColourSchemes; +import jalview.schemes.ResidueColourScheme; import jalview.urls.UrlLinkTableModel; -import jalview.urls.UrlProvider; -import jalview.urls.UrlProviderI; +import jalview.urls.api.UrlProviderFactoryI; +import jalview.urls.api.UrlProviderI; +import jalview.urls.desktop.DesktopUrlProviderFactory; import jalview.util.MessageManager; import jalview.util.Platform; +import jalview.util.UrlConstants; import jalview.ws.sifts.SiftsSettings; import java.awt.BorderLayout; @@ -52,7 +57,6 @@ import javax.help.HelpSetException; import javax.swing.JColorChooser; import javax.swing.JFileChooser; import javax.swing.JInternalFrame; -import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.ListSelectionModel; import javax.swing.RowFilter; @@ -126,17 +130,23 @@ public class Preferences extends GPreferences public static List groupURLLinks; static { - String string = Cache.getDefault("SEQUENCE_LINKS", - UrlProviderI.DEFAULT_STRING); - sequenceUrlLinks = new UrlProvider(UrlProviderI.DEFAULT_LABEL, string); - - List colNames = new ArrayList(); - // colNames.add("ID"); - // TODO KM add to properties file - colNames.add("URL"); - colNames.add("In Menu"); - colNames.add("Default"); - dataModel = new UrlLinkTableModel(sequenceUrlLinks, colNames, "ID"); + // get links selected to be in the menu (SEQUENCE_LINKS) + // and links entered by the user but not selected (STORED_LINKS) + String inMenuString = Cache.getDefault("SEQUENCE_LINKS", ""); + String notInMenuString = Cache.getDefault("STORED_LINKS", ""); + String defaultUrl = Cache.getDefault("DEFAULT_URL", + UrlConstants.DEFAULT_LABEL); + + // if both links lists are empty, add the DEFAULT_URL link + // otherwise we assume the default link is in one of the lists + if (inMenuString.isEmpty() && notInMenuString.isEmpty()) + { + inMenuString = UrlConstants.DEFAULT_STRING; + } + UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl, + inMenuString, notInMenuString); + sequenceUrlLinks = factory.createUrlProvider(); + dataModel = new UrlLinkTableModel(sequenceUrlLinks); /** * TODO: reformulate groupURL encoding so two or more can be stored in the @@ -276,12 +286,16 @@ public class Preferences extends GPreferences /* * Set Colours tab defaults */ - for (int i = ColourSchemeProperty.FIRST_COLOUR; i <= ColourSchemeProperty.LAST_COLOUR; i++) + protColour.addItem(ResidueColourScheme.NONE); + nucColour.addItem(ResidueColourScheme.NONE); + for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes()) { - protColour.addItem(ColourSchemeProperty.getColourName(i)); - nucColour.addItem(ColourSchemeProperty.getColourName(i)); + String name = cs.getSchemeName(); + protColour.addItem(name); + nucColour.addItem(name); } - String oldProp = Cache.getDefault(DEFAULT_COLOUR, "None"); + String oldProp = Cache.getDefault(DEFAULT_COLOUR, + ResidueColourScheme.NONE); String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null); protColour.setSelectedItem(newProp != null ? newProp : oldProp); newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null); @@ -337,10 +351,13 @@ public class Preferences extends GPreferences linkUrlTable.setRowSorter(sorter); List sortKeys = new ArrayList<>(); - sortKeys.add(new RowSorter.SortKey(3, + UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel(); + sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(), SortOrder.DESCENDING)); - sortKeys.add(new RowSorter.SortKey(2, SortOrder.DESCENDING)); - sortKeys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING)); + sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(), + SortOrder.DESCENDING)); + sortKeys.add(new RowSorter.SortKey(m.getNameColumn(), + SortOrder.ASCENDING)); sorter.setSortKeys(sortKeys); sorter.sort(); @@ -366,8 +383,7 @@ public class Preferences extends GPreferences public boolean include( Entry entry) { - String id = entry.getStringValue(4); - return sequenceUrlLinks.isUserEntry(id); + return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry); } }; @@ -389,24 +405,26 @@ public class Preferences extends GPreferences filterTB.getDocument().addDocumentListener(new DocumentListener() { + String caseInsensitiveFlag = "(?i)"; + @Override public void changedUpdate(DocumentEvent e) { - sorter.setRowFilter(RowFilter.regexFilter("(?i)" + sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag + filterTB.getText())); } @Override public void removeUpdate(DocumentEvent e) { - sorter.setRowFilter(RowFilter.regexFilter("(?i)" + sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag + filterTB.getText())); } @Override public void insertUpdate(DocumentEvent e) { - sorter.setRowFilter(RowFilter.regexFilter("(?i)" + sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag + filterTB.getText())); } }); @@ -416,9 +434,12 @@ public class Preferences extends GPreferences new UrlListSelectionHandler()); // set up radio buttons - linkUrlTable.getColumn("Default").setCellRenderer( - new RadioButtonRenderer()); - linkUrlTable.getColumn("Default") + int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel()) + .getPrimaryColumn(); + String onClickName = linkUrlTable.getColumnName(onClickCol); + linkUrlTable.getColumn(onClickName).setCellRenderer( + new RadioButtonRenderer()); + linkUrlTable.getColumn(onClickName) .setCellEditor(new RadioButtonEditor()); // get boolean columns and resize those to min possible @@ -444,8 +465,6 @@ public class Preferences extends GPreferences useProxy.setSelected(Cache.getDefault("USE_PROXY", false)); useProxy_actionPerformed(); // make sure useProxy is correctly initialised - proxyServerTB.setEnabled(useProxy.isSelected()); - proxyPortTB.setEnabled(useProxy.isSelected()); proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", "")); proxyPortTB.setText(Cache.getDefault("PROXY_PORT", "")); @@ -638,17 +657,31 @@ public class Preferences extends GPreferences jalview.util.BrowserLauncher.resetBrowser(); // save user-defined and selected links - String links = linkUrlTable.getModel().toString(); - if (links.isEmpty()) + String menuLinks = sequenceUrlLinks.writeUrlsAsString(true); + if (menuLinks.isEmpty()) { Cache.applicationProperties.remove("SEQUENCE_LINKS"); } else { Cache.applicationProperties.setProperty("SEQUENCE_LINKS", - links.toString()); + menuLinks.toString()); } + String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false); + if (nonMenuLinks.isEmpty()) + { + Cache.applicationProperties.remove("STORED_LINKS"); + } + else + { + Cache.applicationProperties.setProperty("STORED_LINKS", + nonMenuLinks.toString()); + } + + Cache.applicationProperties.setProperty("DEFAULT_URL", + sequenceUrlLinks.getPrimaryUrlId()); + Cache.applicationProperties.setProperty("USE_PROXY", Boolean.toString(useProxy.isSelected())); @@ -765,12 +798,9 @@ public class Preferences extends GPreferences @Override public void startupFileTextfield_mouseClicked() { - JalviewFileChooser chooser = new JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[] { - "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc", - "jar" }, new String[] { "Fasta", "Clustal", "PFAM", "MSF", - "PIR", "BLC", "Jalview" }, - jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT")); + String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT"); + JalviewFileChooser chooser = JalviewFileChooser.forRead( + Cache.getProperty("LAST_DIRECTORY"), fileFormat); chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle(MessageManager .getString("label.select_startup_file")); @@ -779,8 +809,12 @@ public class Preferences extends GPreferences if (value == JalviewFileChooser.APPROVE_OPTION) { - jalview.bin.Cache.applicationProperties.setProperty( - "DEFAULT_FILE_FORMAT", chooser.getSelectedFormat()); + FileFormatI format = chooser.getSelectedFormat(); + if (format != null) + { + Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT", + format.getName()); + } startupFileTextfield.setText(chooser.getSelectedFile() .getAbsolutePath()); } @@ -828,20 +862,28 @@ public class Preferences extends GPreferences @Override public void newLink_actionPerformed(ActionEvent e) { - GSequenceLink link = new GSequenceLink(); boolean valid = false; while (!valid) { - if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link, + if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link, MessageManager.getString("label.new_sequence_url_link"), - JOptionPane.OK_CANCEL_OPTION, -1, null) == JOptionPane.OK_OPTION) + JvOptionPane.OK_CANCEL_OPTION, -1, null) == JvOptionPane.OK_OPTION) { if (link.checkValid()) { - ((UrlLinkTableModel) linkUrlTable.getModel()).insertRow( - link.getName(), link.getURL()); - valid = true; + if (((UrlLinkTableModel) linkUrlTable.getModel()) + .isUniqueName(link.getName())) + { + ((UrlLinkTableModel) linkUrlTable.getModel()).insertRow( + link.getName(), link.getURL()); + valid = true; + } + else + { + link.notifyDuplicate(); + continue; + } } } else @@ -859,31 +901,41 @@ public class Preferences extends GPreferences int index = linkUrlTable.getSelectedRow(); if (index == -1) { - // no row was selected - JOptionPane.showInternalMessageDialog(Desktop.desktop, - MessageManager.getString("label.no_link_selected"), - MessageManager.getString("label.no_link_selected"), - JOptionPane.WARNING_MESSAGE); + // button no longer enabled if row is not selected + Cache.log.debug("Edit with no row selected in linkUrlTable"); return; } - link.setName(linkUrlTable.getValueAt(index, 0).toString()); - link.setURL(linkUrlTable.getValueAt(index, 1).toString()); + int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel()) + .getNameColumn(); + int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel()) + .getUrlColumn(); + String oldName = linkUrlTable.getValueAt(index, nameCol).toString(); + link.setName(oldName); + link.setURL(linkUrlTable.getValueAt(index, urlCol).toString()); boolean valid = false; while (!valid) { - - if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link, - MessageManager.getString("label.new_sequence_url_link"), - JOptionPane.OK_CANCEL_OPTION, -1, null) == JOptionPane.OK_OPTION) + if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link, + MessageManager.getString("label.edit_sequence_url_link"), + JvOptionPane.OK_CANCEL_OPTION, -1, null) == JvOptionPane.OK_OPTION) { if (link.checkValid()) { - - linkUrlTable.setValueAt(link.getName(), index, 0); - linkUrlTable.setValueAt(link.getURL(), index, 1); - valid = true; + if ((oldName.equals(link.getName())) + || (((UrlLinkTableModel) linkUrlTable.getModel()) + .isUniqueName(link.getName()))) + { + linkUrlTable.setValueAt(link.getName(), index, nameCol); + linkUrlTable.setValueAt(link.getURL(), index, urlCol); + valid = true; + } + else + { + link.notifyDuplicate(); + continue; + } } } else @@ -900,11 +952,8 @@ public class Preferences extends GPreferences int modelIndex = -1; if (index == -1) { - // no row is selected - JOptionPane.showInternalMessageDialog(Desktop.desktop, - MessageManager.getString("label.no_link_selected"), - MessageManager.getString("label.no_link_selected"), - JOptionPane.WARNING_MESSAGE); + // button no longer enabled if row is not selected + Cache.log.debug("Delete with no row selected in linkUrlTable"); return; } else @@ -995,10 +1044,10 @@ public class Preferences extends GPreferences } } catch (NumberFormatException x) { - JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager + JvOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager .getString("warn.user_defined_width_requirements"), MessageManager.getString("label.invalid_id_column_width"), - JOptionPane.WARNING_MESSAGE); + JvOptionPane.WARNING_MESSAGE); userIdWidth.setText(""); } } @@ -1021,10 +1070,10 @@ public class Preferences extends GPreferences File f = new File(chimeraPath.getText()); if (!f.canExecute()) { - JOptionPane.showInternalMessageDialog(Desktop.desktop, + JvOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager.getString("label.invalid_chimera_path"), MessageManager.getString("label.invalid_name"), - JOptionPane.ERROR_MESSAGE); + JvOptionPane.ERROR_MESSAGE); return false; } } @@ -1060,13 +1109,13 @@ public class Preferences extends GPreferences if (!found) { String[] options = { "OK", "Help" }; - int showHelp = JOptionPane.showInternalOptionDialog( + int showHelp = JvOptionPane.showInternalOptionDialog( Desktop.desktop, JvSwingUtils.wrapTooltip(true, MessageManager.getString("label.chimera_missing")), - "", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, + "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE, null, options, options[0]); - if (showHelp == JOptionPane.NO_OPTION) + if (showHelp == JvOptionPane.NO_OPTION) { try { @@ -1152,26 +1201,25 @@ public class Preferences extends GPreferences } int modelIndex = linkUrlTable.convertRowIndexToModel(index); - // determine if the new selection is a custom url or not - if (!sequenceUrlLinks.isUserEntry((String) linkUrlTable -.getModel() - .getValueAt(modelIndex, 4))) // KM TODO do this better + // enable/disable edit and delete link buttons + if (((UrlLinkTableModel) linkUrlTable.getModel()) + .isRowDeletable(modelIndex)) { - // entry is not a user-defined url and so should not be edited - // disable edit and delete buttons - deleteLink.setEnabled(false); - editLink.setEnabled(false); + deleteLink.setEnabled(true); } else { - deleteLink.setEnabled(true); - editLink.setEnabled(true); + deleteLink.setEnabled(false); } - // BUT it's the default url, don't allow deletion - if ((boolean) linkUrlTable.getValueAt(index, 3)) + if (((UrlLinkTableModel) linkUrlTable.getModel()) + .isRowEditable(modelIndex)) { - deleteLink.setEnabled(false); + editLink.setEnabled(true); + } + else + { + editLink.setEnabled(false); } } }