fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / scripting / workben / installer / IdeVersion.java
blob052e3f07811df8ca59e1d8ce69ae5af609ee17f7
1 /*
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 .
19 package installer;
21 import java.awt.*;
22 import java.awt.event.*;
23 import java.io.*;
24 import java.util.*;
26 import javax.swing.*;
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) {
34 this.wizard=wizard;
35 setBackground(Color.white);
36 initComponents();
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());
50 try {
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");
64 String path = null;
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");
74 if(jeditProps!=null)
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];
80 String path = null;
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);
89 props = ideProps;
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);
95 catch (Exception e) {
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() );
112 if (col != 2)
113 return null;
115 int row = rowAtPoint( event.getPoint() );
116 Object o = getValueAt(row, col);
118 if (o == null)
119 return null;
121 if (o.toString().equals(""))
122 return null;
124 return o.toString();
127 public Point getToolTipLocation(MouseEvent event)
129 int col = columnAtPoint( event.getPoint() );
130 if (col != 2)
131 return null;
133 int row = rowAtPoint( event.getPoint() );
134 Object o = getValueAt(row,col);
136 if (o == null)
137 return null;
139 if (o.toString().equals(""))
140 return null;
142 Point pt = getCellRect(row, col, true).getLocation();
143 pt.translate(-1,-2);
144 return pt;
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);
169 }// initComponents
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);
194 else {
195 nav.enableNext(false);
199 private void initColumnSizes(JTable table, MyTableModelIDE model) {
200 TableColumn column = null;
201 Component comp = null;
202 int headerWidth = 0;
203 int cellWidth = 0;
204 int preferredWidth = 0;
205 int totalWidth = 0;
206 Object[] longValues = model.longValues;
208 for (int i = 0; i < 3; i++) {
209 column = table.getColumnModel().getColumn(i);
211 try {
212 comp = column.getHeaderRenderer().
213 getTableCellRendererComponent(
214 null, column.getHeaderValue(),
215 false, false, 0, 0);
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],
232 false, false, 0, i);
233 cellWidth = comp.getPreferredSize().width;
235 preferredWidth = Math.max(headerWidth, cellWidth);
237 if (false) {
238 System.out.println("Initializing width of column "
239 + i + ". "
240 + "preferredWidth = " + preferredWidth
241 + "; totalWidth = " + totalWidth
242 + "; leftWidth = " + (InstallWizard.DEFWIDTH - totalWidth));
245 //XXX: Before Swing 1.1 Beta 2, use setMinWidth instead.
246 if (i == 2) {
247 if (preferredWidth > InstallWizard.DEFWIDTH - totalWidth)
248 column.setPreferredWidth(InstallWizard.DEFWIDTH - totalWidth);
249 else
250 column.setPreferredWidth(preferredWidth);
252 else {
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];
280 String path = null;
282 if ((path = properties.getProperty(key)) != null) {
283 ArrayList<Object> row = new ArrayList<Object>();
284 row.add(0, new Boolean(false));
286 row.add(1, key);
287 if (key.length() > ((String)longValues[1]).length()) {
288 longValues[1] = key;
291 row.add(2, path);
292 if (path.length() > ((String)longValues[2]).length()) {
293 longValues[2] = path;
296 data.add(row);
299 }// MyTableModel
301 public int getColumnCount() {
302 return 3;
305 public int getRowCount() {
306 return data.size();
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())
316 return null;
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) {
327 if (col == 0) {
328 return true;
329 } else {
330 return false;
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() {
341 return null;
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) {
349 return true;
352 return false;