1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * The Contents of this file are made available subject to the terms of 4*cdf0e10cSrcweir * the BSD license. 5*cdf0e10cSrcweir * 6*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 7*cdf0e10cSrcweir * All rights reserved. 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * Redistribution and use in source and binary forms, with or without 10*cdf0e10cSrcweir * modification, are permitted provided that the following conditions 11*cdf0e10cSrcweir * are met: 12*cdf0e10cSrcweir * 1. Redistributions of source code must retain the above copyright 13*cdf0e10cSrcweir * notice, this list of conditions and the following disclaimer. 14*cdf0e10cSrcweir * 2. Redistributions in binary form must reproduce the above copyright 15*cdf0e10cSrcweir * notice, this list of conditions and the following disclaimer in the 16*cdf0e10cSrcweir * documentation and/or other materials provided with the distribution. 17*cdf0e10cSrcweir * 3. Neither the name of Sun Microsystems, Inc. nor the names of its 18*cdf0e10cSrcweir * contributors may be used to endorse or promote products derived 19*cdf0e10cSrcweir * from this software without specific prior written permission. 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22*cdf0e10cSrcweir * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23*cdf0e10cSrcweir * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24*cdf0e10cSrcweir * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25*cdf0e10cSrcweir * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26*cdf0e10cSrcweir * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27*cdf0e10cSrcweir * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 28*cdf0e10cSrcweir * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29*cdf0e10cSrcweir * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 30*cdf0e10cSrcweir * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 31*cdf0e10cSrcweir * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32*cdf0e10cSrcweir * 33*cdf0e10cSrcweir *************************************************************************/ 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir // __________ Imports __________ 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir // base classes 38*cdf0e10cSrcweir import com.sun.star.uno.XInterface; 39*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 40*cdf0e10cSrcweir import com.sun.star.lang.*; 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir // property access 43*cdf0e10cSrcweir import com.sun.star.beans.*; 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir // application specific classes 46*cdf0e10cSrcweir import com.sun.star.chart.*; 47*cdf0e10cSrcweir import com.sun.star.drawing.*; 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir import com.sun.star.table.CellRangeAddress; 50*cdf0e10cSrcweir import com.sun.star.table.XCellRange; 51*cdf0e10cSrcweir import com.sun.star.sheet.XCellRangeAddressable; 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir import com.sun.star.frame.XModel; 54*cdf0e10cSrcweir import com.sun.star.frame.XController; 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir import com.sun.star.util.XNumberFormatsSupplier; 57*cdf0e10cSrcweir import com.sun.star.util.XNumberFormats; 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir // base graphics things 60*cdf0e10cSrcweir import com.sun.star.awt.Point; 61*cdf0e10cSrcweir import com.sun.star.awt.Size; 62*cdf0e10cSrcweir import com.sun.star.awt.Rectangle; 63*cdf0e10cSrcweir import com.sun.star.awt.FontWeight; 64*cdf0e10cSrcweir import com.sun.star.awt.FontRelief; 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir // Exceptions 67*cdf0e10cSrcweir import com.sun.star.uno.Exception; 68*cdf0e10cSrcweir import com.sun.star.uno.RuntimeException; 69*cdf0e10cSrcweir import com.sun.star.beans.UnknownPropertyException; 70*cdf0e10cSrcweir import com.sun.star.lang.IndexOutOfBoundsException; 71*cdf0e10cSrcweir import com.sun.star.util.MalformedNumberFormatException; 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir // __________ Implementation __________ 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir /** Create a spreadsheet add some data and add a chart 77*cdf0e10cSrcweir @author Björn Milcke 78*cdf0e10cSrcweir */ 79*cdf0e10cSrcweir public class ChartInCalc 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir // ____________________ 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir public static void main( String args[] ) 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir Helper aHelper = new Helper( args ); 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir CalcHelper aCalcHelper = new CalcHelper( aHelper.createSpreadsheetDocument() ); 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir // insert a cell range with 4 columns and 24 rows filled with random numbers 90*cdf0e10cSrcweir XCellRange aRange = aCalcHelper.insertRandomRange( 4, 24 ); 91*cdf0e10cSrcweir CellRangeAddress aRangeAddress = ((XCellRangeAddressable) UnoRuntime.queryInterface( 92*cdf0e10cSrcweir XCellRangeAddressable.class, aRange)).getRangeAddress(); 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir // change view to sheet containing the chart 95*cdf0e10cSrcweir aCalcHelper.raiseChartSheet(); 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir // the unit for measures is 1/100th of a millimeter 98*cdf0e10cSrcweir // position at (1cm, 1cm) 99*cdf0e10cSrcweir Point aPos = new Point( 1000, 1000 ); 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir // size of the chart is 15cm x 9.271cm 102*cdf0e10cSrcweir Size aExtent = new Size( 15000, 9271 ); 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir // insert a new chart into the "Chart" sheet of the 105*cdf0e10cSrcweir // spreadsheet document 106*cdf0e10cSrcweir XChartDocument aChartDoc = aCalcHelper.insertChart( 107*cdf0e10cSrcweir "ScatterChart", 108*cdf0e10cSrcweir aRangeAddress, 109*cdf0e10cSrcweir aPos, 110*cdf0e10cSrcweir aExtent, 111*cdf0e10cSrcweir "com.sun.star.chart.XYDiagram" ); 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir // instantiate test class with newly created chart 114*cdf0e10cSrcweir ChartInCalc aTest = new ChartInCalc( aChartDoc ); 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir try 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir aTest.lockControllers(); 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir aTest.testDiagram(); 121*cdf0e10cSrcweir aTest.testArea(); 122*cdf0e10cSrcweir aTest.testWall(); 123*cdf0e10cSrcweir aTest.testTitle(); 124*cdf0e10cSrcweir aTest.testAxis(); 125*cdf0e10cSrcweir aTest.testGrid(); 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir // show an intermediate state, ... 128*cdf0e10cSrcweir aTest.unlockControllers(); 129*cdf0e10cSrcweir aTest.lockControllers(); 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir // ..., because the following takes a while: 132*cdf0e10cSrcweir // an internet URL has to be resolved 133*cdf0e10cSrcweir aTest.testDataRowProperties(); 134*cdf0e10cSrcweir aTest.testDataPointProperties(); 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir aTest.unlockControllers(); 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir catch( Exception ex ) 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir System.out.println( "UNO Exception caught: " + ex ); 141*cdf0e10cSrcweir System.out.println( "Message: " + ex.getMessage() ); 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir System.exit( 0 ); 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir // ________________________________________ 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir public ChartInCalc( XChartDocument aChartDoc ) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir maChartDocument = aChartDoc; 153*cdf0e10cSrcweir maDiagram = maChartDocument.getDiagram(); 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir // ____________________ 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir public void lockControllers() 159*cdf0e10cSrcweir throws RuntimeException 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir ((XModel) UnoRuntime.queryInterface( XModel.class, maChartDocument )).lockControllers(); 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir // ____________________ 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir public void unlockControllers() 167*cdf0e10cSrcweir throws RuntimeException 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir ((XModel) UnoRuntime.queryInterface( XModel.class, maChartDocument )).unlockControllers(); 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir // ____________________ 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir public void testDiagram() 175*cdf0e10cSrcweir throws RuntimeException, UnknownPropertyException, PropertyVetoException, 176*cdf0e10cSrcweir com.sun.star.lang.IllegalArgumentException, WrappedTargetException 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, maDiagram ); 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir if( aDiaProp != null ) 181*cdf0e10cSrcweir { 182*cdf0e10cSrcweir // change chart type 183*cdf0e10cSrcweir aDiaProp.setPropertyValue( "Lines", new Boolean( true )); 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir // change attributes for all series 186*cdf0e10cSrcweir // set line width to 0.5mm 187*cdf0e10cSrcweir aDiaProp.setPropertyValue( "LineWidth", new Integer( 50 )); 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir // ____________________ 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir public void testDataRowProperties() 194*cdf0e10cSrcweir throws RuntimeException, UnknownPropertyException, PropertyVetoException, 195*cdf0e10cSrcweir com.sun.star.lang.IllegalArgumentException, WrappedTargetException 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir // change properties of the data series 198*cdf0e10cSrcweir try 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir XPropertySet aSeriesProp; 201*cdf0e10cSrcweir for( int i = 1; i <= 3; i++ ) 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir aSeriesProp = maDiagram.getDataRowProperties( i ); 204*cdf0e10cSrcweir aSeriesProp.setPropertyValue( "LineColor", new Integer( 205*cdf0e10cSrcweir 0x400000 * i + 206*cdf0e10cSrcweir 0x005000 * i + 207*cdf0e10cSrcweir 0x0000ff - 0x40 * i )); 208*cdf0e10cSrcweir if( 1 == i ) 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir StringBuffer sUrl = new StringBuffer("file:///"); 211*cdf0e10cSrcweir try { 212*cdf0e10cSrcweir /* for use without net it's easier to load a local graphic */ 213*cdf0e10cSrcweir java.io.File sourceFile = new java.io.File("bullet.gif"); 214*cdf0e10cSrcweir sUrl.append(sourceFile.getCanonicalPath().replace('\\', '/')); 215*cdf0e10cSrcweir } catch (java.io.IOException e) { 216*cdf0e10cSrcweir sUrl = new StringBuffer("http://graphics.openoffice.org/chart/bullet1.gif"); 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir // set a bitmap via URL as symbol for the first series 220*cdf0e10cSrcweir aSeriesProp.setPropertyValue( "SymbolType", new Integer( ChartSymbolType.BITMAPURL )); 221*cdf0e10cSrcweir aSeriesProp.setPropertyValue( "SymbolBitmapURL", sUrl.toString() ); 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir else 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir aSeriesProp.setPropertyValue( "SymbolType", new Integer( ChartSymbolType.SYMBOL1 )); 226*cdf0e10cSrcweir aSeriesProp.setPropertyValue( "SymbolSize", new Size( 250, 250 )); 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir } 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir catch( IndexOutOfBoundsException ex ) 231*cdf0e10cSrcweir { 232*cdf0e10cSrcweir System.out.println( "Oops, there not enough series for setting properties: " + ex ); 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir // ____________________ 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir public void testDataPointProperties() 239*cdf0e10cSrcweir throws RuntimeException, UnknownPropertyException, PropertyVetoException, 240*cdf0e10cSrcweir com.sun.star.lang.IllegalArgumentException, WrappedTargetException 241*cdf0e10cSrcweir { 242*cdf0e10cSrcweir // set properties for a single data point 243*cdf0e10cSrcweir try 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir // determine the maximum value of the first series 246*cdf0e10cSrcweir int nMaxIndex = 0; 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir XChartDataArray aDataArray = (XChartDataArray) UnoRuntime.queryInterface( 249*cdf0e10cSrcweir XChartDataArray.class, maChartDocument.getData()); 250*cdf0e10cSrcweir double aData[][] = aDataArray.getData(); 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir int i; 253*cdf0e10cSrcweir double fMax = aData[ 0 ][ 1 ]; 254*cdf0e10cSrcweir for( i = 1; i < aData.length; i++ ) 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir if( aData[ i ][ 1 ] > fMax ) 257*cdf0e10cSrcweir { 258*cdf0e10cSrcweir fMax = aData[ i ][ 1 ]; 259*cdf0e10cSrcweir nMaxIndex = i; 260*cdf0e10cSrcweir } 261*cdf0e10cSrcweir } 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir // first parameter is the index of the point, the second one is the series 264*cdf0e10cSrcweir XPropertySet aPointProp = maDiagram.getDataPointProperties( 0, 1 ); 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir // set a different, larger symbol 267*cdf0e10cSrcweir aPointProp.setPropertyValue( "SymbolType", new Integer( ChartSymbolType.SYMBOL6 )); 268*cdf0e10cSrcweir aPointProp.setPropertyValue( "SymbolSize", new Size( 600, 600 )); 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir // add a label text with bold font, bordeaux red 14pt 271*cdf0e10cSrcweir aPointProp.setPropertyValue( "DataCaption", new Integer( ChartDataCaption.VALUE )); 272*cdf0e10cSrcweir aPointProp.setPropertyValue( "CharHeight", new Float( 14.0 )); 273*cdf0e10cSrcweir aPointProp.setPropertyValue( "CharColor", new Integer( 0x993366 )); 274*cdf0e10cSrcweir aPointProp.setPropertyValue( "CharWeight", new Float( FontWeight.BOLD )); 275*cdf0e10cSrcweir } 276*cdf0e10cSrcweir catch( IndexOutOfBoundsException ex ) 277*cdf0e10cSrcweir { 278*cdf0e10cSrcweir System.out.println( "Oops, there not enough data points or series for setting properties: " + ex ); 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir // ____________________ 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir public void testArea() 285*cdf0e10cSrcweir throws RuntimeException, UnknownPropertyException, PropertyVetoException, 286*cdf0e10cSrcweir com.sun.star.lang.IllegalArgumentException, WrappedTargetException 287*cdf0e10cSrcweir { 288*cdf0e10cSrcweir XPropertySet aArea = maChartDocument.getArea(); 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir if( aArea != null ) 291*cdf0e10cSrcweir { 292*cdf0e10cSrcweir // change background color of entire chart 293*cdf0e10cSrcweir aArea.setPropertyValue( "FillStyle", FillStyle.SOLID ); 294*cdf0e10cSrcweir aArea.setPropertyValue( "FillColor", new Integer( 0xeeeeee )); 295*cdf0e10cSrcweir } 296*cdf0e10cSrcweir } 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir // ____________________ 299*cdf0e10cSrcweir 300*cdf0e10cSrcweir public void testWall() 301*cdf0e10cSrcweir throws RuntimeException, UnknownPropertyException, PropertyVetoException, 302*cdf0e10cSrcweir com.sun.star.lang.IllegalArgumentException, WrappedTargetException 303*cdf0e10cSrcweir { 304*cdf0e10cSrcweir XPropertySet aWall = ((X3DDisplay) UnoRuntime.queryInterface( 305*cdf0e10cSrcweir X3DDisplay.class, maDiagram )).getWall(); 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir // change background color of area 308*cdf0e10cSrcweir aWall.setPropertyValue( "FillStyle", FillStyle.SOLID ); 309*cdf0e10cSrcweir aWall.setPropertyValue( "FillColor", new Integer( 0xcccccc )); 310*cdf0e10cSrcweir } 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir // ____________________ 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir public void testTitle() 315*cdf0e10cSrcweir throws RuntimeException, UnknownPropertyException, PropertyVetoException, 316*cdf0e10cSrcweir com.sun.star.lang.IllegalArgumentException, WrappedTargetException 317*cdf0e10cSrcweir { 318*cdf0e10cSrcweir // change main title 319*cdf0e10cSrcweir XPropertySet aDocProp = (XPropertySet) UnoRuntime.queryInterface( 320*cdf0e10cSrcweir XPropertySet.class, maChartDocument ); 321*cdf0e10cSrcweir aDocProp.setPropertyValue( "HasMainTitle", new Boolean( true )); 322*cdf0e10cSrcweir 323*cdf0e10cSrcweir XShape aTitle = maChartDocument.getTitle(); 324*cdf0e10cSrcweir XPropertySet aTitleProp = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, aTitle ); 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir // set new text 327*cdf0e10cSrcweir if( aTitleProp != null ) 328*cdf0e10cSrcweir { 329*cdf0e10cSrcweir aTitleProp.setPropertyValue( "String", "Random Scatter Chart" ); 330*cdf0e10cSrcweir aTitleProp.setPropertyValue( "CharHeight", new Float(14.0) ); 331*cdf0e10cSrcweir } 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir // align title with y axis 334*cdf0e10cSrcweir XShape aAxis = (XShape) UnoRuntime.queryInterface( 335*cdf0e10cSrcweir XShape.class, ((XAxisYSupplier) UnoRuntime.queryInterface( 336*cdf0e10cSrcweir XAxisYSupplier.class, maDiagram )).getYAxis() ); 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir if( aAxis != null && 339*cdf0e10cSrcweir aTitle != null ) 340*cdf0e10cSrcweir { 341*cdf0e10cSrcweir Point aPos = aTitle.getPosition(); 342*cdf0e10cSrcweir aPos.X = ( aAxis.getPosition() ).X; 343*cdf0e10cSrcweir aTitle.setPosition( aPos ); 344*cdf0e10cSrcweir } 345*cdf0e10cSrcweir } 346*cdf0e10cSrcweir 347*cdf0e10cSrcweir // ____________________ 348*cdf0e10cSrcweir 349*cdf0e10cSrcweir public void testAxis() 350*cdf0e10cSrcweir throws RuntimeException, UnknownPropertyException, PropertyVetoException, 351*cdf0e10cSrcweir com.sun.star.lang.IllegalArgumentException, WrappedTargetException, 352*cdf0e10cSrcweir MalformedNumberFormatException 353*cdf0e10cSrcweir { 354*cdf0e10cSrcweir // x axis 355*cdf0e10cSrcweir XPropertySet aAxisProp = ((XAxisXSupplier) UnoRuntime.queryInterface( 356*cdf0e10cSrcweir XAxisXSupplier.class, maDiagram )).getXAxis(); 357*cdf0e10cSrcweir if( aAxisProp != null ) 358*cdf0e10cSrcweir { 359*cdf0e10cSrcweir aAxisProp.setPropertyValue( "Max", new Integer( 24 )); 360*cdf0e10cSrcweir aAxisProp.setPropertyValue( "StepMain", new Integer( 3 )); 361*cdf0e10cSrcweir } 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir // change number format for y axis 364*cdf0e10cSrcweir aAxisProp = ((XAxisYSupplier) UnoRuntime.queryInterface( 365*cdf0e10cSrcweir XAxisYSupplier.class, maDiagram )).getYAxis(); 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir // add a new custom number format and get the new key 368*cdf0e10cSrcweir int nNewNumberFormat = 0; 369*cdf0e10cSrcweir XNumberFormatsSupplier aNumFmtSupp = (XNumberFormatsSupplier) UnoRuntime.queryInterface( 370*cdf0e10cSrcweir XNumberFormatsSupplier.class, maChartDocument ); 371*cdf0e10cSrcweir 372*cdf0e10cSrcweir if( aNumFmtSupp != null ) 373*cdf0e10cSrcweir { 374*cdf0e10cSrcweir XNumberFormats aFormats = aNumFmtSupp.getNumberFormats(); 375*cdf0e10cSrcweir Locale aLocale = new Locale( "de", "DE", "de" ); 376*cdf0e10cSrcweir 377*cdf0e10cSrcweir String aFormatStr = aFormats.generateFormat( nNewNumberFormat, aLocale, true, true, (short)3, (short)1 ); 378*cdf0e10cSrcweir nNewNumberFormat = aFormats.addNew( aFormatStr, aLocale ); 379*cdf0e10cSrcweir } 380*cdf0e10cSrcweir 381*cdf0e10cSrcweir if( aAxisProp != null ) 382*cdf0e10cSrcweir { 383*cdf0e10cSrcweir aAxisProp.setPropertyValue( "NumberFormat", new Integer( nNewNumberFormat )); 384*cdf0e10cSrcweir } 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir 387*cdf0e10cSrcweir // ____________________ 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir public void testGrid() 390*cdf0e10cSrcweir throws RuntimeException, UnknownPropertyException, PropertyVetoException, 391*cdf0e10cSrcweir com.sun.star.lang.IllegalArgumentException, WrappedTargetException 392*cdf0e10cSrcweir { 393*cdf0e10cSrcweir // y major grid 394*cdf0e10cSrcweir XPropertySet aGridProp = (XPropertySet) UnoRuntime.queryInterface( 395*cdf0e10cSrcweir XPropertySet.class, 396*cdf0e10cSrcweir ( (XAxisYSupplier) UnoRuntime.queryInterface( 397*cdf0e10cSrcweir XAxisYSupplier.class, maDiagram )).getYMainGrid()); 398*cdf0e10cSrcweir 399*cdf0e10cSrcweir if( aGridProp != null ) 400*cdf0e10cSrcweir { 401*cdf0e10cSrcweir LineDash aDash = new LineDash(); 402*cdf0e10cSrcweir aDash.Style = DashStyle.ROUND; 403*cdf0e10cSrcweir aDash.Dots = 2; 404*cdf0e10cSrcweir aDash.DotLen = 10; 405*cdf0e10cSrcweir aDash.Dashes = 1; 406*cdf0e10cSrcweir aDash.DashLen = 200; 407*cdf0e10cSrcweir aDash.Distance = 100; 408*cdf0e10cSrcweir 409*cdf0e10cSrcweir aGridProp.setPropertyValue( "LineColor", new Integer( 0x999999 )); 410*cdf0e10cSrcweir aGridProp.setPropertyValue( "LineStyle", LineStyle.DASH ); 411*cdf0e10cSrcweir aGridProp.setPropertyValue( "LineDash", aDash ); 412*cdf0e10cSrcweir aGridProp.setPropertyValue( "LineWidth", new Integer( 30 )); 413*cdf0e10cSrcweir } 414*cdf0e10cSrcweir } 415*cdf0e10cSrcweir 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir // ______________________________ 418*cdf0e10cSrcweir // 419*cdf0e10cSrcweir // private members 420*cdf0e10cSrcweir // ______________________________ 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir private XChartDocument maChartDocument; 423*cdf0e10cSrcweir private XDiagram maDiagram; 424*cdf0e10cSrcweir } 425