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: * PlainTextDialog.java
028: *
029: * Created on March 14, 2006, 9:52 PM
030: *
031: */
032:
033: package it.businesslogic.ireport.gui.sheet;
034:
035: import it.businesslogic.ireport.util.Misc;
036: import javax.swing.JOptionPane;
037: import it.businesslogic.ireport.util.I18n;
038:
039: /**
040: *
041: * @author gtoffoli
042: */
043: public class PlainTextDialog extends javax.swing.JDialog {
044:
045: private String text = "";
046: private int dialogResult = JOptionPane.CANCEL_OPTION;
047:
048: /** Creates new form PlainTextDialog */
049: public PlainTextDialog(java.awt.Frame parent, boolean modal) {
050: super (parent, modal);
051: initComponents();
052: Misc.centerFrame(this );
053:
054: javax.swing.KeyStroke escape = javax.swing.KeyStroke
055: .getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0,
056: false);
057: javax.swing.Action escapeAction = new javax.swing.AbstractAction() {
058: public void actionPerformed(java.awt.event.ActionEvent e) {
059: jButtonCancelActionPerformed(e);
060: }
061: };
062:
063: getRootPane().getInputMap(
064: javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(
065: escape, "ESCAPE");
066: getRootPane().getActionMap().put("ESCAPE", escapeAction);
067: applyI18n();
068:
069: //to make the default button ...
070: this .getRootPane().setDefaultButton(this .jButtonOk);
071: }
072:
073: /** This method is called from within the constructor to
074: * initialize the form.
075: * WARNING: Do NOT modify this code. The content of this method is
076: * always regenerated by the Form Editor.
077: */
078: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
079: private void initComponents() {
080: java.awt.GridBagConstraints gridBagConstraints;
081:
082: jScrollPane1 = new javax.swing.JScrollPane();
083: jTextArea1 = new javax.swing.JTextArea();
084: jPanel1 = new javax.swing.JPanel();
085: jButtonOk = new javax.swing.JButton();
086: jButtonCancel = new javax.swing.JButton();
087:
088: getContentPane().setLayout(new java.awt.GridBagLayout());
089:
090: setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
091: jScrollPane1.setPreferredSize(new java.awt.Dimension(400, 300));
092: jTextArea1.setColumns(20);
093: jTextArea1.setRows(5);
094: jScrollPane1.setViewportView(jTextArea1);
095:
096: gridBagConstraints = new java.awt.GridBagConstraints();
097: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
098: gridBagConstraints.weightx = 1.0;
099: gridBagConstraints.weighty = 1.0;
100: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
101: getContentPane().add(jScrollPane1, gridBagConstraints);
102:
103: jPanel1.setLayout(new java.awt.GridBagLayout());
104:
105: jButtonOk.setText("Ok");
106: jButtonOk
107: .addActionListener(new java.awt.event.ActionListener() {
108: public void actionPerformed(
109: java.awt.event.ActionEvent evt) {
110: jButtonOkActionPerformed(evt);
111: }
112: });
113:
114: gridBagConstraints = new java.awt.GridBagConstraints();
115: gridBagConstraints.gridy = 1;
116: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
117: jPanel1.add(jButtonOk, gridBagConstraints);
118:
119: jButtonCancel.setText("Cancel");
120: jButtonCancel
121: .addActionListener(new java.awt.event.ActionListener() {
122: public void actionPerformed(
123: java.awt.event.ActionEvent evt) {
124: jButtonCancelActionPerformed(evt);
125: }
126: });
127:
128: gridBagConstraints = new java.awt.GridBagConstraints();
129: gridBagConstraints.gridy = 1;
130: jPanel1.add(jButtonCancel, gridBagConstraints);
131:
132: gridBagConstraints = new java.awt.GridBagConstraints();
133: gridBagConstraints.gridy = 1;
134: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
135: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 4);
136: getContentPane().add(jPanel1, gridBagConstraints);
137:
138: pack();
139: }// </editor-fold>//GEN-END:initComponents
140:
141: private void jButtonOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOkActionPerformed
142:
143: this .setText(jTextArea1.getText());
144: this .setDialogResult(JOptionPane.OK_OPTION);
145: this .setVisible(false);
146: this .dispose();
147: }//GEN-LAST:event_jButtonOkActionPerformed
148:
149: private void jButtonCancelActionPerformed(
150: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
151:
152: this .setDialogResult(JOptionPane.CANCEL_OPTION);
153: this .setVisible(false);
154: this .dispose();
155:
156: }//GEN-LAST:event_jButtonCancelActionPerformed
157:
158: public String getText() {
159: return text;
160: }
161:
162: public void setText(String text) {
163: this .text = text;
164: jTextArea1.setText(text);
165: jTextArea1.setCaretPosition(0);
166: }
167:
168: public int getDialogResult() {
169: return dialogResult;
170: }
171:
172: public void setDialogResult(int dialogResult) {
173: this .dialogResult = dialogResult;
174: }
175:
176: // Variables declaration - do not modify//GEN-BEGIN:variables
177: private javax.swing.JButton jButtonCancel;
178: private javax.swing.JButton jButtonOk;
179: private javax.swing.JPanel jPanel1;
180: private javax.swing.JScrollPane jScrollPane1;
181: private javax.swing.JTextArea jTextArea1;
182:
183: // End of variables declaration//GEN-END:variables
184:
185: public void applyI18n() {
186: // Start autogenerated code ----------------------
187: jButtonCancel.setText(I18n.getString(
188: "plainTextDialog.buttonCancel", "Cancel"));
189: jButtonOk.setText(I18n.getString("plainTextDialog.buttonOk",
190: "Ok"));
191: // End autogenerated code ----------------------
192: jButtonCancel.setMnemonic(I18n.getString(
193: "plainTextDialog.buttonCancelMnemonic", "c").charAt(0));
194: jButtonOk.setMnemonic(I18n.getString(
195: "plainTextDialog.buttonOkMnemonic", "o").charAt(0));
196: }
197: }
|