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 com.sun.star.beans.*; 26 import com.sun.star.awt.*; 27 import com.sun.star.lang.XMultiServiceFactory; 28 import com.sun.star.wizards.common.*; 29 import com.sun.star.wizards.common.HelpIds; 30 31 import java.util.*; 32 33 public abstract class ControlScroller 34 { 35 36 protected WizardDialog CurUnoDialog; 37 protected XMultiServiceFactory xMSF; 38 private Object oImgControl; 39 protected int ncurfieldcount; 40 protected int nblockincrement; 41 private int nlineincrement; 42 protected int nscrollvalue = 0; 43 protected int ntotfieldcount; 44 XScrollBar xScrollBar; 45 protected Vector scrollfields; 46 protected Integer ICompPosX; 47 protected int iCompPosX; 48 protected Integer ICompPosY; 49 protected int iCompPosY; 50 protected Integer ICompWidth; 51 protected int iCompWidth; 52 protected Integer ICompHeight; 53 protected int iCompHeight; 54 protected int iStartPosY; 55 protected short curtabindex; 56 int iStep; 57 protected Integer IStep; 58 protected int linedistance; 59 int iScrollBarWidth = 10; 60 int SORELFIRSTPOSY = 3; 61 protected int curHelpIndex; 62 String sIncSuffix; 63 protected Vector ControlGroupVector = new Vector(); 64 protected PeerConfig oTitlePeerConfig; 65 66 class AdjustmentListenerImpl implements com.sun.star.awt.XAdjustmentListener 67 { 68 disposing(com.sun.star.lang.EventObject eventObject)69 public void disposing(com.sun.star.lang.EventObject eventObject) 70 { 71 } 72 adjustmentValueChanged(AdjustmentEvent AdjustEvent)73 public void adjustmentValueChanged(AdjustmentEvent AdjustEvent) 74 { 75 scrollControls(); 76 } 77 } 78 79 /** 80 * 81 * @param _CurUnoDialog 82 * @param iStep 83 * @param iCompPosX 84 * @param iCompPosY 85 * @param iCompWidth 86 * @param _nblockincrement 87 * @param _firsthelpindex 88 * @author bc93774 89 */ 90 // TODO add parameters for tabindices and helpindex ControlScroller(WizardDialog _CurUnoDialog, XMultiServiceFactory _xMSF, int _iStep, int _iCompPosX, int _iCompPosY, int _iCompWidth, int _nblockincrement, int _nlinedistance, int _firsthelpindex)91 protected ControlScroller(WizardDialog _CurUnoDialog, XMultiServiceFactory _xMSF, int _iStep, int _iCompPosX, int _iCompPosY, int _iCompWidth, int _nblockincrement, int _nlinedistance, int _firsthelpindex) 92 { 93 this.xMSF = _xMSF; 94 this.nblockincrement = _nblockincrement; 95 this.CurUnoDialog = _CurUnoDialog; 96 this.iStep = _iStep; 97 this.curHelpIndex = _firsthelpindex; 98 curtabindex = UnoDialog.setInitialTabindex(iStep); 99 this.linedistance = _nlinedistance; 100 IStep = new Integer(iStep); 101 this.iCompPosX = _iCompPosX; 102 this.iCompPosY = _iCompPosY; 103 this.ICompPosX = new Integer(iCompPosX); 104 this.ICompPosY = new Integer(iCompPosY); 105 this.iCompWidth = _iCompWidth; 106 this.ICompWidth = new Integer(iCompWidth); 107 this.iCompHeight = 2 * SORELFIRSTPOSY + nblockincrement * linedistance; 108 iStartPosY = iCompPosY + SORELFIRSTPOSY; 109 int ScrollHeight = iCompHeight - 2; 110 nlineincrement = 1; 111 sIncSuffix = com.sun.star.wizards.common.Desktop.getIncrementSuffix(CurUnoDialog.getDlgNameAccess(), "imgBackground"); 112 oImgControl = CurUnoDialog.insertControlModel("com.sun.star.awt.UnoControlImageControlModel", "imgBackground" + sIncSuffix, 113 new String[] 114 { 115 PropertyNames.PROPERTY_BORDER, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_WIDTH 116 }, 117 new Object[] 118 { 119 new Short("1"), new Integer(iCompHeight), ICompPosX, new Integer(iCompPosY), IStep, ICompWidth 120 }); 121 oImgControl = CurUnoDialog.xDlgContainer.getControl("imgBackground" + sIncSuffix); 122 setComponentMouseTransparent(); 123 xScrollBar = CurUnoDialog.insertScrollBar("TitleScrollBar" + sIncSuffix, 0, 124 new AdjustmentListenerImpl(), 125 new String[] 126 { 127 PropertyNames.PROPERTY_BORDER, PropertyNames.PROPERTY_ENABLED, PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.ORIENTATION, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_WIDTH 128 }, 129 new Object[] 130 { 131 new Short((short) 0), Boolean.TRUE, new Integer(ScrollHeight), HelpIds.getHelpIdString(curHelpIndex), new Integer(ScrollBarOrientation.VERTICAL), new Integer(iCompPosX + iCompWidth - iScrollBarWidth - 1), new Integer(iCompPosY + 1), IStep, new Integer(iScrollBarWidth) 132 }); 133 scrollfields = new Vector(); 134 int ypos = iStartPosY + SORELFIRSTPOSY; 135 for (int i = 0; i < nblockincrement; i++) 136 { 137 insertControlGroup(i, ypos); 138 ypos += linedistance; 139 } 140 } 141 setComponentMouseTransparent()142 public void setComponentMouseTransparent() 143 { 144 CurUnoDialog.getPeerConfiguration().setPeerProperties(oImgControl, new String[] 145 { 146 "MouseTransparent" 147 }, new Boolean[] 148 { 149 Boolean.TRUE 150 }); 151 } 152 setScrollBarOrientationHorizontal()153 protected void setScrollBarOrientationHorizontal() 154 { 155 Helper.setUnoPropertyValue(xScrollBar, PropertyNames.ORIENTATION, new Integer(ScrollBarOrientation.HORIZONTAL)); 156 } 157 158 /** 159 * @author bc93774 160 * @param _ntotfieldcount: The number of fields that are to be administered by the ControlScroller 161 */ initialize(int _ntotfieldcount)162 protected void initialize(int _ntotfieldcount) 163 { 164 try 165 { 166 boolean bisVisible; 167 ntotfieldcount = _ntotfieldcount; 168 setCurFieldCount(); 169 nscrollvalue = 0; 170 Helper.setUnoPropertyValue(UnoDialog.getModel(xScrollBar), "ScrollValue", new Integer(nscrollvalue)); 171 if (ntotfieldcount > nblockincrement) 172 { 173 Helper.setUnoPropertyValues(UnoDialog.getModel(xScrollBar), new String[] 174 { 175 PropertyNames.PROPERTY_ENABLED, "BlockIncrement", "LineIncrement", "ScrollValue", "ScrollValueMax" 176 }, new Object[] 177 { 178 Boolean.TRUE, new Integer(nblockincrement), new Integer(nlineincrement), new Integer(nscrollvalue), new Integer(ntotfieldcount - nblockincrement) 179 }); 180 } 181 else 182 { 183 Helper.setUnoPropertyValues(UnoDialog.getModel(xScrollBar), new String[] 184 { 185 PropertyNames.PROPERTY_ENABLED, "ScrollValue" 186 }, new Object[] 187 { 188 Boolean.FALSE, new Integer(nscrollvalue) 189 }); 190 } 191 fillupControls(true); 192 } 193 catch (java.lang.Exception ex) 194 { 195 ex.printStackTrace(); 196 } 197 } 198 fillupControls(boolean binitialize)199 protected void fillupControls(boolean binitialize) 200 { 201 int newindex; 202 PropertyValue[] oldproperties; 203 PropertyValue[] newproperties; 204 for (int a = 0; a < this.nblockincrement; a++) 205 { 206 if (a < ncurfieldcount) 207 { 208 fillupControls(a); 209 } 210 if (binitialize) 211 { 212 setControlGroupVisible(a, (a < this.ncurfieldcount)); 213 } 214 } 215 if (binitialize) 216 { 217 CurUnoDialog.repaintDialogStep(); 218 } 219 } 220 fillupControls(int guiRow)221 protected void fillupControls(int guiRow) 222 { 223 PropertyValue[] nameProps = (PropertyValue[]) scrollfields.get(guiRow); 224 PropertyValue[] valueProps = (PropertyValue[]) scrollfields.get(guiRow + nscrollvalue); 225 for (int n = 0; n < nameProps.length; n++) 226 { 227 if (CurUnoDialog.getDlgNameAccess().hasByName(nameProps[n].Name)) 228 { 229 setControlData(nameProps[n].Name, valueProps[n].Value); 230 } 231 else 232 { 233 throw new IllegalArgumentException("No such control !"); 234 } 235 } 236 } 237 setScrollValue(int _nscrollvalue)238 protected void setScrollValue(int _nscrollvalue) 239 { 240 if (_nscrollvalue >= 0) 241 { 242 Helper.setUnoPropertyValue(UnoDialog.getModel(xScrollBar), "ScrollValue", new Integer(_nscrollvalue)); 243 scrollControls(); 244 } 245 } 246 setScrollValue(int _nscrollvalue, int _ntotfieldcount)247 protected void setScrollValue(int _nscrollvalue, int _ntotfieldcount) 248 { 249 setTotalFieldCount(_ntotfieldcount); 250 setScrollValue(_nscrollvalue); 251 } 252 getTotalFieldCount()253 protected int getTotalFieldCount() 254 { 255 return ntotfieldcount; 256 } 257 getCurFieldCount()258 protected int getCurFieldCount() 259 { 260 return ncurfieldcount; 261 } 262 setCurFieldCount()263 private void setCurFieldCount() 264 { 265 if (ntotfieldcount > nblockincrement) 266 { 267 ncurfieldcount = nblockincrement; 268 } 269 else 270 { 271 ncurfieldcount = ntotfieldcount; 272 } 273 } 274 setTotalFieldCount(int _ntotfieldcount)275 protected void setTotalFieldCount(int _ntotfieldcount) 276 { 277 this.ntotfieldcount = _ntotfieldcount; 278 setCurFieldCount(); 279 if (ntotfieldcount > nblockincrement) 280 { 281 Helper.setUnoPropertyValues(UnoDialog.getModel(xScrollBar), new String[] 282 { 283 PropertyNames.PROPERTY_ENABLED, "ScrollValueMax" 284 }, new Object[] 285 { 286 Boolean.TRUE, new Integer(ntotfieldcount - nblockincrement) 287 }); 288 } 289 else 290 { 291 Helper.setUnoPropertyValue(UnoDialog.getModel(xScrollBar), PropertyNames.PROPERTY_ENABLED, Boolean.FALSE); 292 } 293 } 294 toggleComponent(boolean _bdoenable)295 protected void toggleComponent(boolean _bdoenable) 296 { 297 boolean bdoenable = _bdoenable && (ntotfieldcount > nblockincrement); 298 CurUnoDialog.setControlProperty("TitleScrollBar" + sIncSuffix, PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(bdoenable)); 299 } 300 toggleControls(boolean _bdoenable)301 protected void toggleControls(boolean _bdoenable) 302 { 303 for (int n = 0; n < scrollfields.size(); n++) 304 { 305 PropertyValue[] curproperties = (PropertyValue[]) scrollfields.elementAt(n); 306 for (int m = 0; m < curproperties.length; m++) 307 { 308 PropertyValue curproperty = curproperties[m]; 309 CurUnoDialog.setControlProperty(curproperty.Name, PropertyNames.PROPERTY_ENABLED, Boolean.valueOf(_bdoenable)); 310 } 311 } 312 313 } 314 getScrollValue()315 protected int getScrollValue() 316 { 317 return nscrollvalue; 318 } 319 setLineIncrementation(int _nlineincrement)320 protected void setLineIncrementation(int _nlineincrement) 321 { 322 this.nlineincrement = _nlineincrement; 323 Helper.setUnoPropertyValue(UnoDialog.getModel(xScrollBar), "LineIncrement", new Integer(nlineincrement)); 324 325 } 326 getLineIncrementation()327 protected int getLineIncrementation() 328 { 329 return nlineincrement; 330 } 331 setBlockIncrementation(int _nblockincrement)332 protected void setBlockIncrementation(int _nblockincrement) 333 { 334 this.nblockincrement = _nblockincrement; 335 Helper.setUnoPropertyValues(UnoDialog.getModel(xScrollBar), new String[] 336 { 337 PropertyNames.PROPERTY_ENABLED, "BlockIncrement", "ScrollValueMax" 338 }, new Object[] 339 { 340 Boolean.valueOf(ntotfieldcount > nblockincrement), new Integer(nblockincrement), new Integer(ntotfieldcount - nblockincrement) 341 }); 342 } 343 getBlockIncrementation()344 protected int getBlockIncrementation() 345 { 346 return nblockincrement; 347 } 348 scrollControls()349 private void scrollControls() 350 { 351 try 352 { 353 scrollRowsInfo(); 354 nscrollvalue = ((Integer) Helper.getUnoPropertyValue(UnoDialog.getModel(xScrollBar), "ScrollValue")).intValue(); 355 if (nscrollvalue + nblockincrement >= ntotfieldcount) 356 { 357 nscrollvalue = (ntotfieldcount) - nblockincrement; 358 } 359 fillupControls(false); 360 } 361 catch (java.lang.Exception ex) 362 { 363 ex.printStackTrace(); 364 } 365 } 366 scrollRowsInfo()367 protected void scrollRowsInfo() 368 { 369 int cols = 370 scrollfields.size() > 0 371 ? ((PropertyValue[]) scrollfields.get(0)).length 372 : 0; 373 for (int a = 0; a < ncurfieldcount; a++) 374 { 375 for (int n = 0; n < cols; n++) 376 { 377 fieldInfo(a, n); 378 } 379 } 380 } 381 382 /** 383 * updates the corresponding data to 384 * the control in guiRow and column 385 * @param guiRow 0 based row index 386 * @param column 0 based column index 387 * @return the propertyValue object corresponding to 388 * this control. 389 */ fieldInfo(int guiRow, int column)390 protected PropertyValue fieldInfo(int guiRow, int column) 391 { 392 if (guiRow + nscrollvalue < scrollfields.size()) 393 { 394 return fieldInfo( 395 ((PropertyValue[]) scrollfields.elementAt(guiRow + nscrollvalue))[column], 396 ((PropertyValue[]) scrollfields.elementAt(guiRow))[column]); 397 //System.out.println("getting field info for : " + guiRow + "/" + column + ":" + pv.Value + "(" + pv.Name + ")" ); 398 } 399 else 400 { 401 return null; 402 } 403 } 404 fieldInfo(PropertyValue valueProp, PropertyValue nameProp)405 protected PropertyValue fieldInfo(PropertyValue valueProp, PropertyValue nameProp) 406 { 407 if (CurUnoDialog.getDlgNameAccess().hasByName(nameProp.Name)) 408 { 409 valueProp.Value = getControlData(nameProp.Name); 410 } 411 else 412 { 413 valueProp.Value = nameProp.Value; 414 } 415 return valueProp; 416 } 417 unregisterControlGroup(int _index)418 protected void unregisterControlGroup(int _index) 419 { 420 scrollfields.remove(_index); 421 } 422 registerControlGroup(PropertyValue[] _currowproperties, int _i)423 protected void registerControlGroup(PropertyValue[] _currowproperties, int _i) 424 { 425 if (_i == 0) 426 { 427 scrollfields.removeAllElements(); 428 } 429 if (_i >= scrollfields.size()) 430 { 431 scrollfields.addElement(_currowproperties); 432 } 433 else 434 { 435 scrollfields.setElementAt(_currowproperties, _i); 436 } 437 } 438 getControlGroupInfo(int _i)439 protected PropertyValue[] getControlGroupInfo(int _i) 440 { 441 return (PropertyValue[]) scrollfields.elementAt(_i); 442 } 443 setControlData(String controlname, Object newvalue)444 protected void setControlData(String controlname, Object newvalue) 445 { 446 Object oControlModel = UnoDialog.getModel(CurUnoDialog.xDlgContainer.getControl(controlname)); 447 String propertyname = UnoDialog.getDisplayProperty(oControlModel); 448 if (!propertyname.equals(PropertyNames.EMPTY_STRING)) 449 { 450 CurUnoDialog.setControlProperty(controlname, propertyname, newvalue); 451 } 452 } 453 getControlData(String controlname)454 protected Object getControlData(String controlname) 455 { 456 Object oControlModel = UnoDialog.getModel(CurUnoDialog.xDlgContainer.getControl(controlname)); 457 String propertyname = UnoDialog.getDisplayProperty(oControlModel); 458 if (!propertyname.equals(PropertyNames.EMPTY_STRING)) 459 { 460 return CurUnoDialog.getControlProperty(controlname, propertyname); 461 } 462 else 463 { 464 return null; 465 } 466 } 467 getScrollFieldValues()468 protected PropertyValue[][] getScrollFieldValues() 469 { 470 scrollRowsInfo(); 471 PropertyValue[] curproperties; 472 PropertyValue[][] retproperties; 473 retproperties = new PropertyValue[scrollfields.size()][]; 474 try 475 { 476 for (int i = 0; i < scrollfields.size(); i++) 477 { 478 curproperties = (PropertyValue[]) scrollfields.elementAt(i); 479 retproperties[i] = curproperties; 480 } 481 return retproperties; 482 } 483 catch (java.lang.Exception ex) 484 { 485 ex.printStackTrace(System.out); 486 return null; 487 } 488 } 489 initializeScrollFields()490 protected abstract void initializeScrollFields(); 491 492 /** inserts a group of controls into the component. The group may either be a row or a column of controls 493 * The controls should be put on Step 99 (means made invisible at first). All the controlrows that are needed are than 494 * made visible automatically when calling "initialize(_fieldcount)" 495 * @author bc93774 496 * @param i: The index of the control group 497 * @param npos: Can be an x coordinate or an y coordinate which depends on the orientation of the scrollbar 498 */ insertControlGroup(int _index, int npos)499 protected abstract void insertControlGroup(int _index, int npos); 500 setControlGroupVisible(int _index, boolean _bIsVisible)501 protected abstract void setControlGroupVisible(int _index, boolean _bIsVisible); 502 } 503