📄 fsdefineshape.java
字号:
/*
* FSDefineShape.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.*;
/**
FSDefineShape defines a shape to be displayed.
<table class="datasheet">
<tr>
<th align="left" colspan="2">Attributes</th>
</tr>
<tr>
<td><a name="FSDefineShape_0">type</a></td>
<td>Identifies the data structure when it is encoded. Read-only.</td>
</tr>
<tr>
<td><a name="FSDefineShape_1">identifier</a></td>
<td>An unique identifier for this object, in the range 1..65535.</td>
</tr>
<tr>
<td><a name="FSDefineShape_2">bounds</a></td>
<td>The bounding area inside which the shape is drawn.</td>
</tr>
<tr>
<td><a name="FSDefineShape_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="FSDefineShape_4">lineStyles</a></td>
<td>An array of line styles used to draw the outline of the shape.</td>
</tr>
<tr>
<td><a name="FSDefineShape_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.</p>
<p>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 FSDefineShape class represents the DefineShape tag from the Macromedia Flash (SWF) File Format Specification. It was introduced in Flash 1.</p>
*/
public class FSDefineShape extends FSDefineObject
{
private FSBounds bounds = null;
private ArrayList fillStyles = null;
private ArrayList lineStyles = null;
private FSShape shape = null;
/**
* Construct an FSDefineShape object, initalizing it with values decoded
* from an encoded object.
*
* @param coder an FSCoder containing the binary data.
*/
public FSDefineShape(FSCoder coder)
{
super(FSMovieObject.DefineShape, 0);
decode(coder);
}
/** Constructs an FSDefineShape object.
@param anIdentifier the unique identifier for the shape in the range 1..65535.
@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 FSDefineShape(int anIdentifier, FSBounds aBounds, ArrayList fillStyleArray, ArrayList lineStyleArray, FSShape aShape)
{
super(FSMovieObject.DefineShape, 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 FSDefineShape(FSDefineShape 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.
@param anArray set the line styles for the shape.
*/
public void setLineStyles(ArrayList anArray)
{
lineStyles = anArray;
}
/** Sets the shape.
@param aShape set the shape to be drawn.
*/
public void setShape(FSShape aShape)
{
shape = aShape;
}
public Object clone()
{
FSDefineShape anObject = (FSDefineShape)super.clone();
anObject.bounds = (bounds != null) ? (FSBounds)bounds.clone() : null;
anObject.fillStyles = new ArrayList();
for (Iterator i = fillStyles.iterator(); i.hasNext();)
anObject.fillStyles.add(((FSFillStyle)i.next()).clone());
anObject.lineStyles = new ArrayList();
for (Iterator i = lineStyles.iterator(); i.hasNext();)
anObject.lineStyles.add(((FSLineStyle)i.next()).clone());
anObject.shape = (shape != null) ? (FSShape)shape.clone() : null;
return anObject;
}
public boolean equals(Object anObject)
{
boolean result = false;
if (super.equals(anObject))
{
FSDefineShape typedObject = (FSDefineShape)anObject;
if (bounds != null)
result = bounds.equals(typedObject.bounds);
else
result = bounds == typedObject.bounds;
if (fillStyles != null)
result = result && fillStyles.equals(typedObject.fillStyles);
else
result = result && fillStyles == typedObject.fillStyles;
if (lineStyles != null)
result = result && lineStyles.equals(typedObject.lineStyles);
else
result = result && lineStyles == typedObject.lineStyles;
if (shape != null)
result = result && shape.equals(typedObject.shape);
else
result = result && shape == typedObject.shape;
}
return result;
}
public void appendDescription(StringBuffer buffer, int depth)
{
buffer.append(name());
if (depth > 0)
{
buffer.append(": { ");
Transform.append(buffer, "bounds", bounds, depth);
Transform.append(buffer, "fillStyles", fillStyles, depth);
Transform.append(buffer, "lineStyles", lineStyles, depth);
Transform.append(buffer, "shape", shape, depth);
buffer.append("}");
}
}
public int length(FSCoder coder)
{
int numberOfFillBits = FSCoder.size(fillStyles.size(), false);
int numberOfLineBits = FSCoder.size(lineStyles.size(), false);
super.length(coder);
length += bounds.length(coder);
length += 1;
for (Iterator styleIterator = fillStyles.iterator(); styleIterator.hasNext();)
length += ((FSTransformObject)styleIterator.next()).length(coder);
length += 1;
for (Iterator styleIterator = lineStyles.iterator(); styleIterator.hasNext();)
length += ((FSTransformObject)styleIterator.next()).length(coder);
coder.context[FSCoder.NumberOfFillBits] = numberOfFillBits;
coder.context[FSCoder.NumberOfLineBits] = numberOfLineBits;
length += shape.length(coder);
coder.context[FSCoder.NumberOfFillBits] = 0;
coder.context[FSCoder.NumberOfLineBits] = 0;
return length;
}
public void encode(FSCoder coder)
{
int numberOfFillBits = FSCoder.size(fillStyles.size(), false);
int numberOfLineBits = FSCoder.size(lineStyles.size(), false);
super.encode(coder);
bounds.encode(coder);
coder.writeWord(fillStyles.size(), 1);
for (Iterator styleIterator = fillStyles.iterator(); styleIterator.hasNext();)
((FSTransformObject)styleIterator.next()).encode(coder);
coder.writeWord(lineStyles.size(), 1);
for (Iterator styleIterator = lineStyles.iterator(); styleIterator.hasNext();)
((FSTransformObject)styleIterator.next()).encode(coder);
coder.context[FSCoder.NumberOfFillBits] = numberOfFillBits;
coder.context[FSCoder.NumberOfLineBits] = numberOfLineBits;
shape.encode(coder);
coder.context[FSCoder.NumberOfFillBits] = 0;
coder.context[FSCoder.NumberOfLineBits] = 0;
coder.endObject(name());
}
public void decode(FSCoder coder)
{
int fillStyleCount = 0;
int lineStyleCount = 0;
super.decode(coder);
int start = coder.getPointer()-16; // account for identifier
bounds = new FSBounds(coder);
fillStyleCount = coder.readWord(1, false);
fillStyles = new ArrayList(fillStyleCount);
fillStyles = new ArrayList();
for (int i=0; i<fillStyleCount; i++)
{
switch (coder.scanWord(1, false))
{
case FSFillStyle.Solid:
fillStyles.add(new FSSolidFill(coder));
break;
case FSFillStyle.Linear:
fillStyles.add(new FSGradientFill(coder));
break;
case FSFillStyle.Radial:
fillStyles.add(new FSGradientFill(coder));
break;
case FSFillStyle.Tiled:
fillStyles.add(new FSBitmapFill(coder));
break;
case FSFillStyle.Clipped:
fillStyles.add(new FSBitmapFill(coder));
break;
case FSFillStyle.Unsmoothed_Tiled:
fillStyles.add(new FSBitmapFill(coder));
break;
case FSFillStyle.Unsmoothed_Clipped:
fillStyles.add(new FSBitmapFill(coder));
break;
default:
break;
}
}
lineStyleCount = coder.readWord(1, false);
lineStyles = new ArrayList(lineStyleCount);
for (int i=0; i<lineStyleCount; i++)
lineStyles.add(new FSSolidLine(coder));
int bytesDecoded = (coder.getPointer()-start) >> 3;
if (coder.context[FSCoder.DecodeShapes] == 1)
shape = new FSShape(coder);
else
shape = new FSShape(coder, length-bytesDecoded);
coder.endObject(name());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -