2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
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]"
26 * The Original Software is NetBeans. The Initial Developer of the Original
27 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28 * Microsystems, Inc. All Rights Reserved.
29 * Portions Copyright 2008 Alexander Coles (Ikonoklastik Productions).
31 * If you wish your version of this file to be governed by only the CDDL
32 * or only the GPL Version 2, indicate your decision by adding
33 * "[Contributor] elects to include this software in this distribution
34 * under the [CDDL or GPL Version 2] license." If you do not indicate a
35 * single choice of license, a recipient has the option to distribute
36 * your version of this file under either the CDDL, the GPL Version 2 or
37 * to extend the choice of license to its licensees as provided above.
38 * However, if you add GPL Version 2 code and therefore, elected the GPL
39 * Version 2 license, then the option applies only if the new code is
40 * made subject to such option by the copyright holder.
42 package org
.netbeans
.modules
.git
.ui
.clone
;
44 import java
.awt
.event
.ActionEvent
;
45 import java
.awt
.event
.ActionListener
;
47 import javax
.swing
.JFileChooser
;
48 import javax
.swing
.filechooser
.FileFilter
;
49 import org
.netbeans
.modules
.git
.GitModuleConfig
;
50 import org
.netbeans
.modules
.versioning
.util
.AccessibleJFileChooser
;
51 import org
.netbeans
.spi
.project
.ui
.support
.ProjectChooser
;
52 import org
.openide
.util
.NbBundle
;
56 * @author Padraig O'Briain
58 public class ClonePanel
extends javax
.swing
.JPanel
implements ActionListener
{
60 private File repository
;
62 /** Creates new form ClonePanel */
63 public ClonePanel(File repo
, File to
) {
66 browseButton
.addActionListener(this);
67 setMainCheckBox
.addActionListener(this);
68 fromTextField
.setText(repo
.getAbsolutePath());
69 toTextField
.setText(to
.getParent());
70 toCloneField
.setText(to
.getName());
71 setMainCheckBox
.setSelected(GitModuleConfig
.getDefault().getSetMainProject());
74 public String
getOutputFileName() {
75 File target
= new File(toTextField
.getText(), toCloneField
.getText());
76 return target
.getAbsolutePath();
79 /** This method is called from within the constructor to
80 * initialize the form.
81 * WARNING: Do NOT modify this code. The content of this method is
82 * always regenerated by the Form Editor.
84 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
85 private void initComponents() {
87 fromLabel
= new javax
.swing
.JLabel();
88 toLabel
= new javax
.swing
.JLabel();
89 browseButton
= new javax
.swing
.JButton();
90 fromTextField
= new javax
.swing
.JTextField();
91 toNameLabel
= new javax
.swing
.JLabel();
92 toCloneField
= new javax
.swing
.JTextField();
93 destinationLabel
= new javax
.swing
.JLabel();
94 setMainCheckBox
= new javax
.swing
.JCheckBox();
96 fromLabel
.setLabelFor(fromTextField
);
97 org
.openide
.awt
.Mnemonics
.setLocalizedText(fromLabel
, org
.openide
.util
.NbBundle
.getMessage(ClonePanel
.class, "ClonePanel.fromLabel.text")); // NOI18N
99 toLabel
.setLabelFor(toTextField
);
100 org
.openide
.awt
.Mnemonics
.setLocalizedText(toLabel
, org
.openide
.util
.NbBundle
.getMessage(ClonePanel
.class, "ClonePanel.toLabel.text")); // NOI18N
102 org
.openide
.awt
.Mnemonics
.setLocalizedText(browseButton
, org
.openide
.util
.NbBundle
.getMessage(ClonePanel
.class, "ClonePanel.browseButton.text")); // NOI18N
104 fromTextField
.setEditable(false);
106 toNameLabel
.setLabelFor(toCloneField
);
107 org
.openide
.awt
.Mnemonics
.setLocalizedText(toNameLabel
, org
.openide
.util
.NbBundle
.getMessage(ClonePanel
.class, "ClonePanel.toName.text")); // NOI18N
109 org
.openide
.awt
.Mnemonics
.setLocalizedText(destinationLabel
, org
.openide
.util
.NbBundle
.getMessage(ClonePanel
.class, "destinationLabel.text")); // NOI18N
111 org
.openide
.awt
.Mnemonics
.setLocalizedText(setMainCheckBox
, org
.openide
.util
.NbBundle
.getMessage(ClonePanel
.class, "openCheckbox.text")); // NOI18N
113 org
.jdesktop
.layout
.GroupLayout layout
= new org
.jdesktop
.layout
.GroupLayout(this);
114 this.setLayout(layout
);
115 layout
.setHorizontalGroup(
116 layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.LEADING
)
117 .add(layout
.createSequentialGroup()
119 .add(layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.LEADING
)
120 .add(destinationLabel
)
122 .add(layout
.createSequentialGroup()
124 .add(layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.LEADING
)
126 .add(setMainCheckBox
)))
127 .add(layout
.createSequentialGroup()
130 .addPreferredGap(org
.jdesktop
.layout
.LayoutStyle
.RELATED
)
131 .add(layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.LEADING
)
132 .add(fromTextField
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, 270, Short
.MAX_VALUE
)
133 .add(org
.jdesktop
.layout
.GroupLayout
.TRAILING
, layout
.createSequentialGroup()
134 .add(layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.TRAILING
)
135 .add(toCloneField
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, 165, Short
.MAX_VALUE
)
136 .add(toTextField
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, 165, Short
.MAX_VALUE
))
137 .addPreferredGap(org
.jdesktop
.layout
.LayoutStyle
.RELATED
)
141 layout
.setVerticalGroup(
142 layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.LEADING
)
143 .add(layout
.createSequentialGroup()
145 .add(layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.BASELINE
)
147 .add(fromTextField
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
))
149 .add(destinationLabel
)
150 .addPreferredGap(org
.jdesktop
.layout
.LayoutStyle
.RELATED
)
151 .add(layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.BASELINE
)
153 .add(toTextField
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
)
155 .addPreferredGap(org
.jdesktop
.layout
.LayoutStyle
.RELATED
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, Short
.MAX_VALUE
)
156 .add(layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.BASELINE
)
157 .add(toCloneField
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
)
159 .addPreferredGap(org
.jdesktop
.layout
.LayoutStyle
.RELATED
)
160 .add(setMainCheckBox
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
, 21, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
)
164 toTextField
.getAccessibleContext().setAccessibleDescription(org
.openide
.util
.NbBundle
.getMessage(ClonePanel
.class, "ACSD_toTextField")); // NOI18N
165 browseButton
.getAccessibleContext().setAccessibleDescription(org
.openide
.util
.NbBundle
.getMessage(ClonePanel
.class, "ACSD_Browse")); // NOI18N
166 fromTextField
.getAccessibleContext().setAccessibleDescription(org
.openide
.util
.NbBundle
.getMessage(ClonePanel
.class, "ACSD_fromTextField")); // NOI18N
167 toCloneField
.getAccessibleContext().setAccessibleDescription(org
.openide
.util
.NbBundle
.getMessage(ClonePanel
.class, "ACSD_toCloneField")); // NOI18N
168 setMainCheckBox
.getAccessibleContext().setAccessibleDescription(org
.openide
.util
.NbBundle
.getMessage(ClonePanel
.class, "ACSD_setMainCheckBox")); // NOI18N
169 }// </editor-fold>//GEN-END:initComponents
172 public void actionPerformed(ActionEvent evt
) {
173 if (evt
.getSource() == browseButton
) {
175 } else if (evt
.getSource() == setMainCheckBox
) {
176 GitModuleConfig
.getDefault().setSetMainProject(setMainCheckBox
.isSelected());
180 private void onBrowseClick() {
181 File oldFile
= defaultWorkingDirectory();
182 JFileChooser fileChooser
= new AccessibleJFileChooser(NbBundle
.getMessage(ClonePanel
.class, "ACSD_BrowseFolder"), oldFile
); // NO I18N
183 fileChooser
.setDialogTitle(NbBundle
.getMessage(ClonePanel
.class, "Browse_title")); // NO I18N
184 fileChooser
.setMultiSelectionEnabled(false);
185 FileFilter
[] old
= fileChooser
.getChoosableFileFilters();
186 for (int i
= 0; i
< old
.length
; i
++) {
187 FileFilter fileFilter
= old
[i
];
188 fileChooser
.removeChoosableFileFilter(fileFilter
);
191 fileChooser
.addChoosableFileFilter(new FileFilter() {
192 public boolean accept(File f
) {
193 return f
.isDirectory();
195 public String
getDescription() {
196 return NbBundle
.getMessage(ClonePanel
.class, "Folders");// NOI18N
199 fileChooser
.setFileSelectionMode(JFileChooser
.DIRECTORIES_ONLY
);
200 fileChooser
.showDialog(this, NbBundle
.getMessage(ClonePanel
.class, "OK_Button")); // NO I18N
201 File f
= fileChooser
.getSelectedFile();
203 toTextField
.setText(f
.getAbsolutePath());
207 * Returns file to be initally used.
209 * <li>first is takes text in workTextField
210 * <li>then recent project folder
211 * <li>finally <tt>user.home</tt>
214 private File
defaultWorkingDirectory() {
215 File defaultDir
= null;
216 String current
= toTextField
.getText();
217 if (current
!= null && !(current
.trim().equals(""))) { // NOI18N
218 File currentFile
= new File(current
);
219 while (currentFile
!= null && currentFile
.exists() == false) {
220 currentFile
= currentFile
.getParentFile();
222 if (currentFile
!= null) {
223 if (currentFile
.isFile()) {
224 defaultDir
= currentFile
.getParentFile();
226 defaultDir
= currentFile
;
231 if (defaultDir
== null) {
232 File projectFolder
= ProjectChooser
.getProjectsFolder();
233 if (projectFolder
.exists() && projectFolder
.isDirectory()) {
234 defaultDir
= projectFolder
;
239 if (defaultDir
== null) {
240 defaultDir
= new File(System
.getProperty("user.home")); // NOI18N
246 // Variables declaration - do not modify//GEN-BEGIN:variables
247 private javax
.swing
.JButton browseButton
;
248 private javax
.swing
.JLabel destinationLabel
;
249 private javax
.swing
.JLabel fromLabel
;
250 private javax
.swing
.JTextField fromTextField
;
251 private javax
.swing
.JCheckBox setMainCheckBox
;
252 private javax
.swing
.JTextField toCloneField
;
253 private javax
.swing
.JLabel toLabel
;
254 private javax
.swing
.JLabel toNameLabel
;
255 final javax
.swing
.JTextField toTextField
= new javax
.swing
.JTextField();
256 // End of variables declaration//GEN-END:variables