1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
|
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
package installer;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
public class IdeVersion extends javax.swing.JPanel implements ActionListener, TableModelListener {
/** Creates new form Welcome */
public IdeVersion(InstallWizard wizard) {
this.wizard=wizard;
setBackground(Color.white);
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {
Properties props = null;
JPanel versionPanel = new JPanel();
setLayout(new BorderLayout());
try {
//props = InstUtil.getNetbeansLocation();
Properties netbeansProps = InstUtil.getNetbeansLocation();
//Properties jeditProps = InstUtil.getJeditLocation();
Properties ideProps = new Properties();
if(netbeansProps!=null )
{
System.out.println("**** Found netbeans install");
for( int n = 0; n < netbeansProps.size(); n++ ) {
for( int v = 0; v < InstUtil.versions.length; v++ ) {
System.out.println("n: " +n+" v: " +v);
String key = InstUtil.versions[v];
System.out.println("It got here1");
String path = null;
if ( (path = netbeansProps.getProperty(key) ) != null ) {
//System.out.println( "n="+n+" v="+v + " Netbeans " + " key=" + key + " path=" + path );
ideProps.put(key, path);
}
}
}
}
//System.out.println("*** About to look for jedit install");
/*
if(jeditProps!=null)
{
for( int j = 0; j < jeditProps.size(); j++ ) {
for( int v = 0; v < InstUtil.versions.length; v++ ) {
System.out.println("j: " +j+" v: " +v);
String key = InstUtil.versions[v];
String path = null;
if ((path = jeditProps.getProperty(key)) != null) {
//System.out.println( "j="+j+" v="+v + " jEdit " + " key=" + key + " path=" + path );
ideProps.put(key, path);
}
}
}
}
*/
props = ideProps;
}
catch (IOException eIO) {
System.err.println("Failed to parse .netbeans/ide.log");
//JOptionPane.showMessageDialog(this, "There was a problem reading from the NetBeans ide.log file.", "Parse Error", JOptionPane.ERROR_MESSAGE);
}
catch (Exception e) {
System.err.println("Exception thrown in initComponents");
}
tableModel = new MyTableModelIDE (props, InstUtil.versions);
if (tableModel.getRowCount() == 0)
{
JOptionPane.showMessageDialog(this, "No compatible IDEs were found.", "Invalid versions", JOptionPane.ERROR_MESSAGE);
//wizard.exitForm(null);
}
tableModel.addTableModelListener(this);
JTable tableVersions = new JTable(tableModel) {
public String getToolTipText(MouseEvent event)
{
int col = columnAtPoint( event.getPoint() );
if (col != 2)
return null;
int row = rowAtPoint( event.getPoint() );
Object o = getValueAt(row, col);
if (o == null)
return null;
if (o.toString().equals(""))
return null;
return o.toString();
}
public Point getToolTipLocation(MouseEvent event)
{
int col = columnAtPoint( event.getPoint() );
if (col != 2)
return null;
int row = rowAtPoint( event.getPoint() );
Object o = getValueAt(row,col);
if (o == null)
return null;
if (o.toString().equals(""))
return null;
Point pt = getCellRect(row, col, true).getLocation();
pt.translate(-1,-2);
return pt;
}
};
JScrollPane scroll = new JScrollPane(tableVersions);
tableVersions.setPreferredSize(
new Dimension(InstallWizard.DEFWIDTH,InstallWizard.DEFHEIGHT));
tableVersions.setRowSelectionAllowed(false);
tableVersions.setColumnSelectionAllowed(false);
tableVersions.setCellSelectionEnabled(false);
initColumnSizes(tableVersions, tableModel);
versionPanel.add(scroll);
JTextArea area = new JTextArea("Please select IDEs below that you wish to add Scripting support to");
area.setLineWrap(true);
area.setEditable(false);
add(area, BorderLayout.NORTH);
add(versionPanel, BorderLayout.CENTER);
nav = new NavPanel(wizard, true, false, true, InstallWizard.IDEWELCOME, InstallWizard.IDEFINAL);
nav.setNextListener(this);
add(nav, BorderLayout.SOUTH);
}// initComponents
public java.awt.Dimension getPreferredSize() {
return new java.awt.Dimension(320, 280);
}
public void actionPerformed(ActionEvent ev) {
wizard.clearLocations();
int len = tableModel.data.size();
for (int i = 0; i < len; i++) {
ArrayList<?> list = tableModel.data.get(i);
if (((Boolean)list.get(0)).booleanValue() == true)
wizard.storeLocation((String)list.get(2));
}
//System.out.println(wizard.getLocations());
}
public void tableChanged(TableModelEvent e) {
if (tableModel.isAnySelected()) {
nav.enableNext(true);
}
else {
nav.enableNext(false);
}
}
private void initColumnSizes(JTable table, MyTableModelIDE model) {
TableColumn column = null;
Component comp = null;
int headerWidth = 0;
int cellWidth = 0;
int preferredWidth = 0;
int totalWidth = 0;
Object[] longValues = model.longValues;
for (int i = 0; i < 3; i++) {
column = table.getColumnModel().getColumn(i);
try {
comp = column.getHeaderRenderer().
getTableCellRendererComponent(
null, column.getHeaderValue(),
false, false, 0, 0);
headerWidth = comp.getPreferredSize().width;
} catch (NullPointerException e) {
// System.err.println("Null pointer exception!");
// System.err.println(" getHeaderRenderer returns null in 1.3.");
// System.err.println(" The replacement is getDefaultRenderer.");
}
// need to replace spaces in String before getting preferred width
if (longValues[i] instanceof String) {
longValues[i] = ((String)longValues[i]).replace(' ', '_');
}
System.out.println("longValues: " + longValues[i]);
comp = table.getDefaultRenderer(model.getColumnClass(i)).
getTableCellRendererComponent(
table, longValues[i],
false, false, 0, i);
cellWidth = comp.getPreferredSize().width;
preferredWidth = Math.max(headerWidth, cellWidth);
if (false) {
System.out.println("Initializing width of column "
+ i + ". "
+ "preferredWidth = " + preferredWidth
+ "; totalWidth = " + totalWidth
+ "; leftWidth = " + (InstallWizard.DEFWIDTH - totalWidth));
}
//XXX: Before Swing 1.1 Beta 2, use setMinWidth instead.
if (i == 2) {
if (preferredWidth > InstallWizard.DEFWIDTH - totalWidth)
column.setPreferredWidth(InstallWizard.DEFWIDTH - totalWidth);
else
column.setPreferredWidth(preferredWidth);
}
else {
column.setMinWidth(preferredWidth);
totalWidth += preferredWidth;
}
}
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextField jTextField2;
private InstallWizard wizard;
private MyTableModelIDE tableModel;
private NavPanel nav;
// End of variables declaration//GEN-END:variables
}
class MyTableModelIDE extends AbstractTableModel {
ArrayList<ArrayList<Object>> data;
String colNames[] = {"", "IDE Name", "IDE Location"};
Object[] longValues = new Object[] {Boolean.TRUE, "Name", "Location"};
MyTableModelIDE (Properties properties, String [] validVersions) {
data = new ArrayList<ArrayList<Object>>();
//System.out.println(properties);
int len = validVersions.length;
for (int i = 0; i < len; i++) {
String key = validVersions[i];
String path = null;
if ((path = properties.getProperty(key)) != null) {
ArrayList<Object> row = new ArrayList<Object>();
row.add(0, new Boolean(false));
row.add(1, key);
if (key.length() > ((String)longValues[1]).length()) {
longValues[1] = key;
}
row.add(2, path);
if (path.length() > ((String)longValues[2]).length()) {
longValues[2] = path;
}
data.add(row);
}
}
}// MyTableModel
public int getColumnCount() {
return 3;
}
public int getRowCount() {
return data.size();
}
public String getColumnName(int col) {
return colNames[col];
}
public Object getValueAt(int row, int col) {
if (row < 0 || row > getRowCount() ||
col < 0 || col > getColumnCount())
return null;
ArrayList<?> aRow = data.get(row);
return aRow.get(col);
}
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
public boolean isCellEditable(int row, int col) {
if (col == 0) {
return true;
} else {
return false;
}
}
public void setValueAt(Object value, int row, int col) {
ArrayList<Object> aRow = data.get(row);
aRow.set(col, value);
fireTableCellUpdated(row, col);
}
String [] getSelected() {
return null;
}
public boolean isAnySelected() {
Iterator iter = data.iterator();
while (iter.hasNext()) {
ArrayList<?> row = (ArrayList<?>)iter.next();
if (((Boolean)row.get(0)).booleanValue() == true) {
return true;
}
}
return false;
}
}
|