PageRenderTime 27ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/netbeans-7.3/mercurial/src/org/netbeans/modules/mercurial/ui/clone/ClonePanel.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 244 lines | 155 code | 25 blank | 64 comment | 22 complexity | e0be1792103309863c70ed46faf6a209 MD5 | raw file
  1. /*
  2. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  3. *
  4. * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
  5. *
  6. * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  7. * Other names may be trademarks of their respective owners.
  8. *
  9. * The contents of this file are subject to the terms of either the GNU
  10. * General Public License Version 2 only ("GPL") or the Common
  11. * Development and Distribution License("CDDL") (collectively, the
  12. * "License"). You may not use this file except in compliance with the
  13. * License. You can obtain a copy of the License at
  14. * http://www.netbeans.org/cddl-gplv2.html
  15. * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  16. * specific language governing permissions and limitations under the
  17. * License. When distributing the software, include this License Header
  18. * Notice in each file and include the License file at
  19. * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
  20. * particular file as subject to the "Classpath" exception as provided
  21. * by Oracle in the GPL Version 2 section of the License file that
  22. * accompanied this code. If applicable, add the following below the
  23. * License Header, with the fields enclosed by brackets [] replaced by
  24. * your own identifying information:
  25. * "Portions Copyrighted [year] [name of copyright owner]"
  26. *
  27. * Contributor(s):
  28. *
  29. * The Original Software is NetBeans. The Initial Developer of the Original
  30. * Software is Sun Microsystems, Inc. Portions Copyright 1997-2009 Sun
  31. * Microsystems, Inc. All Rights Reserved.
  32. *
  33. * If you wish your version of this file to be governed by only the CDDL
  34. * or only the GPL Version 2, indicate your decision by adding
  35. * "[Contributor] elects to include this software in this distribution
  36. * under the [CDDL or GPL Version 2] license." If you do not indicate a
  37. * single choice of license, a recipient has the option to distribute
  38. * your version of this file under either the CDDL, the GPL Version 2 or
  39. * to extend the choice of license to its licensees as provided above.
  40. * However, if you add GPL Version 2 code and therefore, elected the GPL
  41. * Version 2 license, then the option applies only if the new code is
  42. * made subject to such option by the copyright holder.
  43. */
  44. package org.netbeans.modules.mercurial.ui.clone;
  45. import java.io.File;
  46. import java.awt.event.ActionEvent;
  47. import java.awt.event.ActionListener;
  48. import javax.swing.JFileChooser;
  49. import javax.swing.filechooser.FileFilter;
  50. import org.openide.util.NbBundle;
  51. import org.netbeans.modules.versioning.util.AccessibleJFileChooser;
  52. import org.netbeans.spi.project.ui.support.ProjectChooser;
  53. /**
  54. *
  55. * @author Padraig O'Briain
  56. */
  57. public class ClonePanel extends javax.swing.JPanel implements ActionListener {
  58. private File repository;
  59. /** Creates new form ClonePanel */
  60. public ClonePanel(File repo, File to) {
  61. repository = repo;
  62. initComponents();
  63. browseButton.addActionListener(this);
  64. fromTextField.setText(repo.getAbsolutePath());
  65. toTextField.setText(to.getParent());
  66. toCloneField.setText(to.getName());
  67. }
  68. public File getTargetDir() {
  69. return new File(toTextField.getText(), toCloneField.getText());
  70. }
  71. /** This method is called from within the constructor to
  72. * initialize the form.
  73. * WARNING: Do NOT modify this code. The content of this method is
  74. * always regenerated by the Form Editor.
  75. */
  76. // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  77. private void initComponents() {
  78. fromLabel = new javax.swing.JLabel();
  79. toLabel = new javax.swing.JLabel();
  80. browseButton = new javax.swing.JButton();
  81. fromTextField = new javax.swing.JTextField();
  82. toNameLabel = new javax.swing.JLabel();
  83. toCloneField = new javax.swing.JTextField();
  84. destinationLabel = new javax.swing.JLabel();
  85. fromLabel.setLabelFor(fromTextField);
  86. org.openide.awt.Mnemonics.setLocalizedText(fromLabel, org.openide.util.NbBundle.getMessage(ClonePanel.class, "ClonePanel.fromLabel.text")); // NOI18N
  87. toLabel.setLabelFor(toTextField);
  88. org.openide.awt.Mnemonics.setLocalizedText(toLabel, org.openide.util.NbBundle.getMessage(ClonePanel.class, "ClonePanel.toLabel.text")); // NOI18N
  89. org.openide.awt.Mnemonics.setLocalizedText(browseButton, org.openide.util.NbBundle.getMessage(ClonePanel.class, "ClonePanel.browseButton.text")); // NOI18N
  90. fromTextField.setEditable(false);
  91. toNameLabel.setLabelFor(toCloneField);
  92. org.openide.awt.Mnemonics.setLocalizedText(toNameLabel, org.openide.util.NbBundle.getMessage(ClonePanel.class, "ClonePanel.toName.text")); // NOI18N
  93. org.openide.awt.Mnemonics.setLocalizedText(destinationLabel, org.openide.util.NbBundle.getMessage(ClonePanel.class, "destinationLabel.text")); // NOI18N
  94. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
  95. this.setLayout(layout);
  96. layout.setHorizontalGroup(
  97. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  98. .addGroup(layout.createSequentialGroup()
  99. .addContainerGap()
  100. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  101. .addComponent(destinationLabel)
  102. .addComponent(fromLabel)
  103. .addGroup(layout.createSequentialGroup()
  104. .addGap(12, 12, 12)
  105. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  106. .addComponent(toNameLabel)
  107. .addComponent(toLabel))))
  108. .addGap(94, 94, 94)
  109. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  110. .addComponent(fromTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 272, Short.MAX_VALUE)
  111. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  112. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  113. .addComponent(toCloneField, javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE)
  114. .addComponent(toTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE))
  115. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  116. .addComponent(browseButton)))
  117. .addContainerGap())
  118. );
  119. layout.setVerticalGroup(
  120. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  121. .addGroup(layout.createSequentialGroup()
  122. .addContainerGap()
  123. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  124. .addComponent(fromLabel)
  125. .addComponent(fromTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  126. .addGap(18, 18, 18)
  127. .addComponent(destinationLabel)
  128. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  129. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  130. .addComponent(browseButton)
  131. .addComponent(toTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  132. .addComponent(toLabel))
  133. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  134. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  135. .addComponent(toCloneField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  136. .addComponent(toNameLabel))
  137. .addGap(31, 31, 31))
  138. );
  139. toTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ClonePanel.class, "ACSD_toTextField")); // NOI18N
  140. browseButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ClonePanel.class, "ACSD_Browse")); // NOI18N
  141. fromTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ClonePanel.class, "ACSD_fromTextField")); // NOI18N
  142. toCloneField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ClonePanel.class, "ACSD_toCloneField")); // NOI18N
  143. }// </editor-fold>//GEN-END:initComponents
  144. public void actionPerformed(ActionEvent evt) {
  145. if (evt.getSource() == browseButton) {
  146. onBrowseClick();
  147. }
  148. }
  149. private void onBrowseClick() {
  150. File oldFile = defaultWorkingDirectory();
  151. JFileChooser fileChooser = new AccessibleJFileChooser(NbBundle.getMessage(ClonePanel.class, "ACSD_BrowseFolder"), oldFile); // NO I18N
  152. fileChooser.setDialogTitle(NbBundle.getMessage(ClonePanel.class, "Browse_title")); // NO I18N
  153. fileChooser.setMultiSelectionEnabled(false);
  154. FileFilter[] old = fileChooser.getChoosableFileFilters();
  155. for (int i = 0; i < old.length; i++) {
  156. FileFilter fileFilter = old[i];
  157. fileChooser.removeChoosableFileFilter(fileFilter);
  158. }
  159. fileChooser.addChoosableFileFilter(new FileFilter() {
  160. public boolean accept(File f) {
  161. return f.isDirectory();
  162. }
  163. public String getDescription() {
  164. return NbBundle.getMessage(ClonePanel.class, "Folders");// NOI18N
  165. }
  166. });
  167. fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  168. fileChooser.showDialog(this, NbBundle.getMessage(ClonePanel.class, "OK_Button")); // NO I18N
  169. File f = fileChooser.getSelectedFile();
  170. if (f != null) {
  171. toTextField.setText(f.getAbsolutePath());
  172. }
  173. }
  174. /**
  175. * Returns file to be initally used.
  176. * <ul>
  177. * <li>first is takes text in workTextField
  178. * <li>then recent project folder
  179. * <li>finally <tt>user.home</tt>
  180. * <ul>
  181. */
  182. private File defaultWorkingDirectory() {
  183. File defaultDir = null;
  184. String current = toTextField.getText();
  185. if (current != null && !(current.trim().equals(""))) { // NOI18N
  186. File currentFile = new File(current);
  187. while (currentFile != null && currentFile.exists() == false) {
  188. currentFile = currentFile.getParentFile();
  189. }
  190. if (currentFile != null) {
  191. if (currentFile.isFile()) {
  192. defaultDir = currentFile.getParentFile();
  193. } else {
  194. defaultDir = currentFile;
  195. }
  196. }
  197. }
  198. if (defaultDir == null) {
  199. File projectFolder = ProjectChooser.getProjectsFolder();
  200. if (projectFolder.exists() && projectFolder.isDirectory()) {
  201. defaultDir = projectFolder;
  202. }
  203. }
  204. if (defaultDir == null) {
  205. defaultDir = new File(System.getProperty("user.home")); // NOI18N
  206. }
  207. return defaultDir;
  208. }
  209. // Variables declaration - do not modify//GEN-BEGIN:variables
  210. private javax.swing.JButton browseButton;
  211. private javax.swing.JLabel destinationLabel;
  212. private javax.swing.JLabel fromLabel;
  213. private javax.swing.JTextField fromTextField;
  214. private javax.swing.JTextField toCloneField;
  215. private javax.swing.JLabel toLabel;
  216. private javax.swing.JLabel toNameLabel;
  217. final javax.swing.JTextField toTextField = new javax.swing.JTextField();
  218. // End of variables declaration//GEN-END:variables
  219. }