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

📄 pasteitemedit.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;

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

public class PasteItemEdit extends AbstractUndoableEdit 
{
    private static final long serialVersionUID = -2778264565816334345L;
    
    private TreePath path;
    private TreePath pasteNodePath;
    private JDFTreeNode pasteNode;
    private JDFElement pasteElement;
    private JDFTreeNode intoNode;
    private JDFElement intoElement;
    private String attributeName;
    private String attributeValue;
    private JDFFrame parFrame;
    private int pos;
    private boolean success = true;
    
    public PasteItemEdit(final JDFFrame parentFrame, final TreePath treePath, 
			    		final JDFTreeNode intoNode, final JDFElement intoElement, 
			    		final JDFTreeNode pasteNode) 
    {
         parFrame = parentFrame;
         path = treePath;
         this.intoNode = intoNode;
         this.intoElement = intoElement;
         
         this.pasteNode = pasteNode;
 
         pos = intoNode.getIndex(pasteNode);
         if (!pasteNode.isElement())
         {
             attributeName = StringUtil.token(pasteNode.toString(), 0, "=");
             attributeValue = StringUtil.token(pasteNode.toString(), 1, "=");
             if (attributeValue.indexOf("\"") != -1)
             {
                 attributeValue = attributeValue.substring(1,attributeValue.length()-1);
             }
         }
         else 
         {
             pasteElement = (JDFElement) ((Wrapper) pasteNode.getUserObject()).getElement();
         }
         pasteNodePath = new TreePath(pasteNode.getPath());
 
         parFrame.updateViews(pasteNodePath);
    }

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

    public void redo() throws CannotRedoException 
    {
        parFrame.insertInto(intoNode, pasteNode, pos);
        if (!pasteNode.isElement())
        {
            intoElement.setAttribute(attributeName, attributeValue);
        }
        else 
        {
            intoElement.appendChild(pasteElement);
        }
        pasteNodePath = new TreePath(pasteNode.getPath());
        parFrame.updateViews(pasteNodePath);
    }

    public boolean canUndo() 
    {
         return  success;
    }

    public boolean canRedo() 
    {
        return  success;
    }

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

}

⌨️ 快捷键说明

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