KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > gui > JRSubreportParameterDialog


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * JRSubreportParameterDialog.java
28  *
29  * Created on 9 maggio 2003, 17.25
30  *
31  */

32
33 package it.businesslogic.ireport.gui;
34
35 import it.businesslogic.ireport.util.*;
36 import it.businesslogic.ireport.*;
37 import java.util.Vector JavaDoc;
38 /**
39  *
40  * @author Administrator
41  */

42 public class JRSubreportParameterDialog extends javax.swing.JDialog JavaDoc {
43     /** Creates new form JRParameterDialog */
44     JRSubreportParameter tmpParameter = null;
45     
46     public JRSubreportParameterDialog(java.awt.Dialog JavaDoc parent, boolean modal) {
47         
48         super(parent, modal);
49         initComponents();
50         applyI18n();
51         this.jRTextExpressionAreaDefaultExpression.setText("");
52         
53         // we have to force the context of the parameter.
54
this.jRTextExpressionAreaDefaultExpression.setCrosstabElements( new Vector JavaDoc());
55         this.jRTextExpressionAreaDefaultExpression.setSubDataset( MainFrame.getMainInstance().getActiveReportFrame().getReport());
56         Misc.centerFrame(this);
57         
58         
59         javax.swing.KeyStroke JavaDoc escape = javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0, false);
60         javax.swing.Action JavaDoc escapeAction = new javax.swing.AbstractAction JavaDoc() {
61             public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
62                 jButtonCancelActionPerformed(e);
63             }
64         };
65        
66         getRootPane().getInputMap(javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE");
67         getRootPane().getActionMap().put("ESCAPE", escapeAction);
68
69
70         //to make the default button ...
71
this.getRootPane().setDefaultButton(this.jButtonOK);
72     }
73     
74     /** This method is called from within the constructor to
75      * initialize the form.
76      * WARNING: Do NOT modify this code. The content of this method is
77      * always regenerated by the Form Editor.
78      */

79     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
80
private void initComponents() {
81         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
82
83         jPanel1 = new javax.swing.JPanel JavaDoc();
84         jButtonOK = new javax.swing.JButton JavaDoc();
85         jButtonCancel = new javax.swing.JButton JavaDoc();
86         jPanel2 = new javax.swing.JPanel JavaDoc();
87         jLabel1 = new javax.swing.JLabel JavaDoc();
88         jTextFieldName = new javax.swing.JTextField JavaDoc();
89         jLabel3 = new javax.swing.JLabel JavaDoc();
90         jRTextExpressionAreaDefaultExpression = new it.businesslogic.ireport.gui.JRTextExpressionArea();
91
92         setTitle("Add/modify parameter");
93         setResizable(false);
94         setModal(true);
95         addWindowListener(new java.awt.event.WindowAdapter JavaDoc() {
96             public void windowClosing(java.awt.event.WindowEvent JavaDoc evt) {
97                 closeDialog(evt);
98             }
99         });
100
101         jPanel1.setLayout(new java.awt.FlowLayout JavaDoc(java.awt.FlowLayout.RIGHT));
102
103         jButtonOK.setMnemonic('o');
104         jButtonOK.setText("OK");
105         jButtonOK.addActionListener(new java.awt.event.ActionListener JavaDoc() {
106             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
107                 jButtonOKActionPerformed(evt);
108             }
109         });
110
111         jPanel1.add(jButtonOK);
112
113         jButtonCancel.setMnemonic('c');
114         jButtonCancel.setText("Cancel");
115         jButtonCancel.addActionListener(new java.awt.event.ActionListener JavaDoc() {
116             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
117                 jButtonCancelActionPerformed(evt);
118             }
119         });
120
121         jPanel1.add(jButtonCancel);
122
123         getContentPane().add(jPanel1, java.awt.BorderLayout.SOUTH);
124
125         jPanel2.setLayout(new java.awt.GridBagLayout JavaDoc());
126
127         jLabel1.setText("Subreport parameter name");
128         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
129         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
130         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 0, 3);
131         jPanel2.add(jLabel1, gridBagConstraints);
132
133         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
134         gridBagConstraints.gridx = 0;
135         gridBagConstraints.gridy = 1;
136         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
137         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
138         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 3, 3, 3);
139         jPanel2.add(jTextFieldName, gridBagConstraints);
140
141         jLabel3.setText("Default value expression");
142         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
143         gridBagConstraints.gridx = 0;
144         gridBagConstraints.gridy = 2;
145         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
146         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
147         jPanel2.add(jLabel3, gridBagConstraints);
148
149         jRTextExpressionAreaDefaultExpression.setBorder(javax.swing.BorderFactory.createEtchedBorder());
150         jRTextExpressionAreaDefaultExpression.setPreferredSize(new java.awt.Dimension JavaDoc(300, 80));
151         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
152         gridBagConstraints.gridx = 0;
153         gridBagConstraints.gridy = 3;
154         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
155         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
156         gridBagConstraints.weightx = 1.0;
157         gridBagConstraints.weighty = 1.0;
158         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 3, 3, 3);
159         jPanel2.add(jRTextExpressionAreaDefaultExpression, gridBagConstraints);
160
161         getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);
162
163         setBounds(0, 0, 320, 220);
164     }// </editor-fold>//GEN-END:initComponents
165

