~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to ide/projectopener/src/org/netbeans/projectopener/BrowseNetBeansDialog.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
6
 * The contents of this file are subject to the terms of either the GNU
 
7
 * General Public License Version 2 only ("GPL") or the Common
 
8
 * Development and Distribution License("CDDL") (collectively, the
 
9
 * "License"). You may not use this file except in compliance with the
 
10
 * License. You can obtain a copy of the License at
 
11
 * http://www.netbeans.org/cddl-gplv2.html
 
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
 
13
 * specific language governing permissions and limitations under the
 
14
 * License.  When distributing the software, include this License Header
 
15
 * Notice in each file and include the License file at
 
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
 
17
 * particular file as subject to the "Classpath" exception as provided
 
18
 * by Sun in the GPL Version 2 section of the License file that
 
19
 * accompanied this code. If applicable, add the following below the
 
20
 * License Header, with the fields enclosed by brackets [] replaced by
 
21
 * your own identifying information:
 
22
 * "Portions Copyrighted [year] [name of copyright owner]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
26
 * The Original Software is NetBeans. The Initial Developer of the Original
 
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
 
28
 * Microsystems, Inc. All Rights Reserved.
 
29
 *
 
30
 * If you wish your version of this file to be governed by only the CDDL
 
31
 * or only the GPL Version 2, indicate your decision by adding
 
32
 * "[Contributor] elects to include this software in this distribution
 
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
 
34
 * single choice of license, a recipient has the option to distribute
 
35
 * your version of this file under either the CDDL, the GPL Version 2 or
 
36
 * to extend the choice of license to its licensees as provided above.
 
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
 
38
 * Version 2 license, then the option applies only if the new code is
 
39
 * made subject to such option by the copyright holder.
 
40
 */
 
41
 
 
42
package org.netbeans.projectopener;
 
43
 
 
44
import java.awt.Cursor;
 
45
import java.awt.Dimension;
 
46
import java.awt.Point;
 
47
import java.awt.Toolkit;
 
48
import java.io.File;
 
49
import javax.swing.JFileChooser;
 
50
import javax.swing.JFrame;
 
51
import javax.swing.UIManager;
 
52
import javax.swing.event.DocumentEvent;
 
53
import javax.swing.event.DocumentListener;
 
54
import javax.swing.text.BadLocationException;
 
55
import org.netbeans.projectopener.Utils.DialogDescriptor;
 
56
import org.netbeans.projectopener.Utils.NBInstallDir;
 
57
 
 
58
/**
 
59
 *
 
60
 * @author  Milan Kubec
 
61
 */
 
