diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
commit | 940b4d1848e8c70ab7642901a68594e8016caffc (patch) | |
tree | eb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /odk/examples/DevelopersGuide/Charts/ChartInWriter.java | |
parent | Initial commit. (diff) | |
download | libreoffice-upstream/1%7.0.4.tar.xz libreoffice-upstream/1%7.0.4.zip |
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'odk/examples/DevelopersGuide/Charts/ChartInWriter.java')
-rw-r--r-- | odk/examples/DevelopersGuide/Charts/ChartInWriter.java | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/odk/examples/DevelopersGuide/Charts/ChartInWriter.java b/odk/examples/DevelopersGuide/Charts/ChartInWriter.java new file mode 100644 index 000000000..b84404d8b --- /dev/null +++ b/odk/examples/DevelopersGuide/Charts/ChartInWriter.java @@ -0,0 +1,163 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +// __________ Imports __________ + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.lang.*; + +// property access +import com.sun.star.beans.*; + +// application specific classes +import com.sun.star.chart.*; +import com.sun.star.drawing.*; +import com.sun.star.frame.XModel; +// base graphics things +import com.sun.star.awt.Point; +import com.sun.star.awt.Size; +// Exceptions +import com.sun.star.uno.Exception; +import com.sun.star.uno.RuntimeException; +import com.sun.star.beans.UnknownPropertyException; + + +// __________ Implementation __________ + +/** Test to create a writer document and insert an OLE Chart. + + Be careful! This does not really work. The Writer currently has no + interface for dealing with OLE objects. You can add an OLE shape to the + Writer's drawing layer, but it is not treated correctly as OLE object. + Thus, you can not activate the chart by double-clicking. The office may + also crash when the document is closed! + + */ +public class ChartInWriter +{ + + + public static void main( String args[] ) + { + Helper aHelper = new Helper( args ); + + ChartHelper aChartHelper = new ChartHelper( + UnoRuntime.queryInterface( XModel.class, + aHelper.createTextDocument())); + + // the unit for measures is 1/100th of a millimeter + // position at (1cm, 1cm) + Point aPos = new Point( 1000, 1000 ); + + // size of the chart is 15cm x 12cm + Size aExtent = new Size( 15000, 13000 ); + + // insert a new chart into the "Chart" sheet of the + // spreadsheet document + XChartDocument aChartDoc = aChartHelper.insertOLEChartInWriter( + aPos, + aExtent, + "com.sun.star.chart.AreaDiagram" ); + + // instantiate test class with newly created chart + ChartInWriter aTest = new ChartInWriter( aChartDoc ); + + try + { + aTest.lockControllers(); + + // do tests here + aTest.testWall(); + + aTest.unlockControllers(); + } + catch( Exception ex ) + { + System.out.println( "UNO Exception caught: " + ex ); + System.out.println( "Message: " + ex.getMessage() ); + } + + System.exit( 0 ); + } + + + + + public ChartInWriter( XChartDocument aChartDoc ) + { + maChartDocument = aChartDoc; + maDiagram = maChartDocument.getDiagram(); + } + + + + public void lockControllers() + throws RuntimeException + { + UnoRuntime.queryInterface( XModel.class, maChartDocument ).lockControllers(); + } + + + + public void unlockControllers() + throws RuntimeException + { + UnoRuntime.queryInterface( XModel.class, maChartDocument ).unlockControllers(); + } + + + + public void testWall() + throws RuntimeException, UnknownPropertyException, PropertyVetoException, + com.sun.star.lang.IllegalArgumentException, WrappedTargetException + { + XPropertySet aWall = UnoRuntime.queryInterface( + X3DDisplay.class, maDiagram ).getWall(); + + // change background color of area + aWall.setPropertyValue( "FillColor", Integer.valueOf( 0xeecc99 )); + aWall.setPropertyValue( "FillStyle", FillStyle.SOLID ); + } + + + + // private members + + + private final XChartDocument maChartDocument; + private final XDiagram maDiagram; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |