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 try {
58 boolean antialias = OutputField.isTrue(ctx.getInstaller().getAntialiased());
59 Method setAntialiased = look.getClass().getMethod("setAntiAliased", new Class[]{boolean.class});
61 if(setAntialiased != null){
62 ctx.log("Setting antialiasing:" + antialias);
63 Object[] args = new Boolean[]{new Boolean(antialias)};
65 setAntialiased.invoke(null, args);
66 }
67 }
68 catch (Exception e) {
69 ctx.getLogger().log("JGoodies extensions not functioning:" + e.getMessage());
70 }
71 ctx.log("Setting look and feel:" + lafClassName);
72 UIManager.setLookAndFeel(look);
73 }
74 catch(Exception ex ){
75 ctx.getLogger().log("Can not correctly set Look And Feel:" + ex.getMessage());
76 ctx.getLogger().log(ctx.getInstaller(), ex);
77 }
78 }
79
80 public static boolean isDefault(String laf){
81 return ( laf == null || laf.equals(JGOODIES_LAF) || laf.equals(DEFAULT_LAF) );
82 }
83
89 public static String getLafFromToken(String token) {
90 String laf = null;
91 if(token == null || token.equals(JGOODIES_LAF)) {
92 laf = DEFAULT_LAF;
93 }
94 else if(token.equals(NULL_LAF)) {
95 laf = null;
96 }
97 else if(token.equals(NATIVE_LAF)) {
98 laf = UIManager.getSystemLookAndFeelClassName();
99 }
00 else if(token.equals(GREYMETAL_LAF)) {
01 laf = "org.tp23.antinstaller.renderer.swing.plaf.ModMetalLookAndFeel";
02 }
03 else {
04 laf = token;
05 }
06 return laf;
07 }
08}
09