update dev300-m58
[ooovba.git] / scripting / workben / installer / IdeVersion.java
blob17a5a7d013f5e333e1b1eb70e7877b89ea7b20a9
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 IdeVersion extends javax.swing.JPanel implements ActionListener, TableModelListener {
25 /** Creates new form Welcome */
26 public IdeVersion(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());
43 try {
44 //props = InstUtil.getNetbeansLocation();
46 Properties netbeansProps = InstUtil.getNetbeansLocation();
47 //Properties jeditProps = InstUtil.getJeditLocation();
48 Properties ideProps = new Properties();
49 if(netbeansProps!=null )
51 System.out.println("**** Found netbeans install");
52 for( int n = 0; n < netbeansProps.size(); n++ ) {
53 for( int v = 0; v < InstUtil.versions.length; v++ ) {
54 System.out.println("n: " +n+" v: " +v);
55 String key = InstUtil.versions[v];
56 System.out.println("It got here1");
57 String path = null;
58 if ( (path = netbeansProps.getProperty(key) ) != null ) {
59 //System.out.println( "n="+n+" v="+v + " Netbeans " + " key=" + key + " path=" + path );
60 ideProps.put(key, path);
65 //System.out.println("*** About to look for jedit install");
67 if(jeditProps!=null)
69 for( int j = 0; j < jeditProps.size(); j++ ) {
70 for( int v = 0; v < InstUtil.versions.length; v++ ) {
71 System.out.println("j: " +j+" v: " +v);
72 String key = InstUtil.versions[v];
73 String path = null;
74 if ((path = jeditProps.getProperty(key)) != null) {
75 //System.out.println( "j="+j+" v="+v + " jEdit " + " key=" + key + " path=" + path );
76 ideProps.put(key, path);
82 props = ideProps;
84 catch (IOException eIO) {
85 System.err.println("Failed to parse .netbeans/ide.log");
86 //JOptionPane.showMessageDialog(this, "There was a problem reading from the NetBeans ide.log file.", "Parse Error", JOptionPane.ERROR_MESSAGE);
88 catch (Exception e) {
89 System.err.println("Exception thrown in initComponents");
92 tableModel = new MyTableModelIDE (props, InstUtil.versions);
94 if (tableModel.getRowCount() == 0)
96 JOptionPane.showMessageDialog(this, "No compatible IDEs were found.", "Invalid versions", JOptionPane.ERROR_MESSAGE);
97 //wizard.exitForm(null);
100 tableModel.addTableModelListener(this);
101 JTable tableVersions = new JTable(tableModel) {
102 public String getToolTipText(MouseEvent event)
104 int col = columnAtPoint( event.getPoint() );
105 if (col != 2)
106 return null;
108 int row = rowAtPoint( event.getPoint() );
109 Object o = getValueAt(row, col);
111 if (o == null)
112 return null;
114 if (o.toString().equals(""))
115 return null;
117 return o.toString();
120 public Point getToolTipLocation(MouseEvent event)
122 int col = columnAtPoint( event.getPoint() );
123 if (col != 2)
124 return null;
126 int row = rowAtPoint( event.getPoint() );
127 Object o = getValueAt(row,col);
129 if (o == null)
130 return null;
132 if (o.toString().equals(""))
133 return null;
135 Point pt = getCellRect(row, col, true).getLocation();
136 pt.translate(-1,-2);
137 return pt;
141 JScrollPane scroll = new JScrollPane(tableVersions);
143 tableVersions.setPreferredSize(
144 new Dimension(InstallWizard.DEFWIDTH,InstallWizard.DEFHEIGHT));
146 tableVersions.setRowSelectionAllowed(false);
147 tableVersions.setColumnSelectionAllowed(false);
148 tableVersions.setCellSelectionEnabled(false);
150 initColumnSizes(tableVersions, tableModel);
151 versionPanel.add(scroll);
153 JTextArea area = new JTextArea("Please select IDEs below that you wish to add Scripting support to");
154 area.setLineWrap(true);
155 area.setEditable(false);
156 add(area, BorderLayout.NORTH);
157 add(versionPanel, BorderLayout.CENTER);
158 nav = new NavPanel(wizard, true, false, true, InstallWizard.IDEWELCOME, InstallWizard.IDEFINAL);
159 nav.setNextListener(this);
160 add(nav, BorderLayout.SOUTH);
162 }// initComponents
165 public java.awt.Dimension getPreferredSize() {
166 return new java.awt.Dimension(320, 280);
170 public void actionPerformed(ActionEvent ev) {
171 wizard.clearLocations();
172 int len = tableModel.data.size();
173 for (int i = 0; i < len; i++) {
174 ArrayList list = (ArrayList)tableModel.data.get(i);
175 if (((Boolean)list.get(0)).booleanValue() == true)
176 wizard.storeLocation((String)list.get(2));
179 //System.out.println(wizard.getLocations());
183 public void tableChanged(TableModelEvent e) {
184 if (tableModel.isAnySelected()) {
185 nav.enableNext(true);
187 else {
188 nav.enableNext(false);
192 private void initColumnSizes(JTable table, MyTableModelIDE model) {
193 TableColumn column = null;
194 Component comp = null;
195 int headerWidth = 0;
196 int cellWidth = 0;
197 int preferredWidth = 0;
198 int totalWidth = 0;
199 Object[] longValues = model.longValues;
201 for (int i = 0; i < 3; i++) {
202 column = table.getColumnModel().getColumn(i);
204 try {
205 comp = column.getHeaderRenderer().
206 getTableCellRendererComponent(
207 null, column.getHeaderValue(),
208 false, false, 0, 0);
209 headerWidth = comp.getPreferredSize().width;
210 } catch (NullPointerException e) {
211 // System.err.println("Null pointer exception!");
212 // System.err.println(" getHeaderRenderer returns null in 1.3.");
213 // System.err.println(" The replacement is getDefaultRenderer.");
216 // need to replace spaces in String before getting preferred width
217 if (longValues[i] instanceof String) {
218 longValues[i] = ((String)longValues[i]).replace(' ', '_');
221 System.out.println("longValues: " + longValues[i]);
222 comp = table.getDefaultRenderer(model.getColumnClass(i)).
223 getTableCellRendererComponent(
224 table, longValues[i],
225 false, false, 0, i);
226 cellWidth = comp.getPreferredSize().width;
228 preferredWidth = Math.max(headerWidth, cellWidth);
230 if (false) {
231 System.out.println("Initializing width of column "
232 + i + ". "
233 + "preferredWidth = " + preferredWidth
234 + "; totalWidth = " + totalWidth
235 + "; leftWidth = " + (InstallWizard.DEFWIDTH - totalWidth));
238 //XXX: Before Swing 1.1 Beta 2, use setMinWidth instead.
239 if (i == 2) {
240 if (preferredWidth > InstallWizard.DEFWIDTH - totalWidth)
241 column.setPreferredWidth(InstallWizard.DEFWIDTH - totalWidth);
242 else
243 column.setPreferredWidth(preferredWidth);
245 else {
246 column.setMinWidth(preferredWidth);
247 totalWidth += preferredWidth;
252 // Variables declaration - do not modify//GEN-BEGIN:variables
253 private javax.swing.JTextField jTextField2;
254 private InstallWizard wizard;
255 private MyTableModelIDE tableModel;
256 private NavPanel nav;
257 // End of variables declaration//GEN-END:variables
261 class MyTableModelIDE extends AbstractTableModel {
262 ArrayList data;
263 String colNames[] = {"", "IDE Name", "IDE Location"};
264 Object[] longValues = new Object[] {Boolean.TRUE, "Name", "Location"};
266 MyTableModelIDE (Properties properties, String [] validVersions) {
267 data = new ArrayList();
268 //System.out.println(properties);
270 int len = validVersions.length;
271 for (int i = 0; i < len; i++) {
272 String key = validVersions[i];
273 String path = null;
275 if ((path = properties.getProperty(key)) != null) {
276 ArrayList row = new ArrayList();
277 row.add(0, new Boolean(false));
279 row.add(1, key);
280 if (key.length() > ((String)longValues[1]).length()) {
281 longValues[1] = key;
284 row.add(2, path);
285 if (path.length() > ((String)longValues[2]).length()) {
286 longValues[2] = path;
289 data.add(row);
292 }// MyTableModel
294 public int getColumnCount() {
295 return 3;
298 public int getRowCount() {
299 return data.size();
302 public String getColumnName(int col) {
303 return colNames[col];
306 public Object getValueAt(int row, int col) {
307 if (row < 0 || row > getRowCount() ||
308 col < 0 || col > getColumnCount())
309 return null;
311 ArrayList aRow = (ArrayList)data.get(row);
312 return aRow.get(col);
315 public Class getColumnClass(int c) {
316 return getValueAt(0, c).getClass();
319 public boolean isCellEditable(int row, int col) {
320 if (col == 0) {
321 return true;
322 } else {
323 return false;
327 public void setValueAt(Object value, int row, int col) {
328 ArrayList aRow = (ArrayList)data.get(row);
329 aRow.set(col, value);
330 fireTableCellUpdated(row, col);
333 String [] getSelected() {
334 return null;
337 public boolean isAnySelected() {
338 Iterator iter = data.iterator();
339 while (iter.hasNext()) {
340 ArrayList row = (ArrayList)iter.next();
341 if (((Boolean)row.get(0)).booleanValue() == true) {
342 return true;
345 return false;