PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/netbeans-7.3/php.apigen/src/org/netbeans/modules/php/apigen/ui/options/ApiGenOptionsPanel.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 336 lines | 250 code | 36 blank | 50 comment | 4 complexity | 18232736a54616cc920dccb8ec40885b MD5 | raw file
  1. /*
  2. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  3. *
  4. * Copyright 2011 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. * If you wish your version of this file to be governed by only the CDDL
  28. * or only the GPL Version 2, indicate your decision by adding
  29. * "[Contributor] elects to include this software in this distribution
  30. * under the [CDDL or GPL Version 2] license." If you do not indicate a
  31. * single choice of license, a recipient has the option to distribute
  32. * your version of this file under either the CDDL, the GPL Version 2 or
  33. * to extend the choice of license to its licensees as provided above.
  34. * However, if you add GPL Version 2 code and therefore, elected the GPL
  35. * Version 2 license, then the option applies only if the new code is
  36. * made subject to such option by the copyright holder.
  37. *
  38. * Contributor(s):
  39. *
  40. * Portions Copyrighted 2011 Sun Microsystems, Inc.
  41. */
  42. package org.netbeans.modules.php.apigen.ui.options;
  43. import java.awt.Component;
  44. import java.awt.Cursor;
  45. import java.awt.event.ActionEvent;
  46. import java.awt.event.ActionListener;
  47. import java.awt.event.MouseAdapter;
  48. import java.awt.event.MouseEvent;
  49. import java.io.File;
  50. import java.net.MalformedURLException;
  51. import java.net.URL;
  52. import java.util.List;
  53. import javax.swing.GroupLayout;
  54. import javax.swing.GroupLayout.Alignment;
  55. import javax.swing.JButton;
  56. import javax.swing.JLabel;
  57. import javax.swing.JPanel;
  58. import javax.swing.JTextField;
  59. import javax.swing.LayoutStyle.ComponentPlacement;
  60. import javax.swing.SwingConstants;
  61. import javax.swing.UIManager;
  62. import javax.swing.event.ChangeListener;
  63. import javax.swing.event.DocumentEvent;
  64. import javax.swing.event.DocumentListener;
  65. import org.netbeans.modules.php.api.util.FileUtils;
  66. import org.netbeans.modules.php.api.util.UiUtils;
  67. import org.netbeans.modules.php.apigen.commands.ApiGenScript;
  68. import org.netbeans.spi.options.OptionsPanelController;
  69. import org.openide.awt.HtmlBrowser;
  70. import org.openide.awt.Mnemonics;
  71. import org.openide.filesystems.FileChooserBuilder;
  72. import org.openide.filesystems.FileUtil;
  73. import org.openide.util.ChangeSupport;
  74. import org.openide.util.Exceptions;
  75. import org.openide.util.NbBundle;
  76. @NbBundle.Messages("ApiGenOptionsPanel.keywords.documentation=documentation")
  77. @OptionsPanelController.Keywords(keywords={"php", "apigen", "phpdoc", "phpdocumentor", "#ApiGenOptionsPanel.keywords.documentation"},
  78. location=UiUtils.OPTIONS_PATH, tabTitle= "#LBL_PHPGenOptionsName")
  79. public class ApiGenOptionsPanel extends JPanel {
  80. private static final long serialVersionUID = 458797646546L;
  81. private static final String APIGEN_LAST_FOLDER_SUFFIX = ".apigen";
  82. private final ChangeSupport changeSupport = new ChangeSupport(this);
  83. public ApiGenOptionsPanel() {
  84. initComponents();
  85. init();
  86. }
  87. @NbBundle.Messages({
  88. "# {0} - short script name",
  89. "# {1} - long script name",
  90. "ApiGenOptionsPanel.apiGen.hint=Full path of ApiGen script (typically {0} or {1})."
  91. })
  92. private void init() {
  93. hintLabel.setText(Bundle.ApiGenOptionsPanel_apiGen_hint(ApiGenScript.SCRIPT_NAME, ApiGenScript.SCRIPT_NAME_LONG));
  94. errorLabel.setText(" "); // NOI18N
  95. // listeners
  96. DocumentListener documentListener = new DefaultDocumentListener();
  97. apiGenTextField.getDocument().addDocumentListener(documentListener);
  98. }
  99. public String getApiGen() {
  100. return apiGenTextField.getText();
  101. }
  102. public void setApiGen(String apiGen) {
  103. apiGenTextField.setText(apiGen);
  104. }
  105. public void setError(String message) {
  106. errorLabel.setText(" "); // NOI18N
  107. errorLabel.setForeground(UIManager.getColor("nb.errorForeground")); // NOI18N
  108. errorLabel.setText(message);
  109. }
  110. public void setWarning(String message) {
  111. errorLabel.setText(" "); // NOI18N
  112. errorLabel.setForeground(UIManager.getColor("nb.warningForeground")); // NOI18N
  113. errorLabel.setText(message);
  114. }
  115. public void addChangeListener(ChangeListener listener) {
  116. changeSupport.addChangeListener(listener);
  117. }
  118. public void removeChangeListener(ChangeListener listener) {
  119. changeSupport.removeChangeListener(listener);
  120. }
  121. void fireChange() {
  122. changeSupport.fireChange();
  123. }
  124. /**
  125. * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always regenerated by the Form
  126. * Editor.
  127. */
  128. @SuppressWarnings("unchecked")
  129. // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  130. private void initComponents() {
  131. apiGenLabel = new JLabel();
  132. apiGenTextField = new JTextField();
  133. browseButton = new JButton();
  134. searchButton = new JButton();
  135. hintLabel = new JLabel();
  136. noteLabel = new JLabel();
  137. installationInstructionsLabel = new JLabel();
  138. learnMoreLabel = new JLabel();
  139. errorLabel = new JLabel();
  140. apiGenLabel.setLabelFor(apiGenTextField);
  141. Mnemonics.setLocalizedText(apiGenLabel, NbBundle.getMessage(ApiGenOptionsPanel.class, "ApiGenOptionsPanel.apiGenLabel.text")); // NOI18N
  142. Mnemonics.setLocalizedText(browseButton, NbBundle.getMessage(ApiGenOptionsPanel.class, "ApiGenOptionsPanel.browseButton.text")); // NOI18N
  143. browseButton.addActionListener(new ActionListener() {
  144. public void actionPerformed(ActionEvent evt) {
  145. browseButtonActionPerformed(evt);
  146. }
  147. });
  148. Mnemonics.setLocalizedText(searchButton, NbBundle.getMessage(ApiGenOptionsPanel.class, "ApiGenOptionsPanel.searchButton.text")); // NOI18N
  149. searchButton.addActionListener(new ActionListener() {
  150. public void actionPerformed(ActionEvent evt) {
  151. searchButtonActionPerformed(evt);
  152. }
  153. });
  154. Mnemonics.setLocalizedText(hintLabel, "HINT"); // NOI18N
  155. Mnemonics.setLocalizedText(noteLabel, NbBundle.getMessage(ApiGenOptionsPanel.class, "ApiGenOptionsPanel.noteLabel.text")); // NOI18N
  156. Mnemonics.setLocalizedText(installationInstructionsLabel, NbBundle.getMessage(ApiGenOptionsPanel.class, "ApiGenOptionsPanel.installationInstructionsLabel.text")); // NOI18N
  157. Mnemonics.setLocalizedText(learnMoreLabel, NbBundle.getMessage(ApiGenOptionsPanel.class, "ApiGenOptionsPanel.learnMoreLabel.text")); // NOI18N
  158. learnMoreLabel.addMouseListener(new MouseAdapter() {
  159. public void mouseEntered(MouseEvent evt) {
  160. learnMoreLabelMouseEntered(evt);
  161. }
  162. public void mousePressed(MouseEvent evt) {
  163. learnMoreLabelMousePressed(evt);
  164. }
  165. });
  166. Mnemonics.setLocalizedText(errorLabel, "ERROR"); // NOI18N
  167. GroupLayout layout = new GroupLayout(this);
  168. this.setLayout(layout);
  169. layout.setHorizontalGroup(
  170. layout.createParallelGroup(Alignment.LEADING)
  171. .addGroup(layout.createSequentialGroup()
  172. .addComponent(apiGenLabel)
  173. .addPreferredGap(ComponentPlacement.RELATED)
  174. .addGroup(layout.createParallelGroup(Alignment.LEADING)
  175. .addGroup(layout.createSequentialGroup()
  176. .addComponent(hintLabel)
  177. .addGap(0, 0, Short.MAX_VALUE))
  178. .addGroup(layout.createSequentialGroup()
  179. .addComponent(apiGenTextField)
  180. .addPreferredGap(ComponentPlacement.RELATED)
  181. .addComponent(browseButton)
  182. .addPreferredGap(ComponentPlacement.RELATED)
  183. .addComponent(searchButton))))
  184. .addGroup(layout.createSequentialGroup()
  185. .addContainerGap()
  186. .addGroup(layout.createParallelGroup(Alignment.LEADING)
  187. .addComponent(installationInstructionsLabel)
  188. .addComponent(learnMoreLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
  189. .addContainerGap())
  190. .addGroup(layout.createSequentialGroup()
  191. .addGroup(layout.createParallelGroup(Alignment.LEADING)
  192. .addComponent(noteLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
  193. .addComponent(errorLabel))
  194. .addGap(0, 0, Short.MAX_VALUE))
  195. );
  196. layout.linkSize(SwingConstants.HORIZONTAL, new Component[] {browseButton, searchButton});
  197. layout.setVerticalGroup(
  198. layout.createParallelGroup(Alignment.LEADING)
  199. .addGroup(layout.createSequentialGroup()
  200. .addGroup(layout.createParallelGroup(Alignment.BASELINE)
  201. .addComponent(apiGenTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
  202. .addComponent(apiGenLabel)
  203. .addComponent(searchButton)
  204. .addComponent(browseButton))
  205. .addPreferredGap(ComponentPlacement.RELATED)
  206. .addComponent(hintLabel)
  207. .addGap(18, 18, 18)
  208. .addComponent(noteLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
  209. .addPreferredGap(ComponentPlacement.RELATED)
  210. .addComponent(installationInstructionsLabel)
  211. .addPreferredGap(ComponentPlacement.RELATED)
  212. .addComponent(learnMoreLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
  213. .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  214. .addComponent(errorLabel))
  215. );
  216. }// </editor-fold>//GEN-END:initComponents
  217. private void learnMoreLabelMouseEntered(MouseEvent evt) {//GEN-FIRST:event_learnMoreLabelMouseEntered
  218. evt.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
  219. }//GEN-LAST:event_learnMoreLabelMouseEntered
  220. private void learnMoreLabelMousePressed(MouseEvent evt) {//GEN-FIRST:event_learnMoreLabelMousePressed
  221. try {
  222. HtmlBrowser.URLDisplayer.getDefault().showURL(new URL("http://apigen.org/")); // NOI18N
  223. } catch (MalformedURLException ex) {
  224. Exceptions.printStackTrace(ex);
  225. }
  226. }//GEN-LAST:event_learnMoreLabelMousePressed
  227. @NbBundle.Messages("ApiGenOptionsPanel.browse.title=Select ApiGen script")
  228. private void browseButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
  229. File apiGenScript = new FileChooserBuilder(ApiGenOptionsPanel.class.getName() + APIGEN_LAST_FOLDER_SUFFIX)
  230. .setTitle(Bundle.ApiGenOptionsPanel_browse_title())
  231. .setFilesOnly(true)
  232. .showOpenDialog();
  233. if (apiGenScript != null) {
  234. apiGenScript = FileUtil.normalizeFile(apiGenScript);
  235. apiGenTextField.setText(apiGenScript.getAbsolutePath());
  236. }
  237. }//GEN-LAST:event_browseButtonActionPerformed
  238. @NbBundle.Messages({
  239. "ApiGenOptionsPanel.search.scripts.title=ApiGen scripts",
  240. "ApiGenOptionsPanel.search.scripts=&ApiGen scripts:",
  241. "ApiGenOptionsPanel.search.scripts.pleaseWaitPart=ApiGen scripts",
  242. "ApiGenOptionsPanel.search.scripts.notFound=No ApiGen scripts found."
  243. })
  244. private void searchButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_searchButtonActionPerformed
  245. String script = UiUtils.SearchWindow.search(new UiUtils.SearchWindow.SearchWindowSupport() {
  246. @Override
  247. public List<String> detect() {
  248. return FileUtils.findFileOnUsersPath(ApiGenScript.SCRIPT_NAME, ApiGenScript.SCRIPT_NAME_LONG);
  249. }
  250. @Override
  251. public String getWindowTitle() {
  252. return Bundle.ApiGenOptionsPanel_search_scripts_title();
  253. }
  254. @Override
  255. public String getListTitle() {
  256. return Bundle.ApiGenOptionsPanel_search_scripts();
  257. }
  258. @Override
  259. public String getPleaseWaitPart() {
  260. return Bundle.ApiGenOptionsPanel_search_scripts_pleaseWaitPart();
  261. }
  262. @Override
  263. public String getNoItemsFound() {
  264. return Bundle.ApiGenOptionsPanel_search_scripts_notFound();
  265. }
  266. });
  267. if (script != null) {
  268. apiGenTextField.setText(script);
  269. }
  270. }//GEN-LAST:event_searchButtonActionPerformed
  271. // Variables declaration - do not modify//GEN-BEGIN:variables
  272. private JLabel apiGenLabel;
  273. private JTextField apiGenTextField;
  274. private JButton browseButton;
  275. private JLabel errorLabel;
  276. private JLabel hintLabel;
  277. private JLabel installationInstructionsLabel;
  278. private JLabel learnMoreLabel;
  279. private JLabel noteLabel;
  280. private JButton searchButton;
  281. // End of variables declaration//GEN-END:variables
  282. //~ Inner classes
  283. private final class DefaultDocumentListener implements DocumentListener {
  284. @Override
  285. public void insertUpdate(DocumentEvent e) {
  286. processUpdate();
  287. }
  288. @Override
  289. public void removeUpdate(DocumentEvent e) {
  290. processUpdate();
  291. }
  292. @Override
  293. public void changedUpdate(DocumentEvent e) {
  294. processUpdate();
  295. }
  296. private void processUpdate() {
  297. fireChange();
  298. }
  299. }
  300. }