/[xulu]/trunk/src/appl/parallel/starter/client/XuluStarterController.java
ViewVC logotype

Annotation of /trunk/src/appl/parallel/starter/client/XuluStarterController.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (hide annotations)
Wed Feb 25 11:54:01 2009 UTC (15 years, 9 months ago) by mojays
File size: 3938 byte(s)
First Commit, corresponds to Revision 1008 of Wikisquare-SVN 
1 mojays 2 package appl.parallel.starter.client;
2    
3     import java.awt.Color;
4     import java.awt.Component;
5     import java.awt.event.ActionEvent;
6     import java.awt.event.ActionListener;
7     import java.rmi.RemoteException;
8     import java.util.Vector;
9    
10     import javax.swing.DefaultListCellRenderer;
11     import javax.swing.DefaultListModel;
12     import javax.swing.JList;
13    
14     import org.apache.log4j.LogManager;
15     import org.apache.log4j.Logger;
16    
17     import appl.parallel.client.RemoteExecutionController;
18     import appl.parallel.services.HostnameDiscoveryService;
19     import appl.parallel.starter.Starter;
20     import appl.parallel.starter.server.XuluServerStarter;
21    
22     /**
23     * This is the Controller for the {@link XuluStarterControllerFrame}, which is
24     * the user interface for the {@link XuluServerStarter}. All events are handled
25     * here. <br>
26     *
27     * The controller updates a list of {@link Starter}s it finds in the network.
28     * At the moment is uses the {@link HostnameDiscoveryService} to discover
29     * starters.
30     *
31     * @see HostnameDiscoveryService#getStarterContainers()
32     * @author Dominik Appl
33     */
34     public class XuluStarterController implements ActionListener {
35    
36     Logger LOG = LogManager.getLogger(this.getClass().getName());
37    
38     private XuluStarterClientPanel GUI;
39    
40     private HostnameDiscoveryService discovery;
41    
42     private Vector<StarterContainer> currentData;
43    
44     /**
45     *
46     */
47     public XuluStarterController() {
48     GUI = new XuluStarterClientPanel();
49     // start simpleDiscovery service
50     discovery = new HostnameDiscoveryService();
51     discovery.startService();
52     updateList();
53     initGUI();
54     }
55    
56     private void initGUI() {
57     GUI.startButton.addActionListener(this);
58     GUI.stopButton.addActionListener(this);
59     GUI.refreshButton.addActionListener(this);
60     GUI.restartButton.addActionListener(this);
61     }
62    
63     public XuluStarterClientPanel getPanel() {
64     return GUI;
65     }
66    
67     /**
68     *
69     */
70     private void updateList() {
71     currentData = discovery.getStarterContainers();
72     GUI.serverList.setCellRenderer(new MyCellRenderer(currentData));
73     // DefaultListModel serverListModel = new DefaultListModel();
74     // GUI.serverList.setModel(serverListModel);
75     GUI.serverList.setListData(currentData);
76     }
77    
78     private Starter getSelectedStarter() {
79     Object value = GUI.serverList.getSelectedValue();
80     if (value != null) {
81     return ((StarterContainer) value).getStarter();
82     }
83     return null;
84     }
85    
86     public void actionPerformed(ActionEvent e) {
87     if (e.getSource() == GUI.refreshButton) {
88     updateList();
89     }
90     Starter selectedStarter = getSelectedStarter();
91     // if nothing selected: return
92     if (selectedStarter == null)
93     return;
94     try {
95     if (e.getSource() == GUI.startButton) {
96     selectedStarter.start();
97     updateList();
98     }
99     if (e.getSource() == GUI.stopButton) {
100     selectedStarter.stop();
101     updateList();
102     }
103     if (e.getSource() == GUI.restartButton) {
104     selectedStarter.restart();
105     updateList();
106     }
107     } catch (RemoteException e1) {
108     LOG
109     .error(
110     "Could not access selected Starter. Remote Exeception occured.",
111     e1);
112     }
113     }
114    
115     class MyCellRenderer extends DefaultListCellRenderer {
116     private final Vector<StarterContainer> containers;
117    
118     public MyCellRenderer(Vector<StarterContainer> containers) {
119     this.containers = containers;
120     // TODO Auto-generated constructor stub
121     }
122    
123     @Override
124     public Component getListCellRendererComponent(JList list, Object value,
125     int index, boolean isSelected, boolean cellHasFocus) {
126     // TODO Auto-generated method stub
127     Component listCellRendererComponent = super
128     .getListCellRendererComponent(list, value, index,
129     isSelected, cellHasFocus);
130     if (!isSelected) {
131     if (containers.get(index).isServerRunning())
132     listCellRendererComponent.setBackground(Color.green);
133     else
134     listCellRendererComponent.setBackground(Color.red);
135     }
136     return listCellRendererComponent;
137     }
138    
139     }
140     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26