Android Open Source - Sketcher Styles Factory






From Project

Back to project page Sketcher.

License

The source code is released under:

Apache License

If you think the Android project Sketcher 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.sketcher.style;
/*from   w  w  w .ja  va2  s  . com*/
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.sketcher.Style;

public class StylesFactory {
  public static final int SKETCHY = 0x1001;
  public static final int SHADED = 0x1002;
  public static final int CHROME = 0x1003;
  public static final int FUR = 0x1004;
  public static final int LONGFUR = 0x1005;
  public static final int WEB = 0x1006;
  public static final int SQUARES = 0x1007;
  public static final int RIBBON = 0x1008;
  public static final int CIRCLES = 0x1009;
  public static final int GRID = 0x1010;
  public static final int SIMPLE = 0x1011;
  public static final int ERASER = 0x1012;

  private static Map<Integer, Style> cache = new HashMap<Integer, Style>();
  private static int currentStyle = SKETCHY;

  public static Style getStyle(int id) {
    if (!cache.containsKey(id)) {
      cache.put(id, getStyleInstance(id));
    }
    currentStyle = id;
    return cache.get(id);
  }

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

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

  private static Style getStyleInstance(int id) {
    switch (id) {
    case SKETCHY:
      return new SketchyStyle();
    case SHADED:
      return new ShadedStyle();
    case CHROME:
      return new ChromeStyle();
    case FUR:
      return new FurStyle();
    case LONGFUR:
      return new LongfurStyle();
    case WEB:
      return new WebStyle();
    case SQUARES:
      return new SquaresStyle();
    case RIBBON:
      return new RibbonStyle();
    case CIRCLES:
      return new CirclesStyle();
    case GRID:
      return new GridStyle();
    case SIMPLE:
      return new SimpleStyle();
    case ERASER:
      return new EraserStyle();

    default:
      throw new RuntimeException("Invalid style ID");
    }
  }

  public static void saveState(HashMap<Integer, Object> state) {
    Collection<Style> values = cache.values();
    for (Style style : values) {
      style.saveState(state);
    }
  }

  public static void restoreState(HashMap<Integer, Object> state) {
    Set<Integer> keySet = state.keySet();
    for (int id : keySet) {
      Style style = getStyle(id);
      style.restoreState(state);
    }
  }
}




Java Source Code List

org.sketcher.AboutDialog.java
org.sketcher.Controller.java
org.sketcher.FileHelper.java
org.sketcher.HistoryHelper.java
org.sketcher.SketcherApplication.java
org.sketcher.Sketcher.java
org.sketcher.Style.java
org.sketcher.Surface.java
org.sketcher.colorpicker.AlphaPicker.java
org.sketcher.colorpicker.HuePicker.java
org.sketcher.colorpicker.PickerDialog.java
org.sketcher.colorpicker.Picker.java
org.sketcher.colorpicker.PreviewView.java
org.sketcher.colorpicker.SatValPicker.java
org.sketcher.colorpicker.Utils.java
org.sketcher.style.ChromeStyle.java
org.sketcher.style.CirclesStyle.java
org.sketcher.style.EraserStyle.java
org.sketcher.style.FurStyle.java
org.sketcher.style.GridStyle.java
org.sketcher.style.LongfurStyle.java
org.sketcher.style.RibbonStyle.java
org.sketcher.style.ShadedStyle.java
org.sketcher.style.SimpleStyle.java
org.sketcher.style.SketchyStyle.java
org.sketcher.style.SquaresStyle.java
org.sketcher.style.StylesFactory.java
org.sketcher.style.WebStyle.java