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