|
mxGraph 1.10.3.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.mxgraph.util.mxUtils
public class mxUtils
Contains various helper methods for use with mxGraph.
Field Summary | |
---|---|
protected static Graphics |
fontGraphics
Static Graphics used for Font Metrics. |
static boolean |
IS_MAC
True if the machine is a Mac. |
Constructor Summary | |
---|---|
mxUtils()
|
Method Summary | |
---|---|
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 void |
clearRect(Graphics2D g,
Rectangle rect,
Color background)
Clears the given area of the specified graphics object with the given color or makes the region transparent. |
static boolean |
contains(Object[] array,
Object obj)
Returns true if the given array contains the given object. |
static BufferedImage |
createBufferedImage(int w,
int h,
Color background)
Creates a buffered image for the given parameters. |
static Document |
createDocument()
Deprecated. Use mxDomUtils.createDocument (Jan 2012) |
static Document |
createHtmlDocument()
Deprecated. Use mxDomUtils.createHtmlDocument (Jan 2012) |
static String |
createHtmlDocument(Map<String,Object> style,
String text)
Returns a new, empty DOM document. |
static String |
createHtmlDocument(Map<String,Object> style,
String text,
double scale)
Returns a new, empty DOM document. |
static String |
createHtmlDocument(Map<String,Object> style,
String text,
double scale,
int width)
Returns a new, empty DOM document. |
static String |
createHtmlDocument(Map<String,Object> style,
String text,
double scale,
int width,
String head)
Returns a new, empty DOM document. |
static HTMLDocument |
createHtmlDocumentObject(Map<String,Object> style,
double scale)
Returns a new, empty DOM document. |
static Document |
createSvgDocument(int width,
int height)
Deprecated. Use mxDomUtils.createSvgDocument(int, int) (Jan 2012) |
static Element |
createTable(Document document,
String text,
int x,
int y,
int w,
int h,
double scale,
Map<String,Object> style)
Creates a table for the given text using the given document to create the DOM nodes. |
static Document |
createVmlDocument()
Deprecated. Use mxDomUtils.createVmlDocument (Jan 2012) |
static void |
drawImageClip(Graphics g,
BufferedImage image,
ImageObserver observer)
Draws the image inside the clip bounds to the given graphics object. |
static Object |
eval(String expression)
Evaluates a Java expression as a class member using mxCodecRegistry. |
static void |
fillClippedRect(Graphics g,
int x,
int y,
int width,
int height)
|
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. |
static Node |
findNode(Node node,
String attr,
String value)
Returns the first node where attr equals value. |
static int |
firstCharAt(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 String |
getBodyMarkup(String markup,
boolean replaceLinefeeds)
Returns the body part of the given HTML markup. |
static mxRectangle |
getBoundingBox(mxRectangle rect,
double rotation)
Returns the bounding box for the rotated rectangle. |
static Color |
getColor(Map<String,Object> dict,
String key)
Returns the value for key in dictionary as a color or null if no value is defined for the key. |
static Color |
getColor(Map<String,Object> dict,
String key,
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 double |
getDouble(Map<String,Object> dict,
String key)
Returns the value for key in dictionary as a double or 0 if no value is defined for the key. |
static double |
getDouble(Map<String,Object> dict,
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 float |
getFloat(Map<String,Object> dict,
String key)
Returns the value for key in dictionary as a float or 0 if no value is defined for the key. |
static float |
getFloat(Map<String,Object> dict,
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(Map<String,Object> dict,
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(Map<String,Object> dict,
String key,
float[] defaultValue,
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 Font |
getFont(Map<String,Object> style)
|
static Font |
getFont(Map<String,Object> style,
double scale)
|
static FontMetrics |
getFontMetrics(Font font)
Returns the font metrics of the static font graphics instance |
static String |
getHexColorString(Color color)
Returns a hex representation for the given color. |
static int |
getInt(Map<String,Object> dict,
String key)
Returns the value for key in dictionary as an int or 0 if no value is defined for the key. |
static int |
getInt(Map<String,Object> dict,
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 mxRectangle |
getLabelPaintBounds(String label,
Map<String,Object> style,
boolean isHtml,
mxPoint offset,
mxRectangle vertexBounds,
double scale)
Returns the paint bounds for the given label. |
static mxRectangle |
getLabelSize(String label,
Map<String,Object> style,
boolean isHtml,
double scale)
Returns the size for the given label. |
static mxRectangle |
getLabelSize(String label,
Map<String,Object> style,
boolean isHtml,
double scale,
double htmlWrapWidth)
Returns the size for the given label. |
static String |
getMd5Hash(String text)
Returns the Md5 hash for the given text. |
static int |
getPortConstraints(mxCellState terminal,
mxCellState edge,
boolean source)
Returns an integer mask of the port constraints of the given map |
static int |
getPortConstraints(mxCellState terminal,
mxCellState edge,
boolean source,
int defaultValue)
Returns an integer mask of the port constraints of the given map |
static String |
getPrettyXml(Node node)
Returns a pretty-printed XML string for the given node. |
static String |
getPrettyXml(Node node,
String tab,
String indent)
Returns a pretty-printed XML string for the given node. |
static mxPoint |
getRotatedPoint(mxPoint pt,
double cos,
double sin)
Rotates the given point by the given cos and sin. |
static mxPoint |
getRotatedPoint(mxPoint pt,
double cos,
double sin,
mxPoint c)
Rotates the given point by the given cos and sin. |
static mxRectangle |
getScaledLabelBounds(double x,
double y,
mxRectangle size,
double outerWidth,
double outerHeight,
Map<String,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 mxRectangle |
getSizeForHtml(String markup,
Map<String,Object> style,
double scale,
double wrapWidth)
Returns an mxRectangle with the size (width and height in pixels) of the given HTML markup. |
static mxRectangle |
getSizeForString(String text,
Font font,
double scale)
Returns an |
static String |
getString(Map<String,Object> dict,
String key)
Returns the value for key in dictionary as a string or null if no value is defined for the key. |
static String |
getString(Map<String,Object> dict,
String key,
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 String |
getStylename(String style)
Deprecated. Use mxStyleUtils.getStylename(String) (Jan 2012) |
static String[] |
getStylenames(String style)
Deprecated. Use mxStyleUtils.getStylenames(String) (Jan 2012) |
static String |
getXml(Node node)
Deprecated. Use mxXmlUtils.getXml(Node) (Jan 2012) |
static String |
hexString(Color color)
|
static String |
htmlEntities(String text)
Converts the ampersand, quote, prime, less-than and greater-than characters to their corresponding HTML entities in the given string. |
static int |
indexOf(Object[] array,
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 int |
indexOfStylename(String style,
String stylename)
Deprecated. Use mxStyleUtils.indexOfStylename(String, String) (Jan 2012) |
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. |
static boolean |
intersectsHotspot(mxCellState state,
int x,
int y,
double hotspot)
|
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. |
static boolean |
isNode(Object value,
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 boolean |
isNode(Object value,
String nodeName,
String attributeName,
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 boolean |
isTrue(Map<String,Object> dict,
String key)
Returns true if the dictionary contains true for the given key or false if no value is defined for the key. |
static boolean |
isTrue(Map<String,Object> dict,
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 Document |
loadDocument(String uri)
Returns a new DOM document for the given URI. |
static BufferedImage |
loadImage(String url)
Loads an image from the local filesystem, a data URI or any other URL. |
static Color |
parseColor(String colorString)
Convert a string representing a 24/32bit hex color value into a Color object. |
static Document |
parseXml(String xml)
Deprecated. Use mxXmlUtils.parseXml (Jan 2012) |
static String |
readFile(String filename)
Reads the given filename into a string. |
static String |
readInputStream(InputStream stream)
Reads the given filename into a string. |
static String |
removeAllStylenames(String style)
Deprecated. Use mxStyleUtils.removeAllStylenames(String) (Jan 2012) |
static int |
reversePortConstraints(int constraint)
|
static Node |
selectSingleNode(Document doc,
String expression)
Returns a single node that matches the given XPath expression. |
static void |
setAntiAlias(Graphics2D g,
boolean antiAlias,
boolean textAntiAlias)
|
static void |
setCellStyleFlags(mxIGraphModel model,
Object[] cells,
String key,
int flag,
Boolean value)
Deprecated. Use mxStyleUtils.setCellStyleFlags(mxIGraphModel, Object[],String, int, Boolean) (Jan 2012) |
static void |
setCellStyles(mxIGraphModel model,
Object[] cells,
String key,
String value)
Deprecated. Use mxStyleUtils.setCellStyles(mxIGraphModel, Object[], String, String) (Jan 2012) |
static String |
setStyle(String style,
String key,
String value)
Deprecated. Use mxStyleUtils.setStyle(String, String, String) (Jan 2012) |
static String |
setStyleFlag(String style,
String key,
int flag,
Boolean value)
Deprecated. Use mxStyleUtils.setStyleFlag(String, String, int, Boolean) (Jan 2012) |
static Collection<Object> |
sortCells(Collection<Object> cells,
boolean ascending)
Sorts the given cells according to the order in the cell hierarchy. |
static Object[] |
sortCells(Object[] cells,
boolean ascending)
Sorts the given cells according to the order in the cell hierarchy. |
static List<mxPoint> |
translatePoints(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 String[] |
wordWrap(String text,
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 |
static void |
writeFile(String contents,
String filename)
Writes the given string into the given file. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static boolean IS_MAC
protected static transient Graphics fontGraphics
Constructor Detail |
---|
public mxUtils()
Method Detail |
---|
public static mxRectangle getLabelSize(String label, Map<String,Object> style, boolean isHtml, double scale)
public static mxRectangle getLabelSize(String label, Map<String,Object> style, boolean isHtml, double scale, double htmlWrapWidth)
public static String getBodyMarkup(String markup, boolean replaceLinefeeds)
public static mxRectangle getLabelPaintBounds(String label, Map<String,Object> style, boolean isHtml, mxPoint offset, mxRectangle vertexBounds, double scale)
public static mxRectangle getScaledLabelBounds(double x, double y, mxRectangle size, double outerWidth, double outerHeight, Map<String,Object> style, double scale)
public static FontMetrics getFontMetrics(Font font)
font
- The font whose metrics are to be returned
public static mxRectangle getSizeForString(String text, Font font, double scale)
text
- String whose size should be returned.font
- Font to be used for the computation.public static String[] wordWrap(String text, FontMetrics metrics, double width)
text
- the text to wrapmetrics
- the font metrics to calculate the text size forwidth
- the width that the text must fit within
public static mxRectangle getSizeForHtml(String markup, Map<String,Object> style, double scale, double wrapWidth)
markup
- HTML markup whose size should be returned.public static double[] arcToCurves(double x0, double y0, double r1, double r2, double angle, double largeArcFlag, double sweepFlag, double x, double y)
public static mxRectangle getBoundingBox(mxRectangle rect, double rotation)
public static int firstCharAt(String text, int inputChar, int fromIndex)
text
- the string to test for the presence of the input characterinputChar
- the test characterfromIndex
- the index position of the string to start from
public static mxPoint getRotatedPoint(mxPoint pt, double cos, double sin)
public static int findNearestSegment(mxCellState state, double x, double y)
public static mxPoint getRotatedPoint(mxPoint pt, double cos, double sin, mxPoint c)
public static int getPortConstraints(mxCellState terminal, mxCellState edge, boolean source)
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
public static int getPortConstraints(mxCellState terminal, mxCellState edge, boolean source, int defaultValue)
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.
public static int reversePortConstraints(int constraint)
public static void drawImageClip(Graphics g, BufferedImage image, ImageObserver observer)
public static void fillClippedRect(Graphics g, int x, int y, int width, int height)
public static List<mxPoint> translatePoints(List<mxPoint> pts, double dx, double dy)
public static mxPoint intersection(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3)
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.
public static Object[] sortCells(Object[] cells, boolean ascending)
public static Collection<Object> sortCells(Collection<Object> cells, boolean ascending)
public static boolean contains(Object[] array, Object obj)
public static int indexOf(Object[] array, Object obj)
public static String getStylename(String style)
mxStyleUtils.getStylename(String)
(Jan 2012)
style
- String of the form stylename[;key=value].
public static String[] getStylenames(String style)
mxStyleUtils.getStylenames(String)
(Jan 2012)
style
- String of the form stylename[;stylename][;key=value].
public static int indexOfStylename(String style, String stylename)
mxStyleUtils.indexOfStylename(String, String)
(Jan 2012)
public static String removeAllStylenames(String style)
mxStyleUtils.removeAllStylenames(String)
(Jan 2012)
public static void setCellStyles(mxIGraphModel model, Object[] cells, String key, String value)
mxStyleUtils.setCellStyles(mxIGraphModel, Object[], String, String)
(Jan 2012)
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.public static String setStyle(String style, String key, String value)
mxStyleUtils.setStyle(String, String, String)
(Jan 2012)
style
- String of the form stylename[;key=value]
.key
- Key of the style to be changed.value
- New value for the given key.
public static void setCellStyleFlags(mxIGraphModel model, Object[] cells, String key, int flag, Boolean value)
mxStyleUtils.setCellStyleFlags(mxIGraphModel, Object[],String, int, Boolean)
(Jan 2012)
mxUtils.setCellStyleFlags(graph.getModel(),
cells,
mxConstants.STYLE_FONTSTYLE,
mxConstants.FONT_BOLD, null);
Toggles the bold font style.
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.public static String setStyleFlag(String style, String key, int flag, Boolean value)
mxStyleUtils.setStyleFlag(String, String, int, Boolean)
(Jan 2012)
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.public static boolean intersectsHotspot(mxCellState state, int x, int y, double hotspot)
public static boolean intersectsHotspot(mxCellState state, int x, int y, double hotspot, int min, int max)
public static boolean isTrue(Map<String,Object> dict, String key)
dict
- Dictionary that contains the key, value pairs.key
- Key whose value should be returned.
public static boolean isTrue(Map<String,Object> dict, String key, boolean defaultValue)
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.
public static int getInt(Map<String,Object> dict, String key)
dict
- Dictionary that contains the key, value pairs.key
- Key whose value should be returned.
public static int getInt(Map<String,Object> dict, String key, int defaultValue)
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.
public static float getFloat(Map<String,Object> dict, String key)
dict
- Dictionary that contains the key, value pairs.key
- Key whose value should be returned.
public static float getFloat(Map<String,Object> dict, String key, float defaultValue)
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.
public static float[] getFloatArray(Map<String,Object> dict, String key, float[] defaultValue)
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.
public static float[] getFloatArray(Map<String,Object> dict, String key, float[] defaultValue, String separator)
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.
public static double getDouble(Map<String,Object> dict, String key)
dict
- Dictionary that contains the key, value pairs.key
- Key whose value should be returned.
public static double getDouble(Map<String,Object> dict, String key, double defaultValue)
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.
public static String getString(Map<String,Object> dict, String key)
dict
- Dictionary that contains the key, value pairs.key
- Key whose value should be returned.
public static String getString(Map<String,Object> dict, String key, String defaultValue)
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.
public static Color getColor(Map<String,Object> dict, String key)
dict
- Dictionary that contains the key, value pairs.key
- Key whose value should be returned.
public static Color getColor(Map<String,Object> dict, String key, Color defaultValue)
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.
public static Font getFont(Map<String,Object> style)
public static Font getFont(Map<String,Object> style, double scale)
public static String hexString(Color color)
public static Color parseColor(String colorString) throws NumberFormatException
colorString
- the 24/32bit hex string value (ARGB)
NumberFormatException
- if the specified string cannot be interpreted as a
hexidecimal integerpublic static String getHexColorString(Color color)
color
- Color to return the hex string for.
public static String readFile(String filename) throws IOException
filename
- Name of the file to be read.
IOException
public static String readInputStream(InputStream stream) throws IOException
filename
- Name of the file to be read.
IOException
public static void writeFile(String contents, String filename) throws IOException
contents
- String representing the file contents.filename
- Name of the file to be written.
IOException
public static String getMd5Hash(String text)
text
- String whose Md5 hash should be returned.
public static boolean isNode(Object value, String nodeName)
value
- Object that should be examined as a node.nodeName
- String that specifies the node name.
public static boolean isNode(Object value, String nodeName, String attributeName, String attributeValue)
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.
public static void setAntiAlias(Graphics2D g, boolean antiAlias, boolean textAntiAlias)
g
- antiAlias
- textAntiAlias
- public static void clearRect(Graphics2D g, Rectangle rect, Color background)
public static BufferedImage createBufferedImage(int w, int h, Color background) throws OutOfMemoryError
OutOfMemoryError
public static BufferedImage loadImage(String url)
public static Element createTable(Document document, String text, int x, int y, int w, int h, double scale, Map<String,Object> style)
public static Document createDocument()
mxDomUtils.createDocument
(Jan 2012)
public static Document createSvgDocument(int width, int height)
mxDomUtils.createSvgDocument(int, int)
(Jan 2012)
public static Document createVmlDocument()
mxDomUtils.createVmlDocument
(Jan 2012)
public static Document createHtmlDocument()
mxDomUtils.createHtmlDocument
(Jan 2012)
public static String createHtmlDocument(Map<String,Object> style, String text)
public static String createHtmlDocument(Map<String,Object> style, String text, double scale)
public static String createHtmlDocument(Map<String,Object> style, String text, double scale, int width)
public static String createHtmlDocument(Map<String,Object> style, String text, double scale, int width, String head)
mxUtils.createHtmlDocument(style, text, 1, 0, "")
public static HTMLDocument createHtmlDocumentObject(Map<String,Object> style, double scale)
public static Document loadDocument(String uri)
uri
- URI to parse into the document.
public static Document parseXml(String xml)
mxXmlUtils.parseXml
(Jan 2012)
xml
- String that represents the XML data.
public static Object eval(String expression)
public static Node findNode(Node node, String attr, String value)
public static Node selectSingleNode(Document doc, String expression)
doc
- Document that contains the nodes.expression
- XPath expression to be matched.
public static String htmlEntities(String text)
public static String getXml(Node node)
mxXmlUtils.getXml(Node)
(Jan 2012)
node
- Node to return the XML for.
public static String getPrettyXml(Node node)
node
- Node to return the XML for.
public static String getPrettyXml(Node node, String tab, String indent)
node
- Node to return the XML for.tab
- String to be used for indentation of inner nodes.indent
- Current indentation for the node.
|
mxGraph 1.10.3.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |