⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 compieretheme.java

📁 Java写的ERP系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			{
				menuFont = new FontUIResource(Font.getFont("swing.plaf.metal.menuFont",
					new Font(FONT_DEFAULT, Font.PLAIN, FONT_SIZE)));
			}
			catch (Exception e)
			{
				menuFont = new FontUIResource(FONT_DEFAULT, Font.PLAIN, FONT_SIZE);
			}
		}
		return menuFont;
	}
	public FontUIResource getMenuTextFont() {return _getMenuTextFont();}

	/**
	 *  Window Title
	 *  @return font
	 */
	private static FontUIResource _getWindowTitleFont()
	{
		if (windowFont == null)
		{
			try
			{
				windowFont = new FontUIResource(Font.getFont("swing.plaf.metal.windowFont",
					new Font(FONT_DEFAULT, Font.BOLD, FONT_SIZE+2)));
			}
			catch (Exception e)
			{
				windowFont = new FontUIResource(FONT_DEFAULT, Font.BOLD, FONT_SIZE+2);
			}
		}
		return windowFont;
	}
	public FontUIResource getWindowTitleFont() {return _getWindowTitleFont();}

	/**
	 *  Sub Text
	 *  @return font
	 */
	private static FontUIResource _getSubTextFont()
	{
		if (smallFont == null)
		{
			try
			{
				smallFont = new FontUIResource(Font.getFont("swing.plaf.metal.smallFont",
					new Font(FONT_DEFAULT, Font.PLAIN, FONT_SIZE-2)));
			}
			catch (Exception e)
			{
				smallFont = new FontUIResource(FONT_DEFAULT, Font.PLAIN, FONT_SIZE-2);
			}
		}
		return smallFont;
	}
	public FontUIResource getSubTextFont() {return _getSubTextFont();}

	/*************************************************************************/

	/**
	 *  Store information as property file
	 *  @param fileName
	 */
	public static void save (String fileName)
	{
		Properties p = new Properties();
		save (p);
		//
		try
		{
			FileOutputStream fos = new FileOutputStream (fileName);
			p.store(fos, NAME);
			fos.close();
		}
		catch (Exception e)
		{
			System.err.println("CompiereTheme.store - " + e.getMessage());
		}
	}   //  store

	/**
	 *  Load Data
	 *  @param fileName
	 */
	public static void load (String fileName)
	{
		Properties p = new Properties();
		try
		{
			FileInputStream fis = new FileInputStream (fileName);
			p.load(fis);
			fis.close();
		}
		catch (Exception e)
		{
			System.err.println("CompiereTheme.load - " + e.getMessage());
			return;
		}
		load (p);
	}   //  load

	//  Static property info

	private static final String P_Primary1      = "#ColorPrimary1";
	private static final String P_Primary2      = "#ColorPrimary2";
	private static final String P_Primary3      = "#ColorPrimary3";
	private static final String P_Secondary1    = "#ColorSecondary1";
	private static final String P_Secondary2    = "#ColorSecondary2";
	private static final String P_Secondary3    = "#ColorSecondary3";
	private static final String P_Black         = "#ColorBlack";
	private static final String P_White         = "#ColorWhite";
	private static final String P_Error         = "#ColorError";
	private static final String P_Info          = "#ColorInfo";
	private static final String P_Mandatory     = "#ColorMandatory";
	private static final String P_Inactive      = "#ColorInactive";
	private static final String P_Txt_OK        = "#ColorTextOK";
	private static final String P_Txt_Error     = "#ColorTextError";
	//
	private static final String P_Control       = "#FontControl";
	private static final String P_System        = "#FontSystem";
	private static final String P_User          = "#FontUser";
	private static final String P_Small         = "#FontSmall";
	private static final String P_Window        = "#FontWindow";
	private static final String P_Menu          = "#FontMenu";
	//
	protected static final String P_CompiereColor = "#CompiereColor";

	/**
	 *  Save information in Properties
	 *  @param p
	 */
	public static void save (Properties p)
	{
		p.setProperty(P_Primary1, getColorAsString(primary1));
		p.setProperty(P_Primary2, getColorAsString(primary2));
		p.setProperty(P_Primary3, getColorAsString(primary3));
		p.setProperty(P_Secondary1, getColorAsString(secondary1));
		p.setProperty(P_Secondary2, getColorAsString(secondary2));
		p.setProperty(P_Secondary3, getColorAsString(secondary3));
		p.setProperty(P_Error, getColorAsString(error));
		p.setProperty(P_Info, getColorAsString(info));
		p.setProperty(P_Mandatory, getColorAsString(mandatory));
		p.setProperty(P_Inactive, getColorAsString(inactive));
		p.setProperty(P_White, getColorAsString(white));
		p.setProperty(P_Black, getColorAsString(black));
		p.setProperty(P_Txt_OK, getColorAsString(txt_ok));
		p.setProperty(P_Txt_Error, getColorAsString(txt_error));
		//
		p.setProperty(P_Control, ((Font)controlFont).toString());
		p.setProperty(P_System, ((Font)systemFont).toString());
		p.setProperty(P_User, ((Font)userFont).toString());
		p.setProperty(P_Small, ((Font)smallFont).toString());
		p.setProperty(P_Window, ((Font)windowFont).toString());
		p.setProperty(P_Menu, ((Font)menuFont).toString());
		//
		p.setProperty(P_CompiereColor, CompiereColor.getDefaultBackground().toString());
	}   //  save

	/**
	 *  Parses Color into String representation.
	 *  Required as SystemColors and Alpha Colors have different formats
	 *  @param c Color
	 *  @return [r=102,g=102,b=153,a=255]
	 *  @see #parseColor
	 */
	public static String getColorAsString (Color c)
	{
		if (c == null)
			c = SystemColor.control;
		StringBuffer sb = new StringBuffer("[r=").append(c.getRed())
			.append(",g=").append(c.getGreen())
			.append(",b=").append(c.getBlue())
			.append(",a=").append(c.getAlpha())
			.append("]");
	//	System.out.println(sb.toString());
		return sb.toString();
	}   //  getColorAsString

	/**
	 *  Load Properties from Ini
	 */
	public static void load ()
	{
		load (Ini.getProperties());
	}   //  load

	/**
	 *  Load information from properties
	 *  @param p Properties
	 */
	public static void load (Properties p)
	{
		primary1 = parseColor (p.getProperty(P_Primary1), primary1);
		primary2 = parseColor (p.getProperty(P_Primary2), primary2);
		primary3 = parseColor (p.getProperty(P_Primary3), primary3);
		secondary1 = parseColor (p.getProperty(P_Secondary1), secondary1);
		secondary2 = parseColor (p.getProperty(P_Secondary2), secondary2);
		secondary3 = parseColor (p.getProperty(P_Secondary3), secondary3);
		error = parseColor(p.getProperty(P_Error), error);
		info = parseColor(p.getProperty(P_Info), info);
		mandatory = parseColor(p.getProperty(P_Mandatory), mandatory);
		inactive = parseColor(p.getProperty(P_Inactive), inactive);
		white = parseColor(p.getProperty(P_White), white);
		black = parseColor(p.getProperty(P_Black), black);
		txt_ok = parseColor(p.getProperty(P_Txt_OK), txt_ok);
		txt_error = parseColor(p.getProperty(P_Txt_Error), txt_error);
		//
		controlFont = parseFont(p.getProperty(P_Control), controlFont);
		systemFont = parseFont(p.getProperty(P_System), systemFont);
		userFont = parseFont(p.getProperty(P_User), userFont);
		smallFont = parseFont(p.getProperty(P_Small), smallFont);
		windowFont = parseFont(p.getProperty(P_Window), windowFont);
		menuFont = parseFont(p.getProperty(P_Menu), menuFont);
		//
		CompiereColor.setDefaultBackground(CompiereColor.parse(p.getProperty(P_CompiereColor)));
	}   //  load

	/**
	 *  Reset Info in Properties
	 *  @param p Properties
	 */
	public static void reset (Properties p)
	{
		p.remove (P_Primary1);
		p.remove (P_Primary2);
		p.remove (P_Primary3);
		p.remove (P_Secondary1);
		p.remove (P_Secondary2);
		p.remove (P_Secondary3);
		p.remove (P_Error);
		p.remove (P_Info);
		p.remove (P_Mandatory);
		p.remove (P_Inactive);
		p.remove (P_White);
		p.remove (P_Black);
		p.remove (P_Txt_OK);
		p.remove (P_Txt_Error);
		//
		p.remove (P_Control);
		p.remove (P_System);
		p.remove (P_User);
		p.remove (P_Small);
		p.remove (P_Window);
		p.remove (P_Menu);
		//  CompiereColor
		p.remove(P_CompiereColor);

		//  Initialize
		p.setProperty(Ini.P_UI_LOOK, CompiereLookAndFeel.NAME);
		p.setProperty(Ini.P_UI_THEME, NAME);
		//
		setDefault();

		//  Background
	//	CompiereColor cc = new CompiereColor(SystemColor.control);      //  flat Windows 212-208-200
	//	CompiereColor cc = new CompiereColor(secondary3);               //  flat Metal   204-204-204
		CompiereColor cc = new CompiereColor(secondary3, false);
		CompiereColor.setDefaultBackground (cc);
		//
		save(p);    //  save properties
	}   //  reset

	/**
	 *  Parse Color.
	 *  <p>
	 *  Color - [r=102,g=102,b=153,a=0]
	 *
	 *  @param info string information to be parsed
	 *  @param stdColor color used if info cannot parsed
	 *  @return color
	 *  @see #getColorAsString
	 */
	protected static ColorUIResource parseColor (String info, ColorUIResource stdColor)
	{
		if (info == null || info.length() == 0)
			return stdColor;
	//	System.out.print("ParseColor=" + info);
		try
		{
			int r = Integer.parseInt(info.substring(info.indexOf("r=")+2, info.indexOf(",g=")));
			int g = Integer.parseInt(info.substring(info.indexOf("g=")+2, info.indexOf(",b=")));
			int b = 0;
			int a = 255;
			if (info.indexOf("a=") == -1)
				b = Integer.parseInt(info.substring(info.indexOf("b=")+2, info.indexOf("]")));
			else
			{
				b = Integer.parseInt(info.substring(info.indexOf("b=")+2, info.indexOf(",a=")));
				a = Integer.parseInt(info.substring(info.indexOf("a=")+2, info.indexOf("]")));
			}
			ColorUIResource retValue = new ColorUIResource(new Color(r, g, b, a));
		//	System.out.println(" - " + retValue.toString());
			return retValue;
		}
		catch (Exception e)
		{
			System.err.println("ParseColor=" + info + " - cannot parse - " + e.toString());
		}
		return stdColor;
	}   //  parseColor

	/**
	 *  Parse Font
	 *  <p>
	 *  javax.swing.plaf.FontUIResource[family=dialog.bold,name=Dialog,style=bold,size=12]
	 *
	 *  @param info string information to be parsed
	 *  @param stdFont font used if info cannot be parsed
	 *  @return font
	 */
	private static FontUIResource parseFont(String info, FontUIResource stdFont)
	{
		if (info == null)
			return stdFont;
	//	System.out.print("ParseFont=" + info);
		try
		{
			String name = info.substring(info.indexOf("name=")+5, info.indexOf(",style="));
			String s = info.substring(info.indexOf("style=")+6, info.indexOf(",size="));
			int style = Font.PLAIN;
			if (s.equals("bold"))
				style = Font.BOLD;
			else if (s.equals("italic"))
				style = Font.ITALIC;
			else if (s.equals("bolditalic"))
				style = Font.BOLD | Font.ITALIC;
			int size = Integer.parseInt(info.substring(info.indexOf(",size=")+6, info.lastIndexOf("]")));;
			FontUIResource retValue = new FontUIResource(name,style,size);
		//	System.out.println(" - " + retValue.toString());
			return retValue;
		}
		catch (Exception e)
		{
			System.err.println("ParseFont=" + info + " - cannot parse - " + e.toString());
		}
		return stdFont;
	}   //  parseFont

}   //  CompiereTheme

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -