public class General
extends Object
Modifier and Type | Field and Description |
---|---|
static int |
AcceleratorKey
Key to use with shortcut commands; i.e., CNTL on PC, Cmd on Mac
|
static Border |
BeveledBorder |
static Color |
chargerBlueColor |
static int |
defaultMaxUndoLevels |
static BasicStroke |
defaultStroke |
static boolean |
infoOn |
private static Border |
loweredBevel |
private static Border |
raisedBevel |
Constructor and Description |
---|
General() |
Modifier and Type | Method and Description |
---|---|
static String |
a_or_an(String s)
Prints a string with a prefix, deciding whether to use "a" or "an" for
the article, based on the string.
|
static void |
addChangeListener(JTextComponent textComponent,
ChangeListener changeListener)
Installs a listener to receive notification when the text of any
JTextComponent is changed. |
static void |
adjustTableColumnWidths(JTable table)
For each column of a JTable, scans every entry and determines the maximum
width for the column.
|
static File |
chooseInputFile(String query,
String filename,
File sourceDirectoryFile,
FileFilter filter)
Handles the choosing of an input file.
|
static File |
chooseOutputFile(String query,
String filename)
Handles the choosing of an input file by the user, with possible user
intervention.
|
static void |
consoleMsg(String s)
Displays a status message on System.out
|
static String |
displayAsHex(byte[] bytes) |
static void |
drawCenteredString(Graphics2D g,
String s,
double x,
double y)
Displays a centered text string in black
|
static void |
drawCenteredString(Graphics2D g,
String s,
double x,
double y,
Color c)
Displays the text string centered about the point x,y in the given color.
|
static void |
drawCenteredString(Graphics2D g,
String s,
Point2D.Double p,
Color c) |
static long |
elapsedTime(long time)
Returns a printable string to show the time elapsed since a given time.
|
static boolean |
equalsToRoundedInt(Rectangle2D.Double r1,
Rectangle2D.Double r2)
If the rectangles' location and dimension all round (Math.round) to the same int (pixel) then return true.
|
static void |
error(String s)
Displays an error message on System.out
|
static String |
excludeChars(String s,
String set)
Convert any forbidden characters to a space character.
|
static Point2D.Double |
get_line_intersection(Line2D.Double pLine1,
Line2D.Double pLine2)
Figure out the point where the two lines intersect.
|
static Point2D.Double |
get_rectangle_line_intersection(Rectangle2D.Double rect,
Line2D.Double line) |
static Point |
get2ndScreenOrigin()
Determine whether there's another screen, and if so, get the x,y of its bounds.
|
static String |
getFileExtension(String filename)
Identifies the extension part of a filename string.
|
static String |
getFileFromClassPath(String desiredFoldername,
String desiredFilename)
Returns the contents of a file after first deciding whether to load from
a jar file or from a directory and class hierarchy.
|
static ImageIcon |
getIconFromClassPath(String gifname)
Returns the icon image after first deciding whether to load from a jar
file or from a directory and class hierarchy.
|
static String |
getPathname(String s)
Extracts the prepended pathname part of a supposed file name string
|
static Rectangle |
getScreenBounds(boolean useMainScreen)
Find the bounds of one of the available screens.
|
static String |
getSimpleFilename(String s)
Extracts the suffixed filename part of a supposed file name string, incl
extensions.
|
static String |
getXmlText(org.w3c.dom.Element element,
String tagname)
Find the value of the text bracketed inside the given tagname.
|
static boolean |
hasPathName(String s)
Tells whether there's a path prepended or not
|
static void |
hideTableColumn(TableColumn col) |
static void |
info(String s)
Displays a status message on System.out
|
static Point2D.Double |
make2DDouble(Point2D.Double point)
Creates a clone of the point.
|
static Point2D.Double |
make2DDouble(Point2D.Float p) |
static Rectangle2D.Double |
make2DDouble(Rectangle2D.Double rect)
Creates a clone of the rectangle.
|
static String |
makeLegalChars(String s,
String characterSet)
Makes sure that no "illegal" characters remain in the string.
|
static Point2D.Double |
midPoint(Point2D.Double p1,
Point2D.Double p2) |
static String |
ordinal(int num)
Converts a number to its ordinal description.
|
static File |
queryForInputFile(String query,
File sourceDirectoryFile,
FileFilter filter)
Queries the user to find a file to be used for input.
|
static File |
queryForOutputFile(String query,
File initialDirectory,
String filename)
Queries the user to find a file to be used for input.
|
static String |
removeSubstring(String s,
int startPos,
int endPos) |
static ArrayList |
repeatingVector(int theSize,
Object value)
Creates a vector of a given size where every element has the same value.
|
static void |
setTableColumnWidth(TableColumn col,
int width) |
static void |
showArrayList(ArrayList v) |
static String |
splitWithSeparator(String original,
String regex,
String sep)
Splits a string according to each occurrence of a regular expression,
inserting a separator between each part of the string.
|
static String |
stripFileExtension(String filename)
Extracts the extension part of a filename string.
|
static void |
tearDownMenu(JMenu menu)
Does a complete erasure of a JMenu.
|
static String |
toXML(org.w3c.dom.Node doc)
Pretty print the doc as given.
|
static void |
warning(String s)
Displays a warning message on System.out
|
static void |
writeToFile(File f,
String s,
boolean append)
A generic file writer, usable by any Charger class
|
public static Color chargerBlueColor
private static Border raisedBevel
private static Border loweredBevel
public static Border BeveledBorder
public static boolean infoOn
public static int defaultMaxUndoLevels
public static int AcceleratorKey
public static BasicStroke defaultStroke
public static void info(String s)
s
- the status message to be shownGlobal#infoOn
,
Global#ShowBoringDebugInfo
public static void warning(String s)
s
- the warning message to be shownpublic static void error(String s)
s
- the error message to be shownpublic static void consoleMsg(String s)
s
- the status message to be shownpublic static void drawCenteredString(Graphics2D g, String s, double x, double y, Color c)
g
- the current Graphics contexts
- the string to be displayedx
- horizontal position of the centerpoint (in pixels)y
- vertical position of the centerpoint (in pixels)c
- the color to be displayedpublic static void drawCenteredString(Graphics2D g, String s, double x, double y)
CGUtil#drawCenteredString
public static void drawCenteredString(Graphics2D g, String s, Point2D.Double p, Color c)
public static File queryForInputFile(String query, File sourceDirectoryFile, FileFilter filter)
sourceDirectoryFile
- starting point directory (user may change)filter
- allows the viewing of only certain files.null
if user
cancels.public static void setTableColumnWidth(TableColumn col, int width)
public static File queryForOutputFile(String query, File initialDirectory, String filename)
query
- the title for the querying dialoginitialDirectory
- path for the directory where we'll start trying
to queryfilename
- initial choice of where to point the saving operation
(user may change)null
if user
cancels.public static String getFileExtension(String filename)
filename
- any stringpublic static String getFileFromClassPath(String desiredFoldername, String desiredFilename)
desiredFilename
- file name of the text file, relative to the
classpathdesiredFoldername
- folder name containing the text filepublic static ArrayList repeatingVector(int theSize, Object value)
theSize
- The desired vector sizevalue
- The value of each elementpublic static File chooseInputFile(String query, String filename, File sourceDirectoryFile, FileFilter filter)
filename
- the initial selection of a file; null
if
none is knownsourceDirectoryFile
- initial directory (user may change)filter
- allows the viewing of only certain files.File
, possibly permission-protected.public static Point get2ndScreenOrigin()
public static File chooseOutputFile(String query, String filename)
query
- the prompt string for the userfilename
- the initial selection of a file; null
if
none is known. If it's an absolute path name, then the directory is
obtained from it, otherwise some implementation-dependent directory is
chosen.File
, possibly permission-protected.public static Rectangle getScreenBounds(boolean useMainScreen)
useMainScreen
- whether to get the bounds of the main screen or notpublic static long elapsedTime(long time)
time
- Start timepublic static ImageIcon getIconFromClassPath(String gifname)
gifname
- file name of the icon's image, relative to the classpathpublic static String getSimpleFilename(String s)
s
- supposed file name stringpublic static void hideTableColumn(TableColumn col)
public static String toXML(org.w3c.dom.Node doc)
doc
- Any DOM documentpublic static void showArrayList(ArrayList v)
public static String ordinal(int num)
public static String displayAsHex(byte[] bytes)
public static String removeSubstring(String s, int startPos, int endPos)
s
- startPos
- the index (starting at 0) of the start of the string to
removeendPos
- the index (starting at 0) of the start of the string to
removepublic static Point2D.Double get_line_intersection(Line2D.Double pLine1, Line2D.Double pLine2)
pLine1
- pLine2
- public static void adjustTableColumnWidths(JTable table)
table
- the table to be adjusted.public static String a_or_an(String s)
a_or_an( "element" )
returns
"an element"
, whereas
a_or_an( "person" )
returns
"a person"
public static Point2D.Double midPoint(Point2D.Double p1, Point2D.Double p2)
public static boolean equalsToRoundedInt(Rectangle2D.Double r1, Rectangle2D.Double r2)
r1
- r2
- public static void writeToFile(File f, String s, boolean append)
public static String getPathname(String s)
s
- supposed file name stringpublic static boolean hasPathName(String s)
s
- supposed file name stringpublic static void tearDownMenu(JMenu menu)
menu
- public static String excludeChars(String s, String set)
s
- set
- The set of excluded characters, each of which will be converted to a space.public static String makeLegalChars(String s, String characterSet)
the
- string to be examinedthe
- character set allowed for that string.CharacterSets
public static String splitWithSeparator(String original, String regex, String sep)
original
- The original string to be splitregex
- A regular expression to be found in the string. Follows the
same rules as String#splitsep
- The string to be inserted between the parts (if null, then
this method has no effect)public static Rectangle2D.Double make2DDouble(Rectangle2D.Double rect)
rect
- public static Point2D.Double make2DDouble(Point2D.Double point)
point
- public static Point2D.Double make2DDouble(Point2D.Float p)
public static String stripFileExtension(String filename)
filename
- any stringpublic static String getXmlText(org.w3c.dom.Element element, String tagname)
element
- tagname
- public static Point2D.Double get_rectangle_line_intersection(Rectangle2D.Double rect, Line2D.Double line)
public static void addChangeListener(JTextComponent textComponent, ChangeListener changeListener)
JTextComponent
is changed. Internally, it installs a
DocumentListener
on the text component's Document
,
and a PropertyChangeListener
on the text component to detect
if the Document
itself is replaced.textComponent
- any text component, such as a JTextField
or JTextArea
changeListener
- a listener to receieve ChangeEvent
s
when the text is changed; the source object for the events
will be the text componentNullPointerException
- if either parameter is null
obtained from https://stackoverflow.com/questions/3953208/value-change-listener-to-jtextfield