3 import javax
.swing
.tree
.*;
4 import java
.awt
.geom
.Rectangle2D
;
6 import com
.sun
.star
.beans
.XPropertyChangeListener
;
7 import com
.sun
.star
.beans
.PropertyChangeEvent
;
9 import com
.sun
.star
.accessibility
.XAccessible
;
10 import com
.sun
.star
.accessibility
.XAccessibleContext
;
11 import com
.sun
.star
.accessibility
.XAccessibleComponent
;
12 import com
.sun
.star
.accessibility
.XAccessibleExtendedComponent
;
13 import com
.sun
.star
.accessibility
.XAccessibleText
;
14 import com
.sun
.star
.accessibility
.XAccessibleStateSet
;
15 import com
.sun
.star
.accessibility
.AccessibleStateType
;
19 public final Color maHighlightColor
= Color
.red
;
20 public final Color maSelectionColor
= Color
.green
;
21 public final Color maFocusColor
= Color
.blue
;
23 // public AccessibleObject (XAccessibleContext xContext, TreePath aPath)
24 public CanvasShape (AccTreeNode aNode
)
27 mxContext
= aNode
.getContext();
28 msName
= "name unknown";
29 msDescription
= "description unknown";
30 maShape
= new Rectangle2D
.Double (-10,-10,10,10);
31 maPosition
= new Point (-10,-10);
32 maSize
= new Dimension (10,10);
33 maFgColor
= java
.awt
.Color
.black
;
34 maBgColor
= Color
.blue
;
36 mbHighlighted
= false;
39 mxComponent
= aNode
.getComponent();
46 /** Update the data obtained from the xAccessible.
50 if (mxContext
!= null)
52 msName
= mxContext
.getAccessibleName();
53 msDescription
= mxContext
.getAccessibleDescription();
54 mnRole
= mxContext
.getAccessibleRole();
56 // Extract the selected and focused flag.
57 XAccessibleStateSet xStateSet
= mxContext
.getAccessibleStateSet ();
58 if (xStateSet
!= null)
60 mbSelected
= xStateSet
.contains (AccessibleStateType
.SELECTED
);
61 mbFocused
= xStateSet
.contains (AccessibleStateType
.FOCUSED
);
66 if (mxComponent
!= null)
68 // Note: alpha values in office 0..255 have to be mapped to
70 Color aCol
= new Color (mxComponent
.getForeground(), true);
71 maFgColor
= new Color (aCol
.getRed (),
74 0xff - aCol
.getAlpha ());
75 aCol
= new Color (mxComponent
.getBackground(), true);
76 maBgColor
= new Color (aCol
.getRed (),
79 0xff - aCol
.getAlpha ());
83 public void updateGeometry ()
85 if (mxComponent
!= null)
87 com
.sun
.star
.awt
.Point aLocationOnScreen
= mxComponent
.getLocationOnScreen();
88 com
.sun
.star
.awt
.Size aSizeOnScreen
= mxComponent
.getSize();
89 maPosition
= new Point (
92 maSize
= new Dimension (
94 aSizeOnScreen
.Height
);
99 /** Paint the object into the specified canvas. It is transformed
100 according to the specified offset and scale.
102 public void paint (Graphics2D g
,
103 double nXOffset
, double nYOffset
, double nScaleFactor
,
104 boolean bShowDescription
, boolean bShowName
, boolean bShowText
)
107 // Transform the object's position and size according to the
108 // specified offset and scale.
109 Point aLocation
= new Point();
110 maShape
= new Rectangle2D
.Double (
111 maPosition
.x
* nScaleFactor
+ nXOffset
,
112 maPosition
.y
* nScaleFactor
+ nYOffset
,
113 maSize
.width
* nScaleFactor
,
114 maSize
.height
* nScaleFactor
);
116 // Fill the object's bounding box with its background color if it
118 if (mxContext
.getAccessibleChildCount() == 0)
120 g
.setColor (maBgColor
);
124 // Remove alpha channel from color before drawing the frame.
125 Color color
= maFgColor
;
126 if (maFgColor
.getAlpha()<128)
127 color
= new Color (maFgColor
.getRed(), maFgColor
.getGreen(), maFgColor
.getBlue());
133 g
.setColor (maFocusColor
);
134 for (int x
=0; x
<=2; x
++)
135 for (int y
=0; y
<=2; y
++)
137 new Rectangle2D
.Double (
138 maShape
.x
+ x
/2.0 * maShape
.width
-3,
139 maShape
.y
+ y
/2.0 * maShape
.height
-3,
145 g
.setColor (maSelectionColor
);
146 for (int x
=0; x
<=2; x
++)
147 for (int y
=0; y
<=2; y
++)
149 new Rectangle2D
.Double (
150 maShape
.x
+ x
/2.0 * maShape
.width
-2,
151 maShape
.y
+ y
/2.0 * maShape
.height
-2,
156 // Write the object's text OR name and description.
157 g
.setColor (maFgColor
);
160 if (bShowDescription
)
161 paintDescription (g
);
170 public void paint_highlight (Graphics2D g
,
171 double nXOffset
, double nYOffset
, double nScaleFactor
)
174 g
.setColor (maHighlightColor
);
176 g
.setColor (maFgColor
);
183 private void paintName (Graphics2D g
)
185 g
.drawString ("Name: " + msName
,
187 (float)maShape
.y
+15);
192 private void paintDescription (Graphics2D g
)
194 g
.drawString ("Description: " + msDescription
,
196 (float)maShape
.y
+35);
202 private void paintText (Graphics2D g
)
204 XAccessibleText xText
= null;
205 // get XAccessibleText
206 xText
= maNode
.getText();
208 // Draw every character in the text string.
211 String sText
= xText
.getText();
214 for(int i
= 0; i
< sText
.length(); i
++)
216 com
.sun
.star
.awt
.Rectangle aRect
=
217 xText
.getCharacterBounds(i
);
219 double x
= maShape
.x
+ aRect
.X
;
220 double y
= maShape
.y
+ aRect
.Y
+ aRect
.Height
;
222 g
.drawString(sText
.substring(i
, i
+1), (float)x
, (float)y
);
225 catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
)
233 /** Callback for disposing events.
235 public void disposing (com
.sun
.star
.lang
.EventObject e
)
237 System
.out
.println ("Disposing");
243 /** Compute whether the specified point lies inside the object's
246 public boolean contains (int x
, int y
)
248 return (maShape
.contains (x
,y
));
251 public void highlight ()
253 mbHighlighted
= true;
256 public void unhighlight ()
258 mbHighlighted
= false;
261 public boolean isHighlighted ()
263 return mbHighlighted
;
266 public Rectangle
getBBox ()
268 return new Rectangle (maPosition
, maSize
);
271 public Point
getOrigin ()
276 public TreePath
getPath ()
278 return new TreePath (maNode
.createPath());
281 public int getRole ()
286 public XAccessibleContext
getContext ()
291 public XAccessibleComponent
getComponent ()
296 public String
toString ()
298 return ">"+msName
+", "+msDescription
+" +"+maPosition
.x
+"+"+maPosition
.y
299 +"x"+maSize
.width
+"x"+maSize
.height
+"<";
304 private XAccessibleContext
306 private XAccessibleComponent
311 private Rectangle2D
.Double
322 // Highlighting objects is an internal concept. Corresponds to selection in the tree view.
324 // Set when the accessible object is selected.
326 // Set when the accessible object is focused.