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 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.lang.XComponent;
39 
40 import com.sun.star.beans.PropertyValue;
41 import com.sun.star.beans.XPropertySet;
42 
43 import com.sun.star.drawing.LineDash;
44 import com.sun.star.drawing.XShape;
45 import com.sun.star.drawing.XShapes;
46 import com.sun.star.drawing.XDrawPage;
47 
48 import com.sun.star.awt.Gradient;
49 import com.sun.star.awt.GradientStyle;
50 import com.sun.star.awt.Point;
51 import com.sun.star.awt.Size;
52 
53 
54 // __________ Implementation __________
55 
56 /** FillStyle and LineStyle demo
57     @author Sven Jacobi
58  */
59 
60 public class FillAndLineStyleDemo
61 {
62     public static void main( String args[] )
63     {
64 		XComponent xDrawDoc = null;
65 		try
66 		{
67             // get the remote office context of a running office (a new office
68             // instance is started if necessary)
69 			com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect();
70 
71 			// suppress Presentation Autopilot when opening the document
72 			// properties are the same as described for
73 			// com.sun.star.document.MediaDescriptor
74 			PropertyValue[] pPropValues = new PropertyValue[ 1 ];
75 			pPropValues[ 0 ] = new PropertyValue();
76 			pPropValues[ 0 ].Name = "Silent";
77 			pPropValues[ 0 ].Value = new Boolean( true );
78 
79 			xDrawDoc = Helper.createDocument( xOfficeContext,
80 				"private:factory/sdraw", "_blank", 0, pPropValues );
81 
82 			XDrawPage xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 );
83 
84 			XShape xRectangle = ShapeHelper.createShape( xDrawDoc,
85 				new Point( 0, 0 ),
86 					new Size( 15000, 12000 ),
87 						"com.sun.star.drawing.RectangleShape" );
88 
89 			XShapes xShapes = (XShapes)
90 					UnoRuntime.queryInterface( XShapes.class, xPage );
91 			xShapes.add( xRectangle );
92 
93 			XPropertySet xPropSet = (XPropertySet)
94 				UnoRuntime.queryInterface( XPropertySet.class, xRectangle );
95 
96 			/* apply a gradient fill style that goes from top left to bottom
97 			   right and is changing its color from green to yellow */
98 			xPropSet.setPropertyValue( "FillStyle",
99                                        com.sun.star.drawing.FillStyle.GRADIENT );
100 			Gradient aGradient = new Gradient();
101 			aGradient.Style = GradientStyle.LINEAR;
102 			aGradient.StartColor = 0x00ff00;
103 			aGradient.EndColor = 0xffff00;
104 			aGradient.Angle = 450;
105 			aGradient.Border = 0;
106 			aGradient.XOffset = 0;
107 			aGradient.YOffset = 0;
108 			aGradient.StartIntensity = 100;
109 			aGradient.EndIntensity = 100;
110 			aGradient.StepCount = 10;
111 			xPropSet.setPropertyValue( "FillGradient", aGradient );
112 
113 			/* create a blue line with dashes and dots */
114 			xPropSet.setPropertyValue( "LineStyle",
115                                        com.sun.star.drawing.LineStyle.DASH );
116 			LineDash aLineDash = new LineDash();
117 			aLineDash.Dots = 3;
118 			aLineDash.DotLen = 150;
119 			aLineDash.Dashes = 3;
120 			aLineDash.DashLen = 300;
121 			aLineDash.Distance = 150;
122 			xPropSet.setPropertyValue( "LineDash", aLineDash );
123 			xPropSet.setPropertyValue( "LineColor", new Integer( 0x0000ff ) );
124 			xPropSet.setPropertyValue( "LineWidth", new Integer( 200 ) );
125 
126 		}
127 		catch( Exception ex )
128 		{
129             System.out.println( ex );
130 		}
131 		System.exit( 0 );
132     }
133 }
134