6 * Created on 04 July 2002, 15:43
15 import java
.awt
.event
.*;
19 import javax
.swing
.event
.*;
20 import javax
.swing
.table
.*;
21 import javax
.swing
.SwingUtilities
.*;
23 public class Version
extends javax
.swing
.JPanel
implements ActionListener
, TableModelListener
{
25 /** Creates new form Welcome */
26 public Version(InstallWizard wizard
) {
28 setBackground(Color
.white
);
32 /** This method is called from within the constructor to
33 * initialize the form.
34 * WARNING: Do NOT modify this code. The content of this method is
35 * always regenerated by the Form Editor.
37 private void initComponents() {
38 Properties props
= null;
39 JPanel versionPanel
= new JPanel();
40 setLayout(new BorderLayout());
42 System
.out
.println("Initialising versions");
44 File fileVersions
= null;
47 fileVersions
= InstUtil
.buildSversionLocation();
49 catch(IOException eFnF
)
51 System
.err
.println("Cannot find sversion.ini/.sversionrc");
52 JOptionPane
.showMessageDialog(this, eFnF
.getMessage(), "File not Found", JOptionPane
.ERROR_MESSAGE
);
53 wizard
.exitForm(null);
57 props
= InstUtil
.getOfficeVersions(fileVersions
);
59 catch (IOException eIO
) {
60 //Message about no installed versions found
61 System
.err
.println("Failed to parse SVERSION");
62 JOptionPane
.showMessageDialog(this, "There was a problem reading from the Office settings file.", "Parse Error", JOptionPane
.ERROR_MESSAGE
);
63 wizard
.exitForm(null);
66 tableModel
= new MyTableModel(props
, versions
);
67 if (tableModel
.getRowCount() == 0)
69 JOptionPane
.showMessageDialog(this, "No compatible versions of Office were found.", "Invalid versions", JOptionPane
.ERROR_MESSAGE
);
70 wizard
.exitForm(null);
73 tableModel
.addTableModelListener(this);
74 JTable tableVersions
= new JTable(tableModel
) {
75 public String
getToolTipText(MouseEvent event
)
77 int col
= columnAtPoint( event
.getPoint() );
81 int row
= rowAtPoint( event
.getPoint() );
82 Object o
= getValueAt(row
, col
);
87 if (o
.toString().equals(""))
93 public Point
getToolTipLocation(MouseEvent event
)
95 int col
= columnAtPoint( event
.getPoint() );
99 int row
= rowAtPoint( event
.getPoint() );
100 Object o
= getValueAt(row
,col
);
105 if (o
.toString().equals(""))
108 Point pt
= getCellRect(row
, col
, true).getLocation();
114 JScrollPane scroll
= new JScrollPane(tableVersions
);
116 tableVersions
.setPreferredSize(
117 new Dimension(InstallWizard
.DEFWIDTH
,InstallWizard
.DEFHEIGHT
));
119 tableVersions
.setRowSelectionAllowed(false);
120 tableVersions
.setColumnSelectionAllowed(false);
121 tableVersions
.setCellSelectionEnabled(false);
123 initColumnSizes(tableVersions
, tableModel
);
124 versionPanel
.add(scroll
);
126 JTextArea area
= new JTextArea("Please select the Office version you wish to Update");
127 area
.setLineWrap(true);
128 area
.setEditable(false);
129 add(area
, BorderLayout
.NORTH
);
130 add(versionPanel
, BorderLayout
.CENTER
);
131 //nav = new NavPanel(wizard, true, false, true, InstallWizard.WELCOME, InstallWizard.FINAL);
132 nav
= new NavPanel(wizard
, true, false, true, InstallWizard
.WELCOME
, InstallWizard
.FINAL
);
133 nav
.setNextListener(this);
134 add(nav
, BorderLayout
.SOUTH
);
138 private void initColumnSizes(JTable table
, MyTableModel model
) {
139 TableColumn column
= null;
140 Component comp
= null;
143 int preferredWidth
= 0;
145 Object
[] longValues
= model
.longValues
;
147 for (int i
= 0; i
< 3; i
++) {
148 column
= table
.getColumnModel().getColumn(i
);
151 comp
= column
.getHeaderRenderer().
152 getTableCellRendererComponent(
153 null, column
.getHeaderValue(),
155 headerWidth
= comp
.getPreferredSize().width
;
156 } catch (NullPointerException e
) {
157 // System.err.println("Null pointer exception!");
158 // System.err.println(" getHeaderRenderer returns null in 1.3.");
159 // System.err.println(" The replacement is getDefaultRenderer.");
162 // need to replace spaces in String before getting preferred width
163 if (longValues
[i
] instanceof String
) {
164 longValues
[i
] = ((String
)longValues
[i
]).replace(' ', '_');
167 System
.out
.println("longValues: " + longValues
[i
]);
168 comp
= table
.getDefaultRenderer(model
.getColumnClass(i
)).
169 getTableCellRendererComponent(
170 table
, longValues
[i
],
172 cellWidth
= comp
.getPreferredSize().width
;
174 preferredWidth
= Math
.max(headerWidth
, cellWidth
);
177 System
.out
.println("Initializing width of column "
179 + "preferredWidth = " + preferredWidth
180 + "; totalWidth = " + totalWidth
181 + "; leftWidth = " + (InstallWizard
.DEFWIDTH
- totalWidth
));
184 //XXX: Before Swing 1.1 Beta 2, use setMinWidth instead.
186 if (preferredWidth
> InstallWizard
.DEFWIDTH
- totalWidth
)
187 column
.setPreferredWidth(InstallWizard
.DEFWIDTH
- totalWidth
);
189 column
.setPreferredWidth(preferredWidth
);
192 column
.setMinWidth(preferredWidth
);
193 totalWidth
+= preferredWidth
;
198 public java
.awt
.Dimension
getPreferredSize() {
199 return new java
.awt
.Dimension(320, 280);
203 public void actionPerformed(ActionEvent ev
) {
204 wizard
.clearLocations();
205 int len
= tableModel
.data
.size();
206 for (int i
= 0; i
< len
; i
++) {
207 ArrayList list
= (ArrayList
)tableModel
.data
.get(i
);
208 if (((Boolean
)list
.get(0)).booleanValue() == true)
209 wizard
.storeLocation((String
)list
.get(2));
212 //System.out.println(wizard.getLocations());
216 public void tableChanged(TableModelEvent e
) {
217 if (tableModel
.isAnySelected()) {
218 nav
.enableNext(true);
221 nav
.enableNext(false);
225 // Variables declaration - do not modify//GEN-BEGIN:variables
226 private javax
.swing
.JTextField jTextField2
;
227 private InstallWizard wizard
;
228 private MyTableModel tableModel
;
229 private NavPanel nav
;
230 //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 //private static final String [] versions = {"OpenOffice.org 643"};
232 //private static final String [] versions = {"OpenOffice.org 643", "StarOffice 6.1"};
233 private static final String
[] versions
= {"StarOffice 6.1", "OpenOffice.org 1.1Beta", "OpenOffice.org 644", "OpenOffice.org 1.1"};
234 // End of variables declaration//GEN-END:variables
238 class MyTableModel
extends AbstractTableModel
{
240 String colNames
[] = {"", "Name", "Location"};
241 Object
[] longValues
= new Object
[] {Boolean
.TRUE
, "Name", "Location"};
243 MyTableModel (Properties properties
, String
[] validVersions
) {
244 data
= new ArrayList();
246 (System
.getProperty("os.name").indexOf("Windows") != -1);
247 int len
= validVersions
.length
;
248 for (Enumeration e
= properties
.propertyNames(); e
.hasMoreElements() ;) {
249 String key
= (String
)e
.nextElement();
252 if ( !( key
.startsWith("#") ) &&
253 ( path
= properties
.getProperty(key
)) != null) {
254 String pkgChkPath
= path
+ File
.separator
+ "program" + File
.separator
;
257 pkgChkPath
+= "pkgchk.exe";
261 pkgChkPath
+= "pkgchk";
263 File pkgChk
= new File( pkgChkPath
);
264 if ( pkgChk
.exists() )
266 ArrayList row
= new ArrayList();
267 row
.add(0, new Boolean(false));
270 if (key
.length() > ((String
)longValues
[1]).length()) {
275 if (path
.length() > ((String
)longValues
[2]).length()) {
276 longValues
[2] = path
;
285 public int getColumnCount() {
289 public int getRowCount() {
293 public String
getColumnName(int col
) {
294 return colNames
[col
];
297 public Object
getValueAt(int row
, int col
) {
298 if (row
< 0 || row
> getRowCount() ||
299 col
< 0 || col
> getColumnCount())
302 ArrayList aRow
= (ArrayList
)data
.get(row
);
303 return aRow
.get(col
);
306 public Class
getColumnClass(int c
) {
307 return getValueAt(0, c
).getClass();
310 public boolean isCellEditable(int row
, int col
) {
318 public void setValueAt(Object value
, int row
, int col
) {
319 ArrayList aRow
= (ArrayList
)data
.get(row
);
320 aRow
.set(col
, value
);
321 fireTableCellUpdated(row
, col
);
324 String
[] getSelected() {
328 public boolean isAnySelected() {
329 Iterator iter
= data
.iterator();
330 while (iter
.hasNext()) {
331 ArrayList row
= (ArrayList
)iter
.next();
332 if (((Boolean
)row
.get(0)).booleanValue() == true) {