com.togethersoft.openapi.util.ui
Class DialogHelper


public class DialogHelper

Presents uniform key bindings for dialog box, so ESCAPE key sloses dialog
box and ENTER acts as default button.
example of usage:


public class MyGuiBuilder implements ActionListener {
public MyGuiBuilder() {

myDialog = IdeAccess.getWindowManager().createDialog(null);
// or
// myDialog=new JDialog();
// if its non-Together's dialog

DialogHelper.bindEscapeKeyAction(myDialog, this);
DialogHelper.bindEnterKeyAction(myDialog, this);
initComponents();
DialogHelper.setDefaultButton(myDialog, myOkButton);
}

public void actionPerformed(ActionEvent evt) {
String actionCommand = evt.getActionCommand();
if (IdeButtonType.CANCEL.equals(actionCommand)) {
doSomeWorkonCancel();
myDialog.dispose();
myDialog = null;
} else if (IdeButtonType.OK.equals(actionCommand)) {
doSomeWorkonOK();
myDialog.dispose();
myDialog = null;
}
}
private JDialog myDialog;
private JButton myOkButton;
}

Author:
TogetherSoft
Since: Together 4.0

Method Summary
 static voidbindEnterKeyAction(JDialog dialog, ActionListener listener)
          Bind ENTER key with OK action.
 static voidbindEscapeKeyAction(JDialog dialog, ActionListener listener)
          Bind ESCAPE key with CANCEL action.
 static voidbindKeyAction(JDialog dialog, int virtualKeyCode, ActionListener listener, String command)
          Register a new keyboard action for specified dialog box.
 static KeyListenercreateKeyListener(Component comp, int virtualKeyCode)
          Returned KeyListener for comp that dispatch key with virtualKeyCode to top level component
 static voidsetDefaultButton(JDialog dialog, JButton button)
          Sets specified button as the default for specified dialog.

Method Detail

bindEnterKeyAction

public static void bindEnterKeyAction(JDialog dialog, ActionListener listener)
Bind ENTER key with OK action.

bindEscapeKeyAction

public static void bindEscapeKeyAction(JDialog dialog, ActionListener listener)
Bind ESCAPE key with CANCEL action.

bindKeyAction

public static void bindKeyAction(JDialog dialog, int virtualKeyCode, ActionListener listener, String command)
Register a new keyboard action for specified dialog box.
listenervirtualKeyCode occurs.

createKeyListener

public static KeyListener createKeyListener(Component comp, int virtualKeyCode)
Returned KeyListener for comp that dispatch key with virtualKeyCode to top level component

setDefaultButton

public static void setDefaultButton(JDialog dialog, JButton button)
Sets specified button as the default for specified dialog.