Adding new notification preferences.

git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@4903 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Derek DeMoro 2006-08-14 16:10:08 +00:00 committed by derek
parent f678f06c6f
commit d92c27298d
4 changed files with 191 additions and 1 deletions

View File

@ -14,6 +14,7 @@ import org.jivesoftware.MainWindowListener;
import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.sparkimpl.preference.PreferenceDialog;
import org.jivesoftware.sparkimpl.preference.PreferencesPanel;
import org.jivesoftware.sparkimpl.preference.notifications.NotificationsPreference;
import org.jivesoftware.sparkimpl.preference.chat.ChatPreference;
import org.jivesoftware.sparkimpl.settings.local.LocalPreference;
@ -35,11 +36,15 @@ public class PreferenceManager {
addPreference(chatPreferences);
chatPreferences.load();
LocalPreference localPreferences = new LocalPreference();
addPreference(localPreferences);
localPreferences.load();
NotificationsPreference notifications = new NotificationsPreference();
addPreference(notifications);
notifications.load();
getPreferences();
SparkManager.getMainWindow().addMainWindowListener(new MainWindowListener() {

View File

@ -0,0 +1,110 @@
/**
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Lesser Public License (LGPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.sparkimpl.preference.notifications;
import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.spark.preference.Preference;
import org.jivesoftware.spark.util.SwingWorker;
import org.jivesoftware.sparkimpl.settings.local.LocalPreferences;
import org.jivesoftware.sparkimpl.settings.local.SettingsManager;
import javax.swing.Icon;
import javax.swing.JComponent;
/**
* Handles the preferences for notification behavior within the Spark IM Client.
*
* @author Derek DeMoro
*/
public class NotificationsPreference implements Preference {
private NotificationsUI panel = new NotificationsUI();
/**
* Define the Namespace used for this preference.
*/
public static final String NAMESPACE = "http://www.jivesoftware.org/spark/notifications";
public String getTitle() {
return "Notifications";
}
public String getListName() {
return "Notifications";
}
public String getTooltip() {
return "Notification preferences for incoming chats.";
}
public Icon getIcon() {
return SparkRes.getImageIcon(SparkRes.USER1_MESSAGE_24x24);
}
public void load() {
SwingWorker thread = new SwingWorker() {
LocalPreferences localPreferences;
public Object construct() {
localPreferences = SettingsManager.getLocalPreferences();
return localPreferences;
}
public void finished() {
boolean toaster = localPreferences.getShowToasterPopup();
boolean windowFocus = localPreferences.getWindowTakesFocus();
panel.setShowToaster(toaster);
panel.setShowWindowPopup(windowFocus);
}
};
thread.start();
}
public void commit() {
LocalPreferences pref = SettingsManager.getLocalPreferences();
pref.setShowToasterPopup(panel.showToaster());
pref.setWindowTakesFocus(panel.shouldWindowPopup());
SettingsManager.saveSettings();
}
public Object getData() {
LocalPreferences pref = SettingsManager.getLocalPreferences();
return pref;
}
public String getErrorMessage() {
return "";
}
public boolean isDataValid() {
return true;
}
public JComponent getGUI() {
return panel;
}
public String getNamespace() {
return NAMESPACE;
}
public void shutdown() {
commit();
}
}

View File

@ -0,0 +1,59 @@
/**
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Lesser Public License (LGPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.sparkimpl.preference.notifications;
import org.jivesoftware.spark.component.VerticalFlowLayout;
import org.jivesoftware.spark.util.ResourceUtils;
import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
/**
* Represents the UI for handling notification preferences within Spark.
*
* @author Derek DeMoro
*/
public class NotificationsUI extends JPanel {
private JCheckBox toasterBox;
private JCheckBox windowFocusBox;
public NotificationsUI() {
setLayout(new VerticalFlowLayout());
setBorder(BorderFactory.createTitledBorder("Notification Options"));
toasterBox = new JCheckBox();
ResourceUtils.resButton(toasterBox, "Show a &Toast Popup");
add(toasterBox);
windowFocusBox = new JCheckBox();
ResourceUtils.resButton(windowFocusBox, "&Bring window to front");
add(windowFocusBox);
}
public void setShowToaster(boolean show) {
toasterBox.setSelected(show);
}
public boolean showToaster() {
return toasterBox.isSelected();
}
public void setShowWindowPopup(boolean popup) {
windowFocusBox.setSelected(popup);
}
public boolean shouldWindowPopup() {
return windowFocusBox.isSelected();
}
}

View File

@ -423,6 +423,22 @@ public class LocalPreferences {
return props.getProperty("nickname", SparkManager.getUserManager().getNickname());
}
public void setShowToasterPopup(boolean show) {
setBoolean("toasterPopup", show);
}
public boolean getShowToasterPopup() {
return getBoolean("toasterPopup", false);
}
public void setWindowTakesFocus(boolean focus) {
setBoolean("windowTakesFocus", focus);
}
public boolean getWindowTakesFocus() {
return getBoolean("windowTakesFocus", false);
}
private boolean getBoolean(String property, boolean defaultValue) {
return Boolean.parseBoolean(props.getProperty(property, Boolean.toString(defaultValue)));
}