/**
 * 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 com.jivesoftware.spark.plugin.apple;

import java.awt.Image;

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

import org.jivesoftware.spark.preference.Preference;

/**
 * Apple Preference<br>
 * Apple, the Apple logo, Mac, and Macintosh are trademarks of Apple Inc
 * 
 * @author Wolf Posdorfer
 */
public class ApplePreference implements Preference {
    private static final String NAMESPACE = "OSX";
    private final AppleProperties _props;
    private ApplePreferencePanel _prefpanel;

    public ApplePreference(AppleProperties props) {
	_props = props;
    }

    @Override
    public void commit() {
        _props.setDockBadges(_prefpanel.getDockBadges());
        _props.setDockBounce(_prefpanel.getDockBounce());
        _props.setRepeatBouncing(_prefpanel.getRepeatBouncing());
        _props.save();
    }

    @Override
    public String getErrorMessage() {
	return "error with apple plugin";
    }

    @Override
    public JComponent getGUI() {
        _prefpanel = new ApplePreferencePanel();
        _prefpanel.setDockBadges(_props.getDockBadges());
        _prefpanel.setDockBounce(_props.getDockBounce());
        _prefpanel.setRepeatBouncing(_props.getRepeatBouncing());
        return _prefpanel;
    }

    @Override
    public Icon getIcon() {
	ClassLoader cl = getClass().getClassLoader();
	ImageIcon icon = new ImageIcon(cl.getResource("images/X.png"));
	Image x = icon.getImage().getScaledInstance(24, 24, java.awt.Image.SCALE_FAST);
	icon = new ImageIcon(x);
	return icon;
    }

    @Override
    public String getListName() {
	return "OSX";
    }

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

    @Override
    public String getTitle() {
	return "OSX";
    }

    @Override
    public String getTooltip() {
	return "Apple Plugin Features";
    }

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

    @Override
    public void load() {
    }

}
