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.SortDialog Class Reference

This class provides a sort dialog. More...

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

List of all members.

Public Member Functions

 SortDialog (JFrame aFrame, Vector first, Vector second)
boolean firstAscending ()
boolean secondAscending ()
int getCriteriaA ()
int getCriteriaB ()
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.
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 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

void setLabel (String newText)

Package Attributes

final ImageIcon sortIcon = new ImageIcon(getClass().getResource("/images/sort32.gif"))
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

JPanel setPanel ()

Private Attributes

JLabel label
JFrame frame
JComboBox primary
JComboBox tiebreaker
boolean ascending1 = true
boolean ascending2 = true
int criteriaA = -1
int criteriaB = -1
final ButtonGroup group = new ButtonGroup()
final ButtonGroup group2 = new ButtonGroup()
final String ascending_1 = "ascending_1"
final String descending_1 = "decending_1"
final String ascending_2 = "ascending_2"
final String descending_2 = "decending_2"

Detailed Description

This class provides a sort dialog.

User is prompted to choose sort criteria.

Author:
Andrei Scudder
Hua Zhong (use SharpDialog)
Version:
Revision:
1.15

Definition at line 25 of file SortDialog.java.


Constructor & Destructor Documentation

SharpTools.SortDialog.SortDialog ( JFrame  aFrame,
Vector  first,
Vector  second 
) [inline]

Definition at line 45 of file SortDialog.java.

                                                                  {
       super(aFrame, "Sort", true);       
               
        primary = new JComboBox(first);
        primary.setSelectedIndex(0);
        
        tiebreaker = new JComboBox(second);
        tiebreaker.setSelectedIndex(0);
        
       JRadioButton[] radioButtons = new JRadioButton[4];
       JButton enter = null;
       JButton close = null;
       JPanel box = new JPanel();
       
       radioButtons[0] = new JRadioButton(SharpTools.translation.getProperty("Ascending"));
        radioButtons[0].setActionCommand(ascending_1);
       
        radioButtons[1] = new JRadioButton(SharpTools.translation.getProperty("Descending"));
        radioButtons[1].setActionCommand(descending_1);
       
        radioButtons[2] = new JRadioButton(SharpTools.translation.getProperty("Ascending"));
        radioButtons[2].setActionCommand(ascending_2);
       
        radioButtons[3] = new JRadioButton(SharpTools.translation.getProperty("Descending"));
        radioButtons[3].setActionCommand(descending_2);

       
       radioButtons[0].setSelected(true);
       group.add(radioButtons[0]);
        group.add(radioButtons[1]);

       
       radioButtons[2].setSelected(true);
       group2.add(radioButtons[2]);
       group2.add(radioButtons[3]);
       
       
        box.setLayout(new GridLayout(0, 3, 10, 5));

       // define key shortcut
        JLabel sortLabel = new JLabel(SharpTools.translation.getProperty("Sort_By:"));
       sortLabel.setLabelFor(primary);
       sortLabel.setDisplayedMnemonic(KeyEvent.VK_S);
       radioButtons[0].setMnemonic(KeyEvent.VK_A);
       radioButtons[1].setMnemonic(KeyEvent.VK_D);
       
       box.add(sortLabel);
       box.add(new JLabel(""));
       box.add(new JLabel(""));
       box.add(primary);
       box.add(radioButtons[0]);
       box.add(radioButtons[1]);

       // define key shortcut
       sortLabel = new JLabel(SharpTools.translation.getProperty("Then_By:"));
       sortLabel.setLabelFor(tiebreaker);
       sortLabel.setDisplayedMnemonic(KeyEvent.VK_T);
       radioButtons[2].setMnemonic(KeyEvent.VK_C);
       radioButtons[3].setMnemonic(KeyEvent.VK_E);      

       box.add(sortLabel);
       box.add(new JLabel(""));
       box.add(new JLabel(""));
       box.add(tiebreaker);
       box.add(radioButtons[2]);
       box.add(radioButtons[3]);
       
       Border padding = BorderFactory.createEmptyBorder(20,20,20,0);
       box.setBorder(padding);
       
       
       Object setting = box;
       
       setOptionPane(box, 
                    JOptionPane.PLAIN_MESSAGE,
                    JOptionPane.YES_NO_OPTION,
                    sortIcon);
       

        
        primary.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                  JComboBox cb = (JComboBox)e.getSource();
                  criteriaA = cb.getSelectedIndex();
              }
           });
       
       
       
       tiebreaker.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                  JComboBox cb = (JComboBox)e.getSource();
                  criteriaB = cb.getSelectedIndex();
              }
           });

    }

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:

Definition at line 147 of file SortDialog.java.

                                   {
       return ascending1;          
    }

Here is the caller 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:

Definition at line 155 of file SortDialog.java.

                             {
       return criteriaA;
    }

Here is the caller graph for this function:

Definition at line 159 of file SortDialog.java.

                             {
       return criteriaB;
    }

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.SortDialog.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 192 of file SortDialog.java.

                                 {
       criteriaA = -1;
       criteriaB = -1;
       return true;
    }
boolean SharpTools.SharpDialog.onClose ( ) [inline, protected, inherited]

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, 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.SortDialog.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 168 of file SortDialog.java.

                             {
       criteriaA = primary.getSelectedIndex();
       criteriaB = tiebreaker.getSelectedIndex();
       String command = group.getSelection().getActionCommand();
       String command2 = group2.getSelection().getActionCommand();
                  
       //Set the sort order of the first column
       if (command == ascending_1) {
           ascending1 = true;
       } else if (command == descending_1) {
           ascending1 = false;
           // Set the sort order of the scond column
       }
       
       if (command2 == ascending_2) {
           ascending2 = true;
           
       } else if (command2 == descending_2) {
           ascending2 = false;
       }
       
       return true;
    }
void SharpTools.SharpDialog.onOpen ( ) [inline, protected, inherited]

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, 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:

Definition at line 151 of file SortDialog.java.

                                    {
       return ascending2;
    }

Here is the caller graph for this function:

void SharpTools.SortDialog.setLabel ( String  newText) [inline, package]

Definition at line 163 of file SortDialog.java.

                                  {
        label.setText(newText);
    }
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:

JPanel SharpTools.SortDialog.setPanel ( ) [inline, private]

Definition at line 143 of file SortDialog.java.

                             {
       return null;
    }

Member Data Documentation

Definition at line 31 of file SortDialog.java.

Definition at line 32 of file SortDialog.java.

final String SharpTools.SortDialog.ascending_1 = "ascending_1" [private]

Definition at line 40 of file SortDialog.java.

final String SharpTools.SortDialog.ascending_2 = "ascending_2" [private]

Definition at line 42 of file SortDialog.java.

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.

int SharpTools.SortDialog.criteriaA = -1 [private]

Definition at line 33 of file SortDialog.java.

int SharpTools.SortDialog.criteriaB = -1 [private]

Definition at line 34 of file SortDialog.java.

final String SharpTools.SortDialog.descending_1 = "decending_1" [private]

Definition at line 41 of file SortDialog.java.

final String SharpTools.SortDialog.descending_2 = "decending_2" [private]

Definition at line 43 of file SortDialog.java.

JFrame SharpTools.SortDialog.frame [private]

Definition at line 28 of file SortDialog.java.

final ButtonGroup SharpTools.SortDialog.group = new ButtonGroup() [private]

Definition at line 38 of file SortDialog.java.

final ButtonGroup SharpTools.SortDialog.group2 = new ButtonGroup() [private]

Definition at line 39 of file SortDialog.java.

JLabel SharpTools.SortDialog.label [private]

Definition at line 27 of file SortDialog.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.

JComboBox SharpTools.SortDialog.primary [private]

Definition at line 29 of file SortDialog.java.

final ImageIcon SharpTools.SortDialog.sortIcon = new ImageIcon(getClass().getResource("/images/sort32.gif")) [package]

Definition at line 35 of file SortDialog.java.

JComboBox SharpTools.SortDialog.tiebreaker [private]

Definition at line 30 of file SortDialog.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: