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