62
public class BrowseNetBeansDialog extends javax.swing.JDialog {
 
63
    
 
64
    private DialogDescriptor dialogDesc;
 
65
    private NBInstallDir nbDir;
 
66
    private String nbVersion;
 
67
    
 
68
    public BrowseNetBeansDialog(DialogDescriptor dd, NBInstallDir dir, String nbVer) {
 
69
        super((JFrame) null, true);
 
70
        dialogDesc = dd;
 
71
        nbDir = dir;
 
72
        nbVersion = nbVer;
 
73
        try {
 
74
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
 
75
        } catch (Exception ex) {
 
76
            //
 
77
        }
 
78
        initComponents();
 
79
        getRootPane().setDefaultButton(contButton);
 
80
        setLocation(getCenterPoint());
 
81
    }
 
82
    
 
83
    private String getMessage() {
 
84
        return "<html>Required version " + nbVersion + " of NetBeans IDE was not found on your computer.<br>" +
 
85
                "Do you want to browse required version yourself?</html>";
 
86
    }
 
87
    
 
88
    /** This method is called from within the constructor to
 
89
     * initialize the form.
 
90
     * WARNING: Do NOT modify this code. The content of this method is
 
91
     * always regenerated by the Form Editor.
 
92
     */
 
93
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
 
94
    private void initComponents() {
 
95
        java.awt.GridBagConstraints gridBagConstraints;
 
96
 
 
97
        jPanel1 = new javax.swing.JPanel();
 
98
        jLabel1 = new javax.swing.JLabel();
 
99
        jLabel2 = new javax.swing.JLabel();
 
100
        dirTextField = new javax.swing.JTextField();
 
101
        browseButton = new javax.swing.JButton();
 
102
        jPanel2 = new javax.swing.JPanel();
 
103
        exitButton = new javax.swing.JButton();
 
104
        contButton = new javax.swing.JButton();
 
105
        jPanel3 = new javax.swing.JPanel();
 
106
        jLabel3 = new javax.swing.JLabel();
 
107
        linkLabel = new javax.swing.JLabel();
 
108
 
 
109
        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
 
110
        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/netbeans/projectopener/Bundle"); // NOI18N
 
111
        setTitle(bundle.getString("BrowseNBDialogTitle")); // NOI18N
 
112
        setMinimumSize(new java.awt.Dimension(450, 23));
 
113
 
 
114
        jPanel1.setMinimumSize(new java.awt.Dimension(250, 23));
 
115
        jPanel1.setLayout(new java.awt.GridBagLayout());
 
116
 
 
117
        jLabel1.setText(getMessage());
 
118
        gridBagConstraints = new java.awt.GridBagConstraints();
 
119
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
 
120
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
 
121
        gridBagConstraints.insets = new java.awt.Insets(8, 8, 12, 8);
 
122
        jPanel1.add(jLabel1, gridBagConstraints);
 
123
 
 
124
        jLabel2.setText(bundle.getString("InstallDirLabel")); // NOI18N
 
125
        gridBagConstraints = new java.awt.GridBagConstraints();
 
126
        gridBagConstraints.gridx = 0;
 
127
        gridBagConstraints.gridy = 1;
 
128
        gridBagConstraints.insets = new java.awt.Insets(0, 8, 0, 0);
 
129
        jPanel1.add(jLabel2, gridBagConstraints);
 
130
 
 
131
        dirTextField.setMinimumSize(new java.awt.Dimension(250, 20));
 
132
        dirTextField.setPreferredSize(new java.awt.Dimension(300, 20));
 
133
        dirTextField.getDocument().addDocumentListener(new DocListener());
 
134
        gridBagConstraints = new java.awt.GridBagConstraints();
 
135
        gridBagConstraints.gridx = 1;
 
136
        gridBagConstraints.gridy = 1;
 
137
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
 
138
        gridBagConstraints.weightx = 1.0;
 
139
        gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 0);
 
140
        jPanel1.add(dirTextField, gridBagConstraints);
 
141
 
 
142
        browseButton.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/projectopener/Bundle").getString("BrowseButtonLabel").charAt(0));
 
143
        browseButton.setText(bundle.getString("BrowseButtonLabel")); // NOI18N
 
144
        browseButton.addActionListener(new java.awt.event.ActionListener() {
 
145
            public void actionPerformed(java.awt.event.ActionEvent evt) {
 
146
                browseButtonActionPerformed(evt);
 
147
            }
 
148
        });
 
149
        gridBagConstraints = new java.awt.GridBagConstraints();
 
150
        gridBagConstraints.gridx = 2;
 
151
        gridBagConstraints.gridy = 1;
 
152
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
 
153
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
 
154
        gridBagConstraints.insets = new java.awt.Insets(0, 8, 1, 8);
 
155
        jPanel1.add(browseButton, gridBagConstraints);
 
156
 
 
157
        jPanel2.setLayout(new java.awt.GridBagLayout());
 
158
 
 
159
        exitButton.setText(bundle.getString("ExitButtonLabel")); // NOI18N
 
160
        exitButton.addActionListener(new java.awt.event.ActionListener() {
 
161
            public void actionPerformed(java.awt.event.ActionEvent evt) {
 
162
                exitButtonActionPerformed(evt);
 
163
            }
 
164
        });
 
165
        gridBagConstraints = new java.awt.GridBagConstraints();
 
166
        gridBagConstraints.gridx = 1;
 
167
        gridBagConstraints.gridy = 0;
 
168
        gridBagConstraints.insets = new java.awt.Insets(0, 8, 8, 8);
 
169
        jPanel2.add(exitButton, gridBagConstraints);
 
170
 
 
171
        contButton.setText(bundle.getString("ContinueButtonLabel")); // NOI18N
 
172
        contButton.addActionListener(new java.awt.event.ActionListener() {
 
173
            public void actionPerformed(java.awt.event.ActionEvent evt) {
 
174
                contButtonActionPerformed(evt);
 
175
            }
 
176
        });
 
177
        gridBagConstraints = new java.awt.GridBagConstraints();
 
178
        gridBagConstraints.gridx = 0;
 
179
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 8, 0);
 
180
        jPanel2.add(contButton, gridBagConstraints);
 
181
        contButton.setEnabled(false);
 
182
 
 
183
        gridBagConstraints = new java.awt.GridBagConstraints();
 
184
        gridBagConstraints.gridx = 1;
 
185
        gridBagConstraints.gridy = 3;
 
186
        gridBagConstraints.gridwidth = 2;
 
187
        gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
 
188
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
 
189
        gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
 
190
        jPanel1.add(jPanel2, gridBagConstraints);
 
191
 
 
192
        jPanel3.setLayout(new java.awt.GridBagLayout());
 
193
 
 
194
        jLabel3.setText("NetBeans IDE Installer can be downloaded from");
 
195
        gridBagConstraints = new java.awt.GridBagConstraints();
 
196
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
 
197
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
 
198
        jPanel3.add(jLabel3, gridBagConstraints);
 
199
 
 
200
        linkLabel.setText("<html><a href=\"#anchor\">NetBeans Download Site</a></html>");
 
