001: // PropertiesServerHelper.java
002: // $Id: PropertiesServerHelper.java,v 1.11 2000/08/16 21:37:30 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.editors;
007:
008: import java.awt.Insets;
009: import java.awt.GridLayout;
010: import java.awt.BorderLayout;
011: import java.awt.CardLayout;
012: import java.awt.Cursor;
013: import java.awt.Component;
014: import java.awt.event.ActionListener;
015: import java.awt.event.ActionEvent;
016:
017: import javax.swing.JPanel;
018: import javax.swing.JButton;
019: import javax.swing.AbstractButton;
020: import javax.swing.BorderFactory;
021: import javax.swing.JTabbedPane;
022: import javax.swing.border.TitledBorder;
023: import javax.swing.event.ChangeListener;
024: import javax.swing.event.ChangeEvent;
025:
026: import java.util.Properties;
027: import java.util.Hashtable;
028:
029: import org.w3c.jigadmin.RemoteResourceWrapper;
030: import org.w3c.jigadmin.PropertyManager;
031: import org.w3c.jigadmin.gui.Message;
032:
033: import org.w3c.jigsaw.admin.RemoteAccessException;
034:
035: import org.w3c.tools.widgets.Utilities;
036: import org.w3c.tools.sorter.Sorter;
037:
038: /**
039: * The server helper dedicated to the properties.
040: * @version $Revision: 1.11 $
041: * @author Benoît Mahé (bmahe@w3.org)
042: */
043: public class PropertiesServerHelper extends JPanel implements
044: ServerHelperInterface, ChangeListener {
045: protected String name = null;
046: protected String tooltip = null;
047: protected RemoteResourceWrapper root = null;
048: protected String properties[] = null;
049: protected JPanel cards = null;
050: protected Hashtable helpers = null;
051: protected String selected = null;
052:
053: /**
054: * Initialize this editor.
055: * @param name the editor name
056: * @param rrw the RemoteResourceWrapper wrapping the editor node.
057: * @param p the editor properties
058: */
059: public void initialize(String name, RemoteResourceWrapper rrw,
060: Properties p) {
061: this .name = name;
062: this .root = rrw;
063: this .tooltip = (String) p.get(TOOLTIP_P);
064: build();
065: }
066:
067: /**
068: * ChangeListener implementation.
069: * @param e a ChangeEvent
070: */
071: public void stateChanged(ChangeEvent e) {
072: Object source = e.getSource();
073: if (source instanceof JTabbedPane) {
074: JTabbedPane pane = (JTabbedPane) source;
075: if (pane.getSelectedComponent() == this ) {
076: removeAll();
077: invalidate();
078: build();
079: if (selected != null)
080: select(selected);
081: validate();
082: }
083: }
084:
085: }
086:
087: /**
088: * Build the interface.
089: */
090: protected void build() {
091: int len = 0;
092: JButton b = null;
093:
094: helpers = new Hashtable();
095:
096: try {
097: properties = root.getResource()
098: .enumerateResourceIdentifiers();
099: Sorter.sortStringArray(properties, true);
100: } catch (RemoteAccessException ex) {
101: Message.showErrorMessage(this , ex);
102: }
103: if (properties == null)
104: return;
105:
106: setLayout(new BorderLayout());
107: len = properties.length;
108: JPanel buttons = new JPanel(new GridLayout(len, 1));
109: cards = new JPanel(new CardLayout());
110:
111: ActionListener listener = new ActionListener() {
112: public void actionPerformed(ActionEvent e) {
113: root.getServerBrowser().setCursor(Cursor.WAIT_CURSOR);
114: String property = e.getActionCommand();
115: select(property);
116: root.getServerBrowser()
117: .setCursor(Cursor.DEFAULT_CURSOR);
118: }
119: };
120:
121: for (int i = 0; i < len; i++) {
122: String name = properties[i];
123: //button
124: b = new JButton(name);
125: b.setVerticalTextPosition(AbstractButton.CENTER);
126: b.setHorizontalTextPosition(AbstractButton.CENTER);
127: b.setActionCommand(name);
128: b.addActionListener(listener);
129: b.setMargin(Utilities.insets2);
130: buttons.add(b);
131: //attribute helper
132: JPanel p1 = new JPanel(new GridLayout(1, 1));
133: p1.setBorder(BorderFactory.createTitledBorder(name));
134: helpers.put(name, p1);
135: cards.add(name, p1);
136: }
137: JPanel p1 = new JPanel(new BorderLayout());
138: p1.add(buttons, BorderLayout.NORTH);
139: p1.setBorder(BorderFactory.createTitledBorder("Properties"));
140: add(p1, BorderLayout.WEST);
141: add(cards, BorderLayout.CENTER);
142: }
143:
144: protected void select(String name) {
145: selected = name;
146: JPanel p1 = (JPanel) helpers.get(name);
147: p1.removeAll();
148: try {
149: RemoteResourceWrapper rrw = root.getChildResource(name);
150: AttributesHelper helper = new AttributesHelper();
151: PropertyManager pm = PropertyManager.getPropertyManager();
152: Properties props = pm.getEditorProperties(rrw);
153: helper.initialize(rrw, props);
154: p1.add(helper.getComponent());
155: p1.invalidate();
156: p1.validate();
157: } catch (RemoteAccessException ex) {
158: Message.showErrorMessage(this , ex);
159: }
160: ((CardLayout) cards.getLayout()).show(cards, name);
161: }
162:
163: /**
164: * Get the helper name.
165: * @return a String instance
166: */
167: public String getName() {
168: return name;
169: }
170:
171: /**
172: * Get the helper tooltip
173: * @return a String
174: */
175: public String getToolTip() {
176: return tooltip;
177: }
178:
179: /**
180: * Get the Component.
181: * @return a Component instance
182: */
183: public Component getComponent() {
184: return this ;
185: }
186:
187: /**
188: * Constructor.
189: */
190: public PropertiesServerHelper() {
191: //new instance
192: }
193:
194: }
|