蓝色空间
简单的程序人生
posts - 11,comments - 70,trackbacks - 0
        在项目中使用SubstanceLookAndFeel,就免不了要每一种感观的Menu了。以下代码就可以生成SubstanceLookAndFeel的Menu项代码,方便自己和他人日后使用。
public static Map LAF_MAP = new TreeMap();//使用TreeMap是为了保证MenuItem有序 
LAF_MAP.put("Windows", "com.sun.java.swing.plaf.windows.WindowsLookAndFeel");//Windows感观
LAF_MAP.put("Substance", "org.jvnet.substance.SubstanceLookAndFeel");
LAF_MAP.put("Autumn", "org.jvnet.substance.skin.SubstanceAutumnLookAndFeel");
LAF_MAP.put("BusinessBlackSteel", "org.jvnet.substance.skin.SubstanceBusinessBlackSteelLookAndFeel");
LAF_MAP.put("BusinessBlueSteel", "org.jvnet.substance.skin.SubstanceBusinessBlueSteelLookAndFeel");
LAF_MAP.put("Business", "org.jvnet.substance.skin.SubstanceBusinessLookAndFeel");
LAF_MAP.put("ChallengerDeep", "org.jvnet.substance.skin.SubstanceChallengerDeepLookAndFeel");
LAF_MAP.put("CremeCoffee", "org.jvnet.substance.skin.SubstanceCremeCoffeeLookAndFeel");
LAF_MAP.put("Creme", "org.jvnet.substance.skin.SubstanceCremeLookAndFeel");
LAF_MAP.put("EmeraldDusk", "org.jvnet.substance.skin.SubstanceEmeraldDuskLookAndFeel");
LAF_MAP.put("FieldOfWheat", "org.jvnet.substance.skin.SubstanceFieldOfWheatLookAndFeel");
LAF_MAP.put("GreenMagic", "org.jvnet.substance.skin.SubstanceGreenMagicLookAndFeel");
LAF_MAP.put("Magma", "org.jvnet.substance.skin.SubstanceMagmaLookAndFeel");
LAF_MAP.put("Mango", "org.jvnet.substance.skin.SubstanceMangoLookAndFeel");
LAF_MAP.put("MistAqua", "org.jvnet.substance.skin.SubstanceMistAquaLookAndFeel");
LAF_MAP.put("MistSilver", "org.jvnet.substance.skin.SubstanceMistSilverLookAndFeel");
LAF_MAP.put("Moderate", "org.jvnet.substance.skin.SubstanceModerateLookAndFeel");
LAF_MAP.put("NebulaBrickWall", "org.jvnet.substance.skin.SubstanceNebulaBrickWallLookAndFeel");
LAF_MAP.put("Nebula", "org.jvnet.substance.skin.SubstanceNebulaLookAndFeel");
LAF_MAP.put("OfficeBlue2007", "org.jvnet.substance.skin.SubstanceOfficeBlue2007LookAndFeel");
LAF_MAP.put("OfficeSilver2007", "org.jvnet.substance.skin.SubstanceOfficeSilver2007LookAndFeel");
LAF_MAP.put("RavenGraphiteGlass", "org.jvnet.substance.skin.SubstanceRavenGraphiteGlassLookAndFeel");
LAF_MAP.put("RavenGraphite", "org.jvnet.substance.skin.SubstanceRavenGraphiteLookAndFeel");
LAF_MAP.put("Raven", "org.jvnet.substance.skin.SubstanceRavenLookAndFeel");
LAF_MAP.put("Sahara", "org.jvnet.substance.skin.SubstanceSaharaLookAndFeel");
    添加感观菜单项代码
/** 
* 添加感观菜单项 
*/ 
private void addLAFMenuItem() { 

    for (Map.Entry entry : Config.LAF_MAP.entrySet()) { 
        JRadioButtonMenuItem lafItem = new JRadioButtonMenuItem(entry.getKey()); 
        lafItem.addActionListener(new LAFListener(entry.getValue(), this)); 
        lafGroup.add(lafItem); 
        menuLAF.add(lafItem); 
    } 
}  
    感观菜单项ActionListener
    package org.ekit.ui.listener; 
    import java.awt.Component; 
    import java.awt.event.ActionEvent; 
    import java.awt.event.ActionListener; 
    import java.util.logging.Level; 
    import java.util.logging.Logger; 
    import javax.swing.LookAndFeel; 
    import javax.swing.SwingUtilities; 
    import javax.swing.UIManager; 
    import javax.swing.UnsupportedLookAndFeelException; 
    /** 
    * 感观菜单项ActionListener 
    * @author ivin 
    */ 

    public class LAFListener implements ActionListener { 
        private String className; 
        private Component com; 
    
        public LAFListener(String className, Component com) { 
            this.className = className; 
            this.com = com; 
        } 
    
        public void actionPerformed(ActionEvent e) { 
    
            try { 
                Object obj = Class.forName(className).newInstance(); 
                if (obj instanceof LookAndFeel) { 
                    UIManager.setLookAndFeel(className); 
                } 
                SwingUtilities.updateComponentTreeUI(com); 
            } catch (ClassNotFoundException ex) { 
                Logger.getLogger(LAFListener.class.getName()).log(Level.SEVERE, null, ex); 
            } catch (InstantiationException ex) { 
                Logger.getLogger(LAFListener.class.getName()).log(Level.SEVERE, null, ex); 
            } catch (IllegalAccessException ex) { 
                Logger.getLogger(LAFListener.class.getName()).log(Level.SEVERE, null, ex); 
            } catch (UnsupportedLookAndFeelException ex) { 
                Logger.getLogger(LAFListener.class.getName()).log(Level.SEVERE, null, ex); 
            } 
    
        } 
    
    }  
        如果一个一个LookAndFeel的Class的找比较的麻烦,所以SubstanceLookAndFeel的那一段代码是自己写的程序生成的。
        另外感觉blogjava的代码格式不如javaeye好,什么时候建议dudu改一下,javaeye的java代码着色和eclipse非常相似,看起来特别的舒服。在这就是那么几个java关键字的高亮显示。看起来比较费劲啊! 
        自力更生,自己来做代码着色的工作!
posted on 2007-12-29 18:41 ivin 阅读(2442) 评论(2)  编辑  收藏 所属分类: 代码收集

FeedBack:
# re: 生成Substance皮肤Menu项的代码
2008-02-27 13:19 | 隔叶黄莺
我采用的是浏览器解析时动态着色,这样让日志本身体积会小,如果将来汇集成册,带上相应样式及js即可;缺点就是中间过程会展露出来。而楼主是预生成的代码内容,解析前进行排版及加上样式的,就是javaeye那样在输入时转换。  回复  更多评论
  
# LAF_MAP.put("EmeraldDusk", "org.jvnet.substance.skin.SubstanceEmeraldDuskLookAndFeel");
2008-09-05 22:11 | sfdwe
assa  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: