vmm3d.core
Class Util
- java.lang.Object
-
- vmm3d.core.Util
-
public class Util extends java.lang.ObjectProvides several static utility funtions that can be used in various places.
-
-
Constructor Summary
Constructors Constructor and Description Util()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static longavailableMemory()Tries to compute the amount of memory that is available and not yet used.static java.awt.CursorcreateCursorFromResource(java.lang.String imageResourceFileName, int activeX, int activeY)A method that creates a cursor from an image file.static java.lang.String[]explode(java.lang.String str, java.lang.String separators)A convenience method that breaks up a string into tokens, where the tokens are substrings seprated by specified delimiters.static java.lang.ObjectexternalStringToValue(java.lang.String str, java.lang.Class valueType)Tries to convert a string to a value of a specified type.static javax.swing.KeyStrokegetAccelerator(java.lang.String description)Returns a KeyStroke, typically for use as the accelerator for a menu command.static java.awt.geom.Point2DgetPoint2DFromUser(java.awt.Component parent, java.lang.String prompt)static java.awt.geom.Point2DgetPoint2DFromUser(java.awt.Component parent, java.lang.String prompt, double initialX, double initialY)static java.awt.geom.Point2DgetPoint2DFromUser(java.awt.Component parent, java.lang.String prompt, double initialX, double initialY, java.lang.String nameForX, java.lang.String nameForY)static booleanisMacOS()Test whether the program is running on Mac OS.static ComplexExpressionparseComplexConstantExpression(java.lang.String expressionAsString)Parses a string to produce a constant ComplexExpression.static ExpressionparseConstantExpression(java.lang.String expressionAsString)Parses a string to produce a constant Expression.static java.lang.StringtoExternalString(java.lang.Object value)Converts any value to a string -- hopefull a string that can be parsed byexternalStringToValue(String, Class)to recover the original value.
-
-
-
Method Detail
-
parseConstantExpression
public static Expression parseConstantExpression(java.lang.String expressionAsString) throws ParseError
Parses a string to produce a constant Expression. A defaultParseris used to do the parsing.- Parameters:
expressionAsString- The constant expression, represented as a string. A ParseError is thrown if this is not a legal real-valued expression.- Returns:
- The expression represented by the string
- Throws:
ParseError
-
parseComplexConstantExpression
public static ComplexExpression parseComplexConstantExpression(java.lang.String expressionAsString) throws ParseError
Parses a string to produce a constant ComplexExpression. A defaultParseris used to do the parsing.- Parameters:
expressionAsString- The constant expression, represented as a string. A ParseError is thrown if this is not a legal complex expression.- Returns:
- The expression represented by the string
- Throws:
ParseError
-
createCursorFromResource
public static java.awt.Cursor createCursorFromResource(java.lang.String imageResourceFileName, int activeX, int activeY)A method that creates a cursor from an image file. The image file is obtained as a resource using thegetResourcemethod of the Toolkit class. If the resource is not found or if any other error occurs, then the return value of the method will be null. The second and third parameters specify the active point of the cursor -- the point that determines the (x,y) position of the cursor in mouse events.
-
isMacOS
public static boolean isMacOS()
Test whether the program is running on Mac OS.
-
getAccelerator
public static javax.swing.KeyStroke getAccelerator(java.lang.String description)
Returns a KeyStroke, typically for use as the accelerator for a menu command. Depending on the OS, either "control" or "meta" will be added to the description that is passed to this method. The descriptions might be just a key name, such as "A", or it might include modifier keys, such as "shift A" or "alt A".
-
availableMemory
public static long availableMemory()
Tries to compute the amount of memory that is available and not yet used.
-
getPoint2DFromUser
public static java.awt.geom.Point2D getPoint2DFromUser(java.awt.Component parent, java.lang.String prompt)
-
getPoint2DFromUser
public static java.awt.geom.Point2D getPoint2DFromUser(java.awt.Component parent, java.lang.String prompt, double initialX, double initialY)
-
getPoint2DFromUser
public static java.awt.geom.Point2D getPoint2DFromUser(java.awt.Component parent, java.lang.String prompt, double initialX, double initialY, java.lang.String nameForX, java.lang.String nameForY)
-
explode
public static java.lang.String[] explode(java.lang.String str, java.lang.String separators)A convenience method that breaks up a string into tokens, where the tokens are substrings seprated by specified delimiters. For example, explode("ab,cde,f,ghij", ",") produces an array of the four substrings "ab" "cde" "f" "ghi".- Parameters:
str- the string that is to be exploded; if null, then the return value is nullseparators- characters in this string are separatos between tokens in the string that is being exploded. If this is null, then the return value will be an array of length one containing str as its only element.
-
toExternalString
public static java.lang.String toExternalString(java.lang.Object value)
Converts any value to a string -- hopefull a string that can be parsed byexternalStringToValue(String, Class)to recover the original value. This method definitely works for: the wrapper types such as Double, Complex, Color, Point2D, Vector3D, double[], int[]. For other types, this method returns value.toString(), which might work. In no case does it throw an exception. Note that a null value is converted to the string "##NULL##". For double and float numbers, the special strings NaN, +INF, -INF, and EPSILON are used to represent the special values Not-a-number, positive infinity, negative infinity, and min_value (the smallest positive value). This method is used inSaveAndRestoreand in other places where conversion of an object to a string is needed.
-
externalStringToValue
public static java.lang.Object externalStringToValue(java.lang.String str, java.lang.Class valueType) throws java.lang.IllegalArgumentExceptionTries to convert a string to a value of a specified type. This method can handle the strings produced bytoExternalString(Object)for at least the following types: the wrapper types, Color, Point2D, Complex, Vector3D, double[], and int[]. The special string "##NULL##" is converted to the value null (except in the case of primitive types.) The method will work for primitive types such as Double.TYPE. Note that for the type Double.TYPE, the return value is of type Double (just as it would be for Double.class). Aside from these built-in types, the method will try to find a static method in the class named "fromString" and with one parameter of type String. If such a method is found, it will be called and its return value will be the return value of this mthod. If no such method is found, an attempt is made to find a constructor in the class with one parameter of type String. If such a constructor is found, it is invoked to produce the return value.An exception of type IllegalArgumentException will be thrown if none of this succeeds in producing an object of the specified type. No other type of exception will be thrown.
- Throws:
java.lang.IllegalArgumentException
-
-
DMelt 3.0 © DataMelt by jWork.ORG