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
44 public DasSourceBrowser()
\r
46 registryURL.setText(jalview.bin.Cache.getDefault("DAS_REGISTRY_URL",
\r
47 "http://das.sanger.ac.uk/registry/das1/sources/") );
\r
49 setSelectedFromProperties();
\r
51 displayFullDetails(null);
\r
52 table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
\r
54 filter1.addListSelectionListener(this);
\r
55 filter2.addListSelectionListener(this);
\r
56 filter3.addListSelectionListener(this);
\r
58 //Ask to be notified of selection changes.
\r
59 ListSelectionModel rowSM = table.getSelectionModel();
\r
60 rowSM.addListSelectionListener(new ListSelectionListener()
\r
62 public void valueChanged(ListSelectionEvent e)
\r
64 //Ignore extra messages.
\r
65 if (e.getValueIsAdjusting())
\r
68 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
\r
69 if (!lsm.isSelectionEmpty())
\r
71 int selectedRow = lsm.getMinSelectionIndex();
\r
72 displayFullDetails(table.getValueAt(selectedRow, 0).toString());
\r
77 table.addMouseListener(new MouseAdapter()
\r
79 public void mouseClicked(MouseEvent evt)
\r
81 if(evt.getClickCount()==2
\r
82 || SwingUtilities.isRightMouseButton(evt))
\r
83 editRemoveLocalSource(evt);
\r
87 if(dasSources==null)
\r
89 Thread worker = new Thread(this);
\r
100 int dSize = dasSources.length;
\r
101 Object[][] data = new Object[dSize][2];
\r
102 for (int i = 0; i < dSize; i++)
\r
104 data[i][0] = dasSources[i].getNickname();
\r
105 data[i][1] = new Boolean(selectedSources.contains(dasSources[i].
\r
109 refreshTableData(data);
\r
110 setCapabilities(dasSources);
\r
112 javax.swing.SwingUtilities.invokeLater(new Runnable()
\r
116 TableSorter sorter = (TableSorter)table.getModel();
\r
117 sorter.setSortingStatus(1, TableSorter.DESCENDING);
\r
118 sorter.setSortingStatus(1, TableSorter.NOT_SORTED);
\r
122 progressBar.setIndeterminate(false);
\r
123 progressBar.setVisible(false);
\r
124 addLocal.setVisible(true);
\r
125 refresh.setVisible(true);
\r
129 public void refreshTableData(Object[][] data)
\r
131 TableSorter sorter = new TableSorter(new DASTableModel(data));
\r
132 sorter.setTableHeader(table.getTableHeader());
\r
133 table.setModel(sorter);
\r
136 void displayFullDetails(String nickName)
\r
139 StringBuffer text = new StringBuffer(
\r
140 "<HTML><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">");
\r
142 if (nickName == null)
\r
144 fullDetails.setText(text +
\r
145 "Select a DAS service from the table"
\r
146 + " to read a full description here.</font></html>");
\r
150 int dSize = dasSources.length;
\r
151 for (int i = 0; i < dSize; i++)
\r
153 if (!dasSources[i].getNickname().equals(nickName))
\r
156 DasSource ds = dasSources[i];
\r
158 text.append("<font color=\"#0000FF\">Id:</font> " + dasSources[i].getId() +
\r
160 text.append("<font color=\"#0000FF\">Nickname:</font> " +
\r
161 dasSources[i].getNickname() + "<br>");
\r
162 text.append("<font color=\"#0000FF\">URL:</font> " + dasSources[i].getUrl() +
\r
165 text.append("<font color=\"#0000FF\">Admin Email:</font> <a href=\"mailto:"
\r
166 +dasSources[i].getAdminemail()
\r
167 +"\">"+dasSources[i].getAdminemail()+"</a>" +
\r
171 text.append("<font color=\"#0000FF\">Registered at:</font> " + dasSources[i].getRegisterDate() +
\r
174 text.append("<font color=\"#0000FF\">Last successful test:</font> " + dasSources[i].getLeaseDate() +
\r
177 text.append("<font color=\"#0000FF\">Labels:</font> ");
\r
178 for(int s=0; s<dasSources[i].getLabels().length; s++)
\r
180 text.append( dasSources[i].getLabels()[s]);
\r
181 if(s<dasSources[i].getLabels().length-1)
\r
185 text.append("<br>");
\r
189 text.append("<font color=\"#0000FF\">Capabilities:</font> ");
\r
190 String[] scap = dasSources[i].getCapabilities();
\r
191 for (int j = 0; j < scap.length; j++)
\r
193 text.append(scap[j]);
\r
194 if (j < scap.length - 1)
\r
197 text.append("<br>");
\r
199 text.append("<font color=\"#0000FF\">Coordinates:</font> ");
\r
200 DasCoordinateSystem[] dcs = ds.getCoordinateSystem();
\r
201 for (int j = 0; j < dcs.length; j++)
\r
203 text.append("(" + dcs[j].getUniqueId() + ") "
\r
204 + dcs[j].getCategory() + ", " + dcs[j].getName());
\r
205 if (dcs[j].getNCBITaxId() != 0)
\r
206 text.append(", " + dcs[j].getNCBITaxId());
\r
207 if (dcs[j].getOrganismName().length() > 0)
\r
208 text.append(", " + dcs[j].getOrganismName());
\r
210 text.append("<br>");
\r
213 text.append("<font color=\"#0000FF\">Description:</font> " +
\r
214 dasSources[i].getDescription() + "<br>");
\r
217 if (dasSources[i].getHelperurl()!=null
\r
218 && dasSources[i].getHelperurl().length() > 0)
\r
220 text.append("<font color=\"#0000FF\"><a href=\"" +
\r
221 dasSources[i].getHelperurl()
\r
222 + "\">Go to site</a></font<br>");
\r
225 text.append("</font></html>");
\r
230 fullDetails.setText(text.toString());
\r
231 javax.swing.SwingUtilities.invokeLater(new Runnable()
\r
235 fullDetailsScrollpane.getVerticalScrollBar().setValue(0);
\r
244 addLocal.setVisible(false);
\r
245 refresh.setVisible(false);
\r
246 progressBar.setVisible(true);
\r
247 progressBar.setIndeterminate(true);
\r
249 dasSources = jalview.io.DasSequenceFeatureFetcher.getDASSources();
\r
251 appendLocalSources();
\r
256 public Vector getSelectedSources()
\r
258 Vector selected = new Vector();
\r
259 for (int r = 0; r < selectedSources.size(); r++)
\r
261 for (int i = 0; i < dasSources.length; i++)
\r
263 if (dasSources[i].getNickname().equals(
\r
264 selectedSources.elementAt(r)))
\r
266 selected.addElement(dasSources[i]);
\r
275 public DasSource[] getDASSource()
\r
277 if(dasSources==null)
\r
279 dasSources = jalview.io.DasSequenceFeatureFetcher.getDASSources();
\r
280 appendLocalSources();
\r
286 public void refresh_actionPerformed(ActionEvent e)
\r
288 saveProperties(jalview.bin.Cache.applicationProperties);
\r
290 Thread worker = new Thread(this);
\r
294 private void setCapabilities(DasSource[] sources)
\r
296 Vector authority = new Vector();
\r
297 Vector type = new Vector();
\r
298 Vector label = new Vector();
\r
300 authority.addElement("Any");
\r
301 type.addElement("Any");
\r
302 label.addElement("Any");
\r
304 for (int i = 0; i < sources.length; i++)
\r
306 DasSource ds = sources[i];
\r
308 DasCoordinateSystem[] dcs = ds.getCoordinateSystem();
\r
310 for (int j = 0; j < dcs.length; j++)
\r
312 if (!type.contains(dcs[j].getCategory()))
\r
313 type.addElement(dcs[j].getCategory());
\r
315 if (!authority.contains(dcs[j].getName()))
\r
316 authority.addElement(dcs[j].getName());
\r
319 String[] slabels = ds.getLabels();
\r
320 for (int s = 0; s < slabels.length; s++)
\r
322 if (!label.contains(slabels[s]))
\r
324 label.addElement(slabels[s]);
\r
330 filter1.setListData(authority);
\r
331 filter2.setListData(type);
\r
332 filter3.setListData(label);
\r
334 javax.swing.SwingUtilities.invokeLater(new Runnable()
\r
338 filter1.setSelectedIndex(0);
\r
339 filter2.setSelectedIndex(0);
\r
340 filter3.setSelectedIndex(0);
\r
345 public void amendLocal(boolean newSource)
\r
347 String url = "http://localhost:8080/", nickname = "";
\r
351 int selectedRow = table.getSelectionModel().getMinSelectionIndex();
\r
352 nickname = table.getValueAt(selectedRow, 0).toString();
\r
353 url = ((DasSource)localSources.get(nickname)).getUrl();
\r
356 JTextField nametf = new JTextField(nickname, 40);
\r
357 JTextField urltf = new JTextField(url, 40);
\r
359 JPanel panel = new JPanel(new BorderLayout());
\r
360 JPanel pane12 = new JPanel(new BorderLayout());
\r
361 pane12.add(new JLabel("Nickname: "), BorderLayout.CENTER);
\r
362 pane12.add(nametf, BorderLayout.EAST);
\r
363 panel.add(pane12, BorderLayout.NORTH);
\r
364 pane12 = new JPanel(new BorderLayout());
\r
365 pane12.add(new JLabel("URL: "), BorderLayout.CENTER);
\r
366 pane12.add(urltf, BorderLayout.EAST);
\r
367 panel.add(pane12, BorderLayout.SOUTH);
\r
370 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
\r
371 panel, "Enter Nickname & URL of Local DAS Source",
\r
372 JOptionPane.OK_CANCEL_OPTION);
\r
374 if (reply != JOptionPane.OK_OPTION )
\r
379 if(!urltf.getText().endsWith("/"))
\r
380 urltf.setText(urltf.getText()+"/");
\r
382 Das1Source local = new Das1Source();
\r
384 local.setUrl(urltf.getText());
\r
385 local.setNickname(nametf.getText());
\r
388 if(localSources==null)
\r
389 localSources = new Hashtable();
\r
391 localSources.put(local.getNickname(), local);
\r
393 if(!newSource && !nickname.equals(nametf.getText()))
\r
395 localSources.remove(nickname);
\r
398 int size = dasSources.length;
\r
399 int adjust = newSource ? 1 : 0;
\r
401 Object[][] data = new Object[size+adjust][2];
\r
402 for (int i = 0; i < size; i++)
\r
404 if(!newSource && dasSources[i].getNickname().equals(nickname))
\r
406 ((DasSource)dasSources[i]).setNickname(local.getNickname());
\r
407 ((DasSource)dasSources[i]).setUrl(local.getUrl());
\r
408 data[i][0] = local.getNickname();
\r
409 data[i][1] = new Boolean(true);
\r
413 data[i][0] = dasSources[i].getNickname();
\r
414 data[i][1] = new Boolean(selectedSources.contains(dasSources[i].
\r
421 data[size][0] = local.getNickname();
\r
422 data[size][1] = new Boolean(true);
\r
423 selectedSources.add(local.getNickname());
\r
426 DasSource [] tmp = new DasSource[size+adjust];
\r
428 System.arraycopy(dasSources, 0, tmp, 0, size);
\r
435 refreshTableData(data);
\r
437 SwingUtilities.invokeLater(new Runnable()
\r
441 scrollPane.getVerticalScrollBar().setValue(
\r
442 scrollPane.getVerticalScrollBar().getMaximum()
\r
447 displayFullDetails(local.getNickname());
\r
450 public void editRemoveLocalSource(MouseEvent evt)
\r
452 int selectedRow = table.getSelectionModel().getMinSelectionIndex();
\r
453 if(selectedRow==-1)
\r
456 String nickname = table.getValueAt(selectedRow, 0).toString();
\r
458 if (!localSources.containsKey(nickname))
\r
460 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
461 "You can only edit or remove local DAS Sources!",
\r
462 "Public DAS source - not editable",
\r
463 JOptionPane.WARNING_MESSAGE);
\r
468 Object[] options = {"Edit", "Remove", "Cancel"};
\r
469 int choice = JOptionPane.showInternalOptionDialog(Desktop.desktop,
\r
470 "Do you want to edit or remove "+nickname+"?",
\r
471 "Edit / Remove Local DAS Source",
\r
472 JOptionPane.YES_NO_CANCEL_OPTION,
\r
473 JOptionPane.QUESTION_MESSAGE,
\r
480 case 0: amendLocal(false); break;
\r
482 localSources.remove(nickname);
\r
483 selectedSources.remove(nickname);
\r
484 Object[][] data = new Object[dasSources.length-1][2];
\r
485 DasSource [] tmp = new DasSource[dasSources.length-1];
\r
487 for (int i = 0; i < dasSources.length; i++)
\r
489 if (dasSources[i].getNickname().equals(nickname))
\r
495 tmp[index] = dasSources[i];
\r
496 data[index][0] = dasSources[i].getNickname();
\r
497 data[index][1] = new Boolean(selectedSources.contains(dasSources[i].
\r
503 refreshTableData(data);
\r
504 SwingUtilities.invokeLater(new Runnable()
\r
508 scrollPane.getVerticalScrollBar().setValue(
\r
509 scrollPane.getVerticalScrollBar().getMaximum()
\r
518 void appendLocalSources()
\r
520 if(localSources==null)
\r
523 int size = dasSources!=null ? dasSources.length : 0;
\r
524 int lsize = localSources.size();
\r
526 Object[][] data = new Object[size+lsize][2];
\r
527 for (int i = 0; i < size; i++)
\r
529 data[i][0] = dasSources[i].getNickname();
\r
530 data[i][1] = new Boolean(selectedSources.contains(dasSources[i].
\r
534 DasSource [] tmp = new DasSource[size+lsize];
\r
535 if(dasSources!=null)
\r
536 System.arraycopy(dasSources, 0, tmp, 0, size);
\r
538 Enumeration en = localSources.keys();
\r
540 while(en.hasMoreElements())
\r
542 String key = en.nextElement().toString();
\r
543 data[index][0] = key;
\r
544 data[index][1] = new Boolean(false);
\r
545 tmp[index] = new Das1Source();
\r
546 tmp[index].setNickname(key);
\r
547 tmp[index].setUrl( ((DasSource)localSources.get(key)).getUrl() );
\r
554 refreshTableData(data);
\r
557 public void valueChanged(ListSelectionEvent evt)
\r
559 //Called when the MainTable selection changes
\r
560 if (evt.getValueIsAdjusting())
\r
565 displayFullDetails(null);
\r
567 // Filter the displayed data sources
\r
568 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 // capabilities.get
\r
579 for (int i = 0; i < dSize; i++)
\r
581 ds = dasSources[i];
\r
583 if (!selectedInList(dummyFeatureList, ds.getCapabilities())
\r
584 || !selectedInList(filter3.getSelectedValues(),
\r
590 DasCoordinateSystem[] dcs = ds.getCoordinateSystem();
\r
591 for (int j = 0; j < dcs.length; j++)
\r
593 if (selectedInList(dummyFeatureList,ds.getCapabilities())
\r
595 selectedInList(filter1.getSelectedValues(),
\r
597 {dcs[j].getName()})
\r
598 && selectedInList(filter2.getSelectedValues(),
\r
600 {dcs[j].getCategory()}))
\r
602 names.add(ds.getNickname());
\r
603 selected.add(new Boolean(
\r
604 selectedSources.contains(ds.getNickname())));
\r
610 dSize = names.size();
\r
611 Object[][] data = new Object[dSize][2];
\r
612 for (int d = 0; d < dSize; d++)
\r
614 data[d][0] = names.get(d);
\r
615 data[d][1] = selected.get(d);
\r
618 refreshTableData(data);
\r
621 boolean selectedInList(Object [] selection, String[] items)
\r
623 for (int i = 0; i < selection.length; i++)
\r
625 if (selection[i].equals("Any"))
\r
628 for (int j = 0; j < items.length; j++)
\r
630 if (selection[i].equals(items[j]))
\r
638 void setSelectedFromProperties()
\r
640 String active = jalview.bin.Cache.getDefault("DAS_ACTIVE_SOURCE", "uniprot");
\r
641 StringTokenizer st = new StringTokenizer(active, "\t");
\r
642 selectedSources = new Vector();
\r
643 while(st.hasMoreTokens())
\r
645 selectedSources.addElement(st.nextToken());
\r
648 String local = jalview.bin.Cache.getProperty("DAS_LOCAL_SOURCE");
\r
651 if(localSources == null)
\r
652 localSources = new Hashtable();
\r
654 st = new StringTokenizer(local, "\t");
\r
655 while(st.hasMoreTokens())
\r
657 String token = st.nextToken();
\r
658 int bar = token.indexOf("|");
\r
659 Das1Source source = new Das1Source();
\r
661 source.setUrl(token.substring(bar + 1));
\r
662 source.setNickname(token.substring(0, bar));
\r
664 localSources.put(source.getNickname(), source);
\r
669 public void saveProperties(Properties properties)
\r
671 properties.setProperty("DAS_REGISTRY_URL", registryURL.getText());
\r
673 StringBuffer sb = new StringBuffer();
\r
674 for(int r=0; r<table.getModel().getRowCount(); r++)
\r
676 if( ((Boolean)table.getValueAt(r,1)).booleanValue())
\r
678 sb.append(table.getValueAt(r,0)+"\t");
\r
682 properties.setProperty("DAS_ACTIVE_SOURCE", sb.toString() );
\r
684 if(localSources!=null)
\r
686 sb = new StringBuffer();
\r
687 Enumeration en = localSources.keys();
\r
688 while(en.hasMoreElements())
\r
690 String token = en.nextElement().toString();
\r
691 sb.append(token+"|"
\r
692 + ((DasSource)localSources.get(token)).getUrl()
\r
696 properties.setProperty("DAS_LOCAL_SOURCE", sb.toString());
\r
701 class DASTableModel
\r
702 extends AbstractTableModel
\r
705 public DASTableModel(Object[][] data)
\r
710 private String[] columnNames = new String[] {"Nickname", "Use Source"};
\r
712 private Object[][] data;
\r
714 public int getColumnCount()
\r
716 return columnNames.length;
\r
719 public int getRowCount()
\r
721 return data.length;
\r
724 public String getColumnName(int col)
\r
726 return columnNames[col];
\r
729 public Object getValueAt(int row, int col)
\r
731 return data[row][col];
\r
735 * JTable uses this method to determine the default renderer/
\r
736 * editor for each cell. If we didn't implement this method,
\r
737 * then the last column would contain text ("true"/"false"),
\r
738 * rather than a check box.
\r
740 public Class getColumnClass(int c)
\r
742 return getValueAt(0, c).getClass();
\r
746 * Don't need to implement this method unless your table's
\r
749 public boolean isCellEditable(int row, int col)
\r
751 //Note that the data/cell address is constant,
\r
752 //no matter where the cell appears onscreen.
\r
758 * Don't need to implement this method unless your table's
\r
761 public void setValueAt(Object value, int row, int col)
\r
763 data[row][col] = value;
\r
764 fireTableCellUpdated(row, col);
\r
766 String name = getValueAt(row,0).toString();
\r
767 boolean selected = ((Boolean)value).booleanValue();
\r
769 if(selectedSources.contains(name) && !selected)
\r
770 selectedSources.remove(name);
\r
772 if(!selectedSources.contains(name) && selected)
\r
773 selectedSources.add(name);
\r