1 package installer; 2 3 /* 4 * Welcome.java 5 * 6 * Created on 04 July 2002, 15:43 7 */ 8 9 /** 10 * 11 * @author mike 12 */ 13 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.*; 22 23 public class IdeVersion extends javax.swing.JPanel implements ActionListener, TableModelListener { 24 25 /** Creates new form Welcome */ 26 public IdeVersion(InstallWizard wizard) { 27 this.wizard=wizard; 28 setBackground(Color.white); 29 initComponents(); 30 } 31 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. 36 */ 37 private void initComponents() { 38 Properties props = null; 39 JPanel versionPanel = new JPanel(); 40 setLayout(new BorderLayout()); 41 42 43 try { 44 //props = InstUtil.getNetbeansLocation(); 45 46 Properties netbeansProps = InstUtil.getNetbeansLocation(); 47 //Properties jeditProps = InstUtil.getJeditLocation(); 48 Properties ideProps = new Properties(); 49 if(netbeansProps!=null ) 50 { 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); 61 } 62 } 63 } 64 } 65 //System.out.println("*** About to look for jedit install"); 66 /* 67 if(jeditProps!=null) 68 { 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); 77 } 78 } 79 } 80 } 81 */ 82 props = ideProps; 83 } 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); 87 } 88 catch (Exception e) { 89 System.err.println("Exception thrown in initComponents"); 90 } 91 92 tableModel = new MyTableModelIDE (props, InstUtil.versions); 93 94 if (tableModel.getRowCount() == 0) 95 { 96 JOptionPane.showMessageDialog(this, "No compatible IDEs were found.", "Invalid versions", JOptionPane.ERROR_MESSAGE); 97 //wizard.exitForm(null); 98 } 99 100 tableModel.addTableModelListener(this); 101 JTable tableVersions = new JTable(tableModel) { 102 public String getToolTipText(MouseEvent event) 103 { 104 int col = columnAtPoint( event.getPoint() ); 105 if (col != 2) 106 return null; 107 108 int row = rowAtPoint( event.getPoint() ); 109 Object o = getValueAt(row, col); 110 111 if (o == null) 112 return null; 113 114 if (o.toString().equals("")) 115 return null; 116 117 return o.toString(); 118 } 119 120 public Point getToolTipLocation(MouseEvent event) 121 { 122 int col = columnAtPoint( event.getPoint() ); 123 if (col != 2) 124 return null; 125 126 int row = rowAtPoint( event.getPoint() ); 127 Object o = getValueAt(row,col); 128 129 if (o == null) 130 return null; 131 132 if (o.toString().equals("")) 133 return null; 134 135 Point pt = getCellRect(row, col, true).getLocation(); 136 pt.translate(-1,-2); 137 return pt; 138 } 139 }; 140 141 JScrollPane scroll = new JScrollPane(tableVersions); 142 143 tableVersions.setPreferredSize( 144 new Dimension(InstallWizard.DEFWIDTH,InstallWizard.DEFHEIGHT)); 145 146 tableVersions.setRowSelectionAllowed(false); 147 tableVersions.setColumnSelectionAllowed(false); 148 tableVersions.setCellSelectionEnabled(false); 149 150 initColumnSizes(tableVersions, tableModel); 151 versionPanel.add(scroll); 152 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); 161 162 }// initComponents 163 164 165 public java.awt.Dimension getPreferredSize() { 166 return new java.awt.Dimension(320, 280); 167 } 168 169 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)); 177 } 178 179 //System.out.println(wizard.getLocations()); 180 } 181 182 183 public void tableChanged(TableModelEvent e) { 184 if (tableModel.isAnySelected()) { 185 nav.enableNext(true); 186 } 187 else { 188 nav.enableNext(false); 189 } 190 } 191 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; 200 201 for (int i = 0; i < 3; i++) { 202 column = table.getColumnModel().getColumn(i); 203 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."); 214 } 215 216 // need to replace spaces in String before getting preferred width 217 if (longValues[i] instanceof String) { 218 longValues[i] = ((String)longValues[i]).replace(' ', '_'); 219 } 220 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; 227 228 preferredWidth = Math.max(headerWidth, cellWidth); 229 230 if (false) { 231 System.out.println("Initializing width of column " 232 + i + ". " 233 + "preferredWidth = " + preferredWidth 234 + "; totalWidth = " + totalWidth 235 + "; leftWidth = " + (InstallWizard.DEFWIDTH - totalWidth)); 236 } 237 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); 244 } 245 else { 246 column.setMinWidth(preferredWidth); 247 totalWidth += preferredWidth; 248 } 249 } 250 } 251 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 258 259 } 260 261 class MyTableModelIDE extends AbstractTableModel { 262 ArrayList data; 263 String colNames[] = {"", "IDE Name", "IDE Location"}; 264 Object[] longValues = new Object[] {Boolean.TRUE, "Name", "Location"}; 265 266 MyTableModelIDE (Properties properties, String [] validVersions) { 267 data = new ArrayList(); 268 //System.out.println(properties); 269 270 int len = validVersions.length; 271 for (int i = 0; i < len; i++) { 272 String key = validVersions[i]; 273 String path = null; 274 275 if ((path = properties.getProperty(key)) != null) { 276 ArrayList row = new ArrayList(); 277 row.add(0, new Boolean(false)); 278 279 row.add(1, key); 280 if (key.length() > ((String)longValues[1]).length()) { 281 longValues[1] = key; 282 } 283 284 row.add(2, path); 285 if (path.length() > ((String)longValues[2]).length()) { 286 longValues[2] = path; 287 } 288 289 data.add(row); 290 } 291 } 292 }// MyTableModel 293 294 public int getColumnCount() { 295 return 3; 296 } 297 298 public int getRowCount() { 299 return data.size(); 300 } 301 302 public String getColumnName(int col) { 303 return colNames[col]; 304 } 305 306 public Object getValueAt(int row, int col) { 307 if (row < 0 || row > getRowCount() || 308 col < 0 || col > getColumnCount()) 309 return null; 310 311 ArrayList aRow = (ArrayList)data.get(row); 312 return aRow.get(col); 313 } 314 315 public Class getColumnClass(int c) { 316 return getValueAt(0, c).getClass(); 317 } 318 319 public boolean isCellEditable(int row, int col) { 320 if (col == 0) { 321 return true; 322 } else { 323 return false; 324 } 325 } 326 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); 331 } 332 333 String [] getSelected() { 334 return null; 335 } 336 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; 343 } 344 } 345 return false; 346 } 347 348 } 349 350