package de.renew.propertymanagement.prop;

import javax.swing.KeyStroke;

/**
 * Extension of {@link ConfigurableProperty} that deals with hotkeys specifically.
 *
 * @author 0schult
 */
public class ConfigurableHotkeyProperty extends ConfigurableProperty {
    private KeyStroke _keyStroke;
    private HotkeyType _hotkeyType;

    /**
     * Creates a new {@link ConfigurableHotkeyProperty} with the given initial value.
     *
     * @param key the key for this property
     * @param keyStroke the default hotkey for this property
     * @param hotkeyType the type of hotkey this property is dealing with
     * @param pluginName the name of the plugin that is registering this property
     * @param displayName the name that should be displayed for this property
     */
    public ConfigurableHotkeyProperty(
        String key, KeyStroke keyStroke, HotkeyType hotkeyType, String pluginName,
        String displayName)
    {
        super(key, keyStroke.toString(), pluginName, displayName, null, false);
        _keyStroke = keyStroke;
        _hotkeyType = hotkeyType;
    }

    /**
     * Creates a new {@link ConfigurableHotkeyProperty} with the given initial value. Provides a description which will be displayed on the tooltip.
     *
     * @param key the key for this property
     * @param keyStroke the default hotkey for this property
     * @param pluginName the name of the plugin that is registering this property
     * @param displayName the name that should be displayed for this property
     * @param description the description which will be displayed when hovering over the property
     */
    public ConfigurableHotkeyProperty(
        String key, KeyStroke keyStroke, HotkeyType hotkeyType, String pluginName,
        String displayName, String description)
    {
        super(key, keyStroke.toString(), pluginName, displayName, null, false, description);
        _keyStroke = keyStroke;
        _hotkeyType = hotkeyType;
    }

    /**
     * Get the current hotkey for this property.
     *
     * @return the {@link KeyStroke} for this property
     */
    public KeyStroke getKeyStroke() {
        return _keyStroke;
    }

    /**
     * Set the hotkey for this property.
     *
     * @param keyStroke the new {@link KeyStroke} for this property
     */
    public void setKeyStroke(KeyStroke keyStroke) {
        _keyStroke = keyStroke;
        setCurrentValue(keyStroke.toString());
    }

    /**
     * Get the type of this hotkey.
     *
     * @return the {@link HotkeyType} of this hotkey
     */
    public HotkeyType getHotkeyType() {
        return _hotkeyType;
    }

    /**
     * Gets the default value as a {@link KeyStroke}.
     *
     * @return the default value as {@code KeyStroke}
     */
    public KeyStroke getDefaultKeyStroke() {
        return KeyStroke.getKeyStroke(getDefaultValue());
    }

    @Override
    public boolean isDefault() {
        return _keyStroke == null || _keyStroke.equals(KeyStroke.getKeyStroke(getDefaultValue()));
    }
}
