KickJava   Java API By Example, From Geeks To Geeks.

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


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  * EventsForm.java
28  *
29  * Created on 11 marzo 2004, 0.04
30  *
31  */

32
33 package it.businesslogic.ireport.gui;
34 import it.businesslogic.ireport.*;
35 import javax.swing.tree.*;
36 import java.util.*;
37 import it.businesslogic.ireport.util.I18n;
38 import it.businesslogic.ireport.util.LanguageChangedEvent;
39 import it.businesslogic.ireport.util.LanguageChangedListener;
40
41 /**
42  *
43  * @author Administrator
44  */

45 public class EventsForm extends javax.swing.JFrame JavaDoc {
46     
47     /** Creates new form EventsForm */
48     public EventsForm() {
49         initComponents();
50         
51         // We add all common events...
52
jComboBoxEvents.addItem(I18n.getString("EventsForm.declarationsItem", "<Imports and global declarations>") );
53         jComboBoxEvents.addItem("afterColumnInit()");
54         jComboBoxEvents.addItem("afterDetailEval()");
55         jComboBoxEvents.addItem("afterGroupInit(java.lang.String groupName)");
56         jComboBoxEvents.addItem("afterPageInit()");
57         jComboBoxEvents.addItem("afterReportInit()");
58         jComboBoxEvents.addItem("beforeColumnInit()");
59         jComboBoxEvents.addItem("beforeDetailEval()");
60         jComboBoxEvents.addItem("beforeGroupInit(java.lang.String groupName)");
61         jComboBoxEvents.addItem("beforePageInit()");
62         jComboBoxEvents.addItem("beforeReportInit()");
63         
64         I18n.addOnLanguageChangedListener( new LanguageChangedListener() {
65             public void languageChanged(LanguageChangedEvent evt) {
66                 applyI18n();
67             }
68         } );
69         
70         applyI18n();
71         
72         org.syntax.jedit.SyntaxDocument sd = new org.syntax.jedit.SyntaxDocument();
73         sd.setTokenMarker(new org.syntax.jedit.tokenmarker.JavaTokenMarker() );
74         this.jEditTextArea1.setDocument( sd );
75         
76         this.jTree1.setCellRenderer(new DocumentExpressionEditorTreeCellRenderer());
77         
78         this.jTree1.setModel(new javax.swing.tree.DefaultTreeModel JavaDoc(new DefaultMutableTreeNode("")));
79       
80         // OPEN this window with a size of 75% x 75% of the screen...
81
java.awt.Toolkit JavaDoc tk = java.awt.Toolkit.getDefaultToolkit();
82         this.setSize((int)(tk.getScreenSize().getWidth()*0.75),
83                      (int)(tk.getScreenSize().getHeight()*0.75));
84         
85         it.businesslogic.ireport.util.Misc.centerFrame(this);
86         
87         
88     }
89     
90     /** This method is called from within the constructor to
91      * initialize the form.
92      * WARNING: Do NOT modify this code. The content of this method is
93      * always regenerated by the Form Editor.
94      */

95     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
96
private void initComponents() {
97         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
98
99         jSplitPane1 = new javax.swing.JSplitPane JavaDoc();
100         jPanel1 = new javax.swing.JPanel JavaDoc();
101         jLabel1 = new javax.swing.JLabel JavaDoc();
102         jComboBoxEvents = new javax.swing.JComboBox JavaDoc();
103         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
104         jEditTextArea1 = new org.syntax.jedit.JEditTextArea();
105         jButtonSave = new javax.swing.JButton JavaDoc();
106         jPanel2 = new javax.swing.JPanel JavaDoc();
107         jLabel2 = new javax.swing.JLabel JavaDoc();
108         jScrollPane2 = new javax.swing.JScrollPane JavaDoc();
109         jTree1 = new javax.swing.JTree JavaDoc();
110
111         addWindowListener(new java.awt.event.WindowAdapter JavaDoc() {
112             public void windowClosing(java.awt.event.WindowEvent JavaDoc evt) {
113                 exitForm(evt);
114             }
115         });
116
117         jSplitPane1.setDividerSize(6);
118         jSplitPane1.setResizeWeight(0.2);
119         jPanel1.setLayout(new java.awt.GridBagLayout JavaDoc());
120
121         jLabel1.setText("Events");
122         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
123         gridBagConstraints.gridx = 0;
124         gridBagConstraints.gridy = 0;
125         gridBagConstraints.gridwidth = 2;
126         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
127         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
128         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 6, 0, 4);
129         jPanel1.add(jLabel1, gridBagConstraints);
130
131         jComboBoxEvents.addActionListener(new java.awt.event.ActionListener JavaDoc() {
132             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
133                 jComboBoxEventsActionPerformed(evt);
134             }
135         });
136
137         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
138         gridBagConstraints.gridx = 0;
139         gridBagConstraints.gridy = 1;
140         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
141         gridBagConstraints.weightx = 1.0;
142         gridBagConstraints.insets = new java.awt.Insets JavaDoc(1, 2, 4, 2);
143         jPanel1.add(jComboBoxEvents, gridBagConstraints);
144
145         jEditTextArea1.setMinimumSize(new java.awt.Dimension JavaDoc(20, 20));
146         jEditTextArea1.setPreferredSize(new java.awt.Dimension JavaDoc(150, 150));
147         jScrollPane1.setViewportView(jEditTextArea1);
148
149         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
150         gridBagConstraints.gridx = 0;
151         gridBagConstraints.gridy = 2;
152         gridBagConstraints.gridwidth = 2;
153         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
154         gridBagConstraints.weightx = 1.0;
155         gridBagConstraints.weighty = 1.0;
156         gridBagConstraints.insets = new java.awt.Insets JavaDoc(2, 2, 0, 2);
157         jPanel1.add(jScrollPane1, gridBagConstraints);
158
159         jButtonSave.setText("Save");
160         jButtonSave.addActionListener(new java.awt.event.ActionListener JavaDoc() {
161             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
162                 jButtonSaveActionPerformed(evt);
163             }
164         });
165
166         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
167         gridBagConstraints.gridx = 1;
168         gridBagConstraints.gridy = 1;
169         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
170         gridBagConstraints.insets = new java.awt.Insets JavaDoc(1, 0, 2, 4);
171         jPanel1.add(jButtonSave, gridBagConstraints);
172
173         jSplitPane1.setRightComponent(jPanel1);
174
175         jPanel2.setLayout(new java.awt.GridBagLayout JavaDoc());
176
177         jLabel2.setText("Objects");
178         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
179         gridBagConstraints.gridx = 0;
180         gridBagConstraints.gridy = 0;
181         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
182         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
183         gridBagConstraints.weightx = 1.0;
184         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 6, 0, 4);
185         jPanel2.add(jLabel2, gridBagConstraints);
186
187         jTree1.setRootVisible(false);
188         jTree1.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener JavaDoc() {
189             public void valueChanged(javax.swing.event.TreeSelectionEvent JavaDoc evt) {
190                 jTree1ValueChanged(evt);
191             }
192         });
193         jTree1.addMouseListener(new java.awt.event.MouseAdapter JavaDoc() {
194             public void mouseClicked(java.awt.event.MouseEvent JavaDoc evt) {
195                 jTree1MouseClicked(evt);
196             }
197         });
198
199         jScrollPane2.setViewportView(jTree1);
200
201         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
202         gridBagConstraints.gridx = 0;
203         gridBagConstraints.gridy = 1;
204         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
205         gridBagConstraints.weightx = 1.0;
206         gridBagConstraints.weighty = 1.0;
207         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 2, 0, 0);
208         jPanel2.add(jScrollPane2, gridBagConstraints);
209
210         jSplitPane1.setLeftComponent(jPanel2);
211
212         getContentPane().add(jSplitPane1, java.awt.BorderLayout.CENTER);
213
214         pack();
215     }// </editor-fold>//GEN-END:initComponents
216

217     private void jButtonSaveActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonSaveActionPerformed
218

219          int portion = getSelectedPortion();
220         jrf.getReport().getScripletCode().setPortionCode( portion, this.jEditTextArea1.getText() );
221         jComboBoxEventsActionPerformed(new java.awt.event.ActionEvent JavaDoc(jButtonSave,0,""));
222         
223     }//GEN-LAST:event_jButtonSaveActionPerformed
224

225     private void jTree1MouseClicked(java.awt.event.MouseEvent JavaDoc evt) {//GEN-FIRST:event_jTree1MouseClicked
226

227        if (evt.getClickCount() == 2 && evt.getButton() == java.awt.event.MouseEvent.BUTTON1)
228        {
229           TreePath path = jTree1.getSelectionPath();
230           if (path == null) return;
231           TreeNode node = (TreeNode)path.getLastPathComponent();
232           if (node instanceof DefaultMutableTreeNode)
233           {
234              DefaultMutableTreeNode nodem = (DefaultMutableTreeNode)node;
235              Object JavaDoc obj = nodem.getUserObject();
236              if (obj != null && obj instanceof JRVariable)
237              {
238                  String JavaDoc s = "getVariableValue(\""+ obj +"\")";
239                  if (((JRVariable)obj).getClassType() != null && ((JRVariable)obj).getClassType().length() > 0)
240                 {
241                     s = "("+ ((JRVariable)obj).getClassType() + ")" + s;
242                 }
243                 try
244                 {
245                     jEditTextArea1.getDocument().insertString( jEditTextArea1.getCaretPosition(), s+"", null);
246                 } catch (Exception JavaDoc ex){}
247              }
248              else if (obj != null && obj instanceof JRParameter)
249              {
250                 String JavaDoc s = "(" + ((JRParameter)obj).getClassType() + ")getParameterValue(\""+ obj +"\")";
251                 try
252                 {
253                     jEditTextArea1.getDocument().insertString( jEditTextArea1.getCaretPosition(), s+"", null);
254                 } catch (Exception JavaDoc ex){}
255              }
256              else if (obj != null && obj instanceof JRField)
257              {
258                  
259                 String JavaDoc s = "(" + ((JRField)obj).getClassType() + ")getFieldValue(\""+ obj +"\")";
260                 
261                 try
262                 {
263                     jEditTextArea1.getDocument().insertString( jEditTextArea1.getCaretPosition(), s+"", null);
264                 } catch (Exception JavaDoc ex){}
265              }
266           }
267        }
268         
269     }//GEN-LAST:event_jTree1MouseClicked
270

