KickJava   Java API By Example, From Geeks To Geeks.

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


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  * JRSubreportReturnValueDialog.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.*;
36 import it.businesslogic.ireport.gui.sheet.Tag;
37 import it.businesslogic.ireport.util.*;
38
39
40 /**
41  * @author Administrator
42  */

43 public class JRSubreportReturnValueDialog
44     extends javax.swing.JDialog JavaDoc
45 {
46
47     /** Creates new form JRParameterDialog */
48     private JRSubreportReturnValue subreportReturnValue = null;
49
50     /**
51      * Creates a new JRVariableDialog object.
52      *
53      * @param report DOCUMENT ME!
54      * @param parent DOCUMENT ME!
55      * @param modal DOCUMENT ME!
56      */

57     public JRSubreportReturnValueDialog(java.awt.Dialog JavaDoc parent, boolean modal)
58     {
59         super(parent, modal);
60         initComponents();
61         applyI18n();
62         setTypes();
63         updateVariables();
64         jComboBoxSubreportVariable.setSelectedItem("");
65         this.setSize(380, 260);
66         Misc.centerFrame(this);
67         
68         
69         javax.swing.KeyStroke JavaDoc escape = javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0, false);
70         javax.swing.Action JavaDoc escapeAction = new javax.swing.AbstractAction JavaDoc() {
71             public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
72                 jButtonCancelActionPerformed(e);
73             }
74         };
75        
76         getRootPane().getInputMap(javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE");
77         getRootPane().getActionMap().put("ESCAPE", escapeAction);
78
79
80         //to make the default button ...
81
this.getRootPane().setDefaultButton(this.jButtonOK);
82     }
83
84     /**
85      * DOCUMENT ME!
86      */

87     public void setTypes()
88     {
89         this.jComboBoxCalculationType.addItem(new Tag("Nothing", I18n.getString("variable.calculationType.Nothing", "Nothing") ));
90         this.jComboBoxCalculationType.addItem(new Tag("Count", I18n.getString("variable.calculationType.Count", "Count")));
91         this.jComboBoxCalculationType.addItem(new Tag("DistinctCount", I18n.getString("variable.calculationType.DistinctCount", "Distinct count")));
92         this.jComboBoxCalculationType.addItem(new Tag("Sum", I18n.getString("variable.calculationType.Sum", "Sum")));
93         this.jComboBoxCalculationType.addItem(new Tag("Average", I18n.getString("variable.calculationType.Average", "Average")));
94         this.jComboBoxCalculationType.addItem(new Tag("Lowest", I18n.getString("variable.calculationType.Lowest", "Lowest")));
95         this.jComboBoxCalculationType.addItem(new Tag("Highest", I18n.getString("variable.calculationType.Highest", "Highest")));
96         this.jComboBoxCalculationType.addItem(new Tag("StandardDeviation", I18n.getString("variable.calculationType.StandardDeviation", "Standard deviation")));
97         this.jComboBoxCalculationType.addItem(new Tag("Variance", I18n.getString("variable.calculationType.Variance", "Variance") ));
98         this.jComboBoxCalculationType.addItem(new Tag("System", I18n.getString("variable.calculationType.System", "System") ));
99         this.jComboBoxCalculationType.addItem(new Tag("First", I18n.getString("variable.calculationType.First", "First") ));
100     }
101
102     /**
103      * Read all available variables from the active report and popute the combobox
104      */

105     public void updateVariables()
106     {
107         try {
108             Misc.updateComboBox(jComboBoxVariable,
109                     it.businesslogic.ireport.gui.MainFrame.getMainInstance().getActiveReportFrame().getReport().getVariables(), false);
110             
111             // Remove builtin variables...
112
for (int i=0; i<jComboBoxVariable.getItemCount(); ++i)
113             {
114                 
115                 Object JavaDoc var = jComboBoxVariable.getItemAt(i);
116                 if (var instanceof JRVariable && ((JRVariable)var).isBuiltin())
117                 {
118                     jComboBoxSubreportVariable.addItem( var+"");
119                     jComboBoxVariable.removeItem(var);
120                     --i;
121                 }
122             }
123             
124         } catch (Exception JavaDoc ex)
125         {
126             
127         }
128     }
129
130     /**
131      * This method is called from within the constructor to initialize the
132      * form. WARNING: Do NOT modify this code. The content of this method is
133      * always regenerated by the Form Editor.
134      */

135
136
137     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
138
private void initComponents() {
139         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
140
141         jLabel1 = new javax.swing.JLabel JavaDoc();
142         jLabel2 = new javax.swing.JLabel JavaDoc();
143         jLabel5 = new javax.swing.JLabel JavaDoc();
144         jComboBoxCalculationType = new javax.swing.JComboBox JavaDoc();
145         jComboBoxVariable = new javax.swing.JComboBox JavaDoc();
146         jLabel8 = new javax.swing.JLabel JavaDoc();
147         jTextFieldNameIncrementerFactoryClass = new javax.swing.JTextField JavaDoc();
148         jPanel1 = new javax.swing.JPanel JavaDoc();
149         jButtonOK = new javax.swing.JButton JavaDoc();
150         jButtonCancel = new javax.swing.JButton JavaDoc();
151         jComboBoxSubreportVariable = new javax.swing.JComboBox JavaDoc();
152
153         getContentPane().setLayout(new java.awt.GridBagLayout JavaDoc());
154
155         setTitle("Add/modify variable");
156         setModal(true);
157         addWindowListener(new java.awt.event.WindowAdapter JavaDoc() {
158             public void windowClosing(java.awt.event.WindowEvent JavaDoc evt) {
159                 closeDialog(evt);
160             }
161         });
162
163         jLabel1.setText("Subreport variable");
164         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
165         gridBagConstraints.gridx = 0;
166         gridBagConstraints.gridy = 0;
167         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
168         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
169         getContentPane().add(jLabel1, gridBagConstraints);
170
171         jLabel2.setText("Calculation type");
172         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
173         gridBagConstraints.gridx = 0;
174         gridBagConstraints.gridy = 4;
175         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
176         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
177         getContentPane().add(jLabel2, gridBagConstraints);
178
179         jLabel5.setText("Local destination variable");
180         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
181         gridBagConstraints.gridx = 0;
182         gridBagConstraints.gridy = 2;
183         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
184         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
185         getContentPane().add(jLabel5, gridBagConstraints);
186
187         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
188         gridBagConstraints.gridx = 0;
189         gridBagConstraints.gridy = 5;
190         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
191         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
192         gridBagConstraints.weightx = 1.0;
193         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
194         getContentPane().add(jComboBoxCalculationType, gridBagConstraints);
195
196         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
197         gridBagConstraints.gridx = 0;
198         gridBagConstraints.gridy = 3;
199         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
200         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
201         gridBagConstraints.weightx = 1.0;
202         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
203         getContentPane().add(jComboBoxVariable, gridBagConstraints);
204
205         jLabel8.setText("Custom Incrementer Factory Class");
206         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
207         gridBagConstraints.gridx = 0;
208         gridBagConstraints.gridy = 8;
209         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
210         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
211         getContentPane().add(jLabel8, gridBagConstraints);
212
213         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
214         gridBagConstraints.gridx = 0;
215         gridBagConstraints.gridy = 9;
216         gridBagConstraints.gridwidth = 2;
217         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
218         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
219         gridBagConstraints.weightx = 1.0;
220         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
221         getContentPane().add(jTextFieldNameIncrementerFactoryClass, gridBagConstraints);
222
223         jPanel1.setLayout(new java.awt.FlowLayout JavaDoc(java.awt.FlowLayout.RIGHT));
224
225         jButtonOK.setMnemonic('o');
226         jButtonOK.setText("OK");
227         jButtonOK.addActionListener(new java.awt.event.ActionListener JavaDoc() {
228             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
229                 jButtonOKActionPerformed(evt);
230             }
231         });
232
233         jPanel1.add(jButtonOK);
234
235         jButtonCancel.setText("Cancel");
236         jButtonCancel.setMnemonic('c');
237         jButtonCancel.addActionListener(new java.awt.event.ActionListener JavaDoc() {
238             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
239                 jButtonCancelActionPerformed(evt);
240             }
241         });
242
243         jPanel1.add(jButtonCancel);
244
245         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
246         gridBagConstraints.gridx = 0;
247         gridBagConstraints.gridy = 14;
248         gridBagConstraints.gridwidth = 3;
249         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
250         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
251         gridBagConstraints.weightx = 1.0;
252         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
253         getContentPane().add(jPanel1, gridBagConstraints);
254
255         jComboBoxSubreportVariable.setEditable(true);
256         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
257         gridBagConstraints.gridx = 0;
258         gridBagConstraints.gridy = 1;
259         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
260         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 4, 0, 4);
261         getContentPane().add(jComboBoxSubreportVariable, gridBagConstraints);
262
263         pack();
264         java.awt.Dimension JavaDoc screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
265         java.awt.Dimension JavaDoc dialogSize = getSize();
266         setLocation((screenSize.width-dialogSize.width)/2,(screenSize.height-dialogSize.height)/2);
267     }// </editor-fold>//GEN-END:initComponents
268
private void jButtonCancelActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_jButtonCancelActionPerformed
269
{
270         setVisible(false);
271         this.setDialogResult(javax.swing.JOptionPane.CANCEL_OPTION);
272         dispose();
273     }//GEN-LAST:event_jButtonCancelActionPerformed
274

