Back to index

wims  3.65+svn20090927
Public Member Functions | Static Public Attributes | Protected Member Functions | Package Functions | Package Attributes | Private Member Functions | Private Attributes
SharpTools.SharpDialog Class Reference
Inheritance diagram for SharpTools.SharpDialog:
Inheritance graph
[legend]
Collaboration diagram for SharpTools.SharpDialog:
Collaboration graph
[legend]

List of all members.

Public Member Functions

int getChoice ()
boolean isCancelled ()

Static Public Attributes

static final int CLOSED_OPTION = JOptionPane.CLOSED_OPTION
static final int YES_OPTION = JOptionPane.YES_OPTION
static final int NO_OPTION = JOptionPane.NO_OPTION
static final int OK_OPTION = JOptionPane.OK_OPTION
static final int CANCEL_OPTION = JOptionPane.CANCEL_OPTION

Protected Member Functions

JRootPane createRootPane ()
 override this protected funciton to register ESCAPE with the root pane
void onOpen ()
 I provide several hooks for the sublasses to override.
boolean onClose ()
 This function is called when (1) the close button is clocked (2) Escape is pressed.
boolean onOK ()
 This function is called when the OK button is pressed.
boolean onCancel ()
 This function is called when the Cancel button is pressed.
boolean onYes ()
 This function is called when the Yes button is pressed.
boolean onNo ()
 This function is called when the No button is pressed.
void setOptionPane (Object message, int messageType, int optionType, Icon icon)
 This is used by subclasses to set the JOptionPane component in the dialog.
void setOptionPane (Object message, int messageType, int optionType, Icon icon, int defaultIndex)
 This is used by subclasses to set the JOptionPane component in the dialog.

Package Functions

 SharpDialog (Dialog c)
 create a non-modal dialog
 SharpDialog (Dialog c, boolean modal)
 SharpDialog (Dialog c, String title)
 create a non-modal dialog
 SharpDialog (Dialog c, String title, boolean modal)
 SharpDialog (Frame c)
 create a non-modal dialog
 SharpDialog (Frame c, boolean modal)
 SharpDialog (Frame c, String title)
 create a non-modal dialog
 SharpDialog (Frame c, String title, boolean modal)

Package Attributes

final ImageIcon okIcon = new ImageIcon(getClass().getResource("/images/ok.gif"))
final ImageIcon cancelIcon = new ImageIcon(getClass().getResource("/images/cancel.gif"))
final ImageIcon noIcon = new ImageIcon(getClass().getResource("/images/no.gif"))

Private Member Functions

Object[] setButtons (int type)
 set button array

Private Attributes

final JButton okButton = new JButton(UIManager.get("OptionPane.okButtonText").toString(), okIcon)
final JButton cancelButton = new JButton(UIManager.get("OptionPane.cancelButtonText").toString(), cancelIcon)
final JButton yesButton = new JButton(UIManager.get("OptionPane.yesButtonText").toString(), okIcon)
final JButton noButton = new JButton(UIManager.get("OptionPane.noButtonText").toString(), noIcon)
final Object[] ok = { okButton }
final Object[] yesno = { yesButton, noButton }
final Object[] yesnocancel = { yesButton, noButton, cancelButton }
final Object[] okcancel = { okButton, cancelButton }
int choice = CLOSED_OPTION

Detailed Description

See also:
PasswordDialog
NewFileDialog
FindDialog
SortDialog
HistoDialog
ConnectDialog

Definition at line 21 of file SharpDialog.java.


Constructor & Destructor Documentation

SharpTools.SharpDialog.SharpDialog ( Dialog  c) [inline, package]

create a non-modal dialog

Parameters:
cparent dialog

Definition at line 54 of file SharpDialog.java.

                          {
       super(c);
    }
SharpTools.SharpDialog.SharpDialog ( Dialog  c,
boolean  modal 
) [inline, package]
Parameters:
cparent dialog
modelwhether to create a modal dialog

Definition at line 62 of file SharpDialog.java.

                                         {
       super(c, modal);
    }
SharpTools.SharpDialog.SharpDialog ( Dialog  c,
String  title 
) [inline, package]

create a non-modal dialog

Parameters:
cparent dialog
titletitle

Definition at line 72 of file SharpDialog.java.

                                        {
       super(c, title);
    }
SharpTools.SharpDialog.SharpDialog ( Dialog  c,
String  title,
boolean  modal 
) [inline, package]
Parameters:
cparent dialog
titletitle
modelwhether to create a modal dialog

Definition at line 81 of file SharpDialog.java.

                                                       {
       super(c, title, modal);
    }
SharpTools.SharpDialog.SharpDialog ( Frame  c) [inline, package]

create a non-modal dialog

Parameters:
cparent frame

Definition at line 90 of file SharpDialog.java.

                         {
       super(c);
    }
SharpTools.SharpDialog.SharpDialog ( Frame  c,
boolean  modal 
) [inline, package]
Parameters:
cparent frame
modelwhether to create a modal dialog

