tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / toolkit / test / accessibility / ov / FocusView.java
blob0428403f80b819e260ad1a4f8709f3b32d5bad56
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.uno.UnoRuntime;
36 public class FocusView
37 extends ListeningObjectView
38 implements ActionListener
40 /** Create a FocusView when the given object supports the
41 XAccessibleComponent interface.
43 public static ObjectView Create (
44 ObjectViewContainer aContainer,
45 XAccessibleContext xContext)
47 XAccessibleComponent xComponent = UnoRuntime.queryInterface(
48 XAccessibleComponent.class, xContext);
49 if (xComponent != null)
50 return new FocusView (aContainer);
51 else
52 return null;
55 private FocusView (ObjectViewContainer aContainer)
57 super (aContainer);
59 setLayout (new GridBagLayout());
60 GridBagConstraints aConstraints = new GridBagConstraints ();
62 maFocused = new JLabel ();
63 aConstraints.gridy = 0;
64 aConstraints.weightx = 1;
65 aConstraints.fill = GridBagConstraints.HORIZONTAL;
66 add (maFocused, aConstraints);
68 maGrabFocus = new JButton ("grabFocus");
69 aConstraints.gridy = 1;
70 aConstraints.fill = GridBagConstraints.NONE;
71 aConstraints.anchor = GridBagConstraints.WEST;
72 add (maGrabFocus, aConstraints);
74 maGrabFocus.addActionListener (this);
77 /** Additionally to the context store a reference to the
78 XAccessibleComponent interface.
80 @Override
81 public void SetObject (XAccessibleContext xObject)
83 mxComponent = UnoRuntime.queryInterface(
84 XAccessibleComponent.class, xObject);
85 super.SetObject (xObject);
88 @Override
89 synchronized public void Destroy ()
91 super.Destroy();
92 maGrabFocus.removeActionListener (this);
95 @Override
96 synchronized public void Update ()
98 if (mxContext == null)
100 maFocused.setText ("<null object>");
101 maGrabFocus.setEnabled (false);
103 else
105 long aStateSet = mxContext.getAccessibleStateSet();
106 if (aStateSet & AccessibleStateType.FOCUSED)
107 maFocused.setText ("focused");
108 else
109 maFocused.setText ("not focused");
110 if (maGrabFocus != null)
111 maGrabFocus.setEnabled (true);
115 @Override
116 public String GetTitle ()
118 return "Focus";
121 synchronized public void actionPerformed (ActionEvent aEvent)
123 if (aEvent.getActionCommand().equals("grabFocus"))
125 mxComponent.grabFocus();
129 @Override
130 public void notifyEvent (AccessibleEventObject aEvent)
132 System.out.println (aEvent);
133 if (aEvent.EventId == AccessibleEventId.STATE_CHANGED)
134 Update ();
137 private final JLabel maFocused;
138 private final JButton maGrabFocus;
139 private XAccessibleComponent mxComponent;