1*cd519653SAndrew Rist /**************************************************************
2*cd519653SAndrew Rist  *
3*cd519653SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*cd519653SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*cd519653SAndrew Rist  * distributed with this work for additional information
6*cd519653SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*cd519653SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*cd519653SAndrew Rist  * "License"); you may not use this file except in compliance
9*cd519653SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*cd519653SAndrew Rist  *
11*cd519653SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*cd519653SAndrew Rist  *
13*cd519653SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*cd519653SAndrew Rist  * software distributed under the License is distributed on an
15*cd519653SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*cd519653SAndrew Rist  * KIND, either express or implied.  See the License for the
17*cd519653SAndrew Rist  * specific language governing permissions and limitations
18*cd519653SAndrew Rist  * under the License.
19*cd519653SAndrew Rist  *
20*cd519653SAndrew Rist  *************************************************************/
21*cd519653SAndrew Rist 
22cdf0e10cSrcweir package installer;
23cdf0e10cSrcweir 
24cdf0e10cSrcweir /*
25cdf0e10cSrcweir  * Welcome.java
26cdf0e10cSrcweir  *
27cdf0e10cSrcweir  * Created on 04 July 2002, 15:43
28cdf0e10cSrcweir  */
29cdf0e10cSrcweir 
30cdf0e10cSrcweir /**
31cdf0e10cSrcweir  *
32cdf0e10cSrcweir  * @author  mike
33cdf0e10cSrcweir  */
34cdf0e10cSrcweir import java.awt.event.*;
35cdf0e10cSrcweir import javax.swing.*;
36cdf0e10cSrcweir import java.io.*;
37cdf0e10cSrcweir import java.net.*;
38cdf0e10cSrcweir import java.util.Properties;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir public class Welcome extends javax.swing.JPanel implements ActionListener {
41cdf0e10cSrcweir 
42cdf0e10cSrcweir     /** Creates new form Welcome */
Welcome(InstallWizard wizard)43cdf0e10cSrcweir     public Welcome(InstallWizard wizard) {
44cdf0e10cSrcweir 	this.wizard = wizard;
45cdf0e10cSrcweir 	setBorder(new javax.swing.border.EtchedBorder(javax.swing.border.EtchedBorder.RAISED));
46cdf0e10cSrcweir         initComponents();
47cdf0e10cSrcweir     }
48cdf0e10cSrcweir 
49cdf0e10cSrcweir     /** This method is called from within the constructor to
50cdf0e10cSrcweir      * initialize the form.
51cdf0e10cSrcweir      * WARNING: Do NOT modify this code. The content of this method is
52cdf0e10cSrcweir      * always regenerated by the Form Editor.
53cdf0e10cSrcweir      */
initComponents()54cdf0e10cSrcweir     private void initComponents() {//GEN-BEGIN:initComponents
55cdf0e10cSrcweir         welcomePanel = new javax.swing.JPanel();
56cdf0e10cSrcweir         area = new javax.swing.JTextArea();
57cdf0e10cSrcweir 	nextButtonEnable = true;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir         setLayout(new java.awt.BorderLayout());
60cdf0e10cSrcweir 
61cdf0e10cSrcweir         welcomePanel.setLayout(new java.awt.BorderLayout());
62cdf0e10cSrcweir         area.setEditable(false);
63cdf0e10cSrcweir         area.setLineWrap(true);
64cdf0e10cSrcweir 
65cdf0e10cSrcweir         String message = "\n\tOffice Scripting Framework Version 0.3" +
66cdf0e10cSrcweir             "\n\n\n\tPlease ensure that you have exited from Office";
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 	/* String userDir = (String) System.getProperty( "user.dir" );
69cdf0e10cSrcweir 	boolean isValid = validateCurrentUserDir(userDir);
70cdf0e10cSrcweir 	if( !isValid ) {
71cdf0e10cSrcweir 		nextButtonEnable = false;
72cdf0e10cSrcweir 		message = "Please run Installer from the program directory in a valid Office installation";
73cdf0e10cSrcweir 		setUpWelcomePanel(message);
74cdf0e10cSrcweir 		return;
75cdf0e10cSrcweir 	}
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 	int programPosition = userDir.lastIndexOf("program");
78cdf0e10cSrcweir 	String offInstallPth = null;
79cdf0e10cSrcweir 	offInstallPth = userDir.substring( 0, programPosition );
80cdf0e10cSrcweir 
81cdf0e10cSrcweir         wizard.storeLocation(offInstallPth); */
82cdf0e10cSrcweir 	setUpWelcomePanel(message);
83cdf0e10cSrcweir 
84cdf0e10cSrcweir     }//GEN-END:initComponents
85cdf0e10cSrcweir 
setUpWelcomePanel(String message)86cdf0e10cSrcweir     private void setUpWelcomePanel(String message){
87cdf0e10cSrcweir 	area.setText( message );
88cdf0e10cSrcweir         welcomePanel.add(area, java.awt.BorderLayout.CENTER);
89cdf0e10cSrcweir         add(welcomePanel, java.awt.BorderLayout.CENTER);
90cdf0e10cSrcweir 	NavPanel nav = new NavPanel(wizard, false, nextButtonEnable, true, "", InstallWizard.VERSIONS);
91cdf0e10cSrcweir 	nav.setNextListener(this);
92cdf0e10cSrcweir 	add(nav, java.awt.BorderLayout.SOUTH);
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 	//Banner br = new Banner();
95cdf0e10cSrcweir 	//add(br, java.awt.BorderLayout.WEST);
96cdf0e10cSrcweir     }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 
validateCurrentUserDir(String userDir)99cdf0e10cSrcweir     private boolean validateCurrentUserDir(String userDir){
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 	Properties props = null;
104cdf0e10cSrcweir 
105cdf0e10cSrcweir         File fileVersions = null;
106cdf0e10cSrcweir 	try
107cdf0e10cSrcweir 	{
108cdf0e10cSrcweir             fileVersions = InstUtil.buildSversionLocation();
109cdf0e10cSrcweir 	}
110cdf0e10cSrcweir 	catch(IOException eFnF)
111cdf0e10cSrcweir 	{
112cdf0e10cSrcweir             System.err.println("Cannot find sversion.ini/.sversionrc");
113cdf0e10cSrcweir             JOptionPane.showMessageDialog(this, eFnF.getMessage(), "File not Found", JOptionPane.ERROR_MESSAGE);
114cdf0e10cSrcweir             wizard.exitForm(null);
115cdf0e10cSrcweir 	}
116cdf0e10cSrcweir 
117cdf0e10cSrcweir         try {
118cdf0e10cSrcweir             props = InstUtil.getOfficeVersions(fileVersions);
119cdf0e10cSrcweir         }
120cdf0e10cSrcweir         catch (IOException eIO) {
121cdf0e10cSrcweir             //Message about no installed versions found
122cdf0e10cSrcweir             System.err.println("Failed to parse SVERSION");
123cdf0e10cSrcweir 			JOptionPane.showMessageDialog(this, "There was a problem reading from the Office settings file.", "Parse Error", JOptionPane.ERROR_MESSAGE);
124cdf0e10cSrcweir 			wizard.exitForm(null);
125cdf0e10cSrcweir         }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 	boolean versionMatch = false;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 	for( int i = 0; i < versions.length; i++ ) {
131cdf0e10cSrcweir 		String key = versions[i];
132cdf0e10cSrcweir 		String progPath = ( String )props.getProperty( key );
133cdf0e10cSrcweir 		if ( progPath != null ){
134cdf0e10cSrcweir 			progPath = progPath  + File.separator + "program";
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 			File tmpFile = new File(progPath + File.separator + "oostubversion.txt");
137cdf0e10cSrcweir 			try{
138cdf0e10cSrcweir 			tmpFile.createNewFile();
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 				if( new File(userDir + File.separator + "oostubversion.txt").exists())
141cdf0e10cSrcweir 				{
142cdf0e10cSrcweir 					versionMatch = true;
143cdf0e10cSrcweir 					break;
144cdf0e10cSrcweir 				}
145cdf0e10cSrcweir 			}
146cdf0e10cSrcweir 			catch( IOException e)
147cdf0e10cSrcweir 			{
148cdf0e10cSrcweir 				// Fail silently
149cdf0e10cSrcweir 			}
150cdf0e10cSrcweir 			tmpFile.delete();
151cdf0e10cSrcweir 		}
152cdf0e10cSrcweir 	}
153cdf0e10cSrcweir 	return versionMatch;
154cdf0e10cSrcweir     }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 
getPreferredSize()158cdf0e10cSrcweir     public java.awt.Dimension getPreferredSize() {
159cdf0e10cSrcweir         return new java.awt.Dimension(InstallWizard.DEFWIDTH, InstallWizard.DEFHEIGHT);
160cdf0e10cSrcweir     }
161cdf0e10cSrcweir 
actionPerformed(ActionEvent ev)162cdf0e10cSrcweir 	public void actionPerformed(ActionEvent ev)
163cdf0e10cSrcweir 	{
164cdf0e10cSrcweir 		//Perform next actions here...
165cdf0e10cSrcweir 	}
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     // Variables declaration - do not modify//GEN-BEGIN:variables
169cdf0e10cSrcweir     private javax.swing.JPanel welcomePanel;
170cdf0e10cSrcweir     private javax.swing.JTextArea area;
171cdf0e10cSrcweir     private InstallWizard wizard;
172cdf0e10cSrcweir     //private static final String [] versions = {"OpenOffice.org 643", "StarOffice 6.1"};
173cdf0e10cSrcweir     private static final String [] versions = { "StarOffice 6.1" };
174cdf0e10cSrcweir     private boolean nextButtonEnable = true;
175cdf0e10cSrcweir 
176cdf0e10cSrcweir     // End of variables declaration//GEN-END:variables
177cdf0e10cSrcweir }
178