KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > graph > service > GraphConsumerSelector


1 /*
2  * EJTools, the Enterprise Java Tools
3  *
4  * Distributable under LGPL license.
5  * See terms of license at www.gnu.org.
6  */

7 package org.ejtools.graph.service;
8
9 import java.util.Arrays JavaDoc;
10 import java.util.List JavaDoc;
11 import java.util.ResourceBundle JavaDoc;
12
13 import org.ejtools.graph.dialog.SelectGraphDialog;
14 import org.ejtools.graph.frame.GraphInternalFrame;
15
16 /**
17  * Description of the Class
18  *
19  * @author Laurent Etiemble
20  * @version $Revision: 1.5 $
21  */

22 public abstract class GraphConsumerSelector
23 {
24    /** Description of the Field */
25    private static ResourceBundle JavaDoc resources = ResourceBundle.getBundle("org.ejtools.graph.GraphService");
26
27
28    /**
29     * Description of the Method
30     *
31     * @param mediator Description of the Parameter
32     * @param name Description of the Parameter
33     * @return Description of the Return Value
34     */

35    public static GraphConsumer select(GraphConsumerMediator mediator, String JavaDoc name)
36    {
37       GraphConsumer[] consumers = mediator.getGraphConsumers();
38       GraphConsumer consumer = null;
39
40       for (int i = 0; i < consumers.length; i++)
41       {
42          GraphConsumer gc = consumers[i];
43          if (gc.toString().equals(name))
44          {
45             consumer = gc;
46          }
47       }
48
49       if (consumer == null)
50       {
51          GraphInternalFrame frame = new GraphInternalFrame();
52          frame.setName(name);
53          consumer = frame;
54       }
55
56       return consumer;
57    }
58
59
60    /**
61     * @param mediator Description of the Parameter
62     * @return Description of the Return Value
63     */

64    public static GraphConsumer selectWithDialog(GraphConsumerMediator mediator)
65    {
66       GraphConsumer[] consumers = mediator.getGraphConsumers();
67       List JavaDoc choices = Arrays.asList(consumers);
68       Object JavaDoc initial = resources.getString("graph.text.untitled");
69       if (choices.size() > 0)
70       {
71          initial = choices.get(0);
72       }
73       SelectGraphDialog dialog = new SelectGraphDialog(null, choices.toArray(), initial);
74       dialog.show();
75       Object JavaDoc selectedValue = dialog.getSelectedValue();
76
77       if (selectedValue == null)
78       {
79          return null;
80       }
81
82       int idx = choices.indexOf(selectedValue);
83       GraphConsumer consumer = null;
84       if (idx < 0)
85       {
86          GraphInternalFrame frame = new GraphInternalFrame();
87          frame.setName("" + selectedValue);
88          consumer = frame;
89       }
90       else
91       {
92          consumer = (GraphConsumer) choices.get(idx);
93       }
94       return consumer;
95    }
96 }
97
Popular Tags