mxGraph
Public Member Functions | Static Public Member Functions | List of all members
com.mxgraph.mxUtils Class Reference

Contains various helper methods for use with mxGraph. More...

Public Member Functions

String AddStylename (String style, String stylename)
 Adds the specified stylename to the given style if it does not already contain the stylename. More...
 
String RemoveStylename (String style, String stylename)
 Removes all occurrences of the specified stylename in the given style and returns the updated style. More...
 

Static Public Member Functions

static mxRectangle GetLabelSize (string label, Dictionary< string, Object > style, int width)
 Returns the size of the given label. More...
 
static mxRectangle GetLabelPaintBounds (String label, Dictionary< string, Object > style, bool isHtml, mxPoint offset, mxRectangle vertexBounds, double scale)
 Returns the paint bounds for the given label. More...
 
static mxRectangle GetScaledLabelBounds (double x, double y, mxRectangle size, double outerWidth, double outerHeight, Dictionary< 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. (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. More...
 
static mxRectangle GetSizeForString (String text, Font font)
 Returns the size of the given text. More...
 
static mxRectangle GetSizeForString (String text, Font font, int width)
 Returns an mxRectangle with the size (width and height in pixels) of the given text. More...
 
static double ToRadians (double deg)
 Converts the given degree to radians. More...
 
static double[] ArcToCurves (double x0, double y0, double r1, double r2, double angle, double largeArcFlag, double sweepFlag, double x, double y)
 Converts the given arc to a series of curves. More...
 
static mxRectangle GetBoundingBox (mxRectangle rect, double rotation)
 Returns the bounding box of the rotated rectangle. More...
 
static mxPoint GetRotatedPoint (mxPoint pt, double cos, double sin)
 Rotates the given point by the given cos and sin. More...
 
static mxPoint GetRotatedPoint (mxPoint pt, double cos, double sin, mxPoint c)
 Rotates the given point by the given cos and sin. More...
 
static void FillClippedRect (Graphics g, Brush brush, int x, int y, int width, int height)
 
static Image CreateImage (int width, int height, Color?background)
 Creates an image for the given parameters. More...
 
static List< mxPointTranslatePoints (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. More...
 
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. More...
 
static String GetStylename (String style)
 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. More...
 
static String[] GetStylenames (String style)
 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. More...
 
static int IndexOfStylename (String style, String stylename)
 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. More...
 
static String RemoveAllStylenames (String style)
 Removes all stylenames from the given style and returns the updated style. More...
 
static void SetCellStyles (mxIGraphModel model, Object[] cells, String key, String value)
 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. More...
 
static String SetStyle (String style, String key, String value)
 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. More...
 
static void SetCellStyleFlags (mxIGraphModel model, Object[] cells, String key, int flag, Boolean value)
 Sets or toggles the flag bit for the given key in the cell's styles. If value is null then the flag is toggled. More...
 
static String SetStyleFlag (String style, String key, int flag, bool?value)
 Sets or removes the given key from the specified style and returns the new style. If value is null then the flag is toggled. More...
 
static bool IsTrue (Dictionary< 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. More...
 
static bool IsTrue (Dictionary< string, Object > dict, string key, bool 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. More...
 
static int GetInt (Dictionary< 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. More...
 
static int GetInt (Dictionary< 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. More...
 
static float GetFloat (Dictionary< 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. More...
 
static float GetFloat (Dictionary< 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. More...
 
static double GetDouble (Dictionary< 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. More...
 
static double GetDouble (Dictionary< 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. More...
 
static string GetString (Dictionary< 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. More...
 
static string GetString (Dictionary< 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. More...
 
static Color GetColor (Dictionary< 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. More...
 
static Color GetColor (Dictionary< 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. More...
 
static Font GetFont (Dictionary< string, Object > style)
 
static Font GetFont (Dictionary< string, Object > style, double scale)
 
static StringFormat GetStringFormat (Dictionary< string, Object > style)
 Creates a new StringFormat object for the given style. More...
 
static string ReadFile (string filename)
 Reads the given filename into a string. More...
 
static string GetMd5Hash (string text)
 Returns the Md5 hash for the given text. More...
 
static bool IsNode (Object value, String nodeName)
 Returns true if the given value is an XML node with the specified nodename. specified. More...
 
static bool IsNode (Object value, String nodeName, String attributeName, String attributeValue)
 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. More...
 
static Image LoadImage (String url)
 Loads an image from the local filesystem, a data URI or any other URL. More...
 
static XmlDocument CreateDocument ()
 Returns a new, empty DOM document. More...
 
static XmlDocument LoadDocument (string uri)
 Returns a new DOM document for the given URI. More...
 
static XmlDocument ParseXml (string xml)
 Returns a document that represents the given XML string. More...
 
static XmlNode FindNode (XmlNode node, String attr, String value)
 Returns the first node where attr equals value. This implementation does not use XPath. More...
 
static Object Eval (string expression)
 Evaluates a Java expression to a class member using mxCodecRegistry. The range of supported expressions is limited to static class members such as mxEdgeStyle.ElbowConnector. More...
 
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. More...
 
static string GetXml (XmlNode node)
 Returns a string that represents the given node. More...
 
static string GetPrettyXml (XmlNode node)
 Returns a pretty-printed XML string for the given node. More...
 
static string GetXml (XmlNode node, Formatting formatting)
 Returns a pretty-printed XML string for the given node. More...
 

Detailed Description

Contains various helper methods for use with mxGraph.

Member Function Documentation

String com.mxgraph.mxUtils.AddStylename ( String  style,
String  stylename 
)
inline

Adds the specified stylename to the given style if it does not already contain the stylename.

Parameters
style
stylename
Returns
static double [] com.mxgraph.mxUtils.ArcToCurves ( double  x0,
double  y0,
double  r1,
double  r2,
double  angle,
double  largeArcFlag,
double  sweepFlag,
double  x,
double  y 
)
inlinestatic

Converts the given arc to a series of curves.

Parameters
x0
y0
r1
r2
angle
largeArcFlag
sweepFlag
x
y
Returns

Referenced by com.mxgraph.mxStencil.DrawElement().

static XmlDocument com.mxgraph.mxUtils.CreateDocument ( )
inlinestatic

Returns a new, empty DOM document.

Returns
Returns a new DOM document.

Referenced by com.mxgraph.mxCodec.mxCodec().

static Image com.mxgraph.mxUtils.CreateImage ( int  width,
int  height,
Color?  background 
)
inlinestatic

Creates an image for the given parameters.

Parameters
width
height
background
Returns

Referenced by com.mxgraph.mxImageCanvas.mxImageCanvas().

static Object com.mxgraph.mxUtils.Eval ( string  expression)
inlinestatic

Evaluates a Java expression to a class member using mxCodecRegistry. The range of supported expressions is limited to static class members such as mxEdgeStyle.ElbowConnector.

Parameters
expression
Returns

References com.mxgraph.mxCodecRegistry.GetTypeForName().

Referenced by com.mxgraph.mxStylesheetCodec.Decode(), com.mxgraph.mxGraphView.GetEdgeStyle(), and com.mxgraph.mxGraphView.GetPerimeterFunction().

static void com.mxgraph.mxUtils.FillClippedRect ( Graphics  g,
Brush  brush,
int  x,
int  y,
int  width,
int  height 
)
inlinestatic

Parameters
g
brush
x
y
width
height
static XmlNode com.mxgraph.mxUtils.FindNode ( XmlNode  node,
String  attr,
String  value 
)
inlinestatic

Returns the first node where attr equals value. This implementation does not use XPath.

static mxRectangle com.mxgraph.mxUtils.GetBoundingBox ( mxRectangle  rect,
double  rotation 
)
inlinestatic
static Color com.mxgraph.mxUtils.GetColor ( Dictionary< string, Object >  dict,
string  key 
)
inlinestatic

Returns the value for key in dictionary as a color or null if no value is defined for the key.

Parameters
dictDictionary that contains the key, value pairs.
keyKey whose value should be returned.
Returns
Returns the color value for key in dict.

Referenced by com.mxgraph.mxGdiCanvas.DrawLine(), com.mxgraph.mxGdiCanvas.DrawShape(), and com.mxgraph.mxGdiCanvas.DrawText().

static Color com.mxgraph.mxUtils.GetColor ( Dictionary< string, Object >  dict,
string  key,
Color?  defaultValue 
)
inlinestatic

Returns the value for key in dictionary as a color or the given default value if no value is defined for the key.

Parameters
dictDictionary that contains the key, value pairs.
keyKey whose value should be returned.
defaultValueDefault value to return if the key is undefined.
Returns
Returns the color value for key in dict.
static double com.mxgraph.mxUtils.GetDouble ( Dictionary< string, Object >  dict,
string  key 
)
inlinestatic
static double com.mxgraph.mxUtils.GetDouble ( Dictionary< string, Object >  dict,
string  key,
double  defaultValue 
)
inlinestatic

Returns the value for key in dictionary as a double or the given default value if no value is defined for the key.

Parameters
dictDictionary that contains the key, value pairs.
keyKey whose value should be returned.
defaultValueDefault value to return if the key is undefined.
Returns
Returns the double value for key in dict.
static float com.mxgraph.mxUtils.GetFloat ( Dictionary< string, Object >  dict,
string  key 
)
inlinestatic

Returns the value for key in dictionary as a float or 0 if no value is defined for the key.

Parameters
dictDictionary that contains the key, value pairs.
keyKey whose value should be returned.
Returns
Returns the float value for key in dict.

Referenced by com.mxgraph.mxGdiCanvas.DrawCell(), com.mxgraph.mxGdiCanvas.DrawGlassEffect(), com.mxgraph.mxGdiCanvas.DrawLine(), com.mxgraph.mxGdiCanvas.DrawShape(), com.mxgraph.mxGdiCanvas.DrawText(), com.mxgraph.mxGraphView.GetRoutingCenterX(), and com.mxgraph.mxGraphView.GetRoutingCenterY().

static float com.mxgraph.mxUtils.GetFloat ( Dictionary< string, Object >  dict,
string  key,
float  defaultValue 
)
inlinestatic

Returns the value for key in dictionary as a float or the given default value if no value is defined for the key.

Parameters
dictDictionary that contains the key, value pairs.
keyKey whose value should be returned.
defaultValueDefault value to return if the key is undefined.
Returns
Returns the float value for key in dict.
static Font com.mxgraph.mxUtils.GetFont ( Dictionary< string, Object >  style)
inlinestatic

Parameters
style
Returns

Referenced by com.mxgraph.mxGdiCanvas.DrawText().

static Font com.mxgraph.mxUtils.GetFont ( Dictionary< string, Object >  style,
double  scale 
)
inlinestatic
static int com.mxgraph.mxUtils.GetInt ( Dictionary< string, Object >  dict,
string  key 
)
inlinestatic

Returns the value for key in dictionary as an int or 0 if no value is defined for the key.

Parameters
dictDictionary that contains the key, value pairs.
keyKey whose value should be returned.
Returns
Returns the integer value for key in dict.

Referenced by com.mxgraph.mxGdiCanvas.DrawShape(), and com.mxgraph.mxGraphView.UpdateBoundingBox().

static int com.mxgraph.mxUtils.GetInt ( Dictionary< string, Object >  dict,
string  key,
int  defaultValue 
)
inlinestatic

Returns the value for key in dictionary as an int or the given default value if no value is defined for the key.

Parameters
dictDictionary that contains the key, value pairs.
keyKey whose value should be returned.
defaultValueDefault value to return if the key is undefined.
Returns
Returns the integer value for key in dict.
static mxRectangle com.mxgraph.mxUtils.GetLabelPaintBounds ( String  label,
Dictionary< string, Object >  style,
bool  isHtml,
mxPoint  offset,
mxRectangle  vertexBounds,
double  scale 
)
inlinestatic
static mxRectangle com.mxgraph.mxUtils.GetLabelSize ( string  label,
Dictionary< string, Object >  style,
int  width 
)
inlinestatic

Returns the size of the given label.

Referenced by com.mxgraph.mxUtils.GetLabelPaintBounds().

static string com.mxgraph.mxUtils.GetMd5Hash ( string  text)
inlinestatic

Returns the Md5 hash for the given text.

Parameters
textString whose Md5 hash should be returned.
Returns
Returns the Md5 hash for the given text.
static string com.mxgraph.mxUtils.GetPrettyXml ( XmlNode  node)
inlinestatic

Returns a pretty-printed XML string for the given node.

Parameters
nodeNode to return the XML for.
Returns
Returns a formatted XML string.
static mxPoint com.mxgraph.mxUtils.GetRotatedPoint ( mxPoint  pt,
double  cos,
double  sin 
)
inlinestatic

Rotates the given point by the given cos and sin.

Referenced by com.mxgraph.mxStencil.DrawShadow().

static mxPoint com.mxgraph.mxUtils.GetRotatedPoint ( mxPoint  pt,
double  cos,
double  sin,
mxPoint  c 
)
inlinestatic

Rotates the given point by the given cos and sin.

References com.mxgraph.mxPoint.X, and com.mxgraph.mxPoint.Y.

static mxRectangle com.mxgraph.mxUtils.GetScaledLabelBounds ( double  x,
double  y,
mxRectangle  size,
double  outerWidth,
double  outerHeight,
Dictionary< string, Object >  style,
double  scale 
)
inlinestatic
static mxRectangle com.mxgraph.mxUtils.GetSizeForString ( String  text,
Font  font 
)
inlinestatic

Returns the size of the given text.

Parameters
textString whose size should be returned.
fontSpecifies the font that should be used.
Returns
Returns the size of the given text.
static mxRectangle com.mxgraph.mxUtils.GetSizeForString ( String  text,
Font  font,
int  width 
)
inlinestatic

Returns an mxRectangle with the size (width and height in pixels) of the given text.

Parameters
textString whose size should be returned.
fontSpecifies the font that should be used.
widthSpecifies the width of the text block for word wrapping.
Returns
Returns the size of the given text.
static string com.mxgraph.mxUtils.GetString ( Dictionary< string, Object >  dict,
string  key 
)
inlinestatic
static string com.mxgraph.mxUtils.GetString ( Dictionary< string, Object >  dict,
string  key,
string  defaultValue 
)
inlinestatic

Returns the value for key in dictionary as a string or the given default value if no value is defined for the key.

Parameters
dictDictionary that contains the key, value pairs.
keyKey whose value should be returned.
defaultValueDefault value to return if the key is undefined.
Returns
Returns the string value for key in dict.
static StringFormat com.mxgraph.mxUtils.GetStringFormat ( Dictionary< string, Object >  style)
inlinestatic
static String com.mxgraph.mxUtils.GetStylename ( String  style)
inlinestatic

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
styleString of the form stylename[;key=value].
Returns
Returns the stylename from the given formatted string.
static String [] com.mxgraph.mxUtils.GetStylenames ( String  style)
inlinestatic

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
styleString of the form stylename[;stylename][;key=value].
Returns
Returns the stylename from the given formatted string.
static string com.mxgraph.mxUtils.GetXml ( XmlNode  node)
inlinestatic

Returns a string that represents the given node.

Parameters
nodeNode to return the XML for.
Returns
Returns an XML string.
static string com.mxgraph.mxUtils.GetXml ( XmlNode  node,
Formatting  formatting 
)
inlinestatic

Returns a pretty-printed XML string for the given node.

Parameters
nodeNode to return the XML for.
formattingFormatting of the string to be returned.
Returns
Returns a formatted XML string.
static String com.mxgraph.mxUtils.HtmlEntities ( String  text)
inlinestatic

Converts the ampersand, quote, prime, less-than and greater-than characters to their corresponding HTML entities in the given string.

Parameters
text
Returns
static int com.mxgraph.mxUtils.IndexOfStylename ( String  style,
String  stylename 
)
inlinestatic

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.

Parameters
style
stylename
Returns
static mxPoint com.mxgraph.mxUtils.Intersection ( double  x0,
double  y0,
double  x1,
double  y1,
double  x2,
double  y2,
double  x3,
double  y3 
)
inlinestatic

Returns the intersection of two lines as an mxPoint.

Parameters
x0X-coordinate of the first line's startpoint.
y0Y-coordinate of the first line's startpoint.
x1X-coordinate of the first line's endpoint.
y1Y-coordinate of the first line's endpoint.
x2X-coordinate of the second line's startpoint.
y2Y-coordinate of the second line's startpoint.
x3X-coordinate of the second line's endpoint.
y3Y-coordinate of the second line's endpoint.
Returns
static bool com.mxgraph.mxUtils.IsNode ( Object  value,
String  nodeName 
)
inlinestatic

Returns true if the given value is an XML node with the specified nodename. specified.

Parameters
valueObject that represents the value to be tested.
nodeNameString that specifies the node name.
Returns
Returns true if the node name of the user object is equal to the given type.
static bool com.mxgraph.mxUtils.IsNode ( Object  value,
String  nodeName,
String  attributeName,
String  attributeValue 
)
inlinestatic

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
valueObject that represents the value to be tested.
nodeNameString that specifies the node name.
attributeNameOptional attribute name to check.
attributeValueOptional attribute value to check.
Returns
Returns true if the cell matches the given conditions.
static bool com.mxgraph.mxUtils.IsTrue ( Dictionary< string, Object >  dict,
string  key 
)
inlinestatic
static bool com.mxgraph.mxUtils.IsTrue ( Dictionary< string, Object >  dict,
string  key,
bool  defaultValue 
)
inlinestatic

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
dictDictionary that contains the key, value pairs.
keyKey whose value should be returned.
defaultValueDefault value to return if the key is undefined.
Returns
Returns the boolean value for key in dict.
static XmlDocument com.mxgraph.mxUtils.LoadDocument ( string  uri)
inlinestatic

Returns a new DOM document for the given URI.

Parameters
uriURI to parse into the document.
Returns
Returns a new DOM document for the given URI.

Referenced by com.mxgraph.mxObjectCodec.ProcessInclude().

static Image com.mxgraph.mxUtils.LoadImage ( String  url)
inlinestatic

Loads an image from the local filesystem, a data URI or any other URL.

Referenced by com.mxgraph.mxGdiCanvas.LoadImage(), and com.mxgraph.mxGdiCanvas2D.LoadImage().

static XmlDocument com.mxgraph.mxUtils.ParseXml ( string  xml)
inlinestatic

Returns a document that represents the given XML string.

Parameters
xmlString that contains the XML markup.
Returns
Returns an XML document.
static string com.mxgraph.mxUtils.ReadFile ( string  filename)
inlinestatic

Reads the given filename into a string.

Parameters
filenameName of the file to be read.
Returns
Returns a string representing the file contents.
static String com.mxgraph.mxUtils.RemoveAllStylenames ( String  style)
inlinestatic

Removes all stylenames from the given style and returns the updated style.

Parameters
style
Returns
String com.mxgraph.mxUtils.RemoveStylename ( String  style,
String  stylename 
)
inline

Removes all occurrences of the specified stylename in the given style and returns the updated style.

Parameters
style
stylename
Returns
static void com.mxgraph.mxUtils.SetCellStyleFlags ( mxIGraphModel  model,
Object[]  cells,
String  key,
int  flag,
Boolean  value 
)
inlinestatic

Sets or toggles the flag bit for the given key in the cell's styles. If value is null then the flag is toggled.

Parameters
modelModel that contains the cells.
cellsArray of cells to change the style for.
keyKey of the style to be changed.
flagInteger for the bit to be changed.
valueOptional boolean value for the flag.

References com.mxgraph.mxIGraphModel.BeginUpdate(), com.mxgraph.mxIGraphModel.EndUpdate(), com.mxgraph.mxIGraphModel.GetStyle(), and com.mxgraph.mxIGraphModel.SetStyle().

static void com.mxgraph.mxUtils.SetCellStyles ( mxIGraphModel  model,
Object[]  cells,
String  key,
String  value 
)
inlinestatic

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
modelModel to execute the transaction in.
cellsArray of cells to be updated.
keyKey of the style to be changed.
valueNew value for the given key.

References com.mxgraph.mxIGraphModel.BeginUpdate(), com.mxgraph.mxIGraphModel.EndUpdate(), com.mxgraph.mxIGraphModel.GetStyle(), and com.mxgraph.mxIGraphModel.SetStyle().

Referenced by com.mxgraph.mxGraph.SetCellStyles().

static String com.mxgraph.mxUtils.SetStyle ( String  style,
String  key,
String  value 
)
inlinestatic

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
styleString of the form stylename[;key=value].
keyKey of the style to be changed.
valueNew value for the given key.
Returns
Returns the new style.
static String com.mxgraph.mxUtils.SetStyleFlag ( String  style,
String  key,
int  flag,
bool?  value 
)
inlinestatic

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
styleString of the form stylename[;key=value].
keyKey of the style to be changed.
flagInteger for the bit to be changed.
valueOptional boolean value for the given flag.
Returns
Returns the new style.
static double com.mxgraph.mxUtils.ToRadians ( double  deg)
inlinestatic

Converts the given degree to radians.

static List<mxPoint> com.mxgraph.mxUtils.TranslatePoints ( List< mxPoint pts,
double  dx,
double  dy 
)
inlinestatic

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.

Parameters
pts
dx
dy
Returns

References com.mxgraph.mxPoint.Clone(), com.mxgraph.mxPoint.X, and com.mxgraph.mxPoint.Y.


The documentation for this class was generated from the following file: