X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FDasSourceBrowser.java;h=c6235301db319ec1ba8855a8be70073796b0f0c7;hb=a45774ee31d9f35d4eff46d54d7deab719afb092;hp=e336d9a649615696069e791fe87ccb21a0876c95;hpb=506d60f0e188723ddc91c26824b41ac7034df3fe;p=jalview.git diff --git a/src/jalview/gui/DasSourceBrowser.java b/src/jalview/gui/DasSourceBrowser.java index e336d9a..c623530 100755 --- a/src/jalview/gui/DasSourceBrowser.java +++ b/src/jalview/gui/DasSourceBrowser.java @@ -1,20 +1,19 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4) - * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7) + * Copyright (C) 2011 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle * - * This program 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 2 - * of the License, or (at your option) any later version. + * This file is part of Jalview. * - * This program 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. + * 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. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * 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 . */ package jalview.gui; @@ -53,14 +52,16 @@ 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; } - public DasSourceBrowser() + public DasSourceBrowser(FeatureSettings featureSettings) { + fs = featureSettings; String registry = getDasRegistryURL(); registryURL.setText(registry); @@ -107,6 +108,13 @@ public class DasSourceBrowser extends GDasSourceBrowser implements } } + FeatureSettings fs = null; + + public DasSourceBrowser() + { + this(null); + } + public void paintComponent(java.awt.Graphics g) { if (dasSources == null && !loadingDasSources) @@ -183,11 +191,10 @@ public class DasSourceBrowser extends GDasSourceBrowser implements text.append("URL: " + dasSources[i].getUrl() + "
"); - text - .append("Admin Email: " - + dasSources[i].getAdminemail() + "" + "
"); + text.append("Admin Email: " + + dasSources[i].getAdminemail() + "" + "
"); text.append("Registered at: " + dasSources[i].getRegisterDate() + "
"); @@ -271,18 +278,56 @@ public class DasSourceBrowser extends GDasSourceBrowser implements refresh.setVisible(false); progressBar.setVisible(true); progressBar.setIndeterminate(true); + setParentGuiEnabled(false); // Refresh the source list. dasSources = null; getDASSource(); init(); + setParentGuiEnabled(true); loadingDasSources = false; } + private void setParentGuiEnabled(boolean b) + { + if (fs != null) + { + fs.fetchDAS.setEnabled(b); + fs.saveDAS.setEnabled(b); + } + } + 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++) { @@ -382,24 +427,28 @@ public class DasSourceBrowser extends GDasSourceBrowser implements public void amendLocal(boolean newSource) { String url = "http://localhost:8080/", nickname = ""; - + boolean seqsrc = false; if (!newSource) { int selectedRow = table.getSelectionModel().getMinSelectionIndex(); nickname = table.getValueAt(selectedRow, 0).toString(); url = ((DasSource) localSources.get(nickname)).getUrl(); + seqsrc = ((DasSource) localSources.get(nickname)) + .hasCapability("sequence"); } JTextField nametf = new JTextField(nickname, 40); JTextField urltf = new JTextField(url, 40); - + JCheckBox seqs = new JCheckBox("Sequence Source"); + seqs.setSelected(seqsrc); 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); @@ -421,7 +470,11 @@ public class DasSourceBrowser extends GDasSourceBrowser implements local.setUrl(urltf.getText()); local.setNickname(nametf.getText()); - + if (seqs.isSelected()) + { + local.setCapabilities(new String[] + { "features", "sequence" }); + } if (localSources == null) { localSources = new Hashtable(); @@ -535,8 +588,8 @@ public class DasSourceBrowser extends GDasSourceBrowser implements { tmp[index] = dasSources[i]; data[index][0] = dasSources[i].getNickname(); - data[index][1] = new Boolean(selectedSources - .contains(dasSources[i].getNickname())); + data[index][1] = new Boolean( + selectedSources.contains(dasSources[i].getNickname())); index++; } } @@ -561,7 +614,8 @@ 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(); @@ -635,14 +689,13 @@ public class DasSourceBrowser extends GDasSourceBrowser implements // HAVE COORDINATE SYSTEMS, INFO WHICH AT PRESENT // IS ADDED FROM THE REGISTRY names.add(ds.getNickname()); - selected - .add(new Boolean(selectedSources.contains(ds.getNickname()))); + selected.add(new Boolean(selectedSources.contains(ds.getNickname()))); continue; } if (!selectedInList(dummyFeatureList, ds.getCapabilities()) - || !selectedInList(filter3.getSelectedValues(), ds - .getLabels())) + || !selectedInList(filter3.getSelectedValues(), + ds.getLabels())) { continue; } @@ -705,24 +758,17 @@ 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) { 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 +779,21 @@ 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 +805,8 @@ 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) { @@ -762,11 +815,15 @@ public class DasSourceBrowser extends GDasSourceBrowser implements while (en.hasMoreElements()) { String token = en.nextElement().toString(); - sb.append(token + "|" + 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 +904,59 @@ 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; + } + + /** + * disable or enable the buttons on the source browser + * + * @param b + */ + public void setGuiEnabled(boolean b) + { + refresh.setEnabled(b); + addLocal.setEnabled(b); + } }