|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.rice.cs.plt.swing.SwingUtil
public class SwingUtil
| Constructor Summary | |
|---|---|
SwingUtil()
|
|
| Method Summary | |
|---|---|
static void |
add(Container parent,
Component... children)
Add the given components to parent in sequence. |
static ActionListener |
asActionListener(Runnable r)
Convert a Runnable to an ActionListener |
static ActionListener |
asActionListener(Runnable1<? super ActionEvent> r)
Convert a Runnable1 to an ActionListener |
static Runnable1<ActionEvent> |
asRunnable(ActionListener l)
Convert an ActionListener to a Runnable1 |
static FileFilter |
asSwingFileFilter(FileFilter filter,
String description)
Define a Swing file filter (for use with JFileChoosers) in terms if a
FileFilter. |
static FileFilter |
asSwingFileFilter(FilePredicate p,
String description)
Define a Swing file filter (for use with JFileChoosers) in terms if a
FileFilter. |
static FileFilter |
asSwingFileFilter(Predicate<? super File> p,
String description)
Define a Swing file filter (for use with JFileChoosers) in terms if a
FileFilter. |
static void |
attemptClearEventQueue()
Call @link{#clearEventQueue}, but ignore any resulting InterruptedException. |
static void |
clearEventQueue()
Wait for all items in the event queue to be handled. |
static void |
displayWindow(Window w)
Shortcut for the boilerplate code to pack and display a window (such as a JFrame). |
static ActionListener |
disposeAction(Window w)
Create an action to invoke Window.dispose() on the given window |
static Action |
getAction(JTextComponent component,
String actionName)
Search the given text component's list of actions for an action with the given name. |
static Map<String,Action> |
getActions(JTextComponent component)
Create a map view of component.getActions(), where the keys are the action
names. |
static String |
getClipboardSelection(Component c)
|
static Color |
gray(float degree)
Create a shade of gray with the given degree of darkness. |
static void |
invokeAndWait(Runnable task)
Runs the the task in the event thread, blocking until it is complete. |
static void |
invokeLater(Runnable task)
Runs the task synchronously if the current thread is the event thread; otherwise passes it to the event thread to be run asynchronously after all events already on the queue have been processed. |
static JPanel |
makeBorderPanel()
Make a JPanel with a BorderLayout. |
static JPanel |
makeBorderPanel(int margin)
Make a JPanel with a BorderLayout; set the border to the given margin on all sides. |
static JPanel |
makeBorderPanel(int vMargin,
int hMargin)
Make a JPanel with a BorderLayout; set the border to the given vertical/horizontal margins. |
static JPanel |
makeBorderPanel(int topMargin,
int leftMargin,
int bottomMargin,
int rightMargin)
Make a JPanel with a BorderLayout; set the border to the given margins. |
static JFrame |
makeDisposableFrame(String title,
int width,
int height)
Boilerplate for creating a JFrame. |
static JPanel |
makeFlowPanel()
Make a JPanel with a FlowLayout. |
static JPanel |
makeFlowPanel(int margin)
Make a JPanel with a FlowLayout; set the border to the given margin on all sides. |
static JPanel |
makeFlowPanel(int vMargin,
int hMargin)
Make a JPanel with a FlowLayout; set the border to the given vertical/horizontal margins. |
static JPanel |
makeFlowPanel(int topMargin,
int leftMargin,
int bottomMargin,
int rightMargin)
Make a JPanel with a FlowLayout; set the border to the given margins. |
static JPanel |
makeHorizontalBoxPanel()
Make a JPanel with a horizontal BoxLayout. |
static JPanel |
makeHorizontalBoxPanel(int margin)
Make a JPanel with a horizontal BoxLayout; set the border to the given margin on all sides. |
static JPanel |
makeHorizontalBoxPanel(int vMargin,
int hMargin)
Make a JPanel with a horizontal BoxLayout; set the border to the given vertical/horizontal margins. |
static JPanel |
makeHorizontalBoxPanel(int topMargin,
int leftMargin,
int bottomMargin,
int rightMargin)
Make a JPanel with a horizontal BoxLayout; set the border to the given margins. |
static JFrame |
makeMainApplicationFrame(String title,
int width,
int height)
Boilerplate for creating a JFrame to be used as the main application window. |
static JFrame |
makeReusableFrame(String title,
int width,
int height)
Boilerplate for creating a JFrame. |
static JPanel |
makeVerticalBoxPanel()
Make a JPanel with a vertical BoxLayout. |
static JPanel |
makeVerticalBoxPanel(int margin)
Make a JPanel with a vertical BoxLayout; set the border to the given margin on all sides. |
static JPanel |
makeVerticalBoxPanel(int vMargin,
int hMargin)
Make a JPanel with a vertical BoxLayout; set the border to the given vertical/horizontal margins. |
static JPanel |
makeVerticalBoxPanel(int topMargin,
int leftMargin,
int bottomMargin,
int rightMargin)
Make a JPanel with a vertical BoxLayout; set the border to the given margins. |
static void |
onWindowClosed(Window w,
Runnable r)
|
static void |
setAlignmentX(float a,
JComponent... components)
Set the horizontal alignment of the given components. |
static void |
setAlignmentY(float a,
JComponent... components)
Set the vertical alignment of the given components. |
static void |
setBackground(Color c,
Component... components)
Set the background color property of the given components. |
static void |
setBorder(Border b,
JComponent... components)
Set the border of the given components. |
static void |
setBottomAlignment(JComponent... components)
Make the given components vertically-bottom aligned. |
static void |
setDialogFont(int size,
Component... components)
Set the font of the given components to the logical "Dialog" font of the given size. |
static void |
setDialogInputFont(int size,
Component... components)
Set the font of the given components to the logical "DialogInput" font of the given size. |
static void |
setEmptyBorder(int top,
int left,
int bottom,
int right,
JComponent... components)
Set the border of the given components to an empty border with the given margins. |
static void |
setEmptyBorder(int vMargin,
int hMargin,
JComponent... components)
Set the border of the given components to an empty border with the given vertical/horizontal margins. |
static void |
setEmptyBorder(int margin,
JComponent... components)
Set the border of the given components to an empty border with the given margin. |
static void |
setEnabled(boolean b,
Component... components)
Set the enabled property of the given components. |
static void |
setFocusable(boolean b,
Component... components)
Set the focusable property of the given components. |
static void |
setFont(Font f,
Component... components)
Set the font property of the given components. |
static void |
setFont(String name,
int size,
Component... components)
Set the font property of the given components. |
static void |
setForeground(Color c,
Component... components)
Set the foreground color property of the given components. |
static void |
setHorizontalCenterAlignment(JComponent... components)
Make the given components horizontally-center aligned. |
static void |
setLeftAlignment(JComponent... components)
Make the given components horizontally-left aligned. |
static void |
setLineBorder(JComponent... components)
Set the border of the given components to a black line border. |
static void |
setMaximumSize(Dimension d,
JComponent... components)
Set the maximum size of the given components. |
static void |
setMaximumSize(int width,
int height,
JComponent... components)
Set the maximum size of the given components. |
static void |
setMinimumSize(Dimension d,
JComponent... components)
Set the minimum size of the given components. |
static void |
setMinimumSize(int width,
int height,
JComponent... components)
Set the minimum size of the given components. |
static void |
setMonospacedFont(int size,
Component... components)
Set the font of the given components to the logical "Monospaced" font of the given size. |
static void |
setOpaque(boolean b,
JComponent... components)
Set the opaque property of the given components. |
static void |
setPopupLoc(Window popup)
Convenience method for setPopupLoc(Window, Component) that gets the owner from popup.getOwner() |
static void |
setPopupLoc(Window popup,
Component owner)
Sets the location of the popup in a consistent way. |
static void |
setPreferredSize(Dimension d,
JComponent... components)
Set the preferred size of the given components. |
static void |
setPreferredSize(int width,
int height,
JComponent... components)
Set the preferred size of the given components. |
static void |
setRightAlignment(JComponent... components)
Make the given components horizontally-right aligned. |
static void |
setSansSerifFont(int size,
Component... components)
Set the font of the given components to the logical "SansSerif" font of the given size. |
static void |
setSerifFont(int size,
Component... components)
Set the font of the given components to the logical "Serif" font of the given size. |
static void |
setTopAlignment(JComponent... components)
Make the given components vertically-top aligned. |
static void |
setVerticalCenterAlignment(JComponent... components)
Make the given components vertically-center aligned. |
static void |
setVisible(boolean b,
Component... components)
Set the visible property of the given components. |
static void |
showApplet(Applet applet,
int width,
int height)
Display the given applet in a window with title "Applet Viewer". |
static void |
showApplet(String title,
Applet applet,
int width,
int height)
Display the given applet in a window with the given title. |
static void |
showApplet(String title,
Applet applet,
int width,
int height,
URL root)
Display the given applet in a window with the given title; if it is not null, sources
are assumed to be rooted at the given URL. |
static void |
showApplet(String title,
Applet applet,
int width,
int height,
URL root,
Map<String,String> params)
Display the given applet in a window with the given title; if it is not null, sources
are assumed to be rooted at the given URL. |
static void |
showApplet(String title,
URL classPath,
String className,
int width,
int height)
Load the given applet class from the sources at URL classPath and display it in a window
with the given title. |
static void |
showApplet(String title,
URL classPath,
String className,
int width,
int height,
Map<String,String> params)
Load the given applet class from the sources at URL classPath and display it in a window
with the given title. |
static void |
showApplet(URL classPath,
String className,
int width,
int height)
Load the given applet class from the sources at URL classPath and display it in a window
with title "Applet Viewer". |
static void |
showDebug(String msg)
Invoke showPopup(java.lang.String, java.lang.String) with title "Debug Message". |
static void |
showPopup(String title,
String msg)
Show a modal message box with an OK button. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public SwingUtil()
| Method Detail |
|---|
public static Color gray(float degree)
0.0f corresponds to white;
1.0f corresponds to black.
public static JFrame makeMainApplicationFrame(String title,
int width,
int height)
public static JFrame makeDisposableFrame(String title,
int width,
int height)
public static JFrame makeReusableFrame(String title,
int width,
int height)
public static void onWindowClosed(Window w,
Runnable r)
public static void displayWindow(Window w)
JFrame).
public static JPanel makeHorizontalBoxPanel()
BoxLayout.
public static JPanel makeHorizontalBoxPanel(int margin)
BoxLayout; set the border to the given margin on all sides.
public static JPanel makeHorizontalBoxPanel(int vMargin,
int hMargin)
BoxLayout; set the border to the given vertical/horizontal margins.
public static JPanel makeHorizontalBoxPanel(int topMargin,
int leftMargin,
int bottomMargin,
int rightMargin)
BoxLayout; set the border to the given margins.
public static JPanel makeVerticalBoxPanel()
BoxLayout.
public static JPanel makeVerticalBoxPanel(int margin)
BoxLayout; set the border to the given margin on all sides.
public static JPanel makeVerticalBoxPanel(int vMargin,
int hMargin)
BoxLayout; set the border to the given vertical/horizontal margins.
public static JPanel makeVerticalBoxPanel(int topMargin,
int leftMargin,
int bottomMargin,
int rightMargin)
BoxLayout; set the border to the given margins.
public static JPanel makeBorderPanel()
BorderLayout.
public static JPanel makeBorderPanel(int margin)
BorderLayout; set the border to the given margin on all sides.
public static JPanel makeBorderPanel(int vMargin,
int hMargin)
BorderLayout; set the border to the given vertical/horizontal margins.
public static JPanel makeBorderPanel(int topMargin,
int leftMargin,
int bottomMargin,
int rightMargin)
BorderLayout; set the border to the given margins.
public static JPanel makeFlowPanel()
FlowLayout.
public static JPanel makeFlowPanel(int margin)
FlowLayout; set the border to the given margin on all sides.
public static JPanel makeFlowPanel(int vMargin,
int hMargin)
FlowLayout; set the border to the given vertical/horizontal margins.
public static JPanel makeFlowPanel(int topMargin,
int leftMargin,
int bottomMargin,
int rightMargin)
FlowLayout; set the border to the given margins.
public static void add(Container parent,
Component... children)
parent in sequence. Intended to reduce clutter in GUI code.
public static void setBackground(Color c,
Component... components)
public static void setForeground(Color c,
Component... components)
public static void setBorder(Border b,
JComponent... components)
public static void setEmptyBorder(int margin,
JComponent... components)
public static void setEmptyBorder(int vMargin,
int hMargin,
JComponent... components)
public static void setEmptyBorder(int top,
int left,
int bottom,
int right,
JComponent... components)
public static void setLineBorder(JComponent... components)
public static void setFont(Font f,
Component... components)
public static void setFont(String name,
int size,
Component... components)
public static void setSerifFont(int size,
Component... components)
"Serif" font of the given size.
public static void setSansSerifFont(int size,
Component... components)
"SansSerif" font of the given size.
public static void setMonospacedFont(int size,
Component... components)
"Monospaced" font of the given size.
public static void setDialogFont(int size,
Component... components)
"Dialog" font of the given size.
public static void setDialogInputFont(int size,
Component... components)
"DialogInput" font of the given size.
public static void setEnabled(boolean b,
Component... components)
public static void setFocusable(boolean b,
Component... components)
public static void setVisible(boolean b,
Component... components)
public static void setOpaque(boolean b,
JComponent... components)
public static void setPreferredSize(Dimension d,
JComponent... components)
JComponents, not arbitrary
Components.
public static void setPreferredSize(int width,
int height,
JComponent... components)
JComponents, not arbitrary
Components.
public static void setMaximumSize(Dimension d,
JComponent... components)
JComponents, not arbitrary
Components.
public static void setMaximumSize(int width,
int height,
JComponent... components)
JComponents, not arbitrary
Components.
public static void setMinimumSize(Dimension d,
JComponent... components)
JComponents, not arbitrary
Components.
public static void setMinimumSize(int width,
int height,
JComponent... components)
JComponents, not arbitrary
Components.
public static void setLeftAlignment(JComponent... components)
public static void setRightAlignment(JComponent... components)
public static void setHorizontalCenterAlignment(JComponent... components)
public static void setTopAlignment(JComponent... components)
public static void setBottomAlignment(JComponent... components)
public static void setVerticalCenterAlignment(JComponent... components)
public static void setAlignmentX(float a,
JComponent... components)
public static void setAlignmentY(float a,
JComponent... components)
public static void invokeLater(Runnable task)
public static void invokeAndWait(Runnable task)
WrappedException - Wrapping an InterruptedException if the current thread is interrupted
RuntimeException - If an exception is thrown by task
public static void clearEventQueue()
throws InterruptedException
IllegalStateException - If this is the event dispatch thread (it is impossible to wait
for the event queue to clear if this code is running in the
event queue).
InterruptedException - If this thread is interrupted while waiting.public static void attemptClearEventQueue()
IllegalStateException - If this is the event dispatch thread (it is impossible to wait
for the event queue to clear if this code is running in the
event queue).public static ActionListener asActionListener(Runnable r)
Runnable to an ActionListener
public static ActionListener asActionListener(Runnable1<? super ActionEvent> r)
Runnable1 to an ActionListener
public static Runnable1<ActionEvent> asRunnable(ActionListener l)
ActionListener to a Runnable1
public static FileFilter asSwingFileFilter(FileFilter filter,
String description)
JFileChoosers) in terms if a
FileFilter.
public static FileFilter asSwingFileFilter(Predicate<? super File> p,
String description)
JFileChoosers) in terms if a
FileFilter.
public static FileFilter asSwingFileFilter(FilePredicate p,
String description)
JFileChoosers) in terms if a
FileFilter. (Defined to disambiguate, since both other declarations apply to FilePredicates.)
public static ActionListener disposeAction(Window w)
Window.dispose() on the given window
public static void showDebug(String msg)
showPopup(java.lang.String, java.lang.String) with title "Debug Message". This may be called by any thread.
public static void showPopup(String title,
String msg)
msg - String to displaytitle - Title of the box
public static void showApplet(URL classPath,
String className,
int width,
int height)
throws ReflectException
classPath and display it in a window
with title "Applet Viewer".
ReflectException
public static void showApplet(String title,
URL classPath,
String className,
int width,
int height)
throws ReflectException
classPath and display it in a window
with the given title.
ReflectException
public static void showApplet(String title,
URL classPath,
String className,
int width,
int height,
Map<String,String> params)
throws ReflectException
classPath and display it in a window
with the given title.
ReflectException
public static void showApplet(Applet applet,
int width,
int height)
"Applet Viewer".
public static void showApplet(String title,
Applet applet,
int width,
int height)
public static void showApplet(String title,
Applet applet,
int width,
int height,
URL root)
null, sources
are assumed to be rooted at the given URL.
public static void showApplet(String title,
Applet applet,
int width,
int height,
URL root,
Map<String,String> params)
null, sources
are assumed to be rooted at the given URL.
public static String getClipboardSelection(Component c)
public static Action getAction(JTextComponent component,
String actionName)
null if no such action is found. See DefaultEditorKit for a list of
action name constants.
public static Map<String,Action> getActions(JTextComponent component)
component.getActions(), where the keys are the action
names. See DefaultEditorKit for a list of action name constants.
public static void setPopupLoc(Window popup)
setPopupLoc(Window, Component) that gets the owner from popup.getOwner()
public static void setPopupLoc(Window popup,
Component owner)
Sets the location of the popup in a consistent way. If the popup has an owner, the popup is centered over the owner. If the popup has no owner (owner == null), the popup is centered over the first monitor. In either case, the popup is moved and scaled if any part of it is not on the screen. This method should be called for all popups to maintain consistancy.
This method should only be called from the event thread.
popup - the popup windowowner - the parent component for the popup, or null
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||