tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / toolkit / test / accessibility / ov / TextView.java
blob518d5ff50788272bd63ccba725bb96f6a4832be4
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 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;
31 public class TextView
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);
43 if (xText != null)
44 return new TextView (aContainer);
45 else
46 return null;
50 private TextView (ObjectViewContainer aContainer)
52 super (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.
87 @Override
88 public void SetObject (XAccessibleContext xObject)
90 mxText = UnoRuntime.queryInterface(
91 XAccessibleText.class, xObject);
92 super.SetObject (xObject);
95 @Override
96 synchronized public void Update ()
98 if (mxText == null)
100 maTextLabel.setText ("<null object>");
101 maCaretPositionLabel.setText ("<null object>");
103 else
105 maTextLabel.setText (mxText.getText());
106 maCaretPositionLabel.setText (Integer.toString(mxText.getCaretPosition()));
110 @Override
111 public String GetTitle ()
113 return "Text";
116 @Override
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 :
124 Update ();
125 break;
129 private final JLabel
130 maTextLabel,
131 maCaretPositionLabel;
132 private XAccessibleText mxText;