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