Fixes event configuration file chooser to use the last stored file location if no file is selected or show the currently selected file. Implemented for both program and sound files. Fixed an issue with URL based file paths.

cusax-fix
Yana Stamcheva 13 years ago
parent 1826ac329b
commit 75d04ad81a

@ -8,6 +8,7 @@
import java.awt.*;
import java.io.*;
import java.net.*;
import javax.swing.*;
@ -78,8 +79,22 @@ public File getApprovedFile()
*/
public void setStartPath(String path)
{
// Passing null makes JFileChooser points to user's default dir.
File file = (path == null) ? null : new File(path);
// If the path is null, we have nothing more to do here.
if (path == null)
return;
// If the path is an URL extract the path from the URL in order to
// remove the "file:" part, which doesn't work with methods provided
// by the file chooser.
try
{
URL url = new URL(path);
path = url.getPath();
}
catch (MalformedURLException e) {}
File file = new File(path);
setCurrentDirectory(file);
@ -89,6 +104,8 @@ public void setStartPath(String path)
*/
if ((file != null) && !file.isDirectory())
setSelectedFile(file);
else
setSelectedFile(null);
}
/**

@ -8,6 +8,7 @@
import java.awt.*;
import java.io.*;
import java.net.*;
import org.jitsi.util.*;
@ -76,7 +77,22 @@ public File getApprovedFile()
*/
public void setStartPath(String path)
{
File file = (path == null) ? null : new File(path);
// If the path is null, we have nothing more to do here.
if (path == null)
return;
// If the path is an URL extract the path from the URL in order to
// remove the "file:" part, which doesn't work with methods provided
// by the file chooser.
try
{
URL url = new URL(path);
path = url.getPath();
}
catch (MalformedURLException e) {}
File file = new File(path);
if ((file != null) && !file.isDirectory())
{
@ -84,7 +100,10 @@ public void setStartPath(String path)
setFile(file.getName());
}
else
{
setDirectory(path);
setFile(null);
}
}
/**

@ -19,6 +19,7 @@
import net.java.sip.communicator.plugin.desktoputil.*;
import org.jitsi.service.audionotifier.*;
import org.jitsi.util.*;
/**
@ -42,21 +43,57 @@ public class NotificationConfigurationPanel
private NotificationsTable notificationList;
private final JTextField soundFileTextField = new JTextField();
private final JButton soundFileChooser
private final JButton soundFileButton
= new JButton(new ImageIcon(Resources.getImageInBytes(
"plugin.notificationconfig.FOLDER_ICON")));
private final JTextField programFileTextField = new JTextField();
private final JButton programFileChooser
private final JButton programFileButton
= new JButton(new ImageIcon(Resources.getImageInBytes(
"plugin.notificationconfig.FOLDER_ICON")));
private final JButton playSoundButton
= new JButton(new ImageIcon(Resources.getImageInBytes(
"plugin.notificationconfig.PLAY_ICON")));
private final JButton restoreButton
= new JButton(Resources.getString("plugin.notificationconfig.RESTORE"));
private SipCommFileChooser fileChooserProgram;
private SipCommFileChooser fileChooserSound;
/**
* The program file chooser component.
*/
private SipCommFileChooser programFileChooser;
/**
* The sound file chooser component.
*/
private SipCommFileChooser soundFileChooser;
/**
* The property for the last stored path from program file chooser.
*/
private static final String PROGRAM_LAST_PATH_PROP
= "net.java.sip.communicator.plugin.notificationconfiguration."
+ "PROGRAM_LAST_PATH";
/**
* The property for the last stored path from sound file chooser.
*/
private static final String SOUND_LAST_PATH_PROP
= "net.java.sip.communicator.plugin.notificationconfiguration."
+ "SOUND_LAST_PATH";
/**
* The last stored path from program file chooser.
*/
private String programLastFilePath;
/**
* The last stored path from sound file chooser.
*/
private String soundLastFilePath;
/**
* Used to suppress saving entry values while filling
@ -73,8 +110,6 @@ public NotificationConfigurationPanel()
JPanel labelsPanel = new TransparentPanel(new GridLayout(2, 1));
initNotificationsList();
JLabel soundFileLabel = new JLabel(
Resources.getString("plugin.notificationconfig.SOUND_FILE"));
JLabel programFileLabel = new JLabel(
@ -97,10 +132,10 @@ public NotificationConfigurationPanel()
soundFilePanel.add(soundFileTextField);
soundFileChooser.setMinimumSize(new Dimension(30,30));
soundFileChooser.setPreferredSize(new Dimension(30,30));
soundFileChooser.addActionListener(this);
soundFilePanel.add(soundFileChooser);
soundFileButton.setMinimumSize(new Dimension(30,30));
soundFileButton.setPreferredSize(new Dimension(30,30));
soundFileButton.addActionListener(this);
soundFilePanel.add(soundFileButton);
JPanel programFilePanel
= new TransparentPanel(new FlowLayout(FlowLayout.LEFT));
@ -114,11 +149,11 @@ public NotificationConfigurationPanel()
programFilePanel.add(programFileTextField);
programFileChooser.setMinimumSize(new Dimension(30,30));
programFileChooser.setPreferredSize(new Dimension(30,30));
programFileChooser.addActionListener(this);
programFileButton.setMinimumSize(new Dimension(30,30));
programFileButton.setPreferredSize(new Dimension(30,30));
programFileButton.addActionListener(this);
programFilePanel.add(programFileChooser);
programFilePanel.add(programFileButton);
JPanel valuesPanel = new TransparentPanel(new GridLayout(2, 1));
valuesPanel.add(soundFilePanel);
@ -137,16 +172,18 @@ public NotificationConfigurationPanel()
add(southPanel, BorderLayout.SOUTH);
fileChooserSound =
soundFileChooser =
GenericFileDialog.create(null,
Resources.getString("plugin.notificationconfig.BROWSE_SOUND"),
SipCommFileChooser.LOAD_FILE_OPERATION);
fileChooserProgram =
programFileChooser =
GenericFileDialog.create(null,
Resources.getString("plugin.notificationconfig.BROWSE_PROGRAM"),
SipCommFileChooser.LOAD_FILE_OPERATION);
String[] soundFormats = {SoundFileUtils.wav};
fileChooserSound.setFileFilter(new SoundFilter(soundFormats));
soundFileChooser.setFileFilter(new SoundFilter(soundFormats));
initNotificationsList();
}
/**
@ -201,21 +238,35 @@ public void setNotificationEntry(NotificationEntry entry)
{
isCurrentlyChangeEntryInTable = true;
programFileChooser.setEnabled(entry.getProgram());
programFileButton.setEnabled(entry.getProgram());
programFileTextField.setEnabled(entry.getProgram());
String programFile = entry.getProgramFile();
programFileTextField.setText(
(programFile != null && programFile.length() > 0) ? programFile : "");
soundFileChooser.setEnabled(entry.getSoundNotification()
(programFile != null && programFile.length() > 0)
? programFile
: "");
programFileChooser.setStartPath(
(programFile != null && programFile.length() > 0)
? programFile
: getLastProgramPath());
soundFileButton.setEnabled(entry.getSoundNotification()
|| entry.getSoundPlayback());
soundFileTextField.setEnabled(entry.getSoundNotification()
|| entry.getSoundPlayback());
String soundFile = entry.getSoundFile();
soundFileTextField.setText(
(soundFile != null && soundFile.length() > 0) ? soundFile : "");
(soundFile != null && soundFile.length() > 0)
? soundFile
: "");
soundFileChooser.setStartPath(
(soundFile != null && soundFile.length() > 0)
? soundFile
: getLastSoundPath());
isCurrentlyChangeEntryInTable = false;
}
@ -235,7 +286,7 @@ public void actionPerformed(ActionEvent e)
NotificationConfigurationActivator.getNotificationService()
.restoreDefaults();
}
else if(e.getSource() == soundFileChooser)
else if(e.getSource() == soundFileButton)
{
if (row < 0)
return;
@ -243,20 +294,22 @@ else if(e.getSource() == soundFileChooser)
NotificationEntry entry
= notificationList.getNotificationEntry(row);
File file = fileChooserSound.getFileFromDialog();
File file = soundFileChooser.getFileFromDialog();
if (file != null)
{
try
{
// Store the last program file path.
setLastSoundPath(file.getParent());
String fileUri = file.toURI().toURL().toExternalForm();
//This is where a real application would open the file.
if (logger.isDebugEnabled())
logger.debug("Opening: "
+ file.toURI().toURL().toExternalForm());
logger.debug("Opening: " + fileUri);
entry.setSoundFile(file.toURI().toURL().toExternalForm());
soundFileTextField.setText(
file.toURI().toURL().toExternalForm());
entry.setSoundFile(fileUri);
soundFileTextField.setText(fileUri);
}
catch (MalformedURLException ex)
{
@ -269,7 +322,7 @@ else if(e.getSource() == soundFileChooser)
logger.debug("Open command cancelled by user.");
}
}
else if(e.getSource() == programFileChooser)
else if(e.getSource() == programFileButton)
{
if (row < 0)
return;
@ -277,10 +330,13 @@ else if(e.getSource() == programFileChooser)
NotificationEntry entry
= notificationList.getNotificationEntry(row);
File file = fileChooserProgram.getFileFromDialog();
File file = programFileChooser.getFileFromDialog();
if (file != null)
{
// Store the last program file path.
setLastProgramPath(file.getParent());
//This is where a real application would open the file.
if (logger.isDebugEnabled())
logger.debug("Opening: " +file.getAbsolutePath());
@ -386,4 +442,48 @@ public void textFieldUpdated(DocumentEvent event)
origSoundAction.isSoundPCSpeakerEnabled()));
}
}
/**
* Returns the last opened sound path.
*
* @return the last opened sound path
*/
private String getLastSoundPath()
{
return NotificationConfigurationActivator.getConfigurationService()
.getString(SOUND_LAST_PATH_PROP, "");
}
/**
* Sets the last opened sound path.
*
* @param the last opened sound path
*/
private void setLastSoundPath(String path)
{
NotificationConfigurationActivator.getConfigurationService()
.setProperty(SOUND_LAST_PATH_PROP, path);
}
/**
* Returns the last opened program path.
*
* @return the last opened program path
*/
private String getLastProgramPath()
{
return NotificationConfigurationActivator.getConfigurationService()
.getString(PROGRAM_LAST_PATH_PROP, "");
}
/**
* Sets the last opened sound path.
*
* @param path the last opened sound path
*/
private void setLastProgramPath(String path)
{
NotificationConfigurationActivator.getConfigurationService()
.setProperty(PROGRAM_LAST_PATH_PROP, path);
}
}

@ -266,7 +266,6 @@ public int getRowCount()
public void setSelectedRow(int row)
{
notifTable.setRowSelectionInterval(row, row);
configPanel.setNotificationEntry(getNotificationEntry(row));
}
/**

Loading…
Cancel
Save