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
.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 static public 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
);
56 public FocusView (ObjectViewContainer 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 public void SetObject (XAccessibleContext xObject
)
83 mxComponent
= UnoRuntime
.queryInterface(
84 XAccessibleComponent
.class, xObject
);
85 super.SetObject (xObject
);
88 synchronized public void Destroy ()
91 maGrabFocus
.removeActionListener (this);
94 synchronized public void Update ()
96 if (mxContext
== null)
98 maFocused
.setText ("<null object>");
99 maGrabFocus
.setEnabled (false);
103 XAccessibleStateSet aStateSet
= mxContext
.getAccessibleStateSet();
104 if (aStateSet
.contains(AccessibleStateType
.FOCUSED
))
105 maFocused
.setText ("focused");
107 maFocused
.setText ("not focused");
108 if (maGrabFocus
!= null)
109 maGrabFocus
.setEnabled (true);
113 public String
GetTitle ()
118 synchronized public void actionPerformed (ActionEvent aEvent
)
120 if (aEvent
.getActionCommand().equals("grabFocus"))
122 mxComponent
.grabFocus();
126 public void notifyEvent (AccessibleEventObject aEvent
)
128 System
.out
.println (aEvent
);
129 if (aEvent
.EventId
== AccessibleEventId
.STATE_CHANGED
)
133 private JLabel maFocused
;
134 private JButton maGrabFocus
;
135 private XAccessibleComponent mxComponent
;