1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
7 * Copyright 2000, 2010 Oracle and/or its affiliates.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
31 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
32 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *************************************************************************/
36 // __________ Imports __________
38 import com
.sun
.star
.uno
.UnoRuntime
;
39 import com
.sun
.star
.lang
.XComponent
;
41 import com
.sun
.star
.beans
.PropertyValue
;
42 import com
.sun
.star
.beans
.XPropertySet
;
44 import com
.sun
.star
.drawing
.LineDash
;
45 import com
.sun
.star
.drawing
.XShape
;
46 import com
.sun
.star
.drawing
.XShapes
;
47 import com
.sun
.star
.drawing
.XDrawPage
;
49 import com
.sun
.star
.awt
.Gradient
;
50 import com
.sun
.star
.awt
.GradientStyle
;
51 import com
.sun
.star
.awt
.Point
;
52 import com
.sun
.star
.awt
.Size
;
55 // __________ Implementation __________
57 // FillStyle and LineStyle demo
59 public class FillAndLineStyleDemo
61 public static void main( String args
[] )
63 XComponent xDrawDoc
= null;
66 // get the remote office context of a running office (a new office
67 // instance is started if necessary)
68 com
.sun
.star
.uno
.XComponentContext xOfficeContext
= Helper
.connect();
70 // suppress Presentation Autopilot when opening the document
71 // properties are the same as described for
72 // com.sun.star.document.MediaDescriptor
73 PropertyValue
[] pPropValues
= new PropertyValue
[ 1 ];
74 pPropValues
[ 0 ] = new PropertyValue();
75 pPropValues
[ 0 ].Name
= "Silent";
76 pPropValues
[ 0 ].Value
= Boolean
.TRUE
;
78 xDrawDoc
= Helper
.createDocument( xOfficeContext
,
79 "private:factory/sdraw", "_blank", 0, pPropValues
);
81 XDrawPage xPage
= PageHelper
.getDrawPageByIndex( xDrawDoc
, 0 );
83 XShape xRectangle
= ShapeHelper
.createShape( xDrawDoc
,
85 new Size( 15000, 12000 ),
86 "com.sun.star.drawing.RectangleShape" );
88 XShapes xShapes
= UnoRuntime
.queryInterface( XShapes
.class, xPage
);
89 xShapes
.add( xRectangle
);
91 XPropertySet xPropSet
= UnoRuntime
.queryInterface( XPropertySet
.class, xRectangle
);
93 /* apply a gradient fill style that goes from top left to bottom
94 right and is changing its color from green to yellow */
95 xPropSet
.setPropertyValue( "FillStyle",
96 com
.sun
.star
.drawing
.FillStyle
.GRADIENT
);
97 Gradient aGradient
= new Gradient();
98 aGradient
.Style
= GradientStyle
.LINEAR
;
99 aGradient
.StartColor
= 0x00ff00;
100 aGradient
.EndColor
= 0xffff00;
101 aGradient
.Angle
= 450;
102 aGradient
.Border
= 0;
103 aGradient
.XOffset
= 0;
104 aGradient
.YOffset
= 0;
105 aGradient
.StartIntensity
= 100;
106 aGradient
.EndIntensity
= 100;
107 aGradient
.StepCount
= 10;
108 xPropSet
.setPropertyValue( "FillGradient", aGradient
);
110 /* create a blue line with dashes and dots */
111 xPropSet
.setPropertyValue( "LineStyle",
112 com
.sun
.star
.drawing
.LineStyle
.DASH
);
113 LineDash aLineDash
= new LineDash();
115 aLineDash
.DotLen
= 150;
116 aLineDash
.Dashes
= 3;
117 aLineDash
.DashLen
= 300;
118 aLineDash
.Distance
= 150;
119 xPropSet
.setPropertyValue( "LineDash", aLineDash
);
120 xPropSet
.setPropertyValue( "LineColor", Integer
.valueOf( 0x0000ff ) );
121 xPropSet
.setPropertyValue( "LineWidth", Integer
.valueOf( 200 ) );
124 catch( Exception ex
)
126 System
.out
.println( ex
);
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */