Package com.claymus.site.module.theme

Source Code of com.claymus.site.module.theme.ThemeData

package com.claymus.site.module.theme;

import java.io.File;
import java.net.URL;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;

import com.claymus.Logger;
import com.claymus.site.Module;
import com.claymus.site.Property;
import com.claymus.site.module.theme.types.PixelPerfect;

public class ThemeData {

  public static Theme getTheme() {
    Theme theme = Property.get("Theme");
    if(theme == null) {
      theme = new PixelPerfect();
      ThemeData.setTheme(theme);
    }
    return theme;
  }

  public static Theme getTheme(String className) {
    try {
      return (Theme) Class.forName(Module.MODULE_PACKAGE + ".theme.types." + className).newInstance();
    } catch(Exception ex) {
      Logger.get().log(Level.SEVERE, null, ex);
      return null;
    }
  }

  public static List<Theme> getThemes() {
    LinkedList<Theme> themes = new LinkedList<Theme>();
    URL url = ThemeData.class.getResource(Module.MODULE_PATH + "theme/types");
    File dir = new File(url.getPath());
    File[] list = dir.listFiles();
    for(File file : list) {
      if(file.isFile()) {
        String className = file.getName().split("[.]")[0];
        Theme theme = ThemeData.getTheme(className);
        if(theme != null)
          themes.add(theme);
      }
    }
    return themes;
  }

  public static boolean setTheme(Theme theme) {
    return Property.put("Theme", theme);
  }

}
TOP

Related Classes of com.claymus.site.module.theme.ThemeData

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.