001 /*
002 * Copyright (c) 2005 Einar Pehrson <einar@pehrson.nu>.
003 *
004 * This file is part of
005 * CleanSheets - a spreadsheet application for the Java platform.
006 *
007 * CleanSheets is free software; you can redistribute it and/or modify
008 * it under the terms of the GNU General Public License as published by
009 * the Free Software Foundation; either version 2 of the License, or
010 * (at your option) any later version.
011 *
012 * CleanSheets is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015 * GNU General Public License for more details.
016 *
017 * You should have received a copy of the GNU General Public License
018 * along with CleanSheets; if not, write to the Free Software
019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020 */
021 package csheets.ui.ext;
022
023 import java.awt.event.ActionEvent;
024 import java.awt.event.KeyEvent;
025
026 import javax.swing.Action;
027
028 import csheets.ui.ctrl.FocusOwnerAction;
029
030 /**
031 * An action for enabling and disabling table decorators.
032 * @author Einar Pehrson
033 */
034 @SuppressWarnings("serial")
035 public class TableDecoratorAction extends FocusOwnerAction {
036
037 /** The extension to control*/
038 private UIExtension extension;
039
040 /** The decorator to control */
041 private TableDecorator decorator;
042
043 /**
044 * Creates a new table decorator action.
045 * @param extension the extension to control
046 */
047 public TableDecoratorAction(UIExtension extension) {
048 // Stores members
049 this.extension = extension;
050 this.decorator = extension.getTableDecorator();
051
052 // Configures action
053 String name = extension.getExtension().getName();
054 putValue(NAME, name);
055 putValue(SHORT_DESCRIPTION, name);
056 putValue(ACTION_COMMAND_KEY, name);
057 putValue(SMALL_ICON, extension.getIcon());
058 }
059
060 protected String getName() {
061 return null;
062 }
063
064 protected void defineProperties() {
065 putValue(Action.MNEMONIC_KEY, KeyEvent.VK_C);
066 }
067
068 /**
069 * Toggles the enabled state of the decorator.
070 * @param event the event that was fired
071 */
072 public void actionPerformed(ActionEvent event) {
073 decorator.setEnabled(!decorator.isEnabled());
074 extension.setEnabledProperty("tabledecorator", decorator.isEnabled());
075 focusOwner.repaint();
076 }
077 }