001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.projectopener;
043:
044: import java.awt.Cursor;
045: import java.awt.Dimension;
046: import java.awt.Point;
047: import java.awt.Toolkit;
048: import java.io.File;
049: import javax.swing.JFileChooser;
050: import javax.swing.JFrame;
051: import javax.swing.UIManager;
052: import javax.swing.event.DocumentEvent;
053: import javax.swing.event.DocumentListener;
054: import javax.swing.text.BadLocationException;
055: import org.netbeans.projectopener.Utils.DialogDescriptor;
056: import org.netbeans.projectopener.Utils.NBInstallDir;
057:
058: /**
059: *
060: * @author Milan Kubec
061: */
062: public class BrowseNetBeansDialog extends javax.swing.JDialog {
063:
064: private DialogDescriptor dialogDesc;
065: private NBInstallDir nbDir;
066: private String nbVersion;
067:
068: public BrowseNetBeansDialog(DialogDescriptor dd, NBInstallDir dir,
069: String nbVer) {
070: super ((JFrame) null, true);
071: dialogDesc = dd;
072: nbDir = dir;
073: nbVersion = nbVer;
074: try {
075: UIManager.setLookAndFeel(UIManager
076: .getSystemLookAndFeelClassName());
077: } catch (Exception ex) {
078: //
079: }
080: initComponents();
081: getRootPane().setDefaultButton(contButton);
082: setLocation(getCenterPoint());
083: }
084:
085: private String getMessage() {
086: return "<html>Required version "
087: + nbVersion
088: + " of NetBeans IDE was not found on your computer.<br>"
089: + "Do you want to browse required version yourself?</html>";
090: }
091:
092: /** This method is called from within the constructor to
093: * initialize the form.
094: * WARNING: Do NOT modify this code. The content of this method is
095: * always regenerated by the Form Editor.
096: */
097: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
098: private void initComponents() {
099: java.awt.GridBagConstraints gridBagConstraints;
100:
101: jPanel1 = new javax.swing.JPanel();
102: jLabel1 = new javax.swing.JLabel();
103: jLabel2 = new javax.swing.JLabel();
104: dirTextField = new javax.swing.JTextField();
105: browseButton = new javax.swing.JButton();
106: jPanel2 = new javax.swing.JPanel();
107: exitButton = new javax.swing.JButton();
108: contButton = new javax.swing.JButton();
109: jPanel3 = new javax.swing.JPanel();
110: jLabel3 = new javax.swing.JLabel();
111: linkLabel = new javax.swing.JLabel();
112:
113: setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
114: java.util.ResourceBundle bundle = java.util.ResourceBundle
115: .getBundle("org/netbeans/projectopener/Bundle"); // NOI18N
116: setTitle(bundle.getString("BrowseNBDialogTitle")); // NOI18N
117: setMinimumSize(new java.awt.Dimension(450, 23));
118:
119: jPanel1.setMinimumSize(new java.awt.Dimension(250, 23));
120: jPanel1.setLayout(new java.awt.GridBagLayout());
121:
122: jLabel1.setText(getMessage());
123: gridBagConstraints = new java.awt.GridBagConstraints();
124: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
125: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
126: gridBagConstraints.insets = new java.awt.Insets(8, 8, 12, 8);
127: jPanel1.add(jLabel1, gridBagConstraints);
128:
129: jLabel2.setText(bundle.getString("InstallDirLabel")); // NOI18N
130: gridBagConstraints = new java.awt.GridBagConstraints();
131: gridBagConstraints.gridx = 0;
132: gridBagConstraints.gridy = 1;
133: gridBagConstraints.insets = new java.awt.Insets(0, 8, 0, 0);
134: jPanel1.add(jLabel2, gridBagConstraints);
135:
136: dirTextField.setMinimumSize(new java.awt.Dimension(250, 20));
137: dirTextField.setPreferredSize(new java.awt.Dimension(300, 20));
138: dirTextField.getDocument().addDocumentListener(
139: new DocListener());
140: gridBagConstraints = new java.awt.GridBagConstraints();
141: gridBagConstraints.gridx = 1;
142: gridBagConstraints.gridy = 1;
143: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
144: gridBagConstraints.weightx = 1.0;
145: gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 0);
146: jPanel1.add(dirTextField, gridBagConstraints);
147:
148: browseButton.setMnemonic(java.util.ResourceBundle.getBundle(
149: "org/netbeans/projectopener/Bundle").getString(
150: "BrowseButtonLabel").charAt(0));
151: browseButton.setText(bundle.getString("BrowseButtonLabel")); // NOI18N
152: browseButton
153: .addActionListener(new java.awt.event.ActionListener() {
154: public void actionPerformed(
155: java.awt.event.ActionEvent evt) {
156: browseButtonActionPerformed(evt);
157: }
158: });
159: gridBagConstraints = new java.awt.GridBagConstraints();
160: gridBagConstraints.gridx = 2;
161: gridBagConstraints.gridy = 1;
162: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
163: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
164: gridBagConstraints.insets = new java.awt.Insets(0, 8, 1, 8);
165: jPanel1.add(browseButton, gridBagConstraints);
166:
167: jPanel2.setLayout(new java.awt.GridBagLayout());
168:
169: exitButton.setText(bundle.getString("ExitButtonLabel")); // NOI18N
170: exitButton
171: .addActionListener(new java.awt.event.ActionListener() {
172: public void actionPerformed(
173: java.awt.event.ActionEvent evt) {
174: exitButtonActionPerformed(evt);
175: }
176: });
177: gridBagConstraints = new java.awt.GridBagConstraints();
178: gridBagConstraints.gridx = 1;
179: gridBagConstraints.gridy = 0;
180: gridBagConstraints.insets = new java.awt.Insets(0, 8, 8, 8);
181: jPanel2.add(exitButton, gridBagConstraints);
182:
183: contButton.setText(bundle.getString("ContinueButtonLabel")); // NOI18N
184: contButton
185: .addActionListener(new java.awt.event.ActionListener() {
186: public void actionPerformed(
187: java.awt.event.ActionEvent evt) {
188: contButtonActionPerformed(evt);
189: }
190: });
191: gridBagConstraints = new java.awt.GridBagConstraints();
192: gridBagConstraints.gridx = 0;
193: gridBagConstraints.insets = new java.awt.Insets(0, 0, 8, 0);
194: jPanel2.add(contButton, gridBagConstraints);
195: contButton.setEnabled(false);
196:
197: gridBagConstraints = new java.awt.GridBagConstraints();
198: gridBagConstraints.gridx = 1;
199: gridBagConstraints.gridy = 3;
200: gridBagConstraints.gridwidth = 2;
201: gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
202: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
203: gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
204: jPanel1.add(jPanel2, gridBagConstraints);
205:
206: jPanel3.setLayout(new java.awt.GridBagLayout());
207:
208: jLabel3
209: .setText("NetBeans IDE Installer can be downloaded from");
210: gridBagConstraints = new java.awt.GridBagConstraints();
211: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
212: gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
213: jPanel3.add(jLabel3, gridBagConstraints);
214:
215: linkLabel
216: .setText("<html><a href=\"#anchor\">NetBeans Download Site</a></html>");
217: linkLabel.setToolTipText(bundle.getString("URL_Download_NB")); // NOI18N
218: linkLabel.addMouseListener(new java.awt.event.MouseAdapter() {
219: public void mouseClicked(java.awt.event.MouseEvent evt) {
220: linkLabelMouseClicked(evt);
221: }
222: });
223: gridBagConstraints = new java.awt.GridBagConstraints();
224: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
225: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
226: gridBagConstraints.weightx = 0.5;
227: gridBagConstraints.insets = new java.awt.Insets(6, 4, 0, 0);
228: jPanel3.add(linkLabel, gridBagConstraints);
229: linkLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
230:
231: gridBagConstraints = new java.awt.GridBagConstraints();
232: gridBagConstraints.gridwidth = 3;
233: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
234: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
235: gridBagConstraints.insets = new java.awt.Insets(6, 8, 4, 8);
236: jPanel1.add(jPanel3, gridBagConstraints);
237:
238: getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
239:
240: pack();
241: }// </editor-fold>//GEN-END:initComponents
242:
243: private void linkLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_linkLabelMouseClicked
244: dialogDesc.setValue(DialogDescriptor.DOWNLOAD);
245: setVisible(false);
246: }//GEN-LAST:event_linkLabelMouseClicked
247:
248: private void exitButtonActionPerformed(
249: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitButtonActionPerformed
250: dialogDesc.setValue(DialogDescriptor.EXIT);
251: setVisible(false);
252: }//GEN-LAST:event_exitButtonActionPerformed
253:
254: private void contButtonActionPerformed(
255: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_contButtonActionPerformed
256: dialogDesc.setValue(DialogDescriptor.CONTINUE);
257: nbDir.setInstallDir(new File(dirTextField.getText()));
258: setVisible(false);
259: }//GEN-LAST:event_contButtonActionPerformed
260:
261: private void browseButtonActionPerformed(
262: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
263: JFileChooser chooser = new JFileChooser();
264: chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
265: chooser.setMultiSelectionEnabled(false);
266: // chooser.setSelectedFile(new File(""));
267: chooser.setDialogTitle("Browse NetBeans installation");
268: if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this )) {
269: File file = chooser.getSelectedFile();
270: // XXX do validation of entered userdir ???
271: dirTextField.setText(file.getAbsolutePath());
272: }
273: }//GEN-LAST:event_browseButtonActionPerformed
274:
275: // XXX this method should be moved to Utils
276: private Point getCenterPoint() {
277: Toolkit toolkit = Toolkit.getDefaultToolkit();
278: Dimension screenSize = toolkit.getScreenSize();
279: int x = (screenSize.width - getWidth() - getInsets().left - getInsets().right) / 2;
280: int y = (screenSize.height - getHeight() - getInsets().top - getInsets().bottom) / 2;
281: return new Point(x, y);
282: }
283:
284: private class DocListener implements DocumentListener {
285: public void insertUpdate(DocumentEvent de) {
286: update(de);
287: }
288:
289: public void removeUpdate(DocumentEvent de) {
290: update(de);
291: }
292:
293: public void changedUpdate(DocumentEvent de) {
294: update(de);
295: }
296:
297: private void update(DocumentEvent de) {
298: String text = null;
299: try {
300: text = de.getDocument().getText(0,
301: de.getDocument().getLength());
302: } catch (BadLocationException ex) {
303: //
304: }
305: File f = new File(text);
306: if (f.exists() && f.isDirectory()) {
307: contButton.setEnabled(true);
308: } else {
309: contButton.setEnabled(false);
310: }
311: }
312: }
313:
314: // Variables declaration - do not modify//GEN-BEGIN:variables
315: private javax.swing.JButton browseButton;
316: private javax.swing.JButton contButton;
317: private javax.swing.JTextField dirTextField;
318: private javax.swing.JButton exitButton;
319: private javax.swing.JLabel jLabel1;
320: private javax.swing.JLabel jLabel2;
321: private javax.swing.JLabel jLabel3;
322: private javax.swing.JPanel jPanel1;
323: private javax.swing.JPanel jPanel2;
324: private javax.swing.JPanel jPanel3;
325: private javax.swing.JLabel linkLabel;
326: // End of variables declaration//GEN-END:variables
327:
328: }
|