1
16package org.tp23.antinstaller.runtime.exe;
17
18import java.io.IOException;
19import java.util.StringTokenizer;
20
21import org.tp23.antinstaller.InstallException;
22import org.tp23.antinstaller.InstallerContext;
23import org.tp23.antinstaller.renderer.swing.plaf.LookAndFeelFactory;
24import org.tp23.antinstaller.runtime.AutoSwingRunner;
25import org.tp23.antinstaller.runtime.AutoTextRunner;
26import org.tp23.antinstaller.runtime.Runner;
27import org.tp23.antinstaller.runtime.SwingRunner;
28import org.tp23.antinstaller.runtime.TextRunner;
29
30
31
37public class CreateUIFilter implements ExecuteFilter {
38
39
42 public void exec(InstallerContext ctx) throws InstallException {
43 try {
44 if(ctx.getInstaller().isVerbose()){
45 ctx.log("Creating UI classes");
46 }
47 ctx.setRunner(getRunner(ctx));
48 ctx.log("Created UI classes");
49 }
50 catch (IOException e) {
51 throw new InstallException("Unable to create the user interface", e);
52 }
53 catch (InstallException e) {
54 throw new InstallException(e.getMessage(), e);
55 }
56 }
57
67 private Runner getRunner(InstallerContext ctx) throws IOException, InstallException {
68
69 if(ctx.getUIOverride() != null){
70 if (ctx.getUIOverride().equalsIgnoreCase("swing")){
71 if(isUi("swing", ctx.getInstaller().getUi())){
72 new LookAndFeelFactory(ctx).setLAF();
73 return new SwingRunner(ctx);
74 }else{
75 throw new InstallException("Not a permited UI override, swing is not allowed");
76 }
77 }
78
79 if (ctx.getUIOverride().equalsIgnoreCase("text")){
80 if(isUi("text", ctx.getInstaller().getUi())){
81 return new TextRunner(ctx);
82 }else{
83 throw new InstallException("Not a permited UI override, text is not allowed");
84 }
85 }
86
87 if (ctx.getUIOverride().equalsIgnoreCase("swing-auto")){
88 if(isUi("swing-auto", ctx.getInstaller().getUi())){
89 new LookAndFeelFactory(ctx).setLAF();
90 return new AutoSwingRunner(ctx);
91 }else{
92 throw new InstallException("Not a permited UI override, swing-auto is not allowed");
93 }
94 }
95
96 if (ctx.getUIOverride().equalsIgnoreCase("text-auto")){
97 if(isUi("text-auto", ctx.getInstaller().getUi())){
98 return new AutoTextRunner(ctx);
99 }else{
00 throw new InstallException("Not a permited UI override, text-auto is not allowed");
01 }
02 }
03
04 }
05 try{
07 java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment();
08
12 new LookAndFeelFactory(ctx).setLAF();
13 return new SwingRunner(ctx);
14 } catch (Throwable e){
15 System.out.println("No graphics environment available, reverting to text");
16 System.out.println();
17 return new TextRunner(ctx);
18 }
19 }
20
21
22 private boolean isUi(String ui, String commaSeparatedUiList){
23 StringTokenizer st = new StringTokenizer(commaSeparatedUiList, ",");
24 while(st.hasMoreTokens()){
25 if(st.nextToken().equals(ui)){
26 return true;
27 }
28 }
29 return false;
30 }
31
32}
33