source: other-projects/trunk/realistic-books/packages/AntInstaller/src/org/tp23/antinstaller/renderer/swing/plaf/LookAndFeelFactory.java@ 19253

Last change on this file since 19253 was 19253, checked in by davidb, 15 years ago

Establishing a source code repository for Veronica's Realistic Book's software

File size: 3.3 KB
Line 
1/*
2 * Copyright 2005 Paul Hinds
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
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/**
28 * @author Paul Hinds
29 * @version $Id: LookAndFeelFactory.java,v 1.9 2007/01/28 21:31:08 teknopaul Exp $
30 */
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 /**
42 *
43 */
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 // Reflection used here to avoid dependencies on JGoodies
62 if(antialias){
63 Method setAntialiased = look.getClass().getMethod("setAntiAliased", new Class[]{boolean.class});
64 if(setAntialiased != null){
65 ctx.log("Setting antialiasing:" + antialias);
66 // JDK1.5 warning fix
67 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 /**
81 * Gets a look and feel class name respecting the tokens supported
82 * such as jgoodies, null, native and greymetal
83 * @param token
84 * @return look and feel class name
85 */
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 }
100 else {
101 laf = token;
102 }
103 return laf;
104 }
105}
Note: See TracBrowser for help on using the repository browser.