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 javax
.swing
.JLabel
;
25 import com
.sun
.star
.accessibility
.AccessibleEventId
;
26 import com
.sun
.star
.accessibility
.AccessibleEventObject
;
27 import com
.sun
.star
.accessibility
.XAccessibleText
;
28 import com
.sun
.star
.accessibility
.XAccessibleContext
;
29 import com
.sun
.star
.uno
.UnoRuntime
;
32 extends ListeningObjectView
34 /** Create a TextView when the given object supports the
35 XAccessibleText interface.
37 public static ObjectView
Create (
38 ObjectViewContainer aContainer
,
39 XAccessibleContext xContext
)
41 XAccessibleText xText
= UnoRuntime
.queryInterface(
42 XAccessibleText
.class, xContext
);
44 return new TextView (aContainer
);
50 private TextView (ObjectViewContainer aContainer
)
54 setLayout (new GridBagLayout());
55 GridBagConstraints aConstraints
= new GridBagConstraints ();
57 JLabel aLabel
= new JLabel ("Text:");
58 aConstraints
.gridy
= 0;
59 aConstraints
.weightx
= 1;
60 aConstraints
.fill
= GridBagConstraints
.HORIZONTAL
;
61 add (aLabel
, aConstraints
);
63 maTextLabel
= new JLabel ("");
64 aConstraints
.gridx
= 1;
65 aConstraints
.fill
= GridBagConstraints
.NONE
;
66 aConstraints
.anchor
= GridBagConstraints
.WEST
;
67 add (maTextLabel
, aConstraints
);
69 aLabel
= new JLabel ("Caret position:");
70 aConstraints
.gridx
= 0;
71 aConstraints
.gridy
= 1;
72 aConstraints
.weightx
= 1;
73 aConstraints
.fill
= GridBagConstraints
.HORIZONTAL
;
74 add (aLabel
, aConstraints
);
76 maCaretPositionLabel
= new JLabel ("");
77 aConstraints
.gridx
= 1;
78 aConstraints
.fill
= GridBagConstraints
.NONE
;
79 aConstraints
.anchor
= GridBagConstraints
.WEST
;
80 add (maCaretPositionLabel
, aConstraints
);
84 /** Additionally to the context store a reference to the
85 XAccessibleText interface.
88 public void SetObject (XAccessibleContext xObject
)
90 mxText
= UnoRuntime
.queryInterface(
91 XAccessibleText
.class, xObject
);
92 super.SetObject (xObject
);
96 synchronized public void Update ()
100 maTextLabel
.setText ("<null object>");
101 maCaretPositionLabel
.setText ("<null object>");
105 maTextLabel
.setText (mxText
.getText());
106 maCaretPositionLabel
.setText (Integer
.toString(mxText
.getCaretPosition()));
111 public String
GetTitle ()
117 public void notifyEvent (AccessibleEventObject aEvent
)
119 System
.out
.println (aEvent
);
120 switch (aEvent
.EventId
)
122 case AccessibleEventId
.TEXT_CHANGED
:
123 case AccessibleEventId
.CARET_CHANGED
:
131 maCaretPositionLabel
;
132 private XAccessibleText mxText
;