201
        linkLabel.setToolTipText(bundle.getString("URL_Download_NB")); // NOI18N
 
202
        linkLabel.addMouseListener(new java.awt.event.MouseAdapter() {
 
203
            public void mouseClicked(java.awt.event.MouseEvent evt) {
 
204
                linkLabelMouseClicked(evt);
 
205
            }
 
206
        });
 
207
        gridBagConstraints = new java.awt.GridBagConstraints();
 
208
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
 
209
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
 
210
        gridBagConstraints.weightx = 0.5;
 
211
        gridBagConstraints.insets = new java.awt.Insets(6, 4, 0, 0);
 
212
        jPanel3.add(linkLabel, gridBagConstraints);
 
213
        linkLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
 
214
 
 
215
        gridBagConstraints = new java.awt.GridBagConstraints();
 
216
        gridBagConstraints.gridwidth = 3;
 
217
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
 
218
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
 
219
        gridBagConstraints.insets = new java.awt.Insets(6, 8, 4, 8);
 
220
        jPanel1.add(jPanel3, gridBagConstraints);
 
221
 
 
222
        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
 
223
 
 
224
        pack();
 
225
    }// </editor-fold>//GEN-END:initComponents
 
226
 
 
227
private void linkLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_linkLabelMouseClicked
 
228
    dialogDesc.setValue(DialogDescriptor.DOWNLOAD);
 
229
    setVisible(false);
 
230
}//GEN-LAST:event_linkLabelMouseClicked
 
231
 
 
232
private void exitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitButtonActionPerformed
 
233
    dialogDesc.setValue(DialogDescriptor.EXIT);
 
234
    setVisible(false);
 
235
}//GEN-LAST:event_exitButtonActionPerformed
 
236
 
 
237
private void contButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_contButtonActionPerformed
 
238
    dialogDesc.setValue(DialogDescriptor.CONTINUE);
 
239
    nbDir.setInstallDir(new File(dirTextField.getText()));
 
240
    setVisible(false);
 
241
}//GEN-LAST:event_contButtonActionPerformed
 
242
 
 
243
private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
 
244
    JFileChooser chooser = new JFileChooser();
 
245
    chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY);
 
246
    chooser.setMultiSelectionEnabled(false);
 
247
    // chooser.setSelectedFile(new File(""));
 
248
    chooser.setDialogTitle("Browse NetBeans installation");
 
249
    if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
 
250
        File file = chooser.getSelectedFile();
 
251
        // XXX do validation of entered userdir ???
 
252
        dirTextField.setText(file.getAbsolutePath());
 
253
    }
 
254
}//GEN-LAST:event_browseButtonActionPerformed
 
255
    
 
256
    // XXX this method should be moved to Utils
 
257
    private Point getCenterPoint() {
 
258
        Toolkit toolkit = Toolkit.getDefaultToolkit();
 
259
        Dimension screenSize = toolkit.getScreenSize();
 
260
        int x = (screenSize.width - getWidth() - getInsets().left - getInsets().right) / 2;
 
261
        int y = (screenSize.height - getHeight() - getInsets().top - getInsets().bottom) / 2;
 
262
        return new Point(x, y);
 
263
    }
 
264
    
 
265
    private class DocListener implements DocumentListener {
 
266
        public void insertUpdate(DocumentEvent de) {
 
267
            update(de);
 
268
        }
 
269
        public void removeUpdate(DocumentEvent de) {
 
270
            update(de);
 
271
        }
 
272
        public void changedUpdate(DocumentEvent de) {
 
273
            update(de);
 
274
        }
 
275
        private void update(DocumentEvent de) {
 
276
            String text = null;
 
277
            try {
 
278
                text = de.getDocument().getText(0, de.getDocument().getLength());
 
279
            } catch (BadLocationException ex) {
 
280
                //
 
281
            }
 
282
            File f = new File(text);
 
283
            if (f.exists() && f.isDirectory()) {
 
284
                contButton.setEnabled(true);
 
285
            } else {
 
286
                contButton.setEnabled(false);
 
287
            }
 
288
        }
 
289
    }
 
290
    
 
291
    // Variables declaration - do not modify//GEN-BEGIN:variables
 
292
    private javax.swing.JButton browseButton;
 
293
    private javax.swing.JButton contButton;
 
294
    private javax.swing.JTextField dirTextField;
 
295
    private javax.swing.JButton exitButton;
 
296
    private javax.swing.JLabel jLabel1;
 
297
    private javax.swing.JLabel jLabel2;
 
298
    private javax.swing.JLabel jLabel3;
 
299
    private javax.swing.JPanel jPanel1;
 
300
    private javax.swing.JPanel jPanel2;
 
301
    private javax.swing.JPanel jPanel3;
 
302
    private javax.swing.JLabel linkLabel;
 
303
    // End of variables declaration//GEN-END:variables
 
304
    
 
305
}