📄 fsdefineshape2.java
字号:
/*
* FSDefineShape2.java
* Transform
*
* Copyright (c) 2001-2006 Flagstone Software Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of Flagstone Software Ltd. nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.flagstone.transform;
import java.util.*;
/**
FSDefineShape2 defines a shape to be displayed.
<p>It extends the functionality of the FSDefineShape class by allowing more than 255 fill or line styles to be specified.</p>
<table class="datasheet">
<tr><th align="left" colspan="2">Attributes</th></tr>
<tr><td><a name="FSDefineShape2_0">type</a></td>
<td>Identifies the data structure when it is encoded. Read-only.</td>
</tr>
<tr>
<td><a name="FSDefineShape2_1">identifier</a></td>
<td>An unique identifier for this object, in the range 1..65535.</td>
</tr>
<tr>
<td><a name="FSDefineShape2_2">bounds</a></td>
<td>The bounding area inside which the shape is drawn.</td>
</tr>
<tr>
<td><a name="FSDefineShape2_3">fillStyles</a></td>
<td>An array of fill styles used to fill the area enclosed by the shape.</td></tr>
<tr>
<td><a name="FSDefineShape2_4">lineStyles</a></td>
<td>An array of line styles used to draw the outline of the shape.</td>
</tr>
<tr><td><a name="FSDefineShape2_5">shape</a></td>
<td>An FSShape object containing the shape records (FSLine, FSCurve and FSShapeStyle
objects) that describe how the shape is drawn and filled shape.</td>
</tr>
</table>
<p>The shape defines a path containing a mix of straight and curved edges and pen
move actions. A path need not be contiguous. When the shape is drawn the FSShapeStyle
object selects the line and fill styles, from the respective array, to be used.
FSShapeStyle objects can be defined in the shape at any time to change the styles
being used. The fill style used can either be a solid colour, a bitmap image or a
gradient. The line style specifies the colour and thickness of the line drawn around
the shape outline. For both line and fill styles the selected style may be undefined,
allowing the shape to be drawn without an outline or left unfilled.</p>
<h1 class="datasheet">Examples</h1>
<p>This example creates a simple rectangle, 200 twips wide and 100 twips high, drawing using a black outline 1 twip wide and filled with a solid red colour. The origin of the shape is at the bottom left corner of the rectangle.</p>
<pre>
// Create the bounding rectangle for the shape. The values also specify
// the coordinate range of the shape.
FSBounds bounds = new FSBounds(0, 0, 200, 100);
// Define the styles for the shape.
ArrayList fillStyles = new ArrayList();
ArrayList lineStyles = new ArrayList();
fillStyles.add(new FSSolidFill(new FSColor(255, 0, 0)));
lineStyles.add(new FSSolidLine(1, new FSColor(0, 0, 0)));
// Draw the shape.
FSShape shape = new FSShape();
// Define the line, fill styles and move to the shape's origin.
shape.add(new FSShapeStyle(1, 1, 0, 0, 0));
shape.add(new FSLine(200,0));
shape.add(new FSLine(0,100));
shape.add(new FSLine(-200,0));
shape.add(new FSLine(0,-100));
FSDefineShape shape = new FSDefineShape(movie.newIdentifier(), bounds, fillStyles, lineStyles, shape);
</pre>
<h1 class="datasheet">History</h1>
<p>The FSDefineShape2 class represents the DefineShape2 data structure from the Macromedia Flash (SWF) File Format Specification. It was introduced in Flash 2.</p>
*/
public class FSDefineShape2 extends FSDefineObject
{
private FSBounds bounds = null;
private ArrayList fillStyles = null;
private ArrayList lineStyles = null;
private FSShape shape = null;
/**
* Construct an FSDefineShape2 object, initalizing it with values decoded
* from an encoded object.
*
* @param coder an FSCoder containing the binary data.
*/
public FSDefineShape2(FSCoder coder)
{
super(DefineShape2, 0);
decode(coder);
}
/** Constructs an FSDefineShape2 object.
@param anIdentifier the unique identifier for the shape.
@param aBounds the bounding rectangle for the shape.
@param fillStyleArray the array of fill styles used in the shape.
@param lineStyleArray the array of line styles used in the shape.
@param aShape the shape to be drawn.
*/
public FSDefineShape2(int anIdentifier, FSBounds aBounds, ArrayList fillStyleArray, ArrayList lineStyleArray, FSShape aShape)
{
super(DefineShape2, anIdentifier);
setBounds(aBounds);
setFillStyles(fillStyleArray);
setLineStyles(lineStyleArray);
setShape(aShape);
}
/**
* Constructs an FSDefineShape object by copying values from an existing
* object.
*
* @param obj an FSDefineShape object.
*/
public FSDefineShape2(FSDefineShape2 obj)
{
super(obj);
bounds = new FSBounds(obj.bounds);
fillStyles = new ArrayList();
for (Iterator i = obj.fillStyles.iterator(); i.hasNext();)
fillStyles.add(((FSFillStyle)i.next()).clone());
lineStyles = new ArrayList();
for (Iterator i = obj.lineStyles.iterator(); i.hasNext();)
lineStyles.add(((FSLineStyle)i.next()).clone());
shape = new FSShape(obj.shape);
}
/** Add a FSSolidLine object to the array of line styles.
@param aLineStyle and FSSolidLine object.
*/
public void add(FSLineStyle aLineStyle)
{
lineStyles.add(aLineStyle);
}
/** Add the fill style object to the array of fill styles.
@param aFillStyle and FSFillStyle object.
*/
public void add(FSFillStyle aFillStyle)
{
fillStyles.add(aFillStyle);
}
/** Gets the bounding rectangle for the shape.
@return the bounding rectangle for the shape.
*/
public FSBounds getBounds() { return bounds; }
/** Gets the array fill styles.
@return the fill styles used in the shape.
*/
public ArrayList getFillStyles() { return fillStyles; }
/** Gets the array line styles.
@return the line styles used in the shape.
*/
public ArrayList getLineStyles() { return lineStyles; }
/** Gets the shape.
@return the shape to be drawn.
*/
public FSShape getShape() { return shape; }
/** Sets the bounding rectangle.
@param aBounds set the bounding rectangle for the shape.
*/
public void setBounds(FSBounds aBounds)
{
bounds = aBounds;
}
/** Sets the fill styles.
@param anArray set the fill styles for the shape.
*/
public void setFillStyles(ArrayList anArray)
{
fillStyles = anArray;
}
/** Sets the line styles.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -