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 IdeVersion
extends javax
.swing
.JPanel
implements ActionListener
, TableModelListener
{
25 /** Creates new form Welcome */
26 public IdeVersion(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());
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");
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");
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];
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);
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);
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() );
108 int row
= rowAtPoint( event
.getPoint() );
109 Object o
= getValueAt(row
, col
);
114 if (o
.toString().equals(""))
120 public Point
getToolTipLocation(MouseEvent event
)
122 int col
= columnAtPoint( event
.getPoint() );
126 int row
= rowAtPoint( event
.getPoint() );
127 Object o
= getValueAt(row
,col
);
132 if (o
.toString().equals(""))
135 Point pt
= getCellRect(row
, col
, true).getLocation();
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
);
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);
188 nav
.enableNext(false);
192 private void initColumnSizes(JTable table
, MyTableModelIDE model
) {
193 TableColumn column
= null;
194 Component comp
= null;
197 int preferredWidth
= 0;
199 Object
[] longValues
= model
.longValues
;
201 for (int i
= 0; i
< 3; i
++) {
202 column
= table
.getColumnModel().getColumn(i
);
205 comp
= column
.getHeaderRenderer().
206 getTableCellRendererComponent(
207 null, column
.getHeaderValue(),
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
],
226 cellWidth
= comp
.getPreferredSize().width
;
228 preferredWidth
= Math
.max(headerWidth
, cellWidth
);
231 System
.out
.println("Initializing width of column "
233 + "preferredWidth = " + preferredWidth
234 + "; totalWidth = " + totalWidth
235 + "; leftWidth = " + (InstallWizard
.DEFWIDTH
- totalWidth
));
238 //XXX: Before Swing 1.1 Beta 2, use setMinWidth instead.
240 if (preferredWidth
> InstallWizard
.DEFWIDTH
- totalWidth
)
241 column
.setPreferredWidth(InstallWizard
.DEFWIDTH
- totalWidth
);
243 column
.setPreferredWidth(preferredWidth
);
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
{
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
];
275 if ((path
= properties
.getProperty(key
)) != null) {
276 ArrayList row
= new ArrayList();
277 row
.add(0, new Boolean(false));
280 if (key
.length() > ((String
)longValues
[1]).length()) {
285 if (path
.length() > ((String
)longValues
[2]).length()) {
286 longValues
[2] = path
;
294 public int getColumnCount() {
298 public int getRowCount() {
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())
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
) {
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() {
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) {