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 com.sun.star.wizards.ui; 24 25 import java.util.Vector; 26 27 import com.sun.star.awt.*; 28 import com.sun.star.lang.EventObject; 29 import com.sun.star.uno.AnyConverter; 30 import com.sun.star.uno.UnoRuntime; 31 import com.sun.star.wizards.common.Helper; 32 import com.sun.star.wizards.common.PropertyNames; 33 34 /** 35 * @author rpiterman 36 * 37 * To change the template for this generated type comment go to 38 * Window>Preferences>Java>Code Generation>Code and Comments 39 */ 40 public class PeerConfig implements XWindowListener 41 { 42 43 private Vector m_aPeerTasks = new Vector(); 44 Vector aControlTasks = new Vector(); 45 Vector aImageUrlTasks = new Vector(); 46 UnoDialog oUnoDialog = null; 47 PeerConfig(UnoDialog _oUnoDialog)48 public PeerConfig(UnoDialog _oUnoDialog) 49 { 50 oUnoDialog = _oUnoDialog; 51 oUnoDialog.xWindow.addWindowListener(this); 52 } 53 54 class PeerTask 55 { 56 57 XControl xControl; 58 String[] propnames; 59 Object[] propvalues; 60 PeerTask(XControl _xControl, String[] propNames_, Object[] propValues_)61 public PeerTask(XControl _xControl, String[] propNames_, Object[] propValues_) 62 { 63 propnames = propNames_; 64 propvalues = propValues_; 65 xControl = _xControl; 66 } 67 } 68 69 class ControlTask 70 { 71 72 Object oModel; 73 String propname; 74 Object propvalue; 75 ControlTask(Object _oModel, String _propName, Object _propValue)76 public ControlTask(Object _oModel, String _propName, Object _propValue) 77 { 78 propname = _propName; 79 propvalue = _propValue; 80 oModel = _oModel; 81 } 82 } 83 84 class ImageUrlTask 85 { 86 87 Object oModel; 88 Object oResource; 89 Object oHCResource; 90 ImageUrlTask(Object _oModel, Object _oResource, Object _oHCResource)91 public ImageUrlTask(Object _oModel, Object _oResource, Object _oHCResource) 92 { 93 oResource = _oResource; 94 oHCResource = _oHCResource; 95 oModel = _oModel; 96 } 97 } 98 windowResized(WindowEvent arg0)99 public void windowResized(WindowEvent arg0) 100 { 101 } 102 windowMoved(WindowEvent arg0)103 public void windowMoved(WindowEvent arg0) 104 { 105 } 106 windowShown(EventObject arg0)107 public void windowShown(EventObject arg0) 108 { 109 try 110 { 111 for (int i = 0; i < this.m_aPeerTasks.size(); i++) 112 { 113 PeerTask aPeerTask = (PeerTask) m_aPeerTasks.elementAt(i); 114 XVclWindowPeer xVclWindowPeer = UnoRuntime.queryInterface(XVclWindowPeer.class, aPeerTask.xControl.getPeer()); 115 for (int n = 0; n < aPeerTask.propnames.length; n++) 116 { 117 xVclWindowPeer.setProperty(aPeerTask.propnames[n], aPeerTask.propvalues[n]); 118 } 119 } 120 for (int i = 0; i < this.aControlTasks.size(); i++) 121 { 122 ControlTask aControlTask = (ControlTask) aControlTasks.elementAt(i); 123 Helper.setUnoPropertyValue(aControlTask.oModel, aControlTask.propname, aControlTask.propvalue); 124 } 125 for (int i = 0; i < this.aImageUrlTasks.size(); i++) 126 { 127 ImageUrlTask aImageUrlTask = (ImageUrlTask) aImageUrlTasks.elementAt(i); 128 String sImageUrl = PropertyNames.EMPTY_STRING; 129 if (AnyConverter.isInt(aImageUrlTask.oResource)) 130 { 131 sImageUrl = oUnoDialog.getWizardImageUrl(((Integer) aImageUrlTask.oResource).intValue(), ((Integer) aImageUrlTask.oHCResource).intValue()); 132 } 133 else if (AnyConverter.isString(aImageUrlTask.oResource)) 134 { 135 sImageUrl = oUnoDialog.getImageUrl(((String) aImageUrlTask.oResource), ((String) aImageUrlTask.oHCResource)); 136 } 137 if (!sImageUrl.equals(PropertyNames.EMPTY_STRING)) 138 { 139 Helper.setUnoPropertyValue(aImageUrlTask.oModel, PropertyNames.PROPERTY_IMAGEURL, sImageUrl); 140 } 141 } 142 143 } 144 catch (RuntimeException re) 145 { 146 re.printStackTrace(System.out); 147 throw re; 148 } 149 } 150 windowHidden(EventObject arg0)151 public void windowHidden(EventObject arg0) 152 { 153 } 154 disposing(EventObject arg0)155 public void disposing(EventObject arg0) 156 { 157 } 158 159 /** 160 * 161 * @param oAPIControl an API control that the interface XControl can be derived from 162 * @param _saccessname 163 */ setAccessibleName(Object oAPIControl, String _saccessname)164 public void setAccessibleName(Object oAPIControl, String _saccessname) 165 { 166 XControl xControl = UnoRuntime.queryInterface(XControl.class, oAPIControl); 167 setPeerProperties(xControl, new String[] 168 { 169 "AccessibleName" 170 }, new String[] 171 { 172 _saccessname 173 }); 174 } 175 setAccessibleName(XControl _xControl, String _saccessname)176 public void setAccessibleName(XControl _xControl, String _saccessname) 177 { 178 setPeerProperties(_xControl, new String[] 179 { 180 "AccessibleName" 181 }, new String[] 182 { 183 _saccessname 184 }); 185 } 186 187 /** 188 * 189 * @param oAPIControl an API control that the interface XControl can be derived from 190 * @param _propnames 191 * @param _propvalues 192 */ setPeerProperties(Object oAPIControl, String[] _propnames, Object[] _propvalues)193 public void setPeerProperties(Object oAPIControl, String[] _propnames, Object[] _propvalues) 194 { 195 XControl xControl = UnoRuntime.queryInterface(XControl.class, oAPIControl); 196 setPeerProperties(xControl, _propnames, _propvalues); 197 } 198 setPeerProperties(XControl _xControl, String[] propnames, Object[] propvalues)199 public void setPeerProperties(XControl _xControl, String[] propnames, Object[] propvalues) 200 { 201 PeerTask oPeerTask = new PeerTask(_xControl, propnames, propvalues); 202 this.m_aPeerTasks.add(oPeerTask); 203 } 204 205 /** 206 * assigns an arbitrary property to a control as soon as the peer is created 207 * Note: The property 'ImageUrl' should better be assigned with 'setImageurl(...)', to consider the High Contrast Mode 208 * @param _ocontrolmodel 209 * @param _spropname 210 * @param _propvalue 211 */ setControlProperty(Object _ocontrolmodel, String _spropname, Object _propvalue)212 public void setControlProperty(Object _ocontrolmodel, String _spropname, Object _propvalue) 213 { 214 ControlTask oControlTask = new ControlTask(_ocontrolmodel, _spropname, _propvalue); 215 this.aControlTasks.add(oControlTask); 216 } 217 218 /** 219 * Assigns an image to the property 'ImageUrl' of a dialog control. The image id must be assigned in a resource file 220 * within the wizards project 221 * wizards project 222 * @param _ocontrolmodel 223 * @param _nResId 224 * @param _nhcResId 225 */ setImageUrl(Object _ocontrolmodel, int _nResId, int _nhcResId)226 public void setImageUrl(Object _ocontrolmodel, int _nResId, int _nhcResId) 227 { 228 ImageUrlTask oImageUrlTask = new ImageUrlTask(_ocontrolmodel, new Integer(_nResId), new Integer(_nhcResId)); 229 this.aImageUrlTasks.add(oImageUrlTask); 230 } 231 232 /** 233 * Assigns an image to the property 'ImageUrl' of a dialog control. The image ids that the Resource urls point to 234 * may be assigned in a Resource file outside the wizards project 235 * @param _ocontrolmodel 236 * @param _sResourceUrl 237 * @param _sHCResourceUrl 238 */ setImageUrl(Object _ocontrolmodel, String _sResourceUrl, String _sHCResourceUrl)239 public void setImageUrl(Object _ocontrolmodel, String _sResourceUrl, String _sHCResourceUrl) 240 { 241 ImageUrlTask oImageUrlTask = new ImageUrlTask(_ocontrolmodel, _sResourceUrl, _sHCResourceUrl); 242 this.aImageUrlTasks.add(oImageUrlTask); 243 } 244 245 /** 246 * Assigns an image to the property 'ImageUrl' of a dialog control. The image id must be assigned in a resource file 247 * within the wizards project 248 * wizards project 249 * @param _ocontrolmodel 250 * @param _oResource 251 * @param _oHCResource 252 */ setImageUrl(Object _ocontrolmodel, Object _oResource, Object _oHCResource)253 public void setImageUrl(Object _ocontrolmodel, Object _oResource, Object _oHCResource) 254 { 255 ImageUrlTask oImageUrlTask = new ImageUrlTask(_ocontrolmodel, _oResource, _oHCResource); 256 this.aImageUrlTasks.add(oImageUrlTask); 257 } 258 } 259