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