2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 import java
.awt
.event
.*;
27 import javax
.swing
.event
.*;
28 import javax
.swing
.table
.*;
30 public class IdeVersion
extends javax
.swing
.JPanel
implements ActionListener
, TableModelListener
{
32 /** Creates new form Welcome */
33 public IdeVersion(InstallWizard wizard
) {
35 setBackground(Color
.white
);
39 /** This method is called from within the constructor to
40 * initialize the form.
41 * WARNING: Do NOT modify this code. The content of this method is
42 * always regenerated by the Form Editor.
44 private void initComponents() {
45 Properties props
= null;
46 JPanel versionPanel
= new JPanel();
47 setLayout(new BorderLayout());
51 //props = InstUtil.getNetbeansLocation();
53 Properties netbeansProps
= InstUtil
.getNetbeansLocation();
54 //Properties jeditProps = InstUtil.getJeditLocation();
55 Properties ideProps
= new Properties();
56 if(netbeansProps
!=null )
58 System
.out
.println("**** Found netbeans install");
59 for( int n
= 0; n
< netbeansProps
.size(); n
++ ) {
60 for( int v
= 0; v
< InstUtil
.versions
.length
; v
++ ) {
61 System
.out
.println("n: " +n
+" v: " +v
);
62 String key
= InstUtil
.versions
[v
];
63 System
.out
.println("It got here1");
65 if ( (path
= netbeansProps
.getProperty(key
) ) != null ) {
66 //System.out.println( "n="+n+" v="+v + " Netbeans " + " key=" + key + " path=" + path );
67 ideProps
.put(key
, path
);
72 //System.out.println("*** About to look for jedit install");
76 for( int j = 0; j < jeditProps.size(); j++ ) {
77 for( int v = 0; v < InstUtil.versions.length; v++ ) {
78 System.out.println("j: " +j+" v: " +v);
79 String key = InstUtil.versions[v];
81 if ((path = jeditProps.getProperty(key)) != null) {
82 //System.out.println( "j="+j+" v="+v + " jEdit " + " key=" + key + " path=" + path );
83 ideProps.put(key, path);
91 catch (IOException eIO
) {
92 System
.err
.println("Failed to parse .netbeans/ide.log");
93 //JOptionPane.showMessageDialog(this, "There was a problem reading from the NetBeans ide.log file.", "Parse Error", JOptionPane.ERROR_MESSAGE);
96 System
.err
.println("Exception thrown in initComponents");
99 tableModel
= new MyTableModelIDE (props
, InstUtil
.versions
);
101 if (tableModel
.getRowCount() == 0)
103 JOptionPane
.showMessageDialog(this, "No compatible IDEs were found.", "Invalid versions", JOptionPane
.ERROR_MESSAGE
);
104 //wizard.exitForm(null);
107 tableModel
.addTableModelListener(this);
108 JTable tableVersions
= new JTable(tableModel
) {
109 public String
getToolTipText(MouseEvent event
)
111 int col
= columnAtPoint( event
.getPoint() );
115 int row
= rowAtPoint( event
.getPoint() );
116 Object o
= getValueAt(row
, col
);
121 if (o
.toString().equals(""))
127 public Point
getToolTipLocation(MouseEvent event
)
129 int col
= columnAtPoint( event
.getPoint() );
133 int row
= rowAtPoint( event
.getPoint() );
134 Object o
= getValueAt(row
,col
);
139 if (o
.toString().equals(""))
142 Point pt
= getCellRect(row
, col
, true).getLocation();
148 JScrollPane scroll
= new JScrollPane(tableVersions
);
150 tableVersions
.setPreferredSize(
151 new Dimension(InstallWizard
.DEFWIDTH
,InstallWizard
.DEFHEIGHT
));
153 tableVersions
.setRowSelectionAllowed(false);
154 tableVersions
.setColumnSelectionAllowed(false);
155 tableVersions
.setCellSelectionEnabled(false);
157 initColumnSizes(tableVersions
, tableModel
);
158 versionPanel
.add(scroll
);
160 JTextArea area
= new JTextArea("Please select IDEs below that you wish to add Scripting support to");
161 area
.setLineWrap(true);
162 area
.setEditable(false);
163 add(area
, BorderLayout
.NORTH
);
164 add(versionPanel
, BorderLayout
.CENTER
);
165 nav
= new NavPanel(wizard
, true, false, true, InstallWizard
.IDEWELCOME
, InstallWizard
.IDEFINAL
);
166 nav
.setNextListener(this);
167 add(nav
, BorderLayout
.SOUTH
);
172 public java
.awt
.Dimension
getPreferredSize() {
173 return new java
.awt
.Dimension(320, 280);
177 public void actionPerformed(ActionEvent ev
) {
178 InstallWizard
.clearLocations();
179 int len
= tableModel
.data
.size();
180 for (int i
= 0; i
< len
; i
++) {
181 ArrayList
<?
> list
= tableModel
.data
.get(i
);
182 if (((Boolean
)list
.get(0)).booleanValue() == true)
183 InstallWizard
.storeLocation((String
)list
.get(2));
186 //System.out.println(wizard.getLocations());
190 public void tableChanged(TableModelEvent e
) {
191 if (tableModel
.isAnySelected()) {
192 nav
.enableNext(true);
195 nav
.enableNext(false);
199 private void initColumnSizes(JTable table
, MyTableModelIDE model
) {
200 TableColumn column
= null;
201 Component comp
= null;
204 int preferredWidth
= 0;
206 Object
[] longValues
= model
.longValues
;
208 for (int i
= 0; i
< 3; i
++) {
209 column
= table
.getColumnModel().getColumn(i
);
212 comp
= column
.getHeaderRenderer().
213 getTableCellRendererComponent(
214 null, column
.getHeaderValue(),
216 headerWidth
= comp
.getPreferredSize().width
;
217 } catch (NullPointerException e
) {
218 // System.err.println("Null pointer exception!");
219 // System.err.println(" getHeaderRenderer returns null in 1.3.");
220 // System.err.println(" The replacement is getDefaultRenderer.");
223 // need to replace spaces in String before getting preferred width
224 if (longValues
[i
] instanceof String
) {
225 longValues
[i
] = ((String
)longValues
[i
]).replace(' ', '_');
228 System
.out
.println("longValues: " + longValues
[i
]);
229 comp
= table
.getDefaultRenderer(model
.getColumnClass(i
)).
230 getTableCellRendererComponent(
231 table
, longValues
[i
],
233 cellWidth
= comp
.getPreferredSize().width
;
235 preferredWidth
= Math
.max(headerWidth
, cellWidth
);
238 System
.out
.println("Initializing width of column "
240 + "preferredWidth = " + preferredWidth
241 + "; totalWidth = " + totalWidth
242 + "; leftWidth = " + (InstallWizard
.DEFWIDTH
- totalWidth
));
245 //XXX: Before Swing 1.1 Beta 2, use setMinWidth instead.
247 if (preferredWidth
> InstallWizard
.DEFWIDTH
- totalWidth
)
248 column
.setPreferredWidth(InstallWizard
.DEFWIDTH
- totalWidth
);
250 column
.setPreferredWidth(preferredWidth
);
253 column
.setMinWidth(preferredWidth
);
254 totalWidth
+= preferredWidth
;
259 // Variables declaration - do not modify//GEN-BEGIN:variables
260 private javax
.swing
.JTextField jTextField2
;
261 private InstallWizard wizard
;
262 private MyTableModelIDE tableModel
;
263 private NavPanel nav
;
264 // End of variables declaration//GEN-END:variables
268 class MyTableModelIDE
extends AbstractTableModel
{
269 ArrayList
<ArrayList
<Object
>> data
;
270 String colNames
[] = {"", "IDE Name", "IDE Location"};
271 Object
[] longValues
= new Object
[] {Boolean
.TRUE
, "Name", "Location"};
273 MyTableModelIDE (Properties properties
, String
[] validVersions
) {
274 data
= new ArrayList
<ArrayList
<Object
>>();
275 //System.out.println(properties);
277 int len
= validVersions
.length
;
278 for (int i
= 0; i
< len
; i
++) {
279 String key
= validVersions
[i
];
282 if ((path
= properties
.getProperty(key
)) != null) {
283 ArrayList
<Object
> row
= new ArrayList
<Object
>();
284 row
.add(0, new Boolean(false));
287 if (key
.length() > ((String
)longValues
[1]).length()) {
292 if (path
.length() > ((String
)longValues
[2]).length()) {
293 longValues
[2] = path
;
301 public int getColumnCount() {
305 public int getRowCount() {
309 public String
getColumnName(int col
) {
310 return colNames
[col
];
313 public Object
getValueAt(int row
, int col
) {
314 if (row
< 0 || row
> getRowCount() ||
315 col
< 0 || col
> getColumnCount())
318 ArrayList
<?
> aRow
= data
.get(row
);
319 return aRow
.get(col
);
322 public Class
getColumnClass(int c
) {
323 return getValueAt(0, c
).getClass();
326 public boolean isCellEditable(int row
, int col
) {
334 public void setValueAt(Object value
, int row
, int col
) {
335 ArrayList
<Object
> aRow
= data
.get(row
);
336 aRow
.set(col
, value
);
337 fireTableCellUpdated(row
, col
);
340 String
[] getSelected() {
344 public boolean isAnySelected() {
345 Iterator iter
= data
.iterator();
346 while (iter
.hasNext()) {
347 ArrayList
<?
> row
= (ArrayList
<?
>)iter
.next();
348 if (((Boolean
)row
.get(0)).booleanValue() == true) {