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 package org.openoffice.accessibility; 24 25 import org.openoffice.java.accessibility.*; 26 27 28 /** 29 * 30 */ 31 public class PopupWindow extends java.awt.Window { 32 javax.accessibility.AccessibleContext accessibleContext = null; 33 ContainerProxy layeredPane = new ContainerProxy(javax.accessibility.AccessibleRole.LAYERED_PANE); 34 ContainerProxy rootPane = new ContainerProxy(javax.accessibility.AccessibleRole.ROOT_PANE); 35 ContainerProxy popupLayer = new ContainerProxy(javax.accessibility.AccessibleRole.PANEL); 36 boolean opened = false; 37 boolean visible = false; 38 39 /** Creates a new instance of PopupWindow */ PopupWindow(java.awt.Window owner)40 public PopupWindow(java.awt.Window owner) { 41 super(owner); 42 super.add(rootPane); 43 rootPane.add(layeredPane); 44 45 javax.accessibility.AccessibleContext ac = rootPane.getAccessibleContext(); 46 47 if (ac != null) { 48 ac.setAccessibleParent(this); 49 } 50 } 51 create( com.sun.star.accessibility.XAccessible xAccessible)52 static PopupWindow create( 53 com.sun.star.accessibility.XAccessible xAccessible) { 54 java.awt.Window parent = java.awt.KeyboardFocusManager.getCurrentKeyboardFocusManager() 55 .getActiveWindow(); 56 57 if (parent != null) { 58 PopupWindow w = new PopupWindow(parent); 59 w.setVisible(true); 60 AccessibleObjectFactory.invokeAndWait(); 61 AccessibleObjectFactory.addChild(w, xAccessible); 62 63 return w; 64 } 65 66 return null; 67 } 68 isShowing()69 public boolean isShowing() { 70 if (isVisible()) { 71 java.awt.Container parent = getParent(); 72 73 return (parent == null) || parent.isShowing(); 74 } 75 76 return false; 77 } 78 addNotify()79 public void addNotify() { 80 } 81 removeNotify()82 public void removeNotify() { 83 } 84 isVisible()85 public boolean isVisible() { 86 return visible; 87 } 88 setVisible(boolean b)89 public void setVisible(boolean b) { 90 if (visible != b) { 91 visible = b; 92 93 if (b) { 94 // If it is the first show, fire WINDOW_OPENED event 95 if (!opened) { 96 AccessibleObjectFactory.postWindowOpened(this); 97 opened = true; 98 } 99 } 100 } 101 } 102 add(java.awt.Component c)103 public java.awt.Component add(java.awt.Component c) { 104 popupLayer.add(c); 105 layeredPane.add(popupLayer); 106 107 if (c instanceof javax.accessibility.Accessible) { 108 javax.accessibility.AccessibleContext ac = layeredPane.getAccessibleContext(); 109 110 if (ac != null) { 111 ac.firePropertyChange(ac.ACCESSIBLE_CHILD_PROPERTY, null, 112 popupLayer.getAccessibleContext()); 113 } 114 } 115 116 return c; 117 } 118 remove(java.awt.Component c)119 public void remove(java.awt.Component c) { 120 layeredPane.remove(popupLayer); 121 122 if (c instanceof javax.accessibility.Accessible) { 123 javax.accessibility.AccessibleContext ac = layeredPane.getAccessibleContext(); 124 125 if (ac != null) { 126 ac.firePropertyChange(ac.ACCESSIBLE_CHILD_PROPERTY, 127 popupLayer.getAccessibleContext(), null); 128 } 129 } 130 131 popupLayer.remove(c); 132 } 133 dispose()134 public void dispose() { 135 setVisible(false); 136 AccessibleObjectFactory.postWindowClosed(this); 137 } 138 getAccessibleContext()139 public javax.accessibility.AccessibleContext getAccessibleContext() { 140 if (accessibleContext == null) { 141 accessibleContext = new AccessiblePopupWindow(); 142 } 143 144 return accessibleContext; 145 } 146 147 protected class AccessiblePopupWindow 148 extends java.awt.Window.AccessibleAWTWindow { AccessiblePopupWindow()149 AccessiblePopupWindow() { 150 } 151 } 152 153 protected class ContainerProxy extends java.awt.Container 154 implements javax.accessibility.Accessible { 155 javax.accessibility.AccessibleContext accessibleContext = null; 156 javax.accessibility.AccessibleRole role; 157 ContainerProxy(javax.accessibility.AccessibleRole role)158 protected ContainerProxy(javax.accessibility.AccessibleRole role) { 159 this.role = role; 160 } 161 add(java.awt.Component c)162 public java.awt.Component add(java.awt.Component c) { 163 if (c instanceof javax.accessibility.Accessible) { 164 javax.accessibility.Accessible a = (javax.accessibility.Accessible) c; 165 javax.accessibility.AccessibleContext ac = a.getAccessibleContext(); 166 167 if (ac != null) { 168 ac.setAccessibleParent(this); 169 } 170 } 171 172 return super.add(c); 173 } 174 remove(java.awt.Component c)175 public void remove(java.awt.Component c) { 176 if (c instanceof javax.accessibility.Accessible) { 177 javax.accessibility.Accessible a = (javax.accessibility.Accessible) c; 178 javax.accessibility.AccessibleContext ac = a.getAccessibleContext(); 179 180 if (ac != null) { 181 ac.setAccessibleParent(null); 182 } 183 } 184 185 super.remove(c); 186 } 187 getAccessibleContext()188 public javax.accessibility.AccessibleContext getAccessibleContext() { 189 if (accessibleContext == null) { 190 accessibleContext = new AccessibleContainerProxy(); 191 } 192 193 return accessibleContext; 194 } 195 196 private class AccessibleContainerProxy 197 extends java.awt.Container.AccessibleAWTContainer { AccessibleContainerProxy()198 AccessibleContainerProxy() { 199 } 200 getAccessibleRole()201 public javax.accessibility.AccessibleRole getAccessibleRole() { 202 return ContainerProxy.this.role; 203 } 204 } 205 } 206 } 207