⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fsshapestyle.java

📁 利用opensource的开源jar实现生成flash文件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
 * FSShapeStyle.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.*;

/**
FSShapeStyle is used to change the drawing environment when a shape is drawn. 
 
<p>Three operations can be performed:</p>

<ul>
<li>Select a line style or fill style.</li>
<li>Move the current drawing point.</li>
<li>Define a new set of line and fill styles.</li>
</ul>

<p>An FSShapeStyle object can specify one or more of the operations rather than specifying them in separate FSShapeStyle objects - compacting the size of the binary data when the object is encoded. Conversely if an operation is not defined then the values may be omitted.</p>

<table class="datasheet">

<tr><th align="left" colspan="2">Attributes</th></tr>

<tr>
<td><a name="FSShapeStyle_0">lineStyle</a></td>
<td>The index of the line style in the parent shape's line style array. Optional. May be set to the framework constant Transform.VALUE_NOT_SET if no style is selected.</td>
</tr>

<tr>
<td><a name="FSShapeStyle_1">fillStyle</a></td>
<td>The index of the fill style in the parent shape's fill style array. Optional. May be set to the framework constant Transform.VALUE_NOT_SET if no style is selected.</td>
</tr>

<tr>
<td><a name="FSShapeStyle_2">altFillStyle</a></td>
<td>The index of the alternate fill style in the parent shape's fill style array. Optional. May be set to the framework constant Transform.VALUE_NOT_SET if no style is selected.</td>
</tr>

<tr>
<td><a name="FSShapeStyle_3">moveX</a></td>
<td>The absolute x-coordinate of the new drawing point. Optional. May be set to the framework constant Transform.VALUE_NOT_SET if the drawing point is not being moved.</td>
</tr>

<tr>
<td><a name="FSShapeStyle_4">moveY</a></td>
<td>The absolute y-coordinate of the new drawing point. Optional. May be set to the framework constant Transform.VALUE_NOT_SET if the drawing point is not being moved.</td>
</tr>

<tr>
<td><a name="FSShapeStyle_5">lineStyles</a></td>
<td>An array of new line styles for the parent shape. Optional. May be set to null or an empty array if no line or fill styles are being added.</td>
</tr>

<tr>
<td><a name="FSShapeStyle_6">fillStyles</a></td>
<td>An array of new fill styles for the parent shape. Optional. May be set to null or an empty array if no line or fill styles are being added.</td>
</tr>

</table>

<p>Line and Fill styles are selected by the index position, starting at 1, of the style in an array of styles. An index of zero means that no style is selected. Using the constant Transform.VALUE_NOT_SET means that the current style is unchanged. Two types of fill style are supported: fillStyle is used where a shape does not contain overlapping areas and altFillStyle is used where areas overlap. This differs from graphics environments that only support one fill style as the overlapping area would form a hole in the shape and not be filled.</p>

<p>In the following example, when a shape is drawn the fillStyle defines the style to the left of the line drawing the outline while the altFillStyle defines the style applied to the right of the outline.</p>

<img src="doc-files/fillStyles.gif">

<p>New fill and line styles can be added to the FSShapeStyle object to change the way shapes are drawn.</p>

<p>A new drawing point is specified using the absolute x and y coordinates. If an FSShapeStyle object is the first in a shape then the current drawing point is the origin of the shape (0,0).</p>

<h1 class="datasheet">Optional Attributes</h1>

<p>Since the FSShapeStyle object can encode three different types of operation, the unused attributes are optional. Setting line or fill styles to the framework constant Transform.VALUE_NOT_SET omits the attribute when the object is encoded - reduced the size.</p>

<p>For the line and fill styles setting the respective attribute to Transform.VALUE_NOT_SET is different from setting to zero. When the attribute is set to Transform.VALUE_NOT_SET attribute is not encoded. When the attribute is set to zero then that instructs the Flash Player that no current line or fill style is selected. The latter is important when filling areas of a shape that overlap - the altFillStyle attribute will be set to the desired style while the lineStyle and fillStyle attributes are set to zero.</p>

<p>Similarly moveX and moveY may be set to Transform.VALUE_NOT_SET to indicate that the current drawing point will not be changed.  This can also be achieved by setting moveX and moveY to zero. However using Transform.VALUE_NOT_SET means that the attributes are not encoded reducing the binary representation. For large files the savings can be significant.</p>

<p>The line or fill style arrays May be empty if no new styles are being specified.</p>

<p>Note that the values for the moveX and moveY attributes and the line and fill styles arrays are defined in pairs and are optional only if both are set to zero or NULL respectively.</p>

<h1 class="datasheet">Examples</h1>

<p>The class provides a range of constructors which define different subsets of the attributes according to the type of operation that will be performed. If an attribute is not specified in a constructor then it will be assigned the default value of Transform.VALUE_NOT_SET and will be omitted when the object is encoded.</p>

<p>1. Select line and fill styles.</p>

<pre>
FSDefineShape shape = new FSShape(movie.newIdentifier(), ...);

// Add fill styles to the shape definition

shape.add(new FSSolidFill(FSColor(0, 0, 255)));
shape.add(new FSBitmapFill(FSFillStyle.Tiled, imageId, transform));

// Add a line styles to the shape definition

shape.add(new FSSolidLine(20, FSColor(0, 0, 0)));

// Select the solid line style and the bitmap fill style. Note that the
// ordinal position of the styles is used. A style index of 0 means that
// style is not set.

shape.add(new FSShapeStyle(1, 2, 0));
</pre>

<p>2. Move the current drawing point.</p>

<p>The drawing point is changed by specifying the position from the current drawing point:</p>

<pre>
FSShapeStyle style = new FSShapeStyle(x, y);
</pre>

<p>3. Specifying New Styles.</p>

<p>Adding a new set of styles to an FSShapeStyle object will replace the existing set of styles defined for the shape.</p>

<pre>
FSDefineShape shape = new FSDefineShape(movie.newIdentifier(), bounds, fillStyles, lineStyles, shape);

// Replace the existing set of fill and line styles in the shape definition

ArrayList fillStyles = new ArrayList();
ArrayList lineStyles = new ArrayList();

fillStyles.add(new FSSolidFill(FSColor(255, 0, 0)));
fillStyles.add(new FSSolidFill(FSColor(0, 255, 0)));
fillStyles.add(new FSSolidFill(FSColor(0, 0, 255)));

lineStyles.add(new FSSolidLine(1, FSColor(0, 0, 0)));

shape.add(new FSShapeStyle(lineStyles, fillStyles));
</pre>

<p>4. Creating an overlapping shape.</p>

<pre>
// Create the bounding rectangle for the shape. Two rectangles 100 x 100 pixels 
// are drawn. The area overlap area is 50 x 50 pixels.

FSBounds bounds = new FSBounds(0, -50, 150, 100);

// Define the styles for the shape.

ArrayList fillStyles = new ArrayList();
ArrayList lineStyles = new ArrayList();

fillStyles.add(new FSSolidFill(new FSColor(255, 0, 0)));
fillStyles.add(new FSSolidFill(new FSColor(255, 255, 0)));
fillStyles.add(new FSSolidFill(new FSColor(16, 123, 255)));

lineStyles.add(new FSSolidLine(20, new FSColor(0, 0, 0)));

FSDefineShape shape = new FSDefineShape(movie.newIdentifier, bounds, fillStyles, lineStyles, new FSShape());
</pre>

<pre>
// To create the overlapping shape shown above the following styles 
// selections are made while the shape is drawn.

shape.add(new FSShapeStyle(1, 1, 0, 0, 0));
shape.add(new FSLine(50,0));
shape.add(new FSShapeStyle(1, 1, 3));
shape.add(new FSLine(0,50));
shape.add(new FSLine(50,0));
shape.add(new FSShapeStyle(1, 0, 2));
shape.add(new FSLine(50,0));
shape.add(new FSLine(0,-100));
shape.add(new FSLine(-100,0));
shape.add(new FSLine(0,50));
shape.add(new FSShapeStyle(1, 3, 2));
shape.add(new FSLine(50,0));
shape.add(new FSLine(0,50));
shape.add(new FSShapeStyle(1, 1, 0));
shape.add(new FSLine(0,50));
shape.add(new FSLine(-100,0));
shape.add(new FSLine(0,-100));
</pre>

<h1 class="datasheet">History</h1>

<p>The FSShapeStyle class represents the StyleChange record from the Macromedia Flash (SWF) File Format Specification. It was introduced in Flash 1.</p>
 */
