⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractlayeraction.java

📁 tiled地图编辑器是2d的,很不错的国外软件,使用起来很方便的
💻 JAVA
字号:
/*
 *  Tiled Map Editor, (c) 2004-2006
 *
 *  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.
 *
 *  Adam Turk <aturk@biggeruniverse.com>
 *  Bjorn Lindeijer <b.lindeijer@xs4all.nl>
 */

package tiled.mapeditor.actions;

import java.awt.event.ActionEvent;
import java.util.Vector;
import javax.swing.AbstractAction;
import javax.swing.Icon;

import tiled.core.Map;
import tiled.mapeditor.MapEditor;
import tiled.mapeditor.undo.MapLayerStateEdit;

/**
 * Provides a common abstract class for actions that modify the layer
 * configuration. It makes sure the undo/redo information is properly
 * maintained.
 *
 * todo: These actions will need to listen to changing of the current selected
 * todo: layer index as well as changes to the opened map. Action should always
 * todo: be disabled when no map is opened. More specific checks should be
 * todo: included in subclasses.
 *
 * @version $Id: AbstractLayerAction.java 683 2006-06-25 14:17:37Z bjorn $
 */
public abstract class AbstractLayerAction extends AbstractAction
{
    protected final MapEditor editor;

    protected AbstractLayerAction(MapEditor editor,
                                  String name, String description)
    {
        super(name);
        putValue(SHORT_DESCRIPTION, description);
        putValue(ACTION_COMMAND_KEY, name);
        this.editor = editor;
    }

    protected AbstractLayerAction(MapEditor editor,
                                  String name, String description, Icon icon)
    {
        this(editor, name, description);
        putValue(SMALL_ICON, icon);
    }

    /**
     * Wraps {@link #doPerformAction} in order to capture the layer vector
     * before and after the action is performed.
     */
    public final void actionPerformed(ActionEvent e) {
        // Capture the layers before the operation is executed.
        Map map = editor.getCurrentMap();
        Vector layersBefore = new Vector(map.getLayerVector());

        doPerformAction();

        // Capture the layers after the operation is executed and create the
        // layer state edit instance.
        Vector layersAfter = new Vector(map.getLayerVector());
        MapLayerStateEdit mapLayerStateEdit =
                new MapLayerStateEdit(map, layersBefore, layersAfter,
                                      e.getActionCommand());
        editor.getUndoSupport().postEdit(mapLayerStateEdit);
    }

    /**
     * Actually performs the action that modifies the layer configuration.
     */
    protected abstract void doPerformAction();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -