001: // SpaceServerHelper.java
002: // $Id: SpaceServerHelper.java,v 1.22 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.editors;
007:
008: import javax.swing.JDesktopPane;
009: import javax.swing.JScrollPane;
010: import javax.swing.BorderFactory;
011: import javax.swing.JInternalFrame;
012: import javax.swing.JTabbedPane;
013: import javax.swing.JLayeredPane;
014: import javax.swing.JOptionPane;
015: import javax.swing.border.BevelBorder;
016:
017: import java.awt.Component;
018: import java.awt.GridLayout;
019: import java.awt.Container;
020:
021: import java.util.Properties;
022: import java.util.Hashtable;
023: import java.util.Vector;
024: import java.util.Enumeration;
025:
026: import org.w3c.jigadmin.RemoteResourceWrapper;
027: import org.w3c.jigadmin.PropertyManager;
028: import org.w3c.jigadmin.gui.Message;
029: import org.w3c.jigadmin.widgets.DraggableList;
030: import org.w3c.jigadmin.events.ResourceActionListener;
031: import org.w3c.jigadmin.events.ResourceActionEvent;
032:
033: import org.w3c.jigsaw.admin.RemoteAccessException;
034:
035: import org.w3c.tools.sorter.Sorter;
036:
037: /**
038: * Server Helper for resources space.
039: * @version $Revision: 1.22 $
040: * @author Benoît Mahé (bmahe@w3.org)
041: */
042: public class SpaceServerHelper extends JDesktopPane implements
043: ServerHelperInterface, ResourceActionListener {
044:
045: protected String name = null;
046: protected String tooltip = null;
047: protected RemoteResourceWrapper root = null;
048: protected ResourceTreeBrowser tree = null;
049: protected JTabbedPane tabbedPane = null;
050: protected JScrollPane treeview = null;
051: protected JInternalFrame iframe = 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: * Get a draggable JList of ResourceCell
069: * @param cells a Vector of ResourceCell
070: * @return A DraggableList instance
071: */
072: protected DraggableList getResourceList(Vector cells) {
073: DraggableList list = new DraggableList(cells);
074: list.setCellRenderer(new ResourceCellRenderer());
075: return list;
076: }
077:
078: /**
079: * Get the Internal Frame containing frame & resource lists
080: * @return A JInternalFrame instance
081: */
082: protected JInternalFrame getInternalFrame() {
083: PropertyManager pm = PropertyManager.getPropertyManager();
084: JInternalFrame frame = new JInternalFrame(
085: "Available Resources", true, //resizable
086: false, //closable
087: true, //maximizable
088: true);//iconifiable
089: tabbedPane = new JTabbedPane();
090: //Resource list
091: Hashtable resources = pm.getResources();
092: Enumeration e = (Sorter.sortStringEnumeration(resources.keys()))
093: .elements();
094: Vector cells = new Vector(10);
095: while (e.hasMoreElements()) {
096: String name = (String) e.nextElement();
097: ResourceCell cell = new ResourceCell(name,
098: (String) resources.get(name));
099: cells.addElement(cell);
100: }
101: DraggableList list = getResourceList(cells);
102: JScrollPane scroll = new JScrollPane(list);
103: tabbedPane.addTab("Resources", null, scroll,
104: "Resources available");
105: //frames
106: resources = pm.getFrames();
107: e = (Sorter.sortStringEnumeration(resources.keys())).elements();
108: cells = new Vector(10);
109: while (e.hasMoreElements()) {
110: String name = (String) e.nextElement();
111: ResourceCell cell = new ResourceCell(name,
112: (String) resources.get(name));
113: cells.addElement(cell);
114: }
115: list = getResourceList(cells);
116: scroll = new JScrollPane(list);
117: tabbedPane.addTab("Frames", null, scroll,
118: "Frames and Filters available");
119: frame.getContentPane().add(tabbedPane);
120: frame.setSize(350, 410);
121: return frame;
122: }
123:
124: /**
125: * A resource action occured.
126: * @param e the ResourceActionEvent
127: */
128: public void resourceActionPerformed(ResourceActionEvent e) {
129: tree.resourceActionPerformed(e);
130: }
131:
132: /**
133: * Return a new ResourceTreeBrowser.
134: * @return a ResourceTreeBrowser instance
135: */
136: protected ResourceTreeBrowser getTreeBrowser() {
137: return ResourceTreeBrowser.getResourceTreeBrowser(root, "Root");
138: }
139:
140: /**
141: * Build the interface
142: */
143: protected void build() {
144: setOpaque(false);
145: tree = getTreeBrowser();
146: treeview = new JScrollPane(tree);
147: add(treeview, JLayeredPane.FRAME_CONTENT_LAYER);
148: treeview.setLocation(10, 10);
149: treeview.setBorder(BorderFactory
150: .createBevelBorder(BevelBorder.LOWERED));
151: iframe = getInternalFrame();
152: add(iframe, JLayeredPane.PALETTE_LAYER);
153: }
154:
155: /**
156: * Update the layout in the JDesktopPane
157: * @param width The JDesktopPane width
158: * @param height The JDesktopPane height
159: */
160: protected void updateLayout(int width, int height) {
161: int treewidth = 5 * width / 12;
162: treeview.setLocation(10, 10);
163: treeview.setSize(treewidth, height - 20);
164: int x = iframe.getLocation().x;
165: int minx = 20 + treewidth;
166: if (x < minx)
167: iframe.setLocation(minx, 10);
168: }
169:
170: /**
171: * Moves and resizes this component. The new location of the top-left
172: * corner is specified by x and y, and the new size is specified by
173: * width and height.
174: * @param x The new x-coordinate of this component.
175: * @param y The new y-coordinate of this component.
176: * @param width The new width of this component.
177: * @param height The new height of this component.
178: */
179: public void setBounds(int x, int y, int width, int height) {
180: updateLayout(width, height);
181: super .setBounds(x, y, width, height);
182: }
183:
184: /**
185: * Get the helper name.
186: * @return a String instance
187: */
188: public String getName() {
189: return name;
190: }
191:
192: /**
193: * Get the helper tooltip
194: * @return a String
195: */
196: public String getToolTip() {
197: return tooltip;
198: }
199:
200: /**
201: * Get the Component.
202: * @return a Component instance
203: */
204: public Component getComponent() {
205: return this ;
206: }
207:
208: /**
209: * Constructor.
210: */
211: public SpaceServerHelper() {
212: //new instance
213: }
214:
215: }
|