2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
\r
3 * Copyright (C) 2008 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 extends GDasSourceBrowser implements
\r
34 Runnable, ListSelectionListener
\r
36 static DasSource[] dasSources = null;
\r
38 Hashtable localSources = null;
\r
40 Vector selectedSources;
\r
42 public static String DEFAULT_REGISTRY = "http://www.dasregistry.org/das1/sources/";
\r
45 * true if thread is running and we are talking to DAS registry service
\r
47 public boolean loadingDasSources = false;
\r
49 protected static String getDasRegistryURL()
\r
51 String registry = jalview.bin.Cache.getDefault("DAS_REGISTRY_URL",
\r
54 if (registry.indexOf("/registry/das1/sources/") > -1)
\r
56 jalview.bin.Cache.setProperty(jalview.bin.Cache.DAS_REGISTRY_URL, DEFAULT_REGISTRY);
\r
57 registry = DEFAULT_REGISTRY;
\r
62 public DasSourceBrowser()
\r
64 String registry = getDasRegistryURL();
\r
66 registryURL.setText(registry);
\r
68 setSelectedFromProperties();
\r
70 displayFullDetails(null);
\r
71 table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
\r
73 filter1.addListSelectionListener(this);
\r
74 filter2.addListSelectionListener(this);
\r
75 filter3.addListSelectionListener(this);
\r
77 // Ask to be notified of selection changes.
\r
78 ListSelectionModel rowSM = table.getSelectionModel();
\r
79 rowSM.addListSelectionListener(new ListSelectionListener()
\r
81 public void valueChanged(ListSelectionEvent e)
\r
83 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
\r
84 if (!lsm.isSelectionEmpty())
\r
86 int selectedRow = lsm.getMinSelectionIndex();
\r
87 displayFullDetails(table.getValueAt(selectedRow, 0).toString());
\r
92 table.addMouseListener(new MouseAdapter()
\r
94 public void mouseClicked(MouseEvent evt)
\r
96 if (evt.getClickCount() == 2
\r
97 || SwingUtilities.isRightMouseButton(evt))
\r
99 editRemoveLocalSource(evt);
\r
104 if (dasSources != null)
\r
110 public void paintComponent(java.awt.Graphics g)
\r
112 if (dasSources == null && !loadingDasSources)
\r
114 Thread worker = new Thread(this);
\r
121 int dSize = dasSources.length;
\r
122 Object[][] data = new Object[dSize][2];
\r
123 for (int i = 0; i < dSize; i++)
\r
125 data[i][0] = dasSources[i].getNickname();
\r
126 data[i][1] = new Boolean(selectedSources.contains(dasSources[i]
\r
130 refreshTableData(data);
\r
131 setCapabilities(dasSources);
\r
133 javax.swing.SwingUtilities.invokeLater(new Runnable()
\r
137 TableSorter sorter = (TableSorter) table.getModel();
\r
138 sorter.setSortingStatus(1, TableSorter.DESCENDING);
\r
139 sorter.setSortingStatus(1, TableSorter.NOT_SORTED);
\r
143 progressBar.setIndeterminate(false);
\r
144 progressBar.setVisible(false);
\r
145 addLocal.setVisible(true);
\r
146 refresh.setVisible(true);
\r
149 public void refreshTableData(Object[][] data)
\r
151 TableSorter sorter = new TableSorter(new DASTableModel(data));
\r
152 sorter.setTableHeader(table.getTableHeader());
\r
153 table.setModel(sorter);
\r
156 void displayFullDetails(String nickName)
\r
159 StringBuffer text = new StringBuffer(
\r
160 "<HTML><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">");
\r
162 if (nickName == null)
\r
164 fullDetails.setText(text + "Select a DAS service from the table"
\r
165 + " to read a full description here.</font></html>");
\r
169 int dSize = dasSources.length;
\r
170 for (int i = 0; i < dSize; i++)
\r
172 if (!dasSources[i].getNickname().equals(nickName))
\r
177 DasSource ds = dasSources[i];
\r
179 text.append("<font color=\"#0000FF\">Id:</font> "
\r
180 + dasSources[i].getId() + "<br>");
\r
181 text.append("<font color=\"#0000FF\">Nickname:</font> "
\r
182 + dasSources[i].getNickname() + "<br>");
\r
183 text.append("<font color=\"#0000FF\">URL:</font> "
\r
184 + dasSources[i].getUrl() + "<br>");
\r
187 .append("<font color=\"#0000FF\">Admin Email:</font> <a href=\"mailto:"
\r
188 + dasSources[i].getAdminemail()
\r
190 + dasSources[i].getAdminemail() + "</a>" + "<br>");
\r
192 text.append("<font color=\"#0000FF\">Registered at:</font> "
\r
193 + dasSources[i].getRegisterDate() + "<br>");
\r
195 text.append("<font color=\"#0000FF\">Last successful test:</font> "
\r
196 + dasSources[i].getLeaseDate() + "<br>");
\r
198 text.append("<font color=\"#0000FF\">Labels:</font> ");
\r
199 for (int s = 0; s < dasSources[i].getLabels().length; s++)
\r
201 text.append(dasSources[i].getLabels()[s]);
\r
202 if (s < dasSources[i].getLabels().length - 1)
\r
208 text.append("<br>");
\r
210 text.append("<font color=\"#0000FF\">Capabilities:</font> ");
\r
211 String[] scap = dasSources[i].getCapabilities();
\r
212 for (int j = 0; j < scap.length; j++)
\r
214 text.append(scap[j]);
\r
215 if (j < scap.length - 1)
\r
220 text.append("<br>");
\r
222 text.append("<font color=\"#0000FF\">Coordinates:</font> ");
\r
223 DasCoordinateSystem[] dcs = ds.getCoordinateSystem();
\r
224 for (int j = 0; j < dcs.length; j++)
\r
226 text.append("(" + dcs[j].getUniqueId() + ") "
\r
227 + dcs[j].getCategory() + ", " + dcs[j].getName());
\r
228 if (dcs[j].getNCBITaxId() != 0)
\r
230 text.append(", " + dcs[j].getNCBITaxId());
\r
232 if (dcs[j].getOrganismName().length() > 0)
\r
234 text.append(", " + dcs[j].getOrganismName());
\r
237 text.append("<br>");
\r
240 text.append("<font color=\"#0000FF\">Description:</font> "
\r
241 + dasSources[i].getDescription() + "<br>");
\r
243 if (dasSources[i].getHelperurl() != null
\r
244 && dasSources[i].getHelperurl().length() > 0)
\r
246 text.append("<font color=\"#0000FF\"><a href=\""
\r
247 + dasSources[i].getHelperurl()
\r
248 + "\">Go to site</a></font<br>");
\r
251 text.append("</font></html>");
\r
256 fullDetails.setText(text.toString());
\r
257 javax.swing.SwingUtilities.invokeLater(new Runnable()
\r
261 fullDetailsScrollpane.getVerticalScrollBar().setValue(0);
\r
268 loadingDasSources = true;
\r
270 addLocal.setVisible(false);
\r
271 refresh.setVisible(false);
\r
272 progressBar.setVisible(true);
\r
273 progressBar.setIndeterminate(true);
\r
274 // Refresh the source list.
\r
280 loadingDasSources = false;
\r
284 public Vector getSelectedSources()
\r
286 // wait around if we're still loading.
\r
287 while (dasSources ==null) {
\r
288 if (!loadingDasSources)
\r
290 new Thread(this).start();
\r
291 try { Thread.sleep(5); } catch (Exception e) {};
\r
292 while (loadingDasSources)
\r
294 try { Thread.sleep(5); } catch (Exception e) {};
\r
299 Vector selected = new Vector();
\r
300 for (int r = 0; r < selectedSources.size(); r++)
\r
302 for (int i = 0; i < dasSources.length; i++)
\r
304 if (dasSources[i].getNickname()
\r
305 .equals(selectedSources.elementAt(r)))
\r
307 selected.addElement(dasSources[i]);
\r
317 * retrieve das sources from registry and add local source list
\r
321 public DasSource[] getDASSource()
\r
323 if (dasSources == null)
\r
325 dasSources = jalview.ws.DasSequenceFeatureFetcher.getDASSources();
\r
326 appendLocalSources();
\r
332 public void refresh_actionPerformed(ActionEvent e)
\r
334 saveProperties(jalview.bin.Cache.applicationProperties);
\r
336 Thread worker = new Thread(this);
\r
340 private void setCapabilities(DasSource[] sources)
\r
342 Vector authority = new Vector();
\r
343 Vector type = new Vector();
\r
344 Vector label = new Vector();
\r
346 authority.addElement("Any");
\r
347 type.addElement("Any");
\r
348 label.addElement("Any");
\r
350 for (int i = 0; i < sources.length; i++)
\r
352 DasSource ds = sources[i];
\r
354 DasCoordinateSystem[] dcs = ds.getCoordinateSystem();
\r
356 for (int j = 0; j < dcs.length; j++)
\r
358 if (!type.contains(dcs[j].getCategory()))
\r
360 type.addElement(dcs[j].getCategory());
\r
363 if (!authority.contains(dcs[j].getName()))
\r
365 authority.addElement(dcs[j].getName());
\r
369 String[] slabels = ds.getLabels();
\r
370 for (int s = 0; s < slabels.length; s++)
\r
372 if (!label.contains(slabels[s]))
\r
374 label.addElement(slabels[s]);
\r
380 filter1.setListData(authority);
\r
381 filter2.setListData(type);
\r
382 filter3.setListData(label);
\r
384 javax.swing.SwingUtilities.invokeLater(new Runnable()
\r
388 filter1.setSelectedIndex(0);
\r
389 filter2.setSelectedIndex(0);
\r
390 filter3.setSelectedIndex(0);
\r
395 public void amendLocal(boolean newSource)
\r
397 String url = "http://localhost:8080/", nickname = "";
\r
398 boolean seqsrc=false;
\r
401 int selectedRow = table.getSelectionModel().getMinSelectionIndex();
\r
402 nickname = table.getValueAt(selectedRow, 0).toString();
\r
403 url = ((DasSource) localSources.get(nickname)).getUrl();
\r
404 seqsrc = ((DasSource)localSources.get(nickname)).hasCapability("sequence");
\r
407 JTextField nametf = new JTextField(nickname, 40);
\r
408 JTextField urltf = new JTextField(url, 40);
\r
409 JCheckBox seqs = new JCheckBox("Sequence Source");
\r
410 seqs.setSelected(seqsrc);
\r
411 JPanel panel = new JPanel(new BorderLayout());
\r
412 JPanel pane12 = new JPanel(new BorderLayout());
\r
413 pane12.add(new JLabel("Nickname: "), BorderLayout.CENTER);
\r
414 pane12.add(nametf, BorderLayout.EAST);
\r
415 panel.add(pane12, BorderLayout.NORTH);
\r
416 pane12 = new JPanel(new BorderLayout());
\r
417 pane12.add(new JLabel("URL: "), BorderLayout.NORTH);
\r
418 pane12.add(seqs, BorderLayout.SOUTH);
\r
419 pane12.add(urltf, BorderLayout.EAST);
\r
420 panel.add(pane12, BorderLayout.SOUTH);
\r
422 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
\r
423 panel, "Enter Nickname & URL of Local DAS Source",
\r
424 JOptionPane.OK_CANCEL_OPTION);
\r
426 if (reply != JOptionPane.OK_OPTION)
\r
431 if (!urltf.getText().endsWith("/"))
\r
433 urltf.setText(urltf.getText() + "/");
\r
436 Das1Source local = new Das1Source();
\r
438 local.setUrl(urltf.getText());
\r
439 local.setNickname(nametf.getText());
\r
440 if (seqs.isSelected())
\r
442 local.setCapabilities(new String[] {"features","sequence"});
\r
444 if (localSources == null)
\r
446 localSources = new Hashtable();
\r
449 localSources.put(local.getNickname(), local);
\r
451 if (!newSource && !nickname.equals(nametf.getText()))
\r
453 localSources.remove(nickname);
\r
456 int size = dasSources.length;
\r
457 int adjust = newSource ? 1 : 0;
\r
459 Object[][] data = new Object[size + adjust][2];
\r
460 for (int i = 0; i < size; i++)
\r
462 if (!newSource && dasSources[i].getNickname().equals(nickname))
\r
464 ((DasSource) dasSources[i]).setNickname(local.getNickname());
\r
465 ((DasSource) dasSources[i]).setUrl(local.getUrl());
\r
466 data[i][0] = local.getNickname();
\r
467 data[i][1] = new Boolean(true);
\r
471 data[i][0] = dasSources[i].getNickname();
\r
472 data[i][1] = new Boolean(selectedSources.contains(dasSources[i]
\r
479 data[size][0] = local.getNickname();
\r
480 data[size][1] = new Boolean(true);
\r
481 selectedSources.add(local.getNickname());
\r
484 DasSource[] tmp = new DasSource[size + adjust];
\r
486 System.arraycopy(dasSources, 0, tmp, 0, size);
\r
495 refreshTableData(data);
\r
497 SwingUtilities.invokeLater(new Runnable()
\r
501 scrollPane.getVerticalScrollBar().setValue(
\r
502 scrollPane.getVerticalScrollBar().getMaximum());
\r
506 displayFullDetails(local.getNickname());
\r
509 public void editRemoveLocalSource(MouseEvent evt)
\r
511 int selectedRow = table.getSelectionModel().getMinSelectionIndex();
\r
512 if (selectedRow == -1)
\r
517 String nickname = table.getValueAt(selectedRow, 0).toString();
\r
519 if (!localSources.containsKey(nickname))
\r
521 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
522 "You can only edit or remove local DAS Sources!",
\r
523 "Public DAS source - not editable",
\r
524 JOptionPane.WARNING_MESSAGE);
\r
529 { "Edit", "Remove", "Cancel" };
\r
530 int choice = JOptionPane.showInternalOptionDialog(Desktop.desktop,
\r
531 "Do you want to edit or remove " + nickname + "?",
\r
532 "Edit / Remove Local DAS Source",
\r
533 JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,
\r
534 null, options, options[2]);
\r
542 localSources.remove(nickname);
\r
543 selectedSources.remove(nickname);
\r
544 Object[][] data = new Object[dasSources.length - 1][2];
\r
545 DasSource[] tmp = new DasSource[dasSources.length - 1];
\r
547 for (int i = 0; i < dasSources.length; i++)
\r
549 if (dasSources[i].getNickname().equals(nickname))
\r
555 tmp[index] = dasSources[i];
\r
556 data[index][0] = dasSources[i].getNickname();
\r
557 data[index][1] = new Boolean(selectedSources
\r
558 .contains(dasSources[i].getNickname()));
\r
563 refreshTableData(data);
\r
564 SwingUtilities.invokeLater(new Runnable()
\r
568 scrollPane.getVerticalScrollBar().setValue(
\r
569 scrollPane.getVerticalScrollBar().getMaximum());
\r
577 void appendLocalSources()
\r
579 if (localSources == null)
\r
583 // note - we add all das sources to list so they can be filtered for the standard fetchDbRefs function
\r
584 int size = dasSources != null ? dasSources.length : 0;
\r
585 int lsize = localSources.size();
\r
587 Object[][] data = new Object[size + lsize][2];
\r
588 for (int i = 0; i < size; i++)
\r
590 data[i][0] = dasSources[i].getNickname();
\r
591 data[i][1] = new Boolean(selectedSources.contains(dasSources[i]
\r
595 DasSource[] tmp = new DasSource[size + lsize];
\r
596 if (dasSources != null)
\r
598 System.arraycopy(dasSources, 0, tmp, 0, size);
\r
601 Enumeration en = localSources.keys();
\r
603 while (en.hasMoreElements())
\r
605 String key = en.nextElement().toString();
\r
606 data[index][0] = key;
\r
607 data[index][1] = new Boolean(false);
\r
608 tmp[index] = new Das1Source();
\r
609 tmp[index].setNickname(key);
\r
610 tmp[index].setUrl(((DasSource) localSources.get(key)).getUrl());
\r
617 refreshTableData(data);
\r
620 public void valueChanged(ListSelectionEvent evt)
\r
622 // Called when the MainTable selection changes
\r
623 if (evt.getValueIsAdjusting())
\r
628 displayFullDetails(null);
\r
630 // Filter the displayed data sources
\r
631 int dSize = dasSources.length;
\r
633 ArrayList names = new ArrayList();
\r
634 ArrayList selected = new ArrayList();
\r
637 // The features filter is not visible, but we must still
\r
638 // filter the das source list here.
\r
639 // July 2006 - only 6 sources fo not serve features
\r
640 Object[] dummyFeatureList = new Object[]
\r
643 for (int i = 0; i < dSize; i++)
\r
645 ds = dasSources[i];
\r
646 DasCoordinateSystem[] dcs = ds.getCoordinateSystem();
\r
648 if (dcs.length == 0 && ds.getCapabilities().length == 0
\r
649 && filter1.getSelectedIndex() == 0
\r
650 && filter2.getSelectedIndex() == 0
\r
651 && filter3.getSelectedIndex() == 0)
\r
653 // THIS IS A FIX FOR LOCAL SOURCES WHICH DO NOT
\r
654 // HAVE COORDINATE SYSTEMS, INFO WHICH AT PRESENT
\r
655 // IS ADDED FROM THE REGISTRY
\r
656 names.add(ds.getNickname());
\r
658 .add(new Boolean(selectedSources.contains(ds.getNickname())));
\r
662 if (!selectedInList(dummyFeatureList, ds.getCapabilities())
\r
663 || !selectedInList(filter3.getSelectedValues(), ds
\r
669 for (int j = 0; j < dcs.length; j++)
\r
671 if (selectedInList(filter1.getSelectedValues(), new String[]
\r
672 { dcs[j].getName() })
\r
673 && selectedInList(filter2.getSelectedValues(), new String[]
\r
674 { dcs[j].getCategory() }))
\r
676 names.add(ds.getNickname());
\r
677 selected.add(new Boolean(selectedSources.contains(ds
\r
684 dSize = names.size();
\r
685 Object[][] data = new Object[dSize][2];
\r
686 for (int d = 0; d < dSize; d++)
\r
688 data[d][0] = names.get(d);
\r
689 data[d][1] = selected.get(d);
\r
692 refreshTableData(data);
\r
695 boolean selectedInList(Object[] selection, String[] items)
\r
697 for (int i = 0; i < selection.length; i++)
\r
699 if (selection[i].equals("Any"))
\r
704 for (int j = 0; j < items.length; j++)
\r
706 if (selection[i].equals(items[j]))
\r
716 void setSelectedFromProperties()
\r
718 String active = jalview.bin.Cache.getDefault("DAS_ACTIVE_SOURCE",
\r
720 StringTokenizer st = new StringTokenizer(active, "\t");
\r
721 selectedSources = new Vector();
\r
722 while (st.hasMoreTokens())
\r
724 selectedSources.addElement(st.nextToken());
\r
727 Vector _localSources = jalview.bin.Cache.getLocalDasSources();
\r
728 if (_localSources!=null)
\r
730 if (localSources==null)
\r
732 localSources = new Hashtable();
\r
734 Enumeration sources = _localSources.elements();
\r
735 while (sources.hasMoreElements())
\r
737 Das1Source source = (Das1Source) sources.nextElement();
\r
738 localSources.put(source.getNickname(), source);
\r
743 public void reset_actionPerformed(ActionEvent e)
\r
745 registryURL.setText(DEFAULT_REGISTRY);
\r
749 * set the DAS source settings in the given jalview properties.
\r
750 * @param properties
\r
752 public void saveProperties(Properties properties)
\r
754 if (registryURL.getText() == null || registryURL.getText().length() < 1)
\r
756 properties.remove(jalview.bin.Cache.DAS_REGISTRY_URL);
\r
760 properties.setProperty(jalview.bin.Cache.DAS_REGISTRY_URL, registryURL.getText());
\r
763 StringBuffer sb = new StringBuffer();
\r
764 for (int r = 0; r < table.getModel().getRowCount(); r++)
\r
766 if (((Boolean) table.getValueAt(r, 1)).booleanValue())
\r
768 sb.append(table.getValueAt(r, 0) + "\t");
\r
772 properties.setProperty(jalview.bin.Cache.DAS_ACTIVE_SOURCE, sb.toString());
\r
774 if (localSources != null)
\r
776 sb = new StringBuffer();
\r
777 Enumeration en = localSources.keys();
\r
778 while (en.hasMoreElements())
\r
780 String token = en.nextElement().toString();
\r
781 sb.append(token + "|"
\r
782 +(((DasSource) localSources.get(token)).hasCapability("sequence") ? "sequence:" : "")
\r
783 + ((DasSource) localSources.get(token)).getUrl() + "\t");
\r
786 properties.setProperty(jalview.bin.Cache.DAS_LOCAL_SOURCE, sb.toString());
\r
791 class DASTableModel extends AbstractTableModel
\r
794 public DASTableModel(Object[][] data)
\r
799 private String[] columnNames = new String[]
\r
800 { "Nickname", "Use Source" };
\r
802 private Object[][] data;
\r
804 public int getColumnCount()
\r
806 return columnNames.length;
\r
809 public int getRowCount()
\r
811 return data.length;
\r
814 public String getColumnName(int col)
\r
816 return columnNames[col];
\r
819 public Object getValueAt(int row, int col)
\r
821 return data[row][col];
\r
825 * JTable uses this method to determine the default renderer/ editor for
\r
826 * each cell. If we didn't implement this method, then the last column would
\r
827 * contain text ("true"/"false"), rather than a check box.
\r
829 public Class getColumnClass(int c)
\r
831 return getValueAt(0, c).getClass();
\r
835 * Don't need to implement this method unless your table's editable.
\r
837 public boolean isCellEditable(int row, int col)
\r
839 // Note that the data/cell address is constant,
\r
840 // no matter where the cell appears onscreen.
\r
846 * Don't need to implement this method unless your table's data can change.
\r
848 public void setValueAt(Object value, int row, int col)
\r
850 data[row][col] = value;
\r
851 fireTableCellUpdated(row, col);
\r
853 String name = getValueAt(row, 0).toString();
\r
854 boolean selected = ((Boolean) value).booleanValue();
\r
856 if (selectedSources.contains(name) && !selected)
\r
858 selectedSources.remove(name);
\r
861 if (!selectedSources.contains(name) && selected)
\r
863 selectedSources.add(name);
\r
868 public void initDasSources()
\r
871 Thread thr = new Thread(new Runnable()
\r
875 // this actually initialises the das source list
\r
876 paintComponent(null); // yuk
\r
880 while (loadingDasSources
\r
881 || dasSources == null)
\r
886 } catch (Exception e)
\r
893 public Vector resolveSourceNicknames(Vector sources)
\r
896 Vector resolved = new Vector();
\r
897 if (sources != null)
\r
899 for (int i = 0; i < dasSources.length; i++)
\r
901 if (sources.contains(dasSources[i].getNickname()))
\r
903 if (!resolved.contains(dasSources[i]))
\r
905 resolved.addElement(dasSources[i]);
\r