Class ODGDocument

  • All Implemented Interfaces:
    java.lang.Cloneable, org.w3c.dom.Document, org.w3c.dom.Node

    public class ODGDocument
    extends com.jsevy.jxml.XMLDocument
    Class representing an Open Document Format drawing document, which owns an ODGGraphics on which drawing commands can be made. The document's toODGString method can then be called to generate the ODG text corresponding to the drawing done on the Graphics object. The typical workflow is as follows:
     
     // Create an odg document and get its associated ODGGraphics instance
     ODGDocument odgDocument = new ODGDocument(); 
     ODGGraphics graphics = odgDocument.getGraphics(); 
     
     // Do drawing commands as you would on any other Graphics object. If you have a paint(Graphics)  
     // method, you can just use it with the ODGGraphics instance since it's a subclass of Graphics. 
     graphics.setColor(Color.RED);  
     graphics.setStroke(new BasicStroke(3));
     graphics.drawLine(0, 0, 1000, 500); 
     graphics.drawRect(1000, 500, 150, 150); 
     graphics.drawRoundRect(20, 200, 130, 100, 20, 10); 
     
     // Get the flat ODG output as a string - it's just XML text - and  save  in a file for use 
     // with LibreOffice Draw or any other draw package that accepts flat ODG (.fodg) files
     String stringOutput = odgDocument.toODGString(); 
     String filePath = "path/to/file.fodg"; 
     FileWriter fileWriter = new FileWriter(filePath); 
     fileWriter.write(odgText); 
     fileWriter.flush(); 
     fileWriter.close();
     
     
    Author:
    jsevy
    • Field Summary

      • Fields inherited from interface org.w3c.dom.Node

        ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_PRECEDING, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
    • Constructor Summary

      Constructors 
      Constructor Description
      ODGDocument()
      Create a new ODGDocument
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addEntity​(com.jsevy.jodg.ODGEntity entity)
      Utility method used by the associated ODGGraphics object.
      ODGGraphics getGraphics()
      Get the ODGGraphics associated with this document for use with standard Graphics drawing operations to generate an odg text representation.
      void preapplyTransform​(boolean preApplyTransform)
      When set to true, the current Java transform will be applied to a shape before it is converted into an equivalent ODG object.
      void setScaleFactor​(double javaUnitsPerUnit)
      Set the scale factor for dimensions in the Java drawing - how many Java units/pixels correspong to one unit in the ODG output.
      void setTextFrameExpansionFactor​(double textFrameExpansionFactor)
      Since the fonts used in an ODG program (e.g., LibreOffice Draw) aren't identical to those used in Java, the physical widths of strings can differ slightly.
      void setUnits​(int unitsCode)
      Set the units for interpreting the dimension values in the ODG file.
      java.lang.String toODGString()
      Return the ODG text associated with this ODG document.
      • Methods inherited from class com.jsevy.jxml.XMLDocument

        adoptNode, cloneNode, createAttribute, createAttributeNS, createCDATASection, createComment, createDocumentFragment, createElement, createElementNS, createEntityReference, createProcessingInstruction, createTextNode, getDoctype, getDocumentElement, getDocumentURI, getDomConfig, getElementById, getElementsByTagName, getElementsByTagNameNS, getImplementation, getInputEncoding, getNodeType, getStrictErrorChecking, getTextContent, getXmlEncoding, getXmlStandalone, getXmlVersion, importNode, normalizeDocument, renameNode, setDoctype, setDocumentElement, setDocumentURI, setInputEncoding, setStrictErrorChecking, setXmlEncoding, setXmlStandalone, setXmlVersion
      • Methods inherited from class com.jsevy.jxml.XMLNode

        appendChild, clone, compareDocumentPosition, equals, getAttributes, getBaseURI, getChildNodes, getDescendants, getFeature, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeName, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, getUserData, hasAttributes, hasChildNodes, insertAfter, insertBefore, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, prependChild, removeChild, replaceChild, setNamespaceURI, setNodeName, setNodeValue, setOwnerDocument, setParentNode, setPrefix, setTextContent, setUserData
      • Methods inherited from class java.lang.Object

        getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface org.w3c.dom.Node

        appendChild, compareDocumentPosition, getAttributes, getBaseURI, getChildNodes, getFeature, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeName, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, getUserData, hasAttributes, hasChildNodes, insertBefore, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, removeChild, replaceChild, setNodeValue, setPrefix, setTextContent, setUserData
    • Constructor Detail

      • ODGDocument

        public ODGDocument()
        Create a new ODGDocument
    • Method Detail

      • setUnits

        public void setUnits​(int unitsCode)
        Set the units for interpreting the dimension values in the ODG file.
        Parameters:
        unitsCode - ODG code indicating units: 0 = Unitless 1 = Inches 2 = Feet 3 = Miles 4 = Millimeter 5 = Centimeters 6 = Meters 7 = Kilometers 8 = Microinches 9 = Mils 10 = Yards
      • setScaleFactor

        public void setScaleFactor​(double javaUnitsPerUnit)
        Set the scale factor for dimensions in the Java drawing - how many Java units/pixels correspong to one unit in the ODG output. Note that the units can be set with a call to setUnits
        Parameters:
        javaUnitsPerUnit - How many Java units/pixels correspond to one ODG unit
      • preapplyTransform

        public void preapplyTransform​(boolean preApplyTransform)
        When set to true, the current Java transform will be applied to a shape before it is converted into an equivalent ODG object. The default is false; in this case the current Java transform is just embedded as part of the ODG shape's definition, as discussed in the ODG specification. However, some versions of vector drawing packages, most notably LibreOffice Draw, do not handle certain types of transforms correctly, and thus will incorrectly render some shapes with embedded transforms. By setting this flag to true, the Java transform is used to transform shapes before the ODG is generated, so they won't (for the most part) have embedded transforms. (The exception concerns ellipses - when the major and minor axes aren't parallel to the x and y axes, these need to have a rotation and translation associated since the ODG ellipse definition only supports horizontal and vertical major and minor axes. Fortunately LibreOffice handles these transforms correctly.) See: https://bugs.documentfoundation.org/show_bug.cgi?id=98584 https://bugs.documentfoundation.org/show_bug.cgi?id=98565
        Parameters:
        preApplyTransform - When false (the default), any Java transform is embedded in the ODG definition. When true, the current Java transform is applied to each shape before its ODG equivalent is generated.
      • setTextFrameExpansionFactor

        public void setTextFrameExpansionFactor​(double textFrameExpansionFactor)
        Since the fonts used in an ODG program (e.g., LibreOffice Draw) aren't identical to those used in Java, the physical widths of strings can differ slightly. When the ODG fonts are slightly wider, the text generated by the JODG library may not fit into the text frame created for them when they are displayed in the ODG viewer and may be split into two lines. This factor causes the text frame width to be increased slightly to accommodate this discrepancy. The default value is set to 1.05, so that frames will be 5% larger than needed. Note that this won't affect the display since the frames are invisible in the ODG drawing. You'll only notice if you go to edit the text.
        Parameters:
        textFrameExpansionFactor - Factor to multiply each text frame's width by (default is 1.05)
      • getGraphics

        public ODGGraphics getGraphics()
        Get the ODGGraphics associated with this document for use with standard Graphics drawing operations to generate an odg text representation.
        Returns:
        The ODGGraphics associated with this document, on which standard Java Graphics drawing calls can be made
      • toODGString

        public java.lang.String toODGString()
        Return the ODG text associated with this ODG document. This includes the header, classes, tables, blocks, entities and objects sections, populated with content generated by graphics calls on the associated ODGGraphics.
        Returns:
        The ODG text associated with this document.
      • addEntity

        public void addEntity​(com.jsevy.jodg.ODGEntity entity)
        Utility method used by the associated ODGGraphics object.
        Parameters:
        entity - an odgEntity instance