1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
|
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) {
public String getToolTipText(MouseEvent event)
{
int col = columnAtPoint( event.getPoint() );
if (col != 2)
return null;
int row = rowAtPoint( event.getPoint() );
Object o = getValueAt(row, col);
if (o == null)
return null;
if (o.toString().equals(""))
return null;
return o.toString();
}
public Point getToolTipLocation(MouseEvent event)
{
int col = columnAtPoint( event.getPoint() );
if (col != 2)
return null;
int row = rowAtPoint( event.getPoint() );
Object o = getValueAt(row,col);
if (o == null)
return null;
if (o.toString().equals(""))
return null;
Point pt = getCellRect(row, col, true).getLocation();
pt.translate(-1,-2);
return pt;
}
};
JScrollPane scroll = new JScrollPane(tableVersions);
tableVersions.setPreferredSize(
new Dimension(InstallWizard.DEFWIDTH,InstallWizard.DEFHEIGHT));
tableVersions.setRowSelectionAllowed(false);
tableVersions.setColumnSelectionAllowed(false);
tableVersions.setCellSelectionEnabled(false);
initColumnSizes(tableVersions, tableModel);
versionPanel.add(scroll);
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
private void initColumnSizes(JTable table, MyTableModel model) {
TableColumn column = null;
Component comp = null;
int headerWidth = 0;
int cellWidth = 0;
int preferredWidth = 0;
int totalWidth = 0;
Object[] longValues = model.longValues;
for (int i = 0; i < 3; i++) {
column = table.getColumnModel().getColumn(i);
try {
comp = column.getHeaderRenderer().
getTableCellRendererComponent(
null, column.getHeaderValue(),
false, false, 0, 0);
headerWidth = comp.getPreferredSize().width;
} catch (NullPointerException e) {
// System.err.println("Null pointer exception!");
// System.err.println(" getHeaderRenderer returns null in 1.3.");
// System.err.println(" The replacement is getDefaultRenderer.");
}
// need to replace spaces in String before getting preferred width
if (longValues[i] instanceof String) {
longValues[i] = ((String)longValues[i]).replace(' ', '_');
}
System.out.println("longValues: " + longValues[i]);
comp = table.getDefaultRenderer(model.getColumnClass(i)).
getTableCellRendererComponent(
table, longValues[i],
false, false, 0, i);
cellWidth = comp.getPreferredSize().width;
preferredWidth = Math.max(headerWidth, cellWidth);
if (false) {
System.out.println("Initializing width of column "
+ i + ". "
+ "preferredWidth = " + preferredWidth
+ "; totalWidth = " + totalWidth
+ "; leftWidth = " + (InstallWizard.DEFWIDTH - totalWidth));
}
//XXX: Before Swing 1.1 Beta 2, use setMinWidth instead.
if (i == 2) {
if (preferredWidth > InstallWizard.DEFWIDTH - totalWidth)
column.setPreferredWidth(InstallWizard.DEFWIDTH - totalWidth);
else
column.setPreferredWidth(preferredWidth);
}
else {
column.setMinWidth(preferredWidth);
totalWidth += preferredWidth;
}
}
}
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"};
private static final String [] versions = {"StarOffice 6.1", "OpenOffice.org 1.1Beta", "OpenOffice.org 644", "OpenOffice.org 1.1"};
// End of variables declaration//GEN-END:variables
}
class MyTableModel extends AbstractTableModel {
ArrayList data;
String colNames[] = {"", "Name", "Location"};
Object[] longValues = new Object[] {Boolean.TRUE, "Name", "Location"};
MyTableModel (Properties properties, String [] validVersions) {
data = new ArrayList();
boolean isWindows =
(System.getProperty("os.name").indexOf("Windows") != -1);
int len = validVersions.length;
for (Enumeration e = properties.propertyNames(); e.hasMoreElements() ;) {
String key = (String)e.nextElement();
String path = null;
if ( !( key.startsWith("#") ) &&
( path = properties.getProperty(key)) != null) {
String pkgChkPath = path + File.separator + "program" + File.separator;
if ( isWindows )
{
pkgChkPath += "pkgchk.exe";
}
else
{
pkgChkPath += "pkgchk";
}
File pkgChk = new File( pkgChkPath );
if ( pkgChk.exists() )
{
ArrayList row = new ArrayList();
row.add(0, new Boolean(false));
row.add(1, key);
if (key.length() > ((String)longValues[1]).length()) {
longValues[1] = key;
}
row.add(2, path);
if (path.length() > ((String)longValues[2]).length()) {
longValues[2] = path;
}
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) {
if (row < 0 || row > getRowCount() ||
col < 0 || col > getColumnCount())
return null;
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;
}
}
|