2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.gui;
\r
24 import java.awt.event.*;
\r
25 import javax.swing.*;
\r
26 import javax.swing.event.*;
\r
27 import javax.swing.table.*;
\r
29 import org.biojava.dasobert.dasregistry.*;
\r
30 import jalview.jbgui.*;
\r
31 import jalview.util.*;
\r
33 public class DasSourceBrowser
\r
34 extends GDasSourceBrowser implements Runnable, ListSelectionListener
\r
36 static DasSource[] dasSources = null;
\r
38 Hashtable localSources = null;
\r
40 Vector selectedSources;
\r
42 public static String DEFAULT_REGISTRY =
\r
43 "http://www.dasregistry.org/das1/sources/";
\r
46 * true if thread is running and we are talking to DAS registry service
\r
48 public boolean loadingDasSources = false;
\r
50 public DasSourceBrowser()
\r
52 String registry = jalview.bin.Cache.getDefault("DAS_REGISTRY_URL",
\r
55 if (registry.indexOf("/registry/das1/sources/") > -1)
\r
57 jalview.bin.Cache.setProperty("DAS_REGISTRY_URL", DEFAULT_REGISTRY);
\r
58 registry = DEFAULT_REGISTRY;
\r
61 registryURL.setText(registry);
\r
63 setSelectedFromProperties();
\r
65 displayFullDetails(null);
\r
66 table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
\r
68 filter1.addListSelectionListener(this);
\r
69 filter2.addListSelectionListener(this);
\r
70 filter3.addListSelectionListener(this);
\r
72 //Ask to be notified of selection changes.
\r
73 ListSelectionModel rowSM = table.getSelectionModel();
\r
74 rowSM.addListSelectionListener(new ListSelectionListener()
\r
76 public void valueChanged(ListSelectionEvent e)
\r
78 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
\r
79 if (!lsm.isSelectionEmpty())
\r
81 int selectedRow = lsm.getMinSelectionIndex();
\r
82 displayFullDetails(table.getValueAt(selectedRow, 0).toString());
\r
87 table.addMouseListener(new MouseAdapter()
\r
89 public void mouseClicked(MouseEvent evt)
\r
91 if (evt.getClickCount() == 2
\r
92 || SwingUtilities.isRightMouseButton(evt))
\r
94 editRemoveLocalSource(evt);
\r
99 if (dasSources != null)
\r
105 public void paintComponent(java.awt.Graphics g)
\r
107 if (dasSources == null && !loadingDasSources)
\r
109 Thread worker = new Thread(this);
\r
116 int dSize = dasSources.length;
\r
117 Object[][] data = new Object[dSize][2];
\r
118 for (int i = 0; i < dSize; i++)
\r
120 data[i][0] = dasSources[i].getNickname();
\r
121 data[i][1] = new Boolean(selectedSources.contains(dasSources[i].
\r
125 refreshTableData(data);
\r
126 setCapabilities(dasSources);
\r
128 javax.swing.SwingUtilities.invokeLater(new Runnable()
\r
132 TableSorter sorter = (TableSorter) table.getModel();
\r
133 sorter.setSortingStatus(1, TableSorter.DESCENDING);
\r
134 sorter.setSortingStatus(1, TableSorter.NOT_SORTED);
\r
138 progressBar.setIndeterminate(false);
\r
139 progressBar.setVisible(false);
\r
140 addLocal.setVisible(true);
\r
141 refresh.setVisible(true);
\r
144 public void refreshTableData(Object[][] data)
\r
146 TableSorter sorter = new TableSorter(new DASTableModel(data));
\r
147 sorter.setTableHeader(table.getTableHeader());
\r
148 table.setModel(sorter);
\r
151 void displayFullDetails(String nickName)
\r
154 StringBuffer text = new StringBuffer(
\r
155 "<HTML><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">");
\r
157 if (nickName == null)
\r
159 fullDetails.setText(text +
\r
160 "Select a DAS service from the table"
\r
161 + " to read a full description here.</font></html>");
\r
165 int dSize = dasSources.length;
\r
166 for (int i = 0; i < dSize; i++)
\r
168 if (!dasSources[i].getNickname().equals(nickName))
\r
173 DasSource ds = dasSources[i];
\r
175 text.append("<font color=\"#0000FF\">Id:</font> " + dasSources[i].getId() +
\r
177 text.append("<font color=\"#0000FF\">Nickname:</font> " +
\r
178 dasSources[i].getNickname() + "<br>");
\r
179 text.append("<font color=\"#0000FF\">URL:</font> " + dasSources[i].getUrl() +
\r
183 "<font color=\"#0000FF\">Admin Email:</font> <a href=\"mailto:"
\r
184 + dasSources[i].getAdminemail()
\r
185 + "\">" + dasSources[i].getAdminemail() + "</a>" +
\r
188 text.append("<font color=\"#0000FF\">Registered at:</font> " +
\r
189 dasSources[i].getRegisterDate() +
\r
192 text.append("<font color=\"#0000FF\">Last successful test:</font> " +
\r
193 dasSources[i].getLeaseDate() +
\r
196 text.append("<font color=\"#0000FF\">Labels:</font> ");
\r
197 for (int s = 0; s < dasSources[i].getLabels().length; s++)
\r
199 text.append(dasSources[i].getLabels()[s]);
\r
200 if (s < dasSources[i].getLabels().length - 1)
\r
206 text.append("<br>");
\r
208 text.append("<font color=\"#0000FF\">Capabilities:</font> ");
\r
209 String[] scap = dasSources[i].getCapabilities();
\r
210 for (int j = 0; j < scap.length; j++)
\r
212 text.append(scap[j]);
\r
213 if (j < scap.length - 1)
\r
218 text.append("<br>");
\r
220 text.append("<font color=\"#0000FF\">Coordinates:</font> ");
\r
221 DasCoordinateSystem[] dcs = ds.getCoordinateSystem();
\r
222 for (int j = 0; j < dcs.length; j++)
\r
224 text.append("(" + dcs[j].getUniqueId() + ") "
\r
225 + dcs[j].getCategory() + ", " + dcs[j].getName());
\r
226 if (dcs[j].getNCBITaxId() != 0)
\r
228 text.append(", " + dcs[j].getNCBITaxId());
\r
230 if (dcs[j].getOrganismName().length() > 0)
\r
232 text.append(", " + dcs[j].getOrganismName());
\r
235 text.append("<br>");
\r
238 text.append("<font color=\"#0000FF\">Description:</font> " +
\r
239 dasSources[i].getDescription() + "<br>");
\r
241 if (dasSources[i].getHelperurl() != null
\r
242 && dasSources[i].getHelperurl().length() > 0)
\r
244 text.append("<font color=\"#0000FF\"><a href=\"" +
\r
245 dasSources[i].getHelperurl()
\r
246 + "\">Go to site</a></font<br>");
\r
249 text.append("</font></html>");
\r
254 fullDetails.setText(text.toString());
\r
255 javax.swing.SwingUtilities.invokeLater(new Runnable()
\r
259 fullDetailsScrollpane.getVerticalScrollBar().setValue(0);
\r
266 loadingDasSources = true;
\r
268 addLocal.setVisible(false);
\r
269 refresh.setVisible(false);
\r
270 progressBar.setVisible(true);
\r
271 progressBar.setIndeterminate(true);
\r
273 dasSources = jalview.ws.DasSequenceFeatureFetcher.getDASSources();
\r
275 appendLocalSources();
\r
279 loadingDasSources = false;
\r
283 public Vector getSelectedSources()
\r
285 Vector selected = new Vector();
\r
286 for (int r = 0; r < selectedSources.size(); r++)
\r
288 for (int i = 0; i < dasSources.length; i++)
\r
290 if (dasSources[i].getNickname().equals(
\r
291 selectedSources.elementAt(r)))
\r
293 selected.addElement(dasSources[i]);
\r
302 public DasSource[] getDASSource()
\r
304 if (dasSources == null)
\r
306 dasSources = jalview.ws.DasSequenceFeatureFetcher.getDASSources();
\r
307 appendLocalSources();
\r
313 public void refresh_actionPerformed(ActionEvent e)
\r
315 saveProperties(jalview.bin.Cache.applicationProperties);
\r
317 Thread worker = new Thread(this);
\r
321 private void setCapabilities(DasSource[] sources)
\r
323 Vector authority = new Vector();
\r
324 Vector type = new Vector();
\r
325 Vector label = new Vector();
\r
327 authority.addElement("Any");
\r
328 type.addElement("Any");
\r
329 label.addElement("Any");
\r
331 for (int i = 0; i < sources.length; i++)
\r
333 DasSource ds = sources[i];
\r
335 DasCoordinateSystem[] dcs = ds.getCoordinateSystem();
\r
337 for (int j = 0; j < dcs.length; j++)
\r
339 if (!type.contains(dcs[j].getCategory()))
\r
341 type.addElement(dcs[j].getCategory());
\r
344 if (!authority.contains(dcs[j].getName()))
\r
346 authority.addElement(dcs[j].getName());
\r
350 String[] slabels = ds.getLabels();
\r
351 for (int s = 0; s < slabels.length; s++)
\r
353 if (!label.contains(slabels[s]))
\r
355 label.addElement(slabels[s]);
\r
361 filter1.setListData(authority);
\r
362 filter2.setListData(type);
\r
363 filter3.setListData(label);
\r
365 javax.swing.SwingUtilities.invokeLater(new Runnable()
\r
369 filter1.setSelectedIndex(0);
\r
370 filter2.setSelectedIndex(0);
\r
371 filter3.setSelectedIndex(0);
\r
376 public void amendLocal(boolean newSource)
\r
378 String url = "http://localhost:8080/", nickname = "";
\r
382 int selectedRow = table.getSelectionModel().getMinSelectionIndex();
\r
383 nickname = table.getValueAt(selectedRow, 0).toString();
\r
384 url = ( (DasSource) localSources.get(nickname)).getUrl();
\r
387 JTextField nametf = new JTextField(nickname, 40);
\r
388 JTextField urltf = new JTextField(url, 40);
\r
390 JPanel panel = new JPanel(new BorderLayout());
\r
391 JPanel pane12 = new JPanel(new BorderLayout());
\r
392 pane12.add(new JLabel("Nickname: "), BorderLayout.CENTER);
\r
393 pane12.add(nametf, BorderLayout.EAST);
\r
394 panel.add(pane12, BorderLayout.NORTH);
\r
395 pane12 = new JPanel(new BorderLayout());
\r
396 pane12.add(new JLabel("URL: "), BorderLayout.CENTER);
\r
397 pane12.add(urltf, BorderLayout.EAST);
\r
398 panel.add(pane12, BorderLayout.SOUTH);
\r
400 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
\r
401 panel, "Enter Nickname & URL of Local DAS Source",
\r
402 JOptionPane.OK_CANCEL_OPTION);
\r
404 if (reply != JOptionPane.OK_OPTION)
\r
409 if (!urltf.getText().endsWith("/"))
\r
411 urltf.setText(urltf.getText() + "/");
\r
414 Das1Source local = new Das1Source();
\r
416 local.setUrl(urltf.getText());
\r
417 local.setNickname(nametf.getText());
\r
419 if (localSources == null)
\r
421 localSources = new Hashtable();
\r
424 localSources.put(local.getNickname(), local);
\r
426 if (!newSource && !nickname.equals(nametf.getText()))
\r
428 localSources.remove(nickname);
\r
431 int size = dasSources.length;
\r
432 int adjust = newSource ? 1 : 0;
\r
434 Object[][] data = new Object[size + adjust][2];
\r
435 for (int i = 0; i < size; i++)
\r
437 if (!newSource && dasSources[i].getNickname().equals(nickname))
\r
439 ( (DasSource) dasSources[i]).setNickname(local.getNickname());
\r
440 ( (DasSource) dasSources[i]).setUrl(local.getUrl());
\r
441 data[i][0] = local.getNickname();
\r
442 data[i][1] = new Boolean(true);
\r
446 data[i][0] = dasSources[i].getNickname();
\r
447 data[i][1] = new Boolean(selectedSources.contains(dasSources[i].
\r
454 data[size][0] = local.getNickname();
\r
455 data[size][1] = new Boolean(true);
\r
456 selectedSources.add(local.getNickname());
\r
459 DasSource[] tmp = new DasSource[size + adjust];
\r
461 System.arraycopy(dasSources, 0, tmp, 0, size);
\r
470 refreshTableData(data);
\r
472 SwingUtilities.invokeLater(new Runnable()
\r
476 scrollPane.getVerticalScrollBar().setValue(
\r
477 scrollPane.getVerticalScrollBar().getMaximum()
\r
482 displayFullDetails(local.getNickname());
\r
485 public void editRemoveLocalSource(MouseEvent evt)
\r
487 int selectedRow = table.getSelectionModel().getMinSelectionIndex();
\r
488 if (selectedRow == -1)
\r
493 String nickname = table.getValueAt(selectedRow, 0).toString();
\r
495 if (!localSources.containsKey(nickname))
\r
497 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
498 "You can only edit or remove local DAS Sources!",
\r
499 "Public DAS source - not editable",
\r
500 JOptionPane.WARNING_MESSAGE);
\r
506 "Edit", "Remove", "Cancel"};
\r
507 int choice = JOptionPane.showInternalOptionDialog(Desktop.desktop,
\r
508 "Do you want to edit or remove " + nickname + "?",
\r
509 "Edit / Remove Local DAS Source",
\r
510 JOptionPane.YES_NO_CANCEL_OPTION,
\r
511 JOptionPane.QUESTION_MESSAGE,
\r
522 localSources.remove(nickname);
\r
523 selectedSources.remove(nickname);
\r
524 Object[][] data = new Object[dasSources.length - 1][2];
\r
525 DasSource[] tmp = new DasSource[dasSources.length - 1];
\r
527 for (int i = 0; i < dasSources.length; i++)
\r
529 if (dasSources[i].getNickname().equals(nickname))
\r
535 tmp[index] = dasSources[i];
\r
536 data[index][0] = dasSources[i].getNickname();
\r
537 data[index][1] = new Boolean(selectedSources.contains(dasSources[i].
\r
543 refreshTableData(data);
\r
544 SwingUtilities.invokeLater(new Runnable()
\r
548 scrollPane.getVerticalScrollBar().setValue(
\r
549 scrollPane.getVerticalScrollBar().getMaximum()
\r
558 void appendLocalSources()
\r
560 if (localSources == null)
\r
565 int size = dasSources != null ? dasSources.length : 0;
\r
566 int lsize = localSources.size();
\r
568 Object[][] data = new Object[size + lsize][2];
\r
569 for (int i = 0; i < size; i++)
\r
571 data[i][0] = dasSources[i].getNickname();
\r
572 data[i][1] = new Boolean(selectedSources.contains(dasSources[i].
\r
576 DasSource[] tmp = new DasSource[size + lsize];
\r
577 if (dasSources != null)
\r
579 System.arraycopy(dasSources, 0, tmp, 0, size);
\r
582 Enumeration en = localSources.keys();
\r
584 while (en.hasMoreElements())
\r
586 String key = en.nextElement().toString();
\r
587 data[index][0] = key;
\r
588 data[index][1] = new Boolean(false);
\r
589 tmp[index] = new Das1Source();
\r
590 tmp[index].setNickname(key);
\r
591 tmp[index].setUrl( ( (DasSource) localSources.get(key)).getUrl());
\r
598 refreshTableData(data);
\r
601 public void valueChanged(ListSelectionEvent evt)
\r
603 //Called when the MainTable selection changes
\r
604 if (evt.getValueIsAdjusting())
\r
609 displayFullDetails(null);
\r
611 // Filter the displayed data sources
\r
612 int dSize = dasSources.length;
\r
614 ArrayList names = new ArrayList();
\r
615 ArrayList selected = new ArrayList();
\r
618 //The features filter is not visible, but we must still
\r
619 //filter the das source list here.
\r
620 //July 2006 - only 6 sources fo not serve features
\r
621 Object[] dummyFeatureList = new Object[]
\r
625 for (int i = 0; i < dSize; i++)
\r
627 ds = dasSources[i];
\r
628 DasCoordinateSystem[] dcs = ds.getCoordinateSystem();
\r
630 if (dcs.length == 0 && ds.getCapabilities().length == 0
\r
631 && filter1.getSelectedIndex() == 0
\r
632 && filter2.getSelectedIndex() == 0
\r
633 && filter3.getSelectedIndex() == 0)
\r
635 //THIS IS A FIX FOR LOCAL SOURCES WHICH DO NOT
\r
636 //HAVE COORDINATE SYSTEMS, INFO WHICH AT PRESENT
\r
637 //IS ADDED FROM THE REGISTRY
\r
638 names.add(ds.getNickname());
\r
639 selected.add(new Boolean(
\r
640 selectedSources.contains(ds.getNickname())));
\r
644 if (!selectedInList(dummyFeatureList, ds.getCapabilities())
\r
645 || !selectedInList(filter3.getSelectedValues(),
\r
651 for (int j = 0; j < dcs.length; j++)
\r
653 if (selectedInList(filter1.getSelectedValues(),
\r
655 {dcs[j].getName()})
\r
656 && selectedInList(filter2.getSelectedValues(),
\r
658 {dcs[j].getCategory()}))
\r
660 names.add(ds.getNickname());
\r
661 selected.add(new Boolean(
\r
662 selectedSources.contains(ds.getNickname())));
\r
668 dSize = names.size();
\r
669 Object[][] data = new Object[dSize][2];
\r
670 for (int d = 0; d < dSize; d++)
\r
672 data[d][0] = names.get(d);
\r
673 data[d][1] = selected.get(d);
\r
676 refreshTableData(data);
\r
679 boolean selectedInList(Object[] selection, String[] items)
\r
681 for (int i = 0; i < selection.length; i++)
\r
683 if (selection[i].equals("Any"))
\r
688 for (int j = 0; j < items.length; j++)
\r
690 if (selection[i].equals(items[j]))
\r
700 void setSelectedFromProperties()
\r
702 String active = jalview.bin.Cache.getDefault("DAS_ACTIVE_SOURCE", "uniprot");
\r
703 StringTokenizer st = new StringTokenizer(active, "\t");
\r
704 selectedSources = new Vector();
\r
705 while (st.hasMoreTokens())
\r
707 selectedSources.addElement(st.nextToken());
\r
710 String local = jalview.bin.Cache.getProperty("DAS_LOCAL_SOURCE");
\r
713 if (localSources == null)
\r
715 localSources = new Hashtable();
\r
718 st = new StringTokenizer(local, "\t");
\r
719 while (st.hasMoreTokens())
\r
721 String token = st.nextToken();
\r
722 int bar = token.indexOf("|");
\r
723 Das1Source source = new Das1Source();
\r
725 source.setUrl(token.substring(bar + 1));
\r
726 source.setNickname(token.substring(0, bar));
\r
728 localSources.put(source.getNickname(), source);
\r
733 public void reset_actionPerformed(ActionEvent e)
\r
735 registryURL.setText(DEFAULT_REGISTRY);
\r
738 public void saveProperties(Properties properties)
\r
740 if (registryURL.getText() == null || registryURL.getText().length() < 1)
\r
742 properties.remove("DAS_REGISTRY_URL");
\r
746 properties.setProperty("DAS_REGISTRY_URL", registryURL.getText());
\r
749 StringBuffer sb = new StringBuffer();
\r
750 for (int r = 0; r < table.getModel().getRowCount(); r++)
\r
752 if ( ( (Boolean) table.getValueAt(r, 1)).booleanValue())
\r
754 sb.append(table.getValueAt(r, 0) + "\t");
\r
758 properties.setProperty("DAS_ACTIVE_SOURCE", sb.toString());
\r
760 if (localSources != null)
\r
762 sb = new StringBuffer();
\r
763 Enumeration en = localSources.keys();
\r
764 while (en.hasMoreElements())
\r
766 String token = en.nextElement().toString();
\r
767 sb.append(token + "|"
\r
768 + ( (DasSource) localSources.get(token)).getUrl()
\r
772 properties.setProperty("DAS_LOCAL_SOURCE", sb.toString());
\r
777 class DASTableModel
\r
778 extends AbstractTableModel
\r
781 public DASTableModel(Object[][] data)
\r
786 private String[] columnNames = new String[]
\r
788 "Nickname", "Use Source"};
\r
790 private Object[][] data;
\r
792 public int getColumnCount()
\r
794 return columnNames.length;
\r
797 public int getRowCount()
\r
799 return data.length;
\r
802 public String getColumnName(int col)
\r
804 return columnNames[col];
\r
807 public Object getValueAt(int row, int col)
\r
809 return data[row][col];
\r
813 * JTable uses this method to determine the default renderer/
\r
814 * editor for each cell. If we didn't implement this method,
\r
815 * then the last column would contain text ("true"/"false"),
\r
816 * rather than a check box.
\r
818 public Class getColumnClass(int c)
\r
820 return getValueAt(0, c).getClass();
\r
824 * Don't need to implement this method unless your table's
\r
827 public boolean isCellEditable(int row, int col)
\r
829 //Note that the data/cell address is constant,
\r
830 //no matter where the cell appears onscreen.
\r
836 * Don't need to implement this method unless your table's
\r
839 public void setValueAt(Object value, int row, int col)
\r
841 data[row][col] = value;
\r
842 fireTableCellUpdated(row, col);
\r
844 String name = getValueAt(row, 0).toString();
\r
845 boolean selected = ( (Boolean) value).booleanValue();
\r
847 if (selectedSources.contains(name) && !selected)
\r
849 selectedSources.remove(name);
\r
852 if (!selectedSources.contains(name) && selected)
\r
854 selectedSources.add(name);
\r