2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 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
45 public DasSourceBrowser()
\r
47 registryURL.setText(jalview.bin.Cache.getDefault("DAS_REGISTRY_URL",
\r
48 "http://das.sanger.ac.uk/registry/das1/sources/") );
\r
50 setSelectedFromProperties();
\r
52 displayFullDetails(null);
\r
53 table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
\r
55 filter1.addListSelectionListener(this);
\r
56 filter2.addListSelectionListener(this);
\r
57 filter3.addListSelectionListener(this);
\r
59 //Ask to be notified of selection changes.
\r
60 ListSelectionModel rowSM = table.getSelectionModel();
\r
61 rowSM.addListSelectionListener(new ListSelectionListener()
\r
63 public void valueChanged(ListSelectionEvent e)
\r
65 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
\r
66 if (!lsm.isSelectionEmpty())
\r
68 int selectedRow = lsm.getMinSelectionIndex();
\r
69 displayFullDetails(table.getValueAt(selectedRow, 0).toString());
\r
74 table.addMouseListener(new MouseAdapter()
\r
76 public void mouseClicked(MouseEvent evt)
\r
78 if(evt.getClickCount()==2
\r
79 || SwingUtilities.isRightMouseButton(evt))
\r
80 editRemoveLocalSource(evt);
\r
84 if(dasSources==null)
\r
86 Thread worker = new Thread(this);
\r
97 int dSize = dasSources.length;
\r
98 Object[][] data = new Object[dSize][2];
\r
99 for (int i = 0; i < dSize; i++)
\r
101 data[i][0] = dasSources[i].getNickname();
\r
102 data[i][1] = new Boolean(selectedSources.contains(dasSources[i].
\r
106 refreshTableData(data);
\r
107 setCapabilities(dasSources);
\r
109 javax.swing.SwingUtilities.invokeLater(new Runnable()
\r
113 TableSorter sorter = (TableSorter)table.getModel();
\r
114 sorter.setSortingStatus(1, TableSorter.DESCENDING);
\r
115 sorter.setSortingStatus(1, TableSorter.NOT_SORTED);
\r
119 progressBar.setIndeterminate(false);
\r
120 progressBar.setVisible(false);
\r
121 addLocal.setVisible(true);
\r
122 refresh.setVisible(true);
\r
126 public void refreshTableData(Object[][] data)
\r
128 TableSorter sorter = new TableSorter(new DASTableModel(data));
\r
129 sorter.setTableHeader(table.getTableHeader());
\r
130 table.setModel(sorter);
\r
133 void displayFullDetails(String nickName)
\r
136 StringBuffer text = new StringBuffer(
\r
137 "<HTML><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">");
\r
139 if (nickName == null)
\r
141 fullDetails.setText(text +
\r
142 "Select a DAS service from the table"
\r
143 + " to read a full description here.</font></html>");
\r
147 int dSize = dasSources.length;
\r
148 for (int i = 0; i < dSize; i++)
\r
150 if (!dasSources[i].getNickname().equals(nickName))
\r
153 DasSource ds = dasSources[i];
\r
155 text.append("<font color=\"#0000FF\">Id:</font> " + dasSources[i].getId() +
\r
157 text.append("<font color=\"#0000FF\">Nickname:</font> " +
\r
158 dasSources[i].getNickname() + "<br>");
\r
159 text.append("<font color=\"#0000FF\">URL:</font> " + dasSources[i].getUrl() +
\r
162 text.append("<font color=\"#0000FF\">Admin Email:</font> <a href=\"mailto:"
\r
163 +dasSources[i].getAdminemail()
\r
164 +"\">"+dasSources[i].getAdminemail()+"</a>" +
\r
168 text.append("<font color=\"#0000FF\">Registered at:</font> " + dasSources[i].getRegisterDate() +
\r
171 text.append("<font color=\"#0000FF\">Last successful test:</font> " + dasSources[i].getLeaseDate() +
\r
174 text.append("<font color=\"#0000FF\">Labels:</font> ");
\r
175 for(int s=0; s<dasSources[i].getLabels().length; s++)
\r
177 text.append( dasSources[i].getLabels()[s]);
\r
178 if(s<dasSources[i].getLabels().length-1)
\r
182 text.append("<br>");
\r
186 text.append("<font color=\"#0000FF\">Capabilities:</font> ");
\r
187 String[] scap = dasSources[i].getCapabilities();
\r
188 for (int j = 0; j < scap.length; j++)
\r
190 text.append(scap[j]);
\r
191 if (j < scap.length - 1)
\r
194 text.append("<br>");
\r
196 text.append("<font color=\"#0000FF\">Coordinates:</font> ");
\r
197 DasCoordinateSystem[] dcs = ds.getCoordinateSystem();
\r
198 for (int j = 0; j < dcs.length; j++)
\r
200 text.append("(" + dcs[j].getUniqueId() + ") "
\r
201 + dcs[j].getCategory() + ", " + dcs[j].getName());
\r
202 if (dcs[j].getNCBITaxId() != 0)
\r
203 text.append(", " + dcs[j].getNCBITaxId());
\r
204 if (dcs[j].getOrganismName().length() > 0)
\r
205 text.append(", " + dcs[j].getOrganismName());
\r
207 text.append("<br>");
\r
210 text.append("<font color=\"#0000FF\">Description:</font> " +
\r
211 dasSources[i].getDescription() + "<br>");
\r
214 if (dasSources[i].getHelperurl()!=null
\r
215 && dasSources[i].getHelperurl().length() > 0)
\r
217 text.append("<font color=\"#0000FF\"><a href=\"" +
\r
218 dasSources[i].getHelperurl()
\r
219 + "\">Go to site</a></font<br>");
\r
222 text.append("</font></html>");
\r
227 fullDetails.setText(text.toString());
\r
228 javax.swing.SwingUtilities.invokeLater(new Runnable()
\r
232 fullDetailsScrollpane.getVerticalScrollBar().setValue(0);
\r
240 addLocal.setVisible(false);
\r
241 refresh.setVisible(false);
\r
242 progressBar.setVisible(true);
\r
243 progressBar.setIndeterminate(true);
\r
245 dasSources = jalview.io.DasSequenceFeatureFetcher.getDASSources();
\r
247 appendLocalSources();
\r
253 public Vector getSelectedSources()
\r
255 Vector selected = new Vector();
\r
256 for (int r = 0; r < selectedSources.size(); r++)
\r
258 for (int i = 0; i < dasSources.length; i++)
\r
260 if (dasSources[i].getNickname().equals(
\r
261 selectedSources.elementAt(r)))
\r
263 selected.addElement(dasSources[i]);
\r
272 public DasSource[] getDASSource()
\r
274 if(dasSources==null)
\r
276 dasSources = jalview.io.DasSequenceFeatureFetcher.getDASSources();
\r
277 appendLocalSources();
\r
283 public void refresh_actionPerformed(ActionEvent e)
\r
285 saveProperties(jalview.bin.Cache.applicationProperties);
\r
287 Thread worker = new Thread(this);
\r
291 private void setCapabilities(DasSource[] sources)
\r
293 Vector authority = new Vector();
\r
294 Vector type = new Vector();
\r
295 Vector label = new Vector();
\r
297 authority.addElement("Any");
\r
298 type.addElement("Any");
\r
299 label.addElement("Any");
\r
301 for (int i = 0; i < sources.length; i++)
\r
303 DasSource ds = sources[i];
\r
305 DasCoordinateSystem[] dcs = ds.getCoordinateSystem();
\r
307 for (int j = 0; j < dcs.length; j++)
\r
309 if (!type.contains(dcs[j].getCategory()))
\r
310 type.addElement(dcs[j].getCategory());
\r
312 if (!authority.contains(dcs[j].getName()))
\r
313 authority.addElement(dcs[j].getName());
\r
316 String[] slabels = ds.getLabels();
\r
317 for (int s = 0; s < slabels.length; s++)
\r
319 if (!label.contains(slabels[s]))
\r
321 label.addElement(slabels[s]);
\r
327 filter1.setListData(authority);
\r
328 filter2.setListData(type);
\r
329 filter3.setListData(label);
\r
331 javax.swing.SwingUtilities.invokeLater(new Runnable()
\r
335 filter1.setSelectedIndex(0);
\r
336 filter2.setSelectedIndex(0);
\r
337 filter3.setSelectedIndex(0);
\r
342 public void amendLocal(boolean newSource)
\r
344 String url = "http://localhost:8080/", nickname = "";
\r
348 int selectedRow = table.getSelectionModel().getMinSelectionIndex();
\r
349 nickname = table.getValueAt(selectedRow, 0).toString();
\r
350 url = ((DasSource)localSources.get(nickname)).getUrl();
\r
353 JTextField nametf = new JTextField(nickname, 40);
\r
354 JTextField urltf = new JTextField(url, 40);
\r
356 JPanel panel = new JPanel(new BorderLayout());
\r
357 JPanel pane12 = new JPanel(new BorderLayout());
\r
358 pane12.add(new JLabel("Nickname: "), BorderLayout.CENTER);
\r
359 pane12.add(nametf, BorderLayout.EAST);
\r
360 panel.add(pane12, BorderLayout.NORTH);
\r
361 pane12 = new JPanel(new BorderLayout());
\r
362 pane12.add(new JLabel("URL: "), BorderLayout.CENTER);
\r
363 pane12.add(urltf, BorderLayout.EAST);
\r
364 panel.add(pane12, BorderLayout.SOUTH);
\r
367 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
\r
368 panel, "Enter Nickname & URL of Local DAS Source",
\r
369 JOptionPane.OK_CANCEL_OPTION);
\r
371 if (reply != JOptionPane.OK_OPTION )
\r
376 if(!urltf.getText().endsWith("/"))
\r
377 urltf.setText(urltf.getText()+"/");
\r
379 Das1Source local = new Das1Source();
\r
381 local.setUrl(urltf.getText());
\r
382 local.setNickname(nametf.getText());
\r
385 if(localSources==null)
\r
386 localSources = new Hashtable();
\r
388 localSources.put(local.getNickname(), local);
\r
390 if(!newSource && !nickname.equals(nametf.getText()))
\r
392 localSources.remove(nickname);
\r
395 int size = dasSources.length;
\r
396 int adjust = newSource ? 1 : 0;
\r
398 Object[][] data = new Object[size+adjust][2];
\r
399 for (int i = 0; i < size; i++)
\r
401 if(!newSource && dasSources[i].getNickname().equals(nickname))
\r
403 ((DasSource)dasSources[i]).setNickname(local.getNickname());
\r
404 ((DasSource)dasSources[i]).setUrl(local.getUrl());
\r
405 data[i][0] = local.getNickname();
\r
406 data[i][1] = new Boolean(true);
\r
410 data[i][0] = dasSources[i].getNickname();
\r
411 data[i][1] = new Boolean(selectedSources.contains(dasSources[i].
\r
418 data[size][0] = local.getNickname();
\r
419 data[size][1] = new Boolean(true);
\r
420 selectedSources.add(local.getNickname());
\r
423 DasSource [] tmp = new DasSource[size+adjust];
\r
425 System.arraycopy(dasSources, 0, tmp, 0, size);
\r
432 refreshTableData(data);
\r
434 SwingUtilities.invokeLater(new Runnable()
\r
438 scrollPane.getVerticalScrollBar().setValue(
\r
439 scrollPane.getVerticalScrollBar().getMaximum()
\r
444 displayFullDetails(local.getNickname());
\r
447 public void editRemoveLocalSource(MouseEvent evt)
\r
449 int selectedRow = table.getSelectionModel().getMinSelectionIndex();
\r
450 if(selectedRow==-1)
\r
453 String nickname = table.getValueAt(selectedRow, 0).toString();
\r
455 if (!localSources.containsKey(nickname))
\r
457 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
458 "You can only edit or remove local DAS Sources!",
\r
459 "Public DAS source - not editable",
\r
460 JOptionPane.WARNING_MESSAGE);
\r
465 Object[] options = {"Edit", "Remove", "Cancel"};
\r
466 int choice = JOptionPane.showInternalOptionDialog(Desktop.desktop,
\r
467 "Do you want to edit or remove "+nickname+"?",
\r
468 "Edit / Remove Local DAS Source",
\r
469 JOptionPane.YES_NO_CANCEL_OPTION,
\r
470 JOptionPane.QUESTION_MESSAGE,
\r
477 case 0: amendLocal(false); break;
\r
479 localSources.remove(nickname);
\r
480 selectedSources.remove(nickname);
\r
481 Object[][] data = new Object[dasSources.length-1][2];
\r
482 DasSource [] tmp = new DasSource[dasSources.length-1];
\r
484 for (int i = 0; i < dasSources.length; i++)
\r
486 if (dasSources[i].getNickname().equals(nickname))
\r
492 tmp[index] = dasSources[i];
\r
493 data[index][0] = dasSources[i].getNickname();
\r
494 data[index][1] = new Boolean(selectedSources.contains(dasSources[i].
\r
500 refreshTableData(data);
\r
501 SwingUtilities.invokeLater(new Runnable()
\r
505 scrollPane.getVerticalScrollBar().setValue(
\r
506 scrollPane.getVerticalScrollBar().getMaximum()
\r
515 void appendLocalSources()
\r
517 if(localSources==null)
\r
520 int size = dasSources!=null ? dasSources.length : 0;
\r
521 int lsize = localSources.size();
\r
523 Object[][] data = new Object[size+lsize][2];
\r
524 for (int i = 0; i < size; i++)
\r
526 data[i][0] = dasSources[i].getNickname();
\r
527 data[i][1] = new Boolean(selectedSources.contains(dasSources[i].
\r
531 DasSource [] tmp = new DasSource[size+lsize];
\r
532 if(dasSources!=null)
\r
533 System.arraycopy(dasSources, 0, tmp, 0, size);
\r
535 Enumeration en = localSources.keys();
\r
537 while(en.hasMoreElements())
\r
539 String key = en.nextElement().toString();
\r
540 data[index][0] = key;
\r
541 data[index][1] = new Boolean(false);
\r
542 tmp[index] = new Das1Source();
\r
543 tmp[index].setNickname(key);
\r
544 tmp[index].setUrl( ((DasSource)localSources.get(key)).getUrl() );
\r
551 refreshTableData(data);
\r
554 public void valueChanged(ListSelectionEvent evt)
\r
556 //Called when the MainTable selection changes
\r
557 if (evt.getValueIsAdjusting() )
\r
563 displayFullDetails(null);
\r
565 // Filter the displayed data sources
\r
566 int dSize = dasSources.length;
\r
569 ArrayList names = new ArrayList();
\r
570 ArrayList selected = new ArrayList();
\r
573 //The features filter is not visible, but we must still
\r
574 //filter the das source list here.
\r
575 //July 2006 - only 6 sources fo not serve features
\r
576 Object [] dummyFeatureList = new Object[]{"features"};
\r
578 for (int i = 0; i < dSize; i++)
\r
580 ds = dasSources[i];
\r
581 DasCoordinateSystem[] dcs = ds.getCoordinateSystem();
\r
583 if (dcs.length == 0 && ds.getCapabilities().length == 0
\r
584 && filter1.getSelectedIndex() == 0
\r
585 && filter2.getSelectedIndex() == 0
\r
586 && filter3.getSelectedIndex() == 0)
\r
588 //THIS IS A FIX FOR LOCAL SOURCES WHICH DO NOT
\r
589 //HAVE COORDINATE SYSTEMS, INFO WHICH AT PRESENT
\r
590 //IS ADDED FROM THE REGISTRY
\r
591 names.add(ds.getNickname());
\r
592 selected.add(new Boolean(
\r
593 selectedSources.contains(ds.getNickname())));
\r
598 if (!selectedInList(dummyFeatureList, ds.getCapabilities())
\r
599 || !selectedInList(filter3.getSelectedValues(),
\r
605 for (int j = 0; j < dcs.length; j++)
\r
607 if ( selectedInList(filter1.getSelectedValues(),
\r
609 {dcs[j].getName()})
\r
610 && selectedInList(filter2.getSelectedValues(),
\r
612 {dcs[j].getCategory()}))
\r
614 names.add(ds.getNickname());
\r
615 selected.add(new Boolean(
\r
616 selectedSources.contains(ds.getNickname())));
\r
622 dSize = names.size();
\r
623 Object[][] data = new Object[dSize][2];
\r
624 for (int d = 0; d < dSize; d++)
\r
626 data[d][0] = names.get(d);
\r
627 data[d][1] = selected.get(d);
\r
630 refreshTableData(data);
\r
633 boolean selectedInList(Object [] selection, String[] items)
\r
635 for (int i = 0; i < selection.length; i++)
\r
637 if (selection[i].equals("Any") )
\r
640 for (int j = 0; j < items.length; j++)
\r
642 if (selection[i].equals(items[j]))
\r
650 void setSelectedFromProperties()
\r
652 String active = jalview.bin.Cache.getDefault("DAS_ACTIVE_SOURCE", "uniprot");
\r
653 StringTokenizer st = new StringTokenizer(active, "\t");
\r
654 selectedSources = new Vector();
\r
655 while(st.hasMoreTokens())
\r
657 selectedSources.addElement(st.nextToken());
\r
660 String local = jalview.bin.Cache.getProperty("DAS_LOCAL_SOURCE");
\r
663 if(localSources == null)
\r
664 localSources = new Hashtable();
\r
666 st = new StringTokenizer(local, "\t");
\r
667 while(st.hasMoreTokens())
\r
669 String token = st.nextToken();
\r
670 int bar = token.indexOf("|");
\r
671 Das1Source source = new Das1Source();
\r
673 source.setUrl(token.substring(bar + 1));
\r
674 source.setNickname(token.substring(0, bar));
\r
676 localSources.put(source.getNickname(), source);
\r
681 public void saveProperties(Properties properties)
\r
683 if (registryURL.getText() == null || registryURL.getText().length() < 1)
\r
684 properties.remove("DAS_REGISTRY_URL");
\r
686 properties.setProperty("DAS_REGISTRY_URL", registryURL.getText());
\r
688 StringBuffer sb = new StringBuffer();
\r
689 for(int r=0; r<table.getModel().getRowCount(); r++)
\r
691 if( ((Boolean)table.getValueAt(r,1)).booleanValue())
\r
693 sb.append(table.getValueAt(r,0)+"\t");
\r
697 properties.setProperty("DAS_ACTIVE_SOURCE", sb.toString() );
\r
699 if(localSources!=null)
\r
701 sb = new StringBuffer();
\r
702 Enumeration en = localSources.keys();
\r
703 while(en.hasMoreElements())
\r
705 String token = en.nextElement().toString();
\r
706 sb.append(token+"|"
\r
707 + ((DasSource)localSources.get(token)).getUrl()
\r
711 properties.setProperty("DAS_LOCAL_SOURCE", sb.toString());
\r
716 class DASTableModel
\r
717 extends AbstractTableModel
\r
720 public DASTableModel(Object[][] data)
\r
725 private String[] columnNames = new String[] {"Nickname", "Use Source"};
\r
727 private Object[][] data;
\r
729 public int getColumnCount()
\r
731 return columnNames.length;
\r
734 public int getRowCount()
\r
736 return data.length;
\r
739 public String getColumnName(int col)
\r
741 return columnNames[col];
\r
744 public Object getValueAt(int row, int col)
\r
746 return data[row][col];
\r
750 * JTable uses this method to determine the default renderer/
\r
751 * editor for each cell. If we didn't implement this method,
\r
752 * then the last column would contain text ("true"/"false"),
\r
753 * rather than a check box.
\r
755 public Class getColumnClass(int c)
\r
757 return getValueAt(0, c).getClass();
\r
761 * Don't need to implement this method unless your table's
\r
764 public boolean isCellEditable(int row, int col)
\r
766 //Note that the data/cell address is constant,
\r
767 //no matter where the cell appears onscreen.
\r
773 * Don't need to implement this method unless your table's
\r
776 public void setValueAt(Object value, int row, int col)
\r
778 data[row][col] = value;
\r
779 fireTableCellUpdated(row, col);
\r
781 String name = getValueAt(row,0).toString();
\r
782 boolean selected = ((Boolean)value).booleanValue();
\r
784 if(selectedSources.contains(name) && !selected)
\r
785 selectedSources.remove(name);
\r
787 if(!selectedSources.contains(name) && selected)
\r
788 selectedSources.add(name);
\r