From: kiramt Date: Wed, 7 Dec 2016 11:43:28 +0000 (+0000) Subject: JAL-2316 Restructure identifiers.org download X-Git-Tag: Release_2_10_3b1~346^2~25 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=e63a4d52c27252dfb83efeeee1bda6c89b6dddec;p=jalview.git JAL-2316 Restructure identifiers.org download --- diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index a52e6a4..1f5bdeb 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -1277,6 +1277,7 @@ exception.url_cannot_have_miriam_id = {0} is a MIRIAM id and cannot be used as a exception.url_cannot_have_duplicate_id = {0} cannot be used as a label for more than one line label.filter = Filter text: action.customfilter = Custom only +action.showall = Show All label.insert = Insert: action.seq_id = $SEQUENCE_ID$ action.db_acc = $DB_ACCESSION$ diff --git a/resources/lang/Messages_es.properties b/resources/lang/Messages_es.properties index f1339f8..b0194b9 100644 --- a/resources/lang/Messages_es.properties +++ b/resources/lang/Messages_es.properties @@ -1278,6 +1278,7 @@ exception.url_cannot_have_miriam_id = {0} is a MIRIAM id and cannot be used as a exception.url_cannot_have_duplicate_id = {0} cannot be used as a label for more than one link label.filter = Filter text: action.customfilter = Custom only +action.showall = Show All label.insert = Insert: action.seq_id = $SEQUENCE_ID$ action.db_acc = $DB_ACCESSION$ diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index 8412dab..fe21406 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -22,6 +22,7 @@ package jalview.bin; import jalview.datamodel.PDBEntry; import jalview.structure.StructureImportSettings; +import jalview.urls.IdOrgSettings; import jalview.ws.dbsources.das.api.DasSourceRegistryI; import jalview.ws.dbsources.das.datamodel.DasSourceRegistry; import jalview.ws.sifts.SiftsSettings; @@ -220,6 +221,9 @@ public class Cache public static final String DAS_ACTIVE_SOURCE = "DAS_ACTIVE_SOURCE"; + /** + * Sifts settings + */ public static final String DEFAULT_SIFTS_DOWNLOAD_DIR = System .getProperty("user.home") + File.separatorChar @@ -230,6 +234,14 @@ public class Cache private final static String DEFAULT_FAIL_SAFE_PID_THRESHOLD = "30"; /** + * Identifiers.org download settings + */ + private static final String ID_ORG_FILE = System.getProperty("user.home") + + File.separatorChar + ".jalview_identifiers"; + + private static final String ID_ORG_URL = "http://identifiers.org/rest/collections/"; + + /** * Allowed values are PDB or mmCIF */ private final static String PDB_DOWNLOAD_FORMAT = PDBEntry.Type.MMCIF @@ -440,6 +452,9 @@ public class Cache "sifts_cache_threshold_in_days", DEFAULT_CACHE_THRESHOLD_IN_DAYS)); + IdOrgSettings.setUrl(ID_ORG_URL); + IdOrgSettings.setDownloadLocation(ID_ORG_FILE); + System.out .println("Jalview Version: " + codeVersion + codeInstallation); diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index e0abe93..41ce9a7 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -34,11 +34,13 @@ import jalview.io.JalviewFileView; import jalview.jbgui.GSplitFrame; import jalview.jbgui.GStructureViewer; import jalview.structure.StructureSelectionManager; +import jalview.urls.IdOrgSettings; import jalview.util.ImageMaker; import jalview.util.MessageManager; import jalview.util.Platform; import jalview.util.UrlConstants; import jalview.viewmodel.AlignmentViewport; +import jalview.ws.UrlDownloadClient; import jalview.ws.params.ParamManager; import java.awt.BorderLayout; @@ -74,6 +76,7 @@ import java.beans.PropertyChangeListener; import java.io.BufferedInputStream; import java.io.File; import java.io.FileOutputStream; +import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.Hashtable; @@ -389,6 +392,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements showNews.setVisible(false); + getIdentifiersOrgData(); + checkURLLinks(); this.addWindowListener(new WindowAdapter() @@ -525,6 +530,29 @@ public class Desktop extends jalview.jbgui.GDesktop implements }); } + public void getIdentifiersOrgData() + { + // Thread off the identifiers fetcher + addDialogThread(new Runnable() + { + @Override + public void run() + { + Cache.log.debug("Downloading data from identifiers.org"); + UrlDownloadClient client = new UrlDownloadClient(); + try + { + client.download(IdOrgSettings.getUrl(), + IdOrgSettings.getDownloadLocation()); + } catch (IOException e) + { + Cache.log.debug("Exception downloading identifiers.org data" + + e.getMessage()); + } + } + }); + } + @Override protected void showNews_actionPerformed(ActionEvent e) { diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index 550f324..efe1ed6 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -128,10 +128,13 @@ public class Preferences extends GPreferences public static List groupURLLinks; static { - String string = Cache.getDefault("SEQUENCE_LINKS", + String inMenuString = Cache.getDefault("SEQUENCE_LINKS", UrlConstants.DEFAULT_STRING); - UrlProviderFactoryI factory = new DesktopUrlProviderFactory( - UrlConstants.DEFAULT_LABEL, string); + String notInMenuString = Cache.getDefault("STORED_LINKS", ""); + String defaultUrl = Cache.getDefault("DEFAULT_URL", + UrlConstants.DEFAULT_LABEL); + UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl, + inMenuString, notInMenuString); sequenceUrlLinks = factory.createUrlProvider(); dataModel = new UrlLinkTableModel(sequenceUrlLinks); @@ -414,7 +417,7 @@ public class Preferences extends GPreferences // set up radio buttons linkUrlTable.getColumn("Default").setCellRenderer( - new RadioButtonRenderer()); + new RadioButtonRenderer()); linkUrlTable.getColumn("Default") .setCellEditor(new RadioButtonEditor()); @@ -635,17 +638,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.getDefaultUrlId()); + Cache.applicationProperties.setProperty("USE_PROXY", Boolean.toString(useProxy.isSelected())); diff --git a/src/jalview/jbgui/GPreferences.java b/src/jalview/jbgui/GPreferences.java index 3fe1939..6fe6be2 100755 --- a/src/jalview/jbgui/GPreferences.java +++ b/src/jalview/jbgui/GPreferences.java @@ -654,6 +654,12 @@ public class GPreferences extends JPanel linkUrlTable.setAutoCreateRowSorter(true); linkUrlTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + // adjust row height so radio buttons actually fit + // don't do this in the renderer, it causes the awt thread to activate + // constantly + JRadioButton temp = new JRadioButton(); + linkUrlTable.setRowHeight(temp.getMinimumSize().height); + // Table in scrollpane so that the table is given a scrollbar JScrollPane linkScrollPane = new JScrollPane(linkUrlTable); linkScrollPane.setBorder(null); @@ -706,7 +712,7 @@ public class GPreferences extends JPanel filterTB.setFont(LABEL_FONT); filterTB.setText(""); - doReset.setText(MessageManager.getString("action.reset")); + doReset.setText(MessageManager.getString("action.showall")); userOnly.setText(MessageManager.getString("action.customfilter")); // Panel for filter functionality @@ -1515,54 +1521,51 @@ public class GPreferences extends JPanel // set colours to match rest of table if (isSelected) - { - setBackground(table.getSelectionBackground()); - setForeground(table.getSelectionForeground()); - } - else - { - setBackground(table.getBackground()); - setForeground(table.getForeground()); + { + setBackground(table.getSelectionBackground()); + setForeground(table.getSelectionForeground()); + } + else + { + setBackground(table.getBackground()); + setForeground(table.getForeground()); } - // adjust row height so radio buttons actually fit - table.setRowHeight(row, getMinimumSize().height); - return this; } } public class RadioButtonEditor extends AbstractCellEditor implements - TableCellEditor - { - private JRadioButton button = new JRadioButton(); - - public RadioButtonEditor() + TableCellEditor { - this.button.setHorizontalAlignment(SwingConstants.CENTER); - this.button.addActionListener(new ActionListener() + private JRadioButton button = new JRadioButton(); + + public RadioButtonEditor() { - @Override - public void actionPerformed(ActionEvent e) + // this.button.setHorizontalAlignment(SwingConstants.CENTER); + this.button.addActionListener(new ActionListener() { - fireEditingStopped(); - } - }); - } + @Override + public void actionPerformed(ActionEvent e) + { + fireEditingStopped(); + } + }); + } - @Override - public Component getTableCellEditorComponent(JTable table, - Object value, boolean isSelected, int row, int column) - { + @Override + public Component getTableCellEditorComponent(JTable table, + Object value, boolean isSelected, int row, int column) + { button.setSelected((boolean) value); - return button; - } + return button; + } - @Override - public Object getCellEditorValue() - { + @Override + public Object getCellEditorValue() + { return button.isSelected(); - } + } } } diff --git a/src/jalview/urls/AppletUrlProviderFactory.java b/src/jalview/urls/AppletUrlProviderFactory.java index 6faf9c0..db1206c 100644 --- a/src/jalview/urls/AppletUrlProviderFactory.java +++ b/src/jalview/urls/AppletUrlProviderFactory.java @@ -49,11 +49,11 @@ public class AppletUrlProviderFactory implements UrlProviderFactoryI { // create all the UrlProviders we need List providers = new ArrayList(); - UrlProviderI customProvider = new CustomUrlProvider(provUrlList); + UrlProviderI customProvider = new CustomUrlProvider(provUrlList, null); providers.add(customProvider); UrlProviderI prov = new UrlProvider(provDefaultUrl, providers); - return null; + return prov; } } diff --git a/src/jalview/urls/CustomUrlProvider.java b/src/jalview/urls/CustomUrlProvider.java index ec594b6..ab84be2 100644 --- a/src/jalview/urls/CustomUrlProvider.java +++ b/src/jalview/urls/CustomUrlProvider.java @@ -52,84 +52,107 @@ public class CustomUrlProvider extends UrlProviderImpl // Default sequence URL link label for SRS private static final String SRS_LABEL = "SRS"; - // map of string ids to urlLinks - private HashMap urls; + // map of string ids to urlLinks (selected) + private HashMap selectedUrls; + + // map of string ids to urlLinks (not selected) + private HashMap nonselectedUrls; /** * Construct UrlProvider for custom (user-entered) URLs * - * @param cachedUrlList - * list of URLs in form stored in Cache. i.e. SEP delimited string + * @param inMenuUrlList + * list of URLs set to be displayed in menu, in form stored in Cache. + * i.e. SEP delimited string + * @param storedUrlList + * list of custom URLs entered by user but not currently displayed in + * menu, in form stored in Cache */ - public CustomUrlProvider(String cachedUrlList) + public CustomUrlProvider(String inMenuUrlList, String storedUrlList) { try { - urls = new HashMap(); - - // cachedUrlList is in form