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 // base classes 36*cdf0e10cSrcweir import com.sun.star.uno.XInterface; 37*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 38*cdf0e10cSrcweir import com.sun.star.uno.Type; 39*cdf0e10cSrcweir import com.sun.star.container.XIndexAccess; 40*cdf0e10cSrcweir import com.sun.star.lib.uno.helper.WeakBase; 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir // factories 43*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 44*cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory; 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir // graphics stuff 47*cdf0e10cSrcweir import com.sun.star.drawing.*; 48*cdf0e10cSrcweir import com.sun.star.awt.Point; 49*cdf0e10cSrcweir import com.sun.star.awt.Rectangle; 50*cdf0e10cSrcweir import com.sun.star.awt.Size; 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir // chart stuff 53*cdf0e10cSrcweir import com.sun.star.chart.*; 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir // property access 56*cdf0e10cSrcweir import com.sun.star.beans.*; 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir // Add-In stuff 59*cdf0e10cSrcweir import com.sun.star.lang.XInitialization; 60*cdf0e10cSrcweir import com.sun.star.util.XRefreshable; 61*cdf0e10cSrcweir import com.sun.star.lang.XServiceName; 62*cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo; 63*cdf0e10cSrcweir import com.sun.star.lang.XTypeProvider; 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir // Exceptions 66*cdf0e10cSrcweir import com.sun.star.uno.Exception; 67*cdf0e10cSrcweir import com.sun.star.uno.RuntimeException; 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir import javax.swing.JOptionPane; 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir public class JavaSampleChartAddIn extends WeakBase implements 72*cdf0e10cSrcweir XInitialization, 73*cdf0e10cSrcweir XRefreshable, 74*cdf0e10cSrcweir XDiagram, 75*cdf0e10cSrcweir XServiceName, 76*cdf0e10cSrcweir XServiceInfo 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir public JavaSampleChartAddIn() 79*cdf0e10cSrcweir {} 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir // __________ interface methods __________ 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir // XInitialization 84*cdf0e10cSrcweir public void initialize( Object[] aArguments ) 85*cdf0e10cSrcweir throws Exception, RuntimeException 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir if( aArguments.length > 0 ) 88*cdf0e10cSrcweir { 89*cdf0e10cSrcweir maChartDocument = (XChartDocument) UnoRuntime.queryInterface( 90*cdf0e10cSrcweir XChartDocument.class, aArguments[ 0 ]); 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir XPropertySet aDocProp = (XPropertySet) UnoRuntime.queryInterface( 93*cdf0e10cSrcweir XPropertySet.class, maChartDocument ); 94*cdf0e10cSrcweir if( aDocProp != null ) 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir // set base diagram which will be extended in refresh() 97*cdf0e10cSrcweir aDocProp.setPropertyValue( "BaseDiagram", "com.sun.star.chart.XYDiagram" ); 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir // get the draw page 101*cdf0e10cSrcweir XDrawPageSupplier aPageSupp = (XDrawPageSupplier) UnoRuntime.queryInterface( 102*cdf0e10cSrcweir XDrawPageSupplier.class, maChartDocument ); 103*cdf0e10cSrcweir if( aPageSupp != null ) 104*cdf0e10cSrcweir maDrawPage = (XDrawPage) UnoRuntime.queryInterface( 105*cdf0e10cSrcweir XDrawPage.class, aPageSupp.getDrawPage() ); 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir // get a factory for creating shapes 108*cdf0e10cSrcweir maShapeFactory = (XMultiServiceFactory) UnoRuntime.queryInterface( 109*cdf0e10cSrcweir XMultiServiceFactory.class, maChartDocument ); 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir // XRefreshable 114*cdf0e10cSrcweir public void refresh() throws RuntimeException 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir // recycle shapes in first call, if document was loaded 117*cdf0e10cSrcweir if( maBottomLine == null || 118*cdf0e10cSrcweir maTopLine == null ) 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir // try to recycle loaded shapes 121*cdf0e10cSrcweir XPropertySet aDocProp = (XPropertySet) UnoRuntime.queryInterface( 122*cdf0e10cSrcweir XPropertySet.class, maChartDocument ); 123*cdf0e10cSrcweir if( aDocProp != null ) 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir try 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir XIndexAccess aShapesIA = (XIndexAccess) UnoRuntime.queryInterface( 128*cdf0e10cSrcweir XIndexAccess.class, aDocProp.getPropertyValue( "AdditionalShapes" )); 129*cdf0e10cSrcweir if( aShapesIA != null && 130*cdf0e10cSrcweir aShapesIA.getCount() > 0 ) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir XShape aShape; 133*cdf0e10cSrcweir String aName; 134*cdf0e10cSrcweir for( int i = aShapesIA.getCount() - 1; i >= 0; --i ) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir aShape = (XShape) UnoRuntime.queryInterface( 137*cdf0e10cSrcweir XShape.class, aShapesIA.getByIndex( i )); 138*cdf0e10cSrcweir if( aShape != null ) 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir XPropertySet aProp = (XPropertySet) UnoRuntime.queryInterface( 141*cdf0e10cSrcweir XPropertySet.class, aShape ); 142*cdf0e10cSrcweir aName = (String) aProp.getPropertyValue( "Name" ); 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir if( aName.equals( "top" )) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir maTopLine = aShape; 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir else if( aName.equals( "bottom" )) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir maBottomLine = aShape; 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir catch( Exception ex ) 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir JOptionPane.showMessageDialog( null, ex, "Exception caught", JOptionPane.WARNING_MESSAGE ); 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir // create top line if it does not yet exist 164*cdf0e10cSrcweir try 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir if( maTopLine == null ) 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir maTopLine = (XShape) UnoRuntime.queryInterface( 169*cdf0e10cSrcweir XShape.class, maShapeFactory.createInstance( "com.sun.star.drawing.LineShape" )); 170*cdf0e10cSrcweir maDrawPage.add( maTopLine ); 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir // make line red and thicker 173*cdf0e10cSrcweir XPropertySet aShapeProp = (XPropertySet) UnoRuntime.queryInterface( 174*cdf0e10cSrcweir XPropertySet.class, maTopLine ); 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir aShapeProp.setPropertyValue( "LineColor", new Integer( 0xe01010 )); 177*cdf0e10cSrcweir aShapeProp.setPropertyValue( "LineWidth", new Integer( 50 )); 178*cdf0e10cSrcweir aShapeProp.setPropertyValue( "Name", "top" ); 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir catch( Exception ex ) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir JOptionPane.showMessageDialog( null, ex, "Exception caught", JOptionPane.WARNING_MESSAGE ); 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir // create bottom line if it does not yet exist 187*cdf0e10cSrcweir try 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir if( maBottomLine == null ) 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir maBottomLine = (XShape) UnoRuntime.queryInterface( 192*cdf0e10cSrcweir XShape.class, maShapeFactory.createInstance( "com.sun.star.drawing.LineShape" )); 193*cdf0e10cSrcweir maDrawPage.add( maBottomLine ); 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir // make line green and thicker 196*cdf0e10cSrcweir XPropertySet aShapeProp = (XPropertySet) UnoRuntime.queryInterface( 197*cdf0e10cSrcweir XPropertySet.class, maBottomLine ); 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir aShapeProp.setPropertyValue( "LineColor", new Integer( 0x10e010 )); 200*cdf0e10cSrcweir aShapeProp.setPropertyValue( "LineWidth", new Integer( 50 )); 201*cdf0e10cSrcweir aShapeProp.setPropertyValue( "Name", "bottom" ); 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir catch( Exception ex ) 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir JOptionPane.showMessageDialog( null, ex, "Exception caught", JOptionPane.WARNING_MESSAGE ); 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir if( maTopLine == null || 210*cdf0e10cSrcweir maBottomLine == null ) 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir JOptionPane.showMessageDialog( null, "One of the lines is still null", "Assertion", JOptionPane.WARNING_MESSAGE ); 213*cdf0e10cSrcweir return; 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir // position lines 217*cdf0e10cSrcweir // -------------- 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir // get data 220*cdf0e10cSrcweir XChartDataArray aDataArray = (XChartDataArray) UnoRuntime.queryInterface( 221*cdf0e10cSrcweir XChartDataArray.class, maChartDocument.getData()); 222*cdf0e10cSrcweir double aData[][] = aDataArray.getData(); 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir // get axes 225*cdf0e10cSrcweir XDiagram aDiagram = maChartDocument.getDiagram(); 226*cdf0e10cSrcweir XShape aXAxis = (XShape) UnoRuntime.queryInterface( 227*cdf0e10cSrcweir XShape.class, ((XAxisXSupplier) UnoRuntime.queryInterface( 228*cdf0e10cSrcweir XAxisXSupplier.class, aDiagram )).getXAxis() ); 229*cdf0e10cSrcweir XShape aYAxis = (XShape) UnoRuntime.queryInterface( 230*cdf0e10cSrcweir XShape.class, ((XAxisYSupplier) UnoRuntime.queryInterface( 231*cdf0e10cSrcweir XAxisYSupplier.class, aDiagram )).getYAxis() ); 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir // calculate points for hull 234*cdf0e10cSrcweir final int nLength = aData.length; 235*cdf0e10cSrcweir int i, j; 236*cdf0e10cSrcweir double fMax, fMin; 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir Point aMaxPtSeq[][] = new Point[ 1 ][]; 239*cdf0e10cSrcweir aMaxPtSeq[ 0 ] = new Point[ nLength ]; 240*cdf0e10cSrcweir Point aMinPtSeq[][] = new Point[ 1 ][]; 241*cdf0e10cSrcweir aMinPtSeq[ 0 ] = new Point[ nLength ]; 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir for( i = 0; i < nLength; i++ ) 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir fMin = fMax = aData[ i ][ 1 ]; 246*cdf0e10cSrcweir for( j = 1; j < aData[ i ].length; j++ ) 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir if( aData[ i ][ j ] > fMax ) 249*cdf0e10cSrcweir fMax = aData[ i ][ j ]; 250*cdf0e10cSrcweir else if( aData[ i ][ j ] < fMin ) 251*cdf0e10cSrcweir fMin = aData[ i ][ j ]; 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir aMaxPtSeq[ 0 ][ i ] = new Point( getAxisPosition( aXAxis, aData[ i ][ 0 ], false ), 254*cdf0e10cSrcweir getAxisPosition( aYAxis, fMax, true )); 255*cdf0e10cSrcweir aMinPtSeq[ 0 ][ i ] = new Point( getAxisPosition( aXAxis, aData[ i ][ 0 ], false ), 256*cdf0e10cSrcweir getAxisPosition( aYAxis, fMin, true )); 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir // apply point sequences to lines 260*cdf0e10cSrcweir try 261*cdf0e10cSrcweir { 262*cdf0e10cSrcweir XPropertySet aShapeProp = (XPropertySet) UnoRuntime.queryInterface( 263*cdf0e10cSrcweir XPropertySet.class, maTopLine ); 264*cdf0e10cSrcweir aShapeProp.setPropertyValue( "PolyPolygon", aMaxPtSeq ); 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir aShapeProp = (XPropertySet) UnoRuntime.queryInterface( 267*cdf0e10cSrcweir XPropertySet.class, maBottomLine ); 268*cdf0e10cSrcweir aShapeProp.setPropertyValue( "PolyPolygon", aMinPtSeq ); 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir catch( Exception ex ) 271*cdf0e10cSrcweir { 272*cdf0e10cSrcweir JOptionPane.showMessageDialog( null, ex, "Exception caught", JOptionPane.WARNING_MESSAGE ); 273*cdf0e10cSrcweir } 274*cdf0e10cSrcweir } 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir public void addRefreshListener( com.sun.star.util.XRefreshListener aListener ) 277*cdf0e10cSrcweir throws RuntimeException 278*cdf0e10cSrcweir { 279*cdf0e10cSrcweir // we don't want this but we have to implement the interface 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir public void removeRefreshListener( com.sun.star.util.XRefreshListener aListener ) 283*cdf0e10cSrcweir throws RuntimeException 284*cdf0e10cSrcweir { 285*cdf0e10cSrcweir // we don't want this but we have to implement the interface 286*cdf0e10cSrcweir } 287*cdf0e10cSrcweir 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir // XServiceName 290*cdf0e10cSrcweir public String getServiceName() throws RuntimeException 291*cdf0e10cSrcweir { 292*cdf0e10cSrcweir return new String( smServiceName ); 293*cdf0e10cSrcweir } 294*cdf0e10cSrcweir 295*cdf0e10cSrcweir // XServiceInfo 296*cdf0e10cSrcweir public boolean supportsService( String aServiceName ) 297*cdf0e10cSrcweir { 298*cdf0e10cSrcweir String[] aServices = getSupportedServiceNames_Static(); 299*cdf0e10cSrcweir int i, nLength = aServices.length; 300*cdf0e10cSrcweir boolean bResult = false; 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir for( i = 0; !bResult && i < nLength; ++i ) 303*cdf0e10cSrcweir bResult = aServiceName.equals( aServices[ i ] ); 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir return bResult; 306*cdf0e10cSrcweir } 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir public String getImplementationName() 309*cdf0e10cSrcweir { 310*cdf0e10cSrcweir return( JavaSampleChartAddIn.class.getName() ); 311*cdf0e10cSrcweir } 312*cdf0e10cSrcweir 313*cdf0e10cSrcweir public String[] getSupportedServiceNames() 314*cdf0e10cSrcweir { 315*cdf0e10cSrcweir return getSupportedServiceNames_Static(); 316*cdf0e10cSrcweir } 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir // XDiagram 319*cdf0e10cSrcweir public String getDiagramType() throws RuntimeException 320*cdf0e10cSrcweir { 321*cdf0e10cSrcweir return new String( smServiceName ); 322*cdf0e10cSrcweir } 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir public XPropertySet getDataRowProperties( int nRow ) 325*cdf0e10cSrcweir throws com.sun.star.lang.IndexOutOfBoundsException, RuntimeException 326*cdf0e10cSrcweir { 327*cdf0e10cSrcweir return maChartDocument.getDiagram().getDataRowProperties( nRow ); 328*cdf0e10cSrcweir } 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir public XPropertySet getDataPointProperties( int nCol, int nRow ) 331*cdf0e10cSrcweir throws com.sun.star.lang.IndexOutOfBoundsException, RuntimeException 332*cdf0e10cSrcweir { 333*cdf0e10cSrcweir return maChartDocument.getDiagram().getDataPointProperties( nCol, nRow ); 334*cdf0e10cSrcweir } 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir // XShape : XDiagram 337*cdf0e10cSrcweir public Size getSize() throws RuntimeException 338*cdf0e10cSrcweir { 339*cdf0e10cSrcweir return ((XShape) UnoRuntime.queryInterface( XShape.class, maChartDocument.getDiagram())).getSize(); 340*cdf0e10cSrcweir } 341*cdf0e10cSrcweir public void setSize( Size aSize ) throws RuntimeException, PropertyVetoException 342*cdf0e10cSrcweir { 343*cdf0e10cSrcweir ((XShape) UnoRuntime.queryInterface( XShape.class, maChartDocument.getDiagram())).setSize( aSize ); 344*cdf0e10cSrcweir } 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir public Point getPosition() throws RuntimeException 347*cdf0e10cSrcweir { 348*cdf0e10cSrcweir return ((XShape) UnoRuntime.queryInterface( XShape.class, maChartDocument.getDiagram())).getPosition(); 349*cdf0e10cSrcweir } 350*cdf0e10cSrcweir public void setPosition( Point aPos ) throws RuntimeException 351*cdf0e10cSrcweir { 352*cdf0e10cSrcweir ((XShape) UnoRuntime.queryInterface( XShape.class, maChartDocument.getDiagram())).setPosition( aPos ); 353*cdf0e10cSrcweir } 354*cdf0e10cSrcweir 355*cdf0e10cSrcweir // XShapeDescriptor : XShape : XDiagram 356*cdf0e10cSrcweir public String getShapeType() throws RuntimeException 357*cdf0e10cSrcweir { 358*cdf0e10cSrcweir return new String( "com.sun.star.comp.Chart.JavaSampleDiagramShape" ); 359*cdf0e10cSrcweir } 360*cdf0e10cSrcweir 361*cdf0e10cSrcweir 362*cdf0e10cSrcweir // __________ private members __________ 363*cdf0e10cSrcweir private com.sun.star.chart.XChartDocument maChartDocument; 364*cdf0e10cSrcweir private com.sun.star.drawing.XDrawPage maDrawPage; 365*cdf0e10cSrcweir private com.sun.star.lang.XMultiServiceFactory maShapeFactory; 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir // shapes added by add-in 368*cdf0e10cSrcweir private com.sun.star.drawing.XShape maTopLine; 369*cdf0e10cSrcweir private com.sun.star.drawing.XShape maBottomLine; 370*cdf0e10cSrcweir 371*cdf0e10cSrcweir // __________ private methods __________ 372*cdf0e10cSrcweir 373*cdf0e10cSrcweir private int getAxisPosition( XShape aAxis, double fValue, boolean bVertical ) 374*cdf0e10cSrcweir { 375*cdf0e10cSrcweir int nResult = 0; 376*cdf0e10cSrcweir 377*cdf0e10cSrcweir if( aAxis != null ) 378*cdf0e10cSrcweir { 379*cdf0e10cSrcweir XPropertySet aAxisProp = (XPropertySet) UnoRuntime.queryInterface( 380*cdf0e10cSrcweir XPropertySet.class, aAxis ); 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir try 383*cdf0e10cSrcweir { 384*cdf0e10cSrcweir double fMin, fMax; 385*cdf0e10cSrcweir fMin = ((Double) aAxisProp.getPropertyValue( "Min" )).doubleValue(); 386*cdf0e10cSrcweir fMax = ((Double) aAxisProp.getPropertyValue( "Max" )).doubleValue(); 387*cdf0e10cSrcweir double fRange = fMax - fMin; 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir if( fMin <= fValue && fValue <= fMax && 390*cdf0e10cSrcweir fRange != 0 ) 391*cdf0e10cSrcweir { 392*cdf0e10cSrcweir if( bVertical ) 393*cdf0e10cSrcweir { 394*cdf0e10cSrcweir nResult = aAxis.getPosition().Y + 395*cdf0e10cSrcweir (int)((double)(aAxis.getSize().Height) * 396*cdf0e10cSrcweir (1.0 - (( fValue - fMin ) / fRange ))); 397*cdf0e10cSrcweir } 398*cdf0e10cSrcweir else 399*cdf0e10cSrcweir { 400*cdf0e10cSrcweir nResult = aAxis.getPosition().X + 401*cdf0e10cSrcweir (int)((double)(aAxis.getSize().Width) * 402*cdf0e10cSrcweir (( fValue - fMin ) / fRange )); 403*cdf0e10cSrcweir } 404*cdf0e10cSrcweir } 405*cdf0e10cSrcweir } 406*cdf0e10cSrcweir catch( Exception ex ) 407*cdf0e10cSrcweir { 408*cdf0e10cSrcweir JOptionPane.showMessageDialog( null, ex, "Exception caught", JOptionPane.WARNING_MESSAGE ); 409*cdf0e10cSrcweir } 410*cdf0e10cSrcweir } 411*cdf0e10cSrcweir return nResult; 412*cdf0e10cSrcweir } 413*cdf0e10cSrcweir 414*cdf0e10cSrcweir // __________ static things __________ 415*cdf0e10cSrcweir 416*cdf0e10cSrcweir private static final String smServiceName = "com.sun.star.comp.Chart.JavaSampleChartAddIn"; 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir public static String[] getSupportedServiceNames_Static() 419*cdf0e10cSrcweir { 420*cdf0e10cSrcweir String[] aResult = { smServiceName, 421*cdf0e10cSrcweir "com.sun.star.chart.Diagram", 422*cdf0e10cSrcweir "com.sun.star.chart.ChartAxisYSupplier" }; 423*cdf0e10cSrcweir return aResult; 424*cdf0e10cSrcweir } 425*cdf0e10cSrcweir 426*cdf0e10cSrcweir 427*cdf0e10cSrcweir /** 428*cdf0e10cSrcweir * Returns a factory for creating the service. 429*cdf0e10cSrcweir * This method is called by the <code>JavaLoader</code> 430*cdf0e10cSrcweir * <p> 431*cdf0e10cSrcweir * @return returns a <code>XSingleServiceFactory</code> for creating the component 432*cdf0e10cSrcweir * @param implName the name of the implementation for which a service is desired 433*cdf0e10cSrcweir * @param multiFactory the service manager to be used if needed 434*cdf0e10cSrcweir * @param regKey the registryKey 435*cdf0e10cSrcweir * @see com.sun.star.comp.loader.JavaLoader 436*cdf0e10cSrcweir */ 437*cdf0e10cSrcweir public static XSingleServiceFactory __getServiceFactory( 438*cdf0e10cSrcweir String implName, 439*cdf0e10cSrcweir XMultiServiceFactory multiFactory, 440*cdf0e10cSrcweir com.sun.star.registry.XRegistryKey regKey ) 441*cdf0e10cSrcweir { 442*cdf0e10cSrcweir XSingleServiceFactory xSingleServiceFactory = null; 443*cdf0e10cSrcweir 444*cdf0e10cSrcweir if( implName.equals( JavaSampleChartAddIn.class.getName()) ) 445*cdf0e10cSrcweir { 446*cdf0e10cSrcweir xSingleServiceFactory = com.sun.star.comp.loader.FactoryHelper.getServiceFactory( 447*cdf0e10cSrcweir JavaSampleChartAddIn.class, smServiceName, 448*cdf0e10cSrcweir multiFactory, regKey ); 449*cdf0e10cSrcweir } 450*cdf0e10cSrcweir 451*cdf0e10cSrcweir return xSingleServiceFactory; 452*cdf0e10cSrcweir } 453*cdf0e10cSrcweir 454*cdf0e10cSrcweir /** 455*cdf0e10cSrcweir * Writes the service information into the given registry key. 456*cdf0e10cSrcweir * This method is called by the <code>JavaLoader</code> 457*cdf0e10cSrcweir * <p> 458*cdf0e10cSrcweir * @return returns true if the operation succeeded 459*cdf0e10cSrcweir * @param regKey the registryKey 460*cdf0e10cSrcweir * @see com.sun.star.comp.loader.JavaLoader 461*cdf0e10cSrcweir */ 462*cdf0e10cSrcweir // This method not longer necessary since OOo 3.4 where the component registration 463*cdf0e10cSrcweir // was changed to passive component registration. For more details see 464*cdf0e10cSrcweir // http://wiki.services.openoffice.org/wiki/Passive_Component_Registration 465*cdf0e10cSrcweir 466*cdf0e10cSrcweir // public static boolean __writeRegistryServiceInfo( com.sun.star.registry.XRegistryKey regKey ) 467*cdf0e10cSrcweir // { 468*cdf0e10cSrcweir // boolean bResult = true; 469*cdf0e10cSrcweir 470*cdf0e10cSrcweir // String[] aServices = getSupportedServiceNames_Static(); 471*cdf0e10cSrcweir // int i, nLength = aServices.length; 472*cdf0e10cSrcweir 473*cdf0e10cSrcweir // for( i = 0; i < nLength; ++i ) 474*cdf0e10cSrcweir // { 475*cdf0e10cSrcweir // bResult = bResult && com.sun.star.comp.loader.FactoryHelper.writeRegistryServiceInfo( 476*cdf0e10cSrcweir // JavaSampleChartAddIn.class.getName(), aServices[ i ], regKey ); 477*cdf0e10cSrcweir // } 478*cdf0e10cSrcweir // return bResult; 479*cdf0e10cSrcweir // } 480*cdf0e10cSrcweir } 481