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: * EventsForm.java
028: *
029: * Created on 11 marzo 2004, 0.04
030: *
031: */
032:
033: package it.businesslogic.ireport.gui;
034:
035: import it.businesslogic.ireport.*;
036: import javax.swing.tree.*;
037: import java.util.*;
038: import it.businesslogic.ireport.util.I18n;
039: import it.businesslogic.ireport.util.LanguageChangedEvent;
040: import it.businesslogic.ireport.util.LanguageChangedListener;
041:
042: /**
043: *
044: * @author Administrator
045: */
046: public class EventsForm extends javax.swing.JFrame {
047:
048: /** Creates new form EventsForm */
049: public EventsForm() {
050: initComponents();
051:
052: // We add all common events...
053: jComboBoxEvents.addItem(I18n.getString(
054: "EventsForm.declarationsItem",
055: "<Imports and global declarations>"));
056: jComboBoxEvents.addItem("afterColumnInit()");
057: jComboBoxEvents.addItem("afterDetailEval()");
058: jComboBoxEvents
059: .addItem("afterGroupInit(java.lang.String groupName)");
060: jComboBoxEvents.addItem("afterPageInit()");
061: jComboBoxEvents.addItem("afterReportInit()");
062: jComboBoxEvents.addItem("beforeColumnInit()");
063: jComboBoxEvents.addItem("beforeDetailEval()");
064: jComboBoxEvents
065: .addItem("beforeGroupInit(java.lang.String groupName)");
066: jComboBoxEvents.addItem("beforePageInit()");
067: jComboBoxEvents.addItem("beforeReportInit()");
068:
069: I18n
070: .addOnLanguageChangedListener(new LanguageChangedListener() {
071: public void languageChanged(LanguageChangedEvent evt) {
072: applyI18n();
073: }
074: });
075:
076: applyI18n();
077:
078: org.syntax.jedit.SyntaxDocument sd = new org.syntax.jedit.SyntaxDocument();
079: sd
080: .setTokenMarker(new org.syntax.jedit.tokenmarker.JavaTokenMarker());
081: this .jEditTextArea1.setDocument(sd);
082:
083: this .jTree1
084: .setCellRenderer(new DocumentExpressionEditorTreeCellRenderer());
085:
086: this .jTree1.setModel(new javax.swing.tree.DefaultTreeModel(
087: new DefaultMutableTreeNode("")));
088:
089: // OPEN this window with a size of 75% x 75% of the screen...
090: java.awt.Toolkit tk = java.awt.Toolkit.getDefaultToolkit();
091: this .setSize((int) (tk.getScreenSize().getWidth() * 0.75),
092: (int) (tk.getScreenSize().getHeight() * 0.75));
093:
094: it.businesslogic.ireport.util.Misc.centerFrame(this );
095:
096: }
097:
098: /** This method is called from within the constructor to
099: * initialize the form.
100: * WARNING: Do NOT modify this code. The content of this method is
101: * always regenerated by the Form Editor.
102: */
103: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
104: private void initComponents() {
105: java.awt.GridBagConstraints gridBagConstraints;
106:
107: jSplitPane1 = new javax.swing.JSplitPane();
108: jPanel1 = new javax.swing.JPanel();
109: jLabel1 = new javax.swing.JLabel();
110: jComboBoxEvents = new javax.swing.JComboBox();
111: jScrollPane1 = new javax.swing.JScrollPane();
112: jEditTextArea1 = new org.syntax.jedit.JEditTextArea();
113: jButtonSave = new javax.swing.JButton();
114: jPanel2 = new javax.swing.JPanel();
115: jLabel2 = new javax.swing.JLabel();
116: jScrollPane2 = new javax.swing.JScrollPane();
117: jTree1 = new javax.swing.JTree();
118:
119: addWindowListener(new java.awt.event.WindowAdapter() {
120: public void windowClosing(java.awt.event.WindowEvent evt) {
121: exitForm(evt);
122: }
123: });
124:
125: jSplitPane1.setDividerSize(6);
126: jSplitPane1.setResizeWeight(0.2);
127: jPanel1.setLayout(new java.awt.GridBagLayout());
128:
129: jLabel1.setText("Events");
130: gridBagConstraints = new java.awt.GridBagConstraints();
131: gridBagConstraints.gridx = 0;
132: gridBagConstraints.gridy = 0;
133: gridBagConstraints.gridwidth = 2;
134: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
135: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
136: gridBagConstraints.insets = new java.awt.Insets(4, 6, 0, 4);
137: jPanel1.add(jLabel1, gridBagConstraints);
138:
139: jComboBoxEvents
140: .addActionListener(new java.awt.event.ActionListener() {
141: public void actionPerformed(
142: java.awt.event.ActionEvent evt) {
143: jComboBoxEventsActionPerformed(evt);
144: }
145: });
146:
147: gridBagConstraints = new java.awt.GridBagConstraints();
148: gridBagConstraints.gridx = 0;
149: gridBagConstraints.gridy = 1;
150: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
151: gridBagConstraints.weightx = 1.0;
152: gridBagConstraints.insets = new java.awt.Insets(1, 2, 4, 2);
153: jPanel1.add(jComboBoxEvents, gridBagConstraints);
154:
155: jEditTextArea1.setMinimumSize(new java.awt.Dimension(20, 20));
156: jEditTextArea1
157: .setPreferredSize(new java.awt.Dimension(150, 150));
158: jScrollPane1.setViewportView(jEditTextArea1);
159:
160: gridBagConstraints = new java.awt.GridBagConstraints();
161: gridBagConstraints.gridx = 0;
162: gridBagConstraints.gridy = 2;
163: gridBagConstraints.gridwidth = 2;
164: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
165: gridBagConstraints.weightx = 1.0;
166: gridBagConstraints.weighty = 1.0;
167: gridBagConstraints.insets = new java.awt.Insets(2, 2, 0, 2);
168: jPanel1.add(jScrollPane1, gridBagConstraints);
169:
170: jButtonSave.setText("Save");
171: jButtonSave
172: .addActionListener(new java.awt.event.ActionListener() {
173: public void actionPerformed(
174: java.awt.event.ActionEvent evt) {
175: jButtonSaveActionPerformed(evt);
176: }
177: });
178:
179: gridBagConstraints = new java.awt.GridBagConstraints();
180: gridBagConstraints.gridx = 1;
181: gridBagConstraints.gridy = 1;
182: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
183: gridBagConstraints.insets = new java.awt.Insets(1, 0, 2, 4);
184: jPanel1.add(jButtonSave, gridBagConstraints);
185:
186: jSplitPane1.setRightComponent(jPanel1);
187:
188: jPanel2.setLayout(new java.awt.GridBagLayout());
189:
190: jLabel2.setText("Objects");
191: gridBagConstraints = new java.awt.GridBagConstraints();
192: gridBagConstraints.gridx = 0;
193: gridBagConstraints.gridy = 0;
194: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
195: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
196: gridBagConstraints.weightx = 1.0;
197: gridBagConstraints.insets = new java.awt.Insets(4, 6, 0, 4);
198: jPanel2.add(jLabel2, gridBagConstraints);
199:
200: jTree1.setRootVisible(false);
201: jTree1
202: .addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
203: public void valueChanged(
204: javax.swing.event.TreeSelectionEvent evt) {
205: jTree1ValueChanged(evt);
206: }
207: });
208: jTree1.addMouseListener(new java.awt.event.MouseAdapter() {
209: public void mouseClicked(java.awt.event.MouseEvent evt) {
210: jTree1MouseClicked(evt);
211: }
212: });
213:
214: jScrollPane2.setViewportView(jTree1);
215:
216: gridBagConstraints = new java.awt.GridBagConstraints();
217: gridBagConstraints.gridx = 0;
218: gridBagConstraints.gridy = 1;
219: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
220: gridBagConstraints.weightx = 1.0;
221: gridBagConstraints.weighty = 1.0;
222: gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 0);
223: jPanel2.add(jScrollPane2, gridBagConstraints);
224:
225: jSplitPane1.setLeftComponent(jPanel2);
226:
227: getContentPane().add(jSplitPane1, java.awt.BorderLayout.CENTER);
228:
229: pack();
230: }// </editor-fold>//GEN-END:initComponents
231:
232: private void jButtonSaveActionPerformed(
233: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSaveActionPerformed
234:
235: int portion = getSelectedPortion();
236: jrf.getReport().getScripletCode().setPortionCode(portion,
237: this .jEditTextArea1.getText());
238: jComboBoxEventsActionPerformed(new java.awt.event.ActionEvent(
239: jButtonSave, 0, ""));
240: jrf.getReport().incrementReportChanges();
241:
242: }//GEN-LAST:event_jButtonSaveActionPerformed
243:
244: private void jTree1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTree1MouseClicked
245:
246: if (evt.getClickCount() == 2
247: && evt.getButton() == java.awt.event.MouseEvent.BUTTON1) {
248: TreePath path = jTree1.getSelectionPath();
249: if (path == null)
250: return;
251: TreeNode node = (TreeNode) path.getLastPathComponent();
252: if (node instanceof DefaultMutableTreeNode) {
253: DefaultMutableTreeNode nodem = (DefaultMutableTreeNode) node;
254: Object obj = nodem.getUserObject();
255: if (obj != null && obj instanceof JRVariable) {
256: String s = "getVariableValue(\"" + obj + "\")";
257: if (((JRVariable) obj).getClassType() != null
258: && ((JRVariable) obj).getClassType()
259: .length() > 0) {
260: s = "(" + ((JRVariable) obj).getClassType()
261: + ")" + s;
262: }
263: try {
264: jEditTextArea1.getDocument().insertString(
265: jEditTextArea1.getCaretPosition(),
266: s + "", null);
267: } catch (Exception ex) {
268: }
269: } else if (obj != null && obj instanceof JRParameter) {
270: String s = "(" + ((JRParameter) obj).getClassType()
271: + ")getParameterValue(\"" + obj + "\")";
272: try {
273: jEditTextArea1.getDocument().insertString(
274: jEditTextArea1.getCaretPosition(),
275: s + "", null);
276: } catch (Exception ex) {
277: }
278: } else if (obj != null && obj instanceof JRField) {
279:
280: String s = "(" + ((JRField) obj).getClassType()
281: + ")getFieldValue(\"" + obj + "\")";
282:
283: try {
284: jEditTextArea1.getDocument().insertString(
285: jEditTextArea1.getCaretPosition(),
286: s + "", null);
287: } catch (Exception ex) {
288: }
289: }
290: }
291: }
292:
293: }//GEN-LAST:event_jTree1MouseClicked
294:
295: private void jTree1ValueChanged(
296: javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_jTree1ValueChanged
297:
298: }//GEN-LAST:event_jTree1ValueChanged
299:
300: private void jComboBoxEventsActionPerformed(
301: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxEventsActionPerformed
302: if (jrf == null)
303: return;
304: int portion = getSelectedPortion();
305: this .jEditTextArea1.setText(jrf.getReport().getScripletCode()
306: .getPortion(portion));
307: }//GEN-LAST:event_jComboBoxEventsActionPerformed
308:
309: /** Exit the Application */
310: private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
311: setVisible(false);
312: }//GEN-LAST:event_exitForm
313:
314: /**
315: * @param args the command line arguments
316: */
317: public static void main(String args[]) {
318: new EventsForm().setVisible(true);
319: }
320:
321: // Variables declaration - do not modify//GEN-BEGIN:variables
322: private javax.swing.JButton jButtonSave;
323: private javax.swing.JComboBox jComboBoxEvents;
324: private org.syntax.jedit.JEditTextArea jEditTextArea1;
325: private javax.swing.JLabel jLabel1;
326: private javax.swing.JLabel jLabel2;
327: private javax.swing.JPanel jPanel1;
328: private javax.swing.JPanel jPanel2;
329: private javax.swing.JScrollPane jScrollPane1;
330: private javax.swing.JScrollPane jScrollPane2;
331: private javax.swing.JSplitPane jSplitPane1;
332: private javax.swing.JTree jTree1;
333: // End of variables declaration//GEN-END:variables
334:
335: private JReportFrame jrf;
336:
337: public int getSelectedPortion() {
338: return (int) Math.max(0, jComboBoxEvents.getSelectedIndex());
339: }
340:
341: /** Getter for property jrf.
342: * @return Value of property jrf.
343: *
344: */
345: public it.businesslogic.ireport.gui.JReportFrame getJrf() {
346: return jrf;
347: }
348:
349: /** Setter for property jrf.
350: * @param jrf New value of property jrf.
351: *
352: */
353: public void setJReportFrame(
354: it.businesslogic.ireport.gui.JReportFrame jrf) {
355: this .jrf = jrf;
356:
357: if (jrf == null
358: || jrf.getReport().getScriptletHandling() != Report.SCRIPTLET_IREPORT_INTERNAL_HANDLING
359: || jrf.getReport().getScripletCode() == null) {
360: this .setVisible(false);
361: return;
362: }
363:
364: DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) jTree1
365: .getModel().getRoot();
366: dmtn.removeAllChildren();
367:
368: DefaultMutableTreeNode dmtnFields = new DefaultMutableTreeNode(
369: "Fields");
370: Enumeration enumFields = jrf.getReport().getFields().elements();
371: while (enumFields.hasMoreElements()) {
372: dmtnFields.add(new DefaultMutableTreeNode(enumFields
373: .nextElement()));
374: }
375: dmtn.add(dmtnFields);
376:
377: DefaultMutableTreeNode dmtnVariables = new DefaultMutableTreeNode(
378: "Variables");
379: Enumeration enumVariables = jrf.getReport().getVariables()
380: .elements();
381: while (enumVariables.hasMoreElements()) {
382: dmtnVariables.add(new DefaultMutableTreeNode(enumVariables
383: .nextElement()));
384: }
385: dmtn.add(dmtnVariables);
386:
387: DefaultMutableTreeNode dmtnParameters = new DefaultMutableTreeNode(
388: "Parameters");
389: Enumeration enumParameters = jrf.getReport().getParameters()
390: .elements();
391: while (enumParameters.hasMoreElements()) {
392: dmtnParameters.add(new DefaultMutableTreeNode(
393: enumParameters.nextElement()));
394: }
395: dmtn.add(dmtnParameters);
396:
397: jTree1.updateUI();
398:
399: int portion = getSelectedPortion();
400: this .jEditTextArea1.setText(jrf.getReport().getScripletCode()
401: .getPortion(portion));
402: this .jEditTextArea1.setCaretPosition(0);
403: this .jEditTextArea1.updateUI();
404: this .jEditTextArea1.updateScrollBars();
405:
406: }
407:
408: public void applyI18n() {
409: // Start autogenerated code ----------------------
410: jButtonSave.setText(I18n.getString("eventsForm.buttonSave",
411: "Save"));
412: jLabel1.setText(I18n.getString("eventsForm.label1", "Events"));
413: jLabel2.setText(I18n.getString("eventsForm.label2", "Objects"));
414: // End autogenerated code ----------------------
415: }
416: }
|