X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FDasSourceBrowser.java;h=fc2b387d609d12ff8b5f6f83bd523b3b00dda751;hb=35426f122a3db9e75360f2692c26a5452ec54460;hp=5b1adb1d16dbcfa10c84ce4b104eef72865d5e36;hpb=07af649391c1b952c268b8e5776531ab6f3d2f0e;p=jalview.git diff --git a/src/jalview/gui/DasSourceBrowser.java b/src/jalview/gui/DasSourceBrowser.java index 5b1adb1..fc2b387 100755 --- a/src/jalview/gui/DasSourceBrowser.java +++ b/src/jalview/gui/DasSourceBrowser.java @@ -1,6 +1,6 @@ /* * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Copyright (C) 2006 AM Waterhouse, J Procter, 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 @@ -41,19 +41,24 @@ public class DasSourceBrowser extends GDasSourceBrowser Vector selectedSources; + String DEFAULT_REGISTRY = "http://das.sanger.ac.uk/registry/das1/sources/"; + + boolean loadingDasSources = false; + + public DasSourceBrowser() { registryURL.setText(jalview.bin.Cache.getDefault("DAS_REGISTRY_URL", - "http://servlet.sanger.ac.uk/dasregistry/services/das_registry") ); + DEFAULT_REGISTRY) ); setSelectedFromProperties(); displayFullDetails(null); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - capabilities.addListSelectionListener(this); - coords1.addListSelectionListener(this); - coords2.addListSelectionListener(this); + filter1.addListSelectionListener(this); + filter2.addListSelectionListener(this); + filter3.addListSelectionListener(this); //Ask to be notified of selection changes. ListSelectionModel rowSM = table.getSelectionModel(); @@ -61,10 +66,6 @@ public class DasSourceBrowser extends GDasSourceBrowser { public void valueChanged(ListSelectionEvent e) { - //Ignore extra messages. - if (e.getValueIsAdjusting()) - return; - ListSelectionModel lsm = (ListSelectionModel) e.getSource(); if (!lsm.isSelectionEmpty()) { @@ -84,15 +85,19 @@ public class DasSourceBrowser extends GDasSourceBrowser } }); - if(dasSources==null) + if(dasSources!=null) { - Thread worker = new Thread(this); - worker.start(); - } - else - { init(); - } + } + } + + public void paintComponent(java.awt.Graphics g) + { + if (dasSources == null && !loadingDasSources) + { + Thread worker = new Thread(this); + worker.start(); + } } void init() @@ -240,6 +245,8 @@ public class DasSourceBrowser extends GDasSourceBrowser public void run() { + loadingDasSources = true; + addLocal.setVisible(false); refresh.setVisible(false); progressBar.setVisible(true); @@ -250,6 +257,28 @@ public class DasSourceBrowser extends GDasSourceBrowser appendLocalSources(); init(); + + loadingDasSources = false; + + } + + public Vector getSelectedSources() + { + Vector selected = new Vector(); + for (int r = 0; r < selectedSources.size(); r++) + { + for (int i = 0; i < dasSources.length; i++) + { + if (dasSources[i].getNickname().equals( + selectedSources.elementAt(r))) + { + selected.addElement(dasSources[i]); + break; + } + } + } + + return selected; } public DasSource[] getDASSource() @@ -273,49 +302,51 @@ public class DasSourceBrowser extends GDasSourceBrowser private void setCapabilities(DasSource[] sources) { - Vector vcapabilities = new Vector(); - Vector vcoords = new Vector(); - Vector vcoords2 = new Vector(); + Vector authority = new Vector(); + Vector type = new Vector(); + Vector label = new Vector(); - vcapabilities.addElement("All"); - vcoords.addElement("All"); - vcoords2.addElement("All"); + authority.addElement("Any"); + type.addElement("Any"); + label.addElement("Any"); for (int i = 0; i < sources.length; i++) { DasSource ds = sources[i]; - String[] scap = ds.getCapabilities(); - for (int s = 0; s < scap.length; s++) - { - if (!vcapabilities.contains(scap[s])) - { - vcapabilities.addElement(scap[s]); - } - } DasCoordinateSystem[] dcs = ds.getCoordinateSystem(); for (int j = 0; j < dcs.length; j++) { - if (!vcoords.contains(dcs[j].getCategory())) - vcoords.addElement(dcs[j].getCategory()); + if (!type.contains(dcs[j].getCategory())) + type.addElement(dcs[j].getCategory()); + + if (!authority.contains(dcs[j].getName())) + authority.addElement(dcs[j].getName()); + } - if (!vcoords2.contains(dcs[j].getName())) - vcoords2.addElement(dcs[j].getName()); + String[] slabels = ds.getLabels(); + for (int s = 0; s < slabels.length; s++) + { + if (!label.contains(slabels[s])) + { + label.addElement(slabels[s]); + } } + } - capabilities.setListData(vcapabilities); - coords1.setListData(vcoords); - coords2.setListData(vcoords2); + filter1.setListData(authority); + filter2.setListData(type); + filter3.setListData(label); javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { - capabilities.setSelectedIndex(0); - coords1.setSelectedIndex(0); - coords2.setSelectedIndex(0); + filter1.setSelectedIndex(0); + filter2.setSelectedIndex(0); + filter3.setSelectedIndex(0); } }); } @@ -527,44 +558,70 @@ public class DasSourceBrowser extends GDasSourceBrowser index++; } - dasSources = tmp; + dasSources = tmp; - refreshTableData(data); + refreshTableData(data); } public void valueChanged(ListSelectionEvent evt) { //Called when the MainTable selection changes - if (evt.getValueIsAdjusting()) + if (evt.getValueIsAdjusting() ) { return; } + displayFullDetails(null); // Filter the displayed data sources int dSize = dasSources.length; + + ArrayList names = new ArrayList(); ArrayList selected = new ArrayList(); DasSource ds; - // capabilities.get + //The features filter is not visible, but we must still + //filter the das source list here. + //July 2006 - only 6 sources fo not serve features + Object [] dummyFeatureList = new Object[]{"features"}; + for (int i = 0; i < dSize; i++) { ds = dasSources[i]; + DasCoordinateSystem[] dcs = ds.getCoordinateSystem(); - if (!selectedInList(capabilities, ds.getCapabilities())) + if (dcs.length == 0 && ds.getCapabilities().length == 0 + && filter1.getSelectedIndex() == 0 + && filter2.getSelectedIndex() == 0 + && filter3.getSelectedIndex() == 0) + { + //THIS IS A FIX FOR LOCAL SOURCES WHICH DO NOT + //HAVE COORDINATE SYSTEMS, INFO WHICH AT PRESENT + //IS ADDED FROM THE REGISTRY + names.add(ds.getNickname()); + selected.add(new Boolean( + selectedSources.contains(ds.getNickname()))); + continue; + } + + + if (!selectedInList(dummyFeatureList, ds.getCapabilities()) + || !selectedInList(filter3.getSelectedValues(), + ds.getLabels())) { continue; } - DasCoordinateSystem[] dcs = ds.getCoordinateSystem(); for (int j = 0; j < dcs.length; j++) { - if (selectedInList(coords1, new String[] - {dcs[j].getCategory()}) - && selectedInList(coords2, new String[] - {dcs[j].getName()})) + if ( selectedInList(filter1.getSelectedValues(), + new String[] + {dcs[j].getName()}) + && selectedInList(filter2.getSelectedValues(), + new String[] + {dcs[j].getCategory()})) { names.add(ds.getNickname()); selected.add(new Boolean( @@ -585,12 +642,11 @@ public class DasSourceBrowser extends GDasSourceBrowser refreshTableData(data); } - boolean selectedInList(JList list, String[] items) + boolean selectedInList(Object [] selection, String[] items) { - Object[] selection = list.getSelectedValues(); for (int i = 0; i < selection.length; i++) { - if (selection[i].equals("All")) + if (selection[i].equals("Any") ) return true; for (int j = 0; j < items.length; j++) @@ -634,9 +690,17 @@ public class DasSourceBrowser extends GDasSourceBrowser } } - void saveProperties(Properties properties) + public void reset_actionPerformed(ActionEvent e) { - properties.setProperty("DAS_REGISTRY_URL", registryURL.getText()); + registryURL.setText(DEFAULT_REGISTRY); + } + + public void saveProperties(Properties properties) + { + if (registryURL.getText() == null || registryURL.getText().length() < 1) + properties.remove("DAS_REGISTRY_URL"); + else + properties.setProperty("DAS_REGISTRY_URL", registryURL.getText()); StringBuffer sb = new StringBuffer(); for(int r=0; r