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

📄 insertattredit.java

📁 java xml 应用开发
💻 JAVA
字号:
import javax.swing.tree.TreePath;
import javax.swing.undo.AbstractUndoableEdit;
import javax.swing.undo.CannotRedoException;
import javax.swing.undo.CannotUndoException;

import org.cip4.jdflib.core.JDFElement;
import org.cip4.jdflib.util.StringUtil;
import org.w3c.dom.Attr;

/*
 * InsertAttrEdit.java
 * @author Elena Skobchenko
 */

public class InsertAttrEdit extends AbstractUndoableEdit 
{
    private static final long serialVersionUID = -2778264565816334345L;
    
    private TreePath path;
    private TreePath attrPath;
    private Attr attrib;
    private JDFTreeNode intoNode;
    private JDFElement intoElement;
    private JDFTreeNode attrNode;
    private String attributeName;
    private JDFFrame parFrame;
    private int pos;
    private boolean success = true;
    
    public InsertAttrEdit(final JDFFrame parentFrame, final TreePath treePath, final JDFTreeNode newAttrNode) 
    {
         parFrame = parentFrame;
         path = treePath;
         attrNode = newAttrNode;
         
         try
         {
             intoNode = (JDFTreeNode) path.getLastPathComponent();
             intoElement = (JDFElement) ((Wrapper) intoNode.getUserObject()).getElement();
         }
         catch (Exception s)
         {
             intoNode = (JDFTreeNode) path.getParentPath().getLastPathComponent();
             intoElement = (JDFElement) ((Wrapper) intoNode.getUserObject()).getElement();
         }

         pos = intoNode.getIndex(attrNode);
         attributeName = StringUtil.token(attrNode.toString(), 0, "=");
         attrib = intoElement.getAttributeNode(attributeName);
         attrPath = new TreePath(attrNode.getPath());

         parFrame.updateViews(attrPath);
    }

    public void undo() throws CannotUndoException 
    { 
         success = parFrame.deleteItem(attrPath);
         attrPath = null;
         parFrame.updateViews(path);
    }

    public void redo() throws CannotRedoException 
    {
        parFrame.insertInto(intoNode, attrNode, pos);
        intoElement.setAttributeNode(attrib);
        attrPath = new TreePath(attrNode.getPath());
        parFrame.updateViews(attrPath);
    }

    public boolean canUndo() 
    {
         return success;
    }

    public boolean canRedo() 
    {
        return success;
    }

    public String getPresentationName() 
    {
         return "InsertAttribute";
    }

}

⌨️ 快捷键说明

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