All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alee.laf.slider.SliderSettingsProcessor Maven / Gradle / Ivy

/*
 * This file is part of WebLookAndFeel library.
 *
 * WebLookAndFeel library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * WebLookAndFeel library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with WebLookAndFeel library.  If not, see .
 */

package com.alee.laf.slider;

import com.alee.managers.settings.Configuration;
import com.alee.managers.settings.SettingsProcessor;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

/**
 * {@link SettingsProcessor} implementation that handles {@link JSlider} settings.
 *
 * @author Mikle Garin
 * @see How to use SettingsManager
 * @see com.alee.managers.settings.UISettingsManager
 * @see com.alee.managers.settings.SettingsManager
 * @see SettingsProcessor
 */
public class SliderSettingsProcessor extends SettingsProcessor>
{
    /**
     * {@link ChangeListener} for tracking {@link JSlider} value changes.
     */
    protected transient ChangeListener changeListener;

    /**
     * Constructs new {@link SliderSettingsProcessor}.
     *
     * @param slider        {@link JSlider} which settings are being managed
     * @param configuration {@link Configuration}
     */
    public SliderSettingsProcessor ( final JSlider slider, final Configuration configuration )
    {
        super ( slider, configuration );
    }

    @Override
    protected void register ( final JSlider slider )
    {
        changeListener = new ChangeListener ()
        {
            @Override
            public void stateChanged ( final ChangeEvent e )
            {
                save ();
            }
        };
        slider.addChangeListener ( changeListener );
    }

    @Override
    protected void unregister ( final JSlider slider )
    {
        slider.removeChangeListener ( changeListener );
        changeListener = null;
    }

    @Override
    protected SliderState createDefaultValue ()
    {
        return new SliderState ( component () );
    }

    @Override
    protected void loadSettings ( final JSlider slider )
    {
        loadSettings ().apply ( slider );
    }

    @Override
    protected void saveSettings ( final JSlider slider )
    {
        saveSettings ( new SliderState ( slider ) );
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy