11b0aaa91SAndrew Rist /**************************************************************
21b0aaa91SAndrew Rist  *
31b0aaa91SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
41b0aaa91SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
51b0aaa91SAndrew Rist  * distributed with this work for additional information
61b0aaa91SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
71b0aaa91SAndrew Rist  * to you under the Apache License, Version 2.0 (the
81b0aaa91SAndrew Rist  * "License"); you may not use this file except in compliance
91b0aaa91SAndrew Rist  * with the License.  You may obtain a copy of the License at
101b0aaa91SAndrew Rist  *
111b0aaa91SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
121b0aaa91SAndrew Rist  *
131b0aaa91SAndrew Rist  * Unless required by applicable law or agreed to in writing,
141b0aaa91SAndrew Rist  * software distributed under the License is distributed on an
151b0aaa91SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
161b0aaa91SAndrew Rist  * KIND, either express or implied.  See the License for the
171b0aaa91SAndrew Rist  * specific language governing permissions and limitations
181b0aaa91SAndrew Rist  * under the License.
191b0aaa91SAndrew Rist  *
201b0aaa91SAndrew Rist  *************************************************************/
211b0aaa91SAndrew Rist 
22cdf0e10cSrcweir import java.util.*;
23cdf0e10cSrcweir import java.awt.*;
24cdf0e10cSrcweir import java.awt.event.*;
25cdf0e10cSrcweir import javax.swing.*;
26cdf0e10cSrcweir import javax.swing.tree.*;
27cdf0e10cSrcweir import javax.swing.event.TreeSelectionListener;
28cdf0e10cSrcweir import javax.swing.event.TreeSelectionEvent;
29cdf0e10cSrcweir import java.awt.geom.Rectangle2D;
30cdf0e10cSrcweir 
31cdf0e10cSrcweir import com.sun.star.accessibility.XAccessible;
32cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleContext;
33cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleComponent;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir /** This canvas displays accessible objects graphically.  Each accessible
36cdf0e10cSrcweir     object with graphical representation is represented by an
37cdf0e10cSrcweir     CanvasShape object and has to be added by the
38cdf0e10cSrcweir     <member>addAccessible</member> member function.
39cdf0e10cSrcweir 
40cdf0e10cSrcweir     <p>The canvas listens to selection events of the associated JTree and
41cdf0e10cSrcweir     highlights the first selected node of that tree.</p>
42cdf0e10cSrcweir */
43cdf0e10cSrcweir class Canvas
44cdf0e10cSrcweir     extends JPanel
45cdf0e10cSrcweir     implements MouseListener, MouseMotionListener, TreeSelectionListener//, Scrollable
46cdf0e10cSrcweir {
47cdf0e10cSrcweir     // This constant can be passed to SetZoomMode to always show the whole screen.
48cdf0e10cSrcweir     public static final int WHOLE_SCREEN = -1;
49cdf0e10cSrcweir 
Canvas()50cdf0e10cSrcweir     public Canvas ()
51cdf0e10cSrcweir     {
52cdf0e10cSrcweir         super (true);
53cdf0e10cSrcweir         maObjects = new java.util.HashMap ();
54cdf0e10cSrcweir         maNodes = new Vector ();
55cdf0e10cSrcweir         maObjectList = new Vector ();
56cdf0e10cSrcweir         maContexts = new Vector ();
57cdf0e10cSrcweir         addMouseListener (this);
58cdf0e10cSrcweir         addMouseMotionListener (this);
59cdf0e10cSrcweir         maBoundingBox = new Rectangle (0,0,100,100);
60cdf0e10cSrcweir         maTree = null;
61cdf0e10cSrcweir         mnHOffset = 0;
62cdf0e10cSrcweir         mnVOffset = 0;
63cdf0e10cSrcweir         mnScale = 1;
64cdf0e10cSrcweir         setShowText(false);
65cdf0e10cSrcweir         setShowDescriptions (true);
66cdf0e10cSrcweir         setShowNames (true);
67cdf0e10cSrcweir         setAntialiasing (true);
68cdf0e10cSrcweir         maLastWidgetSize = new Dimension (0,0);
69cdf0e10cSrcweir     }
70cdf0e10cSrcweir 
71cdf0e10cSrcweir     /** Tell the canvas which tree view to use to highlight accessible
72cdf0e10cSrcweir         objects.
73cdf0e10cSrcweir     */
setTree(JTree aTree)74cdf0e10cSrcweir     public void setTree (JTree aTree)
75cdf0e10cSrcweir     {
76cdf0e10cSrcweir         if (maTree != null)
77cdf0e10cSrcweir             maTree.removeTreeSelectionListener (this);
78cdf0e10cSrcweir         maTree = aTree;
79cdf0e10cSrcweir         if (maTree != null)
80cdf0e10cSrcweir             maTree.addTreeSelectionListener (this);
81cdf0e10cSrcweir     }
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 
addNode(AccTreeNode aNode)86cdf0e10cSrcweir     public void addNode (AccTreeNode aNode)
87cdf0e10cSrcweir     {
88cdf0e10cSrcweir         if (maNodes.indexOf (aNode) == -1)
89cdf0e10cSrcweir         {
90cdf0e10cSrcweir             maNodes.add (aNode);
91cdf0e10cSrcweir 
92cdf0e10cSrcweir             CanvasShape aObject = (CanvasShape) maObjects.get (aNode);
93cdf0e10cSrcweir             if (aObject == null)
94cdf0e10cSrcweir             {
95cdf0e10cSrcweir                 aObject = new CanvasShape (aNode);
96cdf0e10cSrcweir                 // Update bounding box that includes all objects.
97cdf0e10cSrcweir                 if (maObjects.size() == 0)
98cdf0e10cSrcweir                     maBoundingBox = aObject.getBBox();
99cdf0e10cSrcweir                 else
100cdf0e10cSrcweir                     maBoundingBox = maBoundingBox.union (aObject.getBBox());
101cdf0e10cSrcweir 
102cdf0e10cSrcweir                 maObjects.put (aNode, aObject);
103cdf0e10cSrcweir                 maObjectList.add (aObject);
104cdf0e10cSrcweir 
105cdf0e10cSrcweir             }
106cdf0e10cSrcweir             repaint ();
107cdf0e10cSrcweir         }
108cdf0e10cSrcweir     }
109cdf0e10cSrcweir 
removeNode(AccTreeNode aNode)110cdf0e10cSrcweir     public void removeNode (AccTreeNode aNode)
111cdf0e10cSrcweir     {
112cdf0e10cSrcweir         int i = maNodes.indexOf (aNode);
113cdf0e10cSrcweir         if( i != -1 )
114cdf0e10cSrcweir         {
115cdf0e10cSrcweir             Object aObject = maObjects.get(aNode);
116cdf0e10cSrcweir             maObjectList.remove (aObject);
117cdf0e10cSrcweir             maObjects.remove (aObject);
118cdf0e10cSrcweir             maNodes.remove (aNode);
119cdf0e10cSrcweir             repaint ();
120cdf0e10cSrcweir         }
121cdf0e10cSrcweir     }
122cdf0e10cSrcweir 
updateNode(AccTreeNode aNode)123cdf0e10cSrcweir     public void updateNode (AccTreeNode aNode)
124cdf0e10cSrcweir     {
125cdf0e10cSrcweir         int i = maNodes.indexOf (aNode);
126cdf0e10cSrcweir         if (i != -1)
127cdf0e10cSrcweir         {
128cdf0e10cSrcweir             CanvasShape aObject = (CanvasShape)maObjects.get(aNode);
129cdf0e10cSrcweir             if (aObject != null)
130cdf0e10cSrcweir                 aObject.update();
131cdf0e10cSrcweir         }
132cdf0e10cSrcweir     }
133cdf0e10cSrcweir 
updateNodeGeometry(AccTreeNode aNode)134cdf0e10cSrcweir     public void updateNodeGeometry (AccTreeNode aNode)
135cdf0e10cSrcweir     {
136cdf0e10cSrcweir         CanvasShape aObject = (CanvasShape)maObjects.get(aNode);
137cdf0e10cSrcweir         if (aObject != null)
138cdf0e10cSrcweir             aObject.updateGeometry();
139cdf0e10cSrcweir     }
140cdf0e10cSrcweir 
clear()141cdf0e10cSrcweir     public void clear ()
142cdf0e10cSrcweir     {
143cdf0e10cSrcweir         while (maNodes.size() > 0)
144cdf0e10cSrcweir             removeNode ((AccTreeNode)maNodes.elementAt(0));
145cdf0e10cSrcweir 
146cdf0e10cSrcweir         maNodes.clear();
147cdf0e10cSrcweir         maObjects.clear();
148cdf0e10cSrcweir         maObjectList.clear();
149cdf0e10cSrcweir     }
150cdf0e10cSrcweir 
getShowDescriptions()151cdf0e10cSrcweir     public boolean getShowDescriptions ()
152cdf0e10cSrcweir     {
153cdf0e10cSrcweir         return Options.GetBoolean ("ShowDescriptions");
154cdf0e10cSrcweir     }
155cdf0e10cSrcweir 
setShowDescriptions(boolean bNewValue)156cdf0e10cSrcweir     public void setShowDescriptions (boolean bNewValue)
157cdf0e10cSrcweir     {
158cdf0e10cSrcweir         Options.SetBoolean ("ShowDescriptions", bNewValue);
159cdf0e10cSrcweir         repaint ();
160cdf0e10cSrcweir     }
161cdf0e10cSrcweir 
getShowNames()162cdf0e10cSrcweir     public boolean getShowNames ()
163cdf0e10cSrcweir     {
164cdf0e10cSrcweir         return Options.GetBoolean ("ShowNames");
165cdf0e10cSrcweir     }
166cdf0e10cSrcweir 
setShowNames(boolean bNewValue)167cdf0e10cSrcweir     public void setShowNames (boolean bNewValue)
168cdf0e10cSrcweir     {
169cdf0e10cSrcweir         Options.SetBoolean ("ShowNames", bNewValue);
170cdf0e10cSrcweir         repaint ();
171cdf0e10cSrcweir     }
172cdf0e10cSrcweir 
getAntialiasing()173cdf0e10cSrcweir     public boolean getAntialiasing ()
174cdf0e10cSrcweir     {
175cdf0e10cSrcweir         return Options.GetBoolean ("Antialiasing");
176cdf0e10cSrcweir     }
177cdf0e10cSrcweir 
setAntialiasing(boolean bNewValue)178cdf0e10cSrcweir     public void setAntialiasing (boolean bNewValue)
179cdf0e10cSrcweir     {
180cdf0e10cSrcweir         Options.SetBoolean ("Antialiasing", bNewValue);
181cdf0e10cSrcweir         repaint ();
182cdf0e10cSrcweir     }
183cdf0e10cSrcweir 
getShowText()184cdf0e10cSrcweir     public boolean getShowText ()
185cdf0e10cSrcweir     {
186cdf0e10cSrcweir         return Options.GetBoolean ("ShowText");
187cdf0e10cSrcweir     }
188cdf0e10cSrcweir 
setShowText(boolean bNewValue)189cdf0e10cSrcweir     public void setShowText (boolean bNewValue)
190cdf0e10cSrcweir     {
191cdf0e10cSrcweir         Options.SetBoolean ("ShowText", bNewValue);
192cdf0e10cSrcweir         repaint ();
193cdf0e10cSrcweir     }
194cdf0e10cSrcweir 
setZoomMode(int nZoomMode)195cdf0e10cSrcweir     public void setZoomMode (int nZoomMode)
196cdf0e10cSrcweir     {
197cdf0e10cSrcweir         Options.SetInteger ("ZoomMode", nZoomMode);
198cdf0e10cSrcweir         repaint ();
199cdf0e10cSrcweir     }
200cdf0e10cSrcweir 
getZoomMode()201cdf0e10cSrcweir     public int getZoomMode ()
202cdf0e10cSrcweir     {
203cdf0e10cSrcweir         return Options.GetInteger ("ZoomMode", WHOLE_SCREEN);
204cdf0e10cSrcweir     }
205cdf0e10cSrcweir 
206cdf0e10cSrcweir 
paintComponent(Graphics g)207cdf0e10cSrcweir     public void paintComponent (Graphics g)
208cdf0e10cSrcweir     {
209cdf0e10cSrcweir         synchronized (g)
210cdf0e10cSrcweir         {
211cdf0e10cSrcweir             super.paintComponent (g);
212cdf0e10cSrcweir 
213cdf0e10cSrcweir             Graphics2D g2 = (Graphics2D)g;
214cdf0e10cSrcweir             if (getAntialiasing())
215cdf0e10cSrcweir                 g2.setRenderingHint (RenderingHints.KEY_ANTIALIASING,
216cdf0e10cSrcweir                     RenderingHints.VALUE_ANTIALIAS_ON);
217cdf0e10cSrcweir             else
218cdf0e10cSrcweir                 g2.setRenderingHint (RenderingHints.KEY_ANTIALIASING,
219cdf0e10cSrcweir                     RenderingHints.VALUE_ANTIALIAS_OFF);
220cdf0e10cSrcweir 
221cdf0e10cSrcweir             setupTransformation ();
222cdf0e10cSrcweir 
223cdf0e10cSrcweir             // Draw the screen representation to give a hint of the location of the
224cdf0e10cSrcweir             // accessible object on the screen.
225cdf0e10cSrcweir             Dimension aScreenSize = Toolkit.getDefaultToolkit().getScreenSize();
226cdf0e10cSrcweir             Rectangle2D.Double aScreen = new Rectangle2D.Double (
227cdf0e10cSrcweir                 mnHOffset,
228cdf0e10cSrcweir                 mnVOffset,
229cdf0e10cSrcweir                 mnScale*aScreenSize.getWidth(),
230cdf0e10cSrcweir                 mnScale*aScreenSize.getHeight());
231*86e1cf34SPedro Giffuni             // Fill the screen rectangle and draw a frame around it to increase its visibility.
232cdf0e10cSrcweir             g2.setColor (new Color (250,240,230));
233cdf0e10cSrcweir             g2.fill (aScreen);
234cdf0e10cSrcweir             g2.setColor (Color.BLACK);
235cdf0e10cSrcweir             g2.draw (aScreen);
236cdf0e10cSrcweir 
237cdf0e10cSrcweir             synchronized (maObjectList)
238cdf0e10cSrcweir             {
239cdf0e10cSrcweir                 int nCount = maObjectList.size();
240cdf0e10cSrcweir                 boolean bShowDescriptions = getShowDescriptions();
241cdf0e10cSrcweir                 boolean bShowNames = getShowNames();
242cdf0e10cSrcweir                 boolean bShowText = getShowText();
243cdf0e10cSrcweir                 for (int i=0; i<nCount; i++)
244cdf0e10cSrcweir                 {
245cdf0e10cSrcweir                     CanvasShape aCanvasShape = (CanvasShape)maObjectList.elementAt(i);
246cdf0e10cSrcweir                     aCanvasShape.paint (
247cdf0e10cSrcweir                         g2,
248cdf0e10cSrcweir                         mnHOffset, mnVOffset, mnScale,
249cdf0e10cSrcweir                         bShowDescriptions, bShowNames, bShowText);
250cdf0e10cSrcweir                 }
251cdf0e10cSrcweir             }
252cdf0e10cSrcweir 
253cdf0e10cSrcweir             // Paint highlighted frame around active object as the last thing.
254cdf0e10cSrcweir             if (maActiveObject != null)
255cdf0e10cSrcweir                 maActiveObject.paint_highlight (
256cdf0e10cSrcweir                     g2,
257cdf0e10cSrcweir                     mnHOffset, mnVOffset, mnScale);
258cdf0e10cSrcweir         }
259cdf0e10cSrcweir     }
260cdf0e10cSrcweir 
261cdf0e10cSrcweir 
262cdf0e10cSrcweir 
263cdf0e10cSrcweir 
264cdf0e10cSrcweir     /** Set up the transformation so that the graphical display can show a
265cdf0e10cSrcweir         centered representation of the whole screen.
266cdf0e10cSrcweir     */
setupTransformation()267cdf0e10cSrcweir     private void setupTransformation ()
268cdf0e10cSrcweir     {
269cdf0e10cSrcweir         // Turn off scrollbars when showing the whole screen.  Otherwise show them when needed.
270cdf0e10cSrcweir         JViewport aViewport = (JViewport)getParent();
271cdf0e10cSrcweir         JScrollPane aScrollPane = (JScrollPane)aViewport.getParent();
272cdf0e10cSrcweir         int nZoomMode = getZoomMode();
273cdf0e10cSrcweir         if (nZoomMode == WHOLE_SCREEN)
274cdf0e10cSrcweir         {
275cdf0e10cSrcweir             if (aScrollPane.getHorizontalScrollBarPolicy()
276cdf0e10cSrcweir                 != JScrollPane.HORIZONTAL_SCROLLBAR_NEVER)
277cdf0e10cSrcweir                 aScrollPane.setHorizontalScrollBarPolicy (JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
278cdf0e10cSrcweir             if (aScrollPane.getVerticalScrollBarPolicy()
279cdf0e10cSrcweir                 != JScrollPane.VERTICAL_SCROLLBAR_NEVER)
280cdf0e10cSrcweir                 aScrollPane.setVerticalScrollBarPolicy (JScrollPane.VERTICAL_SCROLLBAR_NEVER);
281cdf0e10cSrcweir         }
282cdf0e10cSrcweir         else
283cdf0e10cSrcweir         {
284cdf0e10cSrcweir             if (aScrollPane.getHorizontalScrollBarPolicy()
285cdf0e10cSrcweir                 != JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED)
286cdf0e10cSrcweir                 aScrollPane.setHorizontalScrollBarPolicy (JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
287cdf0e10cSrcweir             if (aScrollPane.getVerticalScrollBarPolicy()
288cdf0e10cSrcweir                 != JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED)
289cdf0e10cSrcweir                 aScrollPane.setVerticalScrollBarPolicy (JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
290cdf0e10cSrcweir         }
291cdf0e10cSrcweir 
292cdf0e10cSrcweir         Dimension aScreenSize = Toolkit.getDefaultToolkit().getScreenSize();
293cdf0e10cSrcweir         Dimension aWidgetSize = aViewport.getSize();
294cdf0e10cSrcweir         {
295cdf0e10cSrcweir             if ((aScreenSize.getWidth() > 0) && (aScreenSize.getHeight() > 0))
296cdf0e10cSrcweir             {
297cdf0e10cSrcweir                 if (nZoomMode == WHOLE_SCREEN)
298cdf0e10cSrcweir                 {
299cdf0e10cSrcweir                     // Calculate the scales that would map the screen onto the
300cdf0e10cSrcweir                     // widget in both of the coordinate axes and select the
301cdf0e10cSrcweir                     // smaller
302cdf0e10cSrcweir                     // of the two: it maps the screen onto the widget in both
303cdf0e10cSrcweir                     // axes at the same time.
304cdf0e10cSrcweir                     double nHScale = (aWidgetSize.getWidth() - 10) / aScreenSize.getWidth();
305cdf0e10cSrcweir                     double nVScale = (aWidgetSize.getHeight() - 10) / aScreenSize.getHeight();
306cdf0e10cSrcweir                     if (nHScale < nVScale)
307cdf0e10cSrcweir                         mnScale = nHScale;
308cdf0e10cSrcweir                     else
309cdf0e10cSrcweir                         mnScale = nVScale;
310cdf0e10cSrcweir                 }
311cdf0e10cSrcweir                 else
312cdf0e10cSrcweir                 {
313cdf0e10cSrcweir                     mnScale = nZoomMode / 100.0;
314cdf0e10cSrcweir                 }
315cdf0e10cSrcweir 
316cdf0e10cSrcweir                 // Calculate offsets that center the scaled screen inside the widget.
317cdf0e10cSrcweir                 mnHOffset = (aWidgetSize.getWidth() - mnScale*aScreenSize.getWidth()) / 2.0;
318cdf0e10cSrcweir                 mnVOffset = (aWidgetSize.getHeight() - mnScale*aScreenSize.getHeight()) / 2.0;
319cdf0e10cSrcweir                 if (mnHOffset < 0)
320cdf0e10cSrcweir                     mnHOffset = 0;
321cdf0e10cSrcweir                 if (mnVOffset < 0)
322cdf0e10cSrcweir                     mnVOffset = 0;
323cdf0e10cSrcweir 
324cdf0e10cSrcweir                 setPreferredSize (new Dimension (
325cdf0e10cSrcweir                     (int)(2*mnHOffset + mnScale * aScreenSize.getWidth()),
326cdf0e10cSrcweir                     (int)(2*mnVOffset + mnScale * aScreenSize.getHeight())));
327cdf0e10cSrcweir                 revalidate ();
328cdf0e10cSrcweir             }
329cdf0e10cSrcweir             else
330cdf0e10cSrcweir             {
331cdf0e10cSrcweir                 // In case of a degenerate (not yet initialized?) screen size
332cdf0e10cSrcweir                 // use some meaningless default values.
333cdf0e10cSrcweir                 mnScale = 1;
334cdf0e10cSrcweir                 mnHOffset = 0;
335cdf0e10cSrcweir                 mnVOffset = 0;
336cdf0e10cSrcweir             }
337cdf0e10cSrcweir         }
338cdf0e10cSrcweir         maLastWidgetSize = aWidgetSize;
339cdf0e10cSrcweir     }
340cdf0e10cSrcweir 
341cdf0e10cSrcweir 
342cdf0e10cSrcweir 
343cdf0e10cSrcweir     /**  Call getAccessibleAt to determine accessible object under mouse.
344cdf0e10cSrcweir     */
mouseClicked(MouseEvent e)345cdf0e10cSrcweir     public void mouseClicked (MouseEvent e)
346cdf0e10cSrcweir     {
347cdf0e10cSrcweir     }
348cdf0e10cSrcweir 
mousePressed(MouseEvent e)349cdf0e10cSrcweir     public void mousePressed (MouseEvent e)
350cdf0e10cSrcweir     {
351cdf0e10cSrcweir         CanvasShape aObjectUnderMouse = FindCanvasShapeUnderMouse (e);
352cdf0e10cSrcweir         highlightObject (aObjectUnderMouse);
353cdf0e10cSrcweir         if ((e.getModifiers() & InputEvent.CTRL_MASK) != 0)
354cdf0e10cSrcweir         {
355cdf0e10cSrcweir             maTree.expandPath (aObjectUnderMouse.getPath());
356cdf0e10cSrcweir         }
357cdf0e10cSrcweir     }
358cdf0e10cSrcweir 
mouseReleased(MouseEvent e)359cdf0e10cSrcweir     public void mouseReleased (MouseEvent e)
360cdf0e10cSrcweir     {
361cdf0e10cSrcweir     }
362cdf0e10cSrcweir 
mouseEntered(MouseEvent e)363cdf0e10cSrcweir     public void mouseEntered (MouseEvent e)
364cdf0e10cSrcweir     {
365cdf0e10cSrcweir     }
366cdf0e10cSrcweir 
mouseExited(MouseEvent e)367cdf0e10cSrcweir     public void mouseExited (MouseEvent e)
368cdf0e10cSrcweir     {
369cdf0e10cSrcweir         // Deselect currently active object.
370cdf0e10cSrcweir         if (maActiveObject != null)
371cdf0e10cSrcweir         {
372cdf0e10cSrcweir             maActiveObject.unhighlight ();
373cdf0e10cSrcweir             maActiveObject = null;
374cdf0e10cSrcweir             repaint ();
375cdf0e10cSrcweir         }
376cdf0e10cSrcweir     }
377cdf0e10cSrcweir 
mouseDragged(MouseEvent e)378cdf0e10cSrcweir     public void mouseDragged (MouseEvent e)
379cdf0e10cSrcweir     {
380cdf0e10cSrcweir     }
381cdf0e10cSrcweir 
mouseMoved(MouseEvent e)382cdf0e10cSrcweir     public void mouseMoved (MouseEvent e)
383cdf0e10cSrcweir     {
384cdf0e10cSrcweir         if ((e.getModifiers() & InputEvent.SHIFT_MASK) != 0)
385cdf0e10cSrcweir             highlightObject (FindCanvasShapeUnderMouse (e));
386cdf0e10cSrcweir     }
387cdf0e10cSrcweir 
FindCanvasShapeUnderMouse(MouseEvent e)388cdf0e10cSrcweir     protected CanvasShape FindCanvasShapeUnderMouse (MouseEvent e)
389cdf0e10cSrcweir     {
390cdf0e10cSrcweir         int nObjects = maObjects.size();
391cdf0e10cSrcweir         CanvasShape aObjectUnderMouse = null;
392cdf0e10cSrcweir         int nCount = maObjectList.size();
393cdf0e10cSrcweir         for (int i=nCount-1; i>=0; --i)
394cdf0e10cSrcweir         {
395cdf0e10cSrcweir             CanvasShape aObject = (CanvasShape)maObjectList.elementAt(i);
396cdf0e10cSrcweir             if (aObject != null)
397cdf0e10cSrcweir                 if (aObject.contains (e.getX(),e.getY()))
398cdf0e10cSrcweir                 {
399cdf0e10cSrcweir                     aObjectUnderMouse = aObject;
400cdf0e10cSrcweir                     break;
401cdf0e10cSrcweir                 }
402cdf0e10cSrcweir         }
403cdf0e10cSrcweir         return aObjectUnderMouse;
404cdf0e10cSrcweir     }
405cdf0e10cSrcweir 
highlightObject(CanvasShape aNewActiveObject)406cdf0e10cSrcweir     protected boolean highlightObject (CanvasShape aNewActiveObject)
407cdf0e10cSrcweir     {
408cdf0e10cSrcweir         if (aNewActiveObject != maActiveObject)
409cdf0e10cSrcweir         {
410cdf0e10cSrcweir             if (maActiveObject != null)
411cdf0e10cSrcweir                 maActiveObject.unhighlight();
412cdf0e10cSrcweir 
413cdf0e10cSrcweir             maActiveObject = aNewActiveObject;
414cdf0e10cSrcweir             if (maActiveObject != null)
415cdf0e10cSrcweir             {
416cdf0e10cSrcweir                 if (maTree != null)
417cdf0e10cSrcweir                 {
418cdf0e10cSrcweir                     maTree.scrollPathToVisible (maActiveObject.getPath());
419cdf0e10cSrcweir                     maTree.setSelectionPath (maActiveObject.getPath());
420cdf0e10cSrcweir                     maTree.repaint ();
421cdf0e10cSrcweir                 }
422cdf0e10cSrcweir                 maActiveObject.highlight ();
423cdf0e10cSrcweir                 repaint ();
424cdf0e10cSrcweir             }
425cdf0e10cSrcweir             return true;
426cdf0e10cSrcweir         }
427cdf0e10cSrcweir         else
428cdf0e10cSrcweir             return false;
429cdf0e10cSrcweir     }
430cdf0e10cSrcweir 
431cdf0e10cSrcweir     /** Called when the selection of the tree changes.  Highlight the
432cdf0e10cSrcweir         corresponding graphical representation of the first selected object.
433cdf0e10cSrcweir     */
valueChanged(javax.swing.event.TreeSelectionEvent event)434cdf0e10cSrcweir     public void valueChanged (javax.swing.event.TreeSelectionEvent event)
435cdf0e10cSrcweir     {
436cdf0e10cSrcweir         TreePath aPath = event.getPath();
437cdf0e10cSrcweir         Object aObject = aPath.getLastPathComponent();
438cdf0e10cSrcweir         if (aObject instanceof AccTreeNode)
439cdf0e10cSrcweir         {
440cdf0e10cSrcweir             CanvasShape aCanvasShape = (CanvasShape)maObjects.get ((AccTreeNode)aObject);
441cdf0e10cSrcweir             if (highlightObject (aCanvasShape))
442cdf0e10cSrcweir                 repaint();
443cdf0e10cSrcweir         }
444cdf0e10cSrcweir     }
445cdf0e10cSrcweir 
446cdf0e10cSrcweir     private int
447cdf0e10cSrcweir         mnXAnchor,
448cdf0e10cSrcweir         mnYAnchor,
449cdf0e10cSrcweir         maResizeFlag;
450cdf0e10cSrcweir     private double
451cdf0e10cSrcweir         mnHOffset,
452cdf0e10cSrcweir         mnVOffset,
453cdf0e10cSrcweir         mnScale;
454cdf0e10cSrcweir     private CanvasShape
455cdf0e10cSrcweir         maActiveObject;
456cdf0e10cSrcweir     private java.util.HashMap
457cdf0e10cSrcweir         maObjects;
458cdf0e10cSrcweir     private Vector
459cdf0e10cSrcweir         maObjectList,
460cdf0e10cSrcweir         maContexts,
461cdf0e10cSrcweir         maNodes;
462cdf0e10cSrcweir     private Rectangle
463cdf0e10cSrcweir         maBoundingBox;
464cdf0e10cSrcweir     private JTree
465cdf0e10cSrcweir         maTree;
466cdf0e10cSrcweir     // The size of the widget at the last call of setupTransformation()
467cdf0e10cSrcweir     private Dimension
468cdf0e10cSrcweir         maLastWidgetSize;
469cdf0e10cSrcweir }
470