package org.kne.cloud.network.klalb.ui;

import java.awt.Color;
import java.awt.Font;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.IOException;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;

import javax.swing.JButton;
import javax.swing.UIManager;

import org.kne.ui.LinearGradientColor;
public class UIEnv {
	private static Font font;
	private static Image icon ;
	private static Color defaultcolor=new Color(207,218,223);//new Color(207,218,223)
	private static Color selectedcolor=new Color(207/2,218/2,223/2);
	
	static final LinearGradientColor RANGE_1=new LinearGradientColor(new float[] {0.0f,0.5f,0.8f,1.0f},new Color[] {Color.GREEN,Color.GREEN,Color.YELLOW,Color.RED});
	static final LinearGradientColor RANGE_2=new LinearGradientColor(new float[] {0.0f,0.05f,0.3f,0.6f,1.0f},new Color[] {Color.GREEN,Color.GREEN,Color.YELLOW,Color.RED,Color.BLACK});
	static final LinearGradientColor RANGE_3=new LinearGradientColor(new float[] {0.0f,0.02f,0.15f,0.5f,1.0f},new Color[] {Color.GREEN,Color.GREEN,Color.YELLOW,Color.RED,Color.BLACK});
	static final LinearGradientColor RANGE_4=new LinearGradientColor(new float[] {0.0f,0.01f,0.1f,1.0f},new Color[] {Color.GREEN,Color.YELLOW,Color.RED,Color.BLACK});
	
	
	private static ResourceBundle rsb;
	public static void setRsb(String xrsb) throws IOException {
		rsb=new PropertyResourceBundle(UIEnv.class.getResourceAsStream("/klalb_"+xrsb+".properties"));
	}
	
	public static void setRsb(ResourceBundle xrsb) {
		rsb=xrsb;
	}
	public static ResourceBundle getRsb() {
		if(rsb==null) {
			try {
				rsb=new PropertyResourceBundle(UIEnv.class.getResourceAsStream("/klalb_en_US.properties"));
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return rsb;
	}
	//private static Color tpccolor=new Color(250,250,250,190);
		public static Color getDefaultcolor() {
		return defaultcolor;
	}
	public static void setDefaultColor(Color defaultcolor) {
		UIEnv.defaultcolor = defaultcolor;
	}

	public static Color titlecolor=new Color(0,0,100,200);

	public static Color backgroundcolor=new Color(0,0,100,255);
	public static Color getDefaultTitleColor() {
		return titlecolor;
	}
	
	public static Color getDefaultBackgroundColor() {
		return backgroundcolor;
	}
	
	public static Color getHalfTransparentDefaultColor() {
		return new Color(defaultcolor.getRed(), defaultcolor.getGreen(), defaultcolor.getBlue(), 210);
	}
		public static void inituie(){
			/*try {
				UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
			} catch (ClassNotFoundException e) {
				// TODO 自动生成的 catch 块
				e.printStackTrace();
			} catch (InstantiationException e) {
				// TODO 自动生成的 catch 块
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				// TODO 自动生成的 catch 块
				e.printStackTrace();
			} catch (UnsupportedLookAndFeelException e) {
				// TODO 自动生成的 catch 块
				e.printStackTrace();
			}*/
			font=new Font("微软雅黑",Font.PLAIN , 12);
			/*try {
				font = Font.createFont(Font.PLAIN, UIEnv.class.getResourceAsStream("/assets/SourceHanSansCN-Light.otf")).deriveFont(13f);
			} catch (FontFormatException e1) {
				e1.printStackTrace();
			} catch (IOException e1) {
				// TODO 自动生成的 catch 块
				e1.printStackTrace();
			}*/
			
		        java.util.Enumeration keys = UIManager.getDefaults().keys();
		        while (keys.hasMoreElements()) {
		            Object key = keys.nextElement();
		            Object value = UIManager.get(key);
		            if (value instanceof javax.swing.plaf.FontUIResource) {
		                UIManager.put(key, font);
		            }
		        }
		       icon=Toolkit.getDefaultToolkit().getImage(
		   			UIEnv.class.getResource("/assets/KLALB2.png"));
		}
		public static void defbut(JButton start) {
			if(font==null)
				inituie();
			start.setBorderPainted(false);
			start.setForeground(Color.WHITE);
			start.setFont(font.deriveFont(Font.BOLD, 18));
			start.setBackground(defaultcolor);
		}
		public static void defbut(JButton start,int fontsize) {
			if(font==null)
				inituie();
			start.setBorderPainted(false);
			start.setForeground(Color.WHITE);
			start.setFont(font.deriveFont(Font.BOLD, fontsize));
			start.setBackground(defaultcolor);
		}
		public static Font getFont(){
			if(icon==null)
				inituie();
			return font;
		}
		public static Image getIcon(){
			if(icon==null)
				inituie();
			return icon;
		}
		
		public static Color getSelectedcolor() {
			return selectedcolor;
		}
		public static void setSelectedcolor(Color selectedcolor) {
			UIEnv.selectedcolor = selectedcolor;
		}
		/*public static Color getHalfTransparentColor() {
			return tpccolor;
		}*/
	
}
