From 1e6e9f6dcb72ebd7152fbda4867f4bbdec90a396 Mon Sep 17 00:00:00 2001 From: "edburns%acm.org" Date: Thu, 8 Jun 2000 18:40:20 +0000 Subject: [PATCH] Checked in nascent "select the current node in the tree view when the user shift-clicks on a node" feature, but it's blocked by the incompleteness of the DOM implementation in M13. --- .../webclient/test/DOMViewerFrame.java | 89 ++++++++++++++++++- 1 file changed, 86 insertions(+), 3 deletions(-) diff --git a/java/webclient/classes_spec/org/mozilla/webclient/test/DOMViewerFrame.java b/java/webclient/classes_spec/org/mozilla/webclient/test/DOMViewerFrame.java index 051ef626ea2..9c1a59a0df2 100644 --- a/java/webclient/classes_spec/org/mozilla/webclient/test/DOMViewerFrame.java +++ b/java/webclient/classes_spec/org/mozilla/webclient/test/DOMViewerFrame.java @@ -31,6 +31,11 @@ import org.w3c.dom.NodeList; import org.w3c.dom.Element; import org.w3c.dom.Document; +import org.w3c.dom.events.Event; +import org.w3c.dom.events.EventTarget; +import org.w3c.dom.events.EventListener; +import org.w3c.dom.events.MouseEvent; + import javax.swing.JScrollPane; import javax.swing.JSplitPane; import javax.swing.JPanel; @@ -38,16 +43,19 @@ import javax.swing.JFrame; import javax.swing.JTree; import javax.swing.tree.TreeSelectionModel; +import javax.swing.tree.TreePath; import java.awt.BorderLayout; +import java.util.Stack; + /** * * A dom viewer Frame * - * @version $Id: DOMViewerFrame.java,v 1.1 2000-06-04 22:16:04 edburns%acm.org Exp $ + * @version $Id: DOMViewerFrame.java,v 1.2 2000-06-08 18:40:20 edburns%acm.org Exp $ * * @see org.mozilla.webclient.BrowserControlFactory @@ -62,7 +70,7 @@ import java.awt.BorderLayout; -public class DOMViewerFrame extends JFrame { +public class DOMViewerFrame extends JFrame implements EventListener { private EmbeddedMozilla creator; @@ -76,6 +84,8 @@ private JTree tree; private Document doc; +private Stack pathStack; + public DOMViewerFrame (String title, EmbeddedMozilla Creator) { @@ -106,9 +116,23 @@ public DOMViewerFrame (String title, EmbeddedMozilla Creator) public void setDocument(Document newDocument) { if (null == newDocument) { - return; + return; + } + EventTarget eventTarget = null; + + if (null != doc) { + if (doc instanceof EventTarget) { + System.out.println("debug: edburns: Document is EventTarget"); + eventTarget = (EventTarget) doc; + eventTarget.removeEventListener("mousedown", this, false); + } } doc = newDocument; + if (doc instanceof EventTarget) { + System.out.println("debug: edburns: Document is EventTarget"); + eventTarget = (EventTarget) doc; + eventTarget.addEventListener("click", this, false); + } try { // store the document as the root node @@ -136,6 +160,65 @@ public void setDocument(Document newDocument) } +// +// From org.w3c.dom.events.EventListener +// + +public void handleEvent(Event e) +{ + if (!(e instanceof MouseEvent)) { + return; + } + MouseEvent mouseEvent = (MouseEvent) e; + + if (mouseEvent.getShiftKey()) { + // As of M13, getCurrentNode is un-implemented in mozilla. + // selectNodeInTree(mouseEvent.getCurrentNode()); + } + +} + +protected void selectNodeInTree(Node node) +{ + TreeSelectionModel selection = tree.getSelectionModel(); + if (null == selection) { + return; + } + + if (null == node) { + selection.clearSelection(); + } + if (null != pathStack) { + pathStack.clear(); + } + populatePathStackFromNode(node); + if (null == pathStack || pathStack.isEmpty()) { + return; + } + TreePath nodePath = new TreePath(pathStack.toArray()); + + System.out.println("treePath: " + nodePath.toString()); + + selection.setSelectionPath(nodePath); +} + +protected void populatePathStackFromNode(Node node) +{ + if (null == pathStack) { + // PENDING(edburns): perhaps provide default size + pathStack = new Stack(); + } + if (null == pathStack) { + return; + } + pathStack.push(node); + Node parent = node.getParentNode(); + if (null != parent) { + populatePathStackFromNode(node); + } +} + + } // EOF