/*
 * jNPad v0.3 - jNPad's an Simple Text Editor written in Java
 *
 * Copyright (C) 2014-2017  rgs
 *
 * Require JDK 1.6 (or later)
 *
 * This program 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 2 of the License, or (at your option)
 * any later version.
 *
 * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 *
 *
 * Info, Questions, Suggestions & Bugs Report to rgsevero@gmail.com
 */

package jnpad.action;

import java.awt.event.ItemEvent;

import javax.swing.KeyStroke;

import jnpad.JNPadFrame;
import jnpad.action.JNPadActions.Group;
import jnpad.config.Config;
import jnpad.config.ViewActionScope;
import jnpad.ui.status.StatusDisplayable;

/**
 * The Class SelectViewActionScopeAction.
 *
 * @version 0.3
 * @since   jNPad v0.1
 */
public abstract class SelectViewActionScopeAction extends JNPadAction {
  private ViewActionScope   scope;

  /** UID */
  private static final long serialVersionUID = -1934162877492633718L;

  /**
   * Instantiates a new select view action scope action.
   *
   * @param jNPad the jNPad's frame
   * @param name the name
   * @param defaultAccelerator the default accelerator
   * @param scope the scope
   */
  protected SelectViewActionScopeAction(JNPadFrame jNPad, String name, KeyStroke defaultAccelerator, ViewActionScope scope) {
    super(jNPad, name, Group.VIEW, defaultAccelerator, null);
    this.scope = scope;
    setSelected(scope == Config.VIEW_ACTION_SCOPE.getValue());
    setStateAction(true);
  }

  /**
   * Handle state changed.
   *
   * @param e the ItemEvent
   * @see jnpad.action.JNPadAction#handleStateChanged(java.awt.event.ItemEvent)
   */
  @Override
  public void handleStateChanged(final ItemEvent e) {
    if (ItemEvent.SELECTED == e.getStateChange()) {
      Config.VIEW_ACTION_SCOPE.setValue(scope);
      
      String msg = ActionBundle.getString("select-view-action-scope.message", getLabel()); //$NON-NLS-1$
      jNPad.setStatus(msg, StatusDisplayable.TIMEOUT_DEFAULT);
    }
  }

}