275     private void jButtonOKActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_jButtonOKActionPerformed
276
{
277
278         if ((this.jComboBoxSubreportVariable.getSelectedItem()+"").trim().length() <= 0)
279         {
280             javax.swing.JOptionPane.showMessageDialog(this,
281                     I18n.getString( "messages.jRSubreportReturnValueDialog.notValidName","Please insert a valid subreport variable name!"),
282                     I18n.getString( "messages.jRSubreportReturnValueDialog.notValidNameCaption","Invalid variable!"),
283                     javax.swing.JOptionPane.WARNING_MESSAGE);
284
285             return;
286         }
287
288         subreportReturnValue = new JRSubreportReturnValue();
289         
290         subreportReturnValue.setSubreportVariable( this.jComboBoxSubreportVariable.getSelectedItem()+"" );
291         
292         
293         if (this.jComboBoxVariable.getSelectedItem() == null)
294         {
295             javax.swing.JOptionPane.showMessageDialog(this,
296                     I18n.getString( "messages.jRSubreportReturnValueDialog.notValidLocalVariable","Please insert a valid local variable! If no variables are available, please close this dialog and create one."),
297                     I18n.getString( "messages.jRSubreportReturnValueDialog.notValidLocalVariableCaption","Invalid variable!"),
298                     javax.swing.JOptionPane.WARNING_MESSAGE);
299
300             return;
301         }
302         subreportReturnValue.setToVariable( jComboBoxVariable.getSelectedItem()+"");
303
304         Object JavaDoc t = this.jComboBoxCalculationType.getSelectedItem();
305         if (t != null && t instanceof Tag) subreportReturnValue.setCalculation( ((Tag)t).getValue()+"" );
306         subreportReturnValue.setIncrementFactoryClass( this.jTextFieldNameIncrementerFactoryClass.getText());
307         
308         setVisible(false);
309         this.setDialogResult(javax.swing.JOptionPane.OK_OPTION);
310         dispose();
311     }//GEN-LAST:event_jButtonOKActionPerformed
312

313     /**
314      * Closes the dialog
315      * @param evt DOCUMENT ME!
316      */

