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 29 import java.awt.event.ActionListener; 30 import java.awt.event.ActionEvent; 31 32 import javax.swing.JLabel; 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.XAccessibleComponent; 38 import com.sun.star.accessibility.XAccessibleContext; 39 import com.sun.star.uno.UnoRuntime; 40 41 import org.openoffice.accessibility.misc.NameProvider; 42 43 /** The <type>ContextView</type> class displays information accessible over 44 the <type>XAccessibleContext</type> interface. This includes name, 45 description, and role. 46 */ 47 public class ComponentView 48 extends ObjectView 49 { Create( ObjectViewContainer aContainer, XAccessibleContext xContext)50 static public ObjectView Create ( 51 ObjectViewContainer aContainer, 52 XAccessibleContext xContext) 53 { 54 if (UnoRuntime.queryInterface( 55 XAccessibleComponent.class, xContext) != null) 56 return new ComponentView (aContainer); 57 else 58 return null; 59 } 60 ComponentView(ObjectViewContainer aContainer)61 public ComponentView (ObjectViewContainer aContainer) 62 { 63 super (aContainer); 64 65 ViewGridLayout aLayout = new ViewGridLayout (this); 66 67 maRelativeLocationLabel = aLayout.AddLabeledEntry ("Relative Location: "); 68 maAbsoluteLocationLabel = aLayout.AddLabeledEntry ("Location on Screen: "); 69 maSizeLabel = aLayout.AddLabeledEntry ("Size"); 70 maBoundingBoxLabel = aLayout.AddLabeledEntry ("Bounding Box: "); 71 maConsistencyLabel = aLayout.AddLabeledEntry ("Consistent: "); 72 maForegroundColorLabel = aLayout.AddLabeledEntry ("Foreground Color: "); 73 maBackgroundColorLabel = aLayout.AddLabeledEntry ("Background Color: "); 74 } 75 76 SetObject(XAccessibleContext xContext)77 public void SetObject (XAccessibleContext xContext) 78 { 79 mxComponent = (XAccessibleComponent)UnoRuntime.queryInterface( 80 XAccessibleComponent.class, xContext); 81 super.SetObject (xContext); 82 } 83 Update()84 public void Update () 85 { 86 if (mxContext == null) 87 { 88 maRelativeLocationLabel.setText ("<null object>"); 89 maAbsoluteLocationLabel.setText ("<null object>"); 90 maSizeLabel.setText ("<null object>"); 91 maBoundingBoxLabel.setText ("<null object>"); 92 maConsistencyLabel.setText ("<null object>"); 93 maForegroundColorLabel.setText ("<null object>"); 94 maBackgroundColorLabel.setText ("<null object>"); 95 } 96 else 97 { 98 com.sun.star.awt.Point aLocation = mxComponent.getLocation(); 99 maRelativeLocationLabel.setText ( 100 aLocation.X + ", " + aLocation.Y); 101 com.sun.star.awt.Point aLocationOnScreen = 102 mxComponent.getLocationOnScreen(); 103 maAbsoluteLocationLabel.setText ( 104 aLocationOnScreen.X + ", " + aLocationOnScreen.Y); 105 com.sun.star.awt.Size aSize = mxComponent.getSize(); 106 maSizeLabel.setText ( 107 aSize.Width + ", " + aSize.Height); 108 com.sun.star.awt.Rectangle aBBox = mxComponent.getBounds(); 109 maBoundingBoxLabel.setText ( 110 aBBox.X + ", " + aBBox.Y + "," 111 + aBBox.Width + ", " + aBBox.Height); 112 int nColor = mxComponent.getForeground(); 113 maForegroundColorLabel.setText ( 114 "R"+ (nColor>>16&0xff) 115 + "G" + (nColor>>8&0xff) 116 + "B" + (nColor>>0&0xff) 117 + "A" + (nColor>>24&0xff)); 118 nColor = mxComponent.getBackground(); 119 maBackgroundColorLabel.setText ( 120 "R"+ (nColor>>16&0xff) 121 + "G" + (nColor>>8&0xff) 122 + "B" + (nColor>>0&0xff) 123 + "A" + (nColor>>24&0xff)); 124 125 // Check consistency of coordinates. 126 String sConsistency = new String (); 127 if (aBBox.X!=aLocation.X || aBBox.Y!=aLocation.Y) 128 sConsistency += (sConsistency.length()!=0?", ":"") + 129 "Bounding box conflicts with relative location"; 130 if (aBBox.Width!=aSize.Width || aBBox.Height!=aSize.Height) 131 sConsistency += (sConsistency.length()!=0?", ":"") + 132 "Bounding box conflicts with size"; 133 XAccessible xParent = mxContext.getAccessibleParent(); 134 XAccessibleComponent xParentComponent = 135 (XAccessibleComponent)UnoRuntime.queryInterface( 136 XAccessibleComponent.class, xParent); 137 if (xParentComponent == null) 138 { 139 if (aLocation.X != aLocationOnScreen.X 140 || aLocation.Y != aLocationOnScreen.Y) 141 sConsistency += (sConsistency.length()!=0?", ":"") + 142 "location on screen does not equal " 143 + "relative location without parent"; 144 } 145 else 146 { 147 com.sun.star.awt.Point aParentLocationOnScreen = 148 xParentComponent.getLocationOnScreen(); 149 if (aLocation.X+aParentLocationOnScreen.X 150 != aLocationOnScreen.X 151 || aLocation.Y+aParentLocationOnScreen.Y 152 != aLocationOnScreen.Y) 153 sConsistency += (sConsistency.length()!=0?", ":"") + 154 "location on screen does not match " 155 + "relative location"; 156 } 157 if (sConsistency.length() == 0) 158 sConsistency += "yes"; 159 else 160 maConsistencyLabel.setBackground (GetContainer().GetErrorColor()); 161 maConsistencyLabel.setText (sConsistency); 162 } 163 } 164 GetTitle()165 public String GetTitle () 166 { 167 return ("Component"); 168 } 169 170 /** Listen for changes regarding displayed values. 171 */ notifyEvent(AccessibleEventObject aEvent)172 public void notifyEvent (AccessibleEventObject aEvent) 173 { 174 switch (aEvent.EventId) 175 { 176 case AccessibleEventId.BOUNDRECT_CHANGED : 177 case AccessibleEventId.VISIBLE_DATA_CHANGED : 178 Update (); 179 } 180 } 181 182 private XAccessibleComponent mxComponent; 183 private JLabel 184 maRelativeLocationLabel, 185 maAbsoluteLocationLabel, 186 maSizeLabel, 187 maBoundingBoxLabel, 188 maConsistencyLabel, 189 maForegroundColorLabel, 190 maBackgroundColorLabel; 191 } 192