2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 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
21 import jalview.jbgui.*;
\r
22 import javax.swing.table.AbstractTableModel;
\r
23 import javax.swing.event.*;
\r
24 import jalview.util.TableSorter;
\r
25 import java.awt.event.*;
\r
26 import javax.swing.*;
\r
30 import org.biojava.dasobert.dasregistry.DasCoordinateSystem;
\r
31 import org.biojava.dasobert.dasregistry.DasSource;
\r
32 import org.biojava.dasobert.dasregistry.Das1Source;
\r
33 import java.awt.BorderLayout;
\r
35 public class DasSourceBrowser extends GDasSourceBrowser
\r
36 implements Runnable, ListSelectionListener
\r
38 static DasSource[] dasSources = null;
\r
40 Hashtable localSources = null;
\r
42 Vector selectedSources;
\r
44 String DEFAULT_REGISTRY = "http://www.dasregistry.org/registry/das1/sources/";
\r
46 boolean loadingDasSources = false;
\r
49 public DasSourceBrowser()
\r
51 String registry = jalview.bin.Cache.getDefault("DAS_REGISTRY_URL",
\r
54 if(registry.equals("http://das.sanger.ac.uk/registry/das1/sources/"))
\r
56 jalview.bin.Cache.setProperty("DAS_REGISTRY_URL", DEFAULT_REGISTRY);
\r
57 registry = DEFAULT_REGISTRY;
\r
60 registryURL.setText( registry );
\r
62 setSelectedFromProperties();
\r
64 displayFullDetails(null);
\r
65 table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
\r
67 filter1.addListSelectionListener(this);
\r
68 filter2.addListSelectionListener(this);
\r
69 filter3.addListSelectionListener(this);
\r
71 //Ask to be notified of selection changes.
\r
72 ListSelectionModel rowSM = table.getSelectionModel();
\r
73 rowSM.addListSelectionListener(new ListSelectionListener()
\r
75 public void valueChanged(ListSelectionEvent e)
\r
77 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
\r
78 if (!lsm.isSelectionEmpty())
\r
80 int selectedRow = lsm.getMinSelectionIndex();
\r
81 displayFullDetails(table.getValueAt(selectedRow, 0).toString());
\r
86 table.addMouseListener(new MouseAdapter()
\r
88 public void mouseClicked(MouseEvent evt)
\r
90 if(evt.getClickCount()==2
\r
91 || SwingUtilities.isRightMouseButton(evt))
\r
92 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
142 public void refreshTableData(Object[][] data)
\r
144 TableSorter sorter = new TableSorter(new DASTableModel(data));
\r
145 sorter.setTableHeader(table.getTableHeader());
\r
146 table.setModel(sorter);
\r
149 void displayFullDetails(String nickName)
\r
152 StringBuffer text = new StringBuffer(
\r
153 "<HTML><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">");
\r
155 if (nickName == null)
\r
157 fullDetails.setText(text +
\r
158 "Select a DAS service from the table"
\r
159 + " to read a full description here.</font></html>");
\r
163 int dSize = dasSources.length;
\r
164 for (int i = 0; i < dSize; i++)
\r
166 if (!dasSources[i].getNickname().equals(nickName))
\r
169 DasSource ds = dasSources[i];
\r
171 text.append("<font color=\"#0000FF\">Id:</font> " + dasSources[i].getId() +
\r
173 text.append("<font color=\"#0000FF\">Nickname:</font> " +
\r
174 dasSources[i].getNickname() + "<br>");
\r
175 text.append("<font color=\"#0000FF\">URL:</font> " + dasSources[i].getUrl() +
\r
178 text.append("<font color=\"#0000FF\">Admin Email:</font> <a href=\"mailto:"
\r
179 +dasSources[i].getAdminemail()
\r
180 +"\">"+dasSources[i].getAdminemail()+"</a>" +
\r
184 text.append("<font color=\"#0000FF\">Registered at:</font> " + dasSources[i].getRegisterDate() +
\r
187 text.append("<font color=\"#0000FF\">Last successful test:</font> " + dasSources[i].getLeaseDate() +
\r
190 text.append("<font color=\"#0000FF\">Labels:</font> ");
\r
191 for(int s=0; s<dasSources[i].getLabels().length; s++)
\r
193 text.append( dasSources[i].getLabels()[s]);
\r
194 if(s<dasSources[i].getLabels().length-1)
\r
198 text.append("<br>");
\r
202 text.append("<font color=\"#0000FF\">Capabilities:</font> ");
\r
203 String[] scap = dasSources[i].getCapabilities();
\r
204 for (int j = 0; j < scap.length; j++)
\r
206 text.append(scap[j]);
\r
207 if (j < scap.length - 1)
\r
210 text.append("<br>");
\r
212 text.append("<font color=\"#0000FF\">Coordinates:</font> ");
\r
213 DasCoordinateSystem[] dcs = ds.getCoordinateSystem();
\r
214 for (int j = 0; j < dcs.length; j++)
\r
216 text.append("(" + dcs[j].getUniqueId() + ") "
\r
217 + dcs[j].getCategory() + ", " + dcs[j].getName());
\r
218 if (dcs[j].getNCBITaxId() != 0)
\r
219 text.append(", " + dcs[j].getNCBITaxId());
\r
220 if (dcs[j].getOrganismName().length() > 0)
\r
221 text.append(", " + dcs[j].getOrganismName());
\r
223 text.append("<br>");
\r
226 text.append("<font color=\"#0000FF\">Description:</font> " +
\r
227 dasSources[i].getDescription() + "<br>");
\r
230 if (dasSources[i].getHelperurl()!=null
\r
231 && dasSources[i].getHelperurl().length() > 0)
\r
233 text.append("<font color=\"#0000FF\"><a href=\"" +
\r
234 dasSources[i].getHelperurl()
\r
235 + "\">Go to site</a></font<br>");
\r
238 text.append("</font></html>");
\r
243 fullDetails.setText(text.toString());
\r
244 javax.swing.SwingUtilities.invokeLater(new Runnable()
\r
248 fullDetailsScrollpane.getVerticalScrollBar().setValue(0);
\r
256 loadingDasSources = true;
\r
258 addLocal.setVisible(false);
\r
259 refresh.setVisible(false);
\r
260 progressBar.setVisible(true);
\r
261 progressBar.setIndeterminate(true);
\r
263 dasSources = jalview.io.DasSequenceFeatureFetcher.getDASSources();
\r
265 appendLocalSources();
\r
269 loadingDasSources = false;
\r
273 public Vector getSelectedSources()
\r
275 Vector selected = new Vector();
\r
276 for (int r = 0; r < selectedSources.size(); r++)
\r
278 for (int i = 0; i < dasSources.length; i++)
\r
280 if (dasSources[i].getNickname().equals(
\r
281 selectedSources.elementAt(r)))
\r
283 selected.addElement(dasSources[i]);
\r
292 public DasSource[] getDASSource()
\r
294 if(dasSources==null)
\r
296 dasSources = jalview.io.DasSequenceFeatureFetcher.getDASSources();
\r
297 appendLocalSources();
\r
303 public void refresh_actionPerformed(ActionEvent e)
\r
305 saveProperties(jalview.bin.Cache.applicationProperties);
\r
307 Thread worker = new Thread(this);
\r
311 private void setCapabilities(DasSource[] sources)
\r
313 Vector authority = new Vector();
\r
314 Vector type = new Vector();
\r
315 Vector label = new Vector();
\r
317 authority.addElement("Any");
\r
318 type.addElement("Any");
\r
319 label.addElement("Any");
\r
321 for (int i = 0; i < sources.length; i++)
\r
323 DasSource ds = sources[i];
\r
325 DasCoordinateSystem[] dcs = ds.getCoordinateSystem();
\r
327 for (int j = 0; j < dcs.length; j++)
\r
329 if (!type.contains(dcs[j].getCategory()))
\r
330 type.addElement(dcs[j].getCategory());
\r
332 if (!authority.contains(dcs[j].getName()))
\r
333 authority.addElement(dcs[j].getName());
\r
336 String[] slabels = ds.getLabels();
\r
337 for (int s = 0; s < slabels.length; s++)
\r
339 if (!label.contains(slabels[s]))
\r
341 label.addElement(slabels[s]);
\r
347 filter1.setListData(authority);
\r
348 filter2.setListData(type);
\r
349 filter3.setListData(label);
\r
351 javax.swing.SwingUtilities.invokeLater(new Runnable()
\r
355 filter1.setSelectedIndex(0);
\r
356 filter2.setSelectedIndex(0);
\r
357 filter3.setSelectedIndex(0);
\r
362 public void amendLocal(boolean newSource)
\r
364 String url = "http://localhost:8080/", nickname = "";
\r
368 int selectedRow = table.getSelectionModel().getMinSelectionIndex();
\r
369 nickname = table.getValueAt(selectedRow, 0).toString();
\r
370 url = ((DasSource)localSources.get(nickname)).getUrl();
\r
373 JTextField nametf = new JTextField(nickname, 40);
\r
374 JTextField urltf = new JTextField(url, 40);
\r
376 JPanel panel = new JPanel(new BorderLayout());
\r
377 JPanel pane12 = new JPanel(new BorderLayout());
\r
378 pane12.add(new JLabel("Nickname: "), BorderLayout.CENTER);
\r
379 pane12.add(nametf, BorderLayout.EAST);
\r
380 panel.add(pane12, BorderLayout.NORTH);
\r
381 pane12 = new JPanel(new BorderLayout());
\r
382 pane12.add(new JLabel("URL: "), BorderLayout.CENTER);
\r
383 pane12.add(urltf, BorderLayout.EAST);
\r
384 panel.add(pane12, BorderLayout.SOUTH);
\r
387 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
\r
388 panel, "Enter Nickname & URL of Local DAS Source",
\r
389 JOptionPane.OK_CANCEL_OPTION);
\r
391 if (reply != JOptionPane.OK_OPTION )
\r
396 if(!urltf.getText().endsWith("/"))
\r
397 urltf.setText(urltf.getText()+"/");
\r
399 Das1Source local = new Das1Source();
\r
401 local.setUrl(urltf.getText());
\r
402 local.setNickname(nametf.getText());
\r
405 if(localSources==null)
\r
406 localSources = new Hashtable();
\r
408 localSources.put(local.getNickname(), local);
\r
410 if(!newSource && !nickname.equals(nametf.getText()))
\r
412 localSources.remove(nickname);
\r
415 int size = dasSources.length;
\r
416 int adjust = newSource ? 1 : 0;
\r
418 Object[][] data = new Object[size+adjust][2];
\r
419 for (int i = 0; i < size; i++)
\r
421 if(!newSource && dasSources[i].getNickname().equals(nickname))
\r
423 ((DasSource)dasSources[i]).setNickname(local.getNickname());
\r
424 ((DasSource)dasSources[i]).setUrl(local.getUrl());
\r
425 data[i][0] = local.getNickname();
\r
426 data[i][1] = new Boolean(true);
\r
430 data[i][0] = dasSources[i].getNickname();
\r
431 data[i][1] = new Boolean(selectedSources.contains(dasSources[i].
\r
438 data[size][0] = local.getNickname();
\r
439 data[size][1] = new Boolean(true);
\r
440 selectedSources.add(local.getNickname());
\r
443 DasSource [] tmp = new DasSource[size+adjust];
\r
445 System.arraycopy(dasSources, 0, tmp, 0, size);
\r
452 refreshTableData(data);
\r
454 SwingUtilities.invokeLater(new Runnable()
\r
458 scrollPane.getVerticalScrollBar().setValue(
\r
459 scrollPane.getVerticalScrollBar().getMaximum()
\r
464 displayFullDetails(local.getNickname());
\r
467 public void editRemoveLocalSource(MouseEvent evt)
\r
469 int selectedRow = table.getSelectionModel().getMinSelectionIndex();
\r
470 if(selectedRow==-1)
\r
473 String nickname = table.getValueAt(selectedRow, 0).toString();
\r
475 if (!localSources.containsKey(nickname))
\r
477 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
478 "You can only edit or remove local DAS Sources!",
\r
479 "Public DAS source - not editable",
\r
480 JOptionPane.WARNING_MESSAGE);
\r
485 Object[] options = {"Edit", "Remove", "Cancel"};
\r
486 int choice = JOptionPane.showInternalOptionDialog(Desktop.desktop,
\r
487 "Do you want to edit or remove "+nickname+"?",
\r
488 "Edit / Remove Local DAS Source",
\r
489 JOptionPane.YES_NO_CANCEL_OPTION,
\r
490 JOptionPane.QUESTION_MESSAGE,
\r
497 case 0: amendLocal(false); break;
\r
499 localSources.remove(nickname);
\r
500 selectedSources.remove(nickname);
\r
501 Object[][] data = new Object[dasSources.length-1][2];
\r
502 DasSource [] tmp = new DasSource[dasSources.length-1];
\r
504 for (int i = 0; i < dasSources.length; i++)
\r
506 if (dasSources[i].getNickname().equals(nickname))
\r
512 tmp[index] = dasSources[i];
\r
513 data[index][0] = dasSources[i].getNickname();
\r
514 data[index][1] = new Boolean(selectedSources.contains(dasSources[i].
\r
520 refreshTableData(data);
\r
521 SwingUtilities.invokeLater(new Runnable()
\r
525 scrollPane.getVerticalScrollBar().setValue(
\r
526 scrollPane.getVerticalScrollBar().getMaximum()
\r
535 void appendLocalSources()
\r
537 if(localSources==null)
\r
540 int size = dasSources!=null ? dasSources.length : 0;
\r
541 int lsize = localSources.size();
\r
543 Object[][] data = new Object[size+lsize][2];
\r
544 for (int i = 0; i < size; i++)
\r
546 data[i][0] = dasSources[i].getNickname();
\r
547 data[i][1] = new Boolean(selectedSources.contains(dasSources[i].
\r
551 DasSource [] tmp = new DasSource[size+lsize];
\r
552 if(dasSources!=null)
\r
553 System.arraycopy(dasSources, 0, tmp, 0, size);
\r
555 Enumeration en = localSources.keys();
\r
557 while(en.hasMoreElements())
\r
559 String key = en.nextElement().toString();
\r
560 data[index][0] = key;
\r
561 data[index][1] = new Boolean(false);
\r
562 tmp[index] = new Das1Source();
\r
563 tmp[index].setNickname(key);
\r
564 tmp[index].setUrl( ((DasSource)localSources.get(key)).getUrl() );
\r
571 refreshTableData(data);
\r
574 public void valueChanged(ListSelectionEvent evt)
\r
576 //Called when the MainTable selection changes
\r
577 if (evt.getValueIsAdjusting() )
\r
583 displayFullDetails(null);
\r
585 // Filter the displayed data sources
\r
586 int dSize = dasSources.length;
\r
589 ArrayList names = new ArrayList();
\r
590 ArrayList selected = new ArrayList();
\r
593 //The features filter is not visible, but we must still
\r
594 //filter the das source list here.
\r
595 //July 2006 - only 6 sources fo not serve features
\r
596 Object [] dummyFeatureList = new Object[]{"features"};
\r
598 for (int i = 0; i < dSize; i++)
\r
600 ds = dasSources[i];
\r
601 DasCoordinateSystem[] dcs = ds.getCoordinateSystem();
\r
603 if (dcs.length == 0 && ds.getCapabilities().length == 0
\r
604 && filter1.getSelectedIndex() == 0
\r
605 && filter2.getSelectedIndex() == 0
\r
606 && filter3.getSelectedIndex() == 0)
\r
608 //THIS IS A FIX FOR LOCAL SOURCES WHICH DO NOT
\r
609 //HAVE COORDINATE SYSTEMS, INFO WHICH AT PRESENT
\r
610 //IS ADDED FROM THE REGISTRY
\r
611 names.add(ds.getNickname());
\r
612 selected.add(new Boolean(
\r
613 selectedSources.contains(ds.getNickname())));
\r
618 if (!selectedInList(dummyFeatureList, ds.getCapabilities())
\r
619 || !selectedInList(filter3.getSelectedValues(),
\r
625 for (int j = 0; j < dcs.length; j++)
\r
627 if ( selectedInList(filter1.getSelectedValues(),
\r
629 {dcs[j].getName()})
\r
630 && selectedInList(filter2.getSelectedValues(),
\r
632 {dcs[j].getCategory()}))
\r
634 names.add(ds.getNickname());
\r
635 selected.add(new Boolean(
\r
636 selectedSources.contains(ds.getNickname())));
\r
642 dSize = names.size();
\r
643 Object[][] data = new Object[dSize][2];
\r
644 for (int d = 0; d < dSize; d++)
\r
646 data[d][0] = names.get(d);
\r
647 data[d][1] = selected.get(d);
\r
650 refreshTableData(data);
\r
653 boolean selectedInList(Object [] selection, String[] items)
\r
655 for (int i = 0; i < selection.length; i++)
\r
657 if (selection[i].equals("Any") )
\r
660 for (int j = 0; j < items.length; j++)
\r
662 if (selection[i].equals(items[j]))
\r
670 void setSelectedFromProperties()
\r
672 String active = jalview.bin.Cache.getDefault("DAS_ACTIVE_SOURCE", "uniprot");
\r
673 StringTokenizer st = new StringTokenizer(active, "\t");
\r
674 selectedSources = new Vector();
\r
675 while(st.hasMoreTokens())
\r
677 selectedSources.addElement(st.nextToken());
\r
680 String local = jalview.bin.Cache.getProperty("DAS_LOCAL_SOURCE");
\r
683 if(localSources == null)
\r
684 localSources = new Hashtable();
\r
686 st = new StringTokenizer(local, "\t");
\r
687 while(st.hasMoreTokens())
\r
689 String token = st.nextToken();
\r
690 int bar = token.indexOf("|");
\r
691 Das1Source source = new Das1Source();
\r
693 source.setUrl(token.substring(bar + 1));
\r
694 source.setNickname(token.substring(0, bar));
\r
696 localSources.put(source.getNickname(), source);
\r
701 public void reset_actionPerformed(ActionEvent e)
\r
703 registryURL.setText(DEFAULT_REGISTRY);
\r
706 public void saveProperties(Properties properties)
\r
708 if (registryURL.getText() == null || registryURL.getText().length() < 1)
\r
709 properties.remove("DAS_REGISTRY_URL");
\r
711 properties.setProperty("DAS_REGISTRY_URL", registryURL.getText());
\r
713 StringBuffer sb = new StringBuffer();
\r
714 for(int r=0; r<table.getModel().getRowCount(); r++)
\r
716 if( ((Boolean)table.getValueAt(r,1)).booleanValue())
\r
718 sb.append(table.getValueAt(r,0)+"\t");
\r
722 properties.setProperty("DAS_ACTIVE_SOURCE", sb.toString() );
\r
724 if(localSources!=null)
\r
726 sb = new StringBuffer();
\r
727 Enumeration en = localSources.keys();
\r
728 while(en.hasMoreElements())
\r
730 String token = en.nextElement().toString();
\r
731 sb.append(token+"|"
\r
732 + ((DasSource)localSources.get(token)).getUrl()
\r
736 properties.setProperty("DAS_LOCAL_SOURCE", sb.toString());
\r
741 class DASTableModel
\r
742 extends AbstractTableModel
\r
745 public DASTableModel(Object[][] data)
\r
750 private String[] columnNames = new String[] {"Nickname", "Use Source"};
\r
752 private Object[][] data;
\r
754 public int getColumnCount()
\r
756 return columnNames.length;
\r
759 public int getRowCount()
\r
761 return data.length;
\r
764 public String getColumnName(int col)
\r
766 return columnNames[col];
\r
769 public Object getValueAt(int row, int col)
\r
771 return data[row][col];
\r
775 * JTable uses this method to determine the default renderer/
\r
776 * editor for each cell. If we didn't implement this method,
\r
777 * then the last column would contain text ("true"/"false"),
\r
778 * rather than a check box.
\r
780 public Class getColumnClass(int c)
\r
782 return getValueAt(0, c).getClass();
\r
786 * Don't need to implement this method unless your table's
\r
789 public boolean isCellEditable(int row, int col)
\r
791 //Note that the data/cell address is constant,
\r
792 //no matter where the cell appears onscreen.
\r
798 * Don't need to implement this method unless your table's
\r
801 public void setValueAt(Object value, int row, int col)
\r
803 data[row][col] = value;
\r
804 fireTableCellUpdated(row, col);
\r
806 String name = getValueAt(row,0).toString();
\r
807 boolean selected = ((Boolean)value).booleanValue();
\r
809 if(selectedSources.contains(name) && !selected)
\r
810 selectedSources.remove(name);
\r
812 if(!selectedSources.contains(name) && selected)
\r
813 selectedSources.add(name);
\r