/**
 * Copyright (C) 2004-2011 Jive Software. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jivesoftware.spark.plugin.flashing;

import javax.swing.Icon;
import javax.swing.JComponent;

import org.jivesoftware.spark.preference.Preference;

public class FlashingPreference implements Preference {
	public static final String NAMESPACE = "flashing";

	private FlashingPreferenceDialog dialog;
	private final FlashingPreferences preferences = new FlashingPreferences();

	public FlashingPreferences getPreferences() {
		return preferences;
	}

	@Override
	public void commit() {
		preferences.setFlashingEnabled(dialog.getFlashing());
		preferences.setFlashingType(dialog.getFlashingType());
		preferences.save();
	}

	@Override
	public Object getData() {
		return preferences;
	}

	@Override
	public String getErrorMessage() {
		return null;
	}

	@Override
	public JComponent getGUI() {
        dialog = new FlashingPreferenceDialog();
        dialog.setFlashing(preferences.isFlashingEnabled());
        dialog.setFlashingType(preferences.getFlashingType());
		return dialog;
	}

	@Override
	public Icon getIcon() {
		return FlashingResources.LIGHTING_BOLT_IMAGE;
	}

	@Override
	public String getListName() {
		return FlashingResources.getString("title.flashing");
	}

	@Override
	public String getNamespace() {
		return NAMESPACE;
	}

	@Override
	public String getTitle() {
		return FlashingResources.getString("title.flashing");
	}

	@Override
	public String getTooltip() {
		return FlashingResources.getString("title.flashing");
	}

	@Override
	public boolean isDataValid() {
		return true;
	}

	@Override
	public void load() {
	}
}
