update dev300-m58
[ooovba.git] / scripting / workben / installer / Version.java
blobb872acef5b7e6c6e96f13d060d2505cfbeef3827
1 package installer;
3 /*
4 * Welcome.java
6 * Created on 04 July 2002, 15:43
7 */
9 /**
11 * @author mike
14 import java.awt.*;
15 import java.awt.event.*;
16 import java.io.*;
17 import java.util.*;
18 import javax.swing.*;
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) {
27 this.wizard=wizard;
28 setBackground(Color.white);
29 initComponents();
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;
45 try
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);
56 try {
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() );
78 if (col != 2)
79 return null;
81 int row = rowAtPoint( event.getPoint() );
82 Object o = getValueAt(row, col);
84 if (o == null)
85 return null;
87 if (o.toString().equals(""))
88 return null;
90 return o.toString();
93 public Point getToolTipLocation(MouseEvent event)
95 int col = columnAtPoint( event.getPoint() );
96 if (col != 2)
97 return null;
99 int row = rowAtPoint( event.getPoint() );
100 Object o = getValueAt(row,col);
102 if (o == null)
103 return null;
105 if (o.toString().equals(""))
106 return null;
108 Point pt = getCellRect(row, col, true).getLocation();
109 pt.translate(-1,-2);
110 return pt;
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);
136 }// initComponents
138 private void initColumnSizes(JTable table, MyTableModel model) {
139 TableColumn column = null;
140 Component comp = null;
141 int headerWidth = 0;
142 int cellWidth = 0;
143 int preferredWidth = 0;
144 int totalWidth = 0;
145 Object[] longValues = model.longValues;
147 for (int i = 0; i < 3; i++) {
148 column = table.getColumnModel().getColumn(i);
150 try {
151 comp = column.getHeaderRenderer().
152 getTableCellRendererComponent(
153 null, column.getHeaderValue(),
154 false, false, 0, 0);
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],
171 false, false, 0, i);
172 cellWidth = comp.getPreferredSize().width;
174 preferredWidth = Math.max(headerWidth, cellWidth);
176 if (false) {
177 System.out.println("Initializing width of column "
178 + i + ". "
179 + "preferredWidth = " + preferredWidth
180 + "; totalWidth = " + totalWidth
181 + "; leftWidth = " + (InstallWizard.DEFWIDTH - totalWidth));
184 //XXX: Before Swing 1.1 Beta 2, use setMinWidth instead.
185 if (i == 2) {
186 if (preferredWidth > InstallWizard.DEFWIDTH - totalWidth)
187 column.setPreferredWidth(InstallWizard.DEFWIDTH - totalWidth);
188 else
189 column.setPreferredWidth(preferredWidth);
191 else {
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);
220 else {
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 {
239 ArrayList data;
240 String colNames[] = {"", "Name", "Location"};
241 Object[] longValues = new Object[] {Boolean.TRUE, "Name", "Location"};
243 MyTableModel (Properties properties, String [] validVersions) {
244 data = new ArrayList();
245 boolean isWindows =
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();
250 String path = null;
252 if ( !( key.startsWith("#") ) &&
253 ( path = properties.getProperty(key)) != null) {
254 String pkgChkPath = path + File.separator + "program" + File.separator;
255 if ( isWindows )
257 pkgChkPath += "pkgchk.exe";
259 else
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));
269 row.add(1, key);
270 if (key.length() > ((String)longValues[1]).length()) {
271 longValues[1] = key;
274 row.add(2, path);
275 if (path.length() > ((String)longValues[2]).length()) {
276 longValues[2] = path;
279 data.add(row);
283 }// MyTableModel
285 public int getColumnCount() {
286 return 3;
289 public int getRowCount() {
290 return data.size();
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())
300 return null;
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) {
311 if (col == 0) {
312 return true;
313 } else {
314 return false;
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() {
325 return null;
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) {
333 return true;
336 return false;