Definition at line 98 of file SharpDialog.java.

                                        {
       super(c, modal);
    }
SharpTools.SharpDialog.SharpDialog ( Frame  c,
String  title 
) [inline, package]

create a non-modal dialog

Parameters:
cparent frame
titletitle

Definition at line 108 of file SharpDialog.java.

                                       {
       super(c, title);
    }
SharpTools.SharpDialog.SharpDialog ( Frame  c,
String  title,
boolean  modal 
) [inline, package]
Parameters:
cparent frame
titletitle
modelwhether to create a modal dialog

Definition at line 117 of file SharpDialog.java.

                                                      {
       super(c, title, modal);
    }

Member Function Documentation

JRootPane SharpTools.SharpDialog.createRootPane ( ) [inline, protected]

override this protected funciton to register ESCAPE with the root pane

Returns:
a customized JRootPane object

Definition at line 126 of file SharpDialog.java.

                                         {
       KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
       JRootPane rootPane = new JRootPane();
       rootPane.registerKeyboardAction(
                                   new ActionListener() {
                                          public void actionPerformed
                                              (ActionEvent ev) {    
                                              if (onClose()) {
                                                 choice = CLOSED_OPTION;
                                                 setVisible(false);
                                              }
                                          }
                                       },
                                   stroke,
                                   JComponent.WHEN_IN_FOCUSED_WINDOW);
       return rootPane;
    }

Here is the call graph for this function:

Returns:
user choice

Definition at line 344 of file SharpDialog.java.

                           {
       return choice;
    }

Here is the caller graph for this function:

Returns:
whether this operation was cancelled

Definition at line 351 of file SharpDialog.java.

                                 {
       return choice == CANCEL_OPTION || choice == CLOSED_OPTION;
    }

Here is the caller graph for this function:

boolean SharpTools.SharpDialog.onCancel ( ) [inline, protected]

This function is called when the Cancel button is pressed.

Returns:
whether the dialog should be closed

Reimplemented in SharpTools.SortDialog, SharpTools.NewFileDialog, and SharpTools.PasswordDialog.

Definition at line 187 of file SharpDialog.java.

                                 {
       return true;
    }

Here is the caller graph for this function:

boolean SharpTools.SharpDialog.onClose ( ) [inline, protected]

This function is called when (1) the close button is clocked (2) Escape is pressed.

By default, we think it's the same as clicking Cancel button

Returns:
whether the dialog should be closed

Reimplemented in SharpTools.NewFileDialog.

Definition at line 167 of file SharpDialog.java.

                                {
       return onCancel();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

boolean SharpTools.SharpDialog.onNo ( ) [inline, protected]

This function is called when the No button is pressed.

Returns:
whether the dialog should be closed

Definition at line 207 of file SharpDialog.java.

                             {
       return true;
    }

Here is the caller graph for this function:

boolean SharpTools.SharpDialog.onOK ( ) [inline, protected]

This function is called when the OK button is pressed.

Returns:
whether the dialog should be closed

Reimplemented in SharpTools.HistoDialog, SharpTools.SortDialog, SharpTools.ConnectDialog, SharpTools.NewFileDialog, SharpTools.FindDialog, and SharpTools.PasswordDialog.

Definition at line 177 of file SharpDialog.java.

                             {     
       return true;
    }

Here is the caller graph for this function:

void SharpTools.SharpDialog.onOpen ( ) [inline, protected]

I provide several hooks for the sublasses to override.

This function is called when the dialog window is opened.

Reimplemented in SharpTools.ConnectDialog, SharpTools.NewFileDialog, SharpTools.PasswordDialog, and SharpTools.FindDialog.

Definition at line 153 of file SharpDialog.java.

                            {
       
    }

Here is the caller graph for this function:

boolean SharpTools.SharpDialog.onYes ( ) [inline, protected]

This function is called when the Yes button is pressed.

Returns:
whether the dialog should be closed

Definition at line 197 of file SharpDialog.java.

                              {
       return true;
    }

Here is the caller graph for this function:

Object [] SharpTools.SharpDialog.setButtons ( int  type) [inline, private]

set button array

Definition at line 319 of file SharpDialog.java.

                                          {

       Object[] buttons;
       
       switch (type) {
       case JOptionPane.YES_NO_CANCEL_OPTION:
           buttons = yesnocancel;
           break;
       case JOptionPane.YES_NO_OPTION:
           buttons = yesno;
           break;
       case JOptionPane.OK_CANCEL_OPTION:     
           buttons = okcancel;
           break;
       default:
           buttons = ok;
           break;
       }

       return buttons;
    }

Here is the caller graph for this function:

void SharpTools.SharpDialog.setOptionPane ( Object  message,
int  messageType,
int  optionType,
Icon  icon 
) [inline, protected]

This is used by subclasses to set the JOptionPane component in the dialog.

Parameters:
messagethe message box
messageTypethe message type
optionTypethe option type
iconthe icon to display

Definition at line 220 of file SharpDialog.java.

                                        {
       
       setOptionPane(message, messageType, optionType, icon, 0);
    }

Here is the caller graph for this function:

void SharpTools.SharpDialog.setOptionPane ( Object  message,
int  messageType,
int  optionType,
Icon  icon,
int  defaultIndex 
) [inline, protected]

This is used by subclasses to set the JOptionPane component in the dialog.

Parameters:
messagethe message box
messageTypethe message type
optionTypethe option type
iconthe icon to display
defaultIndexthe default index

Definition at line 238 of file SharpDialog.java.

                                               {
       
       addWindowListener(new WindowAdapter() {

              public void windowOpened(WindowEvent we) {
                  // set the initial focus to rowField
                  onOpen();
              }
              
                public void windowClosing(WindowEvent we) {
                  if (onClose()) {
                     choice = CLOSED_OPTION;
                     setVisible(false);
                  }
              }
           });
       
       // handle this by onClose()
       setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

       okButton.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent evt) {
                  if (onOK()) {
                     choice = OK_OPTION;
                     setVisible(false);
                  }
              }
           });

       cancelButton.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent evt) {
                  if (onCancel()) {
                     choice = CANCEL_OPTION;
                     setVisible(false);
                  }
              }
           });
       
       yesButton.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent evt) {
                  if (onYes()) {
                     choice = YES_OPTION;
                     setVisible(false);
                  }
              }
           });
       
       noButton.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent evt) {
                  if (onNo()) {
                     choice = NO_OPTION;
                     setVisible(false);
                  }
              }
           });

       // setup Mnemonic
       okButton.setMnemonic (KeyEvent.VK_O);
       cancelButton.setMnemonic (KeyEvent.VK_C);
       yesButton.setMnemonic (KeyEvent.VK_Y);
       noButton.setMnemonic (KeyEvent.VK_N);
       
       Object[] buttons = setButtons(optionType);
       JOptionPane optionPane = new JOptionPane(message, messageType,
                                           optionType, icon,
                                           buttons,
                                           buttons[defaultIndex]);
       
       setContentPane(optionPane);

       pack();
       setLocationRelativeTo(getParent());
    }

