1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package org.openoffice.accessibility.awb.view; 25 26 import java.awt.event.ActionListener; 27 import java.awt.event.ActionEvent; 28 import javax.swing.JButton; 29 30 import com.sun.star.accessibility.XAccessibleContext; 31 import com.sun.star.accessibility.XAccessibleEditableText; 32 import com.sun.star.uno.UnoRuntime; 33 34 import org.openoffice.accessibility.awb.view.text.TextDialogFactory; 35 36 37 public class EditableTextView 38 extends ObjectView 39 implements ActionListener 40 { 41 /** Create a EditableTextView when the given object supports the 42 XAccessibleEditableText interface. 43 */ Create( ObjectViewContainer aContainer, XAccessibleContext xContext)44 static public ObjectView Create ( 45 ObjectViewContainer aContainer, 46 XAccessibleContext xContext) 47 { 48 XAccessibleEditableText xEditableText = 49 (XAccessibleEditableText)UnoRuntime.queryInterface( 50 XAccessibleEditableText.class, xContext); 51 if (xEditableText != null) 52 return new EditableTextView (aContainer); 53 else 54 return null; 55 } 56 EditableTextView(ObjectViewContainer aContainer)57 public EditableTextView (ObjectViewContainer aContainer) 58 { 59 super (aContainer); 60 61 JButton aButton = new JButton ("cut..."); 62 aButton.setFont (ViewGridLayout.GetFont()); 63 aButton.addActionListener (this); 64 add (aButton); 65 aButton = new JButton ("paste..."); 66 aButton.setFont (ViewGridLayout.GetFont()); 67 aButton.addActionListener (this); 68 add (aButton); 69 aButton = new JButton ("edit..."); 70 aButton.setFont (ViewGridLayout.GetFont()); 71 aButton.addActionListener (this); 72 add (aButton); 73 aButton = new JButton ("format..."); 74 aButton.setFont (ViewGridLayout.GetFont()); 75 aButton.addActionListener (this); 76 add (aButton); 77 } 78 79 80 /** Additionally to the context store a reference to the 81 XAccessibleEditableText interface. 82 */ SetObject(XAccessibleContext xObject)83 public void SetObject (XAccessibleContext xObject) 84 { 85 mxEditableText = (XAccessibleEditableText)UnoRuntime.queryInterface( 86 XAccessibleEditableText.class, xObject); 87 super.SetObject (xObject); 88 } 89 GetTitle()90 public String GetTitle () 91 { 92 return ("Editable Text"); 93 } 94 Destroy()95 synchronized public void Destroy () 96 { 97 mxEditableText = null; 98 super.Destroy(); 99 } 100 actionPerformed(ActionEvent aEvent)101 public void actionPerformed (ActionEvent aEvent) 102 { 103 String sCommand = aEvent.getActionCommand(); 104 if (sCommand.equals ("cut...")) 105 TextDialogFactory.CreateCutDialog (mxContext); 106 else if (sCommand.equals ("past...")) 107 TextDialogFactory.CreatePasteDialog (mxContext); 108 else if (sCommand.equals ("edit...")) 109 TextDialogFactory.CreateEditDialog (mxContext); 110 else if (sCommand.equals ("format...")) 111 TextDialogFactory.CreateFormatDialog (mxContext); 112 } 113 114 private XAccessibleEditableText mxEditableText; 115 } 116