Back to index

wims  3.65+svn20090927
Public Member Functions | Static Public Attributes | Protected Member Functions | Package Attributes | Private Member Functions | Private Attributes
SharpTools.NewFileDialog Class Reference

This class provides a new-file dialog. More...

Inheritance diagram for SharpTools.NewFileDialog:
Inheritance graph
[legend]
Collaboration diagram for SharpTools.NewFileDialog:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 NewFileDialog (JFrame aFrame, int initrows, int initcols)
int getRows ()
 Get the input row number.
int getColumns ()
 Get the input column number.
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

boolean onOK ()
 This function is called when the OK button is pressed.
boolean onCancel ()
 This function is called when the Cancel button is pressed.
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.
JRootPane createRootPane ()
 override this protected funciton to register ESCAPE with the root pane
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 Attributes

final ImageIcon newFileIcon = new ImageIcon(getClass().getResource("/images/new32.gif"))
final NumberField rowField
final NumberField colField
final JCheckBox saveDefault
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

void newFileError (String error, JTextField com)
 a function to display error messages

Private Attributes

int rows
int cols

Detailed Description

This class provides a new-file dialog.

User is prompted to choose rows/columns when they are creating a new document.

Author:
Hua Zhong
Version:
Revision:
1.6

Definition at line 22 of file NewFileDialog.java.


Constructor & Destructor Documentation

SharpTools.NewFileDialog.NewFileDialog ( JFrame  aFrame,
int  initrows,
int  initcols 
) [inline]

Definition at line 31 of file NewFileDialog.java.

                                                                    {
        
       super(aFrame, "New", true);

       //various properties of the dialog labels and text fields 
       final JLabel msgString1 = new JLabel(SharpTools.translation.getProperty("Rows")+": ");
       final JLabel msgString2 = new JLabel(SharpTools.translation.getProperty("Columns")+": ");
       rowField = new NumberField(5, true, true);
       colField = new NumberField(5, true, true);
       msgString1.setLabelFor(rowField);
       msgString2.setLabelFor(colField);
       msgString1.setDisplayedMnemonic(KeyEvent.VK_R);
       msgString2.setDisplayedMnemonic(KeyEvent.VK_C);

       saveDefault = new JCheckBox(SharpTools.translation.getProperty("Save_as_default"), false);
       saveDefault.setMnemonic(KeyEvent.VK_S);

       rowField.setText(String.valueOf(initrows));
       colField.setText(String.valueOf(initcols));
       
       Object[] input = {msgString1, rowField, msgString2, colField,
                       saveDefault};

        setOptionPane(input, 
                    JOptionPane.QUESTION_MESSAGE,
                    JOptionPane.OK_CANCEL_OPTION,
                    newFileIcon);
       
       //     pack();
    }

Here is the call graph for this function:


Member Function Documentation

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

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:

int SharpTools.SharpDialog.getChoice ( ) [inline, inherited]
Returns:
user choice

Definition at line 344 of file SharpDialog.java.

                           {
       return choice;
    }

Here is the caller graph for this function:

Get the input column number.

Returns:
the column number

Definition at line 74 of file NewFileDialog.java.

{ return cols; }

Here is the caller graph for this function:

Get the input row number.

Returns:
the row number

Definition at line 67 of file NewFileDialog.java.

{ return rows; }

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:

void SharpTools.NewFileDialog.newFileError ( String  error,
JTextField  com 
) [inline, private]

a function to display error messages

Parameters:
errorthe error message
fieldthe component causing this error

Definition at line 82 of file NewFileDialog.java.

                                                            {    
        SharpOptionPane.showMessageDialog(this, error, SharpTools.translation.getProperty("Error"),
                                     JOptionPane.ERROR_MESSAGE);
       com.selectAll();
       com.requestFocus();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

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

This function is called when the Cancel button is pressed.

Returns:
whether the dialog should be closed

Reimplemented from SharpTools.SharpDialog.

Definition at line 125 of file NewFileDialog.java.

                                 {
       rows = cols = 0;
       return true;
    }
boolean SharpTools.NewFileDialog.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 from SharpTools.SharpDialog.

Definition at line 136 of file NewFileDialog.java.

                                {
       // cancelled
       rows = cols = 0;
       return true;
    }
boolean SharpTools.SharpDialog.onNo ( ) [inline, protected, inherited]

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.NewFileDialog.onOK ( ) [inline, protected]

This function is called when the OK button is pressed.

Returns:
whether the dialog should be closed

Reimplemented from SharpTools.SharpDialog.

Definition at line 89 of file NewFileDialog.java.

                             {
                  
       try {
           rows = rowField.getInteger().intValue();
       }
       catch (Exception e1) {
           rows = 0;
       }
       
       if (rows <= 0) {
           newFileError(SharpTools.translation.getProperty("Invalid_row_value"), rowField);
           return false;
       }
       
       try {
           cols = colField.getInteger().intValue();
       }
       catch (Exception e2) {
           cols = 0;
       }
       
       if (cols <= 0) {
           newFileError(SharpTools.translation.getProperty("Invalid_column_value"), colField);
           return false;
       }   
       
       if (saveDefault.isSelected()) {
           // save stuff
           Config config = SharpTools.getConfig();
           config.setInt("ROWS", rows);
           config.setInt("COLUMNS", cols);
       }                    
       
       return true;
    }

Here is the call graph for this function:

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

I provide several hooks for the sublasses to override.

This function is called when the dialog window is opened.

Reimplemented from SharpTools.SharpDialog.

Definition at line 130 of file NewFileDialog.java.

                            {
       // set the initial focus to rowField
       rowField.selectAll();
       rowField.requestFocus();
    }
boolean SharpTools.SharpDialog.onYes ( ) [inline, protected, inherited]

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:

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

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, inherited]

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, inherited]

Definition at line 26 of file SharpDialog.java.

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

Definition at line 28 of file SharpDialog.java.

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

Definition at line 22 of file SharpDialog.java.

Definition at line 28 of file NewFileDialog.java.

Definition at line 24 of file NewFileDialog.java.

final ImageIcon SharpTools.NewFileDialog.newFileIcon = new ImageIcon(getClass().getResource("/images/new32.gif")) [package]

Definition at line 25 of file NewFileDialog.java.

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

Definition at line 24 of file SharpDialog.java.

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

Definition at line 29 of file SharpDialog.java.

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

Definition at line 25 of file SharpDialog.java.

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

Definition at line 27 of file SharpDialog.java.

Definition at line 27 of file NewFileDialog.java.

Definition at line 23 of file NewFileDialog.java.

final JCheckBox SharpTools.NewFileDialog.saveDefault [package]

Definition at line 29 of file NewFileDialog.java.

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

Definition at line 23 of file SharpDialog.java.


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