Android Open Source - Sketcher-Tab History Item






From Project

Back to project page Sketcher-Tab.

License

The source code is released under:

Apache License

If you think the Android project Sketcher-Tab listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.sketchertab;
/*  www  .  j  a v a  2s.co m*/
import android.graphics.Bitmap;
import org.sketchertab.style.StylesFactory;

import java.nio.IntBuffer;
import java.util.HashMap;
import java.util.Map;

/**
 * History element
 */
public final class HistoryItem {
    private SurfaceDiff surfaceDiff;
    private IntBuffer oldSurfaceBuffer;
    private Map<StylesFactory.BrushType, Object> oldBrushData = new HashMap<StylesFactory.BrushType, Object>();
    private HistoryItemState state = HistoryItemState.UNDO;

    public HistoryItem(IntBuffer oldSurface, Map<StylesFactory.BrushType, Object> oldBrushData) {
        surfaceDiff = SurfaceDiff.Create(oldSurface, Sketcher.getInstance().getSurface().getBitmap());

        if (null == surfaceDiff)
            this.oldSurfaceBuffer = (IntBuffer) oldSurface.rewind();

        this.oldBrushData = oldBrushData;
    }

    public void undo() {
        swap();
    }

    public void redo() {
        swap();
    }

    private void swap() {
        Bitmap bitmap = Sketcher.getInstance().getSurface().getBitmap();
        Map<StylesFactory.BrushType, Object> brushData = new HashMap<StylesFactory.BrushType, Object>();
        StylesFactory.saveState(brushData);

        if (null != surfaceDiff) {
            surfaceDiff.applyAndSwap(bitmap);
        } else {
            IntBuffer surf = IntBuffer.allocate(bitmap.getWidth() * bitmap.getHeight());
            bitmap.copyPixelsToBuffer(surf);

            bitmap.copyPixelsFromBuffer(oldSurfaceBuffer);
            oldSurfaceBuffer = (IntBuffer) surf.rewind();
        }

        StylesFactory.restoreState(oldBrushData);
        oldBrushData = brushData;

        Sketcher.getInstance().getSurface().invalidate();
    }

    public HistoryItemState getState() {
        return state;
    }

    public void setState(HistoryItemState state) {
        this.state = state;
    }

    public static enum HistoryItemState {
        UNDO,
        REDO
    }
}




Java Source Code List

org.sketchertab.AboutDialog.java
org.sketchertab.BrushProperties.java
org.sketchertab.DocumentHistory.java
org.sketchertab.DrawController.java
org.sketchertab.FileHelper.java
org.sketchertab.HistoryItem.java
org.sketchertab.Sketcher.java
org.sketchertab.Style.java
org.sketchertab.SurfaceDiff.java
org.sketchertab.Surface.java
org.sketchertab.colorpicker.HuePicker.java
org.sketchertab.colorpicker.PickerDialog.java
org.sketchertab.colorpicker.Picker.java
org.sketchertab.colorpicker.PreviewView.java
org.sketchertab.colorpicker.SatValPicker.java
org.sketchertab.colorpicker.Utils.java
org.sketchertab.style.CirclesStyle.java
org.sketchertab.style.FurStyle.java
org.sketchertab.style.RibbonStyle.java
org.sketchertab.style.ShadedStyle.java
org.sketchertab.style.SimpleStyle.java
org.sketchertab.style.SketchyStyle.java
org.sketchertab.style.StyleBrush.java
org.sketchertab.style.StylesFactory.java
org.sketchertab.style.WebStyle.java