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

📄 cubestack.java

📁 wince 5.0上基于personal java写的的虚拟魔方
💻 JAVA
字号:

/*
 * Java Virtual Cube
 * -----------------
 *
 * Copyright 1996, Song Li  
 * URL: http://www.cs.umbc.edu/~sli2
 *
 * 
 * You can use the code for any nonprofittable use. But remember to mention
 * the authors' names in your revised program. You are also encouraged to
 * improve the program or give your comments and bug reports. If there are
 * further questions, please contact me and I'll be glad to help. My E-Mail
 * address is: sli2@gl.umbc.edu.
 *
 */


import java.awt.*; 
import java.util.*;



class CubeStack {

    private int        Watermark ;
    private int        Count ;
    private Stack      UndoStack ;
    private Stack      RedoStack ;
    private Label      StepText ;
    private boolean    UpdateEnabled = true ;
    
   

    CubeStack (Label steptext) {
        UndoStack = new Stack () ;
        RedoStack = new Stack () ;
        Watermark = 0 ;
        Count     = 0 ;
        StepText  = steptext ;
    }



    public void EnableUpdate (boolean enabled) {
        UpdateEnabled = enabled ;
        if (UpdateEnabled)
            UpdateStep () ;
    }
    

    public void UpdateStep () {
        if (UpdateEnabled)
            StepText.setText (String.valueOf (Count-Watermark)) ;
    }
        


    void Clear () {
        while (! UndoStack.empty ())
            UndoStack.pop () ;
        while (! RedoStack.empty ())
            RedoStack.pop () ;
        Watermark = 0 ;
        Count     = 0 ;
        UpdateStep () ;
    }



    void Do (CubeAction action) {
        UndoStack.push (action) ;
        if (! RedoStack.empty ())
            RedoStack = new Stack () ;
        Count ++ ;
        UpdateStep () ;
    }
    
    
    CubeAction Undo () {
        if (Count > Watermark) {
            CubeAction newaction ;
            try {
                newaction = (CubeAction) UndoStack.pop () ;
            } catch (EmptyStackException e) {return null ;}

            RedoStack.push (newaction) ;
            Count -- ;
            UpdateStep () ;
            return newaction ;
            }
        return null ;
    }
    
    
    
    CubeAction ForceUndo () {
        CubeAction newaction ;
        try {
            newaction = (CubeAction) UndoStack.pop () ;
        } catch (EmptyStackException e) {return null ;}

        Watermark -- ;
        Count -- ;
        if (! RedoStack.empty ())
            RedoStack = new Stack () ;
        UpdateStep () ;
        return newaction ;
    }
    


    CubeAction Redo () {
        CubeAction newaction ;
        try {
            newaction = (CubeAction) RedoStack.pop () ;
        } catch (EmptyStackException e) {return null ;}
        Count ++ ;
        UpdateStep () ;
        return (CubeAction) UndoStack.push (newaction) ;
    }
        
    
    
    void SetWatermark () {
        Watermark = Count ;
        UpdateStep () ;
    }
}



⌨️ 快捷键说明

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