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