diff --git a/src/net/java/sip/communicator/impl/gui/main/call/RecordButton.java b/src/net/java/sip/communicator/impl/gui/main/call/RecordButton.java index 02b8973c7..d4bb0dd94 100644 --- a/src/net/java/sip/communicator/impl/gui/main/call/RecordButton.java +++ b/src/net/java/sip/communicator/impl/gui/main/call/RecordButton.java @@ -45,12 +45,6 @@ public class RecordButton private static final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd@HH.mm.ss"); - /** - * true when the default directory to save calls to is set, - * false 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 null 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); } diff --git a/src/net/java/sip/communicator/util/swing/GenericFileDialog.java b/src/net/java/sip/communicator/util/swing/GenericFileDialog.java index 56c222bd5..29b82c373 100644 --- a/src/net/java/sip/communicator/util/swing/GenericFileDialog.java +++ b/src/net/java/sip/communicator/util/swing/GenericFileDialog.java @@ -24,19 +24,13 @@ */ public class GenericFileDialog { - /** - * The Logger used by the GenericFileDialog 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; } } diff --git a/src/net/java/sip/communicator/util/swing/SipCommFileChooser.java b/src/net/java/sip/communicator/util/swing/SipCommFileChooser.java index 0196b5da9..05f1ef1d4 100644 --- a/src/net/java/sip/communicator/util/swing/SipCommFileChooser.java +++ b/src/net/java/sip/communicator/util/swing/SipCommFileChooser.java @@ -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 diff --git a/src/net/java/sip/communicator/util/swing/SipCommFileChooserImpl.java b/src/net/java/sip/communicator/util/swing/SipCommFileChooserImpl.java index b2fab1a84..b7224ccf9 100644 --- a/src/net/java/sip/communicator/util/swing/SipCommFileChooserImpl.java +++ b/src/net/java/sip/communicator/util/swing/SipCommFileChooserImpl.java @@ -11,7 +11,7 @@ import javax.swing.*; /** - * SipCommFileChooser implementation for Swing's JFileChooser. + * Implements SipCommFileChooser for Swing's JFileChooser. * * @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 SipCommFileChooserImpl 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); } /** diff --git a/src/net/java/sip/communicator/util/swing/SipCommFileDialogImpl.java b/src/net/java/sip/communicator/util/swing/SipCommFileDialogImpl.java index c1326e75f..112fe9f5f 100644 --- a/src/net/java/sip/communicator/util/swing/SipCommFileDialogImpl.java +++ b/src/net/java/sip/communicator/util/swing/SipCommFileDialogImpl.java @@ -10,15 +10,15 @@ import java.io.*; /** - * SipCommFileChooser implementation for the use of AWT's FileDialog. - * + * Implements SipCommFileChooser for AWT's FileDialog. + * * @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); } /**