Class LayoutUtils


  • public class LayoutUtils
    extends Object
    Class that provides several utility function to handle SVG Objects (like DOM initialization etc pp
    Author:
    Thomas Pfau
    • Constructor Detail

      • LayoutUtils

        public LayoutUtils()
    • Method Detail

      • createSVGDoc

        public static org.w3c.dom.svg.SVGDocument createSVGDoc()
        Create an SVG Document using a default DOM implementation.
        Returns:
        An SVG Document with default settings
      • getSVGFontMetrics

        public static FontMetrics getSVGFontMetrics​(Font font)
      • TransferGraphicsToDocument

        public static void TransferGraphicsToDocument​(org.w3c.dom.svg.SVGDocument doc,
                                                      Dimension canvasdimension,
                                                      org.apache.batik.svggen.SVGGraphics2D g)
        Transfer data that was writen to an SVGGraphics2D context to a document using a specified canvasdimension.
        Parameters:
        doc - - the SVGDocument to write to.
        canvasdimension - - the target canvas dimension (can be null, in which instance default sizes are used (400/290)
        g - - The SVGGraphics2D Context to write in.
      • scaleSVGFont

        public static Font scaleSVGFont​(Dimension dim,
                                        Font font,
                                        String label)
        Scale a Font so that a given label fits into a specific dimension in an SVG context.
        Parameters:
        dim - - the dimension the label should fit in.
        font - - the font to scale.
        label - - the String that should fit into the dimension.
        Returns:
        the font scaled to the provided Dimension using a default svg graphics context
      • scaleFont

        public static Font scaleFont​(Dimension dim,
                                     Font font,
                                     Graphics g,
                                     String label)
        Scale a Font so that a given label fits into a specific dimension.
        Parameters:
        dim - - the dimension the label should fit in.
        font - - the font to scale.
        g - - the graphics context to use
        label - - the String that should fit into the dimension.
        Returns:
        the font scaled to the provided Dimension
      • getLabelsForData

        public static HashMap<Comparable,​String> getLabelsForData​(Vector<Comparable> entries)
        Get alphanumeric unique labels for a set of entries (i.e. for labeling items or similar things) This function provides the same labels when called with the same entries
        Parameters:
        entries - - Comparable objects (not necessarily of the same type)
        Returns:
        a Mapping of the provided objects to alphanumeric labels.