merge the formfield patch from ooo-build
[ooovba.git] / scripting / workben / installer / InstallWizard.java
blob4501d2e4b52e1247646ced8af095b64d46ad3c36
1 package installer;
3 /*
4 * InstallWizard.java
6 * Created on 04 July 2002, 15:09
7 */
9 /**
11 * @author mike
14 import javax.swing.*;
15 import java.awt.*;
16 import java.awt.event.*;
17 import java.util.*;
18 import java.net.*;
19 import java.io.*;
21 public class InstallWizard extends javax.swing.JFrame implements ActionListener {
23 private static class ShutdownHook extends Thread {
24 public void run()
26 if (InstallWizard.isInstallStarted())
28 // Check for and backup any config.xml files
29 // Check for and backup any StarBasic macro files
30 // Check for and backup ProtocolHandler
32 if (!InstallWizard.isPatchedTypes())
34 File backup = new File(InstUtil.getTmpDir(), "TypeDetection.xml");
35 File destination = new File(InstallWizard.getTypesPath());
36 InstUtil.copy(backup, destination); //Restore typedetection.xml
38 if (!InstallWizard.isPatchedJava())
40 File backup = new File(InstUtil.getTmpDir(), "Java.xml");
41 File destination = new File(InstallWizard.getJavaPath());
42 InstUtil.copy(backup, destination); //Restore typedetection.xml
44 if (!InstallWizard.isPatchedRDB())
46 File backup = new File(InstUtil.getTmpDir(), "applicat.rdb");
47 File destination = new File(InstallWizard.getJavaPath());
48 //InstUtil.copy(backup, destination); //Restore typedetection.xml
51 System.out.println( "ShutdownHook" );
54 InstUtil.removeTmpDir();
56 }// class ShutdownHook
58 static {
59 Runtime rt=Runtime.getRuntime();
60 rt.addShutdownHook(new ShutdownHook());
62 */
63 /** Creates new form InstallWizard */
64 public InstallWizard() {
65 super("Office Scripting Framework Installer - Early Developer Release");
67 try {
68 System.out.print("All diagnostic output is being redirected to SFrameworkInstall.log\n");
69 System.out.print("Location: "+ System.getProperty( "user.dir" ) +
70 File.separator + "SFrameworkInstall.log\n");
72 LogStream log = new LogStream( "SFrameworkInstall.log" );
73 System.setErr(log);
75 System.setOut(log);
77 catch( FileNotFoundException fnfe ) {
78 System.err.println("Office Scripting Framework Installer - Error: ");
79 System.err.println("Unable to create log file for installation.");
80 exitForm(null);
83 //setBackground(Color.WHITE);
84 setBackground(new Color(0,0,0));
85 locations = new ArrayList();
86 //Point center = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
87 Point center = new Point( 400, 400 );
88 int windowWidth=200;
89 int windowHeight=300;
90 setSize(windowWidth,windowHeight);
91 setBounds((center.x-windowWidth/2)-115,(center.y-windowWidth/2)-100, windowWidth,windowHeight);
92 initComponents();
93 setResizable(false);
96 /** This method is called from within the constructor to
97 * initialize the form.
99 private void initComponents() {
100 navigation = new javax.swing.JPanel();
101 navBack = new javax.swing.JButton();
102 navNext = new javax.swing.JButton();
103 navCancel = new javax.swing.JButton();
104 screens = new javax.swing.JPanel();
106 addWindowListener(new java.awt.event.WindowAdapter() {
107 public void windowClosing(java.awt.event.WindowEvent evt) {
108 exitForm(evt);
112 navigation.setLayout(new java.awt.GridBagLayout());
113 java.awt.GridBagConstraints gridBagConstraints1;
115 navBack.setText("<< Back");
116 gridBagConstraints1 = new java.awt.GridBagConstraints();
117 gridBagConstraints1.insets = new java.awt.Insets(1, 1, 1, 1);
119 navNext.setText("Next >>");
120 gridBagConstraints1 = new java.awt.GridBagConstraints();
121 gridBagConstraints1.gridx = 2;
122 gridBagConstraints1.gridy = 0;
124 navCancel.setText("Cancel");
125 gridBagConstraints1 = new java.awt.GridBagConstraints();
126 gridBagConstraints1.gridx = 6;
127 gridBagConstraints1.gridy = 0;
128 //navigation.add(navNext, gridBagConstraints1);
129 //navigation.add(navBack, gridBagConstraints1);
130 //navigation.add(navCancel, gridBagConstraints1);
132 getContentPane().add(navigation, java.awt.BorderLayout.SOUTH);
133 screens.setLayout(new java.awt.CardLayout());
134 screens.add(WELCOME, new Welcome(this));
135 version = new Version(this);
136 screens.add(VERSIONS, version);
137 _final = new Final(this);
138 screens.add(FINAL, _final);
140 //boolean hasIDEInstallation = (InstUtil.hasNetbeansInstallation() || InstUtil.hasJeditInstallation()) ;
141 boolean hasIDEInstallation = ( InstUtil.hasNetbeansInstallation() ) ;
143 if( hasIDEInstallation )
145 idewelcome = new IdeWelcome(this);
146 screens.add(IDEWELCOME, idewelcome);
147 ideversion = new IdeVersion(this);
148 screens.add(IDEVERSIONS, ideversion);
149 idefinal = new IdeFinal(this);
150 screens.add(IDEFINAL, idefinal);
152 getContentPane().add(screens, java.awt.BorderLayout.CENTER);
154 navNext.addActionListener(this);
155 navNext.addActionListener(version);
156 navNext.addActionListener(_final);
158 if( hasIDEInstallation )
160 navNext.addActionListener(ideversion);
161 navNext.addActionListener(idefinal);
164 navCancel.addActionListener(this);
165 navBack.addActionListener(this);
168 URL url = this.getClass().getResource("sidebar.jpg");
169 JLabel sideBar = new JLabel();
170 sideBar.setIcon(new ImageIcon(url));
171 getContentPane().add (sideBar, java.awt.BorderLayout.WEST);
172 pack();
173 }// initComponents
175 /** Exit the Application */
176 public void exitForm(java.awt.event.WindowEvent evt) {
177 System.exit(0);
181 public void actionPerformed(ActionEvent e)
183 if (e.getSource() == navNext)
185 ((CardLayout)screens.getLayout()).next(screens);
188 if (e.getSource() == navCancel)
190 exitForm(null);
193 if (e.getSource() == navBack)
195 ((CardLayout)screens.getLayout()).previous(screens);
197 }// actionPerformed
199 public static void storeLocation(String path)
201 locations.add(path);
204 public static ArrayList getLocations()
206 return locations;
209 public static void clearLocations()
211 locations.clear();
214 public void show(String cardName)
216 ((CardLayout)screens.getLayout()).show(screens, cardName);
220 * @param args the command line arguments
222 public static void main(String args[]) {
223 String officePath = null;
224 String netbeansPath = null;
225 //String jeditPath = null;
226 int i = 0;
228 while (i < args.length) {
229 if (args[i].equals("-help")) {
230 printUsage();
231 System.exit(0);
233 if (args[i].equals("-office"))
234 officePath = args[++i];
235 if (args[i].equals("-netbeans"))
236 netbeansPath = args[++i];
237 if (args[i].equals("-net"))
238 bNetworkInstall = true;
239 if (args[i].equals("-bindings"))
240 bBindingsInstall = true;
241 //if (args[i].equals("-jedit"))
242 // jeditPath = args[++i];
243 i++;
246 //if (officePath == null && netbeansPath == null && jeditPath == null)
247 if (officePath == null && netbeansPath == null)
248 new InstallWizard().show();
250 JLabel label = new JLabel();
251 JProgressBar progressbar = new JProgressBar();
253 try {
254 System.out.println("Log file is: " +
255 System.getProperty("user.dir") +
256 File.separator + "SFrameworkInstall.log");
258 LogStream log = new LogStream( "SFrameworkInstall.log" );
259 System.setErr(log);
260 System.setOut(log);
262 catch( FileNotFoundException fnfe ) {
263 System.err.println("Error: Unable to create log file: "
264 + fnfe.getMessage());
265 System.exit(-1);
268 if (officePath != null) {
269 XmlUpdater xud = new XmlUpdater(officePath, label, progressbar, bNetworkInstall, bBindingsInstall );
270 xud.run();
273 if (netbeansPath != null) {
274 IdeUpdater ideup = new IdeUpdater(netbeansPath, label, progressbar);
275 ideup.run();
278 //if (jeditPath != null) {
279 // IdeUpdater ideup = new IdeUpdater(jeditPath, label, progressbar);
280 // ideup.run();
284 private static void printUsage() {
285 System.err.println("java -jar SFrameworkInstall.jar");
286 System.err.println("\t[-office <path_to_office_installation]");
287 System.err.println("\t[-netbeans <path_to_netbeans_installation]");
288 System.err.println("\t[-net]");
289 System.err.println("\t[-bindings]");
290 System.err.println("\n\n-net indicates that this is the network part of a network install.");
291 System.err.println("-bindings will only install the menu & key bindings in user/config/soffice.cfg.");
292 //System.err.println("\t[-jedit <path_to_jedit_installation]");
295 public static synchronized boolean isPatchedTypes()
297 return bPatchedTypes;
300 public static synchronized boolean isPatchedJava()
302 return bPatchedJava;
305 public static synchronized boolean isPatchedRDB()
307 return bPatchedRDB;
310 public static synchronized boolean isInstallStarted()
312 return bInstallStarted;
315 public static synchronized void setPatchedTypes(boolean value)
317 bPatchedTypes = value;
320 public static synchronized void setPatchedJava(boolean value)
322 bPatchedJava = value;
325 public static synchronized void setPatchedRDB(boolean value)
327 bPatchedRDB = value;
330 public static synchronized void setInstallStarted(boolean value)
332 bInstallStarted = value;
335 public static synchronized void setTypesPath(String path)
337 typesPath = path;
340 public static synchronized void setJavaPath(String path)
342 javaPath = path;
345 public static synchronized String getTypesPath()
347 return typesPath;
350 public static synchronized String getJavaPath()
352 return javaPath;
355 private javax.swing.JPanel navigation;
356 private javax.swing.JButton navBack;
357 private javax.swing.JButton navNext;
358 private javax.swing.JButton navCancel;
359 private javax.swing.JPanel screens;
361 private Version version = null;
362 private Final _final = null;
363 private IdeVersion ideversion = null;
364 private IdeFinal idefinal = null;
365 private IdeWelcome idewelcome = null;
366 private static ArrayList locations = null;
368 public static String VERSIONS = "VERSIONS";
369 public static String WELCOME = "WELCOME";
370 public static String FINAL = "FINAL";
371 public static String IDEVERSIONS = "IDEVERSIONS";
372 public static String IDEWELCOME = "IDEWELCOME";
373 public static String IDEFINAL = "IDEFINAL";
375 public static int DEFWIDTH = 480;
376 public static int DEFHEIGHT = 240;
378 private static String typesPath = null;
379 private static String javaPath = null;
381 public static boolean bNetworkInstall = false;
382 public static boolean bBindingsInstall = false;
384 private static boolean bPatchedTypes = false;
385 private static boolean bPatchedJava = false;
386 private static boolean bPatchedRDB = false;
387 private static boolean bInstallStarted = false;
389 }// InstallWizard