public class Flag
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
Flag.Alignment
The alignment of stripes or other design elements on the
flag.
|
static class |
Flag.Background
The "background layer" of the flag, generally one or several
squares or triangles of different color.
|
static class |
Flag.Decoration
The "middle layer" of the flag, generally a number of vertical,
horizontal or diagonal bars.
|
static class |
Flag.UnionPosition
The position of the "union", which depends on the alignment of
the background.
|
static class |
Flag.UnionShape
The shape of the "union", which generally depends on the
decoration or background of the flag.
|
Modifier and Type | Field and Description |
---|---|
private Flag.Background |
background |
private java.util.List<java.awt.Color> |
backgroundColors
If the background is striped, the background colors will be
used in turn, from top to bottom, or from left to right.
|
static double |
BEND_X |
static double |
BEND_Y |
static double |
CHEVRON_X |
static double |
CROSS_OFFSET
MAGIC NUMBER: the horizontal offset of the vertical bar of the
Scandinavian cross.
|
private Flag.Decoration |
decoration |
static double |
DECORATION_SIZE
MAGIC NUMBER: the width of decoration elements.
|
private java.awt.Color |
decorationColor |
static int |
HEIGHT |
private static int[][] |
layout
The distribution of stars in the "union", based on historical
flags of the United States.
|
static double |
SQRT_3 |
private static java.awt.geom.GeneralPath |
star |
static double |
STAR_SIZE
MAGIC NUMBER: the size of the stars in the union.
|
private java.awt.Color |
starColor |
private int |
stars
The number of stars in the union.
|
private int |
stripes
The number of background stripes.
|
private java.awt.Color |
unionColor |
private Flag.UnionPosition |
unionPosition |
private Flag.UnionShape |
unionShape |
static int |
WIDTH
Width and height are used in the usual sense, not the
vexillological sense.
|
Constructor and Description |
---|
Flag(Flag.Background background,
Flag.Decoration decoration,
Flag.UnionPosition unionPosition) |
Flag(Flag.Background background,
Flag.Decoration decoration,
Flag.UnionPosition unionPosition,
Flag.UnionShape unionShape) |
Modifier and Type | Method and Description |
---|---|
private void |
center(java.awt.geom.GeneralPath path,
double x,
double y)
Centers the given path on the given point (x,y).
|
private void |
drawBackground(java.awt.Graphics2D g) |
private void |
drawPerBend(java.awt.Graphics2D g,
boolean sinister) |
private void |
drawPerSaltire(java.awt.Graphics2D g) |
private void |
drawQuarters(java.awt.Graphics2D g) |
private void |
drawStripes(java.awt.Graphics2D g,
Flag.Alignment alignment,
int stripes) |
Flag.Background |
getBackground()
Returns the background of the flag.
|
java.util.List<java.awt.Color> |
getBackgroundColors()
Returns a
List of background colors. |
private java.awt.geom.GeneralPath |
getBend(boolean sinister) |
private java.awt.geom.GeneralPath |
getCircleOfStars(double radius)
Returns either a single star, or a circle of stars with the
given radius, centered at the origin.
|
private java.awt.geom.GeneralPath |
getCross(Flag.Decoration decoration) |
Flag.Decoration |
getDecoration()
Returns the decoration of the flag.
|
java.awt.Color |
getDecorationColor()
Returns the decoration color of the flag.
|
java.awt.geom.GeneralPath |
getGridOfStars(java.awt.geom.Rectangle2D.Double union) |
java.awt.image.BufferedImage |
getImage()
Generates an image of the flag.
|
private java.awt.geom.GeneralPath |
getPall() |
private java.awt.geom.Rectangle2D.Double |
getRectangle() |
private java.awt.geom.GeneralPath |
getRhombus() |
private static java.awt.geom.GeneralPath |
getStar()
Return the basic five-point star.
|
java.awt.geom.GeneralPath |
getStar(double x,
double y)
Returns a star at the given coordinates (x, y).
|
java.awt.geom.GeneralPath |
getStar(double scale,
double x,
double y)
Returns a star of the given scale at the given coordinates (x, y).
|
java.awt.Color |
getStarColor()
Returns the star color of the flag.
|
int |
getStars()
Returns the number of stars in the union.
|
private double |
getStripeHeight(Flag.Alignment alignment)
Calculate the height of stripes on the basis of the given
alignment.
|
int |
getStripes()
Returns the number of background stripes.
|
private double |
getStripeWidth(Flag.Alignment alignment)
Calculate the width of stripes on the basis of the given
alignment.
|
private java.awt.geom.GeneralPath |
getTriangle(Flag.UnionShape unionShape,
boolean small)
Returns a triangle of the given shape and size.
|
java.awt.Color |
getUnionColor()
Returns the union color of the flag.
|
Flag.UnionPosition |
getUnionPosition()
Returns the union position of the flag.
|
private java.awt.geom.GeneralPath |
getUnionRectangle(java.awt.geom.Rectangle2D.Double union)
Return the stars in a rectangular "union", distributed
according to rules derived from historical flags of the United
States.
|
private java.awt.geom.GeneralPath |
getUnionRhombus() |
Flag.UnionShape |
getUnionShape()
Returns the union shape of the flag.
|
private java.awt.geom.GeneralPath |
getUnionTriangle(boolean isosceles) |
Flag |
setBackground(Flag.Background background)
Sets the background of the flag and returns the flag itself.
|
Flag |
setBackgroundColors(java.awt.Color... colors)
Sets the background colors of the flag and returns the flag
itself.
|
Flag |
setBackgroundColors(java.util.List<java.awt.Color> backgroundColors)
Sets the background colors of the flag and returns the flag
itself.
|
Flag |
setDecoration(Flag.Decoration decoration)
Sets the decoration of the flag and returns the flag itself.
|
Flag |
setDecorationColor(java.awt.Color decorationColor)
Sets the decoration color of the flag and returns the flag
itself.
|
Flag |
setStarColor(java.awt.Color starColor)
Sets the star color of the flag and returns the flag itself.
|
Flag |
setStars(int stars)
Sets the number of stars in the union and returns the flag
itself.
|
Flag |
setStripes(int stripes)
Sets the number of background stripes and returns the flag
itself.
|
Flag |
setUnionColor(java.awt.Color unionColor)
Sets the union color of the flag and returns the flag itself.
|
Flag |
setUnionPosition(Flag.UnionPosition position)
Sets the union position of the flag and returns the flag
itself.
|
Flag |
setUnionShape(Flag.UnionShape shape)
Sets the union shape of the flag and returns the flag itself.
|
private java.awt.geom.GeneralPath |
transformBend(java.awt.geom.GeneralPath triangle)
Flip or rotate a top left triangle so that it fits another
corner.
|
private java.awt.geom.GeneralPath |
transformTriangle(java.awt.geom.GeneralPath triangle)
Flip or rotate a left triangle so that it fits another side.
|
public static final int WIDTH
public static final int HEIGHT
public static final double SQRT_3
public static final double DECORATION_SIZE
public static final double CHEVRON_X
public static final double STAR_SIZE
public static final double CROSS_OFFSET
public static final double BEND_X
public static final double BEND_Y
private static final java.awt.geom.GeneralPath star
private static final int[][] layout
private java.util.List<java.awt.Color> backgroundColors
private java.awt.Color unionColor
private java.awt.Color starColor
private java.awt.Color decorationColor
private Flag.Background background
private Flag.Decoration decoration
private Flag.UnionShape unionShape
private Flag.UnionPosition unionPosition
private int stars
private int stripes
public Flag(Flag.Background background, Flag.Decoration decoration, Flag.UnionPosition unionPosition)
public Flag(Flag.Background background, Flag.Decoration decoration, Flag.UnionPosition unionPosition, Flag.UnionShape unionShape)
public Flag.Background getBackground()
Background
value.public Flag setBackground(Flag.Background background)
background
- The new Background
value.public Flag.Decoration getDecoration()
Decoration
value.public Flag setDecoration(Flag.Decoration decoration)
decoration
- The new Decoration
value.public Flag.UnionPosition getUnionPosition()
UnionPosition
value.public Flag setUnionPosition(Flag.UnionPosition position)
position
- The new UnionPosition
value.public Flag.UnionShape getUnionShape()
UnionShape
value.public Flag setUnionShape(Flag.UnionShape shape)
shape
- The new UnionShape
value.public java.util.List<java.awt.Color> getBackgroundColors()
List
of background colors.List
of background colors.public Flag setBackgroundColors(java.util.List<java.awt.Color> backgroundColors)
backgroundColors
- A List
of background colors.public Flag setBackgroundColors(java.awt.Color... colors)
colors
- A variable number of background colors.public java.awt.Color getUnionColor()
Color
value.public Flag setUnionColor(java.awt.Color unionColor)
unionColor
- The new Color
value.public java.awt.Color getDecorationColor()
Color
value.public Flag setDecorationColor(java.awt.Color decorationColor)
decorationColor
- The new Color
value.public java.awt.Color getStarColor()
Color
value.public Flag setStarColor(java.awt.Color starColor)
starColor
- The new Color
value.public int getStars()
public Flag setStars(int stars)
stars
- The new number of stars.public int getStripes()
public Flag setStripes(int stripes)
stripes
- The new number of background stripes.public java.awt.image.BufferedImage getImage()
private java.awt.geom.GeneralPath getUnionRectangle(java.awt.geom.Rectangle2D.Double union)
union
- The rectangular area to fill.private java.awt.geom.GeneralPath getUnionTriangle(boolean isosceles)
private java.awt.geom.GeneralPath transformBend(java.awt.geom.GeneralPath triangle)
triangle
- The top left triangle.private java.awt.geom.GeneralPath transformTriangle(java.awt.geom.GeneralPath triangle)
triangle
- The left triangle.private java.awt.geom.GeneralPath getUnionRhombus()
private double getStripeWidth(Flag.Alignment alignment)
alignment
- The alignment of the stripes.private double getStripeHeight(Flag.Alignment alignment)
alignment
- The alignment of the stripes.private void drawBackground(java.awt.Graphics2D g)
private void drawStripes(java.awt.Graphics2D g, Flag.Alignment alignment, int stripes)
private void drawQuarters(java.awt.Graphics2D g)
private void drawPerBend(java.awt.Graphics2D g, boolean sinister)
private void drawPerSaltire(java.awt.Graphics2D g)
private java.awt.geom.GeneralPath getCross(Flag.Decoration decoration)
private java.awt.geom.GeneralPath getBend(boolean sinister)
private java.awt.geom.GeneralPath getPall()
private java.awt.geom.GeneralPath getTriangle(Flag.UnionShape unionShape, boolean small)
unionShape
- The shape of the union.small
- Whether the shape is limited by decorations.private java.awt.geom.GeneralPath getRhombus()
private java.awt.geom.Rectangle2D.Double getRectangle()
private static java.awt.geom.GeneralPath getStar()
public java.awt.geom.GeneralPath getStar(double x, double y)
x
- The x coordinate of the star.y
- The y coordinate of the star.public java.awt.geom.GeneralPath getStar(double scale, double x, double y)
scale
- The scale of the star.x
- The x coordinate of the star.y
- The y coordinate of the star.private void center(java.awt.geom.GeneralPath path, double x, double y)
path
- The path to center.x
- The x coordinate of the center.y
- The y coordinate of the center.private java.awt.geom.GeneralPath getCircleOfStars(double radius)
radius
- The radius of the circle.public java.awt.geom.GeneralPath getGridOfStars(java.awt.geom.Rectangle2D.Double union)