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