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.Color; 27 import java.awt.Dimension; 28 import java.awt.GridBagLayout; 29 import java.awt.GridBagConstraints; 30 import java.lang.Integer; 31 import javax.swing.JLabel; 32 import javax.swing.JTextField; 33 34 import com.sun.star.accessibility.AccessibleEventId; 35 import com.sun.star.accessibility.AccessibleEventObject; 36 import com.sun.star.accessibility.XAccessible; 37 import com.sun.star.accessibility.XAccessibleContext; 38 import com.sun.star.lang.IndexOutOfBoundsException; 39 40 import org.openoffice.accessibility.misc.NameProvider; 41 42 43 /** Show informations related to the parent/child relationship. 44 */ 45 public class ParentView 46 extends ObjectView 47 { Create( ObjectViewContainer aContainer, XAccessibleContext xContext)48 static public ObjectView Create ( 49 ObjectViewContainer aContainer, 50 XAccessibleContext xContext) 51 { 52 if (xContext != null) 53 return new ParentView (aContainer); 54 else 55 return null; 56 } 57 ParentView(ObjectViewContainer aContainer)58 public ParentView (ObjectViewContainer aContainer) 59 { 60 super (aContainer); 61 62 ViewGridLayout aLayout = new ViewGridLayout (this); 63 maParentLabel = aLayout.AddLabeledEntry ("Has parent: "); 64 maIndexLabel = aLayout.AddLabeledEntry ("Index in parent: "); 65 maValidLabel = aLayout.AddLabeledEntry ("Parent/Child relationship valid: "); 66 maChildrenLabel = aLayout.AddLabeledEntry ("Child count: "); 67 } 68 Update()69 public void Update () 70 { 71 if (mxContext == null) 72 { 73 maParentLabel.setText ("<null object>"); 74 maIndexLabel.setText ("<null object>"); 75 maValidLabel.setText ("<null object>"); 76 maChildrenLabel.setText ("<null object>"); 77 } 78 else 79 { 80 XAccessible xParent = mxContext.getAccessibleParent(); 81 int nIndex = mxContext.getAccessibleIndexInParent(); 82 maIndexLabel.setText (Integer.toString(nIndex)); 83 if (xParent != null) 84 { 85 maParentLabel.setText ("yes"); 86 XAccessibleContext xParentContext = 87 xParent.getAccessibleContext(); 88 if (xParentContext != null) 89 { 90 try 91 { 92 XAccessible xChild = 93 xParentContext.getAccessibleChild(nIndex); 94 if (xChild != mxContext) 95 maValidLabel.setText ("yes"); 96 else 97 { 98 maValidLabel.setText ("no"); 99 maValidLabel.setBackground (GetContainer().GetErrorColor()); 100 } 101 } 102 catch (IndexOutOfBoundsException e) 103 { 104 maValidLabel.setText ("no: invalid index in parent"); 105 maValidLabel.setBackground (GetContainer().GetErrorColor()); 106 } 107 } 108 else 109 { 110 maValidLabel.setText ("no: parent has no context"); 111 maValidLabel.setBackground (GetContainer().GetErrorColor()); 112 } 113 } 114 else 115 maParentLabel.setText ("no"); 116 maChildrenLabel.setText (Integer.toString(mxContext.getAccessibleChildCount())); 117 } 118 } 119 GetTitle()120 public String GetTitle () 121 { 122 return ("Parent"); 123 } 124 125 126 /** Listen for changes regarding displayed values. 127 */ notifyEvent(AccessibleEventObject aEvent)128 public void notifyEvent (AccessibleEventObject aEvent) 129 { 130 switch (aEvent.EventId) 131 { 132 default: 133 Update (); 134 } 135 } 136 137 138 private JLabel 139 maParentLabel, 140 maIndexLabel, 141 maValidLabel, 142 maChildrenLabel; 143 } 144