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
45 boolean loadingDasSources = false;
\r
47 public DasSourceBrowser()
\r
49 String registry = jalview.bin.Cache.getDefault("DAS_REGISTRY_URL",
\r
52 if (registry.indexOf("/registry/das1/sources/") > -1)
\r
54 jalview.bin.Cache.setProperty("DAS_REGISTRY_URL", DEFAULT_REGISTRY);
\r
55 registry = DEFAULT_REGISTRY;
\r
58 registryURL.setText(registry);
\r
60 setSelectedFromProperties();
\r
62 displayFullDetails(null);
\r
63 table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
\r
65 filter1.addListSelectionListener(this);
\r
66 filter2.addListSelectionListener(this);
\r
67 filter3.addListSelectionListener(this);
\r
69 //Ask to be notified of selection changes.
\r
70 ListSelectionModel rowSM = table.getSelectionModel();
\r
71 rowSM.addListSelectionListener(new ListSelectionListener()
\r
73 public void valueChanged(ListSelectionEvent e)
\r
75 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
\r
76 if (!lsm.isSelectionEmpty())
\r
78 int selectedRow = lsm.getMinSelectionIndex();
\r
79 displayFullDetails(table.getValueAt(selectedRow, 0).toString());
\r
84 table.addMouseListener(new MouseAdapter()
\r
86 public void mouseClicked(MouseEvent evt)
\r
88 if (evt.getClickCount() == 2
\r
89 || SwingUtilities.isRightMouseButton(evt))
\r
91 editRemoveLocalSource(evt);
\r
96 if (dasSources != null)
\r
102 public void paintComponent(java.awt.Graphics g)
\r
104 if (dasSources == null && !loadingDasSources)
\r
106 Thread worker = new Thread(this);
\r
113 int dSize = dasSources.length;
\r
114 Object[][] data = new Object[dSize][2];
\r
115 for (int i = 0; i < dSize; i++)
\r
117 data[i][0] = dasSources[i].getNickname();
\r
118 data[i][1] = new Boolean(selectedSources.contains(dasSources[i].
\r
122 refreshTableData(data);
\r
123 setCapabilities(dasSources);
\r
125 javax.swing.SwingUtilities.invokeLater(new Runnable()
\r
129 TableSorter sorter = (TableSorter) table.getModel();
\r
130 sorter.setSortingStatus(1, TableSorter.DESCENDING);
\r
131 sorter.setSortingStatus(1, TableSorter.NOT_SORTED);
\r
135 progressBar.setIndeterminate(false);
\r
136 progressBar.setVisible(false);
\r
137 addLocal.setVisible(true);
\r
138 refresh.setVisible(true);
\r
141 public void refreshTableData(Object[][] data)
\r
143 TableSorter sorter = new TableSorter(new DASTableModel(data));
\r
144 sorter.setTableHeader(table.getTableHeader());
\r
145 table.setModel(sorter);
\r
148 void displayFullDetails(String nickName)
\r
151 StringBuffer text = new StringBuffer(
\r
152 "<HTML><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">");
\r
154 if (nickName == null)
\r
156 fullDetails.setText(text +
\r
157 "Select a DAS service from the table"
\r
158 + " to read a full description here.</font></html>");
\r
162 int dSize = dasSources.length;
\r
163 for (int i = 0; i < dSize; i++)
\r
165 if (!dasSources[i].getNickname().equals(nickName))
\r
170 DasSource ds = dasSources[i];
\r
172 text.append("<font color=\"#0000FF\">Id:</font> " + dasSources[i].getId() +
\r
174 text.append("<font color=\"#0000FF\">Nickname:</font> " +
\r
175 dasSources[i].getNickname() + "<br>");
\r
176 text.append("<font color=\"#0000FF\">URL:</font> " + dasSources[i].getUrl() +
\r
180 "<font color=\"#0000FF\">Admin Email:</font> <a href=\"mailto:"
\r
181 + dasSources[i].getAdminemail()
\r
182 + "\">" + dasSources[i].getAdminemail() + "</a>" +
\r
185 text.append("<font color=\"#0000FF\">Registered at:</font> " +
\r
186 dasSources[i].getRegisterDate() +
\r
189 text.append("<font color=\"#0000FF\">Last successful test:</font> " +
\r
190 dasSources[i].getLeaseDate() +
\r
193 text.append("<font color=\"#0000FF\">Labels:</font> ");
\r
194 for (int s = 0; s < dasSources[i].getLabels().length; s++)
\r
196 text.append(dasSources[i].getLabels()[s]);
\r
197 if (s < dasSources[i].getLabels().length - 1)
\r
203 text.append("<br>");
\r
205 text.append("<font color=\"#0000FF\">Capabilities:</font> ");
\r
206 String[] scap = dasSources[i].getCapabilities();
\r
207 for (int j = 0; j < scap.length; j++)
\r
209 text.append(scap[j]);
\r
210 if (j < scap.length - 1)
\r
215 text.append("<br>");
\r
217 text.append("<font color=\"#0000FF\">Coordinates:</font> ");
\r
218 DasCoordinateSystem[] dcs = ds.getCoordinateSystem();
\r
219 for (int j = 0; j < dcs.length; j++)
\r
221 text.append("(" + dcs[j].getUniqueId() + ") "
\r
222 + dcs[j].getCategory() + ", " + dcs[j].getName());
\r
223 if (dcs[j].getNCBITaxId() != 0)
\r
225 text.append(", " + dcs[j].getNCBITaxId());
\r
227 if (dcs[j].getOrganismName().length() > 0)
\r
229 text.append(", " + dcs[j].getOrganismName());
\r
232 text.append("<br>");
\r
235 text.append("<font color=\"#0000FF\">Description:</font> " +
\r
236 dasSources[i].getDescription() + "<br>");
\r
238 if (dasSources[i].getHelperurl() != null
\r
239 && dasSources[i].getHelperurl().length() > 0)
\r
241 text.append("<font color=\"#0000FF\"><a href=\"" +
\r
242 dasSources[i].getHelperurl()
\r
243 + "\">Go to site</a></font<br>");
\r
246 text.append("</font></html>");
\r
251 fullDetails.setText(text.toString());
\r
252 javax.swing.SwingUtilities.invokeLater(new Runnable()
\r
256 fullDetailsScrollpane.getVerticalScrollBar().setValue(0);
\r
263 loadingDasSources = true;
\r
265 addLocal.setVisible(false);
\r
266 refresh.setVisible(false);
\r
267 progressBar.setVisible(true);
\r
268 progressBar.setIndeterminate(true);
\r
270 dasSources = jalview.io.DasSequenceFeatureFetcher.getDASSources();
\r
272 appendLocalSources();
\r
276 loadingDasSources = false;
\r
280 public Vector getSelectedSources()
\r
282 Vector selected = new Vector();
\r
283 for (int r = 0; r < selectedSources.size(); r++)
\r
285 for (int i = 0; i < dasSources.length; i++)
\r
287 if (dasSources[i].getNickname().equals(
\r
288 selectedSources.elementAt(r)))
\r
290 selected.addElement(dasSources[i]);
\r
299 public DasSource[] getDASSource()
\r
301 if (dasSources == null)
\r
303 dasSources = jalview.io.DasSequenceFeatureFetcher.getDASSources();
\r
304 appendLocalSources();
\r
310 public void refresh_actionPerformed(ActionEvent e)
\r
312 saveProperties(jalview.bin.Cache.applicationProperties);
\r
314 Thread worker = new Thread(this);
\r
318 private void setCapabilities(DasSource[] sources)
\r
320 Vector authority = new Vector();
\r
321 Vector type = new Vector();
\r
322 Vector label = new Vector();
\r
324 authority.addElement("Any");
\r
325 type.addElement("Any");
\r
326 label.addElement("Any");
\r
328 for (int i = 0; i < sources.length; i++)
\r
330 DasSource ds = sources[i];
\r
332 DasCoordinateSystem[] dcs = ds.getCoordinateSystem();
\r
334 for (int j = 0; j < dcs.length; j++)
\r
336 if (!type.contains(dcs[j].getCategory()))
\r
338 type.addElement(dcs[j].getCategory());
\r
341 if (!authority.contains(dcs[j].getName()))
\r
343 authority.addElement(dcs[j].getName());
\r
347 String[] slabels = ds.getLabels();
\r
348 for (int s = 0; s < slabels.length; s++)
\r
350 if (!label.contains(slabels[s]))
\r
352 label.addElement(slabels[s]);
\r
358 filter1.setListData(authority);
\r
359 filter2.setListData(type);
\r
360 filter3.setListData(label);
\r
362 javax.swing.SwingUtilities.invokeLater(new Runnable()
\r
366 filter1.setSelectedIndex(0);
\r
367 filter2.setSelectedIndex(0);
\r
368 filter3.setSelectedIndex(0);
\r
373 public void amendLocal(boolean newSource)
\r
375 String url = "http://localhost:8080/", nickname = "";
\r
379 int selectedRow = table.getSelectionModel().getMinSelectionIndex();
\r
380 nickname = table.getValueAt(selectedRow, 0).toString();
\r
381 url = ( (DasSource) localSources.get(nickname)).getUrl();
\r
384 JTextField nametf = new JTextField(nickname, 40);
\r
385 JTextField urltf = new JTextField(url, 40);
\r
387 JPanel panel = new JPanel(new BorderLayout());
\r
388 JPanel pane12 = new JPanel(new BorderLayout());
\r
389 pane12.add(new JLabel("Nickname: "), BorderLayout.CENTER);
\r
390 pane12.add(nametf, BorderLayout.EAST);
\r
391 panel.add(pane12, BorderLayout.NORTH);
\r
392 pane12 = new JPanel(new BorderLayout());
\r
393 pane12.add(new JLabel("URL: "), BorderLayout.CENTER);
\r
394 pane12.add(urltf, BorderLayout.EAST);
\r
395 panel.add(pane12, BorderLayout.SOUTH);
\r
397 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
\r
398 panel, "Enter Nickname & URL of Local DAS Source",
\r
399 JOptionPane.OK_CANCEL_OPTION);
\r
401 if (reply != JOptionPane.OK_OPTION)
\r
406 if (!urltf.getText().endsWith("/"))
\r
408 urltf.setText(urltf.getText() + "/");
\r
411 Das1Source local = new Das1Source();
\r
413 local.setUrl(urltf.getText());
\r
414 local.setNickname(nametf.getText());
\r
416 if (localSources == null)
\r
418 localSources = new Hashtable();
\r
421 localSources.put(local.getNickname(), local);
\r
423 if (!newSource && !nickname.equals(nametf.getText()))
\r
425 localSources.remove(nickname);
\r
428 int size = dasSources.length;
\r
429 int adjust = newSource ? 1 : 0;
\r
431 Object[][] data = new Object[size + adjust][2];
\r
432 for (int i = 0; i < size; i++)
\r
434 if (!newSource && dasSources[i].getNickname().equals(nickname))
\r
436 ( (DasSource) dasSources[i]).setNickname(local.getNickname());
\r
437 ( (DasSource) dasSources[i]).setUrl(local.getUrl());
\r
438 data[i][0] = local.getNickname();
\r
439 data[i][1] = new Boolean(true);
\r
443 data[i][0] = dasSources[i].getNickname();
\r
444 data[i][1] = new Boolean(selectedSources.contains(dasSources[i].
\r
451 data[size][0] = local.getNickname();
\r
452 data[size][1] = new Boolean(true);
\r
453 selectedSources.add(local.getNickname());
\r
456 DasSource[] tmp = new DasSource[size + adjust];
\r
458 System.arraycopy(dasSources, 0, tmp, 0, size);
\r
467 refreshTableData(data);
\r
469 SwingUtilities.invokeLater(new Runnable()
\r
473 scrollPane.getVerticalScrollBar().setValue(
\r
474 scrollPane.getVerticalScrollBar().getMaximum()
\r
479 displayFullDetails(local.getNickname());
\r
482 public void editRemoveLocalSource(MouseEvent evt)
\r
484 int selectedRow = table.getSelectionModel().getMinSelectionIndex();
\r
485 if (selectedRow == -1)
\r
490 String nickname = table.getValueAt(selectedRow, 0).toString();
\r
492 if (!localSources.containsKey(nickname))
\r
494 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
495 "You can only edit or remove local DAS Sources!",
\r
496 "Public DAS source - not editable",
\r
497 JOptionPane.WARNING_MESSAGE);
\r
503 "Edit", "Remove", "Cancel"};
\r
504 int choice = JOptionPane.showInternalOptionDialog(Desktop.desktop,
\r
505 "Do you want to edit or remove " + nickname + "?",
\r
506 "Edit / Remove Local DAS Source",
\r
507 JOptionPane.YES_NO_CANCEL_OPTION,
\r
508 JOptionPane.QUESTION_MESSAGE,
\r
519 localSources.remove(nickname);
\r
520 selectedSources.remove(nickname);
\r
521 Object[][] data = new Object[dasSources.length - 1][2];
\r
522 DasSource[] tmp = new DasSource[dasSources.length - 1];
\r
524 for (int i = 0; i < dasSources.length; i++)
\r
526 if (dasSources[i].getNickname().equals(nickname))
\r
532 tmp[index] = dasSources[i];
\r
533 data[index][0] = dasSources[i].getNickname();
\r
534 data[index][1] = new Boolean(selectedSources.contains(dasSources[i].
\r
540 refreshTableData(data);
\r
541 SwingUtilities.invokeLater(new Runnable()
\r
545 scrollPane.getVerticalScrollBar().setValue(
\r
546 scrollPane.getVerticalScrollBar().getMaximum()
\r
555 void appendLocalSources()
\r
557 if (localSources == null)
\r
562 int size = dasSources != null ? dasSources.length : 0;
\r
563 int lsize = localSources.size();
\r
565 Object[][] data = new Object[size + lsize][2];
\r
566 for (int i = 0; i < size; i++)
\r
568 data[i][0] = dasSources[i].getNickname();
\r
569 data[i][1] = new Boolean(selectedSources.contains(dasSources[i].
\r
573 DasSource[] tmp = new DasSource[size + lsize];
\r
574 if (dasSources != null)
\r
576 System.arraycopy(dasSources, 0, tmp, 0, size);
\r
579 Enumeration en = localSources.keys();
\r
581 while (en.hasMoreElements())
\r
583 String key = en.nextElement().toString();
\r
584 data[index][0] = key;
\r
585 data[index][1] = new Boolean(false);
\r
586 tmp[index] = new Das1Source();
\r
587 tmp[index].setNickname(key);
\r
588 tmp[index].setUrl( ( (DasSource) localSources.get(key)).getUrl());
\r
595 refreshTableData(data);
\r
598 public void valueChanged(ListSelectionEvent evt)
\r
600 //Called when the MainTable selection changes
\r
601 if (evt.getValueIsAdjusting())
\r
606 displayFullDetails(null);
\r
608 // Filter the displayed data sources
\r
609 int dSize = dasSources.length;
\r
611 ArrayList names = new ArrayList();
\r
612 ArrayList selected = new ArrayList();
\r
615 //The features filter is not visible, but we must still
\r
616 //filter the das source list here.
\r
617 //July 2006 - only 6 sources fo not serve features
\r
618 Object[] dummyFeatureList = new Object[]
\r
622 for (int i = 0; i < dSize; i++)
\r
624 ds = dasSources[i];
\r
625 DasCoordinateSystem[] dcs = ds.getCoordinateSystem();
\r
627 if (dcs.length == 0 && ds.getCapabilities().length == 0
\r
628 && filter1.getSelectedIndex() == 0
\r
629 && filter2.getSelectedIndex() == 0
\r
630 && filter3.getSelectedIndex() == 0)
\r
632 //THIS IS A FIX FOR LOCAL SOURCES WHICH DO NOT
\r
633 //HAVE COORDINATE SYSTEMS, INFO WHICH AT PRESENT
\r
634 //IS ADDED FROM THE REGISTRY
\r
635 names.add(ds.getNickname());
\r
636 selected.add(new Boolean(
\r
637 selectedSources.contains(ds.getNickname())));
\r
641 if (!selectedInList(dummyFeatureList, ds.getCapabilities())
\r
642 || !selectedInList(filter3.getSelectedValues(),
\r
648 for (int j = 0; j < dcs.length; j++)
\r
650 if (selectedInList(filter1.getSelectedValues(),
\r
652 {dcs[j].getName()})
\r
653 && selectedInList(filter2.getSelectedValues(),
\r
655 {dcs[j].getCategory()}))
\r
657 names.add(ds.getNickname());
\r
658 selected.add(new Boolean(
\r
659 selectedSources.contains(ds.getNickname())));
\r
665 dSize = names.size();
\r
666 Object[][] data = new Object[dSize][2];
\r
667 for (int d = 0; d < dSize; d++)
\r
669 data[d][0] = names.get(d);
\r
670 data[d][1] = selected.get(d);
\r
673 refreshTableData(data);
\r
676 boolean selectedInList(Object[] selection, String[] items)
\r
678 for (int i = 0; i < selection.length; i++)
\r
680 if (selection[i].equals("Any"))
\r
685 for (int j = 0; j < items.length; j++)
\r
687 if (selection[i].equals(items[j]))
\r
697 void setSelectedFromProperties()
\r
699 String active = jalview.bin.Cache.getDefault("DAS_ACTIVE_SOURCE", "uniprot");
\r
700 StringTokenizer st = new StringTokenizer(active, "\t");
\r
701 selectedSources = new Vector();
\r
702 while (st.hasMoreTokens())
\r
704 selectedSources.addElement(st.nextToken());
\r
707 String local = jalview.bin.Cache.getProperty("DAS_LOCAL_SOURCE");
\r
710 if (localSources == null)
\r
712 localSources = new Hashtable();
\r
715 st = new StringTokenizer(local, "\t");
\r
716 while (st.hasMoreTokens())
\r
718 String token = st.nextToken();
\r
719 int bar = token.indexOf("|");
\r
720 Das1Source source = new Das1Source();
\r
722 source.setUrl(token.substring(bar + 1));
\r
723 source.setNickname(token.substring(0, bar));
\r
725 localSources.put(source.getNickname(), source);
\r
730 public void reset_actionPerformed(ActionEvent e)
\r
732 registryURL.setText(DEFAULT_REGISTRY);
\r
735 public void saveProperties(Properties properties)
\r
737 if (registryURL.getText() == null || registryURL.getText().length() < 1)
\r
739 properties.remove("DAS_REGISTRY_URL");
\r
743 properties.setProperty("DAS_REGISTRY_URL", registryURL.getText());
\r
746 StringBuffer sb = new StringBuffer();
\r
747 for (int r = 0; r < table.getModel().getRowCount(); r++)
\r
749 if ( ( (Boolean) table.getValueAt(r, 1)).booleanValue())
\r
751 sb.append(table.getValueAt(r, 0) + "\t");
\r
755 properties.setProperty("DAS_ACTIVE_SOURCE", sb.toString());
\r
757 if (localSources != null)
\r
759 sb = new StringBuffer();
\r
760 Enumeration en = localSources.keys();
\r
761 while (en.hasMoreElements())
\r
763 String token = en.nextElement().toString();
\r
764 sb.append(token + "|"
\r
765 + ( (DasSource) localSources.get(token)).getUrl()
\r
769 properties.setProperty("DAS_LOCAL_SOURCE", sb.toString());
\r
774 class DASTableModel
\r
775 extends AbstractTableModel
\r
778 public DASTableModel(Object[][] data)
\r
783 private String[] columnNames = new String[]
\r
785 "Nickname", "Use Source"};
\r
787 private Object[][] data;
\r
789 public int getColumnCount()
\r
791 return columnNames.length;
\r
794 public int getRowCount()
\r
796 return data.length;
\r
799 public String getColumnName(int col)
\r
801 return columnNames[col];
\r
804 public Object getValueAt(int row, int col)
\r
806 return data[row][col];
\r
810 * JTable uses this method to determine the default renderer/
\r
811 * editor for each cell. If we didn't implement this method,
\r
812 * then the last column would contain text ("true"/"false"),
\r
813 * rather than a check box.
\r
815 public Class getColumnClass(int c)
\r
817 return getValueAt(0, c).getClass();
\r
821 * Don't need to implement this method unless your table's
\r
824 public boolean isCellEditable(int row, int col)
\r
826 //Note that the data/cell address is constant,
\r
827 //no matter where the cell appears onscreen.
\r
833 * Don't need to implement this method unless your table's
\r
836 public void setValueAt(Object value, int row, int col)
\r
838 data[row][col] = value;
\r
839 fireTableCellUpdated(row, col);
\r
841 String name = getValueAt(row, 0).toString();
\r
842 boolean selected = ( (Boolean) value).booleanValue();
\r
844 if (selectedSources.contains(name) && !selected)
\r
846 selectedSources.remove(name);
\r
849 if (!selectedSources.contains(name) && selected)
\r
851 selectedSources.add(name);
\r