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