001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * PasswordDialog.java
028: *
029: * Created on 9 maggio 2003, 17.25
030: *
031: */
032:
033: package it.businesslogic.ireport.connection;
034:
035: import it.businesslogic.ireport.util.*;
036: import it.businesslogic.ireport.*;
037: import java.lang.reflect.InvocationTargetException;
038: import javax.swing.SwingUtilities;
039:
040: /**
041: *
042: * @author Administrator
043: */
044: public class PasswordDialog extends javax.swing.JDialog {
045: /** Creates new form JRParameterDialog */
046: private String password = null;
047:
048: public PasswordDialog(java.awt.Frame parent, boolean modal) {
049:
050: super (parent, modal);
051: initComponents();
052: this .setSize(320, 144);
053: Misc.centerFrame(this );
054:
055: applyI18n();
056:
057: javax.swing.KeyStroke escape = javax.swing.KeyStroke
058: .getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0,
059: false);
060: javax.swing.Action escapeAction = new javax.swing.AbstractAction() {
061: public void actionPerformed(java.awt.event.ActionEvent e) {
062: jButtonCancelActionPerformed(e);
063: }
064: };
065:
066: getRootPane().getInputMap(
067: javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(
068: escape, "ESCAPE");
069: getRootPane().getActionMap().put("ESCAPE", escapeAction);
070:
071: //to make the default button ...
072: this .getRootPane().setDefaultButton(this .jButtonOK);
073: }
074:
075: /** This method is called from within the constructor to
076: * initialize the form.
077: * WARNING: Do NOT modify this code. The content of this method is
078: * always regenerated by the Form Editor.
079: */
080: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
081: private void initComponents() {
082: jLabel1 = new javax.swing.JLabel();
083: jButtonCancel = new javax.swing.JButton();
084: jButtonOK = new javax.swing.JButton();
085: jPasswordField = new javax.swing.JPasswordField();
086:
087: getContentPane().setLayout(null);
088:
089: setTitle("Password");
090: setModal(true);
091: setResizable(false);
092: addWindowListener(new java.awt.event.WindowAdapter() {
093: public void windowClosing(java.awt.event.WindowEvent evt) {
094: closeDialog(evt);
095: }
096: });
097:
098: jLabel1.setText("Password:");
099: getContentPane().add(jLabel1);
100: jLabel1.setBounds(4, 4, 250, 14);
101:
102: jButtonCancel.setMnemonic('c');
103: jButtonCancel.setText("Cancel");
104: jButtonCancel
105: .addActionListener(new java.awt.event.ActionListener() {
106: public void actionPerformed(
107: java.awt.event.ActionEvent evt) {
108: jButtonCancelActionPerformed(evt);
109: }
110: });
111:
112: getContentPane().add(jButtonCancel);
113: jButtonCancel.setBounds(220, 52, 70, 23);
114:
115: jButtonOK.setMnemonic('o');
116: jButtonOK.setText("OK");
117: jButtonOK
118: .addActionListener(new java.awt.event.ActionListener() {
119: public void actionPerformed(
120: java.awt.event.ActionEvent evt) {
121: jButtonOKActionPerformed(evt);
122: }
123: });
124:
125: getContentPane().add(jButtonOK);
126: jButtonOK.setBounds(138, 52, 70, 23);
127:
128: getContentPane().add(jPasswordField);
129: jPasswordField.setBounds(4, 20, 286, 24);
130:
131: pack();
132: }// </editor-fold>//GEN-END:initComponents
133:
134: private void jButtonCancelActionPerformed(
135: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
136: setVisible(false);
137: this .setDialogResult(javax.swing.JOptionPane.CANCEL_OPTION);
138: dispose();
139: }//GEN-LAST:event_jButtonCancelActionPerformed
140:
141: private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed
142:
143: try {
144: password = this .jPasswordField.getDocument().getText(0,
145: this .jPasswordField.getDocument().getLength());
146: } catch (Exception ex) {
147: }
148: this .setDialogResult(javax.swing.JOptionPane.OK_OPTION);
149: dispose();
150: }//GEN-LAST:event_jButtonOKActionPerformed
151:
152: /** Closes the dialog */
153: private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
154: setVisible(false);
155: this .setDialogResult(javax.swing.JOptionPane.CLOSED_OPTION);
156: dispose();
157: }//GEN-LAST:event_closeDialog
158:
159: /** Getter for property dialogResult.
160: * @return Value of property dialogResult.
161: *
162: */
163: public int getDialogResult() {
164: return dialogResult;
165: }
166:
167: /** Setter for property dialogResult.
168: * @param dialogResult New value of property dialogResult.
169: *
170: */
171: public void setDialogResult(int dialogResult) {
172: this .dialogResult = dialogResult;
173: }
174:
175: /** Getter for property password.
176: * @return Value of property password.
177: *
178: */
179: public java.lang.String getPassword() {
180: return password;
181: }
182:
183: /** Setter for property password.
184: * @param password New value of property password.
185: *
186: */
187: public void setPassword(java.lang.String password) {
188: this .password = password;
189: }
190:
191: // Variables declaration - do not modify//GEN-BEGIN:variables
192: private javax.swing.JButton jButtonCancel;
193: private javax.swing.JButton jButtonOK;
194: private javax.swing.JLabel jLabel1;
195: private javax.swing.JPasswordField jPasswordField;
196: // End of variables declaration//GEN-END:variables
197:
198: private int dialogResult;
199:
200: public void applyI18n() {
201: // Start autogenerated code ----------------------
202: jButtonCancel.setText(I18n.getString(
203: "passwordDialog.buttonCancel", "Cancel"));
204: jButtonOK.setText(I18n.getString("passwordDialog.buttonOK",
205: "OK"));
206: jLabel1.setText(I18n.getString("passwordDialog.label1",
207: "Password:"));
208: // End autogenerated code ----------------------
209:
210: this .setTitle(I18n
211: .getString("passwordDialog.title", "Password"));
212: jButtonCancel.setMnemonic(I18n.getString(
213: "passwordDialog.buttonCancelMnemonic", "c").charAt(0));
214: jButtonOK.setMnemonic(I18n.getString(
215: "passwordDialog.buttonOKMnemonic", "o").charAt(0));
216: }
217:
218: }
|