public class FSShapeStyle extends FSTransformObject
{
    private int moveX = Transform.VALUE_NOT_SET;
    private int moveY = Transform.VALUE_NOT_SET;
    private int fillStyle = Transform.VALUE_NOT_SET;
    private int altFillStyle = Transform.VALUE_NOT_SET;
    private int lineStyle = Transform.VALUE_NOT_SET;
    private ArrayList fillStyles = null;
    private ArrayList lineStyles = null;

    /**
     * Construct an FSShapeStyle object, initalizing it with values decoded from
     * an encoded object.
     * 
     * @param coder an FSCoder containing the binary data.
     */
    public FSShapeStyle(FSCoder coder)
    {
        decode(coder);
    }
    /** Constructs an FSShapeStyle object, selecting the line and fill styles.

        @param lineStyleIndex selects the line style at lineStyleIndex in the line styles array of the parent FSShape object.
        @param fillStyleIndex selects the fill style at fillStyleIndex in the fill styles array of the parent FSShape object.
        @param altFillStyleIndex selects the alternate fill style at altFillStyleIndex in the fill styles array of the parent FSShape object.
        */
    public FSShapeStyle(int lineStyleIndex, int fillStyleIndex, int altFillStyleIndex)
    {
        setLineStyle(lineStyleIndex);
        setFillStyle(fillStyleIndex);
        setAltFillStyle(altFillStyleIndex);
    }
    /** Constructs an FSShapeStyle object, selecting the relative drawing point.

        @param relativeX move the current point by relativeX in the x direction.
        @param relativeY move the current point by relativeY in the y direction.
        */
    public FSShapeStyle(int relativeX, int relativeY)
    {
        setMoveX(relativeX);
        setMoveY(relativeY);
    }
    /** Constructs an FSShapeStyle object, specifying the new set of line and fill styles for the parent shape.

        @param lineStylesArray an array of FSLineStyle objects.
        @param fillStylesArray an array of fill style objects.
        */
    public FSShapeStyle(ArrayList lineStylesArray, ArrayList fillStylesArray)
    {
        setLineStyles(lineStylesArray);
        setFillStyles(fillStylesArray);
    }

    /** Constructs an FSShapeStyle object, selecting the line and fill styles and drawing point.

        @param lineStyleIndex selects the line style at lineStyleIndex in the line styles array of the parent FSShape object.
        @param fillStyleIndex selects the fill style at fillStyleIndex in the fill styles array of the parent FSShape object.
        @param altFillStyleIndex selects the alternate fill style at altFillStyleIndex in the fill styles array of the parent FSShape object.
        @param relativeX move the current point by relativeX in the x direction.
        @param relativeY move the current point by relativeY in the y direction.
        */
    public FSShapeStyle(int lineStyleIndex, int fillStyleIndex, int altFillStyleIndex, int relativeX, int relativeY)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -