summaryrefslogtreecommitdiff
path: root/accessibility/workben/org/openoffice/accessibility/awb/canvas
diff options
context:
space:
mode:
Diffstat (limited to 'accessibility/workben/org/openoffice/accessibility/awb/canvas')
-rw-r--r--accessibility/workben/org/openoffice/accessibility/awb/canvas/Canvas.java322
-rw-r--r--accessibility/workben/org/openoffice/accessibility/awb/canvas/CanvasShape.java412
-rw-r--r--accessibility/workben/org/openoffice/accessibility/awb/canvas/Makefile13
-rw-r--r--accessibility/workben/org/openoffice/accessibility/awb/canvas/MouseObserver.java104
-rw-r--r--accessibility/workben/org/openoffice/accessibility/awb/canvas/ShapeContainer.java237
-rw-r--r--accessibility/workben/org/openoffice/accessibility/awb/canvas/makefile.common34
-rw-r--r--accessibility/workben/org/openoffice/accessibility/awb/canvas/makefile.mk47
7 files changed, 1169 insertions, 0 deletions
diff --git a/accessibility/workben/org/openoffice/accessibility/awb/canvas/Canvas.java b/accessibility/workben/org/openoffice/accessibility/awb/canvas/Canvas.java
new file mode 100644
index 000000000000..86b642e8091c
--- /dev/null
+++ b/accessibility/workben/org/openoffice/accessibility/awb/canvas/Canvas.java
@@ -0,0 +1,322 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package org.openoffice.accessibility.awb.canvas;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Rectangle;
+import java.awt.RenderingHints;
+import java.awt.Toolkit;
+import java.awt.geom.Rectangle2D;
+import java.util.Iterator;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JViewport;
+import javax.swing.event.TreeSelectionEvent;
+import javax.swing.tree.TreePath;
+
+import com.sun.star.accessibility.XAccessible;
+import com.sun.star.accessibility.XAccessibleContext;
+import com.sun.star.accessibility.XAccessibleComponent;
+
+import org.openoffice.accessibility.misc.Options;
+
+/** This canvas displays accessible objects graphically. Each accessible
+ object with graphical representation is represented by an
+ CanvasShape object and has to be added by the
+ <member>addAccessible</member> member function.
+
+ <p>The canvas listens to selection events of the associated JTree and
+ highlights the first selected node of that tree.</p>
+*/
+public class Canvas
+ extends JPanel
+{
+ // This constant can be passed to SetZoomMode to always show the whole screen.
+ public static final int WHOLE_SCREEN = -1;
+
+ public Canvas ()
+ {
+ super (true);
+ maShapeList = new ShapeContainer (this);
+ maMouseObserver = new MouseObserver (this);
+ maTree = null;
+ mnHOffset = 0;
+ mnVOffset = 0;
+ mnScale = 1;
+ maLastWidgetSize = new Dimension (0,0);
+ }
+
+
+
+ /** Tell the canvas which tree to use to highlight accessible
+ objects and to observe for changes in the tree structure.
+ */
+ public void SetTree (javax.swing.JTree aTree)
+ {
+ if (aTree != maTree)
+ {
+ maTree = aTree;
+ maShapeList.SetTree (maTree);
+ maMouseObserver.SetTree (maTree);
+ }
+ }
+
+
+
+
+ private void Clear ()
+ {
+ maShapeList.Clear();
+ }
+
+
+
+
+ public Iterator GetShapeIterator ()
+ {
+ return maShapeList.GetIterator();
+ }
+
+
+
+
+ public void paintComponent (Graphics g)
+ {
+ synchronized (g)
+ {
+ super.paintComponent (g);
+
+ Graphics2D g2 = (Graphics2D)g;
+ if (Options.GetBoolean("Antialiasing"))
+ g2.setRenderingHint (RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
+ else
+ g2.setRenderingHint (RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_OFF);
+
+ setupTransformation ();
+ g2.translate (mnHOffset, mnVOffset);
+ g2.scale (mnScale, mnScale);
+
+ // Draw the screen representation to give a hint of the location of the
+ // accessible object on the screen.
+ Dimension aScreenSize = Toolkit.getDefaultToolkit().getScreenSize();
+ Rectangle2D.Double aScreen = new Rectangle2D.Double (
+ 0,
+ 0,
+ aScreenSize.getWidth(),
+ aScreenSize.getHeight());
+ // Fill the screen rectangle and draw a frame arround it to increase its visibility.
+ g2.setColor (new Color (250,240,230));
+ g2.fill (aScreen);
+ g2.setColor (Color.BLACK);
+ g2.draw (aScreen);
+
+ synchronized (maShapeList)
+ {
+ Iterator aShapeIterator = maShapeList.GetIterator();
+ boolean bShowDescriptions = Options.GetBoolean ("ShowDescriptions");
+ boolean bShowNames = Options.GetBoolean ("ShowNames");
+ boolean bShowText = Options.GetBoolean ("ShowText");
+ while (aShapeIterator.hasNext())
+ {
+ CanvasShape aCanvasShape =
+ (CanvasShape)aShapeIterator.next();
+ try
+ {
+ aCanvasShape.paint (
+ g2,
+ bShowDescriptions, bShowNames, bShowText);
+ }
+ catch (Exception aException)
+ {
+ System.err.println ("caught exception while painting a shape:"
+ + aException);
+ aException.printStackTrace (System.err);
+ }
+ }
+ }
+
+ // Paint highlighted frame around active object as the last thing.
+ if (maActiveObject != null)
+ maActiveObject.paint_highlight (g2);
+ }
+ }
+
+
+
+
+ /** Set up the transformation so that the graphical display can show a
+ centered representation of the whole screen.
+ */
+ private void setupTransformation ()
+ {
+ // Turn off scrollbars when showing the whole screen. Otherwise show them when needed.
+ JViewport aViewport = (JViewport)getParent();
+ JScrollPane aScrollPane = (JScrollPane)aViewport.getParent();
+ int nZoomMode = Options.GetInteger ("ZoomMode", WHOLE_SCREEN);
+ if (nZoomMode == WHOLE_SCREEN)
+ {
+ if (aScrollPane.getHorizontalScrollBarPolicy()
+ != JScrollPane.HORIZONTAL_SCROLLBAR_NEVER)
+ aScrollPane.setHorizontalScrollBarPolicy (
+ JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+ if (aScrollPane.getVerticalScrollBarPolicy()
+ != JScrollPane.VERTICAL_SCROLLBAR_NEVER)
+ aScrollPane.setVerticalScrollBarPolicy (
+ JScrollPane.VERTICAL_SCROLLBAR_NEVER);
+ }
+ else
+ {
+ if (aScrollPane.getHorizontalScrollBarPolicy()
+ != JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED)
+ aScrollPane.setHorizontalScrollBarPolicy (
+ JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+ if (aScrollPane.getVerticalScrollBarPolicy()
+ != JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED)
+ aScrollPane.setVerticalScrollBarPolicy (
+ JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
+ }
+
+ Dimension aScreenSize = Toolkit.getDefaultToolkit().getScreenSize();
+ Dimension aWidgetSize = aViewport.getSize();
+ {
+ if ((aScreenSize.getWidth() > 0) && (aScreenSize.getHeight() > 0))
+ {
+ if (nZoomMode == WHOLE_SCREEN)
+ {
+ // Calculate the scales that would map the screen onto the
+ // widget in both of the coordinate axes and select the
+ // smaller
+ // of the two: it maps the screen onto the widget in both
+ // axes at the same time.
+ double nHScale = (aWidgetSize.getWidth() - 10)
+ / aScreenSize.getWidth();
+ double nVScale = (aWidgetSize.getHeight() - 10)
+ / aScreenSize.getHeight();
+ if (nHScale < nVScale)
+ mnScale = nHScale;
+ else
+ mnScale = nVScale;
+ }
+ else
+ {
+ mnScale = nZoomMode / 100.0;
+ }
+
+ // Calculate offsets that center the scaled screen inside
+ // the widget.
+ mnHOffset = (aWidgetSize.getWidth()
+ - mnScale*aScreenSize.getWidth()) / 2.0;
+ mnVOffset = (aWidgetSize.getHeight()
+ - mnScale*aScreenSize.getHeight()) / 2.0;
+ if (mnHOffset < 0)
+ mnHOffset = 0;
+ if (mnVOffset < 0)
+ mnVOffset = 0;
+
+ setPreferredSize (new Dimension (
+ (int)(2*mnHOffset + mnScale * aScreenSize.getWidth()),
+ (int)(2*mnVOffset + mnScale * aScreenSize.getHeight())));
+ revalidate ();
+ }
+ else
+ {
+ // In case of a degenerate (not yet initialized?) screen size
+ // use some meaningless default values.
+ mnScale = 1;
+ mnHOffset = 0;
+ mnVOffset = 0;
+ }
+ }
+ maLastWidgetSize = aWidgetSize;
+ }
+
+
+
+ protected boolean HighlightObject (CanvasShape aNewActiveObject)
+ {
+ if (aNewActiveObject != maActiveObject)
+ {
+ if (maActiveObject != null)
+ maActiveObject.Highlight (false);
+
+ maActiveObject = aNewActiveObject;
+ if (maActiveObject != null)
+ {
+ /* if (maTree != null)
+ {
+ TreePath aPath = new TreePath (
+ maActiveObject.GetNode().GetPath());
+ maTree.scrollPathToVisible (aPath);
+ maTree.setSelectionPath (aPath);
+ maTree.repaint ();
+ }
+ */
+ maActiveObject.Highlight (true);
+ }
+ repaint ();
+ return true;
+ }
+ else
+ return false;
+ }
+
+
+
+
+ /** Called when the selection of the tree changes. Highlight the
+ corresponding graphical representation of the object.
+ */
+ public void SelectObject (javax.swing.tree.TreeNode aNode)
+ {
+ CanvasShape aCanvasShape = maShapeList.Get (aNode);
+ HighlightObject (aCanvasShape);
+ }
+
+
+
+
+ private int
+ mnXAnchor,
+ mnYAnchor,
+ maResizeFlag;
+ private double
+ mnHOffset,
+ mnVOffset,
+ mnScale;
+ private CanvasShape maActiveObject;
+ private javax.swing.JTree maTree;
+ // The size of the widget at the last call of setupTransformation()
+ private Dimension maLastWidgetSize;
+ private ShapeContainer maShapeList;
+ private MouseObserver maMouseObserver;
+}
diff --git a/accessibility/workben/org/openoffice/accessibility/awb/canvas/CanvasShape.java b/accessibility/workben/org/openoffice/accessibility/awb/canvas/CanvasShape.java
new file mode 100644
index 000000000000..f2595351a4f5
--- /dev/null
+++ b/accessibility/workben/org/openoffice/accessibility/awb/canvas/CanvasShape.java
@@ -0,0 +1,412 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package org.openoffice.accessibility.awb.canvas;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics2D;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.NoninvertibleTransformException;
+
+
+import com.sun.star.accessibility.*;
+import com.sun.star.lang.EventObject;
+import com.sun.star.uno.UnoRuntime;
+
+
+class CanvasShape implements XAccessibleEventListener
+{
+ public final Color maHighlightColor = Color.red;
+ public final Color maSelectionColor = Color.green;
+ public final Color maFocusColor = Color.blue;
+
+ public CanvasShape (javax.swing.tree.TreeNode aNode, Canvas aCanvas)
+ {
+ maNode = aNode;
+ msName = "<no name>";
+ msDescription = "<no description>";
+ maShape = new Rectangle2D.Double (-10,-10,10,10);
+ maPosition = new Point (-10,-10);
+ maSize = new Dimension (10,10);
+ maFgColor = java.awt.Color.black;
+ maBgColor = Color.blue;
+ mnRole = -1;
+ mbHighlighted = false;
+ mbSelected = false;
+ mbFocused = false;
+ maCanvas = aCanvas;
+
+ Update ();
+ }
+
+
+
+
+ public javax.swing.tree.TreePath getNodePath (javax.swing.tree.TreeNode node)
+ {
+ javax.swing.tree.TreeNode parent = node.getParent();
+ return (parent != null) ?
+ getNodePath(parent).pathByAddingChild(node) :
+ new javax.swing.tree.TreePath(node);
+ }
+
+ public javax.swing.tree.TreePath getNodePath ()
+ {
+ return getNodePath(maNode);
+ }
+
+
+
+ /** Update the data obtained from the <type>AccessibilityNode</type>
+ object.
+ */
+ public void Update ()
+ {
+ if (maNode instanceof XAccessible) {
+ mxContext = ((XAccessible) maNode).getAccessibleContext();
+ mxComponent = (XAccessibleComponent)UnoRuntime.queryInterface(
+ XAccessibleComponent.class, mxContext);
+ }
+
+ if (mxContext != null)
+ {
+ msName = mxContext.getAccessibleName();
+ msDescription = mxContext.getAccessibleDescription();
+ mnRole = mxContext.getAccessibleRole();
+
+ // Extract the selected and focused flag.
+ XAccessibleStateSet xStateSet = mxContext.getAccessibleStateSet ();
+ if (xStateSet != null)
+ {
+ mbSelected = xStateSet.contains (AccessibleStateType.SELECTED);
+ mbFocused = xStateSet.contains (AccessibleStateType.FOCUSED);
+ }
+ }
+
+ UpdateGeometry ();
+
+ if (mxComponent != null)
+ {
+ // Note: alpha values in office 0..255 have to be mapped to
+ // 255..0 in Java
+ Color aCol = new Color (mxComponent.getForeground(), true);
+ maFgColor = new Color (aCol.getRed (),
+ aCol.getGreen (),
+ aCol.getBlue (),
+ 0xff - aCol.getAlpha ());
+ aCol = new Color (mxComponent.getBackground(), true);
+ maBgColor = new Color (aCol.getRed (),
+ aCol.getGreen (),
+ aCol.getBlue (),
+ 0xff - aCol.getAlpha ());
+ }
+ }
+
+
+
+ public void UpdateGeometry ()
+ {
+ if (mxComponent != null)
+ {
+ com.sun.star.awt.Point aLocationOnScreen =
+ mxComponent.getLocationOnScreen();
+ com.sun.star.awt.Size aSizeOnScreen = mxComponent.getSize();
+ maPosition = new Point (
+ aLocationOnScreen.X,
+ aLocationOnScreen.Y);
+ maSize = new Dimension (
+ aSizeOnScreen.Width,
+ aSizeOnScreen.Height);
+ }
+ }
+
+
+
+ /** Paint the object into the specified canvas. It is transformed
+ according to the specified offset and scale.
+ */
+ public void paint (
+ Graphics2D g,
+ boolean bShowDescription,
+ boolean bShowName,
+ boolean bShowText)
+ {
+ try{
+ // Transform the object's position and size according to the
+ // specified offset and scale.
+ Point aLocation = new Point();
+ maShape = new Rectangle2D.Double (
+ maPosition.x,
+ maPosition.y,
+ maSize.width,
+ maSize.height);
+ maTransformation = g.getTransform();
+
+ // Fill the object's bounding box with its background color if it
+ // has no children.
+ if (mxContext.getAccessibleChildCount() == 0)
+ {
+ g.setColor (maBgColor);
+ g.fill (maShape);
+ }
+
+ // Remove alpha channel from color before drawing the frame.
+ Color color = maFgColor;
+ if (maFgColor.getAlpha()<128)
+ color = new Color (maFgColor.getRed(), maFgColor.getGreen(), maFgColor.getBlue());
+ g.setColor (color);
+ g.draw (maShape);
+
+ if (mbFocused)
+ {
+ g.setColor (maFocusColor);
+ for (int x=0; x<=2; x++)
+ for (int y=0; y<=2; y++)
+ g.fill (
+ new Rectangle2D.Double (
+ maShape.x + x/2.0 * maShape.width-3,
+ maShape.y + y/2.0 * maShape.height-3,
+ 6,
+ 6));
+ }
+ if (mbSelected)
+ {
+ g.setColor (maSelectionColor);
+ for (int x=0; x<=2; x++)
+ for (int y=0; y<=2; y++)
+ g.draw (
+ new Rectangle2D.Double (
+ maShape.x + x/2.0 * maShape.width-2,
+ maShape.y + y/2.0 * maShape.height-2,
+ 4,
+ 4));
+ }
+
+ // Write the object's text OR name and description.
+ g.setColor (maFgColor);
+ if (bShowName)
+ paintName (g);
+ if (bShowDescription)
+ paintDescription (g);
+ if (bShowText)
+ paintText (g);
+ }
+ catch (Exception e)
+ { // don't care
+ }
+ }
+
+
+ public void paint_highlight (Graphics2D g)
+ {
+ if (mbHighlighted)
+ g.setColor (maHighlightColor);
+ else
+ g.setColor (maFgColor);
+ g.draw (maShape);
+ }
+
+
+
+
+ private void paintName (Graphics2D g)
+ {
+ g.drawString ("Name: " + msName,
+ (float)maShape.x+5,
+ (float)maShape.y+15);
+ }
+
+
+
+ private void paintDescription (Graphics2D g)
+ {
+ g.drawString ("Description: " + msDescription,
+ (float)maShape.x+5,
+ (float)maShape.y+35);
+ }
+
+
+
+
+ private void paintText (Graphics2D g)
+ {
+ XAccessibleText xText = null;
+ // get XAccessibleText
+ xText = (XAccessibleText)UnoRuntime.queryInterface(
+ XAccessibleText.class, mxContext);
+
+ // Draw every character in the text string.
+ if (xText != null)
+ {
+ String sText = xText.getText();
+ try
+ {
+ for(int i = 0; i < sText.length(); i++)
+ {
+ com.sun.star.awt.Rectangle aRect =
+ xText.getCharacterBounds(i);
+
+ double x = maShape.x + aRect.X;
+ double y = maShape.y + aRect.Y + aRect.Height;
+
+ g.drawString (sText.substring(i, i+1), (float)x, (float)y);
+ }
+ }
+ catch (com.sun.star.lang.IndexOutOfBoundsException e)
+ {}
+ }
+ }
+
+
+ /** Compute whether the specified point lies inside the object's
+ bounding box.
+ */
+ public boolean Contains (int x, int y)
+ {
+ Point2D aPosition = new Point2D.Double (x,y);
+ try
+ {
+ maTransformation.inverseTransform (aPosition, aPosition);
+ // System.out.println ("transformed "+x+","+y+" to "+aPosition);
+ }
+ catch (NoninvertibleTransformException aException)
+ {
+ return false;
+ }
+ return (maShape.contains (aPosition));
+ }
+
+ public void Highlight (boolean bFlag)
+ {
+ mbHighlighted = bFlag;
+ }
+
+ public boolean IsHighlighted ()
+ {
+ return mbHighlighted;
+ }
+
+ public Rectangle GetBBox ()
+ {
+ return new Rectangle (maPosition, maSize);
+ }
+
+ public Point getOrigin ()
+ {
+ return maPosition;
+ }
+
+ public Dimension GetSize ()
+ {
+ return maSize;
+ }
+
+ public int getRole ()
+ {
+ return mnRole;
+ }
+
+ public XAccessibleContext getContext ()
+ {
+ return mxContext;
+ }
+
+ public XAccessibleComponent getComponent ()
+ {
+ return mxComponent;
+ }
+
+ public String toString ()
+ {
+ return ">"+msName+", "+msDescription+" +"+maPosition.x+"+"+maPosition.y
+ +"x"+maSize.width+"x"+maSize.height+"<";
+ }
+
+ /** */
+ public void notifyEvent(com.sun.star.accessibility.AccessibleEventObject aEvent) {
+ try {
+ switch (aEvent.EventId) {
+ case AccessibleEventId.BOUNDRECT_CHANGED:
+ case AccessibleEventId.VISIBLE_DATA_CHANGED:
+ UpdateGeometry ();
+ maCanvas.repaint();
+ break;
+ default:
+ break;
+ }
+ } catch (Exception aException) {
+ System.err.println ("caught exception while updating a shape:"
+ + aException);
+ aException.printStackTrace (System.err);
+ }
+ }
+
+ /** Callback for disposing events.
+ */
+ public void disposing (com.sun.star.lang.EventObject e)
+ {
+ System.out.println ("Disposing");
+ }
+
+
+
+
+ private Canvas
+ maCanvas;
+ private javax.swing.tree.TreeNode
+ maNode;
+ private XAccessibleContext
+ mxContext;
+ private XAccessibleComponent
+ mxComponent;
+ private String
+ msDescription,
+ msName;
+ private Rectangle2D.Double maShape;
+ private AffineTransform maTransformation;
+ private Point maPosition;
+ private Dimension
+ maTransformedSize,
+ maSize;
+ private Color
+ maFgColor,
+ maBgColor;
+ private boolean
+ // Highlighting objects is an internal concept. Corresponds to selection in the tree view.
+ mbHighlighted,
+ // Set when the accessible object is selected.
+ mbSelected,
+ // Set when the accessible object is focused.
+ mbFocused;
+ private int
+ mnRole;
+}
diff --git a/accessibility/workben/org/openoffice/accessibility/awb/canvas/Makefile b/accessibility/workben/org/openoffice/accessibility/awb/canvas/Makefile
new file mode 100644
index 000000000000..078ac7ee4286
--- /dev/null
+++ b/accessibility/workben/org/openoffice/accessibility/awb/canvas/Makefile
@@ -0,0 +1,13 @@
+all : package
+
+ROOT=../../../../..
+PACKAGE = org.openoffice.accessibility.awb.canvas
+SUBDIRS =
+include makefile.common
+
+include $(ROOT)/makefile.in
+
+
+package : $(CLASS_FILES)
+
+
diff --git a/accessibility/workben/org/openoffice/accessibility/awb/canvas/MouseObserver.java b/accessibility/workben/org/openoffice/accessibility/awb/canvas/MouseObserver.java
new file mode 100644
index 000000000000..3e7e2807906d
--- /dev/null
+++ b/accessibility/workben/org/openoffice/accessibility/awb/canvas/MouseObserver.java
@@ -0,0 +1,104 @@
+package org.openoffice.accessibility.awb.canvas;
+
+import java.awt.Dimension;
+import java.awt.event.InputEvent;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+import java.util.Iterator;
+import javax.swing.tree.TreePath;
+
+
+/** Observe the mouse and highlight shapes of the canvas when clicked.
+*/
+public class MouseObserver
+ implements MouseListener,
+ MouseMotionListener
+{
+ public MouseObserver (Canvas aCanvas)
+ {
+ maCanvas = aCanvas;
+ maCanvas.addMouseListener (this);
+ maCanvas.addMouseMotionListener (this);
+ }
+
+
+ public void SetTree (javax.swing.JTree aTree)
+ {
+ maTree = aTree;
+ }
+
+ public void mouseClicked (MouseEvent e)
+ {}
+
+ public void mousePressed (MouseEvent e)
+ {
+ CanvasShape aObjectUnderMouse = FindCanvasShapeUnderMouse (e);
+ maTree.clearSelection();
+ if (aObjectUnderMouse != null)
+ {
+ TreePath aPath = aObjectUnderMouse.getNodePath();
+ if ((e.getModifiers() & InputEvent.CTRL_MASK) != 0)
+ maTree.expandPath (aPath);
+ // Selecting the entry will eventually highlight the shape.
+ maTree.setSelectionPath (aPath);
+ maTree.makeVisible (aPath);
+ }
+ }
+
+ public void mouseReleased (MouseEvent e)
+ {}
+
+ public void mouseEntered (MouseEvent e)
+ {}
+
+ public void mouseExited (MouseEvent e)
+ {}
+
+ public void mouseDragged (MouseEvent e)
+ {
+ }
+
+ public void mouseMoved (MouseEvent e)
+ {
+ if ((e.getModifiers() & InputEvent.SHIFT_MASK) != 0)
+ maCanvas.HighlightObject (FindCanvasShapeUnderMouse (e));
+ }
+
+
+ /** Search for the smallest shape that contains the mouse position.
+ */
+ protected CanvasShape FindCanvasShapeUnderMouse (MouseEvent e)
+ {
+ Dimension aSmallestSize = null;
+ Iterator maShapeIterator = maCanvas.GetShapeIterator();
+ CanvasShape aShapeUnderMouse = null;
+ while (maShapeIterator.hasNext())
+ {
+ CanvasShape aShape = (CanvasShape)maShapeIterator.next();
+ if (aShape != null)
+ if (aShape.Contains (e.getX(),e.getY()))
+ {
+ if (aShapeUnderMouse == null)
+ {
+ aSmallestSize = aShape.GetSize();
+ aShapeUnderMouse = aShape;
+ }
+ else
+ {
+ Dimension aSize = aShape.GetSize();
+ if (aSize.getWidth()<aSmallestSize.getWidth()
+ || aSize.getHeight()<aSmallestSize.getHeight())
+ {
+ aSmallestSize = aSize;
+ aShapeUnderMouse = aShape;
+ }
+ }
+ }
+ }
+ return aShapeUnderMouse;
+ }
+
+ private Canvas maCanvas;
+ private javax.swing.JTree maTree;
+}
diff --git a/accessibility/workben/org/openoffice/accessibility/awb/canvas/ShapeContainer.java b/accessibility/workben/org/openoffice/accessibility/awb/canvas/ShapeContainer.java
new file mode 100644
index 000000000000..03ad4bf38c46
--- /dev/null
+++ b/accessibility/workben/org/openoffice/accessibility/awb/canvas/ShapeContainer.java
@@ -0,0 +1,237 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package org.openoffice.accessibility.awb.canvas;
+
+import java.awt.Rectangle;
+import java.util.Iterator;
+import javax.swing.event.TreeModelListener;
+import javax.swing.event.TreeExpansionListener;
+import javax.swing.event.TreeWillExpandListener;
+import javax.swing.event.TreeExpansionEvent;
+import javax.swing.event.TreeModelEvent;
+import javax.swing.tree.TreeNode;
+
+import com.sun.star.accessibility.XAccessibleEventBroadcaster;
+
+/** Each canvas has a shape container that is responsible for maintaining
+ a collection of shapes that are displayed by the canvas.
+*/
+public class ShapeContainer
+ implements TreeModelListener,
+ TreeExpansionListener,
+ TreeWillExpandListener
+{
+ public ShapeContainer (Canvas aCanvas)
+ {
+ maShapeList = new java.util.Hashtable();
+ maBoundingBox = new Rectangle (0,0,100,100);
+ maCanvas = aCanvas;
+ maTree = null;
+ }
+
+
+
+
+ public synchronized void SetTree (javax.swing.JTree aTree)
+ {
+ if (aTree != maTree)
+ {
+ if (maTree != null)
+ {
+ maTree.getModel().removeTreeModelListener (this);
+ maTree.removeTreeExpansionListener (this);
+ maTree.removeTreeWillExpandListener (this);
+ }
+
+ Clear();
+
+ maTree = aTree;
+
+ maTree.getModel().addTreeModelListener (this);
+ maTree.addTreeExpansionListener (this);
+ maTree.addTreeWillExpandListener (this);
+ }
+ }
+
+
+
+
+ public synchronized boolean AddNode (TreeNode aNode)
+ {
+ CanvasShape aShape = (CanvasShape)maShapeList.get (aNode);
+ if (aShape == null)
+ {
+ aShape = new CanvasShape (aNode, maCanvas);
+
+ if (aNode instanceof XAccessibleEventBroadcaster)
+ ((XAccessibleEventBroadcaster) aNode).addEventListener(aShape);
+
+ // Update bounding box that includes all objects.
+ if (maShapeList.size() == 0)
+ maBoundingBox = aShape.GetBBox();
+ else
+ maBoundingBox = maBoundingBox.union (aShape.GetBBox());
+
+ maShapeList.put (aNode, aShape);
+
+ maCanvas.repaint();
+
+ return true;
+ }
+ else
+ return false;
+ }
+
+
+ /**
+ */
+ public synchronized boolean RemoveNode (TreeNode aNode)
+ {
+ CanvasShape aShape = (CanvasShape)maShapeList.get (aNode);
+ if (aShape != null)
+ {
+ if (aNode instanceof XAccessibleEventBroadcaster)
+ ((XAccessibleEventBroadcaster) aNode).removeEventListener(aShape);
+
+ maShapeList.remove (aNode);
+ maCanvas.SelectObject (null);
+ maCanvas.repaint ();
+ return true;
+ }
+ else
+ return false;
+ }
+
+
+
+
+ public synchronized void Clear ()
+ {
+ maShapeList.clear ();
+ }
+
+
+
+
+ public Iterator GetIterator ()
+ {
+ return maShapeList.values().iterator ();
+ }
+
+
+
+
+ public CanvasShape Get (TreeNode aNode)
+ {
+ if (aNode != null) {
+ return (CanvasShape)maShapeList.get (aNode);
+ }
+ return null;
+ }
+
+
+ private void PrintMessage (String aMessage, java.util.EventObject aEvent)
+ {
+ // System.out.println ("ShapeContainer: " + aMessage + ": " + aEvent);
+ }
+
+ public void treeNodesChanged (TreeModelEvent aEvent)
+ {
+ PrintMessage ("treeNodesChanged", aEvent);
+ }
+ public void treeNodesInserted (TreeModelEvent aEvent)
+ {
+ PrintMessage ("treeNodesInserted", aEvent);
+ Object[] aNewNodes = aEvent.getChildren();
+ for (int i=0; i<aNewNodes.length; i++)
+ AddNode ((TreeNode)aNewNodes[i]);
+ }
+ public void treeNodesRemoved (TreeModelEvent aEvent)
+ {
+ PrintMessage ("treeNodesRemoved", aEvent);
+ Object[] aOldNodes = aEvent.getChildren();
+ for (int i=0; i<aOldNodes.length; i++)
+ RemoveNode ((TreeNode)aOldNodes[i]);
+ }
+ public void treeStructureChanged (TreeModelEvent aEvent)
+ {
+ PrintMessage ("treeStructureChanged", aEvent);
+ TreeNode aNode = (TreeNode)aEvent.getTreePath().getLastPathComponent();
+ RemoveAllChildren(aNode);
+ AddAllChildren(aNode);
+ }
+
+ public void treeWillExpand (TreeExpansionEvent aEvent)
+ {
+ PrintMessage ("treeWillExpand", aEvent);
+ }
+ public void treeWillCollapse (TreeExpansionEvent aEvent)
+ {
+ PrintMessage ("treeWillCollapse", aEvent);
+ TreeNode aNode = (TreeNode)aEvent.getPath().getLastPathComponent();
+ RemoveAllChildren (aNode);
+ }
+ public void treeExpanded (TreeExpansionEvent aEvent)
+ {
+ PrintMessage ("treeExpanded", aEvent);
+ TreeNode aNode = (TreeNode)aEvent.getPath().getLastPathComponent();
+ AddAllChildren (aNode);
+ }
+ public void treeCollapsed (TreeExpansionEvent aEvent)
+ {
+ PrintMessage ("treeCollapsed", aEvent);
+ }
+
+ private void AddAllChildren (TreeNode aNode) {
+ java.util.Enumeration aChildList = aNode.children();
+ while (aChildList.hasMoreElements()) {
+ TreeNode aChild = (TreeNode) aChildList.nextElement();
+ if (aChild != null) {
+ AddAllChildren (aChild);
+ AddNode (aChild);
+ }
+ }
+ }
+
+ private void RemoveAllChildren (TreeNode aNode) {
+ java.util.Enumeration aChildList = aNode.children();
+ while (aChildList.hasMoreElements()) {
+ TreeNode aChild = (TreeNode) aChildList.nextElement();
+ if (aChild != null) {
+ RemoveAllChildren (aChild);
+ RemoveNode (aChild);
+ }
+ }
+ }
+
+
+ private java.util.Hashtable maShapeList;
+ private Rectangle maBoundingBox;
+ private Canvas maCanvas;
+ private javax.swing.JTree maTree;
+}
diff --git a/accessibility/workben/org/openoffice/accessibility/awb/canvas/makefile.common b/accessibility/workben/org/openoffice/accessibility/awb/canvas/makefile.common
new file mode 100644
index 000000000000..df47f1bc8028
--- /dev/null
+++ b/accessibility/workben/org/openoffice/accessibility/awb/canvas/makefile.common
@@ -0,0 +1,34 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+JARFILES = jurt.jar unoil.jar ridl.jar
+JAVAFILES = \
+ CanvasShape.java \
+ Canvas.java \
+ MouseObserver.java \
+ ShapeContainer.java
+
diff --git a/accessibility/workben/org/openoffice/accessibility/awb/canvas/makefile.mk b/accessibility/workben/org/openoffice/accessibility/awb/canvas/makefile.mk
new file mode 100644
index 000000000000..d2feccfb80cf
--- /dev/null
+++ b/accessibility/workben/org/openoffice/accessibility/awb/canvas/makefile.mk
@@ -0,0 +1,47 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+PRJNAME = awb
+PRJ = ..$/..$/..$/..$/..$/..
+TARGET = awb_canvas
+PACKAGE = org$/openoffice$/accessibility$/awb$/canvas
+
+USE_JAVAVER:=TRUE
+
+# --- Settings -----------------------------------------------------
+
+.INCLUDE : settings.mk
+
+.IF "$(JAVAVER:s/.//)" >= "140"
+.INCLUDE : makefile.common
+JAVACLASSFILES= $(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:b).class)
+JARCLASSDIRS = $(PACKAGE) org/openoffice/java/accessibility/awb
+.ENDIF
+
+# --- Targets ------------------------------------------------------
+
+.INCLUDE : target.mk