166     private void jButtonCancelActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
167
setVisible(false);
168         this.setDialogResult( javax.swing.JOptionPane.CANCEL_OPTION);
169         dispose();
170     }//GEN-LAST:event_jButtonCancelActionPerformed
171

172     private void jButtonOKActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonOKActionPerformed
173

174         if (this.jTextFieldName.getText().trim().length() <= 0)
175         {
176             javax.swing.JOptionPane.showMessageDialog(this,
177                     I18n.getString( "messages.jRSubreportParameterDialog.notValidName","Please insert a valid parameter name!"),
178                     I18n.getString( "messages.jRSubreportParameterDialog.notValidNameCaption","Invalid parameter!"),
179                     javax.swing.JOptionPane.WARNING_MESSAGE );
180             return;
181         }
182         
183         tmpParameter = new it.businesslogic.ireport.JRSubreportParameter( this.jTextFieldName.getText(),this.jRTextExpressionAreaDefaultExpression.getText());
184         setVisible(false);
185         this.setDialogResult( javax.swing.JOptionPane.OK_OPTION);
186         dispose();
187     }//GEN-LAST:event_jButtonOKActionPerformed
188

189     /** Closes the dialog */
190     private void closeDialog(java.awt.event.WindowEvent JavaDoc evt) {//GEN-FIRST:event_closeDialog
191
setVisible(false);
192         this.setDialogResult( javax.swing.JOptionPane.CLOSED_OPTION);
193         dispose();
194     }//GEN-LAST:event_closeDialog
195

196     /**
197      * @param args the command line arguments
198      */

199     public static void main(String JavaDoc args[]) {
200         new JRParameterDialog(new javax.swing.JFrame JavaDoc(), true).setVisible(true);
201     }
202     
203     /** Getter for property tmpParameter.
204      * @return Value of property tmpParameter.
205      *
206      */

207     public it.businesslogic.ireport.JRSubreportParameter getParameter() {
208         return tmpParameter;
209     }
210     
211     /** Setter for property tmpParameter.
212      * @param tmpParameter New value of property tmpParameter.
213      *
214      */

215     public void setParameter(it.businesslogic.ireport.JRSubreportParameter tmpParameter) {
216         this.jTextFieldName.setText( new String JavaDoc(tmpParameter.getName()));
217         this.jRTextExpressionAreaDefaultExpression.setText( new String JavaDoc(tmpParameter.getExpression()));
218     }
219     
220     /** Getter for property dialogResult.
221      * @return Value of property dialogResult.
222      *
223      */

224     public int getDialogResult() {
225         return dialogResult;
226     }
227     
228     /** Setter for property dialogResult.
229      * @param dialogResult New value of property dialogResult.
230      *
231      */

232     public void setDialogResult(int dialogResult) {
233         this.dialogResult = dialogResult;
234     }
235     
236     // Variables declaration - do not modify//GEN-BEGIN:variables
237
private javax.swing.JButton JavaDoc jButtonCancel;
238     private javax.swing.JButton JavaDoc jButtonOK;
239     private javax.swing.JLabel JavaDoc jLabel1;
240     private javax.swing.JLabel JavaDoc jLabel3;
241     private javax.swing.JPanel JavaDoc jPanel1;
242     private javax.swing.JPanel JavaDoc jPanel2;
243     private it.businesslogic.ireport.gui.JRTextExpressionArea jRTextExpressionAreaDefaultExpression;
244     private javax.swing.JTextField JavaDoc jTextFieldName;
245     // End of variables declaration//GEN-END:variables
246

247     private int dialogResult;
248     
249     public void applyI18n(){
250                 // Start autogenerated code ----------------------
251
jButtonCancel.setText(I18n.getString("jRSubreportParameterDialog.buttonCancel","Cancel"));
252                 jButtonOK.setText(I18n.getString("jRSubreportParameterDialog.buttonOK","OK"));
253                 jLabel1.setText(I18n.getString("jRSubreportParameterDialog.label1","Subreport parameter name"));
254                 jLabel3.setText(I18n.getString("jRSubreportParameterDialog.label3","Default value expression"));
255                 // End autogenerated code ----------------------
256
}
257 }
258
Popular Tags