📄 dialog.java.svn-base
字号:
* * @param title The title for the dialog optionally null; * @param text the text displayed in the dialog * @param defaultCommand command to be assigned as the default command or null * @param cmds commands that are added to the form any click on any command * will dispose the form * @param type the type of the alert one of TYPE_WARNING, TYPE_INFO, * TYPE_ERROR, TYPE_CONFIRMATION or TYPE_ALARM * @param icon the icon for the dialog, can be null * @param timeout a timeout after which null would be returned if timeout is 0 inifinite time is used * @param transition the transition installed when the dialog enters/leaves * @return the command pressed by the user */ public static Command show(String title, String text, Command defaultCommand, Command[] cmds, int type, Image icon, long timeout, Transition transition) { TextArea t = new TextArea(text, 3, 30); t.setStyle(UIManager.getInstance().getComponentStyle("DialogBody")); t.setEditable(false); return show(title, t, defaultCommand, cmds, type, icon, timeout, transition); } /** * Shows a modal prompt dialog with the given title and text. * * @param title The title for the dialog optionally null; * @param text the text displayed in the dialog * @param okText the text to appear in the command dismissing the dialog * @param cancelText optionally null for a text to appear in the cancel command * for canceling the dialog * @return true if the ok command was pressed or if cancelText is null. False otherwise. */ public static boolean show(String title, String text, String okText, String cancelText) { return show(title, text, TYPE_INFO, null, okText, cancelText); } /** * Shows a modal dialog with the given component as its "body" placed in the * center. * * @param title title for the dialog * @param body component placed in the center of the dialog * @param cmds commands that are added to the form any click on any command * will dispose the form * @return the command pressed by the user */ public static Command show(String title, Component body, Command[] cmds) { return show(title, body, cmds, TYPE_INFO, null); } /** * Shows a modal dialog with the given component as its "body" placed in the * center. * * @param title title for the dialog * @param body component placed in the center of the dialog * @param cmds commands that are added to the form any click on any command * will dispose the form * @param type the type of the alert one of TYPE_WARNING, TYPE_INFO, * TYPE_ERROR, TYPE_CONFIRMATION or TYPE_ALARM * @param icon the icon for the dialog, can be null * @return the command pressed by the user */ public static Command show(String title, Component body, Command[] cmds, int type, Image icon) { return show(title, body, cmds, type, icon, 0); } /** * Shows a modal dialog with the given component as its "body" placed in the * center. * * @param title title for the dialog * @param body component placed in the center of the dialog * @param cmds commands that are added to the form any click on any command * will dispose the form * @param type the type of the alert one of TYPE_WARNING, TYPE_INFO, * TYPE_ERROR, TYPE_CONFIRMATION or TYPE_ALARM * @param icon the icon for the dialog, can be null * @param timeout a timeout after which null would be returned if timeout is 0 inifinite time is used * @return the command pressed by the user */ public static Command show(String title, Component body, Command[] cmds, final int type, Image icon, long timeout) { return show(title, body, cmds, type, icon, timeout, null); } /** * Shows a modal dialog with the given component as its "body" placed in the * center. * * @param title title for the dialog * @param body component placed in the center of the dialog * @param cmds commands that are added to the form any click on any command * will dispose the form * @param type the type of the alert one of TYPE_WARNING, TYPE_INFO, * TYPE_ERROR, TYPE_CONFIRMATION or TYPE_ALARM * @param icon the icon for the dialog, can be null * @param timeout a timeout after which null would be returned if timeout is 0 inifinite time is used * the transition installed when the dialog enters/leaves * @return the command pressed by the user */ public static Command show(String title, Component body, Command[] cmds, int type, Image icon, long timeout, Transition transition) { return show(title, body, null, cmds, type, icon, timeout, transition); } /** * Shows a modal dialog with the given component as its "body" placed in the * center. * * @param title title for the dialog * @param body component placed in the center of the dialog * @param defaultCommand command to be assigned as the default command or null * @param cmds commands that are added to the form any click on any command * will dispose the form * @param type the type of the alert one of TYPE_WARNING, TYPE_INFO, * TYPE_ERROR, TYPE_CONFIRMATION or TYPE_ALARM * @param icon the icon for the dialog, can be null * @param timeout a timeout after which null would be returned if timeout is 0 inifinite time is used * the transition installed when the dialog enters/leaves * @return the command pressed by the user */ public static Command show(String title, Component body, Command defaultCommand, Command[] cmds, int type, Image icon, long timeout, Transition transition) { Dialog dialog = new Dialog(title); dialog.dialogType = type; dialog.setTransitionInAnimator(transition); dialog.setTransitionOutAnimator(transition); dialog.lastCommandPressed = null; if(cmds != null) { for(int iter = 0 ; iter < cmds.length ; iter++) { dialog.addCommand(cmds[iter]); } } dialog.setLayout(new BorderLayout()); dialog.addComponent(BorderLayout.CENTER, body); if (icon != null) { dialog.addComponent(BorderLayout.EAST, new Label(icon)); } if (timeout != 0) { dialog.setTimeout(timeout); } dialog.show(); return dialog.lastCommandPressed; } /** * @inheritDoc */ protected void onShow() { if (dialogType > 0) { Display.getInstance().playDialogSound(dialogType); } } /** * The default version of show modal shows the dialog occupying the center portion * of the screen. */ public void show() { // this behavior allows a use case where dialogs of various sizes are layered // one on top of the other setDisposed(false); if(top > -1) { show(top, bottom, left, right, includeTitle, modal); } else { if(modal) { super.showModal(); } else { showModeless(); } } } /** * Shows a modeless dialog which is useful for some simpler use cases such as * progress indication etc... */ public void showModeless() { // this behavior allows a use case where dialogs of various sizes are layered // one on top of the other modal = false; setDisposed(false); if(top > -1) { show(top, bottom, left, right, includeTitle, false); } else { showDialog(false); } } /** * Closes the current form and returns to the previous form, releasing the * EDT in the process */ public void dispose() { setDisposed(true); if(!menu) { super.dispose(); } } /** * @inheritDoc */ public void refreshTheme() { Container content = getContentPane(); content.refreshTheme(dialogUIID); Style titleStyle = getTitleStyle(); if (titleStyle.isModified()) { titleStyle.merge(UIManager.getInstance().getComponentStyle(dialogTitleUIID)); } else { setTitleStyle(UIManager.getInstance().getComponentStyle(dialogTitleUIID)); } int size = content.getComponentCount(); for (int i = 0; i < size; i++) { Component cmp = content.getComponentAt(i); cmp.refreshTheme(); } } /** * Shows a modal dialog and returns the command pressed within the modal dialog * * @return last command pressed in the modal dialog */ public Command showDialog() { lastCommandPressed = null; show(); return lastCommandPressed; } /** * Invoked to allow subclasses of form to handle a command from one point * rather than implementing many command instances * * @param cmd the action command */ protected void actionCommand(Command cmd) { lastCommandPressed = cmd; if(menu || (autoDispose && cmd.isDisposesDialog())) { dispose(); } } /** * @inheritDoc */ public boolean animate() { if (time != 0 && System.currentTimeMillis() >= time) { time = 0; dispose(); } return false; } /** * @inheritDoc */ protected void sizeChanged(int w, int h) { Form frm = getPreviousForm(); while (frm instanceof Dialog) { frm = frm.getPreviousForm(); } frm.setSize(new Dimension(w, h)); frm.setShouldCalcPreferredSize(true); frm.doLayout(); super.sizeChanged(w, h); } /** * Indicates that this is a menu preventing getCurrent() from ever returning this class */ boolean isMenu() { return menu; } /** * Indicates that this is a menu preventing getCurrent() from ever returning this class */ void setMenu(boolean menu) { this.menu = menu; } /** * Prevent a menu from adding the select button */ void addSelectCommand() { if (!menu) { super.addSelectCommand(); } } /** * Allows us to indicate disposed state for dialogs */ boolean isDisposed() { return disposed; } /** * Allows us to indicate disposed state for dialogs */ void setDisposed(boolean disposed) { this.disposed = disposed; } /** * Determins whether the execution of a command on this dialog implicitly * disposes the dialog. This defaults to true which is a sensible default for * simple dialogs. */ public boolean isAutoDispose() { return autoDispose; } /** * Determins whether the execution of a command on this dialog implicitly * disposes the dialog. This defaults to true which is a sensible default for * simple dialogs. */ public void setAutoDispose(boolean autoDispose) { this.autoDispose = autoDispose; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -