1*cdf0e10cSrcweir package installer; 2*cdf0e10cSrcweir 3*cdf0e10cSrcweir /* 4*cdf0e10cSrcweir * Welcome.java 5*cdf0e10cSrcweir * 6*cdf0e10cSrcweir * Created on 04 July 2002, 15:43 7*cdf0e10cSrcweir */ 8*cdf0e10cSrcweir 9*cdf0e10cSrcweir /** 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * @author mike 12*cdf0e10cSrcweir */ 13*cdf0e10cSrcweir 14*cdf0e10cSrcweir import java.awt.*; 15*cdf0e10cSrcweir import java.awt.event.*; 16*cdf0e10cSrcweir import java.io.*; 17*cdf0e10cSrcweir import java.util.*; 18*cdf0e10cSrcweir import javax.swing.*; 19*cdf0e10cSrcweir import javax.swing.event.*; 20*cdf0e10cSrcweir import javax.swing.table.*; 21*cdf0e10cSrcweir import javax.swing.SwingUtilities.*; 22*cdf0e10cSrcweir 23*cdf0e10cSrcweir public class Version extends javax.swing.JPanel implements ActionListener, TableModelListener { 24*cdf0e10cSrcweir 25*cdf0e10cSrcweir /** Creates new form Welcome */ 26*cdf0e10cSrcweir public Version(InstallWizard wizard) { 27*cdf0e10cSrcweir this.wizard=wizard; 28*cdf0e10cSrcweir setBackground(Color.white); 29*cdf0e10cSrcweir initComponents(); 30*cdf0e10cSrcweir } 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir /** This method is called from within the constructor to 33*cdf0e10cSrcweir * initialize the form. 34*cdf0e10cSrcweir * WARNING: Do NOT modify this code. The content of this method is 35*cdf0e10cSrcweir * always regenerated by the Form Editor. 36*cdf0e10cSrcweir */ 37*cdf0e10cSrcweir private void initComponents() { 38*cdf0e10cSrcweir Properties props = null; 39*cdf0e10cSrcweir JPanel versionPanel = new JPanel(); 40*cdf0e10cSrcweir setLayout(new BorderLayout()); 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir System.out.println("Initialising versions"); 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir File fileVersions = null; 45*cdf0e10cSrcweir try 46*cdf0e10cSrcweir { 47*cdf0e10cSrcweir fileVersions = InstUtil.buildSversionLocation(); 48*cdf0e10cSrcweir } 49*cdf0e10cSrcweir catch(IOException eFnF) 50*cdf0e10cSrcweir { 51*cdf0e10cSrcweir System.err.println("Cannot find sversion.ini/.sversionrc"); 52*cdf0e10cSrcweir JOptionPane.showMessageDialog(this, eFnF.getMessage(), "File not Found", JOptionPane.ERROR_MESSAGE); 53*cdf0e10cSrcweir wizard.exitForm(null); 54*cdf0e10cSrcweir } 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir try { 57*cdf0e10cSrcweir props = InstUtil.getOfficeVersions(fileVersions); 58*cdf0e10cSrcweir } 59*cdf0e10cSrcweir catch (IOException eIO) { 60*cdf0e10cSrcweir //Message about no installed versions found 61*cdf0e10cSrcweir System.err.println("Failed to parse SVERSION"); 62*cdf0e10cSrcweir JOptionPane.showMessageDialog(this, "There was a problem reading from the Office settings file.", "Parse Error", JOptionPane.ERROR_MESSAGE); 63*cdf0e10cSrcweir wizard.exitForm(null); 64*cdf0e10cSrcweir } 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir tableModel = new MyTableModel(props, versions); 67*cdf0e10cSrcweir if (tableModel.getRowCount() == 0) 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir JOptionPane.showMessageDialog(this, "No compatible versions of Office were found.", "Invalid versions", JOptionPane.ERROR_MESSAGE); 70*cdf0e10cSrcweir wizard.exitForm(null); 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir tableModel.addTableModelListener(this); 74*cdf0e10cSrcweir JTable tableVersions = new JTable(tableModel) { 75*cdf0e10cSrcweir public String getToolTipText(MouseEvent event) 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir int col = columnAtPoint( event.getPoint() ); 78*cdf0e10cSrcweir if (col != 2) 79*cdf0e10cSrcweir return null; 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir int row = rowAtPoint( event.getPoint() ); 82*cdf0e10cSrcweir Object o = getValueAt(row, col); 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir if (o == null) 85*cdf0e10cSrcweir return null; 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir if (o.toString().equals("")) 88*cdf0e10cSrcweir return null; 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir return o.toString(); 91*cdf0e10cSrcweir } 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir public Point getToolTipLocation(MouseEvent event) 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir int col = columnAtPoint( event.getPoint() ); 96*cdf0e10cSrcweir if (col != 2) 97*cdf0e10cSrcweir return null; 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir int row = rowAtPoint( event.getPoint() ); 100*cdf0e10cSrcweir Object o = getValueAt(row,col); 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir if (o == null) 103*cdf0e10cSrcweir return null; 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir if (o.toString().equals("")) 106*cdf0e10cSrcweir return null; 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir Point pt = getCellRect(row, col, true).getLocation(); 109*cdf0e10cSrcweir pt.translate(-1,-2); 110*cdf0e10cSrcweir return pt; 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir }; 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir JScrollPane scroll = new JScrollPane(tableVersions); 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir tableVersions.setPreferredSize( 117*cdf0e10cSrcweir new Dimension(InstallWizard.DEFWIDTH,InstallWizard.DEFHEIGHT)); 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir tableVersions.setRowSelectionAllowed(false); 120*cdf0e10cSrcweir tableVersions.setColumnSelectionAllowed(false); 121*cdf0e10cSrcweir tableVersions.setCellSelectionEnabled(false); 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir initColumnSizes(tableVersions, tableModel); 124*cdf0e10cSrcweir versionPanel.add(scroll); 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir JTextArea area = new JTextArea("Please select the Office version you wish to Update"); 127*cdf0e10cSrcweir area.setLineWrap(true); 128*cdf0e10cSrcweir area.setEditable(false); 129*cdf0e10cSrcweir add(area, BorderLayout.NORTH); 130*cdf0e10cSrcweir add(versionPanel, BorderLayout.CENTER); 131*cdf0e10cSrcweir //nav = new NavPanel(wizard, true, false, true, InstallWizard.WELCOME, InstallWizard.FINAL); 132*cdf0e10cSrcweir nav = new NavPanel(wizard, true, false, true, InstallWizard.WELCOME, InstallWizard.FINAL); 133*cdf0e10cSrcweir nav.setNextListener(this); 134*cdf0e10cSrcweir add(nav, BorderLayout.SOUTH); 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir }// initComponents 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir private void initColumnSizes(JTable table, MyTableModel model) { 139*cdf0e10cSrcweir TableColumn column = null; 140*cdf0e10cSrcweir Component comp = null; 141*cdf0e10cSrcweir int headerWidth = 0; 142*cdf0e10cSrcweir int cellWidth = 0; 143*cdf0e10cSrcweir int preferredWidth = 0; 144*cdf0e10cSrcweir int totalWidth = 0; 145*cdf0e10cSrcweir Object[] longValues = model.longValues; 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir for (int i = 0; i < 3; i++) { 148*cdf0e10cSrcweir column = table.getColumnModel().getColumn(i); 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir try { 151*cdf0e10cSrcweir comp = column.getHeaderRenderer(). 152*cdf0e10cSrcweir getTableCellRendererComponent( 153*cdf0e10cSrcweir null, column.getHeaderValue(), 154*cdf0e10cSrcweir false, false, 0, 0); 155*cdf0e10cSrcweir headerWidth = comp.getPreferredSize().width; 156*cdf0e10cSrcweir } catch (NullPointerException e) { 157*cdf0e10cSrcweir // System.err.println("Null pointer exception!"); 158*cdf0e10cSrcweir // System.err.println(" getHeaderRenderer returns null in 1.3."); 159*cdf0e10cSrcweir // System.err.println(" The replacement is getDefaultRenderer."); 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir // need to replace spaces in String before getting preferred width 163*cdf0e10cSrcweir if (longValues[i] instanceof String) { 164*cdf0e10cSrcweir longValues[i] = ((String)longValues[i]).replace(' ', '_'); 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir System.out.println("longValues: " + longValues[i]); 168*cdf0e10cSrcweir comp = table.getDefaultRenderer(model.getColumnClass(i)). 169*cdf0e10cSrcweir getTableCellRendererComponent( 170*cdf0e10cSrcweir table, longValues[i], 171*cdf0e10cSrcweir false, false, 0, i); 172*cdf0e10cSrcweir cellWidth = comp.getPreferredSize().width; 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir preferredWidth = Math.max(headerWidth, cellWidth); 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir if (false) { 177*cdf0e10cSrcweir System.out.println("Initializing width of column " 178*cdf0e10cSrcweir + i + ". " 179*cdf0e10cSrcweir + "preferredWidth = " + preferredWidth 180*cdf0e10cSrcweir + "; totalWidth = " + totalWidth 181*cdf0e10cSrcweir + "; leftWidth = " + (InstallWizard.DEFWIDTH - totalWidth)); 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir //XXX: Before Swing 1.1 Beta 2, use setMinWidth instead. 185*cdf0e10cSrcweir if (i == 2) { 186*cdf0e10cSrcweir if (preferredWidth > InstallWizard.DEFWIDTH - totalWidth) 187*cdf0e10cSrcweir column.setPreferredWidth(InstallWizard.DEFWIDTH - totalWidth); 188*cdf0e10cSrcweir else 189*cdf0e10cSrcweir column.setPreferredWidth(preferredWidth); 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir else { 192*cdf0e10cSrcweir column.setMinWidth(preferredWidth); 193*cdf0e10cSrcweir totalWidth += preferredWidth; 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir } 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir public java.awt.Dimension getPreferredSize() { 199*cdf0e10cSrcweir return new java.awt.Dimension(320, 280); 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir public void actionPerformed(ActionEvent ev) { 204*cdf0e10cSrcweir wizard.clearLocations(); 205*cdf0e10cSrcweir int len = tableModel.data.size(); 206*cdf0e10cSrcweir for (int i = 0; i < len; i++) { 207*cdf0e10cSrcweir ArrayList list = (ArrayList)tableModel.data.get(i); 208*cdf0e10cSrcweir if (((Boolean)list.get(0)).booleanValue() == true) 209*cdf0e10cSrcweir wizard.storeLocation((String)list.get(2)); 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir //System.out.println(wizard.getLocations()); 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir public void tableChanged(TableModelEvent e) { 217*cdf0e10cSrcweir if (tableModel.isAnySelected()) { 218*cdf0e10cSrcweir nav.enableNext(true); 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir else { 221*cdf0e10cSrcweir nav.enableNext(false); 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir // Variables declaration - do not modify//GEN-BEGIN:variables 226*cdf0e10cSrcweir private javax.swing.JTextField jTextField2; 227*cdf0e10cSrcweir private InstallWizard wizard; 228*cdf0e10cSrcweir private MyTableModel tableModel; 229*cdf0e10cSrcweir private NavPanel nav; 230*cdf0e10cSrcweir //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"}; 231*cdf0e10cSrcweir //private static final String [] versions = {"OpenOffice.org 643"}; 232*cdf0e10cSrcweir //private static final String [] versions = {"OpenOffice.org 643", "StarOffice 6.1"}; 233*cdf0e10cSrcweir private static final String [] versions = {"StarOffice 6.1", "OpenOffice.org 1.1Beta", "OpenOffice.org 644", "OpenOffice.org 1.1"}; 234*cdf0e10cSrcweir // End of variables declaration//GEN-END:variables 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir class MyTableModel extends AbstractTableModel { 239*cdf0e10cSrcweir ArrayList data; 240*cdf0e10cSrcweir String colNames[] = {"", "Name", "Location"}; 241*cdf0e10cSrcweir Object[] longValues = new Object[] {Boolean.TRUE, "Name", "Location"}; 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir MyTableModel (Properties properties, String [] validVersions) { 244*cdf0e10cSrcweir data = new ArrayList(); 245*cdf0e10cSrcweir boolean isWindows = 246*cdf0e10cSrcweir (System.getProperty("os.name").indexOf("Windows") != -1); 247*cdf0e10cSrcweir int len = validVersions.length; 248*cdf0e10cSrcweir for (Enumeration e = properties.propertyNames(); e.hasMoreElements() ;) { 249*cdf0e10cSrcweir String key = (String)e.nextElement(); 250*cdf0e10cSrcweir String path = null; 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir if ( !( key.startsWith("#") ) && 253*cdf0e10cSrcweir ( path = properties.getProperty(key)) != null) { 254*cdf0e10cSrcweir String pkgChkPath = path + File.separator + "program" + File.separator; 255*cdf0e10cSrcweir if ( isWindows ) 256*cdf0e10cSrcweir { 257*cdf0e10cSrcweir pkgChkPath += "pkgchk.exe"; 258*cdf0e10cSrcweir } 259*cdf0e10cSrcweir else 260*cdf0e10cSrcweir { 261*cdf0e10cSrcweir pkgChkPath += "pkgchk"; 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir File pkgChk = new File( pkgChkPath ); 264*cdf0e10cSrcweir if ( pkgChk.exists() ) 265*cdf0e10cSrcweir { 266*cdf0e10cSrcweir ArrayList row = new ArrayList(); 267*cdf0e10cSrcweir row.add(0, new Boolean(false)); 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir row.add(1, key); 270*cdf0e10cSrcweir if (key.length() > ((String)longValues[1]).length()) { 271*cdf0e10cSrcweir longValues[1] = key; 272*cdf0e10cSrcweir } 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir row.add(2, path); 275*cdf0e10cSrcweir if (path.length() > ((String)longValues[2]).length()) { 276*cdf0e10cSrcweir longValues[2] = path; 277*cdf0e10cSrcweir } 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir data.add(row); 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir } 283*cdf0e10cSrcweir }// MyTableModel 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir public int getColumnCount() { 286*cdf0e10cSrcweir return 3; 287*cdf0e10cSrcweir } 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir public int getRowCount() { 290*cdf0e10cSrcweir return data.size(); 291*cdf0e10cSrcweir } 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir public String getColumnName(int col) { 294*cdf0e10cSrcweir return colNames[col]; 295*cdf0e10cSrcweir } 296*cdf0e10cSrcweir 297*cdf0e10cSrcweir public Object getValueAt(int row, int col) { 298*cdf0e10cSrcweir if (row < 0 || row > getRowCount() || 299*cdf0e10cSrcweir col < 0 || col > getColumnCount()) 300*cdf0e10cSrcweir return null; 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir ArrayList aRow = (ArrayList)data.get(row); 303*cdf0e10cSrcweir return aRow.get(col); 304*cdf0e10cSrcweir } 305*cdf0e10cSrcweir 306*cdf0e10cSrcweir public Class getColumnClass(int c) { 307*cdf0e10cSrcweir return getValueAt(0, c).getClass(); 308*cdf0e10cSrcweir } 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir public boolean isCellEditable(int row, int col) { 311*cdf0e10cSrcweir if (col == 0) { 312*cdf0e10cSrcweir return true; 313*cdf0e10cSrcweir } else { 314*cdf0e10cSrcweir return false; 315*cdf0e10cSrcweir } 316*cdf0e10cSrcweir } 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir public void setValueAt(Object value, int row, int col) { 319*cdf0e10cSrcweir ArrayList aRow = (ArrayList)data.get(row); 320*cdf0e10cSrcweir aRow.set(col, value); 321*cdf0e10cSrcweir fireTableCellUpdated(row, col); 322*cdf0e10cSrcweir } 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir String [] getSelected() { 325*cdf0e10cSrcweir return null; 326*cdf0e10cSrcweir } 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir public boolean isAnySelected() { 329*cdf0e10cSrcweir Iterator iter = data.iterator(); 330*cdf0e10cSrcweir while (iter.hasNext()) { 331*cdf0e10cSrcweir ArrayList row = (ArrayList)iter.next(); 332*cdf0e10cSrcweir if (((Boolean)row.get(0)).booleanValue() == true) { 333*cdf0e10cSrcweir return true; 334*cdf0e10cSrcweir } 335*cdf0e10cSrcweir } 336*cdf0e10cSrcweir return false; 337*cdf0e10cSrcweir } 338*cdf0e10cSrcweir 339*cdf0e10cSrcweir } 340