fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / toolkit / test / accessibility / ov / StateSetView.java
blobce0a3ff8582e33fa1628e3fe15c36a3881384527
1 /*
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 .
19 package ov;
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;
55 if (xContext != null)
56 if (mnViewMode == SHOW_ALL_STATES)
57 aView = StateSetAllView.Create (aContainer, xContext);
58 else
59 aView = StateSetSetView.Create (aContainer, xContext);
60 return aView;
63 public StateSetView (ObjectViewContainer aContainer)
65 super (aContainer);
67 addMouseListener (this);
70 private void SetViewMode (int nViewMode)
72 mnViewMode = nViewMode;
73 switch (mnViewMode)
75 case SHOW_SET_STATES :
76 maContainer.ReplaceView (
77 getClass(),
78 StateSetSetView.class);
79 break;
80 case SHOW_ALL_STATES :
81 maContainer.ReplaceView (
82 getClass(),
83 StateSetAllView.class);
84 break;
86 maContainer.SetObject (mxContext);
91 public String GetTitle ()
93 return ("StateSet");
96 public void notifyEvent (AccessibleEventObject aEvent)
98 if (aEvent.EventId == AccessibleEventId.STATE_CHANGED)
99 Update();
102 public void mouseClicked(MouseEvent e)
104 switch (mnViewMode)
106 case SHOW_SET_STATES :
107 SetViewMode (SHOW_ALL_STATES);
108 break;
109 case SHOW_ALL_STATES :
110 SetViewMode (SHOW_SET_STATES);
111 break;
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
126 extends StateSetView
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);
137 else
138 return null;
141 public StateSetAllView (ObjectViewContainer aContainer)
143 super (aContainer);
145 setPreferredSize (new Dimension(300,90));
146 setMinimumSize (new Dimension(200,80));
149 public void paintChildren (Graphics g)
151 synchronized (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 (
159 aInsets.left,
160 aInsets.top,
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();
172 g.setRenderingHint (
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;
186 double nScale = 0.6;
188 // Create a shape for the boxes.
189 int nBoxWidth = nStateWidth-2;
190 if (nBoxWidth > 8)
191 nBoxWidth = 8;
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);
200 g.translate (x,y);
201 if (bStateSet)
203 g.setColor (Color.GREEN);
204 g.fill (aCheckBox);
205 g.setColor (aTextColor);
207 g.draw (aCheckBox);
208 g.rotate (nTextRotation);
209 g.scale (nScale, nScale);
210 g.translate (2,-2);
211 g.drawString (sStateName, 0,0);
218 public static class StateSetSetView
219 extends StateSetView
221 static public ObjectView Create (
222 ObjectViewContainer aContainer,
223 XAccessibleContext xContext)
225 if (xContext != null)
226 return new StateSetSetView (aContainer);
227 else
228 return null;
231 public StateSetSetView (ObjectViewContainer aContainer)
233 super (aContainer);
235 maStates = null;
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++)
249 if (i > 0)
250 sStates = sStates + ", ";
251 sStates = sStates + NameProvider.getStateName(aStates[i]);
253 maStates.setText (sStates);
257 private JLabel maStates;