1 /*************************************************************************
3 * The Contents of this file are made available subject to the terms of
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *************************************************************************/
35 // __________ Imports __________
37 import com
.sun
.star
.uno
.UnoRuntime
;
38 import com
.sun
.star
.lang
.*;
41 import com
.sun
.star
.beans
.*;
43 // application specific classes
44 import com
.sun
.star
.chart
.*;
45 import com
.sun
.star
.drawing
.*;
46 import com
.sun
.star
.frame
.XModel
;
47 // base graphics things
48 import com
.sun
.star
.awt
.Point
;
49 import com
.sun
.star
.awt
.Size
;
51 import com
.sun
.star
.uno
.Exception
;
52 import com
.sun
.star
.uno
.RuntimeException
;
53 import com
.sun
.star
.beans
.UnknownPropertyException
;
56 // __________ Implementation __________
58 /** Test to create a writer document and insert an OLE Chart.
60 Be careful! This does not really work. The Writer currently has no
61 interface for dealing with OLE objects. You can add an OLE shape to the
62 Writer's drawing layer, but it is not treated correctly as OLE object.
63 Thus, you can not activate the chart by double-clicking. The office may
64 also crash when the document is closed!
67 public class ChartInWriter
71 public static void main( String args
[] )
73 Helper aHelper
= new Helper( args
);
75 ChartHelper aChartHelper
= new ChartHelper(
76 UnoRuntime
.queryInterface( XModel
.class,
77 aHelper
.createTextDocument()));
79 // the unit for measures is 1/100th of a millimeter
80 // position at (1cm, 1cm)
81 Point aPos
= new Point( 1000, 1000 );
83 // size of the chart is 15cm x 12cm
84 Size aExtent
= new Size( 15000, 13000 );
86 // insert a new chart into the "Chart" sheet of the
87 // spreadsheet document
88 XChartDocument aChartDoc
= aChartHelper
.insertOLEChartInWriter(
91 "com.sun.star.chart.AreaDiagram" );
93 // instantiate test class with newly created chart
94 ChartInWriter aTest
= new ChartInWriter( aChartDoc
);
98 aTest
.lockControllers();
103 aTest
.unlockControllers();
105 catch( Exception ex
)
107 System
.out
.println( "UNO Exception caught: " + ex
);
108 System
.out
.println( "Message: " + ex
.getMessage() );
117 public ChartInWriter( XChartDocument aChartDoc
)
119 maChartDocument
= aChartDoc
;
120 maDiagram
= maChartDocument
.getDiagram();
125 public void lockControllers()
126 throws RuntimeException
128 UnoRuntime
.queryInterface( XModel
.class, maChartDocument
).lockControllers();
133 public void unlockControllers()
134 throws RuntimeException
136 UnoRuntime
.queryInterface( XModel
.class, maChartDocument
).unlockControllers();
141 public void testWall()
142 throws RuntimeException
, UnknownPropertyException
, PropertyVetoException
,
143 com
.sun
.star
.lang
.IllegalArgumentException
, WrappedTargetException
145 XPropertySet aWall
= UnoRuntime
.queryInterface(
146 X3DDisplay
.class, maDiagram
).getWall();
148 // change background color of area
149 aWall
.setPropertyValue( "FillColor", Integer
.valueOf( 0xeecc99 ));
150 aWall
.setPropertyValue( "FillStyle", FillStyle
.SOLID
);
158 private final XChartDocument maChartDocument
;
159 private final XDiagram maDiagram
;