1*cd519653SAndrew Rist /**************************************************************
2*cd519653SAndrew Rist  *
3*cd519653SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*cd519653SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*cd519653SAndrew Rist  * distributed with this work for additional information
6*cd519653SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*cd519653SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*cd519653SAndrew Rist  * "License"); you may not use this file except in compliance
9*cd519653SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*cd519653SAndrew Rist  *
11*cd519653SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*cd519653SAndrew Rist  *
13*cd519653SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*cd519653SAndrew Rist  * software distributed under the License is distributed on an
15*cd519653SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*cd519653SAndrew Rist  * KIND, either express or implied.  See the License for the
17*cd519653SAndrew Rist  * specific language governing permissions and limitations
18*cd519653SAndrew Rist  * under the License.
19*cd519653SAndrew Rist  *
20*cd519653SAndrew Rist  *************************************************************/
21*cd519653SAndrew Rist 
22cdf0e10cSrcweir /*
23cdf0e10cSrcweir  * SelectPathVisualPanel.java
24cdf0e10cSrcweir  *
25cdf0e10cSrcweir  * Created on February 12, 2003
26cdf0e10cSrcweir  */
27cdf0e10cSrcweir 
28cdf0e10cSrcweir package org.openoffice.netbeans.modules.office.wizard;
29cdf0e10cSrcweir 
30cdf0e10cSrcweir import java.util.Hashtable;
31cdf0e10cSrcweir import java.util.Enumeration;
32cdf0e10cSrcweir import java.io.File;
33cdf0e10cSrcweir import java.io.IOException;
34cdf0e10cSrcweir import javax.swing.JFileChooser;
35cdf0e10cSrcweir 
36cdf0e10cSrcweir import org.openide.util.NbBundle;
37cdf0e10cSrcweir import org.openoffice.idesupport.SVersionRCFile;
38cdf0e10cSrcweir import org.openoffice.idesupport.OfficeInstallation;
39cdf0e10cSrcweir import org.openoffice.netbeans.modules.office.options.OfficeSettings;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir /** A single panel for a wizard - the GUI portion.
42cdf0e10cSrcweir  *
43cdf0e10cSrcweir  * @author tomaso
44cdf0e10cSrcweir  */
45cdf0e10cSrcweir public class SelectPathVisualPanel extends javax.swing.JPanel {
46cdf0e10cSrcweir 
47cdf0e10cSrcweir     /** The wizard panel descriptor associated with this GUI panel.
48cdf0e10cSrcweir      * If you need to fire state changes or something similar, you can
49cdf0e10cSrcweir      * use this handle to do so.
50cdf0e10cSrcweir      */
51cdf0e10cSrcweir     private final SelectPathPanel panel;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir     /** Create the wizard panel and set up some basic properties. */
SelectPathVisualPanel(SelectPathPanel panel)54cdf0e10cSrcweir     public SelectPathVisualPanel(SelectPathPanel panel) {
55cdf0e10cSrcweir         this.panel = panel;
56cdf0e10cSrcweir         initComponents();
57cdf0e10cSrcweir         OfficeInstallation orig = panel.getSelectedPath();
58cdf0e10cSrcweir 
59cdf0e10cSrcweir         try {
60cdf0e10cSrcweir             Enumeration enumer = SVersionRCFile.createInstance().getVersions();
61cdf0e10cSrcweir 
62cdf0e10cSrcweir             while (enumer.hasMoreElements()) {
63cdf0e10cSrcweir                 OfficeInstallation oi = (OfficeInstallation)enumer.nextElement();
64cdf0e10cSrcweir                 installationsComboBox.addItem(oi);
65cdf0e10cSrcweir             }
66cdf0e10cSrcweir         }
67cdf0e10cSrcweir         catch (IOException ioe) {
68cdf0e10cSrcweir             installationsComboBox.addItem("<empty>");
69cdf0e10cSrcweir         }
70cdf0e10cSrcweir 
71cdf0e10cSrcweir         if (orig != null) {
72cdf0e10cSrcweir             installationsComboBox.setSelectedItem(orig);
73cdf0e10cSrcweir             installPath.setText(orig.getPath());
74cdf0e10cSrcweir         }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir         installationsComboBox.addActionListener(
77cdf0e10cSrcweir             new java.awt.event.ActionListener() {
78cdf0e10cSrcweir                 public void actionPerformed(java.awt.event.ActionEvent evt) {
79cdf0e10cSrcweir                     installationsComboBoxActionPerformed(evt);
80cdf0e10cSrcweir                 }
81cdf0e10cSrcweir             }
82cdf0e10cSrcweir         );
83cdf0e10cSrcweir 
84cdf0e10cSrcweir         // Provide a name in the title bar.
85cdf0e10cSrcweir         setName(NbBundle.getMessage(SelectPathVisualPanel.class, "TITLE_SelectPathVisualPanel"));
86cdf0e10cSrcweir         /*
87cdf0e10cSrcweir         // Optional: provide a special description for this pane.
88cdf0e10cSrcweir         // You must have turned on WizardDescriptor.WizardPanel_helpDisplayed
89cdf0e10cSrcweir         // (see descriptor in standard iterator template for an example of this).
90cdf0e10cSrcweir         try {
91cdf0e10cSrcweir             putClientProperty("WizardPanel_helpURL", // NOI18N
92cdf0e10cSrcweir                 new URL("nbresloc:/org/openoffice/netbeans/modules/office/wizard/SelectPathVisualHelp.html")); // NOI18N
93cdf0e10cSrcweir         } catch (MalformedURLException mfue) {
94cdf0e10cSrcweir             throw new IllegalStateException(mfue.toString());
95cdf0e10cSrcweir         }
96cdf0e10cSrcweir          */
97cdf0e10cSrcweir     }
98cdf0e10cSrcweir 
installationsComboBoxActionPerformed( java.awt.event.ActionEvent evt)99cdf0e10cSrcweir     private void installationsComboBoxActionPerformed(
100cdf0e10cSrcweir         java.awt.event.ActionEvent evt) {
101cdf0e10cSrcweir 
102cdf0e10cSrcweir         OfficeInstallation oi =
103cdf0e10cSrcweir             (OfficeInstallation)installationsComboBox.getSelectedItem();
104cdf0e10cSrcweir 
105cdf0e10cSrcweir         installPath.setText(oi.getPath());
106cdf0e10cSrcweir         panel.setSelectedPath(oi);
107cdf0e10cSrcweir     }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     /** This method is called from within the constructor to
110cdf0e10cSrcweir      * initialize the form.
111cdf0e10cSrcweir      * WARNING: Do NOT modify this code. The content of this method is
112cdf0e10cSrcweir      * always regenerated by the Form Editor.
113cdf0e10cSrcweir      */
initComponents()114cdf0e10cSrcweir     private void initComponents() {//GEN-BEGIN:initComponents
115cdf0e10cSrcweir         java.awt.GridBagConstraints gridBagConstraints;
116cdf0e10cSrcweir 
117cdf0e10cSrcweir         jLabel1 = new javax.swing.JLabel();
118cdf0e10cSrcweir         installPath = new javax.swing.JTextField();
119cdf0e10cSrcweir         jLabel2 = new javax.swing.JLabel();
120cdf0e10cSrcweir         installationsComboBox = new javax.swing.JComboBox();
121cdf0e10cSrcweir         jPanel1 = new javax.swing.JPanel();
122cdf0e10cSrcweir         browseButton = new javax.swing.JButton();
123cdf0e10cSrcweir 
124cdf0e10cSrcweir         setLayout(new java.awt.GridBagLayout());
125cdf0e10cSrcweir 
126cdf0e10cSrcweir         setPreferredSize(new java.awt.Dimension(600, 300));
127cdf0e10cSrcweir         jLabel1.setText("Installations Detected");
128cdf0e10cSrcweir         gridBagConstraints = new java.awt.GridBagConstraints();
129cdf0e10cSrcweir         gridBagConstraints.gridx = 0;
130cdf0e10cSrcweir         gridBagConstraints.gridy = 0;
131cdf0e10cSrcweir         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
132cdf0e10cSrcweir         gridBagConstraints.insets = new java.awt.Insets(12, 12, 11, 2);
133cdf0e10cSrcweir         add(jLabel1, gridBagConstraints);
134cdf0e10cSrcweir 
135cdf0e10cSrcweir         installPath.setEditable(false);
136cdf0e10cSrcweir         gridBagConstraints = new java.awt.GridBagConstraints();
137cdf0e10cSrcweir         gridBagConstraints.gridx = 1;
138cdf0e10cSrcweir         gridBagConstraints.gridy = 1;
139cdf0e10cSrcweir         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
140cdf0e10cSrcweir         gridBagConstraints.weightx = 1.0;
141cdf0e10cSrcweir         gridBagConstraints.insets = new java.awt.Insets(12, 0, 11, 11);
142cdf0e10cSrcweir         add(installPath, gridBagConstraints);
143cdf0e10cSrcweir 
144cdf0e10cSrcweir         jLabel2.setText("Installation Directory");
145cdf0e10cSrcweir         gridBagConstraints = new java.awt.GridBagConstraints();
146cdf0e10cSrcweir         gridBagConstraints.gridx = 0;
147cdf0e10cSrcweir         gridBagConstraints.gridy = 1;
148cdf0e10cSrcweir         gridBagConstraints.insets = new java.awt.Insets(12, 12, 11, 12);
149cdf0e10cSrcweir         add(jLabel2, gridBagConstraints);
150cdf0e10cSrcweir 
151cdf0e10cSrcweir         gridBagConstraints = new java.awt.GridBagConstraints();
152cdf0e10cSrcweir         gridBagConstraints.gridx = 1;
153cdf0e10cSrcweir         gridBagConstraints.gridy = 0;
154cdf0e10cSrcweir         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
155cdf0e10cSrcweir         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
156cdf0e10cSrcweir         gridBagConstraints.insets = new java.awt.Insets(11, 0, 11, 11);
157cdf0e10cSrcweir         add(installationsComboBox, gridBagConstraints);
158cdf0e10cSrcweir 
159cdf0e10cSrcweir         gridBagConstraints = new java.awt.GridBagConstraints();
160cdf0e10cSrcweir         gridBagConstraints.gridy = 2;
161cdf0e10cSrcweir         gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
162cdf0e10cSrcweir         gridBagConstraints.weighty = 1.0;
163cdf0e10cSrcweir         add(jPanel1, gridBagConstraints);
164cdf0e10cSrcweir 
165cdf0e10cSrcweir         browseButton.setText("Browse...");
166cdf0e10cSrcweir         browseButton.addActionListener(new java.awt.event.ActionListener() {
167cdf0e10cSrcweir             public void actionPerformed(java.awt.event.ActionEvent evt) {
168cdf0e10cSrcweir                 browseButtonActionPerformed(evt);
169cdf0e10cSrcweir             }
170cdf0e10cSrcweir         });
171cdf0e10cSrcweir 
172cdf0e10cSrcweir         gridBagConstraints = new java.awt.GridBagConstraints();
173cdf0e10cSrcweir         gridBagConstraints.gridx = 2;
174cdf0e10cSrcweir         gridBagConstraints.gridy = 1;
175cdf0e10cSrcweir         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
176cdf0e10cSrcweir         add(browseButton, gridBagConstraints);
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     }//GEN-END:initComponents
179cdf0e10cSrcweir 
browseButtonActionPerformed(java.awt.event.ActionEvent evt)180cdf0e10cSrcweir     private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
181cdf0e10cSrcweir         // Add your handling code here:
182cdf0e10cSrcweir         File target = null;
183cdf0e10cSrcweir 
184cdf0e10cSrcweir         JFileChooser chooser = new JFileChooser();
185cdf0e10cSrcweir         chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
186cdf0e10cSrcweir         int result = chooser.showDialog(null, null);
187cdf0e10cSrcweir 
188cdf0e10cSrcweir         if (result == JFileChooser.APPROVE_OPTION) {
189cdf0e10cSrcweir             target = chooser.getSelectedFile();
190cdf0e10cSrcweir 
191cdf0e10cSrcweir             String path;
192cdf0e10cSrcweir             try {
193cdf0e10cSrcweir                 path = target.getCanonicalPath();
194cdf0e10cSrcweir             }
195cdf0e10cSrcweir             catch (IOException ioe) {
196cdf0e10cSrcweir                 path = target.getAbsolutePath();
197cdf0e10cSrcweir             }
198cdf0e10cSrcweir 
199cdf0e10cSrcweir             OfficeInstallation oi = new OfficeInstallation(path, path);
200cdf0e10cSrcweir 
201cdf0e10cSrcweir             if (oi.supportsFramework()) {
202cdf0e10cSrcweir                 installPath.setText(path);
203cdf0e10cSrcweir                 panel.setSelectedPath(oi);
204cdf0e10cSrcweir             }
205cdf0e10cSrcweir         }
206cdf0e10cSrcweir 
207cdf0e10cSrcweir     }//GEN-LAST:event_browseButtonActionPerformed
208cdf0e10cSrcweir 
209cdf0e10cSrcweir     // Variables declaration - do not modify//GEN-BEGIN:variables
210cdf0e10cSrcweir     private javax.swing.JTextField installPath;
211cdf0e10cSrcweir     private javax.swing.JButton browseButton;
212cdf0e10cSrcweir     private javax.swing.JComboBox installationsComboBox;
213cdf0e10cSrcweir     private javax.swing.JLabel jLabel2;
214cdf0e10cSrcweir     private javax.swing.JLabel jLabel1;
215cdf0e10cSrcweir     private javax.swing.JPanel jPanel1;
216cdf0e10cSrcweir     // End of variables declaration//GEN-END:variables
217cdf0e10cSrcweir }
218