1*1b0aaa91SAndrew Rist /************************************************************** 2*1b0aaa91SAndrew Rist * 3*1b0aaa91SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*1b0aaa91SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*1b0aaa91SAndrew Rist * distributed with this work for additional information 6*1b0aaa91SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*1b0aaa91SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*1b0aaa91SAndrew Rist * "License"); you may not use this file except in compliance 9*1b0aaa91SAndrew Rist * with the License. You may obtain a copy of the License at 10*1b0aaa91SAndrew Rist * 11*1b0aaa91SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*1b0aaa91SAndrew Rist * 13*1b0aaa91SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*1b0aaa91SAndrew Rist * software distributed under the License is distributed on an 15*1b0aaa91SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*1b0aaa91SAndrew Rist * KIND, either express or implied. See the License for the 17*1b0aaa91SAndrew Rist * specific language governing permissions and limitations 18*1b0aaa91SAndrew Rist * under the License. 19*1b0aaa91SAndrew Rist * 20*1b0aaa91SAndrew Rist *************************************************************/ 21*1b0aaa91SAndrew Rist 22cdf0e10cSrcweir package ov; 23cdf0e10cSrcweir 24cdf0e10cSrcweir import java.awt.Color; 25cdf0e10cSrcweir import java.awt.GridBagConstraints; 26cdf0e10cSrcweir import java.awt.GridBagLayout; 27cdf0e10cSrcweir import java.awt.event.ActionListener; 28cdf0e10cSrcweir import java.awt.event.ActionEvent; 29cdf0e10cSrcweir 30cdf0e10cSrcweir import javax.swing.JButton; 31cdf0e10cSrcweir import javax.swing.JLabel; 32cdf0e10cSrcweir 33cdf0e10cSrcweir import com.sun.star.accessibility.AccessibleEventId; 34cdf0e10cSrcweir import com.sun.star.accessibility.AccessibleEventObject; 35cdf0e10cSrcweir import com.sun.star.accessibility.AccessibleStateType; 36cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleText; 37cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleContext; 38cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleStateSet; 39cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 40cdf0e10cSrcweir 41cdf0e10cSrcweir public class TextView 42cdf0e10cSrcweir extends ListeningObjectView 43cdf0e10cSrcweir { 44cdf0e10cSrcweir /** Create a TextView when the given object supports the 45cdf0e10cSrcweir XAccessibleText interface. 46cdf0e10cSrcweir */ Create( ObjectViewContainer aContainer, XAccessibleContext xContext)47cdf0e10cSrcweir static public ObjectView Create ( 48cdf0e10cSrcweir ObjectViewContainer aContainer, 49cdf0e10cSrcweir XAccessibleContext xContext) 50cdf0e10cSrcweir { 51cdf0e10cSrcweir XAccessibleText xText = (XAccessibleText)UnoRuntime.queryInterface( 52cdf0e10cSrcweir XAccessibleText.class, xContext); 53cdf0e10cSrcweir if (xText != null) 54cdf0e10cSrcweir return new TextView (aContainer); 55cdf0e10cSrcweir else 56cdf0e10cSrcweir return null; 57cdf0e10cSrcweir } 58cdf0e10cSrcweir 59cdf0e10cSrcweir TextView(ObjectViewContainer aContainer)60cdf0e10cSrcweir public TextView (ObjectViewContainer aContainer) 61cdf0e10cSrcweir { 62cdf0e10cSrcweir super (aContainer); 63cdf0e10cSrcweir 64cdf0e10cSrcweir setLayout (new GridBagLayout()); 65cdf0e10cSrcweir GridBagConstraints aConstraints = new GridBagConstraints (); 66cdf0e10cSrcweir 67cdf0e10cSrcweir JLabel aLabel = new JLabel ("Text:"); 68cdf0e10cSrcweir aConstraints.gridy = 0; 69cdf0e10cSrcweir aConstraints.weightx = 1; 70cdf0e10cSrcweir aConstraints.fill = GridBagConstraints.HORIZONTAL; 71cdf0e10cSrcweir add (aLabel, aConstraints); 72cdf0e10cSrcweir 73cdf0e10cSrcweir maTextLabel = new JLabel (""); 74cdf0e10cSrcweir aConstraints.gridx = 1; 75cdf0e10cSrcweir aConstraints.fill = GridBagConstraints.NONE; 76cdf0e10cSrcweir aConstraints.anchor = GridBagConstraints.WEST; 77cdf0e10cSrcweir add (maTextLabel, aConstraints); 78cdf0e10cSrcweir 79cdf0e10cSrcweir aLabel = new JLabel ("Caret position:"); 80cdf0e10cSrcweir aConstraints.gridx = 0; 81cdf0e10cSrcweir aConstraints.gridy = 1; 82cdf0e10cSrcweir aConstraints.weightx = 1; 83cdf0e10cSrcweir aConstraints.fill = GridBagConstraints.HORIZONTAL; 84cdf0e10cSrcweir add (aLabel, aConstraints); 85cdf0e10cSrcweir 86cdf0e10cSrcweir maCaretPositionLabel = new JLabel (""); 87cdf0e10cSrcweir aConstraints.gridx = 1; 88cdf0e10cSrcweir aConstraints.fill = GridBagConstraints.NONE; 89cdf0e10cSrcweir aConstraints.anchor = GridBagConstraints.WEST; 90cdf0e10cSrcweir add (maCaretPositionLabel, aConstraints); 91cdf0e10cSrcweir } 92cdf0e10cSrcweir 93cdf0e10cSrcweir 94cdf0e10cSrcweir /** Additionally to the context store a reference to the 95cdf0e10cSrcweir XAccessibleText interface. 96cdf0e10cSrcweir */ SetObject(XAccessibleContext xObject)97cdf0e10cSrcweir public void SetObject (XAccessibleContext xObject) 98cdf0e10cSrcweir { 99cdf0e10cSrcweir mxText = (XAccessibleText)UnoRuntime.queryInterface( 100cdf0e10cSrcweir XAccessibleText.class, xObject); 101cdf0e10cSrcweir super.SetObject (xObject); 102cdf0e10cSrcweir } 103cdf0e10cSrcweir Destroy()104cdf0e10cSrcweir synchronized public void Destroy () 105cdf0e10cSrcweir { 106cdf0e10cSrcweir super.Destroy(); 107cdf0e10cSrcweir } 108cdf0e10cSrcweir Update()109cdf0e10cSrcweir synchronized public void Update () 110cdf0e10cSrcweir { 111cdf0e10cSrcweir if (mxText == null) 112cdf0e10cSrcweir { 113cdf0e10cSrcweir maTextLabel.setText ("<null object>"); 114cdf0e10cSrcweir maCaretPositionLabel.setText ("<null object>"); 115cdf0e10cSrcweir } 116cdf0e10cSrcweir else 117cdf0e10cSrcweir { 118cdf0e10cSrcweir maTextLabel.setText (mxText.getText()); 119cdf0e10cSrcweir maCaretPositionLabel.setText (Integer.toString(mxText.getCaretPosition())); 120cdf0e10cSrcweir } 121cdf0e10cSrcweir } 122cdf0e10cSrcweir GetTitle()123cdf0e10cSrcweir public String GetTitle () 124cdf0e10cSrcweir { 125cdf0e10cSrcweir return ("Text"); 126cdf0e10cSrcweir } 127cdf0e10cSrcweir notifyEvent(AccessibleEventObject aEvent)128cdf0e10cSrcweir public void notifyEvent (AccessibleEventObject aEvent) 129cdf0e10cSrcweir { 130cdf0e10cSrcweir System.out.println (aEvent); 131cdf0e10cSrcweir switch (aEvent.EventId) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir case AccessibleEventId.TEXT_CHANGED : 134cdf0e10cSrcweir case AccessibleEventId.CARET_CHANGED : 135cdf0e10cSrcweir Update (); 136cdf0e10cSrcweir break; 137cdf0e10cSrcweir } 138cdf0e10cSrcweir } 139cdf0e10cSrcweir 140cdf0e10cSrcweir private JLabel 141cdf0e10cSrcweir maTextLabel, 142cdf0e10cSrcweir maCaretPositionLabel; 143cdf0e10cSrcweir private XAccessibleText mxText; 144cdf0e10cSrcweir } 145