public class Util
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ANCHOR_SEPARATOR |
static java.lang.String |
CLASS_EXT |
static java.lang.String |
CLASS_SEPARATOR |
static char |
CLASS_SEPARATOR_CHAR |
static java.lang.String |
CSS_ATTRIBUTE_ALIGN_CENTER |
static java.lang.String |
CSS_ATTRIBUTE_ALIGN_LEFT |
static java.lang.String |
CSS_ATTRIBUTE_ALIGN_RIGHT |
static java.lang.String |
CSS_ATTRIBUTE_LINE_THROUGH |
static java.lang.String |
CSS_ATTRIBUTE_NONE |
static java.lang.String |
CSS_ATTRIBUTE_NORMAL |
static java.lang.String |
CSS_ATTRIBUTE_UNDERLINE |
static java.lang.String |
DIR_UP_INDICATOR |
static java.lang.String |
FILE_PREFIX |
static java.lang.String |
JAR_EXTENSION |
static java.lang.String |
JAR_PREFIX |
static java.lang.String |
JAR_SEPARATOR |
static java.lang.String |
pct |
static java.lang.String |
PROTOCOL_SEPARATOR |
static java.lang.String |
pt |
static java.lang.String |
px |
static java.lang.String |
RELATIVE_PREFIX |
static java.lang.String |
URL_SEPARATOR |
static char |
URL_SEPARATOR_CHAR |
Constructor and Description |
---|
Util() |
Modifier and Type | Method and Description |
---|---|
static void |
addGridBagComponent(javax.swing.JComponent container,
javax.swing.JComponent comp,
java.awt.GridBagLayout g,
java.awt.GridBagConstraints c,
int gx,
int gy,
int a)
convenience method for adding a component to a container
layed out by a GridBagLayout
|
static void |
addGridBagComponent(javax.swing.JComponent container,
javax.swing.JComponent comp,
java.awt.GridBagLayout g,
java.awt.GridBagConstraints c,
int gx,
int gy,
int a,
int gw,
int gh)
convenience method for adding a component to a container
layed out by a GridBagLayout
|
static void |
addGridBagComponent(javax.swing.JComponent container,
javax.swing.JComponent comp,
java.awt.GridBagLayout g,
java.awt.GridBagConstraints c,
int gx,
int gy,
int a,
int gw,
int gh,
int f)
convenience method for adding a component to a container
layed out by a GridBagLayout
|
static void |
addGridBagComponent(javax.swing.JComponent container,
javax.swing.JComponent comp,
java.awt.GridBagLayout g,
java.awt.GridBagConstraints c,
int gx,
int gy,
int a,
int gw,
int gh,
int f,
double wx,
double wy)
convenience method for adding a component to a container
layed out by a GridBagLayout
|
static void |
center(java.awt.Component parent,
java.awt.Component comp)
center a
Component relative to
another Component . |
static void |
copyFile(java.io.File srcFile,
java.io.File destFile)
copies a single file.
|
static void |
deleteDir(java.io.File dir)
delete a directory with all its contents
|
static void |
errMsg(java.awt.Component owner,
java.lang.String msg,
java.lang.Throwable e)
show an error message and print a stack trace to the console if
in development mode (DEV_MODE = true)
|
static javax.swing.text.Element |
findElementDown(java.lang.String name,
javax.swing.text.Element parent)
find the first occurrence of an
Element in the
element tree below a given Element |
static javax.swing.text.Element |
findElementUp(java.lang.String name,
javax.swing.text.Element start)
find the first occurrence of an
Element in the
element tree above a given Element |
static javax.swing.text.Element |
findElementUp(java.lang.String name1,
java.lang.String name2,
javax.swing.text.Element start)
find the first occurrence of an
Element in the
element tree above a given Element |
static java.lang.Object |
findLinkUp(javax.swing.text.Element elem)
find the next link attribute from a given element upwards
through the element hierarchy
|
static float |
getAbsoluteAttrVal(java.lang.Object attr)
get the absolute value of an attribute
|
static float |
getAttrValue(java.lang.Object attr)
get the numerical value for an attribute object
|
static java.lang.String |
getClassFilePath(java.lang.Class cls)
Get the path of the class file for a given class.
|
static int |
getElementIndex(javax.swing.text.Element elem)
get the index of a given element in the list of its parents elements.
|
static java.lang.String |
getLastAttrUnit()
get the unit string from the last attribute object which was
converted to a numerical value
|
static java.lang.String |
getPreference(java.lang.String key,
java.lang.String defaultValue) |
static float |
getPtValue(java.lang.String valStr)
quick hack for getting the point value from an attribute value string
(needs to be refined and consolidated with length value)
|
static java.lang.String |
getRelativePath(java.io.File fromDir,
java.io.File toFile)
get the path to a given file relative to a given directory
|
static java.lang.String |
getResourceString(java.lang.String nm) |
static java.lang.String |
getResourceString(TextResources resources,
java.lang.String nm)
get a string from the resources file
|
static int |
getRowIndex(javax.swing.text.Element cell)
get the row index for a given table cell
|
static java.util.Vector |
getStyleNames(javax.swing.text.html.StyleSheet styles)
get the names of all styles found in a given StyleSheet
|
static java.util.Vector |
getStyleNamesForTag(javax.swing.text.AttributeSet styles,
java.lang.String tag)
get names of all styles for a given tag
|
static java.util.Vector |
getStyleNamesForTag(javax.swing.text.html.StyleSheet styles,
java.lang.String tag)
get names of all styles for a given tag
|
static boolean |
msg(int options,
java.lang.String title,
java.lang.String msg,
java.lang.String item,
java.lang.String sep)
Show a message with options to choose from
|
static int |
msgChoice(int options,
java.lang.String title,
java.lang.String msg,
java.lang.String item,
java.lang.String sep)
Show a message with options to choose from
|
static void |
msgStart(java.lang.String startMsg)
write a message with a time stamp to System.out and remember
the time stamp in a LIFO Vector
|
static java.lang.String |
nameInput(java.awt.Frame parent,
java.lang.String initialName,
java.lang.String regex,
java.lang.String title,
java.lang.String text)
get a name by asking from the user
|
static java.lang.String |
removeChar(java.lang.String src,
char c)
remove all occurrences of a given char from a given string
|
static java.lang.String |
removeExtension(java.lang.String fileName)
remove the extension from a file name
|
static java.io.File |
renameFile(java.io.File from,
java.lang.String newExt)
rename a file to have a given extension
|
static javax.swing.text.AttributeSet |
resolveAttributes(javax.swing.text.AttributeSet style)
resolve sets of attributes that are recursively stored in each other
|
static java.lang.String |
resolveRelativePath(java.lang.String relPath,
java.lang.String absPath)
resolve a relative URL string against an absolute URL string.
|
static javax.swing.text.html.StyleSheet |
styleSheet()
get a StyleSheet object for using its utility methods
|
static java.lang.String[] |
tokenize(java.lang.String input,
java.lang.String delim)
Get an arry of strings from a given string having several entries
delimited by blanks.
|
public static final java.lang.String JAR_PREFIX
public static final java.lang.String JAR_EXTENSION
public static final java.lang.String FILE_PREFIX
public static final java.lang.String CLASS_EXT
public static final java.lang.String JAR_SEPARATOR
public static final java.lang.String URL_SEPARATOR
public static final char URL_SEPARATOR_CHAR
public static final java.lang.String CLASS_SEPARATOR
public static final char CLASS_SEPARATOR_CHAR
public static final java.lang.String DIR_UP_INDICATOR
public static final java.lang.String RELATIVE_PREFIX
public static final java.lang.String PROTOCOL_SEPARATOR
public static final java.lang.String ANCHOR_SEPARATOR
public static final java.lang.String pct
public static final java.lang.String pt
public static final java.lang.String px
public static final java.lang.String CSS_ATTRIBUTE_NORMAL
public static final java.lang.String CSS_ATTRIBUTE_UNDERLINE
public static final java.lang.String CSS_ATTRIBUTE_LINE_THROUGH
public static final java.lang.String CSS_ATTRIBUTE_NONE
public static final java.lang.String CSS_ATTRIBUTE_ALIGN_LEFT
public static final java.lang.String CSS_ATTRIBUTE_ALIGN_CENTER
public static final java.lang.String CSS_ATTRIBUTE_ALIGN_RIGHT
public static java.io.File renameFile(java.io.File from, java.lang.String newExt)
from
- the file to renamenewExt
- the new extension the file shall havepublic static java.lang.Object findLinkUp(javax.swing.text.Element elem)
elem
- the element to start looking atpublic static java.lang.String removeExtension(java.lang.String fileName)
fileName
- the file name to remove the extension frompublic static javax.swing.text.AttributeSet resolveAttributes(javax.swing.text.AttributeSet style)
style
- the set of attributes containing other sets of attributespublic static java.lang.String nameInput(java.awt.Frame parent, java.lang.String initialName, java.lang.String regex, java.lang.String title, java.lang.String text)
Wrapper for JOptionPane with I18N support
initialName
- the name initially shown in option panetitle
- the title to be shown in the option panetext
- the text to be shown in the option panepublic static int msgChoice(int options, java.lang.String title, java.lang.String msg, java.lang.String item, java.lang.String sep)
Wrapper for JOptionPane with I18N support
options
- the options to be shown in the dialogtitle
- the title to be shown in the dialogmsg
- the message to be shown in the dialogitem
- a variable part to be shown before msgsep
- a separator for msg and item (return or blank etc.)public static boolean msg(int options, java.lang.String title, java.lang.String msg, java.lang.String item, java.lang.String sep)
Wrapper for JOptionPane with I18N support
options
- the options to be shown in the dialogtitle
- the title to be shown in the dialogmsg
- the message to be shown in the dialogitem
- a variable part to be shown before msgsep
- a separator for msg and item (return or blank etc.)public static java.util.Vector getStyleNamesForTag(javax.swing.text.html.StyleSheet styles, java.lang.String tag)
styles
- the style sheet to look for style namestag
- the tag to find style names forpublic static java.util.Vector getStyleNamesForTag(javax.swing.text.AttributeSet styles, java.lang.String tag)
styles
- the style sheet to look for style namestag
- the tag to find style names forpublic static java.util.Vector getStyleNames(javax.swing.text.html.StyleSheet styles)
styles
- the StyleSheet to look for style namespublic static void deleteDir(java.io.File dir)
CAUTION: This method deletes all content of the given directory including all subdirectories and their conent
dir
- the directory to deletepublic static void copyFile(java.io.File srcFile, java.io.File destFile) throws java.io.FileNotFoundException, java.io.IOException
If destFile already exists or if both files are the same the method does nothing. The complete destination path will be created before copying, if necessary.
srcFile
- the file to copy fromdestFile
- the file to copy tojava.io.FileNotFoundException
java.io.IOException
public static int getElementIndex(javax.swing.text.Element elem)
elem
- the element to get the index number forpublic static java.lang.String getClassFilePath(java.lang.Class cls)
This is either a directory of a class file or a directory of a JAR file. Thus, this class must reside in the same place as the application in question, not in a separate library for instance.
cls
- the class to get the path forpublic static float getPtValue(java.lang.String valStr)
valStr
- the attribute value string to get the point size forpublic static java.lang.String getLastAttrUnit()
public static float getAttrValue(java.lang.Object attr)
attr
- the attribute to get the value frompublic static float getAbsoluteAttrVal(java.lang.Object attr)
attr
- the attribute to get the value frompublic static int getRowIndex(javax.swing.text.Element cell)
cell
- the cell element to get the row index forpublic static java.lang.String[] tokenize(java.lang.String input, java.lang.String delim)
In the resource file of SimplyHTML for instance menu bar and menu definitions are contained as strings having a key for each item. The keys are delimited with blanks.
A string "file edit help" from the resource file for instance would be broken into an array of strings looking as follows
String[0]="file"
String[1]="edit"
String[2]="help"
input
- the string to transform into a string arraypublic static void msgStart(java.lang.String startMsg)
public static javax.swing.text.Element findElementUp(java.lang.String name, javax.swing.text.Element start)
Element
in the
element tree above a given Element
name
- the name of the Element
to search forstart
- the Element
to start lookingElement
or null if none is foundpublic static javax.swing.text.Element findElementUp(java.lang.String name1, java.lang.String name2, javax.swing.text.Element start)
Element
in the
element tree above a given Element
name1
- the primary name of the Element
to search forname2
- an alternative name for the Element
to search forstart
- the Element
to start lookingElement
or null if none is foundpublic static javax.swing.text.Element findElementDown(java.lang.String name, javax.swing.text.Element parent)
Element
in the
element tree below a given Element
name
- the name of the Element
to search forparent
- the Element
to start lookingElement
or null if none is foundpublic static void addGridBagComponent(javax.swing.JComponent container, javax.swing.JComponent comp, java.awt.GridBagLayout g, java.awt.GridBagConstraints c, int gx, int gy, int a)
container
- the container to add a component tocomp
- the component to add to containerg
- the GridBagLayout associated with containerc
- the GridBagConstraints to usegx
- the value to use for GridBagConstraints.gridxgy
- the value to use for GridBagConstraints.gridya
- the value to use for GridBagConstraints.anchorpublic static void addGridBagComponent(javax.swing.JComponent container, javax.swing.JComponent comp, java.awt.GridBagLayout g, java.awt.GridBagConstraints c, int gx, int gy, int a, int gw, int gh)
container
- the container to add a component tocomp
- the component to add to containerg
- the GridBagLayout associated with containerc
- the GridBagConstraints to usegx
- the value to use for GridBagConstraints.gridxgy
- the value to use for GridBagConstraints.gridya
- the value to use for GridBagConstraints.anchorgw
- the value to use for GridBagConstraints.gridwidthgh
- teh value to use for GridBagConstraints.gridheightpublic static void addGridBagComponent(javax.swing.JComponent container, javax.swing.JComponent comp, java.awt.GridBagLayout g, java.awt.GridBagConstraints c, int gx, int gy, int a, int gw, int gh, int f)
container
- the container to add a component tocomp
- the component to add to containerg
- the GridBagLayout associated with containerc
- the GridBagConstraints to usegx
- the value to use for GridBagConstraints.gridxgy
- the value to use for GridBagConstraints.gridya
- the value to use for GridBagConstraints.anchorgw
- the value to use for GridBagConstraints.gridwidthgh
- teh value to use for GridBagConstraints.gridheightf
- the value to use for GridBagConstraints.fillpublic static void addGridBagComponent(javax.swing.JComponent container, javax.swing.JComponent comp, java.awt.GridBagLayout g, java.awt.GridBagConstraints c, int gx, int gy, int a, int gw, int gh, int f, double wx, double wy)
container
- the container to add a component tocomp
- the component to add to containerg
- the GridBagLayout associated with containerc
- the GridBagConstraints to usegx
- the value to use for GridBagConstraints.gridxgy
- the value to use for GridBagConstraints.gridya
- the value to use for GridBagConstraints.anchorgw
- the value to use for GridBagConstraints.gridwidthgh
- teh value to use for GridBagConstraints.gridheightf
- the value to use for GridBagConstraints.fillwx
- the value to use for GridBagConstraints.weightxwy
- the value to use for GridBagConstraints.weightypublic static java.lang.String resolveRelativePath(java.lang.String relPath, java.lang.String absPath)
the absolute URL string is the start point for the relative path.
Example:
absolute path: file:/d:/eigene dateien/eigene bilder/ relative path: ../images/test.jpg result: file:/d:/eigene dateien/images/test.jpg
relPath
- the relative URL string to resolveabsPath
- the absolute URL string to start atpublic static java.lang.String getRelativePath(java.io.File fromDir, java.io.File toFile)
fromDir
- the directory having the file from which the link referstoFile
- the file to which a link referspublic static void errMsg(java.awt.Component owner, java.lang.String msg, java.lang.Throwable e)
owner
- the owner of the message, or nullmsg
- the message to display, or nulle
- the exception object describing the error, or nullpublic static void center(java.awt.Component parent, java.awt.Component comp)
Component
relative to
another Component
.parent
- the Component
to be used as the
basis for centeringcomp
- the Component
to be centered within parentpublic static javax.swing.text.html.StyleSheet styleSheet()
public static java.lang.String removeChar(java.lang.String src, char c)
src
- the string to remove fromc
- the char to removepublic static java.lang.String getResourceString(TextResources resources, java.lang.String nm)
resources
- the TextResources to get the string fromnm
- the key of the stringpublic static java.lang.String getResourceString(java.lang.String nm)
public static java.lang.String getPreference(java.lang.String key, java.lang.String defaultValue)