sears.tools
Class DialogUtils

java.lang.Object
  extended by sears.tools.DialogUtils

public class DialogUtils
extends java.lang.Object

This class gives methods for display an "open" dialog and a "save as" dialog.
An instance of this class will display (if the good method is called),
after test conditions a FileDialog or JFileChooser.

Example of use:

DialogUtils du = new DialogUtils();
// set options:
du.setConditions( true, true );
du.setApproveButtonText( "Save as" );
du.setOverwriteText(SearsResourceBundle.getResource( "Do you really want to overwrite this file ?" ));
du.setFileFilter(new FileFilter() { ... });
// we get back the file choosen
File file = du.showSaveAsDialog(instance, "Save As", subtitleFile.getFile());
// if user cancel action, file is null:
if (file != null){
// action you want
}


Constructor Summary
DialogUtils()
           
 
Method Summary
 void setApproveButtonText(java.lang.String approveButtonText)
          
this method set the approveButtonText needed by JFileChooser
 void setConditions(boolean OSCondition, boolean lookAndFeelCondition)
          
This method set conditions for display the FileDialog instead of the JFileChooser.
 void setFileFilter(javax.swing.filechooser.FileFilter filter)
          
this method defines the file filer needed by the dialog...
 void setLocale(java.util.Locale locale)
           
 void setOverwriteText(java.lang.String overwriteText)
          
this method defines the overwrite text needed if instance choose a JFileChooser
for display the "save as" dialog
 java.io.File showOpenDialog(java.awt.Frame parent, java.lang.String title, java.io.File openedFile)
           
 java.io.File showSaveAsDialog(java.awt.Frame parent, java.lang.String title, java.io.File openedFile)
          Method saveAsDialog
this method display a dialog for save as a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DialogUtils

public DialogUtils()
Method Detail

setConditions

public void setConditions(boolean OSCondition,
                          boolean lookAndFeelCondition)

This method set conditions for display the FileDialog instead of the JFileChooser.

Parameters:
OSCondition - if true, the class instance will test if app is running on a Mac platform
lookAndFeelCondition - if true, the class instance will test if app's look and feel is the same of the system default one

setApproveButtonText

public void setApproveButtonText(java.lang.String approveButtonText)

this method set the approveButtonText needed by JFileChooser

Parameters:
approveButtonText - the text display in the approve button

setFileFilter

public void setFileFilter(javax.swing.filechooser.FileFilter filter)

this method defines the file filer needed by the dialog...

Parameters:
filter - the file filter

setOverwriteText

public void setOverwriteText(java.lang.String overwriteText)

this method defines the overwrite text needed if instance choose a JFileChooser
for display the "save as" dialog

Parameters:
overwriteText - the overwrite text you want to display if user try to overwrite a file

setLocale

public void setLocale(java.util.Locale locale)

showSaveAsDialog

public java.io.File showSaveAsDialog(java.awt.Frame parent,
                                     java.lang.String title,
                                     java.io.File openedFile)
Method saveAsDialog
this method display a dialog for save as a file.
it displays a FileDialog if require condition is respected, a JfileChooser if not.
A file is return if user accepts to save its ile, null if not.

Parameters:
parent - the parent Frame
title - the title of the dialog
openedFile - the file which want to save
Returns:
the saved file (created or existing file)

showOpenDialog

public java.io.File showOpenDialog(java.awt.Frame parent,
                                   java.lang.String title,
                                   java.io.File openedFile)