Class Style
- java.lang.Object
-
- org.faceless.graph.Style
-
public class Style extends Object
Styles control the colors, borders and fonts of an element. Although a style can have several attributes, not all of them are necessarily used for each element (for example, a face doesn't need a font, and a line of text has no border)
The various "aspects" a style can have are:
- Color: Controls the base color of the element.
- BorderColor: If the element can be filled, controls the color of the border around the edge.
- Borders: If the element can be filled, controls which borders are drawn - top, left, bottom or all four.
- Font: For text elements only, the font to render the text in.
- Alignment: For text elements only, how to align the text - left, centered, bottom aligned or combinations.
- Rotation: For text elements only, what angle to rotate the text to. This operation may not be supported.
by all
Outputtypes.
Once a style has been applied to an element, it cannot be changed.
In version 1.0.3 and later, changes have been made to the way fonts are handled. Previously, the java.awt.Font class was used to define the font, which is practical for output to a subclass of ImageOutput but doesn't work well for output to non-AWT based output devices, like PDF. Consequently calls to the setFont method should be changed from setFont(new Font("Helvetica", Font.PLAIN, 12)) to setFont("Helvetica", Font.PLAIN, 12). The same applies to any constructors taking a java.awt.Font - pass in the font name, style and size instead of the font itself.
-
-
Field Summary
Fields Modifier and Type Field Description static intBOTTOMFor use withsetAlign(int)to align text to it's baseline (the default).static intCENTERFor use withsetAlign(int)to center the text horizontally.static intGRID_BOTHFor use withsetGrid(int)to draw horizontal and vertical grid linesstatic intGRID_HORIZONTALFor use withsetGrid(int)to draw horizontal grid linesstatic intGRID_VERTICALFor use withsetGrid(int)to draw vertical grid linesstatic intLEFTFor use withsetAlign(int)to left align text (the default).static intMIDDLEFor use withsetAlign(int)to center the text vertically.static intRIGHTFor use withsetAlign(int)to right align text.static intTOPFor use withsetAlign(int)to align text at it's top.
-
Constructor Summary
Constructors Constructor Description Style(Paint color)Create a new Style in the specified color.Style(Paint color, Color bordercolor)Create a new Style and set it's color and bordercolor.Style(Paint color, String fontname, int fontstyle, float fontsize)Convenience constructor - create a new Style to be used with TextStyle(Paint color, String fontname, int fontstyle, float fontsize, int align)Convenience constructor - create a new Style to be used with Text, and set it's alignment.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Objectclone()Clone the style.intgetAlign()Get the alignment for this style.ColorgetBorderColor()Get the border color for this stylePaintgetColor()Get the main color for this stylestatic ColorgetDefaultBorderColor()Returns the value set bysetDefaultBorderColor(java.awt.Color)StringgetFontName()Get the font name for this style.static doublegetFontScale()Return the current font scale.floatgetFontSize()Get the font size, after being adjust to account for the scale set bysetFontScale(double)intgetFontStyle()Get the font style (Font.ITALIC, Font.PLAIN, Font.BOLD or a combination) for this style.doublegetLineDashOff()doublegetLineDashOn()doublegetLineDashPhase()doublegetLineThickness()Get the line thickness for this styledoublegetRotate()Get the text rotation for this style, in degrees clockwisevoidsetAlign(int align)Set the text alignment for this style.voidsetBorderColor(Color color)Set the border color for this stylevoidsetColor(Paint color)Set the main color for this stylestatic voidsetDefaultBorderColor(Color c)This method changes the default border color of new styles.static voidsetDefaultLineThickness(double thickness)Set the default line thickness for all styles. 1 is the default, 0.5 is half as thick, and so on.voidsetFont(String name, int style, float size)Set the font for this stylestatic voidsetFontScale(double val)Every text element that's created may have it's font automatically scaled up or down by a percentage by setting a different fontscale.voidsetGrid(int border)Set which grid lines to display for this style - only used by the styles passed toAxesGraph.optionZWallStyle(org.faceless.graph.Style),AxesGraph.optionYWallStyle(org.faceless.graph.Style)andAxesGraph.optionFloorStyle(org.faceless.graph.Style), values should be eitherGRID_HORIZONTALto draw horizontal grid lines,GRID_VERTICALto draw vertical grid lines, or theGRID_BOTHto draw the full grid (the default)static voidsetLightLevel(int level)Set the level of light (technically, the level of shade) that should be applied to a graph.static voidsetLightVector(int x, int y, int z)Set the vector of where the light is coming from.voidsetLineDash(double dashon, double dashoff, double dashphase)voidsetLineThickness(double thick)Set the line thickness for this style. 1 is the default, 0.5 is half as thick, and so on.static voidsetPieEdgeDegrees(double val)Adjust the number of degrees taken by each of the small faces used to draw the edge of a PieGraph.voidsetRotate(double val)Set the text rotation for this style, in degrees clockwiseStringtoString()
-
-
-
Field Detail
-
TOP
public static final int TOP
For use withsetAlign(int)to align text at it's top.- See Also:
- Constant Field Values
-
RIGHT
public static final int RIGHT
For use withsetAlign(int)to right align text.- See Also:
- Constant Field Values
-
BOTTOM
public static final int BOTTOM
For use withsetAlign(int)to align text to it's baseline (the default).- See Also:
- Constant Field Values
-
LEFT
public static final int LEFT
For use withsetAlign(int)to left align text (the default).- See Also:
- Constant Field Values
-
MIDDLE
public static final int MIDDLE
For use withsetAlign(int)to center the text vertically.- See Also:
- Constant Field Values
-
CENTER
public static final int CENTER
For use withsetAlign(int)to center the text horizontally.- See Also:
- Constant Field Values
-
GRID_HORIZONTAL
public static final int GRID_HORIZONTAL
For use withsetGrid(int)to draw horizontal grid lines- See Also:
- Constant Field Values
-
GRID_VERTICAL
public static final int GRID_VERTICAL
For use withsetGrid(int)to draw vertical grid lines- See Also:
- Constant Field Values
-
GRID_BOTH
public static final int GRID_BOTH
For use withsetGrid(int)to draw horizontal and vertical grid lines- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Style
public Style(Paint color)
Create a new Style in the specified color. Although colors may have an alpha component, not all Output classes can understand it.- Parameters:
color- the main color of the element
-
Style
public Style(Paint color, Color bordercolor)
Create a new Style and set it's color and bordercolor. Because either of these can be null, this constructor is generally used to create transparent floors or walls for anAxesGraphby setting thecolorparameter to null.- Parameters:
color- the main color of the elementcolor- the border color of the element
-
Style
public Style(Paint color, String fontname, int fontstyle, float fontsize)
Convenience constructor - create a new Style to be used with Text- Parameters:
color- The main color of the elementfontname- The font for the elementfontstyle- The font style for the element. Either java.awt.Font.PLAIN, Font.ITALIC, Font.BOLD or Font.BOLD+Font.ITALICfontsize- The font size for the element, in points- Since:
- 1.0.3
- See Also:
ImageOutput.setFontMap(java.lang.String, int, java.awt.Font),org.faceless.graph.output.PDFOutput#setFontMap
-
Style
public Style(Paint color, String fontname, int fontstyle, float fontsize, int align)
Convenience constructor - create a new Style to be used with Text, and set it's alignment.- Parameters:
color- The main color of the elementfontname- The font for the elementfontstyle- The font style for the element. Either java.awt.Font.PLAIN, Font.ITALIC, Font.BOLD or Font.BOLD+Font.ITALICfontsize- The font size for the element, in pointsalign- The alignment for the element. A logical OR ofTOP,MIDDLEorBOTTOMandLEFT,CENTERorRIGHT- Since:
- 1.0.3
- See Also:
ImageOutput.setFontMap(java.lang.String, int, java.awt.Font),org.faceless.graph.output.PDFOutput#setFontMap
-
-
Method Detail
-
setColor
public void setColor(Paint color)
Set the main color for this style
-
setBorderColor
public void setBorderColor(Color color)
Set the border color for this style
-
setLineThickness
public void setLineThickness(double thick)
Set the line thickness for this style. 1 is the default, 0.5 is half as thick, and so on. Not all Output classes can use this option. A value of zero means "make the lines as thin as possible".
-
setLineDash
public void setLineDash(double dashon, double dashoff, double dashphase)
-
setFont
public void setFont(String name, int style, float size)
Set the font for this style- Since:
- 1.0.3
-
setGrid
public void setGrid(int border)
Set which grid lines to display for this style - only used by the styles passed toAxesGraph.optionZWallStyle(org.faceless.graph.Style),AxesGraph.optionYWallStyle(org.faceless.graph.Style)andAxesGraph.optionFloorStyle(org.faceless.graph.Style), values should be eitherGRID_HORIZONTALto draw horizontal grid lines,GRID_VERTICALto draw vertical grid lines, or theGRID_BOTHto draw the full grid (the default)- Parameters:
borders- the borders to draw- Since:
- 1.0.7
-
setRotate
public void setRotate(double val)
Set the text rotation for this style, in degrees clockwise
-
setAlign
public void setAlign(int align)
Set the text alignment for this style. Alignment controls where a text element is drawn in relation to it's anchor point. For instance, TOP|LEFT would cause the top left corner of the text to be placed on the anchor point, whereas CENTER|MIDDLE would place center the text horizontally and vertically on it's anchor.
-
getColor
public Paint getColor()
Get the main color for this style
-
getBorderColor
public Color getBorderColor()
Get the border color for this style
-
getLineThickness
public double getLineThickness()
Get the line thickness for this style
-
getLineDashPhase
public double getLineDashPhase()
-
getLineDashOn
public double getLineDashOn()
-
getLineDashOff
public double getLineDashOff()
-
getRotate
public double getRotate()
Get the text rotation for this style, in degrees clockwise
-
getAlign
public int getAlign()
Get the alignment for this style. SeesetAlign(int)
-
getFontName
public String getFontName()
Get the font name for this style.- Since:
- 1.0.3
-
getFontSize
public float getFontSize()
Get the font size, after being adjust to account for the scale set bysetFontScale(double)- Since:
- 1.0.3
-
getFontStyle
public int getFontStyle()
Get the font style (Font.ITALIC, Font.PLAIN, Font.BOLD or a combination) for this style.- Since:
- 1.0.3
-
setFontScale
public static void setFontScale(double val)
Every text element that's created may have it's font automatically scaled up or down by a percentage by setting a different fontscale. This was intended for subclasses ofOutput, so those that use a totally different scaling can set it in one go. But it's useful for the end user too. The default is 1, and a value of 0.5 would make all the text half the original size.since 1.0.3, use the equivalent non-static methods in the Graph class to set defaults on a per-graph basis
-
getFontScale
public static double getFontScale()
Return the current font scale. SeesetFontScale(double)since 1.0.3, use the equivalent non-static methods in the Graph class to set defaults on a per-graph basis
-
setLightLevel
public static void setLightLevel(int level)
Set the level of light (technically, the level of shade) that should be applied to a graph. A value of 0 is no shading at all, a value of 100 gives deep shadows. The default is 70.since 1.0.3, use the equivalent non-static methods in the Graph class to set defaults on a per-graph basis
-
setLightVector
public static void setLightVector(int x, int y, int z)Set the vector of where the light is coming from. The light is assumed to be coming from an infinite distance away in the specified direction, so don't worry about the length of the vector. The default is (1,0,0), which makes the light appear to come from the right side of the graph. CallingStyle.setLightVector(-1,0,1)would put the light to the left and in front of the graph, while a vector (0,-1,0) would put the light directly underneath the graph, for a strange result indeed.since 1.0.3, use the equivalent non-static methods in the Graph class to set defaults on a per-graph basis
-
setDefaultBorderColor
public static void setDefaultBorderColor(Color c)
This method changes the default border color of new styles. By default, this is set to black, but it can be set to null for a different look, or a different color altogether. This is useful if the graph is to be rendered over a black background, for example.since 1.0.3, use the equivalent non-static methods in the Graph class to set defaults on a per-graph basis
-
getDefaultBorderColor
public static Color getDefaultBorderColor()
Returns the value set bysetDefaultBorderColor(java.awt.Color)since 1.0.3, use the equivalent non-static methods in the Graph class to set defaults on a per-graph basis
-
setDefaultLineThickness
public static void setDefaultLineThickness(double thickness)
Set the default line thickness for all styles. 1 is the default, 0.5 is half as thick, and so on. Not all Output classes can use this option. A value of zero means "make the lines as thin as possible".since 1.0.3, use the equivalent non-static methods in the Graph class to set defaults on a per-graph basis
-
setPieEdgeDegrees
public static void setPieEdgeDegrees(double val)
Adjust the number of degrees taken by each of the small faces used to draw the edge of a PieGraph. The higher the number of faces, the less noticeable the "banding" effect will be on the edge of a 3D shaded PieGraph, but at the expense of slower rendering. The default value is 5 degrees.- Parameters:
val- the number of degrees per face at the edge of a PieGraphsince 1.0.3, use the equivalent non-static methods in the Graph class to set defaults on a per-graph basis
-
-