From: kiramt Date: Mon, 5 Dec 2016 13:08:56 +0000 (+0000) Subject: JAL-2316 Added UrlProvider factories. Tidied up labelling. X-Git-Tag: Release_2_10_3b1~346^2~26 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=44fc22cf950ff114ce3a5a07600e7a7eb5fd1216;p=jalview.git JAL-2316 Added UrlProvider factories. Tidied up labelling. --- diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index ffdf908..a52e6a4 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -137,7 +137,8 @@ action.view_flanking_regions = Show flanking regions label.view_flanking_regions = Show sequence data either side of the subsequences involved in this alignment label.structures_manager = Structures Manager label.nickname = Nickname: -label.url = URL: +label.url = URL +label.url\: = URL: label.input_file_url = Enter URL or Input File label.select_feature = Select feature label.name = Name @@ -1278,4 +1279,7 @@ label.filter = Filter text: action.customfilter = Custom only label.insert = Insert: action.seq_id = $SEQUENCE_ID$ -action.db_acc = $DB_ACCESSION$ \ No newline at end of file +action.db_acc = $DB_ACCESSION$ +label.default = Default +label.inmenu = In Menu +label.id = ID \ No newline at end of file diff --git a/resources/lang/Messages_es.properties b/resources/lang/Messages_es.properties index 2ff5d71..f1339f8 100644 --- a/resources/lang/Messages_es.properties +++ b/resources/lang/Messages_es.properties @@ -134,7 +134,8 @@ action.view_flanking_regions = Mostrar flancos label.view_flanking_regions = Mostrar los datos de la secuencia a ambos lados de las subsecuencias implicadas en este alineamiento label.structures_manager = Administrar estructuras label.nickname = Sobrenombre: -label.url = URL: +label.url\: = URL: +label.url = URL label.input_file_url = Introducir URL en el fichero de entrada label.select_feature = Seleccionar característica label.name = Nombre @@ -1280,3 +1281,6 @@ action.customfilter = Custom only label.insert = Insert: action.seq_id = $SEQUENCE_ID$ action.db_acc = $DB_ACCESSION$ +label.default = Default +label.inmenu = In Menu +label.id = ID \ No newline at end of file diff --git a/src/jalview/appletgui/IdPanel.java b/src/jalview/appletgui/IdPanel.java index feca846..f9f1676 100755 --- a/src/jalview/appletgui/IdPanel.java +++ b/src/jalview/appletgui/IdPanel.java @@ -24,7 +24,8 @@ import jalview.datamodel.Sequence; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; -import jalview.urls.UrlProvider; +import jalview.urls.AppletUrlProviderFactory; +import jalview.urls.UrlProviderFactoryI; import jalview.urls.UrlProviderI; import jalview.viewmodel.AlignmentViewport; @@ -85,7 +86,9 @@ public class IdPanel extends Panel implements MouseListener, { // set default as first entry in list String defaultUrl = av.applet.getParameter("linkLabel_1"); - urlProvider = new UrlProvider(defaultUrl, urlList); + UrlProviderFactoryI factory = new AppletUrlProviderFactory( + defaultUrl, urlList); + urlProvider = factory.createUrlProvider(); } } } diff --git a/src/jalview/gui/DasSourceBrowser.java b/src/jalview/gui/DasSourceBrowser.java index e677084..26e9708 100644 --- a/src/jalview/gui/DasSourceBrowser.java +++ b/src/jalview/gui/DasSourceBrowser.java @@ -453,7 +453,7 @@ public class DasSourceBrowser extends GDasSourceBrowser implements pane12.add(nametf, BorderLayout.EAST); panel.add(pane12, BorderLayout.NORTH); pane12 = new JPanel(new BorderLayout()); - pane12.add(new JLabel(MessageManager.getString("label.url")), + pane12.add(new JLabel(MessageManager.getString("label.url:")), BorderLayout.NORTH); pane12.add(seqs, BorderLayout.SOUTH); pane12.add(urltf, BorderLayout.EAST); diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index d129898..550f324 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -29,8 +29,9 @@ import jalview.io.JalviewFileView; import jalview.jbgui.GPreferences; import jalview.jbgui.GSequenceLink; import jalview.schemes.ColourSchemeProperty; +import jalview.urls.DesktopUrlProviderFactory; import jalview.urls.UrlLinkTableModel; -import jalview.urls.UrlProvider; +import jalview.urls.UrlProviderFactoryI; import jalview.urls.UrlProviderI; import jalview.util.MessageManager; import jalview.util.Platform; @@ -129,7 +130,9 @@ public class Preferences extends GPreferences { String string = Cache.getDefault("SEQUENCE_LINKS", UrlConstants.DEFAULT_STRING); - sequenceUrlLinks = new UrlProvider(UrlConstants.DEFAULT_LABEL, string); + UrlProviderFactoryI factory = new DesktopUrlProviderFactory( + UrlConstants.DEFAULT_LABEL, string); + sequenceUrlLinks = factory.createUrlProvider(); dataModel = new UrlLinkTableModel(sequenceUrlLinks); /** diff --git a/src/jalview/gui/WsPreferences.java b/src/jalview/gui/WsPreferences.java index 6ec25b2..632535b 100644 --- a/src/jalview/gui/WsPreferences.java +++ b/src/jalview/gui/WsPreferences.java @@ -454,7 +454,7 @@ public class WsPreferences extends GWsPreferences JTextField urltf = new JTextField(url, 40); JPanel panel = new JPanel(new BorderLayout()); JPanel pane12 = new JPanel(new BorderLayout()); - pane12.add(new JLabel(MessageManager.getString("label.url")), + pane12.add(new JLabel(MessageManager.getString("label.url:")), BorderLayout.CENTER); pane12.add(urltf, BorderLayout.EAST); panel.add(pane12, BorderLayout.NORTH); @@ -574,6 +574,7 @@ public class WsPreferences extends GWsPreferences new Thread(new Runnable() { + @Override public void run() { // force a refresh. @@ -599,6 +600,7 @@ public class WsPreferences extends GWsPreferences new Thread(new Runnable() { + @Override public void run() { progressBar.setVisible(true); @@ -624,6 +626,7 @@ public class WsPreferences extends GWsPreferences new Thread(new Runnable() { + @Override public void run() { long ct = System.currentTimeMillis(); @@ -681,6 +684,7 @@ public class WsPreferences extends GWsPreferences new Thread(new Runnable() { + @Override public void run() { updateWsMenuConfig(false); diff --git a/src/jalview/jbgui/GSequenceLink.java b/src/jalview/jbgui/GSequenceLink.java index 46f64fe..1250bad 100755 --- a/src/jalview/jbgui/GSequenceLink.java +++ b/src/jalview/jbgui/GSequenceLink.java @@ -142,7 +142,7 @@ public class GSequenceLink extends JPanel jLabel1.setBounds(new Rectangle(4, 10, 71, 24)); jLabel2.setFont(JvSwingUtils.getLabelFont()); jLabel2.setHorizontalAlignment(SwingConstants.TRAILING); - jLabel2.setText(MessageManager.getString("label.url")); + jLabel2.setText(MessageManager.getString("label.url:")); jLabel2.setBounds(new Rectangle(17, 37, 54, 27)); jLabel3.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11)); jLabel3.setText(MessageManager.getString("label.use_sequence_id_1")); diff --git a/src/jalview/urls/AppletUrlProviderFactory.java b/src/jalview/urls/AppletUrlProviderFactory.java new file mode 100644 index 0000000..6faf9c0 --- /dev/null +++ b/src/jalview/urls/AppletUrlProviderFactory.java @@ -0,0 +1,59 @@ +/* + * 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. + * + * 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 . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ +package jalview.urls; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * UrlProvider factory for applet code + * + * @author $author$ + * @version $Revision$ + */ + +public class AppletUrlProviderFactory implements UrlProviderFactoryI +{ + private String provDefaultUrl; + + private Map provUrlList; + + public AppletUrlProviderFactory(String defaultUrlString, + Map urlList) + { + provDefaultUrl = defaultUrlString; + provUrlList = urlList; + } + + @Override + public UrlProviderI createUrlProvider() + { + // create all the UrlProviders we need + List providers = new ArrayList(); + UrlProviderI customProvider = new CustomUrlProvider(provUrlList); + providers.add(customProvider); + + UrlProviderI prov = new UrlProvider(provDefaultUrl, providers); + return null; + } + +} diff --git a/src/jalview/urls/CustomUrlProvider.java b/src/jalview/urls/CustomUrlProvider.java index a178ed6..ec594b6 100644 --- a/src/jalview/urls/CustomUrlProvider.java +++ b/src/jalview/urls/CustomUrlProvider.java @@ -167,8 +167,7 @@ public class CustomUrlProvider extends UrlProviderImpl // out // properly! displayLinks.add(new UrlLinkDisplay(key, key, displayLink, - isSelected, - isDefault)); + isSelected, isDefault)); } return displayLinks; } diff --git a/src/jalview/urls/DesktopUrlProviderFactory.java b/src/jalview/urls/DesktopUrlProviderFactory.java new file mode 100644 index 0000000..ee05376 --- /dev/null +++ b/src/jalview/urls/DesktopUrlProviderFactory.java @@ -0,0 +1,62 @@ +/* + * 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. + * + * 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 . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ +package jalview.urls; + +import java.util.ArrayList; +import java.util.List; + +/** + * UrlProvider factory for desktop code + * + * @author $author$ + * @version $Revision$ + */ + +public class DesktopUrlProviderFactory implements UrlProviderFactoryI +{ + + private String provDefaultUrl; + + private String provUrlList; + + public DesktopUrlProviderFactory(String defaultUrlString, + String cachedUrlList) + { + provDefaultUrl = defaultUrlString; + provUrlList = cachedUrlList; + } + + @Override + public UrlProviderI createUrlProvider() + { + // create all the UrlProviders we need + List providers = new ArrayList(); + + UrlProviderI idProvider = new IdentifiersUrlProvider(provUrlList, + IdentifiersUrlProvider.ID_ORG_FILE); + UrlProviderI customProvider = new CustomUrlProvider(provUrlList); + providers.add(idProvider); + providers.add(customProvider); + + return new UrlProvider(provDefaultUrl, providers); + } + +} diff --git a/src/jalview/urls/UrlLinkDisplay.java b/src/jalview/urls/UrlLinkDisplay.java index 9afe6d3..6a49f9e 100644 --- a/src/jalview/urls/UrlLinkDisplay.java +++ b/src/jalview/urls/UrlLinkDisplay.java @@ -21,6 +21,10 @@ package jalview.urls; +import jalview.util.MessageManager; + +import java.util.ArrayList; +import java.util.List; /** * UrlLink table row definition @@ -42,7 +46,20 @@ public class UrlLinkDisplay private boolean isSelected; - public final static int ID = 4; + // Headers for columns in table + private final static List colNames = new ArrayList() + { + { + add(MessageManager.formatMessage("label.name")); + add(MessageManager.formatMessage("label.url")); + add(MessageManager.formatMessage("label.inmenu")); + add(MessageManager.formatMessage("label.default")); + add(MessageManager.formatMessage("label.id")); + } + }; + + // column positions + public final static int NAME = 0; public final static int URL = 1; @@ -50,7 +67,7 @@ public class UrlLinkDisplay public final static int DEFAULT = 3; - public final static int NAME = 0; + public final static int ID = 4; public UrlLinkDisplay(String rowId, String rowName, String rowUrl, boolean rowSelected, boolean rowDefault) @@ -62,6 +79,7 @@ public class UrlLinkDisplay isSelected = rowSelected; } + // getters/setters public String getId() { return id; @@ -117,7 +135,7 @@ public class UrlLinkDisplay case NAME: return name; default: - return null; // TODO + return null; } } @@ -141,12 +159,30 @@ public class UrlLinkDisplay name = (String) value; break; default: - // TODO + // do nothing } } + /** + * Identify editable columns + * + * @param index + * index of column + * @return whether column can be edited in table + */ public boolean isEditable(int index) { return ((index == DEFAULT) || (index == SELECTED)); } + + /** + * Get list of column names to display in UI + * + * @return column names + */ + public static List getDisplayColumnNames() + { + // Display names between NAME and ID (excludes ID) + return colNames.subList(NAME, ID); + } } diff --git a/src/jalview/urls/UrlLinkTableModel.java b/src/jalview/urls/UrlLinkTableModel.java index b2c64f1..edf2561 100644 --- a/src/jalview/urls/UrlLinkTableModel.java +++ b/src/jalview/urls/UrlLinkTableModel.java @@ -64,7 +64,7 @@ public class UrlLinkTableModel extends AbstractTableModel { dataProvider = baseData; data = baseData.getLinksForTable(); - displayColumns = baseData.getDisplayColumnNames(); + displayColumns = UrlLinkDisplay.getDisplayColumnNames(); // find the default row defaultRow = 0; diff --git a/src/jalview/urls/UrlProvider.java b/src/jalview/urls/UrlProvider.java index 9e8d7bc..f93656f 100644 --- a/src/jalview/urls/UrlProvider.java +++ b/src/jalview/urls/UrlProvider.java @@ -24,7 +24,6 @@ import static jalview.util.UrlConstants.SEP; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.Vector; /** @@ -42,30 +41,20 @@ public class UrlProvider implements UrlProviderI // Specific reference to custom URL link provider private UrlProviderI customProvider; - // List of columns which this provider will supply - private List colNames = new ArrayList(); - /** - * Construct URL provider from string of cached URLs, and set default URL + * Constructor for UrlProvider composite * * @param defaultUrlString - * id of the current default URL - * @param cachedUrlList - * string listing current active URLs, expected to be custom URLs - * separated by |, or ids of URLs + * id of default url + * @param allProviders + * list of UrlProviders this provider gives access to */ - public UrlProvider(String defaultUrlString, String cachedUrlList) + public UrlProvider(String defaultUrlString, + List allProviders) { - // create all the UrlProviders we need - providers = new ArrayList(); - - UrlProviderI idProvider = new IdentifiersUrlProvider(cachedUrlList, - IdentifiersUrlProvider.ID_ORG_FILE); - customProvider = new CustomUrlProvider(cachedUrlList); - providers.add(idProvider); - providers.add(customProvider); + providers = allProviders; - setUpColumns(); + customProvider = findCustomProvider(); // check that the defaultUrl still exists if (!setDefaultUrl(defaultUrlString)) @@ -73,42 +62,23 @@ public class UrlProvider implements UrlProviderI chooseDefaultUrl(); } } - - /** - * Construct URL provider from a map of (label,url) pairs, and set default URL - * - * @param defaultUrlString - * id of the current default URL - * @param urlList - * vector of (label, url) pairs + + /* + * Store ref to custom url provider */ - public UrlProvider(String defaultUrlString, Map urlList) + private UrlProviderI findCustomProvider() { - // create all the UrlProviders we need - providers = new ArrayList(); - - UrlProviderI idProvider = new IdentifiersUrlProvider(null, - IdentifiersUrlProvider.ID_ORG_FILE); - customProvider = new CustomUrlProvider(urlList); - providers.add(idProvider); - providers.add(customProvider); - - setUpColumns(); - - // check that the defaultUrl still exists - if (!setDefaultUrl(defaultUrlString)) + for (UrlProviderI p : providers) { - chooseDefaultUrl(); + if (p.getClass().equals(CustomUrlProvider.class)) + { + return p; + } } - } - private void setUpColumns() - { - colNames.add("Name"); - colNames.add("URL"); - colNames.add("In Menu"); - colNames.add("Default"); - colNames.add("ID"); + System.out + .println("Error initialising UrlProvider - no custom url provider"); + return null; } @Override @@ -225,10 +195,4 @@ public class UrlProvider implements UrlProviderI { return customProvider.isUserEntry(id); } - - @Override - public List getDisplayColumnNames() - { - return colNames.subList(0, 4); - } } diff --git a/src/jalview/urls/UrlProviderFactoryI.java b/src/jalview/urls/UrlProviderFactoryI.java new file mode 100644 index 0000000..69e5a80 --- /dev/null +++ b/src/jalview/urls/UrlProviderFactoryI.java @@ -0,0 +1,33 @@ +/* + * 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. + * + * 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 . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ +package jalview.urls; + +/** + * Interface to UrlProvider factories + * + * @author $author$ + * @version $Revision$ + */ +public interface UrlProviderFactoryI +{ + public UrlProviderI createUrlProvider(); + +} diff --git a/src/jalview/urls/UrlProviderI.java b/src/jalview/urls/UrlProviderI.java index 0a02ca0..25303a6 100644 --- a/src/jalview/urls/UrlProviderI.java +++ b/src/jalview/urls/UrlProviderI.java @@ -93,11 +93,4 @@ public interface UrlProviderI * Determine if id is for a user-defined URL */ boolean isUserEntry(String id); - - /** - * Get list of column names to display in UI - * - * @return column names - */ - List getDisplayColumnNames(); } diff --git a/src/jalview/urls/UrlProviderImpl.java b/src/jalview/urls/UrlProviderImpl.java index 0fae392..82eeee9 100644 --- a/src/jalview/urls/UrlProviderImpl.java +++ b/src/jalview/urls/UrlProviderImpl.java @@ -106,10 +106,4 @@ public class UrlProviderImpl implements UrlProviderI return !isMiriamId(id); } - @Override - public List getDisplayColumnNames() - { - return null; - } - }