1*34dd1e25SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*34dd1e25SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*34dd1e25SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*34dd1e25SAndrew Rist * distributed with this work for additional information 6*34dd1e25SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*34dd1e25SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*34dd1e25SAndrew Rist * "License"); you may not use this file except in compliance 9*34dd1e25SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*34dd1e25SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*34dd1e25SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*34dd1e25SAndrew Rist * software distributed under the License is distributed on an 15*34dd1e25SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*34dd1e25SAndrew Rist * KIND, either express or implied. See the License for the 17*34dd1e25SAndrew Rist * specific language governing permissions and limitations 18*34dd1e25SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*34dd1e25SAndrew Rist *************************************************************/ 21*34dd1e25SAndrew Rist 22*34dd1e25SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // __________ Imports __________ 25cdf0e10cSrcweir 26cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 27cdf0e10cSrcweir import com.sun.star.lang.XComponent; 28cdf0e10cSrcweir 29cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 30cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 31cdf0e10cSrcweir 32cdf0e10cSrcweir import com.sun.star.drawing.LineDash; 33cdf0e10cSrcweir import com.sun.star.drawing.XShape; 34cdf0e10cSrcweir import com.sun.star.drawing.XShapes; 35cdf0e10cSrcweir import com.sun.star.drawing.XDrawPage; 36cdf0e10cSrcweir 37cdf0e10cSrcweir import com.sun.star.awt.Gradient; 38cdf0e10cSrcweir import com.sun.star.awt.GradientStyle; 39cdf0e10cSrcweir import com.sun.star.awt.Point; 40cdf0e10cSrcweir import com.sun.star.awt.Size; 41cdf0e10cSrcweir 42cdf0e10cSrcweir 43cdf0e10cSrcweir // __________ Implementation __________ 44cdf0e10cSrcweir 45cdf0e10cSrcweir /** FillStyle and LineStyle demo 46cdf0e10cSrcweir @author Sven Jacobi 47cdf0e10cSrcweir */ 48cdf0e10cSrcweir 49cdf0e10cSrcweir public class FillAndLineStyleDemo 50cdf0e10cSrcweir { main( String args[] )51cdf0e10cSrcweir public static void main( String args[] ) 52cdf0e10cSrcweir { 53cdf0e10cSrcweir XComponent xDrawDoc = null; 54cdf0e10cSrcweir try 55cdf0e10cSrcweir { 56cdf0e10cSrcweir // get the remote office context of a running office (a new office 57cdf0e10cSrcweir // instance is started if necessary) 58cdf0e10cSrcweir com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect(); 59cdf0e10cSrcweir 60cdf0e10cSrcweir // suppress Presentation Autopilot when opening the document 61cdf0e10cSrcweir // properties are the same as described for 62cdf0e10cSrcweir // com.sun.star.document.MediaDescriptor 63cdf0e10cSrcweir PropertyValue[] pPropValues = new PropertyValue[ 1 ]; 64cdf0e10cSrcweir pPropValues[ 0 ] = new PropertyValue(); 65cdf0e10cSrcweir pPropValues[ 0 ].Name = "Silent"; 66cdf0e10cSrcweir pPropValues[ 0 ].Value = new Boolean( true ); 67cdf0e10cSrcweir 68cdf0e10cSrcweir xDrawDoc = Helper.createDocument( xOfficeContext, 69cdf0e10cSrcweir "private:factory/sdraw", "_blank", 0, pPropValues ); 70cdf0e10cSrcweir 71cdf0e10cSrcweir XDrawPage xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); 72cdf0e10cSrcweir 73cdf0e10cSrcweir XShape xRectangle = ShapeHelper.createShape( xDrawDoc, 74cdf0e10cSrcweir new Point( 0, 0 ), 75cdf0e10cSrcweir new Size( 15000, 12000 ), 76cdf0e10cSrcweir "com.sun.star.drawing.RectangleShape" ); 77cdf0e10cSrcweir 78cdf0e10cSrcweir XShapes xShapes = (XShapes) 79cdf0e10cSrcweir UnoRuntime.queryInterface( XShapes.class, xPage ); 80cdf0e10cSrcweir xShapes.add( xRectangle ); 81cdf0e10cSrcweir 82cdf0e10cSrcweir XPropertySet xPropSet = (XPropertySet) 83cdf0e10cSrcweir UnoRuntime.queryInterface( XPropertySet.class, xRectangle ); 84cdf0e10cSrcweir 85cdf0e10cSrcweir /* apply a gradient fill style that goes from top left to bottom 86cdf0e10cSrcweir right and is changing its color from green to yellow */ 87cdf0e10cSrcweir xPropSet.setPropertyValue( "FillStyle", 88cdf0e10cSrcweir com.sun.star.drawing.FillStyle.GRADIENT ); 89cdf0e10cSrcweir Gradient aGradient = new Gradient(); 90cdf0e10cSrcweir aGradient.Style = GradientStyle.LINEAR; 91cdf0e10cSrcweir aGradient.StartColor = 0x00ff00; 92cdf0e10cSrcweir aGradient.EndColor = 0xffff00; 93cdf0e10cSrcweir aGradient.Angle = 450; 94cdf0e10cSrcweir aGradient.Border = 0; 95cdf0e10cSrcweir aGradient.XOffset = 0; 96cdf0e10cSrcweir aGradient.YOffset = 0; 97cdf0e10cSrcweir aGradient.StartIntensity = 100; 98cdf0e10cSrcweir aGradient.EndIntensity = 100; 99cdf0e10cSrcweir aGradient.StepCount = 10; 100cdf0e10cSrcweir xPropSet.setPropertyValue( "FillGradient", aGradient ); 101cdf0e10cSrcweir 102cdf0e10cSrcweir /* create a blue line with dashes and dots */ 103cdf0e10cSrcweir xPropSet.setPropertyValue( "LineStyle", 104cdf0e10cSrcweir com.sun.star.drawing.LineStyle.DASH ); 105cdf0e10cSrcweir LineDash aLineDash = new LineDash(); 106cdf0e10cSrcweir aLineDash.Dots = 3; 107cdf0e10cSrcweir aLineDash.DotLen = 150; 108cdf0e10cSrcweir aLineDash.Dashes = 3; 109cdf0e10cSrcweir aLineDash.DashLen = 300; 110cdf0e10cSrcweir aLineDash.Distance = 150; 111cdf0e10cSrcweir xPropSet.setPropertyValue( "LineDash", aLineDash ); 112cdf0e10cSrcweir xPropSet.setPropertyValue( "LineColor", new Integer( 0x0000ff ) ); 113cdf0e10cSrcweir xPropSet.setPropertyValue( "LineWidth", new Integer( 200 ) ); 114cdf0e10cSrcweir 115cdf0e10cSrcweir } 116cdf0e10cSrcweir catch( Exception ex ) 117cdf0e10cSrcweir { 118cdf0e10cSrcweir System.out.println( ex ); 119cdf0e10cSrcweir } 120cdf0e10cSrcweir System.exit( 0 ); 121cdf0e10cSrcweir } 122cdf0e10cSrcweir } 123