pickmanager on sequence and alignment position, vamsas pick broadcast and refactor...
[jalview.git] / src / jalview / gui / DasSourceBrowser.java
1 /*\r
2  * Jalview - A Sequence Alignment Editor and Viewer\r
3  * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
4  *\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
9  *\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
14  *\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
18  */\r
19 package jalview.gui;\r
20 \r
21 import java.util.*;\r
22 \r
23 import java.awt.*;\r
24 import java.awt.event.*;\r
25 import javax.swing.*;\r
26 import javax.swing.event.*;\r
27 import javax.swing.table.*;\r
28 \r
29 import org.biojava.dasobert.dasregistry.*;\r
30 import jalview.jbgui.*;\r
31 import jalview.util.*;\r
32 \r
33 public class DasSourceBrowser\r
34     extends GDasSourceBrowser implements Runnable, ListSelectionListener\r
35 {\r
36   static DasSource[] dasSources = null;\r
37 \r
38   Hashtable localSources = null;\r
39 \r
40   Vector selectedSources;\r
41 \r
42   public static String DEFAULT_REGISTRY =\r
43       "http://www.dasregistry.org/das1/sources/";\r
44 \r
45   boolean loadingDasSources = false;\r
46 \r
47   public DasSourceBrowser()\r
48   {\r
49     String registry = jalview.bin.Cache.getDefault("DAS_REGISTRY_URL",\r
50         DEFAULT_REGISTRY);\r
51 \r
52     if (registry.indexOf("/registry/das1/sources/") > -1)\r
53     {\r
54       jalview.bin.Cache.setProperty("DAS_REGISTRY_URL", DEFAULT_REGISTRY);\r
55       registry = DEFAULT_REGISTRY;\r
56     }\r
57 \r
58     registryURL.setText(registry);\r
59 \r
60     setSelectedFromProperties();\r
61 \r
62     displayFullDetails(null);\r
63     table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);\r
64 \r
65     filter1.addListSelectionListener(this);\r
66     filter2.addListSelectionListener(this);\r
67     filter3.addListSelectionListener(this);\r
68 \r
69     //Ask to be notified of selection changes.\r
70     ListSelectionModel rowSM = table.getSelectionModel();\r
71     rowSM.addListSelectionListener(new ListSelectionListener()\r
72     {\r
73       public void valueChanged(ListSelectionEvent e)\r
74       {\r
75         ListSelectionModel lsm = (ListSelectionModel) e.getSource();\r
76         if (!lsm.isSelectionEmpty())\r
77         {\r
78           int selectedRow = lsm.getMinSelectionIndex();\r
79           displayFullDetails(table.getValueAt(selectedRow, 0).toString());\r
80         }\r
81       }\r
82     });\r
83 \r
84     table.addMouseListener(new MouseAdapter()\r
85     {\r
86       public void mouseClicked(MouseEvent evt)\r
87       {\r
88         if (evt.getClickCount() == 2\r
89             || SwingUtilities.isRightMouseButton(evt))\r
90         {\r
91           editRemoveLocalSource(evt);\r
92         }\r
93       }\r
94     });\r
95 \r
96     if (dasSources != null)\r
97     {\r
98       init();\r
99     }\r
100   }\r
101 \r
102   public void paintComponent(java.awt.Graphics g)\r
103   {\r
104     if (dasSources == null && !loadingDasSources)\r
105     {\r
106       Thread worker = new Thread(this);\r
107       worker.start();\r
108     }\r
109   }\r
110 \r
111   void init()\r
112   {\r
113     int dSize = dasSources.length;\r
114     Object[][] data = new Object[dSize][2];\r
115     for (int i = 0; i < dSize; i++)\r
116     {\r
117       data[i][0] = dasSources[i].getNickname();\r
118       data[i][1] = new Boolean(selectedSources.contains(dasSources[i].\r
119           getNickname()));\r
120     }\r
121 \r
122     refreshTableData(data);\r
123     setCapabilities(dasSources);\r
124 \r
125     javax.swing.SwingUtilities.invokeLater(new Runnable()\r
126     {\r
127       public void run()\r
128       {\r
129         TableSorter sorter = (TableSorter) table.getModel();\r
130         sorter.setSortingStatus(1, TableSorter.DESCENDING);\r
131         sorter.setSortingStatus(1, TableSorter.NOT_SORTED);\r
132       }\r
133     });\r
134 \r
135     progressBar.setIndeterminate(false);\r
136     progressBar.setVisible(false);\r
137     addLocal.setVisible(true);\r
138     refresh.setVisible(true);\r
139   }\r
140 \r
141   public void refreshTableData(Object[][] data)\r
142   {\r
143     TableSorter sorter = new TableSorter(new DASTableModel(data));\r
144     sorter.setTableHeader(table.getTableHeader());\r
145     table.setModel(sorter);\r
146   }\r
147 \r
148   void displayFullDetails(String nickName)\r
149   {\r
150 \r
151     StringBuffer text = new StringBuffer(\r
152         "<HTML><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">");\r
153 \r
154     if (nickName == null)\r
155     {\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
159       return;\r
160     }\r
161 \r
162     int dSize = dasSources.length;\r
163     for (int i = 0; i < dSize; i++)\r
164     {\r
165       if (!dasSources[i].getNickname().equals(nickName))\r
166       {\r
167         continue;\r
168       }\r
169 \r
170       DasSource ds = dasSources[i];\r
171 \r
172       text.append("<font color=\"#0000FF\">Id:</font> " + dasSources[i].getId() +\r
173                   "<br>");\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
177                   "<br>");\r
178 \r
179       text.append(\r
180           "<font color=\"#0000FF\">Admin Email:</font> <a href=\"mailto:"\r
181           + dasSources[i].getAdminemail()\r
182           + "\">" + dasSources[i].getAdminemail() + "</a>" +\r
183           "<br>");\r
184 \r
185       text.append("<font color=\"#0000FF\">Registered at:</font> " +\r
186                   dasSources[i].getRegisterDate() +\r
187                   "<br>");\r
188 \r
189       text.append("<font color=\"#0000FF\">Last successful test:</font> " +\r
190                   dasSources[i].getLeaseDate() +\r
191                   "<br>");\r
192 \r
193       text.append("<font color=\"#0000FF\">Labels:</font> ");\r
194       for (int s = 0; s < dasSources[i].getLabels().length; s++)\r
195       {\r
196         text.append(dasSources[i].getLabels()[s]);\r
197         if (s < dasSources[i].getLabels().length - 1)\r
198         {\r
199           text.append(",");\r
200         }\r
201         text.append(" ");\r
202       }\r
203       text.append("<br>");\r
204 \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
208       {\r
209         text.append(scap[j]);\r
210         if (j < scap.length - 1)\r
211         {\r
212           text.append(", ");\r
213         }\r
214       }\r
215       text.append("<br>");\r
216 \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
220       {\r
221         text.append("(" + dcs[j].getUniqueId() + ") "\r
222                     + dcs[j].getCategory() + ", " + dcs[j].getName());\r
223         if (dcs[j].getNCBITaxId() != 0)\r
224         {\r
225           text.append(", " + dcs[j].getNCBITaxId());\r
226         }\r
227         if (dcs[j].getOrganismName().length() > 0)\r
228         {\r
229           text.append(", " + dcs[j].getOrganismName());\r
230         }\r
231 \r
232         text.append("<br>");\r
233       }\r
234 \r
235       text.append("<font color=\"#0000FF\">Description:</font> " +\r
236                   dasSources[i].getDescription() + "<br>");\r
237 \r
238       if (dasSources[i].getHelperurl() != null\r
239           && dasSources[i].getHelperurl().length() > 0)\r
240       {\r
241         text.append("<font color=\"#0000FF\"><a href=\"" +\r
242                     dasSources[i].getHelperurl()\r
243                     + "\">Go to site</a></font<br>");\r
244       }\r
245 \r
246       text.append("</font></html>");\r
247 \r
248       break;\r
249     }\r
250 \r
251     fullDetails.setText(text.toString());\r
252     javax.swing.SwingUtilities.invokeLater(new Runnable()\r
253     {\r
254       public void run()\r
255       {\r
256         fullDetailsScrollpane.getVerticalScrollBar().setValue(0);\r
257       }\r
258     });\r
259   }\r
260 \r
261   public void run()\r
262   {\r
263     loadingDasSources = true;\r
264 \r
265     addLocal.setVisible(false);\r
266     refresh.setVisible(false);\r
267     progressBar.setVisible(true);\r
268     progressBar.setIndeterminate(true);\r
269 \r
270     dasSources = jalview.ws.DasSequenceFeatureFetcher.getDASSources();\r
271 \r
272     appendLocalSources();\r
273 \r
274     init();\r
275 \r
276     loadingDasSources = false;\r
277 \r
278   }\r
279 \r
280   public Vector getSelectedSources()\r
281   {\r
282     Vector selected = new Vector();\r
283     for (int r = 0; r < selectedSources.size(); r++)\r
284     {\r
285       for (int i = 0; i < dasSources.length; i++)\r
286       {\r
287         if (dasSources[i].getNickname().equals(\r
288             selectedSources.elementAt(r)))\r
289         {\r
290           selected.addElement(dasSources[i]);\r
291           break;\r
292         }\r
293       }\r
294     }\r
295 \r
296     return selected;\r
297   }\r
298 \r
299   public DasSource[] getDASSource()\r
300   {\r
301     if (dasSources == null)\r
302     {\r
303       dasSources = jalview.ws.DasSequenceFeatureFetcher.getDASSources();\r
304       appendLocalSources();\r
305     }\r
306 \r
307     return dasSources;\r
308   }\r
309 \r
310   public void refresh_actionPerformed(ActionEvent e)\r
311   {\r
312     saveProperties(jalview.bin.Cache.applicationProperties);\r
313 \r
314     Thread worker = new Thread(this);\r
315     worker.start();\r
316   }\r
317 \r
318   private void setCapabilities(DasSource[] sources)\r
319   {\r
320     Vector authority = new Vector();\r
321     Vector type = new Vector();\r
322     Vector label = new Vector();\r
323 \r
324     authority.addElement("Any");\r
325     type.addElement("Any");\r
326     label.addElement("Any");\r
327 \r
328     for (int i = 0; i < sources.length; i++)\r
329     {\r
330       DasSource ds = sources[i];\r
331 \r
332       DasCoordinateSystem[] dcs = ds.getCoordinateSystem();\r
333 \r
334       for (int j = 0; j < dcs.length; j++)\r
335       {\r
336         if (!type.contains(dcs[j].getCategory()))\r
337         {\r
338           type.addElement(dcs[j].getCategory());\r
339         }\r
340 \r
341         if (!authority.contains(dcs[j].getName()))\r
342         {\r
343           authority.addElement(dcs[j].getName());\r
344         }\r
345       }\r
346 \r
347       String[] slabels = ds.getLabels();\r
348       for (int s = 0; s < slabels.length; s++)\r
349       {\r
350         if (!label.contains(slabels[s]))\r
351         {\r
352           label.addElement(slabels[s]);\r
353         }\r
354       }\r
355 \r
356     }\r
357 \r
358     filter1.setListData(authority);\r
359     filter2.setListData(type);\r
360     filter3.setListData(label);\r
361 \r
362     javax.swing.SwingUtilities.invokeLater(new Runnable()\r
363     {\r
364       public void run()\r
365       {\r
366         filter1.setSelectedIndex(0);\r
367         filter2.setSelectedIndex(0);\r
368         filter3.setSelectedIndex(0);\r
369       }\r
370     });\r
371   }\r
372 \r
373   public void amendLocal(boolean newSource)\r
374   {\r
375     String url = "http://localhost:8080/", nickname = "";\r
376 \r
377     if (!newSource)\r
378     {\r
379       int selectedRow = table.getSelectionModel().getMinSelectionIndex();\r
380       nickname = table.getValueAt(selectedRow, 0).toString();\r
381       url = ( (DasSource) localSources.get(nickname)).getUrl();\r
382     }\r
383 \r
384     JTextField nametf = new JTextField(nickname, 40);\r
385     JTextField urltf = new JTextField(url, 40);\r
386 \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
396 \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
400 \r
401     if (reply != JOptionPane.OK_OPTION)\r
402     {\r
403       return;\r
404     }\r
405 \r
406     if (!urltf.getText().endsWith("/"))\r
407     {\r
408       urltf.setText(urltf.getText() + "/");\r
409     }\r
410 \r
411     Das1Source local = new Das1Source();\r
412 \r
413     local.setUrl(urltf.getText());\r
414     local.setNickname(nametf.getText());\r
415 \r
416     if (localSources == null)\r
417     {\r
418       localSources = new Hashtable();\r
419     }\r
420 \r
421     localSources.put(local.getNickname(), local);\r
422 \r
423     if (!newSource && !nickname.equals(nametf.getText()))\r
424     {\r
425       localSources.remove(nickname);\r
426     }\r
427 \r
428     int size = dasSources.length;\r
429     int adjust = newSource ? 1 : 0;\r
430 \r
431     Object[][] data = new Object[size + adjust][2];\r
432     for (int i = 0; i < size; i++)\r
433     {\r
434       if (!newSource && dasSources[i].getNickname().equals(nickname))\r
435       {\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
440       }\r
441       else\r
442       {\r
443         data[i][0] = dasSources[i].getNickname();\r
444         data[i][1] = new Boolean(selectedSources.contains(dasSources[i].\r
445             getNickname()));\r
446       }\r
447     }\r
448 \r
449     if (newSource)\r
450     {\r
451       data[size][0] = local.getNickname();\r
452       data[size][1] = new Boolean(true);\r
453       selectedSources.add(local.getNickname());\r
454     }\r
455 \r
456     DasSource[] tmp = new DasSource[size + adjust];\r
457 \r
458     System.arraycopy(dasSources, 0, tmp, 0, size);\r
459 \r
460     if (newSource)\r
461     {\r
462       tmp[size] = local;\r
463     }\r
464 \r
465     dasSources = tmp;\r
466 \r
467     refreshTableData(data);\r
468 \r
469     SwingUtilities.invokeLater(new Runnable()\r
470     {\r
471       public void run()\r
472       {\r
473         scrollPane.getVerticalScrollBar().setValue(\r
474             scrollPane.getVerticalScrollBar().getMaximum()\r
475             );\r
476       }\r
477     });\r
478 \r
479     displayFullDetails(local.getNickname());\r
480   }\r
481 \r
482   public void editRemoveLocalSource(MouseEvent evt)\r
483   {\r
484     int selectedRow = table.getSelectionModel().getMinSelectionIndex();\r
485     if (selectedRow == -1)\r
486     {\r
487       return;\r
488     }\r
489 \r
490     String nickname = table.getValueAt(selectedRow, 0).toString();\r
491 \r
492     if (!localSources.containsKey(nickname))\r
493     {\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
498       return;\r
499     }\r
500 \r
501     Object[] options =\r
502         {\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
509         null,\r
510         options,\r
511         options[2]);\r
512 \r
513     switch (choice)\r
514     {\r
515       case 0:\r
516         amendLocal(false);\r
517         break;\r
518       case 1:\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
523         int index = 0;\r
524         for (int i = 0; i < dasSources.length; i++)\r
525         {\r
526           if (dasSources[i].getNickname().equals(nickname))\r
527           {\r
528             continue;\r
529           }\r
530           else\r
531           {\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
535                 getNickname()));\r
536             index++;\r
537           }\r
538         }\r
539         dasSources = tmp;\r
540         refreshTableData(data);\r
541         SwingUtilities.invokeLater(new Runnable()\r
542         {\r
543           public void run()\r
544           {\r
545             scrollPane.getVerticalScrollBar().setValue(\r
546                 scrollPane.getVerticalScrollBar().getMaximum()\r
547                 );\r
548           }\r
549         });\r
550 \r
551         break;\r
552     }\r
553   }\r
554 \r
555   void appendLocalSources()\r
556   {\r
557     if (localSources == null)\r
558     {\r
559       return;\r
560     }\r
561 \r
562     int size = dasSources != null ? dasSources.length : 0;\r
563     int lsize = localSources.size();\r
564 \r
565     Object[][] data = new Object[size + lsize][2];\r
566     for (int i = 0; i < size; i++)\r
567     {\r
568       data[i][0] = dasSources[i].getNickname();\r
569       data[i][1] = new Boolean(selectedSources.contains(dasSources[i].\r
570           getNickname()));\r
571     }\r
572 \r
573     DasSource[] tmp = new DasSource[size + lsize];\r
574     if (dasSources != null)\r
575     {\r
576       System.arraycopy(dasSources, 0, tmp, 0, size);\r
577     }\r
578 \r
579     Enumeration en = localSources.keys();\r
580     int index = size;\r
581     while (en.hasMoreElements())\r
582     {\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
589 \r
590       index++;\r
591     }\r
592 \r
593     dasSources = tmp;\r
594 \r
595     refreshTableData(data);\r
596   }\r
597 \r
598   public void valueChanged(ListSelectionEvent evt)\r
599   {\r
600     //Called when the MainTable selection changes\r
601     if (evt.getValueIsAdjusting())\r
602     {\r
603       return;\r
604     }\r
605 \r
606     displayFullDetails(null);\r
607 \r
608     // Filter the displayed data sources\r
609     int dSize = dasSources.length;\r
610 \r
611     ArrayList names = new ArrayList();\r
612     ArrayList selected = new ArrayList();\r
613     DasSource ds;\r
614 \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
619         {\r
620         "features"};\r
621 \r
622     for (int i = 0; i < dSize; i++)\r
623     {\r
624       ds = dasSources[i];\r
625       DasCoordinateSystem[] dcs = ds.getCoordinateSystem();\r
626 \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
631       {\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
638         continue;\r
639       }\r
640 \r
641       if (!selectedInList(dummyFeatureList, ds.getCapabilities())\r
642           || !selectedInList(filter3.getSelectedValues(),\r
643                              ds.getLabels()))\r
644       {\r
645         continue;\r
646       }\r
647 \r
648       for (int j = 0; j < dcs.length; j++)\r
649       {\r
650         if (selectedInList(filter1.getSelectedValues(),\r
651                            new String[]\r
652                            {dcs[j].getName()})\r
653             && selectedInList(filter2.getSelectedValues(),\r
654                               new String[]\r
655                               {dcs[j].getCategory()}))\r
656         {\r
657           names.add(ds.getNickname());\r
658           selected.add(new Boolean(\r
659               selectedSources.contains(ds.getNickname())));\r
660           break;\r
661         }\r
662       }\r
663     }\r
664 \r
665     dSize = names.size();\r
666     Object[][] data = new Object[dSize][2];\r
667     for (int d = 0; d < dSize; d++)\r
668     {\r
669       data[d][0] = names.get(d);\r
670       data[d][1] = selected.get(d);\r
671     }\r
672 \r
673     refreshTableData(data);\r
674   }\r
675 \r
676   boolean selectedInList(Object[] selection, String[] items)\r
677   {\r
678     for (int i = 0; i < selection.length; i++)\r
679     {\r
680       if (selection[i].equals("Any"))\r
681       {\r
682         return true;\r
683       }\r
684 \r
685       for (int j = 0; j < items.length; j++)\r
686       {\r
687         if (selection[i].equals(items[j]))\r
688         {\r
689           return true;\r
690         }\r
691       }\r
692     }\r
693 \r
694     return false;\r
695   }\r
696 \r
697   void setSelectedFromProperties()\r
698   {\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
703     {\r
704       selectedSources.addElement(st.nextToken());\r
705     }\r
706 \r
707     String local = jalview.bin.Cache.getProperty("DAS_LOCAL_SOURCE");\r
708     if (local != null)\r
709     {\r
710       if (localSources == null)\r
711       {\r
712         localSources = new Hashtable();\r
713       }\r
714 \r
715       st = new StringTokenizer(local, "\t");\r
716       while (st.hasMoreTokens())\r
717       {\r
718         String token = st.nextToken();\r
719         int bar = token.indexOf("|");\r
720         Das1Source source = new Das1Source();\r
721 \r
722         source.setUrl(token.substring(bar + 1));\r
723         source.setNickname(token.substring(0, bar));\r
724 \r
725         localSources.put(source.getNickname(), source);\r
726       }\r
727     }\r
728   }\r
729 \r
730   public void reset_actionPerformed(ActionEvent e)\r
731   {\r
732     registryURL.setText(DEFAULT_REGISTRY);\r
733   }\r
734 \r
735   public void saveProperties(Properties properties)\r
736   {\r
737     if (registryURL.getText() == null || registryURL.getText().length() < 1)\r
738     {\r
739       properties.remove("DAS_REGISTRY_URL");\r
740     }\r
741     else\r
742     {\r
743       properties.setProperty("DAS_REGISTRY_URL", registryURL.getText());\r
744     }\r
745 \r
746     StringBuffer sb = new StringBuffer();\r
747     for (int r = 0; r < table.getModel().getRowCount(); r++)\r
748     {\r
749       if ( ( (Boolean) table.getValueAt(r, 1)).booleanValue())\r
750       {\r
751         sb.append(table.getValueAt(r, 0) + "\t");\r
752       }\r
753     }\r
754 \r
755     properties.setProperty("DAS_ACTIVE_SOURCE", sb.toString());\r
756 \r
757     if (localSources != null)\r
758     {\r
759       sb = new StringBuffer();\r
760       Enumeration en = localSources.keys();\r
761       while (en.hasMoreElements())\r
762       {\r
763         String token = en.nextElement().toString();\r
764         sb.append(token + "|"\r
765                   + ( (DasSource) localSources.get(token)).getUrl()\r
766                   + "\t");\r
767       }\r
768 \r
769       properties.setProperty("DAS_LOCAL_SOURCE", sb.toString());\r
770     }\r
771 \r
772   }\r
773 \r
774   class DASTableModel\r
775       extends AbstractTableModel\r
776   {\r
777 \r
778     public DASTableModel(Object[][] data)\r
779     {\r
780       this.data = data;\r
781     }\r
782 \r
783     private String[] columnNames = new String[]\r
784         {\r
785         "Nickname", "Use Source"};\r
786 \r
787     private Object[][] data;\r
788 \r
789     public int getColumnCount()\r
790     {\r
791       return columnNames.length;\r
792     }\r
793 \r
794     public int getRowCount()\r
795     {\r
796       return data.length;\r
797     }\r
798 \r
799     public String getColumnName(int col)\r
800     {\r
801       return columnNames[col];\r
802     }\r
803 \r
804     public Object getValueAt(int row, int col)\r
805     {\r
806       return data[row][col];\r
807     }\r
808 \r
809     /*\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
814      */\r
815     public Class getColumnClass(int c)\r
816     {\r
817       return getValueAt(0, c).getClass();\r
818     }\r
819 \r
820     /*\r
821      * Don't need to implement this method unless your table's\r
822      * editable.\r
823      */\r
824     public boolean isCellEditable(int row, int col)\r
825     {\r
826       //Note that the data/cell address is constant,\r
827       //no matter where the cell appears onscreen.\r
828       return col == 1;\r
829 \r
830     }\r
831 \r
832     /*\r
833      * Don't need to implement this method unless your table's\r
834      * data can change.\r
835      */\r
836     public void setValueAt(Object value, int row, int col)\r
837     {\r
838       data[row][col] = value;\r
839       fireTableCellUpdated(row, col);\r
840 \r
841       String name = getValueAt(row, 0).toString();\r
842       boolean selected = ( (Boolean) value).booleanValue();\r
843 \r
844       if (selectedSources.contains(name) && !selected)\r
845       {\r
846         selectedSources.remove(name);\r
847       }\r
848 \r
849       if (!selectedSources.contains(name) && selected)\r
850       {\r
851         selectedSources.add(name);\r
852       }\r
853     }\r
854   }\r
855 }\r