bump product version to 7.2.5.1
[LibreOffice.git] / toolkit / test / accessibility / ov / FocusView.java
blobcca1a6a0cf1780c02a8b58b56786553e12a30fe7
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.GridBagConstraints;
22 import java.awt.GridBagLayout;
23 import java.awt.event.ActionListener;
24 import java.awt.event.ActionEvent;
26 import javax.swing.JButton;
27 import javax.swing.JLabel;
29 import com.sun.star.accessibility.AccessibleEventId;
30 import com.sun.star.accessibility.AccessibleEventObject;
31 import com.sun.star.accessibility.AccessibleStateType;
32 import com.sun.star.accessibility.XAccessibleComponent;
33 import com.sun.star.accessibility.XAccessibleContext;
34 import com.sun.star.accessibility.XAccessibleStateSet;
35 import com.sun.star.uno.UnoRuntime;
37 public class FocusView
38 extends ListeningObjectView
39 implements ActionListener
41 /** Create a FocusView when the given object supports the
42 XAccessibleComponent interface.
44 public static ObjectView Create (
45 ObjectViewContainer aContainer,
46 XAccessibleContext xContext)
48 XAccessibleComponent xComponent = UnoRuntime.queryInterface(
49 XAccessibleComponent.class, xContext);
50 if (xComponent != null)
51 return new FocusView (aContainer);
52 else
53 return null;
56 private FocusView (ObjectViewContainer aContainer)
58 super (aContainer);
60 setLayout (new GridBagLayout());
61 GridBagConstraints aConstraints = new GridBagConstraints ();
63 maFocused = new JLabel ();
64 aConstraints.gridy = 0;
65 aConstraints.weightx = 1;
66 aConstraints.fill = GridBagConstraints.HORIZONTAL;
67 add (maFocused, aConstraints);
69 maGrabFocus = new JButton ("grabFocus");
70 aConstraints.gridy = 1;
71 aConstraints.fill = GridBagConstraints.NONE;
72 aConstraints.anchor = GridBagConstraints.WEST;
73 add (maGrabFocus, aConstraints);
75 maGrabFocus.addActionListener (this);
78 /** Additionally to the context store a reference to the
79 XAccessibleComponent interface.
81 @Override
82 public void SetObject (XAccessibleContext xObject)
84 mxComponent = UnoRuntime.queryInterface(
85 XAccessibleComponent.class, xObject);
86 super.SetObject (xObject);
89 @Override
90 synchronized public void Destroy ()
92 super.Destroy();
93 maGrabFocus.removeActionListener (this);
96 @Override
97 synchronized public void Update ()
99 if (mxContext == null)
101 maFocused.setText ("<null object>");
102 maGrabFocus.setEnabled (false);
104 else
106 XAccessibleStateSet aStateSet = mxContext.getAccessibleStateSet();
107 if (aStateSet.contains(AccessibleStateType.FOCUSED))
108 maFocused.setText ("focused");
109 else
110 maFocused.setText ("not focused");
111 if (maGrabFocus != null)
112 maGrabFocus.setEnabled (true);
116 @Override
117 public String GetTitle ()
119 return "Focus";
122 synchronized public void actionPerformed (ActionEvent aEvent)
124 if (aEvent.getActionCommand().equals("grabFocus"))
126 mxComponent.grabFocus();
130 @Override
131 public void notifyEvent (AccessibleEventObject aEvent)
133 System.out.println (aEvent);
134 if (aEvent.EventId == AccessibleEventId.STATE_CHANGED)
135 Update ();
138 private final JLabel maFocused;
139 private final JButton maGrabFocus;
140 private XAccessibleComponent mxComponent;