317     private void closeDialog(java.awt.event.WindowEvent JavaDoc evt)//GEN-FIRST:event_closeDialog
318
{
319         setVisible(false);
320         this.setDialogResult(javax.swing.JOptionPane.CLOSED_OPTION);
321         dispose();
322     }//GEN-LAST:event_closeDialog
323

324     /**
325      * Getter for property tmpParameter.
326      *
327      * @return Value of property tmpParameter.
328      */

329     public it.businesslogic.ireport.JRSubreportReturnValue getSubreportReturnValue()
330     {
331
332         return subreportReturnValue;
333     }
334
335     /**
336      * Setter for property tmpParameter.
337      *
338      * @param tmpVariable New value of property tmpParameter.
339      */

340     public void setSubreportReturnValue(it.businesslogic.ireport.JRSubreportReturnValue tmpSubreportReturnValue)
341     {
342         this.jComboBoxSubreportVariable.setSelectedItem(new String JavaDoc(tmpSubreportReturnValue.getSubreportVariable() ));
343         for (int i=0; i<jComboBoxVariable.getItemCount(); ++i)
344         {
345
346             Object JavaDoc var = jComboBoxVariable.getItemAt(i);
347             if ((var+"").equals( tmpSubreportReturnValue.getToVariable() ))
348             {
349                 jComboBoxVariable.setSelectedIndex(i);
350                 break;
351             }
352         }
353         
354         Misc.setComboboxSelectedTagValue( jComboBoxCalculationType, tmpSubreportReturnValue.getCalculation() );
355         this.jTextFieldNameIncrementerFactoryClass.setText(tmpSubreportReturnValue.getIncrementFactoryClass());
356     }
357
358     /**
359      * Getter for property dialogResult.
360      *
361      * @return Value of property dialogResult.
362      */

363     public int getDialogResult()
364     {
365
366         return dialogResult;
367     }
368
369     /**
370      * Setter for property dialogResult.
371      *
372      * @param dialogResult New value of property dialogResult.
373      */

374     public void setDialogResult(int dialogResult)
375     {
376         this.dialogResult = dialogResult;
377     }
378
379  
380     // Variables declaration - do not modify//GEN-BEGIN:variables
381
private javax.swing.JButton JavaDoc jButtonCancel;
382     private javax.swing.JButton JavaDoc jButtonOK;
383     private javax.swing.JComboBox JavaDoc jComboBoxCalculationType;
384     private javax.swing.JComboBox JavaDoc jComboBoxSubreportVariable;
385     private javax.swing.JComboBox JavaDoc jComboBoxVariable;
386     private javax.swing.JLabel JavaDoc jLabel1;
387     private javax.swing.JLabel JavaDoc jLabel2;
388     private javax.swing.JLabel JavaDoc jLabel5;
389     private javax.swing.JLabel JavaDoc jLabel8;
390     private javax.swing.JPanel JavaDoc jPanel1;
391     private javax.swing.JTextField JavaDoc jTextFieldNameIncrementerFactoryClass;
392     // End of variables declaration//GEN-END:variables
393
private int dialogResult;
394
395     public void applyI18n(){
396                 // Start autogenerated code ----------------------
397
jButtonCancel.setText(I18n.getString("jRSubreportReturnValueDialog.buttonCancel","Cancel"));
398                 jButtonOK.setText(I18n.getString("jRSubreportReturnValueDialog.buttonOK","OK"));
399                 jLabel1.setText(I18n.getString("jRSubreportReturnValueDialog.label1","Subreport variable"));
400                 jLabel2.setText(I18n.getString("jRSubreportReturnValueDialog.label2","Calculation type"));
401                 jLabel5.setText(I18n.getString("jRSubreportReturnValueDialog.label5","Local destination variable"));
402                 jLabel8.setText(I18n.getString("jRSubreportReturnValueDialog.label8","Custom Incrementer Factory Class"));
403                 // End autogenerated code ----------------------
404
}
405 }
406
Popular Tags