|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.antelmann.util.gui.Menus
public final class Menus
this class provides some convenient menus, dialogs and other functions (additions to SwingUtilities)
that are potentially useful for any Java Swing Application.
If available, it takes advantage of
com.incors.plaf.kunststoff.KunststoffLookAndFeel and com.jgoodies.looks.
| Field Summary | |
|---|---|
static String |
aboutString
|
static String |
EXCEPTION_KEY
used to put the thrown Exception as a value into the specialExceptionAction |
| Constructor Summary | |
|---|---|
Menus()
|
|
| Method Summary | ||
|---|---|---|
static void |
addActionToMenu(JMenu menu,
Action action,
String menuKey,
String menuDelimiter)
adds the given action to the given menu |
|
static void |
addActionToMenu(JMenuBar menuBar,
Action action,
String menuKey,
String menuDelimiter)
adds the given action to the given menu bar |
|
static Appendable |
asAppendable(JTextArea ta)
|
|
static void |
bringToFront(Component c)
attempts several things to bring the component to the front w/ focus; works well for all components that either are or have a parent of the type Window or JInternalFrame |
|
static void |
cascadeInternalFrames(JDesktopPane desktop)
|
|
static void |
center(Component c)
centers the given Component in the middle of the screen |
|
static void |
clickOnKey(AbstractButton button,
KeyStroke keyStroke,
Object actionKey)
|
|
static boolean |
confirm(Component parent,
Object message)
|
|
static JMenuItem |
createAboutBoxMenuItem(Frame parent)
returns an 'about' menu capable of displaying an Antelmann.com's info box. |
|
static JMenuItem |
createAboutDialogMenuItem(Frame parent)
returns an 'about' menu capable of displaying an Antelmann.com's info box. |
|
static JPopupMenu |
createCopyPasteMenu(JTextComponent comp)
|
|
static JMenuBar |
createDefaultMenuBar(Frame parent)
returns a convenient standard JMenuBar to be used with any Frame |
|
static JDialog |
createDialog(Component parent,
String title,
boolean modal)
|
|
static JMenu |
createLookAndFeelMenu(Component rootComponent)
createLookAndFeelMenu() generates a JMenu that lets the user select from different look&feel options. |
|
static JMenu |
createLookAndFeelMenu(Component component,
boolean searchForRootAtRuntime)
|
|
static ValueRetriever<JPopupMenu> |
createUndoMenuRetriever(UndoManager manager)
|
|
static boolean |
disposeComponent(Component c)
|
|
static void |
enableActionOnKey(JComponent component,
KeyStroke keyStroke,
ActionListener al,
Object actionKey)
|
|
static void |
enableCopyPasteKeys(JComponent... comps)
enables Ctrl-X, Ctrl-C, Ctrl-V for the given component |
|
static void |
enableCopyPasteMenu(JTextComponent... comps)
|
|
static void |
enableMouseContextMenu(Component comp,
JPopupMenu menu)
adds a MouseListener to the given Component that activates the given menu upon right-mouse-click |
|
static void |
enableMouseContextMenu(Component comp,
ValueRetriever<JPopupMenu> retriever)
useful if the menu is really to be created at the time of invocation |
|
static UndoManager |
enableUndo(JTextComponent tc)
enables undo with 'Ctrl-z' and redo with 'Ctrl-y' |
|
static
|
findComponents(Class<T> type,
Component comp)
|
|
static
|
findFirstComponent(Class<T> type,
Component comp)
|
|
static ImageIcon |
getAntelmannIcon()
|
|
static JComponent |
getComponentFor(Object object)
|
|
static Dialog |
getDialogForComponent(Component component)
|
|
static Box.Filler |
getFiller(int width,
int height)
|
|
static ResourceBundle |
getLanguage(Locale locale)
|
|
static String[] |
getLookAndFeelNames()
|
|
static Dimension |
getScaledScreenSize(Component c,
double xfactor,
double yfactor)
|
|
static Action |
getSpecialExceptionAction()
|
|
static boolean |
isCapsLockOn()
|
|
static ResourceBundle |
language()
provides access to the Locale specific language used in this package |
|
static void |
makeCompactSpringGrid(Container parent,
int rows,
int cols,
int padding)
|
|
static void |
makeCompactSpringGrid(Container parent,
int rows,
int cols,
int initialX,
int initialY,
int xPad,
int yPad)
Aligns the first rows * cols
components of parent in
a grid. |
|
static void |
makeFloat(JToolBar toolbar)
centers the given toolbar floating on the center of the component that contains the toolbar |
|
static void |
makeFloat(JToolBar toolbar,
int x,
int y)
makes the toolbar floating (as if later dragged with the mouse); call this only after the component was added to a window. |
|
static void |
makeSpringGrid(Container parent,
int rows,
int cols,
int padding)
|
|
static void |
makeSpringGrid(Container parent,
int rows,
int cols,
int initialX,
int initialY,
int xPad,
int yPad)
Aligns the first rows * cols
components of parent in
a grid. |
|
static JFrame |
makeVisibleOffscreenFrame()
creates a frame that is drawn offscreen but visible for providing a default component for message boxes (needs to be disposed hereafter) |
|
static
|
resizePreferred(T comp,
double xfactor,
double yfactor)
|
|
static void |
selectTabFor(Component c)
|
|
static void |
setCapsLock(boolean flag)
|
|
static void |
setLanguage(Locale locale)
|
|
static void |
setLightWeight(boolean flag)
for reference; this is true by default (but also can be set for each JComponent separately) |
|
static boolean |
setLookAndFeel(String name)
|
|
static boolean |
setPlatformLookAndFeel()
|
|
static void |
setSpecialExceptionAction(Action action)
allows to register a special action that is provided as a button when displaying an Exception |
|
static boolean |
setStandardLookAndFeel()
|
|
static void |
showAboutBox(Component parent)
shows a small antelmann.com about dialog |
|
static void |
showAboutDialog(Component parent)
shows the standard antelmann.com about dialog with license, version and upgrade button |
|
static int |
showConfirmDialog(Component parent,
String title,
Object message,
boolean resizable,
int messageType)
|
|
static int |
showDialog(Component parent,
String title,
Object message,
boolean resizable,
int optionType,
int messageType)
|
|
static void |
showExceptionDialog(Component parent,
Throwable ex)
|
|
static void |
showExceptionDialog(Component parent,
Throwable ex,
Thread t)
if the given Throwable is an instance of WarningOnly, showWarning(Component, Throwable)
is called |
|
static void |
showExceptionDialog(Throwable ex)
|
|
static void |
showLicenseDialog(Component parent)
|
|
static int |
showMessageDialog(Component parent,
String title,
Object message,
boolean resizable,
int messageType)
|
|
static void |
showPropertiesDialog(String title,
Map<?,?> properties,
Component parent,
boolean modal)
Deprecated. use makePropertiesTable with JOptionPane instead |
|
static void |
showVersionDialog(Component parent)
|
|
static void |
showWarning(Component parent,
Throwable ex)
|
|
static void |
sizeToScreen(Component c,
double xfactor,
double yfactor)
sets the size of the given component relative to the screen size |
|
static boolean |
useLookAndFeelName(String name)
|
|
static Component |
wrapToScreen(Component c)
|
|
static Component |
wrapToScreen(Component c,
double widthFactor,
double heightFactor)
returns either the given Component or a JScrollPane that is sized appropriately |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String aboutString
public static final String EXCEPTION_KEY
setSpecialExceptionAction(Action),
Constant Field Values| Constructor Detail |
|---|
public Menus()
| Method Detail |
|---|
public static String[] getLookAndFeelNames()
setLookAndFeel(String)public static boolean setLookAndFeel(String name)
UIManager.LookAndFeelInfo.getName()public static boolean setStandardLookAndFeel()
public static boolean setPlatformLookAndFeel()
public static ImageIcon getAntelmannIcon()
public static ResourceBundle getLanguage(Locale locale)
public static ResourceBundle language()
public static void setLanguage(Locale locale)
public static void setLightWeight(boolean flag)
JComboBox.setLightWeightPopupEnabled(boolean),
JPopupMenu.setLightWeightPopupEnabled(boolean)public static void makeFloat(JToolBar toolbar)
makeFloat(JToolBar, int, int)
public static void makeFloat(JToolBar toolbar,
int x,
int y)
AncestorListener.ancestorAdded(AncestorEvent),
you must ensure that this method is only executed once, since this method itself will invoke
the listener's method.
toolbar - the toolbar that is to made floatingx - horizontal offset from the top left screen edge defining where the toolbar should floaty - vertical offset from the top left screen edge defining where the toolbar should floatpublic static void center(Component c)
Window.setLocationRelativeTo(Component)
public static <T extends Component> T resizePreferred(T comp,
double xfactor,
double yfactor)
public static void sizeToScreen(Component c,
double xfactor,
double yfactor)
c - the component to be resizedxfactor - the width relative to the screen; 0.5 will set the width to half the screen widthyfactor - the height relative to the screen; 0.5 will set the height to half the screen height
public static Dimension getScaledScreenSize(Component c,
double xfactor,
double yfactor)
c - the component that may specify which screen we are on (if we had multiple screens)public static JMenuBar createDefaultMenuBar(Frame parent)
public static JFrame makeVisibleOffscreenFrame()
public static void selectTabFor(Component c)
public static void bringToFront(Component c)
Window or JInternalFrame
c - the component to be made restored, visible on top and having focuspublic static JMenu createLookAndFeelMenu(Component rootComponent)
rootComponent - the top component of the GUI tree that needs to be updated
public static JMenu createLookAndFeelMenu(Component component,
boolean searchForRootAtRuntime)
public static boolean useLookAndFeelName(String name)
public static JMenuItem createAboutDialogMenuItem(Frame parent)
parent - the component over which the modal dialog is to be placedpublic static JMenuItem createAboutBoxMenuItem(Frame parent)
parent - the component over which the modal dialog is to be placedpublic static void showAboutBox(Component parent)
public static void showAboutDialog(Component parent)
public static void showVersionDialog(Component parent)
public static void showLicenseDialog(Component parent)
@Deprecated
public static void showPropertiesDialog(String title,
Map<?,?> properties,
Component parent,
boolean modal)
makePropertiesTable with JOptionPane instead
TableUtils.makePropertiesTable(Map, String, String)public static Action getSpecialExceptionAction()
public static void setSpecialExceptionAction(Action action)
showExceptionDialog(Component, Throwable, Thread),
EXCEPTION_KEYpublic static void showExceptionDialog(Throwable ex)
public static void showExceptionDialog(Component parent,
Throwable ex)
public static void showExceptionDialog(Component parent,
Throwable ex,
Thread t)
WarningOnly, showWarning(Component, Throwable)
is called
WarningOnly
public static void showWarning(Component parent,
Throwable ex)
public static boolean confirm(Component parent,
Object message)
public static int showConfirmDialog(Component parent,
String title,
Object message,
boolean resizable,
int messageType)
public static int showMessageDialog(Component parent,
String title,
Object message,
boolean resizable,
int messageType)
public static int showDialog(Component parent,
String title,
Object message,
boolean resizable,
int optionType,
int messageType)
public static JDialog createDialog(Component parent,
String title,
boolean modal)
JOptionPane.createDialog(Component, String)public static Dialog getDialogForComponent(Component component)
public static void setCapsLock(boolean flag)
throws UnsupportedOperationException
UnsupportedOperationException
public static boolean isCapsLockOn()
throws UnsupportedOperationException
UnsupportedOperationException
public static void makeSpringGrid(Container parent,
int rows,
int cols,
int padding)
public static void makeSpringGrid(Container parent,
int rows,
int cols,
int initialX,
int initialY,
int xPad,
int yPad)
rows * cols
components of parent in
a grid. Each component is as big as the maximum
preferred width and height of the components.
The parent is made just big enough to fit them all.
The parent component must be a SpringLayout.
The code for this method is based on the tutorial from the Sun Java website.
rows - number of rows; if 0 is given, the number of rows is
the number of components by the container divided by the number of columns;
note, however, that the component must contain exactly rows * columns components!cols - number of columnsinitialX - x location to start the grid atinitialY - y location to start the grid atxPad - x padding between cellsyPad - y padding between cells
public static void makeCompactSpringGrid(Container parent,
int rows,
int cols,
int padding)
makeCompactSpringGrid(Container, int, int, int, int, int, int)
public static void makeCompactSpringGrid(Container parent,
int rows,
int cols,
int initialX,
int initialY,
int xPad,
int yPad)
rows * cols
components of parent in
a grid. Each component in a column is as wide as the maximum
preferred width of the components in that column;
height is similarly determined for each row.
The parent is made just big enough to fit them all.
The parent component must be a SpringLayout.
The code for this method is based on the tutorial from the Sun Java website.
rows - number of rows; if 0 is given, the number of rows is
the number of components by the container divided by the number of columns.
If there are fewer components than given by the product of rows and colums,
filler components are automatically used.cols - number of columnsinitialX - x location to start the grid atinitialY - y location to start the grid atxPad - x padding between cellsyPad - y padding between cellsSpringLayout
public static Box.Filler getFiller(int width,
int height)
public static UndoManager enableUndo(JTextComponent tc)
public static ValueRetriever<JPopupMenu> createUndoMenuRetriever(UndoManager manager)
public static void enableCopyPasteKeys(JComponent... comps)
TransferHandler.getCopyAction(),
TransferHandler.getPasteAction(),
TransferHandler.getCutAction()public static void enableCopyPasteMenu(JTextComponent... comps)
public static JPopupMenu createCopyPasteMenu(JTextComponent comp)
public static void enableMouseContextMenu(Component comp,
JPopupMenu menu)
JComponent.setComponentPopupMenu(JPopupMenu)
public static void enableMouseContextMenu(Component comp,
ValueRetriever<JPopupMenu> retriever)
public static Component wrapToScreen(Component c)
public static Component wrapToScreen(Component c,
double widthFactor,
double heightFactor)
public static void addActionToMenu(JMenuBar menuBar,
Action action,
String menuKey,
String menuDelimiter)
menuBar - the menu bar to which the action is to be addedaction - the action to be addedmenuKey - specifies the menu name to be used to place the action; if null or empty, the action is not placed at allmenuDelimiter - specifies a delimiter that allows to specify a hierarchy of sub-menus with the menuKey parameter
public static void addActionToMenu(JMenu menu,
Action action,
String menuKey,
String menuDelimiter)
menu - the menu to which the action is to be addedaction - the action to be addedmenuKey - allows to specify a submenu under which the given action is to be placed within the structuremenuDelimiter - specifies a delimiter that allows to specify a hierarchy of sub-menus with the menuKey parameterpublic static JComponent getComponentFor(Object object)
public static void enableActionOnKey(JComponent component,
KeyStroke keyStroke,
ActionListener al,
Object actionKey)
public static void clickOnKey(AbstractButton button,
KeyStroke keyStroke,
Object actionKey)
public static <T extends Component> T findFirstComponent(Class<T> type,
Component comp)
public static <T extends Component> ArrayList<T> findComponents(Class<T> type,
Component comp)
public static Appendable asAppendable(JTextArea ta)
public static void cascadeInternalFrames(JDesktopPane desktop)
public static boolean disposeComponent(Component c)
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||