Package net.sf.jaxodraw.util
Class JaxoUtils
- java.lang.Object
-
- net.sf.jaxodraw.util.JaxoUtils
-
public final class JaxoUtils extends java.lang.ObjectSome static utility methods.- Since:
- 2.0
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringLINE_SEPARATORThe system-dependent line separator.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voiddrawImageArea(java.awt.Image m, int x, int y, int width, int height, java.awt.Graphics g)Draw the part (x,y,width,height) of the image 'm' on 'g', at the same position (x,y).static voiddrawImageArea(java.awt.Image m, int x, int y, int width, int height, java.awt.Graphics g, int gx, int gy)Draw the part (x,y,width,height) of the image 'm' on 'g' at (gx,gy).static booleanequal(float a, float b)Compares the two floats.static booleanequal(float a, float b, float epsilon)Compares the two floats within a certain accuracy.static booleanequals(java.lang.Object[] expected, java.lang.Object[] actual)Check if two arrays are equal.static booleanequivalent(java.lang.Object[] expected, java.lang.Object[] actual)Check if two arrays are equivalent.static java.awt.ImagegetChooserImage(java.awt.Color iconColor)Returns an image with a box of 40x15 pixels size, of the given color.static java.awt.ImagegetChooserImage(java.awt.Color iconColor, java.awt.Dimension size)Returns an image with a box of the given pixels size, of the given color.static javax.swing.ImageIcongetChooserImageIcon(java.awt.Color iconColor)Returns an image icon with a box of 40x15 pixels size, of the given color.static javax.swing.ImageIcongetChooserImageIcon(java.awt.Color iconColor, java.awt.Dimension size)Returns an image icon with a box of the given pixels size, of the given color.static booleanisButton1(java.awt.event.MouseEvent e)Check for button 1 mouse events.static booleanisButton2(java.awt.event.MouseEvent e)Check for button 2 mouse events.static booleanisButton3(java.awt.event.MouseEvent e)Check for button 3 mouse events.static booleanisDoubleClick(java.awt.event.MouseEvent e)Check for double click mouse events.static java.awt.ImagenewImage(java.lang.String resourceName)Image from /resources/icons/ icon resource.static javax.swing.ImageIconnewImageIcon(java.lang.String resourceName)ImageIcon from /resources/icons/ icon resource.static java.lang.StringtoString(java.lang.Object[] array)This is intended to be equivalent toArrays.toString(a)but also compatible with JDK 1.4.static booleanzero(double a)Checks if the given double is zero.
-
-
-
Method Detail
-
equal
public static boolean equal(float a, float b, float epsilon)Compares the two floats within a certain accuracy.- Parameters:
a- First float to compare.b- Second float to compare.epsilon- the desired accuracy. Has to be non-negative.- Returns:
- True if the floats are equal to within the given accuracy.
-
equal
public static boolean equal(float a, float b)Compares the two floats.- Parameters:
a- First float to compare.b- Second float to compare.- Returns:
- True if the floats are equal to within 0.1%.
-
zero
public static boolean zero(double a)
Checks if the given double is zero.- Parameters:
a- The double to check.- Returns:
- True if the double is smaller in magnitude than 0.001d.
-
drawImageArea
public static void drawImageArea(java.awt.Image m, int x, int y, int width, int height, java.awt.Graphics g)Draw the part (x,y,width,height) of the image 'm' on 'g', at the same position (x,y).- Parameters:
m- The image.x- The x coordinate.y- The y coordinate.width- The width.height- The height.g- The graphics context.
-
drawImageArea
public static void drawImageArea(java.awt.Image m, int x, int y, int width, int height, java.awt.Graphics g, int gx, int gy)Draw the part (x,y,width,height) of the image 'm' on 'g' at (gx,gy).- Parameters:
m- The image.x- The x coordinate.y- The y coordinate.width- The width.height- The height.g- The graphics context.gx- The x coordinate of the new origin.gy- The y coordinate of the new origin.
-
newImageIcon
public static javax.swing.ImageIcon newImageIcon(java.lang.String resourceName)
ImageIcon from /resources/icons/ icon resource.- Parameters:
resourceName- The name of the resource.- Returns:
- An ImageIcon.
-
newImage
public static java.awt.Image newImage(java.lang.String resourceName)
Image from /resources/icons/ icon resource.- Parameters:
resourceName- The name of the resource file.- Returns:
- An Image.
-
getChooserImage
public static java.awt.Image getChooserImage(java.awt.Color iconColor)
Returns an image with a box of 40x15 pixels size, of the given color.- Parameters:
iconColor- The color of theimage.- Returns:
- An Image.
-
getChooserImage
public static java.awt.Image getChooserImage(java.awt.Color iconColor, java.awt.Dimension size)Returns an image with a box of the given pixels size, of the given color.- Parameters:
iconColor- The color of theimage.size- The size ofthe image.- Returns:
- An Image.
-
getChooserImageIcon
public static javax.swing.ImageIcon getChooserImageIcon(java.awt.Color iconColor)
Returns an image icon with a box of 40x15 pixels size, of the given color. Used for the color button in the edit panels.- Parameters:
iconColor- The color of theimage.- Returns:
- An ImageIcon.
-
getChooserImageIcon
public static javax.swing.ImageIcon getChooserImageIcon(java.awt.Color iconColor, java.awt.Dimension size)Returns an image icon with a box of the given pixels size, of the given color.- Parameters:
iconColor- The color of theimage.size- The size ofthe image.- Returns:
- An ImageIcon.
-
isButton1
public static boolean isButton1(java.awt.event.MouseEvent e)
Check for button 1 mouse events.- Parameters:
e- The MouseEvent.- Returns:
- True if e corresponds to a button 1 mouse event.
-
isButton2
public static boolean isButton2(java.awt.event.MouseEvent e)
Check for button 2 mouse events.- Parameters:
e- The MouseEvent.- Returns:
- True if e corresponds to a button 2 mouse event.
-
isButton3
public static boolean isButton3(java.awt.event.MouseEvent e)
Check for button 3 mouse events.- Parameters:
e- The MouseEvent.- Returns:
- True if e corresponds to a button 3 mouse event.
-
isDoubleClick
public static boolean isDoubleClick(java.awt.event.MouseEvent e)
Check for double click mouse events.- Parameters:
e- The MouseEvent.- Returns:
- True if e corresponds to a double click mouse event.
-
toString
public static java.lang.String toString(java.lang.Object[] array)
This is intended to be equivalent toArrays.toString(a)but also compatible with JDK 1.4. This concatenates the results of calling String.valueOf() on each element of the array, so this won't work well for multi-dimensional arrays.- Parameters:
array- An array.- Returns:
- A string.
-
equals
public static boolean equals(java.lang.Object[] expected, java.lang.Object[] actual)Check if two arrays are equal. Two arrays are equal if they contain the same elements in the same order, or if they are both null.- Parameters:
expected- one array to be tested for equality.actual- the other array to be tested for equality.- Returns:
- True if the two arrays are equal.
- See Also:
Arrays.equals(java.lang.Object[],java.lang.Object[])
-
equivalent
public static boolean equivalent(java.lang.Object[] expected, java.lang.Object[] actual)Check if two arrays are equivalent. Two arrays are equivalent if they contain the same number of elements, and every element of one array is also contained in the other array. In other words, two arrays are equivalent if they contain the same elements irrespective of order.This implementation uses
Arrays.sort(java.lang.Object[])to bring the elements of each array into natural order, before they are checked for equality. Therefore, the elements of each array must implement the Comparable interface and they must be mutually comparable.- Parameters:
expected- one array to be tested for equivalence.actual- the other array to be tested for equivalence.- Returns:
- True if the two arrays contain the same elements.
- See Also:
Arrays.equals(java.lang.Object[],java.lang.Object[]),Arrays.sort(java.lang.Object[])
-
-