1 7 package org.ejtools.graph.service; 8 9 import java.util.Arrays ; 10 import java.util.List ; 11 import java.util.ResourceBundle ; 12 13 import org.ejtools.graph.dialog.SelectGraphDialog; 14 import org.ejtools.graph.frame.GraphInternalFrame; 15 16 22 public abstract class GraphConsumerSelector 23 { 24 25 private static ResourceBundle resources = ResourceBundle.getBundle("org.ejtools.graph.GraphService"); 26 27 28 35 public static GraphConsumer select(GraphConsumerMediator mediator, String 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 64 public static GraphConsumer selectWithDialog(GraphConsumerMediator mediator) 65 { 66 GraphConsumer[] consumers = mediator.getGraphConsumers(); 67 List choices = Arrays.asList(consumers); 68 Object 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 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 |