PageRenderTime 24ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/netbeans-7.3/php.project/src/org/netbeans/modules/php/project/connections/common/PasswordPanel.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 201 lines | 126 code | 23 blank | 52 comment | 5 complexity | ef38fbcee61ce7e5f7cf194644c4092e MD5 | raw file
  1. /*
  2. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  3. *
  4. * Copyright 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. * 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 2008 Sun Microsystems, Inc.
  41. */
  42. package org.netbeans.modules.php.project.connections.common;
  43. import javax.swing.GroupLayout;
  44. import javax.swing.GroupLayout.Alignment;
  45. import javax.swing.JLabel;
  46. import javax.swing.JPanel;
  47. import javax.swing.JPasswordField;
  48. import javax.swing.JTextField;
  49. import javax.swing.LayoutStyle.ComponentPlacement;
  50. import org.openide.DialogDescriptor;
  51. import org.openide.DialogDisplayer;
  52. import org.openide.NotifyDescriptor;
  53. import org.openide.awt.Mnemonics;
  54. import org.openide.util.NbBundle;
  55. /**
  56. * @author Radek Matous, Tomas Mysik
  57. */
  58. public final class PasswordPanel extends JPanel {
  59. private static final long serialVersionUID = -12116662158021638L;
  60. private static enum Type { USER, CERTIFICATE };
  61. private final String configurationName;
  62. private PasswordPanel(String configurationName, Type type, String userName) {
  63. assert configurationName != null;
  64. assert type != null;
  65. this.configurationName = configurationName;
  66. initComponents();
  67. switch (type) {
  68. case USER:
  69. certificateLabel.setVisible(false);
  70. usernameField.setText(userName);
  71. break;
  72. case CERTIFICATE:
  73. usernameLabel.setVisible(false);
  74. usernameField.setVisible(false);
  75. break;
  76. default:
  77. throw new IllegalStateException("Unknown type: " + type);
  78. }
  79. }
  80. public static PasswordPanel forUser(String configurationName, String userName) {
  81. assert userName != null;
  82. return new PasswordPanel(configurationName, Type.USER, userName);
  83. }
  84. public static PasswordPanel forCertificate(String configurationName) {
  85. return new PasswordPanel(configurationName, Type.CERTIFICATE, null);
  86. }
  87. public boolean open() {
  88. DialogDescriptor input = new DialogDescriptor(
  89. this,
  90. NbBundle.getMessage(PasswordPanel.class, "LBL_EnterPassword", configurationName),
  91. true,
  92. NotifyDescriptor.OK_CANCEL_OPTION,
  93. NotifyDescriptor.OK_OPTION,
  94. null);
  95. return DialogDisplayer.getDefault().notify(input) == NotifyDescriptor.OK_OPTION;
  96. }
  97. public String getPassword() {
  98. return String.valueOf(passwordField.getPassword());
  99. }
  100. @Override
  101. public void addNotify() {
  102. super.addNotify();
  103. passwordField.requestFocusInWindow();
  104. }
  105. /** This method is called from within the constructor to
  106. * initialize the form.
  107. * WARNING: Do NOT modify this code. The content of this method is
  108. * always regenerated by the Form Editor.
  109. */
  110. @SuppressWarnings("unchecked")
  111. // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  112. private void initComponents() {
  113. usernameLabel = new JLabel();
  114. usernameField = new JTextField();
  115. certificateLabel = new JLabel();
  116. passwordLabel = new JLabel();
  117. passwordField = new JPasswordField();
  118. setFocusTraversalPolicy(null);
  119. usernameLabel.setLabelFor(usernameField);
  120. Mnemonics.setLocalizedText(usernameLabel, NbBundle.getMessage(PasswordPanel.class, "PasswordPanel.usernameLabel.text")); // NOI18N
  121. usernameField.setEditable(false);
  122. certificateLabel.setLabelFor(passwordField);
  123. certificateLabel.setText(NbBundle.getMessage(PasswordPanel.class, "PasswordPanel.certificateLabel.text")); // NOI18N
  124. passwordLabel.setLabelFor(passwordField);
  125. Mnemonics.setLocalizedText(passwordLabel, NbBundle.getMessage(PasswordPanel.class, "PasswordPanel.passwordLabel.text"));
  126. GroupLayout layout = new GroupLayout(this);
  127. this.setLayout(layout);
  128. layout.setHorizontalGroup(
  129. layout.createParallelGroup(Alignment.LEADING)
  130. .addGroup(layout.createSequentialGroup()
  131. .addContainerGap()
  132. .addGroup(layout.createParallelGroup(Alignment.LEADING)
  133. .addGroup(layout.createSequentialGroup()
  134. .addGroup(layout.createParallelGroup(Alignment.TRAILING)
  135. .addComponent(usernameLabel)
  136. .addComponent(passwordLabel))
  137. .addPreferredGap(ComponentPlacement.RELATED)
  138. .addGroup(layout.createParallelGroup(Alignment.LEADING)
  139. .addComponent(passwordField, GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE)
  140. .addComponent(usernameField, GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE)))
  141. .addComponent(certificateLabel))
  142. .addContainerGap())
  143. );
  144. layout.setVerticalGroup(
  145. layout.createParallelGroup(Alignment.LEADING)
  146. .addGroup(layout.createSequentialGroup()
  147. .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  148. .addGroup(layout.createParallelGroup(Alignment.BASELINE)
  149. .addComponent(usernameLabel)
  150. .addComponent(usernameField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
  151. .addPreferredGap(ComponentPlacement.RELATED)
  152. .addComponent(certificateLabel)
  153. .addPreferredGap(ComponentPlacement.RELATED)
  154. .addGroup(layout.createParallelGroup(Alignment.BASELINE)
  155. .addComponent(passwordLabel)
  156. .addComponent(passwordField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
  157. );
  158. usernameLabel.getAccessibleContext().setAccessibleName(NbBundle.getMessage(PasswordPanel.class, "PasswordPanel.usernameLabel.AccessibleContext.accessibleName")); // NOI18N
  159. usernameLabel.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(PasswordPanel.class, "PasswordPanel.usernameLabel.AccessibleContext.accessibleDescription")); // NOI18N
  160. usernameField.getAccessibleContext().setAccessibleName(NbBundle.getMessage(PasswordPanel.class, "PasswordPanel.usernameField.AccessibleContext.accessibleName")); // NOI18N
  161. usernameField.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(PasswordPanel.class, "PasswordPanel.usernameField.AccessibleContext.accessibleDescription")); // NOI18N
  162. certificateLabel.getAccessibleContext().setAccessibleName(NbBundle.getMessage(PasswordPanel.class, "PasswordPanel.certificateLabel.AccessibleContext.accessibleName")); // NOI18N
  163. certificateLabel.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(PasswordPanel.class, "PasswordPanel.certificateLabel.AccessibleContext.accessibleDescription")); // NOI18N
  164. passwordLabel.getAccessibleContext().setAccessibleName(NbBundle.getMessage(PasswordPanel.class, "PasswordPanel.passwordLabel.AccessibleContext.accessibleName")); // NOI18N
  165. passwordLabel.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(PasswordPanel.class, "PasswordPanel.passwordLabel.AccessibleContext.accessibleDescription")); // NOI18N
  166. passwordField.getAccessibleContext().setAccessibleName(NbBundle.getMessage(PasswordPanel.class, "PasswordPanel.passwordField.AccessibleContext.accessibleName")); // NOI18N
  167. passwordField.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(PasswordPanel.class, "PasswordPanel.passwordField.AccessibleContext.accessibleDescription")); // NOI18N
  168. getAccessibleContext().setAccessibleName(NbBundle.getMessage(PasswordPanel.class, "PasswordPanel.AccessibleContext.accessibleName")); // NOI18N
  169. getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(PasswordPanel.class, "PasswordPanel.AccessibleContext.accessibleDescription")); // NOI18N
  170. }// </editor-fold>//GEN-END:initComponents
  171. // Variables declaration - do not modify//GEN-BEGIN:variables
  172. private JLabel certificateLabel;
  173. private JPasswordField passwordField;
  174. private JLabel passwordLabel;
  175. private JTextField usernameField;
  176. private JLabel usernameLabel;
  177. // End of variables declaration//GEN-END:variables
  178. }