Android Open Source - Sketcher-Tab Styles Factory






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.style;
/*from  w  ww.j  a va 2s.c om*/
import org.sketchertab.Sketcher;
import org.sketchertab.Style;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public final class StylesFactory {
    public static final BrushType DEFAULT_BRUSH_TYPE = BrushType.SKETCHY;

    private static Map<BrushType, StyleBrush> usedBrushes = new HashMap<BrushType, StyleBrush>();
    private static BrushType currentStyle = DEFAULT_BRUSH_TYPE;

    public static StyleBrush getStyle(BrushType brushType) {
        if (!usedBrushes.containsKey(brushType)) {
            StyleBrush style;
            try {
                style = getStyleInstance(brushType);
            } catch (RuntimeException e) {
                brushType = DEFAULT_BRUSH_TYPE;
                style = getStyleInstance(brushType);
            }
            usedBrushes.put(brushType, style);
        }
        currentStyle = brushType;
        return usedBrushes.get(brushType);
    }

    public static Style getCurrentStyle() {
        return getStyle(currentStyle);
    }

    public static BrushType getCurrentBrushType() {
        return currentStyle;
    }

    public static void clearCache() {
        usedBrushes.clear();
    }

    private static StyleBrush getStyleInstance(BrushType id) {
        float density = Sketcher.getInstance().getDensity();
        switch (id) {
            case SKETCHY:
                return new SketchyStyle(density);
            case SHADED:
                return new ShadedStyle(density);
            case FUR:
                return new FurStyle(density);
            case WEB:
                return new WebStyle(density);
            case CIRCLES:
                return new CirclesStyle(density);
            case RIBBON:
                return new RibbonStyle();
            case SIMPLE:
                return new SimpleStyle();
            default:
                throw new RuntimeException("Invalid style ID");
        }
    }

    public static void saveState(Map<BrushType, Object> state) {
        Collection<StyleBrush> values = usedBrushes.values();
        for (Style style : values) {
            style.saveState(state);
        }
    }

    public static void restoreState(Map<BrushType, Object> state) {
        Set<BrushType> keySet = state.keySet();
        for (BrushType brushType : keySet) {
            Style style = getStyle(brushType);
            style.restoreState(state);
        }
    }

    public enum BrushType {
        SKETCHY,
        SHADED,
        CHROME,
        FUR,
        WEB,
        RIBBON,
        CIRCLES,
        SIMPLE
    }
}




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