DasRegistry moved again
[jalview.git] / src / jalview / gui / DasSourceBrowser.java
1 /*\r
2  * Jalview - A Sequence Alignment Editor and Viewer\r
3  * Copyright (C) 2006 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 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
27 import java.util.*;\r
28 \r
29 \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
34 \r
35 public class DasSourceBrowser extends GDasSourceBrowser\r
36     implements Runnable, ListSelectionListener\r
37 {\r
38   static DasSource[] dasSources = null;\r
39 \r
40   Hashtable localSources = null;\r
41 \r
42   Vector selectedSources;\r
43 \r
44   public static String DEFAULT_REGISTRY = "http://www.dasregistry.org/das1/sources/";\r
45 \r
46   boolean loadingDasSources = false;\r
47 \r
48 \r
49   public DasSourceBrowser()\r
50   {\r
51     String registry = jalview.bin.Cache.getDefault("DAS_REGISTRY_URL",\r
52         DEFAULT_REGISTRY);\r
53 \r
54     if(registry.indexOf("/registry/das1/sources/")>-1)\r
55     {\r
56       jalview.bin.Cache.setProperty("DAS_REGISTRY_URL", DEFAULT_REGISTRY);\r
57       registry = DEFAULT_REGISTRY;\r
58     }\r
59 \r
60     registryURL.setText( registry );\r
61 \r
62     setSelectedFromProperties();\r
63 \r
64     displayFullDetails(null);\r
65     table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);\r
66 \r
67     filter1.addListSelectionListener(this);\r
68     filter2.addListSelectionListener(this);\r
69     filter3.addListSelectionListener(this);\r
70 \r
71     //Ask to be notified of selection changes.\r
72     ListSelectionModel rowSM = table.getSelectionModel();\r
73     rowSM.addListSelectionListener(new ListSelectionListener()\r
74     {\r
75       public void valueChanged(ListSelectionEvent e)\r
76       {\r
77         ListSelectionModel lsm = (ListSelectionModel) e.getSource();\r
78         if (!lsm.isSelectionEmpty())\r
79         {\r
80           int selectedRow = lsm.getMinSelectionIndex();\r
81           displayFullDetails(table.getValueAt(selectedRow, 0).toString());\r
82         }\r
83       }\r
84     });\r
85 \r
86     table.addMouseListener(new MouseAdapter()\r
87         {\r
88           public void mouseClicked(MouseEvent evt)\r
89           {\r
90             if(evt.getClickCount()==2\r
91                || SwingUtilities.isRightMouseButton(evt))\r
92               editRemoveLocalSource(evt);\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 \r
142   public void refreshTableData(Object[][] data)\r
143   {\r
144     TableSorter sorter = new TableSorter(new DASTableModel(data));\r
145     sorter.setTableHeader(table.getTableHeader());\r
146     table.setModel(sorter);\r
147   }\r
148 \r
149   void displayFullDetails(String nickName)\r
150   {\r
151 \r
152     StringBuffer text = new StringBuffer(\r
153         "<HTML><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">");\r
154 \r
155     if (nickName == null)\r
156     {\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
160       return;\r
161     }\r
162 \r
163     int dSize = dasSources.length;\r
164     for (int i = 0; i < dSize; i++)\r
165     {\r
166       if (!dasSources[i].getNickname().equals(nickName))\r
167         continue;\r
168 \r
169       DasSource ds = dasSources[i];\r
170 \r
171       text.append("<font color=\"#0000FF\">Id:</font> " + dasSources[i].getId() +\r
172                   "<br>");\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
176                   "<br>");\r
177 \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
181                   "<br>");\r
182 \r
183 \r
184       text.append("<font color=\"#0000FF\">Registered at:</font> " + dasSources[i].getRegisterDate() +\r
185                         "<br>");\r
186 \r
187       text.append("<font color=\"#0000FF\">Last successful test:</font> " + dasSources[i].getLeaseDate() +\r
188                         "<br>");\r
189 \r
190       text.append("<font color=\"#0000FF\">Labels:</font> ");\r
191       for(int s=0; s<dasSources[i].getLabels().length; s++)\r
192       {\r
193         text.append( dasSources[i].getLabels()[s]);\r
194         if(s<dasSources[i].getLabels().length-1)\r
195           text.append(",");\r
196         text.append(" ");\r
197       }\r
198       text.append("<br>");\r
199 \r
200 \r
201 \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
205       {\r
206         text.append(scap[j]);\r
207         if (j < scap.length - 1)\r
208           text.append(", ");\r
209       }\r
210       text.append("<br>");\r
211 \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
215       {\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
222 \r
223         text.append("<br>");\r
224       }\r
225 \r
226       text.append("<font color=\"#0000FF\">Description:</font> " +\r
227                   dasSources[i].getDescription() + "<br>");\r
228 \r
229 \r
230       if (dasSources[i].getHelperurl()!=null\r
231           && dasSources[i].getHelperurl().length() > 0)\r
232       {\r
233         text.append("<font color=\"#0000FF\"><a href=\"" +\r
234                     dasSources[i].getHelperurl()\r
235                     + "\">Go to site</a></font<br>");\r
236       }\r
237 \r
238       text.append("</font></html>");\r
239 \r
240       break;\r
241     }\r
242 \r
243     fullDetails.setText(text.toString());\r
244     javax.swing.SwingUtilities.invokeLater(new Runnable()\r
245     {\r
246       public void run()\r
247       {\r
248         fullDetailsScrollpane.getVerticalScrollBar().setValue(0);\r
249       }\r
250     });\r
251   }\r
252 \r
253 \r
254   public void run()\r
255   {\r
256     loadingDasSources = true;\r
257 \r
258     addLocal.setVisible(false);\r
259     refresh.setVisible(false);\r
260     progressBar.setVisible(true);\r
261     progressBar.setIndeterminate(true);\r
262 \r
263     dasSources = jalview.io.DasSequenceFeatureFetcher.getDASSources();\r
264 \r
265     appendLocalSources();\r
266 \r
267     init();\r
268 \r
269     loadingDasSources = false;\r
270 \r
271   }\r
272 \r
273   public Vector getSelectedSources()\r
274   {\r
275     Vector selected = new Vector();\r
276     for (int r = 0; r < selectedSources.size(); r++)\r
277     {\r
278         for (int i = 0; i < dasSources.length; i++)\r
279         {\r
280           if (dasSources[i].getNickname().equals(\r
281               selectedSources.elementAt(r)))\r
282           {\r
283             selected.addElement(dasSources[i]);\r
284             break;\r
285           }\r
286         }\r
287     }\r
288 \r
289     return selected;\r
290   }\r
291 \r
292   public DasSource[] getDASSource()\r
293   {\r
294     if(dasSources==null)\r
295     {\r
296      dasSources = jalview.io.DasSequenceFeatureFetcher.getDASSources();\r
297      appendLocalSources();\r
298     }\r
299 \r
300     return dasSources;\r
301   }\r
302 \r
303   public void refresh_actionPerformed(ActionEvent e)\r
304   {\r
305     saveProperties(jalview.bin.Cache.applicationProperties);\r
306 \r
307     Thread worker = new Thread(this);\r
308     worker.start();\r
309   }\r
310 \r
311   private void setCapabilities(DasSource[] sources)\r
312   {\r
313     Vector authority = new Vector();\r
314     Vector type = new Vector();\r
315     Vector label = new Vector();\r
316 \r
317     authority.addElement("Any");\r
318     type.addElement("Any");\r
319     label.addElement("Any");\r
320 \r
321     for (int i = 0; i < sources.length; i++)\r
322     {\r
323       DasSource ds = sources[i];\r
324 \r
325       DasCoordinateSystem[] dcs = ds.getCoordinateSystem();\r
326 \r
327       for (int j = 0; j < dcs.length; j++)\r
328       {\r
329         if (!type.contains(dcs[j].getCategory()))\r
330           type.addElement(dcs[j].getCategory());\r
331 \r
332         if (!authority.contains(dcs[j].getName()))\r
333           authority.addElement(dcs[j].getName());\r
334       }\r
335 \r
336       String[] slabels = ds.getLabels();\r
337       for (int s = 0; s < slabels.length; s++)\r
338       {\r
339         if (!label.contains(slabels[s]))\r
340         {\r
341           label.addElement(slabels[s]);\r
342         }\r
343       }\r
344 \r
345     }\r
346 \r
347     filter1.setListData(authority);\r
348     filter2.setListData(type);\r
349     filter3.setListData(label);\r
350 \r
351     javax.swing.SwingUtilities.invokeLater(new Runnable()\r
352     {\r
353       public void run()\r
354       {\r
355         filter1.setSelectedIndex(0);\r
356         filter2.setSelectedIndex(0);\r
357         filter3.setSelectedIndex(0);\r
358       }\r
359     });\r
360   }\r
361 \r
362   public void amendLocal(boolean newSource)\r
363   {\r
364     String url = "http://localhost:8080/", nickname = "";\r
365 \r
366     if(!newSource)\r
367     {\r
368       int selectedRow = table.getSelectionModel().getMinSelectionIndex();\r
369       nickname = table.getValueAt(selectedRow, 0).toString();\r
370       url = ((DasSource)localSources.get(nickname)).getUrl();\r
371     }\r
372 \r
373     JTextField nametf = new JTextField(nickname, 40);\r
374     JTextField urltf = new JTextField(url, 40);\r
375 \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
385 \r
386 \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
390 \r
391        if (reply != JOptionPane.OK_OPTION )\r
392        {\r
393            return;\r
394        }\r
395 \r
396        if(!urltf.getText().endsWith("/"))\r
397          urltf.setText(urltf.getText()+"/");\r
398 \r
399        Das1Source local = new Das1Source();\r
400 \r
401        local.setUrl(urltf.getText());\r
402        local.setNickname(nametf.getText());\r
403 \r
404 \r
405        if(localSources==null)\r
406          localSources = new Hashtable();\r
407 \r
408        localSources.put(local.getNickname(), local);\r
409 \r
410        if(!newSource && !nickname.equals(nametf.getText()))\r
411        {\r
412          localSources.remove(nickname);\r
413        }\r
414 \r
415        int size = dasSources.length;\r
416        int adjust = newSource ? 1 : 0;\r
417 \r
418        Object[][] data = new Object[size+adjust][2];\r
419        for (int i = 0; i < size; i++)\r
420        {\r
421          if(!newSource && dasSources[i].getNickname().equals(nickname))\r
422          {\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
427          }\r
428          else\r
429          {\r
430            data[i][0] = dasSources[i].getNickname();\r
431            data[i][1] = new Boolean(selectedSources.contains(dasSources[i].\r
432                getNickname()));\r
433          }\r
434        }\r
435 \r
436        if(newSource)\r
437        {\r
438          data[size][0] = local.getNickname();\r
439          data[size][1] = new Boolean(true);\r
440          selectedSources.add(local.getNickname());\r
441        }\r
442 \r
443        DasSource [] tmp = new DasSource[size+adjust];\r
444 \r
445        System.arraycopy(dasSources, 0, tmp, 0, size);\r
446 \r
447        if(newSource)\r
448          tmp[size] = local;\r
449 \r
450        dasSources = tmp;\r
451 \r
452        refreshTableData(data);\r
453 \r
454        SwingUtilities.invokeLater(new Runnable()\r
455        {\r
456          public void run()\r
457          {\r
458            scrollPane.getVerticalScrollBar().setValue(\r
459                scrollPane.getVerticalScrollBar().getMaximum()\r
460                );\r
461          }\r
462        });\r
463 \r
464        displayFullDetails(local.getNickname());\r
465      }\r
466 \r
467     public void editRemoveLocalSource(MouseEvent evt)\r
468     {\r
469       int selectedRow = table.getSelectionModel().getMinSelectionIndex();\r
470       if(selectedRow==-1)\r
471         return;\r
472 \r
473       String nickname = table.getValueAt(selectedRow, 0).toString();\r
474 \r
475       if (!localSources.containsKey(nickname))\r
476       {\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
481         return;\r
482       }\r
483 \r
484 \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
491     null,\r
492     options,\r
493     options[2]);\r
494 \r
495       switch(choice)\r
496       {\r
497         case 0: amendLocal(false);   break;\r
498         case 1:\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
503           int index = 0;\r
504           for (int i = 0; i < dasSources.length; i++)\r
505           {\r
506             if (dasSources[i].getNickname().equals(nickname))\r
507             {\r
508               continue;\r
509             }\r
510             else\r
511             {\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
515                   getNickname()));\r
516               index++;\r
517             }\r
518           }\r
519            dasSources = tmp;\r
520            refreshTableData(data);\r
521            SwingUtilities.invokeLater(new Runnable()\r
522            {\r
523              public void run()\r
524              {\r
525                scrollPane.getVerticalScrollBar().setValue(\r
526                    scrollPane.getVerticalScrollBar().getMaximum()\r
527                    );\r
528              }\r
529            });\r
530 \r
531           break;\r
532       }\r
533     }\r
534 \r
535     void appendLocalSources()\r
536     {\r
537       if(localSources==null)\r
538         return;\r
539 \r
540       int size = dasSources!=null ? dasSources.length : 0;\r
541       int lsize = localSources.size();\r
542 \r
543       Object[][] data = new Object[size+lsize][2];\r
544       for (int i = 0; i < size; i++)\r
545       {\r
546         data[i][0] = dasSources[i].getNickname();\r
547         data[i][1] = new Boolean(selectedSources.contains(dasSources[i].\r
548             getNickname()));\r
549       }\r
550 \r
551       DasSource [] tmp = new DasSource[size+lsize];\r
552       if(dasSources!=null)\r
553         System.arraycopy(dasSources, 0, tmp, 0, size);\r
554 \r
555       Enumeration en = localSources.keys();\r
556       int index = size;\r
557       while(en.hasMoreElements())\r
558       {\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
565 \r
566         index++;\r
567       }\r
568 \r
569       dasSources = tmp;\r
570 \r
571       refreshTableData(data);\r
572   }\r
573 \r
574   public void valueChanged(ListSelectionEvent evt)\r
575   {\r
576     //Called when the MainTable selection changes\r
577     if (evt.getValueIsAdjusting() )\r
578     {\r
579       return;\r
580     }\r
581 \r
582 \r
583     displayFullDetails(null);\r
584 \r
585     // Filter the displayed data sources\r
586     int dSize = dasSources.length;\r
587 \r
588 \r
589     ArrayList names = new ArrayList();\r
590     ArrayList selected = new ArrayList();\r
591     DasSource ds;\r
592 \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
597 \r
598     for (int i = 0; i < dSize; i++)\r
599     {\r
600       ds = dasSources[i];\r
601       DasCoordinateSystem[] dcs = ds.getCoordinateSystem();\r
602 \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
607       {\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
614         continue;\r
615       }\r
616 \r
617 \r
618       if (!selectedInList(dummyFeatureList, ds.getCapabilities())\r
619       ||  !selectedInList(filter3.getSelectedValues(),\r
620                           ds.getLabels()))\r
621       {\r
622         continue;\r
623       }\r
624 \r
625       for (int j = 0; j < dcs.length; j++)\r
626       {\r
627         if (   selectedInList(filter1.getSelectedValues(),\r
628                            new String[]\r
629                            {dcs[j].getName()})\r
630             && selectedInList(filter2.getSelectedValues(),\r
631                               new String[]\r
632                               {dcs[j].getCategory()}))\r
633         {\r
634           names.add(ds.getNickname());\r
635           selected.add(new Boolean(\r
636               selectedSources.contains(ds.getNickname())));\r
637           break;\r
638         }\r
639       }\r
640     }\r
641 \r
642     dSize = names.size();\r
643     Object[][] data = new Object[dSize][2];\r
644     for (int d = 0; d < dSize; d++)\r
645     {\r
646       data[d][0] = names.get(d);\r
647       data[d][1] = selected.get(d);\r
648     }\r
649 \r
650     refreshTableData(data);\r
651   }\r
652 \r
653   boolean selectedInList(Object [] selection, String[] items)\r
654   {\r
655     for (int i = 0; i < selection.length; i++)\r
656     {\r
657       if (selection[i].equals("Any") )\r
658         return true;\r
659 \r
660       for (int j = 0; j < items.length; j++)\r
661       {\r
662         if (selection[i].equals(items[j]))\r
663           return true;\r
664       }\r
665     }\r
666 \r
667     return false;\r
668   }\r
669 \r
670   void setSelectedFromProperties()\r
671   {\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
676      {\r
677        selectedSources.addElement(st.nextToken());\r
678      }\r
679 \r
680      String local = jalview.bin.Cache.getProperty("DAS_LOCAL_SOURCE");\r
681      if(local!=null)\r
682      {\r
683        if(localSources == null)\r
684          localSources = new Hashtable();\r
685 \r
686        st = new StringTokenizer(local, "\t");\r
687        while(st.hasMoreTokens())\r
688        {\r
689          String token = st.nextToken();\r
690          int bar = token.indexOf("|");\r
691          Das1Source source = new Das1Source();\r
692 \r
693          source.setUrl(token.substring(bar + 1));\r
694          source.setNickname(token.substring(0, bar));\r
695 \r
696          localSources.put(source.getNickname(), source);\r
697        }\r
698      }\r
699   }\r
700 \r
701   public void reset_actionPerformed(ActionEvent e)\r
702   {\r
703     registryURL.setText(DEFAULT_REGISTRY);\r
704   }\r
705 \r
706   public void saveProperties(Properties properties)\r
707   {\r
708     if (registryURL.getText() == null || registryURL.getText().length() < 1)\r
709       properties.remove("DAS_REGISTRY_URL");\r
710     else\r
711       properties.setProperty("DAS_REGISTRY_URL", registryURL.getText());\r
712 \r
713     StringBuffer sb = new StringBuffer();\r
714     for(int r=0; r<table.getModel().getRowCount(); r++)\r
715     {\r
716       if( ((Boolean)table.getValueAt(r,1)).booleanValue())\r
717       {\r
718         sb.append(table.getValueAt(r,0)+"\t");\r
719       }\r
720     }\r
721 \r
722     properties.setProperty("DAS_ACTIVE_SOURCE", sb.toString() );\r
723 \r
724     if(localSources!=null)\r
725     {\r
726       sb = new StringBuffer();\r
727       Enumeration en = localSources.keys();\r
728       while(en.hasMoreElements())\r
729       {\r
730         String token = en.nextElement().toString();\r
731         sb.append(token+"|"\r
732                   + ((DasSource)localSources.get(token)).getUrl()\r
733                   +"\t");\r
734       }\r
735 \r
736       properties.setProperty("DAS_LOCAL_SOURCE", sb.toString());\r
737     }\r
738 \r
739   }\r
740 \r
741   class DASTableModel\r
742       extends AbstractTableModel\r
743   {\r
744 \r
745     public DASTableModel(Object[][] data)\r
746     {\r
747       this.data = data;\r
748     }\r
749 \r
750     private String[] columnNames = new String[]  {"Nickname", "Use Source"};\r
751 \r
752     private Object[][] data;\r
753 \r
754     public int getColumnCount()\r
755     {\r
756       return columnNames.length;\r
757     }\r
758 \r
759     public int getRowCount()\r
760     {\r
761       return data.length;\r
762     }\r
763 \r
764     public String getColumnName(int col)\r
765     {\r
766       return columnNames[col];\r
767     }\r
768 \r
769     public Object getValueAt(int row, int col)\r
770     {\r
771       return data[row][col];\r
772     }\r
773 \r
774     /*\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
779      */\r
780     public Class getColumnClass(int c)\r
781     {\r
782       return getValueAt(0, c).getClass();\r
783     }\r
784 \r
785     /*\r
786      * Don't need to implement this method unless your table's\r
787      * editable.\r
788      */\r
789     public boolean isCellEditable(int row, int col)\r
790     {\r
791       //Note that the data/cell address is constant,\r
792       //no matter where the cell appears onscreen.\r
793       return col == 1;\r
794 \r
795     }\r
796 \r
797     /*\r
798      * Don't need to implement this method unless your table's\r
799      * data can change.\r
800      */\r
801     public void setValueAt(Object value, int row, int col)\r
802     {\r
803       data[row][col] = value;\r
804       fireTableCellUpdated(row, col);\r
805 \r
806       String name = getValueAt(row,0).toString();\r
807       boolean selected = ((Boolean)value).booleanValue();\r
808 \r
809       if(selectedSources.contains(name) && !selected)\r
810         selectedSources.remove(name);\r
811 \r
812       if(!selectedSources.contains(name) && selected)\r
813         selectedSources.add(name);\r
814     }\r
815   }\r
816 }\r
817 \r
818 \r