2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import java
.awt
.Color
;
22 import java
.awt
.Dimension
;
23 import java
.awt
.Graphics
;
24 import java
.awt
.Graphics2D
;
25 import java
.awt
.Insets
;
26 import java
.awt
.Rectangle
;
27 import java
.awt
.RenderingHints
;
28 import java
.awt
.event
.MouseListener
;
29 import java
.awt
.event
.MouseEvent
;
31 import java
.awt
.geom
.AffineTransform
;
34 import javax
.swing
.JLabel
;
35 import com
.sun
.star
.accessibility
.AccessibleEventObject
;
36 import com
.sun
.star
.accessibility
.AccessibleEventId
;
37 import com
.sun
.star
.accessibility
.AccessibleStateType
;
38 import com
.sun
.star
.accessibility
.XAccessibleContext
;
39 import com
.sun
.star
.accessibility
.XAccessibleStateSet
;
41 import tools
.NameProvider
;
43 public class StateSetView
44 extends ListeningObjectView
45 implements MouseListener
47 /** Create a FocusView when the given object supports the
48 XAccessibleComponent interface.
50 static public ObjectView
Create (
51 ObjectViewContainer aContainer
,
52 XAccessibleContext xContext
)
54 ObjectView aView
= null;
56 if (mnViewMode
== SHOW_ALL_STATES
)
57 aView
= StateSetAllView
.Create (aContainer
, xContext
);
59 aView
= StateSetSetView
.Create (aContainer
, xContext
);
63 public StateSetView (ObjectViewContainer aContainer
)
67 addMouseListener (this);
70 private void SetViewMode (int nViewMode
)
72 mnViewMode
= nViewMode
;
75 case SHOW_SET_STATES
:
76 maContainer
.ReplaceView (
78 StateSetSetView
.class);
80 case SHOW_ALL_STATES
:
81 maContainer
.ReplaceView (
83 StateSetAllView
.class);
86 maContainer
.SetObject (mxContext
);
91 public String
GetTitle ()
96 public void notifyEvent (AccessibleEventObject aEvent
)
98 if (aEvent
.EventId
== AccessibleEventId
.STATE_CHANGED
)
102 public void mouseClicked(MouseEvent e
)
106 case SHOW_SET_STATES
:
107 SetViewMode (SHOW_ALL_STATES
);
109 case SHOW_ALL_STATES
:
110 SetViewMode (SHOW_SET_STATES
);
114 public void mouseEntered (MouseEvent e
) {}
115 public void mouseExited (MouseEvent e
) {}
116 public void mousePressed (MouseEvent e
) {}
117 public void mouseReleased(MouseEvent e
) {}
119 private final static int SHOW_SET_STATES
= 0;
120 private final static int SHOW_ALL_STATES
= 1;
121 private static int mnViewMode
= SHOW_ALL_STATES
;
125 public static class StateSetAllView
128 /** Create a FocusView when the given object supports the
129 XAccessibleComponent interface.
131 static public ObjectView
Create (
132 ObjectViewContainer aContainer
,
133 XAccessibleContext xContext
)
135 if (xContext
!= null)
136 return new StateSetAllView (aContainer
);
141 public StateSetAllView (ObjectViewContainer aContainer
)
145 setPreferredSize (new Dimension(300,90));
146 setMinimumSize (new Dimension(200,80));
149 public void paintChildren (Graphics g
)
153 super.paintChildren (g
);
155 // Calculcate the are inside the border.
156 Insets aInsets
= getInsets ();
157 Dimension aSize
= getSize();
158 Rectangle aWidgetArea
= new Rectangle (
161 aSize
.width
-aInsets
.left
-aInsets
.right
,
162 aSize
.height
-aInsets
.top
-aInsets
.bottom
);
164 PaintAllStates ((Graphics2D
)g
, aWidgetArea
);
168 private void PaintAllStates (Graphics2D g
, Rectangle aWidgetArea
)
170 Color aTextColor
= g
.getColor();
173 RenderingHints
.KEY_ANTIALIASING
,
174 RenderingHints
.VALUE_ANTIALIAS_ON
);
176 XAccessibleStateSet xStateSet
= mxContext
.getAccessibleStateSet();
177 if (xStateSet
!= null)
179 short aStates
[] = xStateSet
.getStates ();
180 final int nMaxStateIndex
= AccessibleStateType
.MANAGES_DESCENDANTS
;
181 int nStateWidth
= (aWidgetArea
.width
-12) / (nMaxStateIndex
+1);
182 AffineTransform aTransform
= g
.getTransform ();
183 g
.setColor (aTextColor
);
184 int y
= aWidgetArea
.y
+aWidgetArea
.height
- 12;
185 double nTextRotation
= -0.9;//-java.lang.Math.PI/2;
188 // Create a shape for the boxes.
189 int nBoxWidth
= nStateWidth
-2;
192 Rectangle aCheckBox
= new Rectangle (-nBoxWidth
/2,0,nBoxWidth
,nBoxWidth
);
194 for (short i
=0; i
<=nMaxStateIndex
; i
++)
196 int x
= nStateWidth
+ i
* nStateWidth
;
197 String sStateName
= NameProvider
.getStateName (i
);
198 boolean bStateSet
= xStateSet
.contains (i
);
199 g
.setTransform (aTransform
);
203 g
.setColor (Color
.GREEN
);
205 g
.setColor (aTextColor
);
208 g
.rotate (nTextRotation
);
209 g
.scale (nScale
, nScale
);
211 g
.drawString (sStateName
, 0,0);
218 public static class StateSetSetView
221 static public ObjectView
Create (
222 ObjectViewContainer aContainer
,
223 XAccessibleContext xContext
)
225 if (xContext
!= null)
226 return new StateSetSetView (aContainer
);
231 public StateSetSetView (ObjectViewContainer aContainer
)
236 setPreferredSize (new Dimension(300,90));
240 synchronized public void Update ()
242 XAccessibleStateSet xStateSet
= mxContext
.getAccessibleStateSet();
243 if (xStateSet
!= null)
245 String sStates
= new String ();
246 short aStates
[] = xStateSet
.getStates();
247 for (int i
=0; i
<aStates
.length
; i
++)
250 sStates
= sStates
+ ", ";
251 sStates
= sStates
+ NameProvider
.getStateName(aStates
[i
]);
253 maStates
.setText (sStates
);
257 private JLabel maStates
;