Here is the call graph for this function:


Member Data Documentation

final int SharpTools.SharpDialog.CANCEL_OPTION = JOptionPane.CANCEL_OPTION [static]

Definition at line 26 of file SharpDialog.java.

final JButton SharpTools.SharpDialog.cancelButton = new JButton(UIManager.get("OptionPane.cancelButtonText").toString(), cancelIcon) [private]

Definition at line 36 of file SharpDialog.java.

final ImageIcon SharpTools.SharpDialog.cancelIcon = new ImageIcon(getClass().getResource("/images/cancel.gif")) [package]

Definition at line 28 of file SharpDialog.java.

Definition at line 45 of file SharpDialog.java.

final int SharpTools.SharpDialog.CLOSED_OPTION = JOptionPane.CLOSED_OPTION [static]

Definition at line 22 of file SharpDialog.java.

final int SharpTools.SharpDialog.NO_OPTION = JOptionPane.NO_OPTION [static]

Definition at line 24 of file SharpDialog.java.

final JButton SharpTools.SharpDialog.noButton = new JButton(UIManager.get("OptionPane.noButtonText").toString(), noIcon) [private]

Definition at line 38 of file SharpDialog.java.

final ImageIcon SharpTools.SharpDialog.noIcon = new ImageIcon(getClass().getResource("/images/no.gif")) [package]

Definition at line 29 of file SharpDialog.java.

final Object [] SharpTools.SharpDialog.ok = { okButton } [private]

Definition at line 40 of file SharpDialog.java.

final int SharpTools.SharpDialog.OK_OPTION = JOptionPane.OK_OPTION [static]

Definition at line 25 of file SharpDialog.java.

final JButton SharpTools.SharpDialog.okButton = new JButton(UIManager.get("OptionPane.okButtonText").toString(), okIcon) [private]

Definition at line 35 of file SharpDialog.java.

final Object [] SharpTools.SharpDialog.okcancel = { okButton, cancelButton } [private]

Definition at line 43 of file SharpDialog.java.

final ImageIcon SharpTools.SharpDialog.okIcon = new ImageIcon(getClass().getResource("/images/ok.gif")) [package]

Definition at line 27 of file SharpDialog.java.

final int SharpTools.SharpDialog.YES_OPTION = JOptionPane.YES_OPTION [static]

Definition at line 23 of file SharpDialog.java.

final JButton SharpTools.SharpDialog.yesButton = new JButton(UIManager.get("OptionPane.yesButtonText").toString(), okIcon) [private]

Definition at line 37 of file SharpDialog.java.

final Object [] SharpTools.SharpDialog.yesno = { yesButton, noButton } [private]

Definition at line 41 of file SharpDialog.java.

Definition at line 42 of file SharpDialog.java.


The documentation for this class was generated from the following file: