1
16package org.tp23.antinstaller.renderer.swing.plaf;
17
18import java.lang.reflect.Method;
19
20import javax.swing.LookAndFeel;
21import javax.swing.UIManager;
22
23import org.tp23.antinstaller.InstallerContext;
24import org.tp23.antinstaller.input.OutputField;
25
26
27
31public class LookAndFeelFactory {
32
33 public static final String DEFAULT_LAF = "org.tp23.jgoodies.plaf.plastic.PlasticXPLookAndFeel";
34 public static final String GREYMETAL_LAF = "greymetal";
35 public static final String NATIVE_LAF = "native";
36 public static final String JGOODIES_LAF = "jgoodies";
37 public static final String NULL_LAF = "null";
38
39 private final String specifiedLAF;
40 private final InstallerContext ctx;
41
44 public LookAndFeelFactory(InstallerContext ctx) {
45 this.ctx = ctx;
46 this.specifiedLAF = ctx.getInstaller().getLookAndFeel();
47 }
48
49 public void setLAF(){
50 String lafClassName = null;
51 try{
52 lafClassName = getLafFromToken(specifiedLAF);
53 if(lafClassName == null){
54 return;
55 }
56 LookAndFeel look = (LookAndFeel)Class.forName(lafClassName).newInstance();
57 ctx.log("Setting look and feel:" + lafClassName);
58 UIManager.setLookAndFeel(look);
59
60 boolean antialias = OutputField.isTrue(ctx.getInstaller().getAntialiased());
61 if(antialias){
63 Method setAntialiased = look.getClass().getMethod("setAntiAliased", new Class[]{boolean.class});
64 if(setAntialiased != null){
65 ctx.log("Setting antialiasing:" + antialias);
66 Object[] args = new Boolean[]{new Boolean(antialias)};
68 setAntialiased.invoke(null, args);
69 }
70 }
71 }catch(Exception ex ){
72 ctx.getLogger().log("Can not correctly set Look And Feel:" + ex.getMessage());
73 ctx.getLogger().log(ctx.getInstaller(), ex);
74 }
75 }
76
77 public static boolean isDefault(String laf){
78 return ( laf == null || laf.equals(JGOODIES_LAF) || laf.equals(DEFAULT_LAF) );
79 }
80
86 public static String getLafFromToken(String token) {
87 String laf = null;
88 if(token == null || token.equals(JGOODIES_LAF)) {
89 laf = DEFAULT_LAF;
90 }
91 else if(token.equals(NULL_LAF)) {
92 laf = null;
93 }
94 else if(token.equals(NATIVE_LAF)) {
95 laf = UIManager.getSystemLookAndFeelClassName();
96 }
97 else if(token.equals(GREYMETAL_LAF)) {
98 laf = "org.tp23.antinstaller.renderer.swing.plaf.ModMetalLookAndFeel";
99 }
00 else {
01 laf = token;
02 }
03 return laf;
04 }
05}
06