4 import java
.awt
.BorderLayout
;
5 import java
.awt
.Dimension
;
6 import java
.awt
.Graphics
;
7 import java
.awt
.Graphics2D
;
8 import java
.awt
.Insets
;
9 import java
.awt
.Rectangle
;
10 import java
.awt
.RenderingHints
;
11 import java
.awt
.Shape
;
13 import java
.awt
.event
.MouseListener
;
14 import java
.awt
.event
.MouseEvent
;
16 import java
.awt
.geom
.Rectangle2D
;
17 import java
.awt
.geom
.AffineTransform
;
20 import javax
.swing
.JLabel
;
21 import javax
.swing
.JPanel
;
22 import javax
.swing
.border
.Border
;
24 import com
.sun
.star
.accessibility
.AccessibleEventObject
;
25 import com
.sun
.star
.accessibility
.AccessibleEventId
;
26 import com
.sun
.star
.accessibility
.AccessibleStateType
;
27 import com
.sun
.star
.accessibility
.XAccessibleContext
;
28 import com
.sun
.star
.accessibility
.XAccessibleStateSet
;
30 import tools
.NameProvider
;
32 public class StateSetView
33 extends ListeningObjectView
34 implements MouseListener
36 /** Create a FocusView when the given object supports the
37 XAccessibleComponent interface.
39 static public ObjectView
Create (
40 ObjectViewContainer aContainer
,
41 XAccessibleContext xContext
)
43 ObjectView aView
= null;
45 if (mnViewMode
== SHOW_ALL_STATES
)
46 aView
= StateSetAllView
.Create (aContainer
, xContext
);
48 aView
= StateSetSetView
.Create (aContainer
, xContext
);
52 public StateSetView (ObjectViewContainer aContainer
)
56 addMouseListener (this);
59 private void SetViewMode (int nViewMode
)
61 mnViewMode
= nViewMode
;
64 case SHOW_SET_STATES
:
65 maContainer
.ReplaceView (
67 StateSetSetView
.class);
69 case SHOW_ALL_STATES
:
70 maContainer
.ReplaceView (
72 StateSetAllView
.class);
75 aContainer
.SetObject (mxContext
);
80 public String
GetTitle ()
85 public void notifyEvent (AccessibleEventObject aEvent
)
87 if (aEvent
.EventId
== AccessibleEventId
.STATE_CHANGED
)
91 public void mouseClicked(MouseEvent e
)
95 case SHOW_SET_STATES
:
96 SetViewMode (SHOW_ALL_STATES
);
98 case SHOW_ALL_STATES
:
99 SetViewMode (SHOW_SET_STATES
);
103 public void mouseEntered (MouseEvent e
) {}
104 public void mouseExited (MouseEvent e
) {}
105 public void mousePressed (MouseEvent e
) {}
106 public void mouseReleased(MouseEvent e
) {}
108 private static int mnViewMode
= SHOW_ALL_STATES
;
109 private final static int SHOW_SET_STATES
= 0;
110 private final static int SHOW_ALL_STATES
= 1;
114 public class StateSetAllView
117 /** Create a FocusView when the given object supports the
118 XAccessibleComponent interface.
120 static public ObjectView
Create (
121 ObjectViewContainer aContainer
,
122 XAccessibleContext xContext
)
124 if (xContext
!= null)
125 return new StateSetAllView (aContainer
);
130 public StateSetAllView (ObjectViewContainer aContainer
)
134 setPreferredSize (new Dimension(300,90));
135 setMinimumSize (new Dimension(200,80));
138 public void paintChildren (Graphics g
)
142 super.paintChildren (g
);
144 // Calculcate the are inside the border.
145 Insets aInsets
= getInsets ();
146 Dimension aSize
= getSize();
147 Rectangle aWidgetArea
= new Rectangle (
150 aSize
.width
-aInsets
.left
-aInsets
.right
,
151 aSize
.height
-aInsets
.top
-aInsets
.bottom
);
153 PaintAllStates ((Graphics2D
)g
, aWidgetArea
);
157 private void PaintAllStates (Graphics2D g
, Rectangle aWidgetArea
)
159 Color aTextColor
= g
.getColor();
162 RenderingHints
.KEY_ANTIALIASING
,
163 RenderingHints
.VALUE_ANTIALIAS_ON
);
165 XAccessibleStateSet xStateSet
= mxContext
.getAccessibleStateSet();
166 if (xStateSet
!= null)
168 short aStates
[] = xStateSet
.getStates ();
169 final int nMaxStateIndex
= AccessibleStateType
.MANAGES_DESCENDANTS
;
170 int nStateWidth
= (aWidgetArea
.width
-12) / (nMaxStateIndex
+1);
171 AffineTransform aTransform
= g
.getTransform ();
172 g
.setColor (aTextColor
);
173 int y
= aWidgetArea
.y
+aWidgetArea
.height
- 12;
174 double nTextRotation
= -0.9;//-java.lang.Math.PI/2;
177 // Create a shape for the boxes.
178 int nBoxWidth
= nStateWidth
-2;
181 Rectangle aCheckBox
= new Rectangle (-nBoxWidth
/2,0,nBoxWidth
,nBoxWidth
);
183 for (short i
=0; i
<=nMaxStateIndex
; i
++)
185 int x
= nStateWidth
+ i
* nStateWidth
;
186 String sStateName
= NameProvider
.getStateName (i
);
187 boolean bStateSet
= xStateSet
.contains (i
);
188 g
.setTransform (aTransform
);
192 g
.setColor (Color
.GREEN
);
194 g
.setColor (aTextColor
);
197 g
.rotate (nTextRotation
);
198 g
.scale (nScale
, nScale
);
200 g
.drawString (sStateName
, 0,0);
207 public class StateSetSetView
210 static public ObjectView
Create (
211 ObjectViewContainer aContainer
,
212 XAccessibleContext xContext
)
214 if (xContext
!= null)
215 return new StateSetSetView (aContainer
);
220 public StateSetSetView (ObjectViewContainer aContainer
)
225 setPreferredSize (new Dimension(300,90));
229 synchronized public void Update ()
231 XAccessibleStateSet xStateSet
= mxContext
.getAccessibleStateSet();
232 if (xStateSet
!= null)
234 String sStates
= new String ();
235 short aStates
[] = xStateSet
.getStates();
236 for (int i
=0; i
<aStates
.length
; i
++)
239 sStates
= sStates
+ ", ";
240 sStates
= sStates
+ NameProvider
.getStateName(aStates
[i
]);
242 maStates
.setText (sStates
);
246 private JLabel maStates
;