1 /************************************************************************* 2 * 3 * The Contents of this file are made available subject to the terms of 4 * the BSD license. 5 * 6 * Copyright 2000, 2010 Oracle and/or its affiliates. 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 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. 20 * 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. 32 * 33 *************************************************************************/ 34 35 // __________ Imports __________ 36 37 // base classes 38 import com.sun.star.uno.XInterface; 39 import com.sun.star.uno.UnoRuntime; 40 import com.sun.star.lang.*; 41 42 // property access 43 import com.sun.star.beans.*; 44 45 // application specific classes 46 import com.sun.star.chart.*; 47 import com.sun.star.drawing.*; 48 import com.sun.star.text.XTextDocument; 49 50 import com.sun.star.table.CellRangeAddress; 51 import com.sun.star.frame.XModel; 52 import com.sun.star.frame.XController; 53 54 import com.sun.star.util.XNumberFormatsSupplier; 55 import com.sun.star.util.XNumberFormats; 56 57 // base graphics things 58 import com.sun.star.awt.Point; 59 import com.sun.star.awt.Size; 60 import com.sun.star.awt.Rectangle; 61 import com.sun.star.awt.FontWeight; 62 import com.sun.star.awt.FontRelief; 63 64 // Exceptions 65 import com.sun.star.uno.Exception; 66 import com.sun.star.uno.RuntimeException; 67 import com.sun.star.beans.UnknownPropertyException; 68 import com.sun.star.lang.IndexOutOfBoundsException; 69 import com.sun.star.util.MalformedNumberFormatException; 70 71 72 // __________ Implementation __________ 73 74 /** Test to create a writer document and insert an OLE Chart. 75 76 Be careful! This does not really work. The Writer currently has no 77 interface for dealing with OLE objects. You can add an OLE shape to the 78 Writer's drawing layer, but it is not treated correctly as OLE object. 79 Thus, you can not activate the chart by double-clicking. The office may 80 also crash when the document is closed! 81 82 @author Björn Milcke 83 */ 84 public class ChartInWriter 85 { 86 // ____________________ 87 88 public static void main( String args[] ) 89 { 90 Helper aHelper = new Helper( args ); 91 92 ChartHelper aChartHelper = new ChartHelper( 93 (XModel) UnoRuntime.queryInterface( XModel.class, 94 aHelper.createTextDocument())); 95 96 // the unit for measures is 1/100th of a millimeter 97 // position at (1cm, 1cm) 98 Point aPos = new Point( 1000, 1000 ); 99 100 // size of the chart is 15cm x 12cm 101 Size aExtent = new Size( 15000, 13000 ); 102 103 // insert a new chart into the "Chart" sheet of the 104 // spreadsheet document 105 XChartDocument aChartDoc = aChartHelper.insertOLEChartInWriter( 106 "BarChart", 107 aPos, 108 aExtent, 109 "com.sun.star.chart.AreaDiagram" ); 110 111 // instantiate test class with newly created chart 112 ChartInWriter aTest = new ChartInWriter( aChartDoc ); 113 114 try 115 { 116 aTest.lockControllers(); 117 118 // do tests here 119 aTest.testWall(); 120 121 aTest.unlockControllers(); 122 } 123 catch( Exception ex ) 124 { 125 System.out.println( "UNO Exception caught: " + ex ); 126 System.out.println( "Message: " + ex.getMessage() ); 127 } 128 129 System.exit( 0 ); 130 } 131 132 133 // ________________________________________ 134 135 public ChartInWriter( XChartDocument aChartDoc ) 136 { 137 maChartDocument = aChartDoc; 138 maDiagram = maChartDocument.getDiagram(); 139 } 140 141 // ____________________ 142 143 public void lockControllers() 144 throws RuntimeException 145 { 146 ((XModel) UnoRuntime.queryInterface( XModel.class, maChartDocument )).lockControllers(); 147 } 148 149 // ____________________ 150 151 public void unlockControllers() 152 throws RuntimeException 153 { 154 ((XModel) UnoRuntime.queryInterface( XModel.class, maChartDocument )).unlockControllers(); 155 } 156 157 // ____________________ 158 159 public void testWall() 160 throws RuntimeException, UnknownPropertyException, PropertyVetoException, 161 com.sun.star.lang.IllegalArgumentException, WrappedTargetException 162 { 163 XPropertySet aWall = ((X3DDisplay) UnoRuntime.queryInterface( 164 X3DDisplay.class, maDiagram )).getWall(); 165 166 // change background color of area 167 aWall.setPropertyValue( "FillColor", new Integer( 0xeecc99 )); 168 aWall.setPropertyValue( "FillStyle", FillStyle.SOLID ); 169 } 170 171 // ______________________________ 172 // 173 // private members 174 // ______________________________ 175 176 private XChartDocument maChartDocument; 177 private XDiagram maDiagram; 178 } 179