查看本类的 API文档即时通讯网 - 即时通讯开发者社区!
1   /*
2    * Copyright (C) 2015 Jack Jiang(cngeeker.com) The BeautyEye Project. 
3    * All rights reserved.
4    * Project URL:https://github.com/JackJiang2011/beautyeye
5    * Version 3.6
6    * 
7    * Jack Jiang PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
8    * 
9    * BeautyEyeLookAndFeelWin.java at 2015-2-1 20:25:39, original version by Jack Jiang.
10   * You can contact author with jb2011@163.com.
11   */
12  package org.jb2011.lnf.beautyeye;
13  
14  import javax.swing.BorderFactory;
15  import javax.swing.JDialog;
16  import javax.swing.JFrame;
17  import javax.swing.UIDefaults;
18  import javax.swing.UIManager;
19  import javax.swing.plaf.BorderUIResource;
20  import javax.swing.plaf.InsetsUIResource;
21  
22  import org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper.FrameBorderStyle;
23  import org.jb2011.lnf.beautyeye.winlnfutils.WinUtils;
24  
25  import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
26  
27  /**
28   * <p>
29   * BeautyEye Swing外观实现方案 - Windows平台专用外观实现主类.<br>
30   * <p>
31   * 本主题主类仅供Windows下使用,它将使用Windows操作系统默认的字体等设置.
32   * 
33   * @author Jack Jiang(jb2011@163.com)
34   * @version 1.0
35   */
36  // * 参考源码基于JDK_1.6.0_u18.
37  public class BeautyEyeLookAndFeelWin extends WindowsLookAndFeel
38  {
39  	static{
40  		initLookAndFeelDecorated();
41  	}
42  	
43  	/**
44  	 * Instantiates a new beauty eye look and feel win.
45  	 *
46  	 * @see BeautyEyeLNFHelper#implLNF()
47  	 * @see org.jb2011.lnf.beautyeye.ch20_filechooser.__UI__#uiImpl_win()
48  	 * @see #initForVista()
49  	 */
50  	public BeautyEyeLookAndFeelWin()
51  	{
52  		super();
53  
54  		BeautyEyeLNFHelper.implLNF();
55  		
56  		//自定义JFileChooser的L&F实现(为了解决windows LNF下文件选择框UI未实现背景填充问题)
57  		org.jb2011.lnf.beautyeye.ch20_filechooser.__UI__.uiImpl_win();
58  		
59  		//针对Vista及更新的windows平台进行特殊设置
60  		initForVista();
61  	}
62  	
63  	/**
64  	 * 因Windos LNF会在Vista及更新的操作系统(如win7)上对Windows LNF作附加设置,
65  	 * 以保证与Vista及更新平台的外观的一致性(如让菜单菜项高度更大等),请参见
66  	 * WindowsLookAndFeel.initVistaComponentDefaults(..)。
67  	 * <p>
68  	 * BeautyEye中因需要保证审美一致性(在所有win平台上)而不需要这些额外的设置,
69  	 * 但因该方法是private私有方法,无法进行覆盖屏蔽,所以只能在此单列方法,以便针对Vista
70  	 * 及更新的平台进行补救性重新设置以便与BeautyEye LNF的审核进行适配.
71  	 * 
72  	 * @see WindowsLookAndFeel.initVistaComponentDefaults(..)
73  	 */
74  	protected void initForVista()
75  	{
76  		if(WinUtils.isOnVista())
77  		{
78  			UIManager.put("CheckBoxMenuItem.margin",new InsetsUIResource(0,0,0,0));
79  			UIManager.put("RadioButtonMenuItem.margin",new InsetsUIResource(0,0,0,0));
80  			UIManager.put("Menu.margin",new InsetsUIResource(0,0,0,0));//windows lnf xp中默认是2,2,2,2
81  			UIManager.put("MenuItem.margin",new InsetsUIResource(0,0,0,0));//windows lnf中  xp默认是2,2,2,2
82  			
83  			UIManager.put("Menu.border",new BorderUIResource(BorderFactory.createEmptyBorder(1,3,2,3)));//javax.swing.plaf.basic.BasicBorders.MarginBorder;
84  			UIManager.put("MenuItem.border",new BorderUIResource(BorderFactory.createEmptyBorder(1,0,2,0)));//javax.swing.plaf.basic.BasicBorders.MarginBorder;
85  			UIManager.put("CheckBoxMenuItem.border",new BorderUIResource(BorderFactory.createEmptyBorder(4,2,4,2)));//javax.swing.plaf.basic.BasicBorders.MarginBorder;
86  			UIManager.put("RadioButtonMenuItem.border",new BorderUIResource(BorderFactory.createEmptyBorder(4,0,4,0)));//javax.swing.plaf.basic.BasicBorders.MarginBorder;		
87  //			UIManager.put("PopupMenu.border",new BorderUIResource(BorderFactory.createEmptyBorder(20,10,20,10)));//	
88  		
89  			UIManager.put("CheckBoxMenuItem.checkIcon"
90  					,new org.jb2011.lnf.beautyeye.ch9_menu.BECheckBoxMenuItemUI.CheckBoxMenuItemIcon().setUsedForVista(true));//javax.swing.plaf.basic.BasicIconFactory.CheckBoxMenuItemIcon);
91  			UIManager.put("RadioButtonMenuItem.checkIcon"
92  					,new org.jb2011.lnf.beautyeye.ch9_menu.BERadioButtonMenuItemUI.RadioButtonMenuItemIcon().setUsedForVista(true));
93  		}
94  	}
95  	
96  	/* (non-Javadoc)
97  	 * @see com.sun.java.swing.plaf.windows.WindowsLookAndFeel#getName()
98  	 */
99  	@Override 
100 	public String getName() 
101 	{
102         return "BeautyEyeWin";
103     }
104 
105 	/* (non-Javadoc)
106 	 * @see com.sun.java.swing.plaf.windows.WindowsLookAndFeel#getID()
107 	 */
108 	@Override 
109     public String getID() 
110     {
111         return "BeautyEyeWin";
112     }
113 
114 	/* (non-Javadoc)
115 	 * @see com.sun.java.swing.plaf.windows.WindowsLookAndFeel#getDescription()
116 	 */
117 	@Override 
118     public String getDescription() 
119     {
120         return "BeautyEye windows-platform L&F developed by Jack Jiang(jb2011@163.com).";
121     }
122 	
123 	/**
124 	 * Gets the supports window decorations.
125 	 *
126 	 * @return the supports window decorations
127 	 * {@inheritDoc}
128 	 */
129 	@Override 
130 	public boolean getSupportsWindowDecorations() 
131 	{
132 		return true;
133 	}
134 	
135 	/**
136 	 * {@inheritDoc}
137 	 */
138 	protected void initComponentDefaults(UIDefaults table)
139     {
140 		super.initComponentDefaults(table);
141         initOtherResourceBundle(table);
142     }
143 	/**
144      * Initialize the defaults table with the name of the other ResourceBundle
145      * used for getting localized defaults.
146      */
147     protected void initOtherResourceBundle(UIDefaults table)
148     {
149         table.addResourceBundle( "org.jb2011.lnf.beautyeye.resources.beautyeye" );
150     }
151 	
152 	/**
153 	 * 据BeautyEyeLNFHelper.frameBorderStyle指明的窗口边框类型来
154 	 * 决定是否使用操作系统相关的窗口装饰样式.
155 	 */
156 	static void initLookAndFeelDecorated()
157 	{
158 		if(BeautyEyeLNFHelper.frameBorderStyle == FrameBorderStyle.osLookAndFeelDecorated)
159 		{
160 			JFrame.setDefaultLookAndFeelDecorated(false);
161 			JDialog.setDefaultLookAndFeelDecorated(false);
162 		}
163 		else
164 		{
165 			JFrame.setDefaultLookAndFeelDecorated(true);
166 			JDialog.setDefaultLookAndFeelDecorated(true);
167 		}
168 		
169 //		UIManager.put("swing.aatext", Boolean.FALSE);
170 	}
171 }