Files
loongoffice/scripting/workben/installer/Version.java

208 lines
6.3 KiB
Java

package installer;
/*
* Welcome.java
*
* Created on 04 July 2002, 15:43
*/
/**
*
* @author mike
*/
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import javax.swing.SwingUtilities.*;
public class Version extends javax.swing.JPanel implements ActionListener, TableModelListener {
/** Creates new form Welcome */
public Version(InstallWizard wizard) {
this.wizard=wizard;
setBackground(Color.white);
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {
Properties props = null;
JPanel versionPanel = new JPanel();
setLayout(new BorderLayout());
System.out.println("Initialising versions");
File fileVersions = null;
try
{
fileVersions = InstUtil.buildSversionLocation();
}
catch(IOException eFnF)
{
System.err.println("Cannot find sversion.ini/.sversionrc");
JOptionPane.showMessageDialog(this, eFnF.getMessage(), "File not Found", JOptionPane.ERROR_MESSAGE);
wizard.exitForm(null);
}
try {
props = InstUtil.getOfficeVersions(fileVersions);
}
catch (IOException eIO) {
//Message about no installed versions found
System.err.println("Failed to parse SVERSION");
JOptionPane.showMessageDialog(this, "There was a problem reading from the Office settings file.", "Parse Error", JOptionPane.ERROR_MESSAGE);
wizard.exitForm(null);
}
tableModel = new MyTableModel(props, versions);
if (tableModel.getRowCount() == 0)
{
JOptionPane.showMessageDialog(this, "No compatible versions of Office were found.", "Invalid versions", JOptionPane.ERROR_MESSAGE);
wizard.exitForm(null);
}
tableModel.addTableModelListener(this);
JTable tableVersions = new JTable(tableModel);
tableVersions.setPreferredSize(new Dimension(InstallWizard.DEFWIDTH,InstallWizard.DEFHEIGHT));
tableVersions.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
tableVersions.doLayout();
setBorder(new javax.swing.border.EtchedBorder(javax.swing.border.EtchedBorder.RAISED));
//JScrollPane scroll = new JScrollPane(tableVersions);
//versionPanel.add(scroll);
versionPanel.add(tableVersions);
JTextArea area = new JTextArea("Please select the Office version you wish to Update");
area.setLineWrap(true);
area.setEditable(false);
add(area, BorderLayout.NORTH);
add(versionPanel, BorderLayout.CENTER);
//nav = new NavPanel(wizard, true, false, true, InstallWizard.WELCOME, InstallWizard.FINAL);
nav = new NavPanel(wizard, true, false, true, InstallWizard.WELCOME, InstallWizard.FINAL);
nav.setNextListener(this);
add(nav, BorderLayout.SOUTH);
}// initComponents
public java.awt.Dimension getPreferredSize() {
return new java.awt.Dimension(320, 280);
}
public void actionPerformed(ActionEvent ev) {
wizard.clearLocations();
int len = tableModel.data.size();
for (int i = 0; i < len; i++) {
ArrayList list = (ArrayList)tableModel.data.get(i);
if (((Boolean)list.get(0)).booleanValue() == true)
wizard.storeLocation((String)list.get(2));
}
//System.out.println(wizard.getLocations());
}
public void tableChanged(TableModelEvent e) {
if (tableModel.isAnySelected()) {
nav.enableNext(true);
}
else {
nav.enableNext(false);
}
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextField jTextField2;
private InstallWizard wizard;
private MyTableModel tableModel;
private NavPanel nav;
//private static final String [] versions = {"StarOffice 6.0", "OpenOffice.org 1.0","OpenOffice.org 1.0.1","OpenOffice.org 642","OpenOffice.org 643","StarOffice 6.1"};
//private static final String [] versions = {"OpenOffice.org 643"};
private static final String [] versions = {"OpenOffice.org 643", "StarOffice 6.1"};
// End of variables declaration//GEN-END:variables
}
class MyTableModel extends AbstractTableModel {
ArrayList data;
String colNames[] = {"Install", "Name", "Location"};
MyTableModel(Properties properties, String [] validVersions) {
data = new ArrayList();
//System.out.println(properties);
int len = validVersions.length;
for (int i = 0; i < len; i++) {
String key = validVersions[i];
String path = null;
if ((path = properties.getProperty(key)) != null) {
ArrayList row = new ArrayList();
row.add(0, new Boolean(false));
row.add(1, key);
row.add(2, properties.getProperty(key));
data.add(row);
}
}
}// MyTableModel
public int getColumnCount() {
return 3;
}
public int getRowCount() {
return data.size();
}
public String getColumnName(int col) {
return colNames[col];
}
public Object getValueAt(int row, int col) {
ArrayList aRow = (ArrayList)data.get(row);
return aRow.get(col);
}
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
public boolean isCellEditable(int row, int col) {
if (col == 0) {
return true;
} else {
return false;
}
}
public void setValueAt(Object value, int row, int col) {
ArrayList aRow = (ArrayList)data.get(row);
aRow.set(col, value);
fireTableCellUpdated(row, col);
}
String [] getSelected() {
return null;
}
public boolean isAnySelected() {
Iterator iter = data.iterator();
while (iter.hasNext()) {
ArrayList row = (ArrayList)iter.next();
if (((Boolean)row.get(0)).booleanValue() == true) {
return true;
}
}
return false;
}
}