Class Style


  • public class Style
    extends java.lang.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 Output types.

    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.

    • Constructor Summary

      Constructors 
      Constructor Description
      Style​(java.awt.Paint color)
      Create a new Style in the specified color.
      Style​(java.awt.Paint color, java.awt.Color bordercolor)
      Create a new Style and set it's color and bordercolor.
      Style​(java.awt.Paint color, java.lang.String fontname, int fontstyle, float fontsize)
      Convenience constructor - create a new Style to be used with Text
      Style​(java.awt.Paint color, java.lang.String fontname, int fontstyle, float fontsize, int align)
      Convenience constructor - create a new Style to be used with Text, and set it's alignment.
    • Constructor Detail

      • Style

        public Style​(java.awt.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​(java.awt.Paint color,
                     java.awt.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 an AxesGraph by setting the color parameter to null.
        Parameters:
        color - the main color of the element
        color - the border color of the element
      • Style

        public Style​(java.awt.Paint color,
                     java.lang.String fontname,
                     int fontstyle,
                     float fontsize)
        Convenience constructor - create a new Style to be used with Text
        Parameters:
        color - The main color of the element
        fontname - The font for the element
        fontstyle - The font style for the element. Either java.awt.Font.PLAIN, Font.ITALIC, Font.BOLD or Font.BOLD+Font.ITALIC
        fontsize - The font size for the element, in points
        Since:
        1.0.3
        See Also:
        org.faceless.graph.output.ImageOutput#setFontMap, org.faceless.graph.output.PDFOutput#setFontMap
      • Style

        public Style​(java.awt.Paint color,
                     java.lang.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 element
        fontname - The font for the element
        fontstyle - The font style for the element. Either java.awt.Font.PLAIN, Font.ITALIC, Font.BOLD or Font.BOLD+Font.ITALIC
        fontsize - The font size for the element, in points
        align - The alignment for the element. A logical OR of TOP, MIDDLE or BOTTOM and LEFT, CENTER or RIGHT
        Since:
        1.0.3
        See Also:
        org.faceless.graph.output.ImageOutput#setFontMap, org.faceless.graph.output.PDFOutput#setFontMap
    • Method Detail

      • setColor

        public void setColor​(java.awt.Paint color)
        Set the main color for this style
      • setBorderColor

        public void setBorderColor​(java.awt.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​(java.lang.String name,
                            int style,
                            float size)
        Set the font for this style
        Since:
        1.0.3
      • 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.

        Parameters:
        align - The text alignment. Valid values are TOP, RIGHT, BOTTOM, LEFT, CENTER (for horizontal centering), MIDDLE (for vertical centering), or any logical OR'ing of these values, eg. TOP|CENTER.
      • getColor

        public java.awt.Paint getColor()
        Get the main color for this style
      • getBorderColor

        public java.awt.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. See setAlign(int)
      • getFontName

        public java.lang.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 by setFontScale(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
      • clone

        public java.lang.Object clone()
        Clone the style.
        Overrides:
        clone in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • 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 of Output, 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. See setFontScale(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. Calling Style.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​(java.awt.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 java.awt.Color getDefaultBorderColor()
        Returns the value set by setDefaultBorderColor(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 PieGraph

        since 1.0.3, use the equivalent non-static methods in the Graph class to set defaults on a per-graph basis