notificationspreference.java

来自「开源项目openfire的完整源程序」· Java 代码 · 共 120 行

JAVA
120
字号
/**
 * $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.Res;
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 Res.getString("title.notifications");
    }

    public String getListName() {
        return Res.getString("title.notifications");
    }

    public String getTooltip() {
        return Res.getString("tooltip.notifications");
    }

    public Icon getIcon() {
        return SparkRes.getImageIcon(SparkRes.PROFILE_ICON);
    }

    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();
                boolean offlineNotification = localPreferences.isOfflineNotificationsOn();
                boolean onlineNotification = localPreferences.isOnlineNotificationsOn();
                boolean betaChecking = localPreferences.isBetaCheckingEnabled();

                panel.setShowToaster(toaster);
                panel.setShowWindowPopup(windowFocus);
                panel.setOfflineNotification(offlineNotification);
                panel.setOnlineNotification(onlineNotification);
                panel.setCheckForBeta(betaChecking);
            }
        };

        thread.start();

    }

    public void commit() {
        LocalPreferences pref = SettingsManager.getLocalPreferences();

        pref.setShowToasterPopup(panel.showToaster());
        pref.setWindowTakesFocus(panel.shouldWindowPopup());
        pref.setOfflineNotifications(panel.isOfflineNotificationOn());
        pref.setOnlineNotifications(panel.isOnlineNotificationOn());
        pref.setCheckForBeta(panel.isBetaCheckingEnabled());
        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();
    }


}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?