271     private void jTree1ValueChanged(javax.swing.event.TreeSelectionEvent JavaDoc evt) {//GEN-FIRST:event_jTree1ValueChanged
272

273        
274     }//GEN-LAST:event_jTree1ValueChanged
275

276     private void jComboBoxEventsActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jComboBoxEventsActionPerformed
277
if (jrf == null) return;
278         int portion = getSelectedPortion();
279         this.jEditTextArea1.setText( jrf.getReport().getScripletCode().getPortion( portion ));
280     }//GEN-LAST:event_jComboBoxEventsActionPerformed
281

282     /** Exit the Application */
283     private void exitForm(java.awt.event.WindowEvent JavaDoc evt) {//GEN-FIRST:event_exitForm
284
setVisible(false);
285     }//GEN-LAST:event_exitForm
286

287     /**
288      * @param args the command line arguments
289      */

290     public static void main(String JavaDoc args[]) {
291         new EventsForm().setVisible(true);
292     }
293
294     
295     
296     // Variables declaration - do not modify//GEN-BEGIN:variables
297
private javax.swing.JButton JavaDoc jButtonSave;
298     private javax.swing.JComboBox JavaDoc jComboBoxEvents;
299     private org.syntax.jedit.JEditTextArea jEditTextArea1;
300     private javax.swing.JLabel JavaDoc jLabel1;
301     private javax.swing.JLabel JavaDoc jLabel2;
302     private javax.swing.JPanel JavaDoc jPanel1;
303     private javax.swing.JPanel JavaDoc jPanel2;
304     private javax.swing.JScrollPane JavaDoc jScrollPane1;
305     private javax.swing.JScrollPane JavaDoc jScrollPane2;
306     private javax.swing.JSplitPane JavaDoc jSplitPane1;
307     private javax.swing.JTree JavaDoc jTree1;
308     // End of variables declaration//GEN-END:variables
309

310     private JReportFrame jrf;
311     
312     public int getSelectedPortion()
313     {
314         return (int)Math.max(0,jComboBoxEvents.getSelectedIndex());
315     }
316     
317     /** Getter for property jrf.
318      * @return Value of property jrf.
319      *
320      */

321     public it.businesslogic.ireport.gui.JReportFrame getJrf() {
322         return jrf;
323     }
324     
325     /** Setter for property jrf.
326      * @param jrf New value of property jrf.
327      *
328      */

329     public void setJReportFrame(it.businesslogic.ireport.gui.JReportFrame jrf) {
330         this.jrf = jrf;
331         
332         if (jrf == null)
333         {
334             this.setVisible(false);
335             return;
336         }
337                 
338         DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode)jTree1.getModel().getRoot();
339         dmtn.removeAllChildren();
340         
341         DefaultMutableTreeNode dmtnFields = new DefaultMutableTreeNode("Fields");
342         Enumeration enumFields = jrf.getReport().getFields().elements();
343         while (enumFields.hasMoreElements())
344         {
345            dmtnFields.add( new DefaultMutableTreeNode(enumFields.nextElement()));
346         }
347         dmtn.add( dmtnFields );
348         
349         
350         DefaultMutableTreeNode dmtnVariables = new DefaultMutableTreeNode("Variables");
351         Enumeration enumVariables = jrf.getReport().getVariables().elements();
352         while (enumVariables.hasMoreElements())
353         {
354            dmtnVariables.add( new DefaultMutableTreeNode(enumVariables.nextElement()));
355         }
356         dmtn.add( dmtnVariables );
357         
358         
359         DefaultMutableTreeNode dmtnParameters = new DefaultMutableTreeNode("Parameters");
360         Enumeration enumParameters = jrf.getReport().getParameters().elements();
361         while (enumParameters.hasMoreElements())
362         {
363            dmtnParameters.add( new DefaultMutableTreeNode(enumParameters.nextElement()));
364         }
365         dmtn.add( dmtnParameters );
366
367         jTree1.updateUI();
368         
369         int portion = getSelectedPortion();
370         this.jEditTextArea1.setText( jrf.getReport().getScripletCode().getPortion( portion ));
371         this.jEditTextArea1.setCaretPosition(0);
372         this.jEditTextArea1.updateUI();
373         this.jEditTextArea1.updateScrollBars();
374
375     }
376     
377     public void applyI18n(){
378                 // Start autogenerated code ----------------------
379
jButtonSave.setText(I18n.getString("eventsForm.buttonSave","Save"));
380                 jLabel1.setText(I18n.getString("eventsForm.label1","Events"));
381                 jLabel2.setText(I18n.getString("eventsForm.label2","Objects"));
382                 // End autogenerated code ----------------------
383
}
384 }
385
Popular Tags