Offers a default name for the file into which a call is to be recorded when the 'Toggle Record' button is invoked and there's no default folder for recorded calls set.

cusax-fix
Lyubomir Marinov 16 years ago
parent f3b8ea9579
commit f36d83fb98

@ -45,12 +45,6 @@ public class RecordButton
private static final SimpleDateFormat format
= new SimpleDateFormat("yyyy-MM-dd@HH.mm.ss");
/**
* <tt>true</tt> when the default directory to save calls to is set,
* <tt>false</tt> otherwise.
*/
private boolean isCallDirSet = false;
/**
* The full filename of the saved call on the file system.
*/
@ -115,10 +109,7 @@ public String getDescription()
String saveDir = configuration.getString(Recorder.SAVED_CALLS_PATH);
if ((saveDir != null) && (saveDir.length() != 0))
{
isCallDirSet = true;
toolTip += " (" + saveDir + ")";
}
setToolTipText(toolTip);
}
@ -138,9 +129,15 @@ public void actionPerformed(ActionEvent evt)
// start recording
if (isSelected())
{
String savedCallsPath
= configuration.getString(Recorder.SAVED_CALLS_PATH);
// ask user input about where to save the call
if (!isCallDirSet)
if ((savedCallsPath == null) || (savedCallsPath.length() == 0))
{
// Offer a default name for the file to record into.
callFileChooser.setStartPath(createDefaultFilename(null));
File selectedFile = callFileChooser.getFileFromDialog();
if (selectedFile != null)
@ -171,7 +168,7 @@ public void actionPerformed(ActionEvent evt)
}
}
else
callFilename = createDefaultFilename();
callFilename = createDefaultFilename(savedCallsPath);
telephony.startRecording(call, callFilename);
}
@ -195,18 +192,18 @@ public void actionPerformed(ActionEvent evt)
* prefix and extension. If the directory is <tt>null</tt> user's home
* directory is used.
*
* @param savedCallsPath the path to the directory in which the generated
* file name is to be placed
* @return a full filename for the call
*/
private String createDefaultFilename()
private String createDefaultFilename(String savedCallsPath)
{
String callsDir = configuration.getString(Recorder.SAVED_CALLS_PATH);
// set to user's home when null
if (callsDir == null)
if (savedCallsPath == null)
{
try
{
callsDir
savedCallsPath
= GuiActivator
.getFileAccessService()
.getDefaultDownloadDirectory()
@ -223,7 +220,7 @@ private String createDefaultFilename()
if ((ext == null) || (ext.length() == 0))
ext = SoundFileUtils.DEFAULT_CALL_RECORDING_FORMAT;
return
((callsDir == null) ? "" : (callsDir + File.separator))
((savedCallsPath == null) ? "" : (savedCallsPath + File.separator))
+ generateCallFilename(ext);
}

@ -24,19 +24,13 @@
*/
public class GenericFileDialog
{
/**
* The <tt>Logger</tt> used by the <tt>GenericFileDialog</tt> class for
* logging output.
*/
private static final Logger logger
= Logger.getLogger(GenericFileDialog.class);
/**
* Creates a file dialog (AWT's FileDialog or Swing's JFileChooser)
* regarding to user's operating system.
*
* @param parent the parent Frame/JFrame of this dialog
* @param title dialog's title
* @param fileOperation
* @return a SipCommFileChooser instance
*/
public static SipCommFileChooser create(
@ -89,18 +83,18 @@ public static SipCommFileChooser create(
*
* @param parent the parent Frame/JFrame of this dialog
* @param title dialog's title
* @param fileOperation
* @param path start path of this dialog
* @return SipCommFileChooser an implementation of SipCommFileChooser
*/
public static SipCommFileChooser create(
Frame parent, String title, int fileOperation, String path)
{
SipCommFileChooser scfc =
GenericFileDialog.create(parent, title, fileOperation);
SipCommFileChooser scfc
= GenericFileDialog.create(parent, title, fileOperation);
if(path != null)
scfc.setStartPath(path);
return scfc;
}
}

@ -16,10 +16,10 @@
* user interface for file selection provided by Mac OS which is more practical
* than the user interface performed by a JFileChooser (on Mac).
*
* Therefore, under other plateforms (Microsoft Windows, Linux), the use of
* Therefore, under other platforms (Microsoft Windows, Linux), the use of
* JFileChooser instead of FileDialog performs a better user interface for
* browsing among a file hierarchy.
*
*
* @author Valentin Martinet
*/
public interface SipCommFileChooser

@ -11,7 +11,7 @@
import javax.swing.*;
/**
* SipCommFileChooser implementation for Swing's JFileChooser.
* Implements <tt>SipCommFileChooser</tt> for Swing's <tt>JFileChooser</tt>.
*
* @author Valentin Martinet
*/
@ -19,8 +19,6 @@ public class SipCommFileChooserImpl
extends JFileChooser
implements SipCommFileChooser
{
private static final long serialVersionUID = 6858528563334885869L;
/**
* Parent component of this dialog (JFrame, Frame, etc)
*/
@ -35,21 +33,26 @@ public class SipCommFileChooserImpl
public SipCommFileChooserImpl(String title, int operation)
{
super();
this.setDialogTitle(title);
this.setDialogType(operation);
}
/**
* Constructor
*
* Initializes a new <tt>SipCommFileChooserImpl</tt> instance.
*
* @param parent
* @param path
* @param title
* @param operation
*/
public SipCommFileChooserImpl(
Component pparent, String path, String title, int operation)
Component parent, String path, String title, int operation)
{
this(title, operation);
this.parent = parent;
this.setStartPath(path);
this.parent = pparent;
}
/**
@ -64,20 +67,22 @@ public File getApprovedFile()
/**
* Sets the default path to be considered for browsing among files.
*
*
* @param path the default start path for this dialog
*/
public void setStartPath(String path)
{
if(path == null)
{
// passing null makes file chooser points to user's default dir
this.setCurrentDirectory(null);
}
else
{
this.setCurrentDirectory(new File(path));
}
// Passing null makes JFileChooser points to user's default dir.
File file = (path == null) ? null : new File(path);
setCurrentDirectory(file);
/*
* If the path doesn't exist, the intention of the caller may have been
* to also set a default file name.
*/
if ((file != null) && !file.isDirectory())
setSelectedFile(file);
}
/**

@ -10,15 +10,15 @@
import java.io.*;
/**
* SipCommFileChooser implementation for the use of AWT's FileDialog.
*
* Implements <tt>SipCommFileChooser</tt> for AWT's <tt>FileDialog</tt>.
*
* @author Valentin Martinet
*/
public class SipCommFileDialogImpl
extends FileDialog
implements SipCommFileChooser
{
private static final long serialVersionUID = 8176923801105539356L;
private static final long serialVersionUID = 0L;
/**
* Constructor
@ -50,14 +50,9 @@ public SipCommFileDialogImpl(Frame parent, String title, int fileOperation)
*/
public File getApprovedFile()
{
if(this.getFile() != null)
{
return new File(this.getDirectory(), this.getFile());
}
else
{
return null;
}
String file = getFile();
return (file != null) ? new File(getDirectory(), file) : null;
}
/**
@ -67,7 +62,15 @@ public File getApprovedFile()
*/
public void setStartPath(String path)
{
this.setDirectory(path);
File file = (path == null) ? null : new File(path);
if ((file != null) && !file.isDirectory())
{
setDirectory(file.getParent());
setFile(path);
}
else
setDirectory(path);
}
/**

Loading…
Cancel
Save