changeattributecommand.java

来自「开源(Open Source)项目JHotDraw的文档和源程序」· Java 代码 · 共 53 行

JAVA
53
字号
/*
 * @(#)ChangeAttributeCommand.java 5.2
 *
 */

package CH.ifa.draw.standard;

import java.awt.Color;
import CH.ifa.draw.framework.*;
import CH.ifa.draw.util.*;

/**
 * Command to change a named figure attribute.
 */
public  class ChangeAttributeCommand
        extends Command {

    private DrawingView fView;
    private String      fAttribute;
    private Object      fValue;

   /**
    * Constructs a change attribute command.
    * @param name the command name
    * @param attributeName the name of the attribute to be changed
    * @param value the new attribute value
    * @param view the target view
    */
    public ChangeAttributeCommand(String name, String attributeName,
                           Object value, DrawingView view) {
        super(name);
        fAttribute = attributeName;
        fValue = value;
        fView = view;
    }

    public void execute() {
        FigureEnumeration k = fView.selectionElements();
        while (k.hasMoreElements()) {
            Figure f = k.nextFigure();
            f.setAttribute(fAttribute, fValue);
        }
        fView.checkDamage();
    }

    public boolean isExecutable() {
        return fView.selectionCount() > 0;
    }

}


⌨️ 快捷键说明

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