?? shape.java
字號:
/****************************************************************
* Copyright (c) 2001, David N. Main, All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* 2. 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.
*
* 3. The name of the author may not be used to endorse or
* promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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
* AUTHOR 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.anotherbigidea.flash.movie;
import java.io.*;
import java.util.*;
import com.anotherbigidea.flash.interfaces.*;
import com.anotherbigidea.flash.writers.*;
import com.anotherbigidea.flash.readers.*;
import com.anotherbigidea.flash.structs.*;
import com.anotherbigidea.flash.SWFConstants;
/**
* A Shape Symbol
*/
public class Shape extends Symbol
{
public abstract static class Element {}
public abstract static class Style extends Shape.Element
{
}
public abstract static class FillStyle extends Shape.Style
{
}
public static class ColorFill extends Shape.FillStyle
{
protected Color color;
/**
* @return may be Color or AlphaColor
*/
public Color getColor() { return color; }
public void setColor( Color color ) { this.color = color; }
public ColorFill( Color color )
{
this.color = color;
}
}
public static class ImageFill extends Shape.FillStyle
{
protected Symbol image;
protected Transform matrix;
protected boolean clipped;
public Symbol getImage() { return image; }
public Transform getTransform() { return matrix; }
public boolean isClipped() { return clipped; }
public void setImage( Symbol image ) { this.image = image; }
public void setTransform( Transform matrix ) { this.matrix = matrix; }
public void setClipped( boolean isClipped ) { clipped = isClipped; }
public ImageFill( Symbol image, Transform matrix, boolean isClipped )
{
this.image = image;
this.matrix = matrix;
this.clipped = isClipped;
}
}
public static class GradientFill extends Shape.FillStyle
{
protected Color[] colors;
protected int[] ratios;
protected Transform matrix;
protected boolean radial;
public Color[] getColors() { return colors; }
public Transform getTransform() { return matrix; }
public int[] getRatios() { return ratios; }
public boolean isRadial() { return radial; }
public void setColors( Color[] colors ) { this.colors = colors; }
public void setRatios( int[] ratios ) { this.ratios = ratios; }
public void setTransform( Transform matrix ) { this.matrix = matrix; }
public void setRadial( boolean isRadial ) { this.radial = isRadial; }
public GradientFill( Color[] colors, int[] ratios,
Transform matrix, boolean isRadial )
{
this.colors = colors;
this.matrix = matrix;
this.radial = isRadial;
this.ratios = ratios;
}
}
public static class LineStyle extends Shape.Style
{
protected double width;
protected Color color;
public double getWidth() { return width; }
public Color getColor() { return color; }
public void setWidth( double width ) { this.width = width; }
public void setColor( Color color ) { this.color = color; }
public LineStyle( double width, Color color )
{
this.width = width;
this.color = color;
}
}
public abstract static class SetStyle extends Shape.Element
{
protected int index;
public int getStyleIndex() { return index; }
public void setStyleIndex( int index ) { this.index = index; }
protected SetStyle( int index )
{
this.index = index;
}
}
public abstract static class SetFillStyle extends Shape.SetStyle
{
protected SetFillStyle( int index )
{
super( index );
}
}
public static class SetLeftFillStyle extends Shape.SetFillStyle
{
public SetLeftFillStyle( int index )
{
super( index );
}
}
public static class SetRightFillStyle extends Shape.SetFillStyle
{
public SetRightFillStyle( int index )
{
super( index );
}
}
public static class SetLineStyle extends Shape.SetStyle
{
public SetLineStyle( int index )
{
super( index );
}
}
public abstract static class Vector extends Shape.Element
{
protected double x, y;
public double getX() { return x; }
public double getY() { return y; }
public void setX( double x ) { this.x = x; }
public void setY( double y ) { this.y = y; }
protected Vector( double x, double y )
{
this.x = x;
this.y = y;
}
}
public static class Move extends Shape.Vector
{
public Move( double x, double y )
{
super( x, y );
}
}
public static class Line extends Shape.Vector
{
public Line( double x, double y )
{
super( x, y );
}
}
public static class Curve extends Shape.Vector
{
protected double cx, cy;
public double getControlX() { return cx; }
public double getControlY() { return cy; }
public void setControlX( double cx ) { this.cx = cx; }
public void setControlY( double cy ) { this.cy = cy; }
public Curve( double x, double y, double controlX, double controlY )
{
super( x, y );
this.cx = controlX;
this.cy = controlY;
}
}
protected ArrayList elements = new ArrayList();
protected double minX, maxX, minY, maxY; //bounding rectangle
protected boolean hasAlpha = false;
protected double maxLineWidth;
protected double currx, curry;
public Shape() {}
/**
* Get the bounding rectangle as a double[4] - (min-X,min-Y,max-X,max-Y)
*/
public double[] getBoundingRectangle()
{
return new double[] { minX, minY, maxX, maxY };
}
/**
* Set the bounding rectangle. This will be automatically calculated
* as the geometry vectors are defined and this rectangle will be enlarged
* if it does not contain all the vectors.
*/
public void setBoundingRectangle( double minx, double minY,
double maxX, double maxY )
{
this.minX = minX;
this.minY = minY;
this.maxX = maxX;
this.maxY = maxY;
}
/**
* Access the list of shape elements
* Each object is a subclass of Shape.Element
*/
public ArrayList getShapeElements()
{
return elements;
}
/**
* Define a line style
* @param color if null then black is assumed
*/
public void defineLineStyle( double width, Color color )
{
if( color == null ) color = new Color(0,0,0);
LineStyle style = new LineStyle( width, color );
if( maxLineWidth < width ) maxLineWidth = width;
if( color instanceof AlphaColor ) hasAlpha = true;
elements.add( style );
}
/**
* Define a color fill
* @param color if null then white is assumed
*/
public void defineFillStyle( Color color )
{
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -