JGraphpad Pro
v6.0.5.0


com.jgraph.pad.dialog
Class JGraphpadDialogs

java.lang.Object
  extended bycom.jgraph.pad.dialog.JGraphpadDialogs

public class JGraphpadDialogs
extends Object

Singleton class that provides a set of standard dialogs.


Nested Class Summary
static class JGraphpadDialogs.CancelException
           
static class JGraphpadDialogs.FontDialog
          A simple font dialog.
 
Field Summary
protected static JGraphpadDialogs.FontDialog fontDialog
          Shared simple font dialog.
protected  JFileChooser openEditorChooser
          Holds the various file choosers to preserve their states between uses.
protected  JFileChooser openImageChooser
          Holds the various file choosers to preserve their states between uses.
protected  JFileChooser saveEditorChooser
          Holds the various file choosers to preserve their states between uses.
protected  JFileChooser saveImageChooser
          Holds the various file choosers to preserve their states between uses.
protected static JGraphpadDialogs sharedInstance
          Shared singleton instance.
 
Constructor Summary
protected JGraphpadDialogs()
          Singleton constructor.
 
Method Summary
 Color colorDialog(Component component, String title, Color color)
          Displays a color dialog using JColorChooser.showDialog(java.awt.Component, java.lang.String, java.awt.Color).
 boolean confirmDialog(Component component, String message, boolean yesNo, boolean cancel)
          Displays a confirmation dialog using JOptionPane.showConfirmDialog(java.awt.Component, java.lang.Object, java.lang.String, int) and JGraphpad.APPTITLE for the title.
 double doubleDialog(String title, double initialValue, boolean allowNegative, boolean allowZero)
          Shortcut method to valueDialog(String, String) that returns the user input as a double.
 String editorFileDialog(Component component, String title, String filename, boolean open, File directory)
          Displays a JFileChooser using showFileChooser(Component, JFileChooser, boolean).
 void errorDialog(Component component, String message)
          Shortcut method to messageDialog(Component, String, int) that display a dialog of type JOptionPane.ERROR_MESSAGE.
 String fileDialog(Component component, String title, boolean open, String extension, String desc, File directory)
          Displays a JFileChooser using showFileChooser(Component, JFileChooser, boolean) for files with the specified extension.
 float floatDialog(String title, float initialValue, boolean allowNegative, boolean allowZero)
          Shortcut method to valueDialog(String, String) that returns the user input as a float.
 Font fontDialog(Component component, String title)
          Displays a simple font dialog using JGraphpadDialogs.FontDialog.
static JGraphpadDialogs getSharedInstance()
          Returns the singleton instance.
 String imageFileDialog(Component component, String title, boolean open, File directory)
          Displays a JFileChooser using showFileChooser(Component, JFileChooser, boolean).
 void informationDialog(Component component, String message)
          Shortcut method to messageDialog(Component, String, int) that display a dialog of type JOptionPane.INFORMATION_MESSAGE.
 int intDialog(String title, int initialValue, boolean allowNegative, boolean allowZero)
          Shortcut method to valueDialog(String, String) that returns the user input as an int.
 void messageDialog(Component component, String message, int type)
          Displays a message dialog using JOptionPane.showMessageDialog(java.awt.Component, java.lang.Object, java.lang.String, int) and JGraphpad.APPTITLE for the title.
protected  String showFileChooser(Component component, JFileChooser chooser, boolean open)
          Helper method to display the specified chooser using JFileChooser.showOpenDialog(java.awt.Component) or JFileChooser.showSaveDialog(java.awt.Component) making sure that the returned file has the extension of the selected filter.
 String valueDialog(String title)
          Shortcut method to valueDialog(String, String) with an empty initial value.
 String valueDialog(String title, String initialValue)
          Displays a value dialog using JOptionPane.showInputDialog(java.awt.Component, java.lang.Object).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sharedInstance

protected static JGraphpadDialogs sharedInstance
Shared singleton instance.


fontDialog

protected static JGraphpadDialogs.FontDialog fontDialog
Shared simple font dialog.


saveEditorChooser

protected JFileChooser saveEditorChooser
Holds the various file choosers to preserve their states between uses.


openEditorChooser

protected JFileChooser openEditorChooser
Holds the various file choosers to preserve their states between uses.


saveImageChooser

protected JFileChooser saveImageChooser
Holds the various file choosers to preserve their states between uses.


openImageChooser

protected JFileChooser openImageChooser
Holds the various file choosers to preserve their states between uses.

Constructor Detail

JGraphpadDialogs

protected JGraphpadDialogs()
Singleton constructor.

Method Detail

getSharedInstance

public static JGraphpadDialogs getSharedInstance()
Returns the singleton instance.

Returns:
Returns sharedInstance.

colorDialog

public Color colorDialog(Component component,
                         String title,
                         Color color)
Displays a color dialog using JColorChooser.showDialog(java.awt.Component, java.lang.String, java.awt.Color).

Parameters:
component - The parent component for the dialog to be displayed.
title - The title of the dialog to be displayed.
color - The default color to use in the dialog.
Returns:
Returns the selected color.

fontDialog

public Font fontDialog(Component component,
                       String title)
Displays a simple font dialog using JGraphpadDialogs.FontDialog.

Parameters:
component - The parent component for the dialog to be displayed.
title - The title of the dialog to be displayed.
Returns:
Returns the selected font.

valueDialog

public String valueDialog(String title)
Shortcut method to valueDialog(String, String) with an empty initial value.

Parameters:
title - The title of the dialog to be displayed.
Returns:
Returns the user input.

valueDialog

public String valueDialog(String title,
                          String initialValue)
Displays a value dialog using JOptionPane.showInputDialog(java.awt.Component, java.lang.Object).

Parameters:
title - The title of the dialog to be displayed.
initialValue - The intitial value to be displayed.
Returns:
Returns the user input.

intDialog

public int intDialog(String title,
                     int initialValue,
                     boolean allowNegative,
                     boolean allowZero)
Shortcut method to valueDialog(String, String) that returns the user input as an int.

Parameters:
title - The title of the dialog to be displayed.
initialValue - The initial value to be displayed.
allowNegative - Specifies whether negative values are allowed as input.
allowZero - Specifies whether zero is a valid input.
Returns:
Returns the user input as an int.
Throws:
IllegalArgumentException - If a value <= 0 is entered.
JGraphpadDialogs.CancelException - if the user clicks cancel

floatDialog

public float floatDialog(String title,
                         float initialValue,
                         boolean allowNegative,
                         boolean allowZero)
Shortcut method to valueDialog(String, String) that returns the user input as a float.

Parameters:
title - The title of the dialog to be displayed.
initialValue - The initial value to be displayed.
allowNegative - Specifies whether negative values are allowed as input.
allowZero - Specifies whether zero is a valid input.
Returns:
Returns the user input as a double.
Throws:
IllegalArgumentException - If a value <= 0 is entered.
JGraphpadDialogs.CancelException - if the user clicks cancel

doubleDialog

public double doubleDialog(String title,
                           double initialValue,
                           boolean allowNegative,
                           boolean allowZero)
Shortcut method to valueDialog(String, String) that returns the user input as a double.

Parameters:
title - The title of the dialog to be displayed.
initialValue - The initial value to be displayed.
Returns:
Returns the user input as a double.
Throws:
IllegalArgumentException - If a value <= 0 is entered.
JGraphpadDialogs.CancelException - if the user clicks cancel

confirmDialog

public boolean confirmDialog(Component component,
                             String message,
                             boolean yesNo,
                             boolean cancel)
                      throws JGraphpadDialogs.CancelException
Displays a confirmation dialog using JOptionPane.showConfirmDialog(java.awt.Component, java.lang.Object, java.lang.String, int) and JGraphpad.APPTITLE for the title.

Parameters:
component - The parent component for the dialog to be displayed.
message - The message to be confirmed.
yesNo - Whether to display yes/no or ok/cancel options.
cancel - Whether to display a cancel option for yes/no dialogs.
Returns:
Returns true if the message is confirmed.
Throws:
JGraphpadDialogs.CancelException - If the user clicks cancel.

informationDialog

public void informationDialog(Component component,
                              String message)
Shortcut method to messageDialog(Component, String, int) that display a dialog of type JOptionPane.INFORMATION_MESSAGE.

Parameters:
component - The parent component for the dialog to be displayed.
message - The message to be displayed.

errorDialog

public void errorDialog(Component component,
                        String message)
Shortcut method to messageDialog(Component, String, int) that display a dialog of type JOptionPane.ERROR_MESSAGE.

Parameters:
component - The parent component for the dialog to be displayed.
message - The message to be displayed.

messageDialog

public void messageDialog(Component component,
                          String message,
                          int type)
Displays a message dialog using JOptionPane.showMessageDialog(java.awt.Component, java.lang.Object, java.lang.String, int) and JGraphpad.APPTITLE for the title.

Parameters:
component - The parent component for the dialog to be displayed.
message - The message to be confirmed.
type - The type of message dialog to be displayed.

fileDialog

public String fileDialog(Component component,
                         String title,
                         boolean open,
                         String extension,
                         String desc,
                         File directory)
Displays a JFileChooser using showFileChooser(Component, JFileChooser, boolean) for files with the specified extension. The dialog will show description for file of this type. The full extension including the dot must be specified. If the selected filename does not end with extension then the extension is appended to the filename.

Parameters:
component - The parent component for the dialog to be displayed.
title - The title of the dialog to be displayed.
open - Whether to display an open or save dialog.
extension - The extension to be used for filtering files.
desc - The description of the file format.
directory - The default directory to use for the dialog.
Returns:
Returns the selected filename.

editorFileDialog

public String editorFileDialog(Component component,
                               String title,
                               String filename,
                               boolean open,
                               File directory)
Displays a JFileChooser using showFileChooser(Component, JFileChooser, boolean). This implementation adds two file filters to the chooser, one for .xml files and the other for .xml.gz files.

Parameters:
component - The parent component for the dialog to be displayed.
title - The title of the dialog to be displayed.
open - Whether to display an open or save dialog.
directory - The default directory to use for the dialog.
Returns:
Returns the selected filename.

imageFileDialog

public String imageFileDialog(Component component,
                              String title,
                              boolean open,
                              File directory)
Displays a JFileChooser using showFileChooser(Component, JFileChooser, boolean). This implementation adds two file filters to the chooser, one for .jpg files and the other for .png files.

Parameters:
component - The parent component for the dialog to be displayed.
title - The title of the dialog to be displayed.
open - Whether to display an open or save dialog.
directory - The default directory to use for the dialog.
Returns:
Returns the selected filename.

showFileChooser

protected String showFileChooser(Component component,
                                 JFileChooser chooser,
                                 boolean open)
Helper method to display the specified chooser using JFileChooser.showOpenDialog(java.awt.Component) or JFileChooser.showSaveDialog(java.awt.Component) making sure that the returned file has the extension of the selected filter. This implementation displays a confirmation dialog if a file will be overwritten and returns null if the user chooses not to overwrite it.

Parameters:
component - The parent component for the dialog to be displayed.
chooser - The dialog to be displayed. Whether to display an open or save dialog.
open - Whether to display an open or save dialog.
Returns:
Returns the selected filename.

JGraphpad Pro
v6.0.5.0


Copyright (C) 2005 JGraph.com. All rights reserved.