--- /dev/null
+// FramedResourceHelper.java\r
+// $Id: FramedResourceHelper.java,v 1.1 2010/06/15 12:25:54 smhuang Exp $\r
+// (c) COPYRIGHT MIT and INRIA, 1998.\r
+// Please first read the full copyright statement in file COPYRIGHT.html\r
+\r
+package org.w3c.jigadmin.editors;\r
+\r
+import javax.swing.JPanel;\r
+import javax.swing.JLabel;\r
+import javax.swing.JScrollPane;\r
+import javax.swing.JSplitPane;\r
+import javax.swing.BorderFactory;\r
+import javax.swing.JMenuBar;\r
+import javax.swing.JMenuItem;\r
+import javax.swing.JMenu;\r
+import javax.swing.border.TitledBorder;\r
+import javax.swing.event.TreeSelectionListener;\r
+import javax.swing.event.TreeSelectionEvent;\r
+import javax.swing.tree.TreePath;\r
+\r
+import java.awt.Component;\r
+import java.awt.BorderLayout;\r
+import java.awt.Cursor;\r
+import java.awt.GridLayout;\r
+import java.awt.Dimension;\r
+import java.awt.Window;\r
+import java.awt.event.ActionListener;\r
+import java.awt.event.ActionEvent;\r
+\r
+import java.util.Properties;\r
+\r
+import org.w3c.jigadmin.RemoteResourceWrapper;\r
+import org.w3c.jigadmin.PropertyManager;\r
+import org.w3c.jigadmin.gui.Message;\r
+import org.w3c.jigadmin.widgets.Icons;\r
+\r
+import org.w3c.jigsaw.admin.RemoteAccessException;\r
+\r
+/**\r
+ * The resource editor.\r
+ * @version $Revision: 1.1 $\r
+ * @author Benoît Mahé (bmahe@w3.org)\r
+ */\r
+public class FramedResourceHelper extends ResourceHelper {\r
+\r
+ /**\r
+ * Our MenuBar.\r
+ */\r
+ class ResourceMenu extends JMenuBar implements ActionListener {\r
+ \r
+ private Window parent = null;\r
+\r
+ final static String CLOSE_AC = "quit";\r
+ final static String DEL_AC = "del";\r
+ final static String ADD_AC = "add";\r
+ final static String DOC_AC = "doc";\r
+\r
+ public void actionPerformed(ActionEvent evt) {\r
+ String command = evt.getActionCommand();\r
+ if (command.equals(CLOSE_AC)) {\r
+ parent.dispose();\r
+ } else if ((command.equals(DOC_AC)) && (selected_rrw != null)) {\r
+ try {\r
+ String url = (String)\r
+ selected_rrw.getResource().getValue("help-url");\r
+ showReference(url);\r
+ } catch (RemoteAccessException ex) {\r
+ ex.printStackTrace();\r
+ }\r
+ } else if ((command.equals(DEL_AC)) && (selected_rrw != null)) {\r
+ browser.deleteSelectedResources();\r
+ } else if ((command.equals(ADD_AC)) && (selected_rrw != null)) {\r
+ browser.addResourceToSelectedContainer();\r
+ }\r
+ }\r
+\r
+ protected void showReference(String url) {\r
+ try {\r
+ MiniBrowser.showDocumentationURL(url, \r
+ "Reference documentation");\r
+ } catch (Exception ex) {\r
+ Message.showErrorMessage(this, ex);\r
+ }\r
+ }\r
+\r
+ ResourceMenu(Window parent) {\r
+ super();\r
+ this.parent = parent;\r
+ JMenu resource = new JMenu("Resource");\r
+ add(resource);\r
+\r
+ JMenuItem add = \r
+ new JMenuItem("Add frame to selected resource/frame", \r
+ Icons.addIcon);\r
+ add.setActionCommand(ADD_AC);\r
+ add.addActionListener(this);\r
+ resource.add( add );\r
+\r
+ JMenuItem del = \r
+ new JMenuItem("Delete selected frame(s)", Icons.deleteIcon);\r
+ del.setActionCommand(DEL_AC);\r
+ del.addActionListener(this);\r
+ resource.add( del );\r
+\r
+ resource.addSeparator();\r
+\r
+ JMenuItem quit = new JMenuItem("Close Resource window",\r
+ Icons.closeIcon);\r
+ quit.setActionCommand(CLOSE_AC);\r
+ quit.addActionListener(this);\r
+ resource.add( quit );\r
+\r
+ JMenu help = new JMenu("Help");\r
+ //setHelpMenu not yet implemented (FIXME)\r
+ add(help);\r
+ JMenuItem ref = new JMenuItem("Show reference documentation",\r
+ Icons.infoIcon);\r
+ ref.setActionCommand(DOC_AC);\r
+ ref.addActionListener(this);\r
+ help.add(ref);\r
+ }\r
+ \r
+ }\r
+\r
+ protected String name = null;\r
+ protected JPanel comp = null;\r
+ protected JPanel attrs = null;\r
+ protected RemoteResourceWrapper rrw = null;\r
+ protected RemoteResourceWrapper selected_rrw = null;\r
+ protected FrameBrowser browser = null;\r
+\r
+ /**\r
+ * Our internal TreeSelectionListener\r
+ */\r
+ TreeSelectionListener tsl = new TreeSelectionListener() {\r
+ RemoteResourceWrapper current_rrw = null;\r
+\r
+ public void valueChanged(TreeSelectionEvent e) {\r
+ if (e.isAddedPath()) {\r
+ if (! browser.isDragging()) {\r
+ RemoteFrameWrapperNode node = \r
+ (RemoteFrameWrapperNode)e.getPath().getLastPathComponent();\r
+ RemoteResourceWrapper rrw = node.getResourceWrapper();\r
+ current_rrw = rrw;\r
+ Thread updater = new Thread() {\r
+ public void run() {\r
+ updateAttrs(current_rrw);\r
+ }\r
+ };\r
+ updater.start();\r
+ //updateAttrs(rrw);\r
+ } else {\r
+ attrs.invalidate();\r
+ attrs.removeAll();\r
+ attrs.add(new JLabel(" ", JLabel.CENTER));\r
+ attrs.validate();\r
+ }\r
+ } else {\r
+ selected_rrw = null;\r
+ attrs.invalidate();\r
+ attrs.removeAll();\r
+ attrs.add(new JLabel("no frame selected", JLabel.CENTER));\r
+ attrs.validate();\r
+ }\r
+ }\r
+ };\r
+\r
+ /**\r
+ * Get the helper title.\r
+ * @return a String\r
+ */\r
+ public String getTitle() {\r
+ return "Frames";\r
+ }\r
+\r
+ /**\r
+ * Get the heper Component\r
+ * @return a Component\r
+ */\r
+ public Component getComponent() {\r
+ return comp;\r
+ }\r
+\r
+ /**\r
+ * tells if the edited resource in the helper has changed\r
+ * @return <strong>true</strong> if the values changed.\r
+ * to get more informations about what has changed, you can use the \r
+ * three methods below.\r
+ */\r
+ public boolean hasChanged() {\r
+ return false;\r
+ }\r
+\r
+ /**\r
+ * set the current resource to be the original resource (ie: the\r
+ * hasChanged() method must return <strong>false</false> now.\r
+ * to do a "fine tuned" reset, use one of the three following method.\r
+ */\r
+ public void clearChanged() {\r
+ \r
+ }\r
+\r
+ /**\r
+ * commit the changes (if any)\r
+ * @exception RemoteAccessException if a remote access error occurs.\r
+ */\r
+ public void commitChanges()\r
+ throws RemoteAccessException\r
+ {\r
+\r
+ }\r
+\r
+ /**\r
+ * undo the not-yet-commited changes\r
+ */\r
+ public void resetChanges() {\r
+\r
+ }\r
+\r
+ /**\r
+ * Update the AttributesHelper\r
+ * @param rrw the RemoteResourceWrapper of the RemoteReource to edit.\r
+ */\r
+ protected void updateAttrs(RemoteResourceWrapper rrw) {\r
+ selected_rrw = rrw;\r
+ attrs.invalidate();\r
+ attrs.removeAll();\r
+ AttributesHelper helper = new AttributesHelper();\r
+ try {\r
+ PropertyManager pm = PropertyManager.getPropertyManager();\r
+ Properties props = pm.getEditorProperties(rrw);\r
+ helper.initialize(rrw, props);\r
+ attrs.add(helper.getComponent());\r
+ } catch (RemoteAccessException ex) {\r
+ ex.printStackTrace();\r
+ }\r
+ attrs.validate();\r
+ }\r
+\r
+ /**\r
+ * initialize the helper\r
+ * @param r the ResourceWrapper containing the Resource edited with \r
+ * this helper\r
+ * @param p some Properties, used to fine-tune the helper\r
+ * @exception RemoteAccessException if a remote access error occurs.\r
+ */\r
+ public void initialize(org.w3c.jigadm.RemoteResourceWrapper rw, \r
+ Properties p)\r
+ throws RemoteAccessException \r
+ {\r
+ boolean framed = false;\r
+ rrw = (RemoteResourceWrapper) rw;\r
+ try {\r
+ name = (String)rrw.getResource().getValue("identifier");\r
+ framed = rrw.getResource().isFramed();\r
+ } catch (RemoteAccessException ex) {\r
+ Message.showErrorMessage(rrw, ex);\r
+ }\r
+ if (name == null) {\r
+ comp = new JPanel();\r
+ return;\r
+ }\r
+ build(framed);\r
+ }\r
+\r
+ /**\r
+ * Get the dedicated MenuBar\r
+ * @param parent the Window parent.\r
+ */\r
+ public JMenuBar getMenuBar(Window parent) {\r
+ return new ResourceMenu(parent);\r
+ }\r
+\r
+ /**\r
+ * Build the interface\r
+ * @param framed is the resource a FramedResource or not?\r
+ */\r
+ protected void build(boolean framed) {\r
+ comp = new JPanel(new GridLayout(1,1));\r
+ attrs = new JPanel(new GridLayout(1,1));\r
+ attrs.setBorder(BorderFactory.createTitledBorder("Attributes"));\r
+\r
+ if (framed) {\r
+ browser = FrameBrowser.getFrameBrowser(rrw, name);\r
+ browser.addTreeSelectionListener(this.tsl);\r
+ browser.setSelectionRow(0);\r
+ browser.setBorder(BorderFactory.createTitledBorder("Frames"));\r
+ browser.setSize(new Dimension(30,30));\r
+ JScrollPane scroll = new JScrollPane(browser);\r
+ JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT,\r
+ true,\r
+ scroll,\r
+ attrs);\r
+ split.setDividerLocation(100);\r
+ comp.add(split);\r
+ } else {\r
+ comp.add(attrs);\r
+ updateAttrs(rrw);\r
+ }\r
+ }\r
+\r
+}\r