Package com.mxgraph.util
Class mxUtils
- java.lang.Object
-
- com.mxgraph.util.mxUtils
-
public class mxUtils extends java.lang.ObjectContains various helper methods for use with mxGraph.
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.awt.GraphicsfontGraphicsStatic Graphics used for Font Metrics.static booleanIS_LINUXTrue if the machine is running a linux kernel.static booleanIS_MACTrue if the machine is a Mac.
-
Constructor Summary
Constructors Constructor Description mxUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static double[]arcToCurves(double x0, double y0, double r1, double r2, double angle, double largeArcFlag, double sweepFlag, double x, double y)Function: arcToCurves Converts the given arc to a series of curves.static voidclearRect(java.awt.Graphics2D g, java.awt.Rectangle rect, java.awt.Color background)Clears the given area of the specified graphics object with the given color or makes the region transparent.static booleancontains(java.lang.Object[] array, java.lang.Object obj)Returns true if the given array contains the given object.static java.awt.image.BufferedImagecreateBufferedImage(int w, int h, java.awt.Color background)Creates a buffered image for the given parameters.static java.awt.image.BufferedImagecreateBufferedImage(int w, int h, java.awt.Color background, int type)Creates a buffered image for the given parameters.static org.w3c.dom.DocumentcreateDocument()Deprecated.UsemxDomUtils.createDocument(Jan 2012)static org.w3c.dom.DocumentcreateHtmlDocument()Deprecated.UsemxDomUtils.createHtmlDocument(Jan 2012)static java.lang.StringcreateHtmlDocument(java.util.Map<java.lang.String,java.lang.Object> style, java.lang.String text)Returns a new, empty DOM document.static java.lang.StringcreateHtmlDocument(java.util.Map<java.lang.String,java.lang.Object> style, java.lang.String text, double scale)Returns a new, empty DOM document.static java.lang.StringcreateHtmlDocument(java.util.Map<java.lang.String,java.lang.Object> style, java.lang.String text, double scale, int width)Returns a new, empty DOM document.static java.lang.StringcreateHtmlDocument(java.util.Map<java.lang.String,java.lang.Object> style, java.lang.String text, double scale, int width, java.lang.String head)Returns a new, empty DOM document.static java.lang.StringcreateHtmlDocument(java.util.Map<java.lang.String,java.lang.Object> style, java.lang.String text, double scale, int width, java.lang.String head, java.lang.String bodyCss)Returns a new, empty DOM document.static javax.swing.text.html.HTMLDocumentcreateHtmlDocumentObject(java.util.Map<java.lang.String,java.lang.Object> style, double scale)Returns a new, empty DOM document.static org.w3c.dom.DocumentcreateSvgDocument(int width, int height)Deprecated.UsemxDomUtils.createSvgDocument(int, int)(Jan 2012)static org.w3c.dom.ElementcreateTable(org.w3c.dom.Document document, java.lang.String text, int x, int y, int w, int h, double scale, java.util.Map<java.lang.String,java.lang.Object> style)Creates a table for the given text using the given document to create the DOM nodes.static org.w3c.dom.DocumentcreateVmlDocument()Deprecated.UsemxDomUtils.createVmlDocument(Jan 2012)static voiddrawImageClip(java.awt.Graphics g, java.awt.image.BufferedImage image, java.awt.image.ImageObserver observer)Draws the image inside the clip bounds to the given graphics object.static java.lang.Objecteval(java.lang.String expression)Evaluates a Java expression as a class member using mxCodecRegistry.static voidfillClippedRect(java.awt.Graphics g, int x, int y, int width, int height)static intfindNearestSegment(mxCellState state, double x, double y)Finds the index of the nearest segment on the given cell state for the specified coordinate pair.static org.w3c.dom.NodefindNode(org.w3c.dom.Node node, java.lang.String attr, java.lang.String value)Returns the first node where attr equals value.static intfirstCharAt(java.lang.String text, int inputChar, int fromIndex)Find the first character matching the input character in the given string where the character has no letter preceding it.static java.lang.StringgetBodyMarkup(java.lang.String markup, boolean replaceLinefeeds)Returns the body part of the given HTML markup.static mxRectanglegetBoundingBox(mxRectangle rect, double rotation)Returns the bounding box for the rotated rectangle.static java.awt.ColorgetColor(java.util.Map<java.lang.String,java.lang.Object> dict, java.lang.String key)Returns the value for key in dictionary as a color or null if no value is defined for the key.static java.awt.ColorgetColor(java.util.Map<java.lang.String,java.lang.Object> dict, java.lang.String key, java.awt.Color defaultValue)Returns the value for key in dictionary as a color or the given default value if no value is defined for the key.static doublegetDouble(java.util.Map<java.lang.String,java.lang.Object> dict, java.lang.String key)Returns the value for key in dictionary as a double or 0 if no value is defined for the key.static doublegetDouble(java.util.Map<java.lang.String,java.lang.Object> dict, java.lang.String key, double defaultValue)Returns the value for key in dictionary as a double or the given default value if no value is defined for the key.static floatgetFloat(java.util.Map<java.lang.String,java.lang.Object> dict, java.lang.String key)Returns the value for key in dictionary as a float or 0 if no value is defined for the key.static floatgetFloat(java.util.Map<java.lang.String,java.lang.Object> dict, java.lang.String key, float defaultValue)Returns the value for key in dictionary as a float or the given default value if no value is defined for the key.static float[]getFloatArray(java.util.Map<java.lang.String,java.lang.Object> dict, java.lang.String key, float[] defaultValue)Returns the value for key in dictionary as a float array or the given default value if no value is defined for the key.static float[]getFloatArray(java.util.Map<java.lang.String,java.lang.Object> dict, java.lang.String key, float[] defaultValue, java.lang.String separator)Returns the value for key in dictionary as a float array or the given default value if no value is defined for the key.static java.awt.FontgetFont(java.util.Map<java.lang.String,java.lang.Object> style)static java.awt.FontgetFont(java.util.Map<java.lang.String,java.lang.Object> style, double scale)static java.awt.FontMetricsgetFontMetrics(java.awt.Font font)Returns the font metrics of the static font graphics instancestatic java.lang.StringgetHexColorString(java.awt.Color color)Returns a hex representation for the given color.static intgetInt(java.util.Map<java.lang.String,java.lang.Object> dict, java.lang.String key)Returns the value for key in dictionary as an int or 0 if no value is defined for the key.static intgetInt(java.util.Map<java.lang.String,java.lang.Object> dict, java.lang.String key, int defaultValue)Returns the value for key in dictionary as an int or the given default value if no value is defined for the key.static mxRectanglegetLabelPaintBounds(java.lang.String label, java.util.Map<java.lang.String,java.lang.Object> style, boolean isHtml, mxPoint offset, mxRectangle vertexBounds, double scale)Returns the paint bounds for the given label.static mxRectanglegetLabelPaintBounds(java.lang.String label, java.util.Map<java.lang.String,java.lang.Object> style, boolean isHtml, mxPoint offset, mxRectangle vertexBounds, double scale, boolean isEdge)Returns the paint bounds for the given label.static mxRectanglegetLabelSize(java.lang.String label, java.util.Map<java.lang.String,java.lang.Object> style, boolean isHtml, double scale)Returns the size for the given label.static mxRectanglegetLabelSize(java.lang.String label, java.util.Map<java.lang.String,java.lang.Object> style, boolean isHtml, double scale, double htmlWrapWidth)Returns the size for the given label.static java.lang.StringgetMd5Hash(java.lang.String text)Returns the Md5 hash for the given text.static intgetPortConstraints(mxCellState terminal, mxCellState edge, boolean source)Returns an integer mask of the port constraints of the given mapstatic intgetPortConstraints(mxCellState terminal, mxCellState edge, boolean source, int defaultValue)Returns an integer mask of the port constraints of the given mapstatic java.lang.StringgetPrettyXml(org.w3c.dom.Node node)Returns a pretty-printed XML string for the given node.static java.lang.StringgetPrettyXml(org.w3c.dom.Node node, java.lang.String tab, java.lang.String indent)Returns a pretty-printed XML string for the given node.static mxPointgetRotatedPoint(mxPoint pt, double cos, double sin)Rotates the given point by the given cos and sin.static mxPointgetRotatedPoint(mxPoint pt, double cos, double sin, mxPoint c)Rotates the given point by the given cos and sin.static mxRectanglegetScaledLabelBounds(double x, double y, mxRectangle size, double outerWidth, double outerHeight, java.util.Map<java.lang.String,java.lang.Object> style, double scale)Returns the bounds for a label for the given location and size, taking into account the alignment and spacing in the specified style, as well as the width and height of the rectangle that contains the label.static mxRectanglegetSizeForHtml(java.lang.String markup, java.util.Map<java.lang.String,java.lang.Object> style, double scale, double wrapWidth)Returns an mxRectangle with the size (width and height in pixels) of the given HTML markup.static mxRectanglegetSizeForString(java.lang.String text, java.awt.Font font, double scale)Returns anwith the size (width and height in pixels) of the given string. static java.lang.StringgetString(java.util.Map<java.lang.String,java.lang.Object> dict, java.lang.String key)Returns the value for key in dictionary as a string or null if no value is defined for the key.static java.lang.StringgetString(java.util.Map<java.lang.String,java.lang.Object> dict, java.lang.String key, java.lang.String defaultValue)Returns the value for key in dictionary as a string or the given default value if no value is defined for the key.static java.lang.StringgetStylename(java.lang.String style)Deprecated.UsemxStyleUtils.getStylename(String)(Jan 2012)static java.lang.String[]getStylenames(java.lang.String style)Deprecated.UsemxStyleUtils.getStylenames(String)(Jan 2012)static java.lang.StringgetXml(org.w3c.dom.Node node)Deprecated.UsemxXmlUtils.getXml(Node)(Jan 2012)static java.lang.StringhexString(java.awt.Color color)static java.lang.StringhtmlEntities(java.lang.String text)Converts the ampersand, quote, prime, less-than and greater-than characters to their corresponding HTML entities in the given string.static intindexOf(java.lang.Object[] array, java.lang.Object obj)Returns the index of the given object in the given array of -1 if the object is not contained in the array.static intindexOfStylename(java.lang.String style, java.lang.String stylename)Deprecated.UsemxStyleUtils.indexOfStylename(String, String)(Jan 2012)static mxPointintersection(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3)Returns the intersection of two lines as an mxPoint.static booleanintersectsHotspot(mxCellState state, int x, int y, double hotspot)static booleanintersectsHotspot(mxCellState state, int x, int y, double hotspot, int min, int max)Returns true if the given coordinate pair intersects the hotspot of the given state.static booleanisNode(java.lang.Object value, java.lang.String nodeName)Returns true if the user object is an XML node with the specified type and and the optional attribute has the specified value or is not specified.static booleanisNode(java.lang.Object value, java.lang.String nodeName, java.lang.String attributeName, java.lang.String attributeValue)Returns true if the given value is an XML node with the node name and if the optional attribute has the specified value.static booleanisTrue(java.util.Map<java.lang.String,java.lang.Object> dict, java.lang.String key)Returns true if the dictionary contains true for the given key or false if no value is defined for the key.static booleanisTrue(java.util.Map<java.lang.String,java.lang.Object> dict, java.lang.String key, boolean defaultValue)Returns true if the dictionary contains true for the given key or the given default value if no value is defined for the key.static org.w3c.dom.DocumentloadDocument(java.lang.String uri)Returns a new DOM document for the given URI.static java.awt.image.BufferedImageloadImage(java.lang.String url)Loads an image from the local filesystem, a data URI or any other URL.static java.awt.ColorparseColor(java.lang.String colorString)Shortcut for parseColor with no transparency.static java.awt.ColorparseColor(java.lang.String colorString, double alpha)Convert a string representing a 24/32bit hex color value into a Color object.static float[]parseDashPattern(java.lang.String dashPatternString)Convert a string representing a dash pattern into a float array.static org.w3c.dom.DocumentparseXml(java.lang.String xml)Deprecated.UsemxXmlUtils.parseXml(Jan 2012)static java.lang.StringreadFile(java.lang.String filename)Reads the given filename into a string.static java.lang.StringreadInputStream(java.io.InputStream stream)Reads the given filename into a string.static java.lang.StringremoveAllStylenames(java.lang.String style)Deprecated.UsemxStyleUtils.removeAllStylenames(String)(Jan 2012)static intreversePortConstraints(int constraint)static voidsetAntiAlias(java.awt.Graphics2D g, boolean antiAlias, boolean textAntiAlias)static voidsetCellStyleFlags(mxIGraphModel model, java.lang.Object[] cells, java.lang.String key, int flag, java.lang.Boolean value)Deprecated.UsemxStyleUtils.setCellStyleFlags(mxIGraphModel, Object[],String, int, Boolean)(Jan 2012)static voidsetCellStyles(mxIGraphModel model, java.lang.Object[] cells, java.lang.String key, java.lang.String value)Deprecated.UsemxStyleUtils.setCellStyles(mxIGraphModel, Object[], String, String)(Jan 2012)static java.lang.StringsetStyle(java.lang.String style, java.lang.String key, java.lang.String value)Deprecated.UsemxStyleUtils.setStyle(String, String, String)(Jan 2012)static java.lang.StringsetStyleFlag(java.lang.String style, java.lang.String key, int flag, java.lang.Boolean value)Deprecated.UsemxStyleUtils.setStyleFlag(String, String, int, Boolean)(Jan 2012)static java.lang.Object[]sortCells(java.lang.Object[] cells, boolean ascending)Sorts the given cells according to the order in the cell hierarchy.static java.util.Collection<java.lang.Object>sortCells(java.util.Collection<java.lang.Object> cells, boolean ascending)Sorts the given cells according to the order in the cell hierarchy.static java.util.List<mxPoint>translatePoints(java.util.List<mxPoint> pts, double dx, double dy)Creates a new list of new points obtained by translating the points in the given list by the given vector.static java.lang.String[]wordWrap(java.lang.String text, java.awt.FontMetrics metrics, double width)Returns the specified text in lines that fit within the specified width when the specified font metrics are applied to the textstatic voidwriteFile(java.lang.String contents, java.lang.String filename)Writes the given string into the given file.
-
-
-
Method Detail
-
getLabelSize
public static mxRectangle getLabelSize(java.lang.String label, java.util.Map<java.lang.String,java.lang.Object> style, boolean isHtml, double scale)
Returns the size for the given label. If isHtml is true then any HTML markup in the label is computed as HTML and all newlines inside the HTML body are converted into linebreaks.
-
getLabelSize
public static mxRectangle getLabelSize(java.lang.String label, java.util.Map<java.lang.String,java.lang.Object> style, boolean isHtml, double scale, double htmlWrapWidth)
Returns the size for the given label. If isHtml is true then any HTML markup in the label is computed as HTML and all newlines inside the HTML body are converted into linebreaks.
-
getBodyMarkup
public static java.lang.String getBodyMarkup(java.lang.String markup, boolean replaceLinefeeds)Returns the body part of the given HTML markup.
-
getLabelPaintBounds
public static mxRectangle getLabelPaintBounds(java.lang.String label, java.util.Map<java.lang.String,java.lang.Object> style, boolean isHtml, mxPoint offset, mxRectangle vertexBounds, double scale)
Returns the paint bounds for the given label.
-
getLabelPaintBounds
public static mxRectangle getLabelPaintBounds(java.lang.String label, java.util.Map<java.lang.String,java.lang.Object> style, boolean isHtml, mxPoint offset, mxRectangle vertexBounds, double scale, boolean isEdge)
Returns the paint bounds for the given label.
-
getScaledLabelBounds
public static mxRectangle getScaledLabelBounds(double x, double y, mxRectangle size, double outerWidth, double outerHeight, java.util.Map<java.lang.String,java.lang.Object> style, double scale)
Returns the bounds for a label for the given location and size, taking into account the alignment and spacing in the specified style, as well as the width and height of the rectangle that contains the label. (For edge labels this width and height is 0.) The scale is used to scale the given size and the spacings in the specified style.
-
getFontMetrics
public static java.awt.FontMetrics getFontMetrics(java.awt.Font font)
Returns the font metrics of the static font graphics instance- Parameters:
font- The font whose metrics are to be returned- Returns:
- the font metrics of the specified font
-
getSizeForString
public static mxRectangle getSizeForString(java.lang.String text, java.awt.Font font, double scale)
Returns anwith the size (width and height in pixels) of the given string. - Parameters:
text- String whose size should be returned.font- Font to be used for the computation.
-
wordWrap
public static java.lang.String[] wordWrap(java.lang.String text, java.awt.FontMetrics metrics, double width)Returns the specified text in lines that fit within the specified width when the specified font metrics are applied to the text- Parameters:
text- the text to wrapmetrics- the font metrics to calculate the text size forwidth- the width that the text must fit within- Returns:
- the input text split in lines that fit the specified width
-
getSizeForHtml
public static mxRectangle getSizeForHtml(java.lang.String markup, java.util.Map<java.lang.String,java.lang.Object> style, double scale, double wrapWidth)
Returns an mxRectangle with the size (width and height in pixels) of the given HTML markup.- Parameters:
markup- HTML markup whose size should be returned.
-
arcToCurves
public static double[] arcToCurves(double x0, double y0, double r1, double r2, double angle, double largeArcFlag, double sweepFlag, double x, double y)Function: arcToCurves Converts the given arc to a series of curves.
-
getBoundingBox
public static mxRectangle getBoundingBox(mxRectangle rect, double rotation)
Returns the bounding box for the rotated rectangle.
-
firstCharAt
public static int firstCharAt(java.lang.String text, int inputChar, int fromIndex)Find the first character matching the input character in the given string where the character has no letter preceding it.- Parameters:
text- the string to test for the presence of the input characterinputChar- the test characterfromIndex- the index position of the string to start from- Returns:
- the position of the first character matching the input character in the given string where the character has no letter preceding it.
-
getRotatedPoint
public static mxPoint getRotatedPoint(mxPoint pt, double cos, double sin)
Rotates the given point by the given cos and sin.
-
findNearestSegment
public static int findNearestSegment(mxCellState state, double x, double y)
Finds the index of the nearest segment on the given cell state for the specified coordinate pair.
-
getRotatedPoint
public static mxPoint getRotatedPoint(mxPoint pt, double cos, double sin, mxPoint c)
Rotates the given point by the given cos and sin.
-
getPortConstraints
public static int getPortConstraints(mxCellState terminal, mxCellState edge, boolean source)
Returns an integer mask of the port constraints of the given map- Parameters:
terminal- the cached cell state of the cell to determine the port constraints foredge- the edge connected to the constrained terminalsource- whether or not the edge specified is connected to the terminal specified at its source end- Returns:
- the mask of port constraint directions
-
getPortConstraints
public static int getPortConstraints(mxCellState terminal, mxCellState edge, boolean source, int defaultValue)
Returns an integer mask of the port constraints of the given map- Parameters:
terminal- the cached cell state of the cell to determine the port constraints foredge- the edge connected to the constrained terminalsource- whether or not the edge specified is connected to the terminal specified at its source enddefaultValue- Default value to return if the key is undefined.- Returns:
- the mask of port constraint directions
-
reversePortConstraints
public static int reversePortConstraints(int constraint)
-
drawImageClip
public static void drawImageClip(java.awt.Graphics g, java.awt.image.BufferedImage image, java.awt.image.ImageObserver observer)Draws the image inside the clip bounds to the given graphics object.
-
fillClippedRect
public static void fillClippedRect(java.awt.Graphics g, int x, int y, int width, int height)
-
translatePoints
public static java.util.List<mxPoint> translatePoints(java.util.List<mxPoint> pts, double dx, double dy)
Creates a new list of new points obtained by translating the points in the given list by the given vector. Elements that are not mxPoints are added to the result as-is.
-
intersection
public static mxPoint intersection(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3)
Returns the intersection of two lines as an mxPoint.- Parameters:
x0- X-coordinate of the first line's startpoint.y0- Y-coordinate of the first line's startpoint.x1- X-coordinate of the first line's endpoint.y1- Y-coordinate of the first line's endpoint.x2- X-coordinate of the second line's startpoint.y2- Y-coordinate of the second line's startpoint.x3- X-coordinate of the second line's endpoint.y3- Y-coordinate of the second line's endpoint.- Returns:
- Returns the intersection between the two lines.
-
sortCells
public static java.lang.Object[] sortCells(java.lang.Object[] cells, boolean ascending)Sorts the given cells according to the order in the cell hierarchy.
-
sortCells
public static java.util.Collection<java.lang.Object> sortCells(java.util.Collection<java.lang.Object> cells, boolean ascending)Sorts the given cells according to the order in the cell hierarchy.
-
contains
public static boolean contains(java.lang.Object[] array, java.lang.Object obj)Returns true if the given array contains the given object.
-
indexOf
public static int indexOf(java.lang.Object[] array, java.lang.Object obj)Returns the index of the given object in the given array of -1 if the object is not contained in the array.
-
getStylename
public static java.lang.String getStylename(java.lang.String style)
Deprecated.UsemxStyleUtils.getStylename(String)(Jan 2012)Returns the stylename in a style of the form stylename[;key=value] or an empty string if the given style does not contain a stylename.- Parameters:
style- String of the form stylename[;key=value].- Returns:
- Returns the stylename from the given formatted string.
-
getStylenames
public static java.lang.String[] getStylenames(java.lang.String style)
Deprecated.UsemxStyleUtils.getStylenames(String)(Jan 2012)Returns the stylenames in a style of the form stylename[;key=value] or an empty array if the given style does not contain any stylenames.- Parameters:
style- String of the form stylename[;stylename][;key=value].- Returns:
- Returns the stylename from the given formatted string.
-
indexOfStylename
public static int indexOfStylename(java.lang.String style, java.lang.String stylename)Deprecated.UsemxStyleUtils.indexOfStylename(String, String)(Jan 2012)Returns the index of the given stylename in the given style. This returns -1 if the given stylename does not occur (as a stylename) in the given style, otherwise it returns the index of the first character.
-
removeAllStylenames
public static java.lang.String removeAllStylenames(java.lang.String style)
Deprecated.UsemxStyleUtils.removeAllStylenames(String)(Jan 2012)Removes all stylenames from the given style and returns the updated style.
-
setCellStyles
public static void setCellStyles(mxIGraphModel model, java.lang.Object[] cells, java.lang.String key, java.lang.String value)
Deprecated.UsemxStyleUtils.setCellStyles(mxIGraphModel, Object[], String, String)(Jan 2012)Assigns the value for the given key in the styles of the given cells, or removes the key from the styles if the value is null.- Parameters:
model- Model to execute the transaction in.cells- Array of cells to be updated.key- Key of the style to be changed.value- New value for the given key.
-
setStyle
public static java.lang.String setStyle(java.lang.String style, java.lang.String key, java.lang.String value)Deprecated.UsemxStyleUtils.setStyle(String, String, String)(Jan 2012)Adds or removes the given key, value pair to the style and returns the new style. If value is null or zero length then the key is removed from the style.- Parameters:
style- String of the formstylename[;key=value].key- Key of the style to be changed.value- New value for the given key.- Returns:
- Returns the new style.
-
setCellStyleFlags
public static void setCellStyleFlags(mxIGraphModel model, java.lang.Object[] cells, java.lang.String key, int flag, java.lang.Boolean value)
Deprecated.UsemxStyleUtils.setCellStyleFlags(mxIGraphModel, Object[],String, int, Boolean)(Jan 2012)Sets or toggles the flag bit for the given key in the cell's styles. If value is null then the flag is toggled.mxUtils.setCellStyleFlags(graph.getModel(), cells, mxConstants.STYLE_FONTSTYLE, mxConstants.FONT_BOLD, null);Toggles the bold font style.- Parameters:
model- Model that contains the cells.cells- Array of cells to change the style for.key- Key of the style to be changed.flag- Integer for the bit to be changed.value- Optional boolean value for the flag.
-
setStyleFlag
public static java.lang.String setStyleFlag(java.lang.String style, java.lang.String key, int flag, java.lang.Boolean value)Deprecated.UsemxStyleUtils.setStyleFlag(String, String, int, Boolean)(Jan 2012)Sets or removes the given key from the specified style and returns the new style. If value is null then the flag is toggled.- Parameters:
style- String of the form stylename[;key=value].key- Key of the style to be changed.flag- Integer for the bit to be changed.value- Optional boolean value for the given flag.
-
intersectsHotspot
public static boolean intersectsHotspot(mxCellState state, int x, int y, double hotspot)
-
intersectsHotspot
public static boolean intersectsHotspot(mxCellState state, int x, int y, double hotspot, int min, int max)
Returns true if the given coordinate pair intersects the hotspot of the given state.
-
isTrue
public static boolean isTrue(java.util.Map<java.lang.String,java.lang.Object> dict, java.lang.String key)Returns true if the dictionary contains true for the given key or false if no value is defined for the key.- Parameters:
dict- Dictionary that contains the key, value pairs.key- Key whose value should be returned.- Returns:
- Returns the boolean value for key in dict.
-
isTrue
public static boolean isTrue(java.util.Map<java.lang.String,java.lang.Object> dict, java.lang.String key, boolean defaultValue)Returns true if the dictionary contains true for the given key or the given default value if no value is defined for the key.- Parameters:
dict- Dictionary that contains the key, value pairs.key- Key whose value should be returned.defaultValue- Default value to return if the key is undefined.- Returns:
- Returns the boolean value for key in dict.
-
getInt
public static int getInt(java.util.Map<java.lang.String,java.lang.Object> dict, java.lang.String key)Returns the value for key in dictionary as an int or 0 if no value is defined for the key.- Parameters:
dict- Dictionary that contains the key, value pairs.key- Key whose value should be returned.- Returns:
- Returns the integer value for key in dict.
-
getInt
public static int getInt(java.util.Map<java.lang.String,java.lang.Object> dict, java.lang.String key, int defaultValue)Returns the value for key in dictionary as an int or the given default value if no value is defined for the key.- Parameters:
dict- Dictionary that contains the key, value pairs.key- Key whose value should be returned.defaultValue- Default value to return if the key is undefined.- Returns:
- Returns the integer value for key in dict.
-
getFloat
public static float getFloat(java.util.Map<java.lang.String,java.lang.Object> dict, java.lang.String key)Returns the value for key in dictionary as a float or 0 if no value is defined for the key.- Parameters:
dict- Dictionary that contains the key, value pairs.key- Key whose value should be returned.- Returns:
- Returns the float value for key in dict.
-
getFloat
public static float getFloat(java.util.Map<java.lang.String,java.lang.Object> dict, java.lang.String key, float defaultValue)Returns the value for key in dictionary as a float or the given default value if no value is defined for the key.- Parameters:
dict- Dictionary that contains the key, value pairs.key- Key whose value should be returned.defaultValue- Default value to return if the key is undefined.- Returns:
- Returns the float value for key in dict.
-
getFloatArray
public static float[] getFloatArray(java.util.Map<java.lang.String,java.lang.Object> dict, java.lang.String key, float[] defaultValue)Returns the value for key in dictionary as a float array or the given default value if no value is defined for the key.- Parameters:
dict- Dictionary that contains the key, value pairs.key- Key whose value should be returned.defaultValue- Default value to return if the key is undefined.- Returns:
- Returns the float array value for key in dict.
-
getFloatArray
public static float[] getFloatArray(java.util.Map<java.lang.String,java.lang.Object> dict, java.lang.String key, float[] defaultValue, java.lang.String separator)Returns the value for key in dictionary as a float array or the given default value if no value is defined for the key.- Parameters:
dict- Dictionary that contains the key, value pairs.key- Key whose value should be returned.defaultValue- Default value to return if the key is undefined.- Returns:
- Returns the float array value for key in dict.
-
getDouble
public static double getDouble(java.util.Map<java.lang.String,java.lang.Object> dict, java.lang.String key)Returns the value for key in dictionary as a double or 0 if no value is defined for the key.- Parameters:
dict- Dictionary that contains the key, value pairs.key- Key whose value should be returned.- Returns:
- Returns the double value for key in dict.
-
getDouble
public static double getDouble(java.util.Map<java.lang.String,java.lang.Object> dict, java.lang.String key, double defaultValue)Returns the value for key in dictionary as a double or the given default value if no value is defined for the key.- Parameters:
dict- Dictionary that contains the key, value pairs.key- Key whose value should be returned.defaultValue- Default value to return if the key is undefined.- Returns:
- Returns the double value for key in dict.
-
getString
public static java.lang.String getString(java.util.Map<java.lang.String,java.lang.Object> dict, java.lang.String key)Returns the value for key in dictionary as a string or null if no value is defined for the key.- Parameters:
dict- Dictionary that contains the key, value pairs.key- Key whose value should be returned.- Returns:
- Returns the string value for key in dict.
-
getString
public static java.lang.String getString(java.util.Map<java.lang.String,java.lang.Object> dict, java.lang.String key, java.lang.String defaultValue)Returns the value for key in dictionary as a string or the given default value if no value is defined for the key.- Parameters:
dict- Dictionary that contains the key, value pairs.key- Key whose value should be returned.defaultValue- Default value to return if the key is undefined.- Returns:
- Returns the string value for key in dict.
-
getColor
public static java.awt.Color getColor(java.util.Map<java.lang.String,java.lang.Object> dict, java.lang.String key)Returns the value for key in dictionary as a color or null if no value is defined for the key.- Parameters:
dict- Dictionary that contains the key, value pairs.key- Key whose value should be returned.- Returns:
- Returns the color value for key in dict.
-
getColor
public static java.awt.Color getColor(java.util.Map<java.lang.String,java.lang.Object> dict, java.lang.String key, java.awt.Color defaultValue)Returns the value for key in dictionary as a color or the given default value if no value is defined for the key.- Parameters:
dict- Dictionary that contains the key, value pairs.key- Key whose value should be returned.defaultValue- Default value to return if the key is undefined.- Returns:
- Returns the color value for key in dict.
-
getFont
public static java.awt.Font getFont(java.util.Map<java.lang.String,java.lang.Object> style)
-
getFont
public static java.awt.Font getFont(java.util.Map<java.lang.String,java.lang.Object> style, double scale)
-
hexString
public static java.lang.String hexString(java.awt.Color color)
-
parseColor
public static java.awt.Color parseColor(java.lang.String colorString) throws java.lang.NumberFormatExceptionShortcut for parseColor with no transparency.- Throws:
java.lang.NumberFormatException
-
parseColor
public static java.awt.Color parseColor(java.lang.String colorString, double alpha) throws java.lang.NumberFormatExceptionConvert a string representing a 24/32bit hex color value into a Color object. The following color names are also supported: white, black, red, green, blue, orange, yellow, pink, turquoise, gray and none (null). Examples of possible hex color values are: #C3D9FF, #6482B9 and #774400, but note that you do not include the "#" in the string passed in- Parameters:
colorString- the 24/32bit hex string value (ARGB)- Returns:
- java.awt.Color (24bit RGB on JDK 1.1, 24/32bit ARGB on JDK1.2)
- Throws:
java.lang.NumberFormatException- if the specified string cannot be interpreted as a hexidecimal integer
-
getHexColorString
public static java.lang.String getHexColorString(java.awt.Color color)
Returns a hex representation for the given color.- Parameters:
color- Color to return the hex string for.- Returns:
- Returns a hex string for the given color.
-
parseDashPattern
public static float[] parseDashPattern(java.lang.String dashPatternString) throws java.lang.NumberFormatExceptionConvert a string representing a dash pattern into a float array. A valid dash pattern is a string of dash widths (floating point values) separated by space characters.- Parameters:
dashPatternString- the string representing the dash pattern- Returns:
- float[]
- Throws:
java.lang.NumberFormatException- if any of the dash widths cannot be interpreted as a floating point number
-
readFile
public static java.lang.String readFile(java.lang.String filename) throws java.io.IOExceptionReads the given filename into a string.- Parameters:
filename- Name of the file to be read.- Returns:
- Returns a string representing the file contents.
- Throws:
java.io.IOException
-
readInputStream
public static java.lang.String readInputStream(java.io.InputStream stream) throws java.io.IOExceptionReads the given filename into a string.- Parameters:
filename- Name of the file to be read.- Returns:
- Returns a string representing the file contents.
- Throws:
java.io.IOException
-
writeFile
public static void writeFile(java.lang.String contents, java.lang.String filename) throws java.io.IOExceptionWrites the given string into the given file.- Parameters:
contents- String representing the file contents.filename- Name of the file to be written.- Throws:
java.io.IOException
-
getMd5Hash
public static java.lang.String getMd5Hash(java.lang.String text)
Returns the Md5 hash for the given text.- Parameters:
text- String whose Md5 hash should be returned.- Returns:
- Returns the Md5 hash for the given text.
-
isNode
public static boolean isNode(java.lang.Object value, java.lang.String nodeName)Returns true if the user object is an XML node with the specified type and and the optional attribute has the specified value or is not specified.- Parameters:
value- Object that should be examined as a node.nodeName- String that specifies the node name.- Returns:
- Returns true if the node name of the user object is equal to the given type.
-
isNode
public static boolean isNode(java.lang.Object value, java.lang.String nodeName, java.lang.String attributeName, java.lang.String attributeValue)Returns true if the given value is an XML node with the node name and if the optional attribute has the specified value.- Parameters:
value- Object that should be examined as a node.nodeName- String that specifies the node name.attributeName- Optional attribute name to check.attributeValue- Optional attribute value to check.- Returns:
- Returns true if the value matches the given conditions.
-
setAntiAlias
public static void setAntiAlias(java.awt.Graphics2D g, boolean antiAlias, boolean textAntiAlias)- Parameters:
g-antiAlias-textAntiAlias-
-
clearRect
public static void clearRect(java.awt.Graphics2D g, java.awt.Rectangle rect, java.awt.Color background)Clears the given area of the specified graphics object with the given color or makes the region transparent.
-
createBufferedImage
public static java.awt.image.BufferedImage createBufferedImage(int w, int h, java.awt.Color background)Creates a buffered image for the given parameters. If there is not enough memory to create the image then a OutOfMemoryError is thrown.
-
createBufferedImage
public static java.awt.image.BufferedImage createBufferedImage(int w, int h, java.awt.Color background, int type)Creates a buffered image for the given parameters. If there is not enough memory to create the image then a OutOfMemoryError is thrown.
-
loadImage
public static java.awt.image.BufferedImage loadImage(java.lang.String url)
Loads an image from the local filesystem, a data URI or any other URL.
-
createTable
public static org.w3c.dom.Element createTable(org.w3c.dom.Document document, java.lang.String text, int x, int y, int w, int h, double scale, java.util.Map<java.lang.String,java.lang.Object> style)Creates a table for the given text using the given document to create the DOM nodes. Returns the outermost table node.
-
createDocument
public static org.w3c.dom.Document createDocument()
Deprecated.UsemxDomUtils.createDocument(Jan 2012)Returns a new, empty DOM document.- Returns:
- Returns a new DOM document.
-
createSvgDocument
public static org.w3c.dom.Document createSvgDocument(int width, int height)Deprecated.UsemxDomUtils.createSvgDocument(int, int)(Jan 2012)Creates a new SVG document for the given width and height.
-
createVmlDocument
public static org.w3c.dom.Document createVmlDocument()
Deprecated.UsemxDomUtils.createVmlDocument(Jan 2012)
-
createHtmlDocument
public static org.w3c.dom.Document createHtmlDocument()
Deprecated.UsemxDomUtils.createHtmlDocument(Jan 2012)Returns a document with a HTML node containing a HEAD and BODY node.
-
createHtmlDocument
public static java.lang.String createHtmlDocument(java.util.Map<java.lang.String,java.lang.Object> style, java.lang.String text)Returns a new, empty DOM document.- Returns:
- Returns a new DOM document.
-
createHtmlDocument
public static java.lang.String createHtmlDocument(java.util.Map<java.lang.String,java.lang.Object> style, java.lang.String text, double scale)Returns a new, empty DOM document.- Returns:
- Returns a new DOM document.
-
createHtmlDocument
public static java.lang.String createHtmlDocument(java.util.Map<java.lang.String,java.lang.Object> style, java.lang.String text, double scale, int width)Returns a new, empty DOM document.- Returns:
- Returns a new DOM document.
-
createHtmlDocument
public static java.lang.String createHtmlDocument(java.util.Map<java.lang.String,java.lang.Object> style, java.lang.String text, double scale, int width, java.lang.String head)Returns a new, empty DOM document. The head argument can be used to provide an optional HEAD section without the HEAD tags as follows:mxUtils.createHtmlDocument(style, text, 1, 0, "")
- Returns:
- Returns a new DOM document.
-
createHtmlDocument
public static java.lang.String createHtmlDocument(java.util.Map<java.lang.String,java.lang.Object> style, java.lang.String text, double scale, int width, java.lang.String head, java.lang.String bodyCss)Returns a new, empty DOM document. The head argument can be used to provide an optional HEAD section without the HEAD tags as follows:mxUtils.createHtmlDocument(style, text, 1, 0, "")
- Returns:
- Returns a new DOM document.
-
createHtmlDocumentObject
public static javax.swing.text.html.HTMLDocument createHtmlDocumentObject(java.util.Map<java.lang.String,java.lang.Object> style, double scale)Returns a new, empty DOM document.- Returns:
- Returns a new DOM document.
-
loadDocument
public static org.w3c.dom.Document loadDocument(java.lang.String uri)
Returns a new DOM document for the given URI. External entities and DTDs are ignored.- Parameters:
uri- URI to parse into the document.- Returns:
- Returns a new DOM document for the given URI.
-
parseXml
public static org.w3c.dom.Document parseXml(java.lang.String xml)
Deprecated.UsemxXmlUtils.parseXml(Jan 2012)Returns a new document for the given XML string.- Parameters:
xml- String that represents the XML data.- Returns:
- Returns a new XML document.
-
eval
public static java.lang.Object eval(java.lang.String expression)
Evaluates a Java expression as a class member using mxCodecRegistry. The range of supported expressions is limited to static class members such as mxEdgeStyle.ElbowConnector.
-
findNode
public static org.w3c.dom.Node findNode(org.w3c.dom.Node node, java.lang.String attr, java.lang.String value)Returns the first node where attr equals value. This implementation does not use XPath.
-
htmlEntities
public static java.lang.String htmlEntities(java.lang.String text)
Converts the ampersand, quote, prime, less-than and greater-than characters to their corresponding HTML entities in the given string.
-
getXml
public static java.lang.String getXml(org.w3c.dom.Node node)
Deprecated.UsemxXmlUtils.getXml(Node)(Jan 2012)Returns a string that represents the given node.- Parameters:
node- Node to return the XML for.- Returns:
- Returns an XML string.
-
getPrettyXml
public static java.lang.String getPrettyXml(org.w3c.dom.Node node)
Returns a pretty-printed XML string for the given node.- Parameters:
node- Node to return the XML for.- Returns:
- Returns a formatted XML string.
-
getPrettyXml
public static java.lang.String getPrettyXml(org.w3c.dom.Node node, java.lang.String tab, java.lang.String indent)Returns a pretty-printed XML string for the given node. Note that this string should only be used for humans to read (eg. debug output) but not for further processing as it does not use built-in mechanisms.- Parameters:
node- Node to return the XML for.tab- String to be used for indentation of inner nodes.indent- Current indentation for the node.- Returns:
- Returns a formatted XML string.
-
-