|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgov.nih.nlm.swing.SwingToolkit
GUI utility class. It provides several constants for useful GUI elements, as well as methods for reporting errors, informing uses of information, or requesting feedback from a user.
Field Summary | |
protected static Map |
key_map
|
protected static Properties |
properties
|
Fields inherited from interface gov.nih.nlm.swing.SwingConstants |
EMPTY_BORDER, EMPTY_BORDER_NO_TOP, EMPTY_INSETS, GRID_INSETS, HAS_POPUP_BORDER, IS_REQUIRED_BORDER, VIEW |
Constructor Summary | |
SwingToolkit()
|
Method Summary | |
static boolean |
confirmRequest(Component parent,
String request)
Asks the user a (yes/no) question. |
static boolean |
confirmRequest(String request)
Asks the user a (yes/no) question. |
static boolean |
confirmRequestWithOption(Component parent,
String request,
String key)
Asks the user a (yes/no) question. |
static boolean |
copy(File in,
File out)
Copies the input file to the output file. |
static void |
displayTextFile(Component parent,
String title,
File file)
Displays a text file. |
static void |
displayTextFile(Component parent,
String title,
File file,
int rows,
int cols)
Displays a text file. |
static void |
displayURL(Component parent,
String title,
URL url)
Displays the file at a given URL. |
static void |
Exit(int return_value)
Cleans up loose ends before calling System.exit(int) . |
static String |
getMultiLineUserInput(Component parent,
String message)
Asks the user a question that involves a potentially multi-line answer. |
static String |
getMultiLineUserInput(String request)
Asks the user a question that involves a potentially multi-line answer. |
static JPanel |
getPanelForHTML(URL url)
Returns a JPanel displaying the contents
of the specified url URL . |
static Properties |
getProperties()
Returns the toolkit Properties . |
static String |
getProperty(String name)
Returns the property value for the specified name. |
static String |
getProperty(String name,
String _default)
Returns the property value for the specified name. |
static String |
getUserInput(Component parent,
String message)
Asks the user a question. |
static String |
getUserInput(String request)
Asks the user a question. |
static Image |
makeColorTransparent(Image im,
Color color,
Color repl_color)
Make a certain color transparent and return a new image. |
static String |
md5(File in)
Computes the MD5 of the specified file. |
static void |
notifyUser(Component parent,
String message)
Notifies the user of something. |
static void |
notifyUser(Component parent,
String message,
String title)
Notifies the user of something. |
static void |
notifyUser(String request)
Notifies the user of something. |
static void |
notifyUserWithOption(Component parent,
String message,
String title,
String key)
Notifies the user of something. |
static BufferedImage |
readScaledImage(URL url,
int w,
boolean composite)
Read a scaled image from the specified URL. |
static void |
removeProperty(String name)
Remove a property. |
static void |
reportError(Component parent,
String error,
boolean fatal)
Reports an error message to the user. |
static void |
reportError(String error)
Reports an error message to the user. |
static void |
reportError(String error,
boolean fatal)
Reports an error message to the user. |
static void |
setProperties(Properties props)
Sets the toolkit properties. |
static void |
setProperty(String name,
String value)
Sets a property. |
static boolean |
unzip(String zip_file,
String output_dir,
String archive_subdir,
Frame owner)
Unzips the specified file into the specified directory using the specified operating system command. |
static boolean |
unzip(String unzip_cmd,
String zip_file,
String output_dir,
String archive_subdir,
Frame owner)
Unzips the specified file into the specified directory using the specified operating system command. |
static boolean |
usingView()
Indicates whether or not the application is using a GUI. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static Properties properties
protected static Map key_map
Constructor Detail |
public SwingToolkit()
Method Detail |
public static void setProperty(String name, String value)
name
- the property namevalue
- the property valuepublic static void setProperties(Properties props)
initialize
.
props
- a set of new Properties
public static String getProperty(String name)
name
- the property name
public static String getProperty(String name, String _default)
name
- the property name_default
- the default value if the property value is null
public static void removeProperty(String name)
name
- the property name.public static Properties getProperties()
Properties
.
Properties
public static boolean usingView()
SwingConstants.VIEW
property.
true
if the current application is using a view,
false
otherwisepublic static void reportError(String error)
usingView()
.
error
- an error messagepublic static void reportError(String error, boolean fatal)
usingView()
.
error
- an error messagefatal
- a flag indicating whether or not the error is fatalpublic static void reportError(Component parent, String error, boolean fatal)
usingView()
.
parent
- the parent componenterror
- an error messagefatal
- a flag indicating whether or not the error is fatalpublic static boolean confirmRequest(String request)
confirmRequest(Component, String)
with a null parent
request
- the (yes/no) question
true
if yes, false
if nopublic static boolean confirmRequest(Component parent, String request)
usingView()
returns true, this method opens a dialog box with a message and a
(yes/no) prompt for the user. If usingView()
returns false,
it prompts the user on the command line.
parent
- the parent Component
of the dialog boxrequest
- the (yes/no) question
true
if yes; false
if nopublic static boolean confirmRequestWithOption(Component parent, String request, String key)
usingView()
returns true, this method opens a dialog box with a message and a
(yes/no) prompt for the user. If usingView()
returns false,
it prompts the user on the command line.
parent
- the parent Component
of the dialog boxrequest
- the (yes/no) questionkey
- used to differentiate this request from others
true
if yes; false
if nopublic static void notifyUser(String request)
notifyUser(Component, String)
with a null parent
.
request
- the messagepublic static void notifyUser(Component parent, String message)
usingView()
returns
true
, this method opens a dialog box informing the
user of the state of something . It returns upon an OK click or close.
If usingView()
returns false
, it notifies the
user on the command line.
parent
- the parent Component
message
- the messagepublic static void notifyUser(Component parent, String message, String title)
usingView()
returns
true
, this method opens a dialog box informing the
user of the state of something . It returns upon an OK click or close.
If usingView()
returns false
, it notifies the
user on the command line.
parent
- the parent Component
message
- the messagetitle
- for the dialog boxpublic static void notifyUserWithOption(Component parent, String message, String title, String key)
usingView()
returns
true
, this method opens a dialog box informing the
user of the state of something . It returns upon an OK click or close.
If usingView()
returns false
, it notifies the
user on the command line. Will not display if user has previously
checked the JCheckBox
"Don't show this message again." from the
calling instance indicated by the key parameter.
parent
- the parent Component
message
- the messagetitle
- for the dialog boxkey
- to differentiate calling instancespublic static void displayTextFile(Component parent, String title, File file)
usingView()
returns
true
, this method opens a dialog box displaying the
given File
. It returns upon an OK click or close.
If usingView()
returns false
, it displays the text on
the command line.
parent
- the parent Component
title
- title for the displayfile
- the messagepublic static void displayTextFile(Component parent, String title, File file, int rows, int cols)
usingView()
returns
true
, this method opens a dialog box displaying the
given File
. It returns upon an OK click or close.
If usingView()
returns false
, it displays the text on
the command line.
parent
- the parent Component
title
- title for the displayfile
- the messagerows
- the number of rows to be displayed at one time without scrollingcols
- the number of columns to be displayed at one time without scrollingpublic static void displayURL(Component parent, String title, URL url)
usingView()
returns
true
, this method opens a dialog box displaying the
given URL
. It returns upon an OK click or close.
If usingView()
returns false
, nothing happens.
parent
- the parent Component
title
- title for the displayurl
- URL
to be displayedpublic static String getUserInput(String request)
getUserInput(Component, String)
with a null parent
.
request
- the message
public static String getUserInput(Component parent, String message)
usingView()
returns
true
, this method opens a dialog box with the specified
question and "OK"/"Cancel" buttons. If usingView()
returns
false
, a response from the user is solicited on the
command line.
parent
- the parent Component
message
- the message
public static String getMultiLineUserInput(String request)
getMultiLineUserInput(Component, String)
with
a null parent
request
- the request
public static String getMultiLineUserInput(Component parent, String message)
usingView()
returns true
, this
method opens a dialog box asking the user a question and
soliciting a multi-line response. If usingView()
returns
false
, a response from the user is solicited on the
command line.
parent
- the parent Component
message
- the message
public static boolean copy(File in, File out) throws IOException
in
- the input File
out
- the output File
true
if the copying was successful, false otherwise.
IOException
public static String md5(File in) throws IOException, NoSuchAlgorithmException
in
- the File
IOException
NoSuchAlgorithmException
public static boolean unzip(String zip_file, String output_dir, String archive_subdir, Frame owner) throws IOException
zip_file
- file to be unzippedoutput_dir
- location for unzipped filesarchive_subdir
- the portion of the archive to extractowner
- parent Component
true
if the unzipping was successful, false otherwise.
IOException
public static boolean unzip(String unzip_cmd, String zip_file, String output_dir, String archive_subdir, Frame owner) throws IOException
unzip_cmd
- the OS command to use to unzipzip_file
- file to be unzippedoutput_dir
- location for unzipped filesarchive_subdir
- the portion of the archive to extractowner
- parent Component
true
if the unzipping was successful, false otherwise.
IOException
public static void Exit(int return_value)
System.exit(int)
.
All applications should call SwingToolkit.Exit(0)
instead of
calling System.exit(0)
.
return_value
- the exit code. 0 typically means no error.public static JPanel getPanelForHTML(URL url)
JPanel
displaying the contents
of the specified url URL
.
url
- to display
JPanel
public static Image makeColorTransparent(Image im, Color color, Color repl_color)
im
- The original Image
color
- the Color
to be transparentrepl_color
- Color
replace color
Image
public static BufferedImage readScaledImage(URL url, int w, boolean composite) throws IOException
url
- the URL
w
- scale to this widthcomposite
- true
if images should be faded
BufferedImage
matching the params
IOException
- if the URL
cannot be accessed
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |