Package ca.ualberta.stothard.cgview
Class Legend
java.lang.Object
ca.ualberta.stothard.cgview.Legend
- All Implemented Interfaces:
CgviewConstants
This class is used add legends to a Cgview map. Individual legend entries are represented using
the
LegendItem
class.- Author:
- Paul Stothard
-
Field Summary
Fields inherited from interface ca.ualberta.stothard.cgview.CgviewConstants
BASES, BOUNDS_BUTTON, BOUNDS_FEATURE, BOUNDS_RULER, CENTISOMES, DECORATION_CLOCKWISE_ARROW, DECORATION_COUNTERCLOCKWISE_ARROW, DECORATION_HIDDEN, DECORATION_STANDARD, DIRECT_STRAND, INNER_LABELS_AUTO, INNER_LABELS_NO_SHOW, INNER_LABELS_SHOW, LABEL, LABEL_FORCE, LABEL_NONE, LABEL_ZOOMED, LEGEND_DRAW_ZOOMED, LEGEND_ITEM_ALIGN_CENTER, LEGEND_ITEM_ALIGN_LEFT, LEGEND_ITEM_ALIGN_RIGHT, LEGEND_LOWER_CENTER, LEGEND_LOWER_LEFT, LEGEND_LOWER_RIGHT, LEGEND_MIDDLE_CENTER, LEGEND_MIDDLE_LEFT, LEGEND_MIDDLE_LEFT_OF_CENTER, LEGEND_MIDDLE_RIGHT, LEGEND_MIDDLE_RIGHT_OF_CENTER, LEGEND_NO_DRAW_ZOOMED, LEGEND_UPPER_CENTER, LEGEND_UPPER_LEFT, LEGEND_UPPER_RIGHT, POSITIONS_AUTO, POSITIONS_NO_SHOW, POSITIONS_SHOW, REVERSE_STRAND, SWATCH_NO_SHOW, SWATCH_SHOW
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
addLegendItem
(LegendItem legendItem) Adds a LegendItem object to this Legend.protected void
draw()
Draws the contents of this Legend.int
Returns the alignment of legendItems in this Legend.boolean
Returns whether or not feature labels are allowed to clash with this Legend.Returns the color of the background of this Legend when drawn.float
Returns the opacity of the background of this Legend when drawn.protected Rectangle2D
Returns the bounds of this Legend.int
Returns whether or not this Legend is drawn when a zoomed Cgview map is generated.getFont()
Returns the font used for text in this Legend.Returns the default color that will be used for the text in this Legend.int
Returns the position of this Legend relative to the Cgview map canvas.protected double
Returns the height that is suitable for any LegendItem swatches drawn in this Legend.protected double
getWidestLegendItem
(double swatchWidth) Returns the width of the widest LegendItem in this Legend.void
setAlignment
(int textAlignment) Sets the alignment of the LegendItems in this Legend.void
setAllowLabelClash
(boolean allowClash) Sets whether or not feature labels are allowed to clash with this Legend.void
setBackgroundColor
(Color color) Sets the color of the background of this Legend when drawn.void
setBackgroundOpacity
(float opacity) Sets the opacity of the background of this Legend when drawn.protected void
Calculates the bounds of this Legend.protected void
setBounds
(double cgviewCenterX, double cgviewCenterY) Calculates the bounds of this Legend.void
setDrawWhenZoomed
(int drawWhenZoomed) Sets whether or not this Legend is drawn when a zoomed Cgview map is generated.void
Sets the font used for text in this Legend.void
setFontColor
(Color fontColor) Sets the default color that will be used for the text in this Legend.void
setPosition
(int position) Sets the position of this Legend relative to the Cgview map canvas.
-
Field Details
-
PADDING
protected static final double PADDING- See Also:
-
-
Constructor Details
-
Legend
Constructs a new Legend object.- Parameters:
cgview
- the Cgview object to contain this Legend.
-
-
Method Details
-
addLegendItem
Adds a LegendItem object to this Legend.- Parameters:
legendItem
- the LegendItem object to add to this Legend.
-
draw
protected void draw()Draws the contents of this Legend. -
getBounds
Returns the bounds of this Legend. -
setBounds
protected void setBounds()Calculates the bounds of this Legend. -
setBounds
protected void setBounds(double cgviewCenterX, double cgviewCenterY) Calculates the bounds of this Legend. -
getWidestLegendItem
protected double getWidestLegendItem(double swatchWidth) Returns the width of the widest LegendItem in this Legend. -
getSwatchHeight
protected double getSwatchHeight()Returns the height that is suitable for any LegendItem swatches drawn in this Legend. -
setFontColor
Sets the default color that will be used for the text in this Legend. This color can be changed for individual LegendItem objects usingLegendItem.setFontColor()
.- Parameters:
fontColor
- the default text color for the text in this Legend.
-
getFontColor
Returns the default color that will be used for the text in this Legend. This color can be changed for individual LegendItem objects usingLegendItem.setFontColor(Color)
.- Returns:
- the default text color for the text in this Legend.
-
setFont
Sets the font used for text in this Legend. This font can be changed for individual LegendItem objects usingLegendItem.setFont(Font)
.- Parameters:
font
- the font used for text in this legend.
-
getFont
Returns the font used for text in this Legend. This font can be changed for individual LegendItem objects usingLegendItem.setFont(Font)
.- Returns:
- the font used for text in this Legend.
-
setDrawWhenZoomed
public void setDrawWhenZoomed(int drawWhenZoomed) Sets whether or not this Legend is drawn when a zoomed Cgview map is generated.- Parameters:
drawWhenZoomed
-CgviewConstants.LEGEND_DRAW_ZOOMED
orCgviewConstants.LEGEND_NO_DRAW_ZOOMED
.
-
getDrawWhenZoomed
public int getDrawWhenZoomed()Returns whether or not this Legend is drawn when a zoomed Cgview map is generated. -
setPosition
public void setPosition(int position) Sets the position of this Legend relative to the Cgview map canvas.- Parameters:
position
-CgviewConstants.LEGEND_UPPER_LEFT
,CgviewConstants.LEGEND_UPPER_CENTER
,CgviewConstants.LEGEND_UPPER_RIGHT
,CgviewConstants.LEGEND_MIDDLE_LEFT
,CgviewConstants.LEGEND_MIDDLE_LEFT_OF_CENTER
,CgviewConstants.LEGEND_MIDDLE_CENTER
,CgviewConstants.LEGEND_MIDDLE_RIGHT
,CgviewConstants.LEGEND_MIDDLE_RIGHT_OF_CENTER
,CgviewConstants.LEGEND_LOWER_LEFT
,CgviewConstants.LEGEND_LOWER_CENTER
, orCgviewConstants.LEGEND_LOWER_RIGHT
.
-
getPosition
public int getPosition()Returns the position of this Legend relative to the Cgview map canvas.- Returns:
CgviewConstants.LEGEND_UPPER_LEFT
,CgviewConstants.LEGEND_UPPER_CENTER
,CgviewConstants.LEGEND_UPPER_RIGHT
,CgviewConstants.LEGEND_MIDDLE_LEFT
,CgviewConstants.LEGEND_MIDDLE_LEFT_OF_CENTER
,CgviewConstants.LEGEND_MIDDLE_CENTER
,CgviewConstants.LEGEND_MIDDLE_RIGHT
,CgviewConstants.LEGEND_MIDDLE_RIGHT_OF_CENTER
,CgviewConstants.LEGEND_LOWER_LEFT
,CgviewConstants.LEGEND_LOWER_CENTER
, orCgviewConstants.LEGEND_LOWER_RIGHT
.
-
setAlignment
public void setAlignment(int textAlignment) Sets the alignment of the LegendItems in this Legend.- Parameters:
textAlignment
-CgviewConstants.LEGEND_ITEM_ALIGN_LEFT
,CgviewConstants.LEGEND_ITEM_ALIGN_CENTER
, orCgviewConstants.LEGEND_ITEM_ALIGN_RIGHT
. This setting can be changed for individual legendItems usingLegendItem.setTextAlignment()
.
-
getAlignment
public int getAlignment()Returns the alignment of legendItems in this Legend.- Returns:
CgviewConstants.LEGEND_ITEM_ALIGN_LEFT
,CgviewConstants.LEGEND_ITEM_ALIGN_CENTER
, orCgviewConstants.LEGEND_ITEM_ALIGN_RIGHT
. The alignment of legendItems can be changed for individual legendItems usingLegendItem.setTextAlignment()
.
-
setBackgroundOpacity
public void setBackgroundOpacity(float opacity) Sets the opacity of the background of this Legend when drawn.- Parameters:
opacity
- the opacity between0
and1
, with1
being the most opaque.
-
getBackgroundOpacity
public float getBackgroundOpacity()Returns the opacity of the background of this Legend when drawn.- Returns:
- the opacity between
0
and1
, with1
being the most opaque.
-
setBackgroundColor
Sets the color of the background of this Legend when drawn.- Parameters:
color
- the color of the background.
-
getBackgroundColor
Returns the color of the background of this Legend when drawn.- Returns:
- the color of the background.
-
setAllowLabelClash
public void setAllowLabelClash(boolean allowClash) Sets whether or not feature labels are allowed to clash with this Legend. If false, feature labels are removed if they clash with this Legend.- Parameters:
allowClash
- whether or not feature labels are allowed to clash with this Legend.
-
getAllowLabelClash
public boolean getAllowLabelClash()Returns whether or not feature labels are allowed to clash with this Legend. If false, labels are removed if they clash with this Legend.- Returns:
- whether or not labels are allowed to clash with this Legend.
-