001: // ServerList.java
002: // $Id: ServerList.java,v 1.10 2000/08/16 21:37:31 ylafon Exp $
003: // (c) COPYRIGHT MIT and INRIA, 1998.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005:
006: package org.w3c.jigadmin.gui.slist;
007:
008: import java.awt.Insets;
009: import java.awt.GridLayout;
010: import java.awt.event.ActionListener;
011: import java.awt.event.ActionEvent;
012:
013: import javax.swing.JPanel;
014: import javax.swing.BorderFactory;
015: import javax.swing.JButton;
016: import javax.swing.ImageIcon;
017: import javax.swing.AbstractButton;
018:
019: import javax.swing.event.EventListenerList;
020:
021: import org.w3c.jigadmin.RemoteResourceWrapper;
022: import org.w3c.jigadmin.gui.Message;
023:
024: import org.w3c.jigsaw.admin.RemoteAccessException;
025:
026: import org.w3c.tools.widgets.Utilities;
027:
028: /**
029: * Manage a list of Jigsaw server.
030: * @version $Revision: 1.10 $
031: * @author Benoît Mahé (bmahe@w3.org)
032: */
033: public class ServerList extends JPanel {
034:
035: ServerListModelInterface model = null;
036: EventListenerList listenerList = null;
037:
038: ImageIcon icon = null;
039:
040: /**
041: * Our internal ActionListener.
042: */
043: ActionListener al = new ActionListener() {
044: public void actionPerformed(ActionEvent e) {
045: fireServerSelectedEvent(e.getActionCommand());
046: }
047: };
048:
049: /**
050: * Get the Server List Model.
051: * @return a ServerListModelInterface instance.
052: */
053: public ServerListModelInterface getModel() {
054: return model;
055: }
056:
057: /**
058: * Add a ServerListListener.
059: * @param listener the ServerListListener to add.
060: */
061: public void addServerListListener(ServerListListener listener) {
062: listenerList.add(ServerListListener.class, listener);
063: }
064:
065: /**
066: * Remove a ServerListListener.
067: * @param listener the ServerListListener to remove.
068: */
069: public void removeServerListListener(ServerListListener listener) {
070: listenerList.remove(ServerListListener.class, listener);
071: }
072:
073: /**
074: * Fire a ServerSelectedEvent for the given server name.
075: * @param name the server name.
076: */
077: protected void fireServerSelectedEvent(String name) {
078: RemoteResourceWrapper server = null;
079: server = model.getServer(name);
080: Object listeners[] = listenerList.getListenerList();
081: for (int i = listeners.length - 2; i >= 0; i -= 2) {
082: if (listeners[i] == ServerListListener.class) {
083: ((ServerListListener) listeners[i + 1]).serverSelected(
084: name, server);
085: }
086: }
087: }
088:
089: /**
090: * Build the interface.
091: */
092: protected void build() {
093: String servers[] = model.getServers();
094: int len = servers.length;
095: JButton b = null;
096: setLayout(new GridLayout(len, 1));
097:
098: for (int i = 0; i < len; i++) {
099: b = new JButton(servers[i], icon);
100: b.setVerticalTextPosition(AbstractButton.BOTTOM);
101: b.setHorizontalTextPosition(AbstractButton.CENTER);
102: b.setActionCommand(servers[i]);
103: b.addActionListener(al);
104: b.setMargin(Utilities.insets2);
105: b.setToolTipText("Load or reload the configuration of "
106: + servers[i]);
107: //b.setBorder(BorderFactory.createRaisedBevelBorder());
108: add(b);
109: }
110: }
111:
112: /**
113: * Constructor.
114: * @param model The Server list model.
115: */
116: public ServerList(ServerListModelInterface model) {
117: this (model, null);
118: }
119:
120: /**
121: * Constructor.
122: * @param model The Server list model.
123: * @param icon. The server icon.
124: */
125: public ServerList(ServerListModelInterface model, ImageIcon icon) {
126: this .icon = icon;
127: this .model = model;
128: listenerList = new EventListenerList();
129: build();
130: }
131:
132: /**
133: * Constructor.
134: * @param root The root RemoteResourceWrapper
135: */
136: public ServerList(RemoteResourceWrapper root)
137: throws RemoteAccessException {
138: this (root, null);
139: }
140:
141: /**
142: * Constructor.
143: * @param root The root RemoteResourceWrapper
144: * @param icon. The server icon.
145: */
146: public ServerList(RemoteResourceWrapper root, ImageIcon icon)
147: throws RemoteAccessException {
148: this .icon = icon;
149: this .model = new ServerListModel(root);
150: listenerList = new EventListenerList();
151: build();
152: }
153:
154: }
|