001: // ControlHelper.java
002: // $Id: ControlHelper.java,v 1.21 2000/08/16 21:37:26 ylafon Exp $
003: // (c) COPYRIGHT MIT and INRIA, 1997.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005:
006: package org.w3c.jigadm.editors;
007:
008: import java.awt.BorderLayout;
009: import java.awt.Color;
010: import java.awt.Component;
011: import java.awt.Container;
012: import java.awt.GridBagConstraints;
013: import java.awt.GridBagLayout;
014: import java.awt.Image;
015: import java.awt.Insets;
016: import java.awt.Label;
017: import java.awt.Panel;
018: import java.awt.ScrollPane;
019: import java.awt.Toolkit;
020:
021: import java.awt.event.ActionEvent;
022: import java.awt.event.ActionListener;
023: import java.awt.event.ComponentEvent;
024: import java.awt.event.MouseAdapter;
025: import java.awt.event.MouseEvent;
026:
027: import java.util.EventObject;
028: import java.util.Properties;
029:
030: import org.w3c.jigadm.PropertyManager;
031: import org.w3c.jigadm.RemoteResourceWrapper;
032:
033: import org.w3c.jigsaw.admin.RemoteAccessException;
034: import org.w3c.jigsaw.admin.RemoteResource;
035:
036: import org.w3c.tools.resources.Attribute;
037:
038: import org.w3c.tools.widgets.BorderPanel;
039: import org.w3c.tools.widgets.ImageButton;
040:
041: public class ControlHelper extends ResourceHelper {
042:
043: class ControlListener implements ActionListener {
044:
045: public void actionPerformed(ActionEvent ae) {
046: if (ae.getSource() instanceof ImageButton) {
047: executeAction(ae.getActionCommand());
048: }
049: }
050: }
051:
052: class MouseButtonListener extends MouseAdapter {
053:
054: public void mouseEntered(MouseEvent e) {
055: Component comp = e.getComponent();
056: if (comp instanceof ImageButton) {
057: String action = ((ImageButton) comp).getActionCommand();
058:
059: if (action.equals(CHECKPOINT_L)) {
060: setMessage("Start the Checkpoint resource.");
061: } else if (action.equals(SAVE_L)) {
062: setMessage("Save the current configuration.");
063: } else if (action.equals(STOP_L)) {
064: setMessage("Stop the server.");
065: } else if (action.equals(RESTART_L)) {
066: setMessage("Restart the server "
067: + "(doesn't work yet).");
068: }
069: }
070: }
071:
072: public void mouseExited(MouseEvent e) {
073: setMessage("");
074: }
075:
076: }
077:
078: protected static final String CHECKPOINT_L = "Checkpoint";
079: protected static final String SAVE_L = "Save";
080: protected static final String STOP_L = "Stop";
081: protected static final String RESTART_L = "Restart";
082:
083: private RemoteResourceWrapper rrw = null;
084: private boolean initialized = false;
085: protected Panel widget = null;
086: protected Label controlLabel = null;
087:
088: public void commitChanges() {
089: }
090:
091: public boolean hasChanged() {
092: return false;
093: }
094:
095: public void resetChanges() {
096: }
097:
098: public void clearChanged() {
099: }
100:
101: public Component getComponent() {
102: return widget;
103: }
104:
105: public final String getTitle() {
106: return "Control";
107: }
108:
109: public void setMessage(String msg) {
110: controlLabel.setText(msg);
111: }
112:
113: public ControlHelper() {
114: widget = new BorderPanel(BorderPanel.LOWERED, 2);
115: widget.setLayout(new BorderLayout());
116: }
117:
118: protected void executeAction(String action) {
119: try {
120: setMessage(action + " ...");
121: rrw.getResource().loadResource(action);
122: setMessage(action + " done.");
123: } catch (Exception ex) {
124: ex.printStackTrace();
125: errorPopup("Error", ex);
126: }
127: }
128:
129: protected Image getIcon(PropertyManager pm, String name) {
130: return Toolkit.getDefaultToolkit().getImage(
131: pm.getIconLocation(name));
132: }
133:
134: public void initControlPanel() {
135: Image checkpoint_im, save_im, stop_im, restart_im;
136: ImageButton ib;
137: Panel tfp;
138: Label l;
139: MouseButtonListener mbl = new MouseButtonListener();
140: ControlListener cl = new ControlListener();
141: Panel ControlPanel = new Panel(new BorderLayout());
142: PropertyManager pm = PropertyManager.getPropertyManager();
143: ScrollPane fsp = new ScrollPane();
144: GridBagLayout gbl = new GridBagLayout();
145: GridBagConstraints gbc = new GridBagConstraints();
146: Panel fspp = new Panel(gbl);
147: gbc.insets = new Insets(5, 0, 0, 0);
148: fsp.add(fspp);
149:
150: gbc.fill = GridBagConstraints.HORIZONTAL;
151: gbc.weightx = 0;
152: gbc.weighty = 0;
153:
154: checkpoint_im = getIcon(pm, "checkpoint");
155: save_im = getIcon(pm, "save");
156: stop_im = getIcon(pm, "stop");
157: restart_im = getIcon(pm, "restart");
158:
159: // Checkpoint
160: ib = new ImageButton(checkpoint_im, CHECKPOINT_L);
161: ib.addActionListener(cl);
162: ib.addMouseListener(mbl);
163: gbc.gridwidth = 1;
164: gbl.setConstraints(ib, gbc);
165: fspp.add(ib);
166: l = new Label(CHECKPOINT_L);
167: gbc.gridwidth = GridBagConstraints.REMAINDER;
168: gbl.setConstraints(l, gbc);
169: fspp.add(l);
170:
171: //Save
172: ib = new ImageButton(save_im, SAVE_L);
173: ib.addActionListener(cl);
174: ib.addMouseListener(mbl);
175: gbc.gridwidth = 1;
176: gbl.setConstraints(ib, gbc);
177: fspp.add(ib);
178:
179: l = new Label(SAVE_L);
180: gbc.gridwidth = GridBagConstraints.REMAINDER;
181: gbl.setConstraints(l, gbc);
182: fspp.add(l);
183:
184: //Stop
185: ib = new ImageButton(stop_im, STOP_L);
186: ib.addActionListener(cl);
187: ib.addMouseListener(mbl);
188: gbc.gridwidth = 1;
189: gbl.setConstraints(ib, gbc);
190: fspp.add(ib);
191:
192: l = new Label(STOP_L);
193: gbc.gridwidth = GridBagConstraints.REMAINDER;
194: gbl.setConstraints(l, gbc);
195: fspp.add(l);
196:
197: //Restart
198: ib = new ImageButton(restart_im, RESTART_L);
199: ib.addActionListener(cl);
200: ib.addMouseListener(mbl);
201: gbc.gridwidth = 1;
202: gbl.setConstraints(ib, gbc);
203: fspp.add(ib);
204:
205: l = new Label(RESTART_L);
206: gbc.gridwidth = GridBagConstraints.REMAINDER;
207: gbl.setConstraints(l, gbc);
208: fspp.add(l);
209:
210: ControlPanel.add("Center", fspp);
211: widget.add("Center", ControlPanel);
212: controlLabel = new Label("", Label.CENTER);
213: controlLabel.setBackground(Color.gray);
214: controlLabel.setForeground(Color.white);
215: BorderPanel bpcl = new BorderPanel(BorderPanel.IN, 2);
216: bpcl.setLayout(new BorderLayout());
217: bpcl.add(controlLabel, "Center");
218: widget.add("South", bpcl);
219: widget.validate();
220: widget.setVisible(true);
221: }
222:
223: /**
224: * initialize the editor
225: * @exception RemoteAccessException if a remote access error occurs.
226: */
227: public void initialize(RemoteResourceWrapper rrw, Properties pr)
228: throws RemoteAccessException {
229: this .rrw = rrw;
230: if (!initialized)
231: initialized = true;
232: else
233: return;
234: initControlPanel();
235: }
236: }
|