From 0abc5cc2ec2fb7d2dbb01adabd031299115ff8b8 Mon Sep 17 00:00:00 2001 From: jprocter Date: Thu, 4 Dec 2008 10:25:43 +0000 Subject: [PATCH] das source browser uses local source method from jalview.bin.Cache and methods refactored to allow headless access to list of selected das sources --- src/jalview/gui/DasSourceBrowser.java | 109 +++++++++++++++++++++++++-------- src/jalview/gui/FeatureSettings.java | 60 ++++++++---------- 2 files changed, 111 insertions(+), 58 deletions(-) diff --git a/src/jalview/gui/DasSourceBrowser.java b/src/jalview/gui/DasSourceBrowser.java index e336d9a..7237329 100755 --- a/src/jalview/gui/DasSourceBrowser.java +++ b/src/jalview/gui/DasSourceBrowser.java @@ -53,7 +53,7 @@ public class DasSourceBrowser extends GDasSourceBrowser implements if (registry.indexOf("/registry/das1/sources/") > -1) { - jalview.bin.Cache.setProperty("DAS_REGISTRY_URL", DEFAULT_REGISTRY); + jalview.bin.Cache.setProperty(jalview.bin.Cache.DAS_REGISTRY_URL, DEFAULT_REGISTRY); registry = DEFAULT_REGISTRY; } return registry; @@ -283,6 +283,19 @@ public class DasSourceBrowser extends GDasSourceBrowser implements public Vector getSelectedSources() { + // wait around if we're still loading. + while (dasSources ==null) { + if (!loadingDasSources) + { + new Thread(this).start(); + try { Thread.sleep(5); } catch (Exception e) {}; + while (loadingDasSources) + { + try { Thread.sleep(5); } catch (Exception e) {}; + }; + } + } + Vector selected = new Vector(); for (int r = 0; r < selectedSources.size(); r++) { @@ -392,17 +405,19 @@ public class DasSourceBrowser extends GDasSourceBrowser implements JTextField nametf = new JTextField(nickname, 40); JTextField urltf = new JTextField(url, 40); - + JCheckBox seqs = new JCheckBox("Sequence Source"); + JPanel panel = new JPanel(new BorderLayout()); JPanel pane12 = new JPanel(new BorderLayout()); pane12.add(new JLabel("Nickname: "), BorderLayout.CENTER); pane12.add(nametf, BorderLayout.EAST); panel.add(pane12, BorderLayout.NORTH); pane12 = new JPanel(new BorderLayout()); - pane12.add(new JLabel("URL: "), BorderLayout.CENTER); + pane12.add(new JLabel("URL: "), BorderLayout.NORTH); + pane12.add(seqs, BorderLayout.SOUTH); pane12.add(urltf, BorderLayout.EAST); panel.add(pane12, BorderLayout.SOUTH); - + int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop, panel, "Enter Nickname & URL of Local DAS Source", JOptionPane.OK_CANCEL_OPTION); @@ -421,7 +436,10 @@ public class DasSourceBrowser extends GDasSourceBrowser implements local.setUrl(urltf.getText()); local.setNickname(nametf.getText()); - + if (seqs.isSelected()) + { + local.setCapabilities(new String[] {"sequence"}); + } if (localSources == null) { localSources = new Hashtable(); @@ -561,7 +579,7 @@ public class DasSourceBrowser extends GDasSourceBrowser implements { return; } - + // note - we add all das sources to list so they can be filtered for the standard fetchDbRefs function int size = dasSources != null ? dasSources.length : 0; int lsize = localSources.size(); @@ -704,25 +722,18 @@ public class DasSourceBrowser extends GDasSourceBrowser implements { selectedSources.addElement(st.nextToken()); } - - String local = jalview.bin.Cache.getProperty("DAS_LOCAL_SOURCE"); - if (local != null) + + Vector _localSources = jalview.bin.Cache.getLocalDasSources(); + if (_localSources!=null) { - if (localSources == null) + if (localSources==null) { localSources = new Hashtable(); } - - st = new StringTokenizer(local, "\t"); - while (st.hasMoreTokens()) + Enumeration sources = _localSources.elements(); + while (sources.hasMoreElements()) { - String token = st.nextToken(); - int bar = token.indexOf("|"); - Das1Source source = new Das1Source(); - - source.setUrl(token.substring(bar + 1)); - source.setNickname(token.substring(0, bar)); - + Das1Source source = (Das1Source) sources.nextElement(); localSources.put(source.getNickname(), source); } } @@ -733,15 +744,19 @@ public class DasSourceBrowser extends GDasSourceBrowser implements registryURL.setText(DEFAULT_REGISTRY); } + /** + * set the DAS source settings in the given jalview properties. + * @param properties + */ public void saveProperties(Properties properties) { if (registryURL.getText() == null || registryURL.getText().length() < 1) { - properties.remove("DAS_REGISTRY_URL"); + properties.remove(jalview.bin.Cache.DAS_REGISTRY_URL); } else { - properties.setProperty("DAS_REGISTRY_URL", registryURL.getText()); + properties.setProperty(jalview.bin.Cache.DAS_REGISTRY_URL, registryURL.getText()); } StringBuffer sb = new StringBuffer(); @@ -753,7 +768,7 @@ public class DasSourceBrowser extends GDasSourceBrowser implements } } - properties.setProperty("DAS_ACTIVE_SOURCE", sb.toString()); + properties.setProperty(jalview.bin.Cache.DAS_ACTIVE_SOURCE, sb.toString()); if (localSources != null) { @@ -763,10 +778,11 @@ public class DasSourceBrowser extends GDasSourceBrowser implements { String token = en.nextElement().toString(); sb.append(token + "|" + +(((DasSource) localSources.get(token)).hasCapability("sequence") ? "sequence:" : "") + ((DasSource) localSources.get(token)).getUrl() + "\t"); } - properties.setProperty("DAS_LOCAL_SOURCE", sb.toString()); + properties.setProperty(jalview.bin.Cache.DAS_LOCAL_SOURCE, sb.toString()); } } @@ -847,4 +863,49 @@ public class DasSourceBrowser extends GDasSourceBrowser implements } } } + + public void initDasSources() + { + + Thread thr = new Thread(new Runnable() + { + public void run() + { + // this actually initialises the das source list + paintComponent(null); // yuk + } + }); + thr.start(); + while (loadingDasSources + || dasSources == null) + { + try + { + Thread.sleep(10); + } catch (Exception e) + { + } + ; + } + } + + public Vector resolveSourceNicknames(Vector sources) + { + + Vector resolved = new Vector(); + if (sources != null) + { + for (int i = 0; i < dasSources.length; i++) + { + if (sources.contains(dasSources[i].getNickname())) + { + if (!resolved.contains(dasSources[i])) + { + resolved.addElement(dasSources[i]); + } + } + } + } + return resolved; + } } diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index 632ad00..255340e 100755 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -850,6 +850,30 @@ public class FeatureSettings extends JPanel } /** + * blocking call to initialise the das source browser + */ + public void initDasSources() + { + dassourceBrowser.initDasSources(); + } + /** + * examine the current list of das sources and return any matching the given nicknames in sources + * @param sources Vector of Strings to resolve to DAS source nicknames. + * @return sources that are present in source list. + */ + public Vector resolveSourceNicknames(Vector sources) + { + return dassourceBrowser.resolveSourceNicknames(sources); + } + /** + * get currently selected das sources. ensure you have called initDasSources before calling this. + * @return vector of selected das source nicknames + */ + public Vector getSelectedSources() + { + return dassourceBrowser.getSelectedSources(); + } + /** * properly initialise DAS fetcher and then initiate a new thread to fetch * features from the named sources (rather than any turned on by default) * @@ -857,40 +881,8 @@ public class FeatureSettings extends JPanel */ public void fetchDasFeatures(Vector sources) { - Thread thr = new Thread(new Runnable() - { - public void run() - { - // this actually initialises the das source list - dassourceBrowser.paintComponent(null); // yuk - } - }); - thr.start(); - while (dassourceBrowser.loadingDasSources - || dassourceBrowser.dasSources == null) - { - try - { - Thread.sleep(10); - } catch (Exception e) - { - } - ; - } - Vector resolved = new Vector(); - if (sources != null) - { - for (int i = 0; i < dassourceBrowser.dasSources.length; i++) - { - if (sources.contains(dassourceBrowser.dasSources[i].getNickname())) - { - if (!resolved.contains(dassourceBrowser.dasSources[i])) - { - resolved.addElement(dassourceBrowser.dasSources[i]); - } - } - } - } + initDasSources(); + Vector resolved = resolveSourceNicknames(sources); if (resolved.size() == 0) { resolved = dassourceBrowser.getSelectedSources(); -- 1.7.10.2