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: * JRVariableDialog.java
028: *
029: * Created on 9 maggio 2003, 17.25
030: *
031: */
032:
033: package it.businesslogic.ireport.gui;
034:
035: import it.businesslogic.ireport.*;
036: import it.businesslogic.ireport.gui.sheet.Tag;
037: import it.businesslogic.ireport.util.*;
038:
039: /**
040: * @author Administrator
041: */
042: public class JRVariableDialog extends javax.swing.JDialog {
043:
044: /** Creates new form JRParameterDialog */
045: JRVariable tmpVariable = null;
046: private SubDataset subDataset = null;
047: private String originalName = null;
048:
049: /**
050: * Creates a new JRVariableDialog object.
051: *
052: * @param subDataset DOCUMENT ME!
053: * @param parent DOCUMENT ME!
054: * @param modal DOCUMENT ME!
055: */
056: public JRVariableDialog(SubDataset report, java.awt.Frame parent,
057: boolean modal) {
058: super (parent, modal);
059: initComponents();
060:
061: this .setSubDataset(report);
062: updateGroups();
063:
064: this .jRTextExpressionAreaExpression.setText("");
065: this .jRTextExpressionAreaInitialExpression.setText("");
066: setTypes();
067: this .jComboBoxClassType.setSelectedItem("java.lang.String");
068:
069: Misc.setComboboxSelectedTagValue(jComboBoxCalculationType,
070: "Nothing");
071: Misc.setComboboxSelectedTagValue(jComboBoxResetType, "Report");
072: Misc
073: .setComboboxSelectedTagValue(jComboBoxIncrementType,
074: "None");
075:
076: updateGroups();
077:
078: javax.swing.KeyStroke escape = javax.swing.KeyStroke
079: .getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0,
080: false);
081: javax.swing.Action escapeAction = new javax.swing.AbstractAction() {
082: public void actionPerformed(java.awt.event.ActionEvent e) {
083: jButtonCancelActionPerformed(e);
084: }
085: };
086:
087: getRootPane().getInputMap(
088: javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(
089: escape, "ESCAPE");
090: getRootPane().getActionMap().put("ESCAPE", escapeAction);
091:
092: applyI18n();
093: //to make the default button ...
094: this .getRootPane().setDefaultButton(this .jButtonOK);
095:
096: pack();
097: }
098:
099: public static final int COMPONENT_NONE = 0;
100: public static final int COMPONENT_VARIABLE_EXPRESSION = 1;
101: public static final int COMPONENT_VARIABLE_INIT_EXPRESSION = 2;
102:
103: /**
104: * This method set the focus on a specific component.
105: * Valid constants are something like:
106: * FIELD_XXX
107: */
108: public void setFocusedExpression(int expID) {
109: switch (expID) {
110: case COMPONENT_VARIABLE_EXPRESSION:
111: Misc.selectTextAndFocusArea(jRTextExpressionAreaExpression);
112: break;
113: case COMPONENT_VARIABLE_INIT_EXPRESSION:
114: Misc
115: .selectTextAndFocusArea(jRTextExpressionAreaInitialExpression);
116: break;
117: }
118:
119: }
120:
121: /**
122: * DOCUMENT ME!
123: */
124: public void setTypes() {
125: this .jComboBoxClassType.addItem("java.lang.String");
126: this .jComboBoxClassType.addItem("java.lang.Object");
127: this .jComboBoxClassType.addItem("java.lang.Boolean");
128: this .jComboBoxClassType.addItem("java.lang.Byte");
129: this .jComboBoxClassType.addItem("java.util.Date");
130: this .jComboBoxClassType.addItem("java.sql.Timestamp");
131: this .jComboBoxClassType.addItem("java.sql.Time");
132: this .jComboBoxClassType.addItem("java.lang.Double");
133: this .jComboBoxClassType.addItem("java.lang.Float");
134: this .jComboBoxClassType.addItem("java.lang.Integer");
135: this .jComboBoxClassType.addItem("java.io.InputStream");
136: this .jComboBoxClassType.addItem("java.lang.Long");
137: this .jComboBoxClassType.addItem("java.lang.Short");
138: this .jComboBoxClassType.addItem("java.math.BigDecimal");
139: this .jComboBoxClassType
140: .addItem("net.sf.jasperreports.engine.JREmptyDataSource");
141:
142: this .jComboBoxCalculationType.addItem(new Tag("Nothing", I18n
143: .getString("variable.calculationType.Nothing",
144: "Nothing")));
145: this .jComboBoxCalculationType.addItem(new Tag("Count", I18n
146: .getString("variable.calculationType.Count", "Count")));
147: this .jComboBoxCalculationType.addItem(new Tag("DistinctCount",
148: I18n.getString(
149: "variable.calculationType.DistinctCount",
150: "Distinct count")));
151: this .jComboBoxCalculationType.addItem(new Tag("Sum", I18n
152: .getString("variable.calculationType.Sum", "Sum")));
153: this .jComboBoxCalculationType.addItem(new Tag("Average", I18n
154: .getString("variable.calculationType.Average",
155: "Average")));
156: this .jComboBoxCalculationType
157: .addItem(new Tag("Lowest", I18n.getString(
158: "variable.calculationType.Lowest", "Lowest")));
159: this .jComboBoxCalculationType.addItem(new Tag("Highest", I18n
160: .getString("variable.calculationType.Highest",
161: "Highest")));
162: this .jComboBoxCalculationType.addItem(new Tag(
163: "StandardDeviation", I18n.getString(
164: "variable.calculationType.StandardDeviation",
165: "Standard deviation")));
166: this .jComboBoxCalculationType.addItem(new Tag("Variance", I18n
167: .getString("variable.calculationType.Variance",
168: "Variance")));
169: this .jComboBoxCalculationType
170: .addItem(new Tag("System", I18n.getString(
171: "variable.calculationType.System", "System")));
172: this .jComboBoxCalculationType.addItem(new Tag("First", I18n
173: .getString("variable.calculationType.First", "First")));
174:
175: this .jComboBoxResetType.addItem(new Tag("None",
176: it.businesslogic.ireport.util.I18n.getString(
177: "resetType.None", "None")));
178: this .jComboBoxResetType.addItem(new Tag("Report",
179: it.businesslogic.ireport.util.I18n.getString(
180: "resetType.Report", "Report")));
181: this .jComboBoxResetType.addItem(new Tag("Page",
182: it.businesslogic.ireport.util.I18n.getString(
183: "resetType.Page", "Page")));
184: this .jComboBoxResetType.addItem(new Tag("Column",
185: it.businesslogic.ireport.util.I18n.getString(
186: "resetType.Column", "Column")));
187: this .jComboBoxResetType.addItem(new Tag("Group",
188: it.businesslogic.ireport.util.I18n.getString(
189: "resetType.Group", "Group")));
190:
191: this .jComboBoxIncrementType.addItem(new Tag("None",
192: it.businesslogic.ireport.util.I18n.getString(
193: "incrementType.None", "None")));
194: this .jComboBoxIncrementType.addItem(new Tag("Report",
195: it.businesslogic.ireport.util.I18n.getString(
196: "incrementType.Report", "Report")));
197: this .jComboBoxIncrementType.addItem(new Tag("Page",
198: it.businesslogic.ireport.util.I18n.getString(
199: "incrementType.Page", "Page")));
200: this .jComboBoxIncrementType.addItem(new Tag("Column",
201: it.businesslogic.ireport.util.I18n.getString(
202: "incrementType.Column", "Column")));
203: this .jComboBoxIncrementType.addItem(new Tag("Group",
204: it.businesslogic.ireport.util.I18n.getString(
205: "incrementType.Group", "Group")));
206:
207: }
208:
209: /**
210: * DOCUMENT ME!
211: */
212: public void updateGroups() {
213:
214: if (getSubDataset() == null) {
215: jComboBoxResetGroup.removeAllItems();
216: jComboBoxResetGroup.addItem("");
217: } else {
218: Misc.updateStringComboBox(jComboBoxResetGroup,
219: getSubDataset().getGroups(), false);
220: Misc.updateStringComboBox(jComboBoxIncrementGroup,
221: getSubDataset().getGroups(), false);
222: }
223:
224: }
225:
226: /**
227: * This method is called from within the constructor to initialize the
228: * form. WARNING: Do NOT modify this code. The content of this method is
229: * always regenerated by the Form Editor.
230: */
231:
232: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
233: private void initComponents() {
234: java.awt.GridBagConstraints gridBagConstraints;
235:
236: jLabel1 = new javax.swing.JLabel();
237: jTextFieldName = new javax.swing.JTextField();
238: jLabel2 = new javax.swing.JLabel();
239: jComboBoxResetGroup = new javax.swing.JComboBox();
240: jLabel3 = new javax.swing.JLabel();
241: jLabel4 = new javax.swing.JLabel();
242: jLabel5 = new javax.swing.JLabel();
243: jComboBoxResetType = new javax.swing.JComboBox();
244: jComboBoxCalculationType = new javax.swing.JComboBox();
245: jLabel6 = new javax.swing.JLabel();
246: jComboBoxClassType = new javax.swing.JComboBox();
247: jLabel7 = new javax.swing.JLabel();
248: jRTextExpressionAreaExpression = new it.businesslogic.ireport.gui.JRTextExpressionArea();
249: jRTextExpressionAreaInitialExpression = new it.businesslogic.ireport.gui.JRTextExpressionArea();
250: jLabel8 = new javax.swing.JLabel();
251: jTextFieldNameIncrementerFactoryClass = new javax.swing.JTextField();
252: jPanel1 = new javax.swing.JPanel();
253: jButtonOK = new javax.swing.JButton();
254: jButtonCancel = new javax.swing.JButton();
255: jLabel9 = new javax.swing.JLabel();
256: jLabel10 = new javax.swing.JLabel();
257: jComboBoxIncrementType = new javax.swing.JComboBox();
258: jComboBoxIncrementGroup = new javax.swing.JComboBox();
259:
260: getContentPane().setLayout(new java.awt.GridBagLayout());
261:
262: setTitle("Add/modify variable");
263: setModal(true);
264: addWindowListener(new java.awt.event.WindowAdapter() {
265: public void windowClosing(java.awt.event.WindowEvent evt) {
266: closeDialog(evt);
267: }
268: });
269:
270: jLabel1.setText("Variable name");
271: gridBagConstraints = new java.awt.GridBagConstraints();
272: gridBagConstraints.gridx = 0;
273: gridBagConstraints.gridy = 0;
274: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
275: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
276: getContentPane().add(jLabel1, gridBagConstraints);
277:
278: gridBagConstraints = new java.awt.GridBagConstraints();
279: gridBagConstraints.gridx = 0;
280: gridBagConstraints.gridy = 1;
281: gridBagConstraints.gridwidth = 3;
282: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
283: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
284: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
285: getContentPane().add(jTextFieldName, gridBagConstraints);
286:
287: jLabel2.setText("Calculation type");
288: gridBagConstraints = new java.awt.GridBagConstraints();
289: gridBagConstraints.gridx = 1;
290: gridBagConstraints.gridy = 2;
291: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
292: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
293: getContentPane().add(jLabel2, gridBagConstraints);
294:
295: gridBagConstraints = new java.awt.GridBagConstraints();
296: gridBagConstraints.gridx = 1;
297: gridBagConstraints.gridy = 5;
298: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
299: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
300: gridBagConstraints.weightx = 1.0;
301: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
302: getContentPane().add(jComboBoxResetGroup, gridBagConstraints);
303:
304: jLabel3.setText("Variable expression");
305: gridBagConstraints = new java.awt.GridBagConstraints();
306: gridBagConstraints.gridx = 0;
307: gridBagConstraints.gridy = 10;
308: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
309: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
310: getContentPane().add(jLabel3, gridBagConstraints);
311:
312: jLabel4.setText("Initial value expression");
313: gridBagConstraints = new java.awt.GridBagConstraints();
314: gridBagConstraints.gridx = 0;
315: gridBagConstraints.gridy = 12;
316: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
317: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
318: getContentPane().add(jLabel4, gridBagConstraints);
319:
320: jLabel5.setText("Variable class type");
321: gridBagConstraints = new java.awt.GridBagConstraints();
322: gridBagConstraints.gridx = 0;
323: gridBagConstraints.gridy = 2;
324: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
325: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
326: getContentPane().add(jLabel5, gridBagConstraints);
327:
328: jComboBoxResetType
329: .addActionListener(new java.awt.event.ActionListener() {
330: public void actionPerformed(
331: java.awt.event.ActionEvent evt) {
332: jComboBoxResetTypeActionPerformed(evt);
333: }
334: });
335:
336: gridBagConstraints = new java.awt.GridBagConstraints();
337: gridBagConstraints.gridx = 0;
338: gridBagConstraints.gridy = 5;
339: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
340: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
341: gridBagConstraints.weightx = 1.0;
342: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
343: getContentPane().add(jComboBoxResetType, gridBagConstraints);
344:
345: gridBagConstraints = new java.awt.GridBagConstraints();
346: gridBagConstraints.gridx = 1;
347: gridBagConstraints.gridy = 3;
348: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
349: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
350: gridBagConstraints.weightx = 1.0;
351: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
352: getContentPane().add(jComboBoxCalculationType,
353: gridBagConstraints);
354:
355: jLabel6.setText("Reset group");
356: gridBagConstraints = new java.awt.GridBagConstraints();
357: gridBagConstraints.gridx = 1;
358: gridBagConstraints.gridy = 4;
359: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
360: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
361: getContentPane().add(jLabel6, gridBagConstraints);
362:
363: jComboBoxClassType.setEditable(true);
364: gridBagConstraints = new java.awt.GridBagConstraints();
365: gridBagConstraints.gridx = 0;
366: gridBagConstraints.gridy = 3;
367: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
368: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
369: gridBagConstraints.weightx = 1.0;
370: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
371: getContentPane().add(jComboBoxClassType, gridBagConstraints);
372:
373: jLabel7.setText("Reset type");
374: gridBagConstraints = new java.awt.GridBagConstraints();
375: gridBagConstraints.gridx = 0;
376: gridBagConstraints.gridy = 4;
377: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
378: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
379: getContentPane().add(jLabel7, gridBagConstraints);
380:
381: jRTextExpressionAreaExpression
382: .setBorder(javax.swing.BorderFactory
383: .createEtchedBorder());
384: jRTextExpressionAreaExpression.setCaretVisible(false);
385: jRTextExpressionAreaExpression.setElectricScroll(0);
386: jRTextExpressionAreaExpression
387: .setMinimumSize(new java.awt.Dimension(657, 100));
388: jRTextExpressionAreaExpression
389: .setNextFocusableComponent(jRTextExpressionAreaInitialExpression);
390: jRTextExpressionAreaExpression
391: .setPreferredSize(new java.awt.Dimension(325, 70));
392: gridBagConstraints = new java.awt.GridBagConstraints();
393: gridBagConstraints.gridx = 0;
394: gridBagConstraints.gridy = 11;
395: gridBagConstraints.gridwidth = 2;
396: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
397: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
398: gridBagConstraints.weightx = 1.0;
399: gridBagConstraints.weighty = 1.0;
400: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
401: getContentPane().add(jRTextExpressionAreaExpression,
402: gridBagConstraints);
403:
404: jRTextExpressionAreaInitialExpression
405: .setBorder(javax.swing.BorderFactory
406: .createEtchedBorder());
407: jRTextExpressionAreaInitialExpression.setCaretVisible(false);
408: jRTextExpressionAreaInitialExpression.setElectricScroll(0);
409: jRTextExpressionAreaInitialExpression
410: .setFont(new java.awt.Font("Tahoma", 0, 12));
411: jRTextExpressionAreaInitialExpression
412: .setMinimumSize(new java.awt.Dimension(657, 100));
413: jRTextExpressionAreaInitialExpression
414: .setPreferredSize(new java.awt.Dimension(325, 70));
415: gridBagConstraints = new java.awt.GridBagConstraints();
416: gridBagConstraints.gridx = 0;
417: gridBagConstraints.gridy = 13;
418: gridBagConstraints.gridwidth = 2;
419: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
420: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
421: gridBagConstraints.weightx = 1.0;
422: gridBagConstraints.weighty = 1.0;
423: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
424: getContentPane().add(jRTextExpressionAreaInitialExpression,
425: gridBagConstraints);
426:
427: jLabel8.setText("Custom Incrementer Factory Class");
428: gridBagConstraints = new java.awt.GridBagConstraints();
429: gridBagConstraints.gridx = 0;
430: gridBagConstraints.gridy = 8;
431: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
432: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
433: getContentPane().add(jLabel8, gridBagConstraints);
434:
435: jTextFieldNameIncrementerFactoryClass
436: .setNextFocusableComponent(jRTextExpressionAreaExpression);
437: gridBagConstraints = new java.awt.GridBagConstraints();
438: gridBagConstraints.gridx = 0;
439: gridBagConstraints.gridy = 9;
440: gridBagConstraints.gridwidth = 2;
441: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
442: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
443: gridBagConstraints.weightx = 1.0;
444: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
445: getContentPane().add(jTextFieldNameIncrementerFactoryClass,
446: gridBagConstraints);
447:
448: jPanel1.setLayout(new java.awt.FlowLayout(
449: java.awt.FlowLayout.RIGHT));
450:
451: jButtonOK.setMnemonic('o');
452: jButtonOK.setText("OK");
453: jButtonOK
454: .addActionListener(new java.awt.event.ActionListener() {
455: public void actionPerformed(
456: java.awt.event.ActionEvent evt) {
457: jButtonOKActionPerformed(evt);
458: }
459: });
460:
461: jPanel1.add(jButtonOK);
462:
463: jButtonCancel.setText("Cancel");
464: jButtonCancel.setMnemonic('c');
465: jButtonCancel
466: .addActionListener(new java.awt.event.ActionListener() {
467: public void actionPerformed(
468: java.awt.event.ActionEvent evt) {
469: jButtonCancelActionPerformed(evt);
470: }
471: });
472:
473: jPanel1.add(jButtonCancel);
474:
475: gridBagConstraints = new java.awt.GridBagConstraints();
476: gridBagConstraints.gridx = 0;
477: gridBagConstraints.gridy = 14;
478: gridBagConstraints.gridwidth = 3;
479: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
480: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
481: gridBagConstraints.weightx = 1.0;
482: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
483: getContentPane().add(jPanel1, gridBagConstraints);
484:
485: jLabel9.setText("Increment type");
486: gridBagConstraints = new java.awt.GridBagConstraints();
487: gridBagConstraints.gridx = 0;
488: gridBagConstraints.gridy = 6;
489: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
490: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
491: getContentPane().add(jLabel9, gridBagConstraints);
492:
493: jLabel10.setText("Increment group");
494: gridBagConstraints = new java.awt.GridBagConstraints();
495: gridBagConstraints.gridx = 1;
496: gridBagConstraints.gridy = 6;
497: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
498: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
499: getContentPane().add(jLabel10, gridBagConstraints);
500:
501: jComboBoxIncrementType
502: .addActionListener(new java.awt.event.ActionListener() {
503: public void actionPerformed(
504: java.awt.event.ActionEvent evt) {
505: jComboBoxIncrementTypeActionPerformed(evt);
506: }
507: });
508:
509: gridBagConstraints = new java.awt.GridBagConstraints();
510: gridBagConstraints.gridx = 0;
511: gridBagConstraints.gridy = 7;
512: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
513: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
514: gridBagConstraints.weightx = 1.0;
515: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
516: getContentPane()
517: .add(jComboBoxIncrementType, gridBagConstraints);
518:
519: gridBagConstraints = new java.awt.GridBagConstraints();
520: gridBagConstraints.gridx = 1;
521: gridBagConstraints.gridy = 7;
522: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
523: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
524: gridBagConstraints.weightx = 1.0;
525: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
526: getContentPane().add(jComboBoxIncrementGroup,
527: gridBagConstraints);
528:
529: pack();
530: java.awt.Dimension screenSize = java.awt.Toolkit
531: .getDefaultToolkit().getScreenSize();
532: java.awt.Dimension dialogSize = getSize();
533: setLocation((screenSize.width - dialogSize.width) / 2,
534: (screenSize.height - dialogSize.height) / 2);
535: }// </editor-fold>//GEN-END:initComponents
536:
537: private void jComboBoxIncrementTypeActionPerformed(
538: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxIncrementTypeActionPerformed
539:
540: Object t = jComboBoxIncrementType.getSelectedItem();
541: String val = t + "";
542:
543: if (t != null && t instanceof Tag) {
544: val = "" + ((Tag) t).getValue();
545: }
546:
547: jComboBoxIncrementGroup.setEnabled(val.equals("Group"));
548:
549: if (jComboBoxIncrementGroup.isEnabled()
550: && jComboBoxIncrementGroup.getSelectedItem() == null
551: && jComboBoxIncrementGroup.getItemCount() > 0) {
552: jComboBoxIncrementGroup.setSelectedIndex(0);
553: }
554: }//GEN-LAST:event_jComboBoxIncrementTypeActionPerformed
555:
556: private void jComboBoxResetTypeActionPerformed(
557: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxResetTypeActionPerformed
558:
559: Object t = jComboBoxResetType.getSelectedItem();
560: String val = t + "";
561:
562: if (t != null && t instanceof Tag) {
563: val = "" + ((Tag) t).getValue();
564: }
565:
566: jComboBoxResetGroup.setEnabled(val.equals("Group"));
567:
568: if (jComboBoxResetGroup.isEnabled()
569: && jComboBoxResetGroup.getSelectedItem() == null
570: && jComboBoxResetGroup.getItemCount() > 0) {
571: jComboBoxResetGroup.setSelectedIndex(0);
572: }
573:
574: }//GEN-LAST:event_jComboBoxResetTypeActionPerformed
575:
576: private void jButtonCancelActionPerformed(
577: java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonCancelActionPerformed
578: {
579: setVisible(false);
580: this .setDialogResult(javax.swing.JOptionPane.CANCEL_OPTION);
581: dispose();
582: }//GEN-LAST:event_jButtonCancelActionPerformed
583:
584: private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonOKActionPerformed
585: {
586:
587: if (this .jTextFieldName.getText().trim().length() <= 0) {
588: javax.swing.JOptionPane
589: .showMessageDialog(
590: this ,
591: I18n
592: .getString(
593: "messages.jRVariableDialog.notValidName",
594: "Please insert a valid variable name!"),
595: I18n
596: .getString(
597: "messages.jRVariableDialog.notValidNameCaption",
598: "Invalid variable!"),
599: javax.swing.JOptionPane.WARNING_MESSAGE);
600:
601: return;
602: }
603:
604: tmpVariable = new JRVariable(this .jTextFieldName.getText(),
605: false);
606: tmpVariable.setClassType(this .jComboBoxClassType
607: .getSelectedItem()
608: + "");
609:
610: Object t = this .jComboBoxCalculationType.getSelectedItem();
611: if (t != null && t instanceof Tag)
612: tmpVariable.setCalculation(((Tag) t).getValue() + "");
613:
614: t = this .jComboBoxResetType.getSelectedItem();
615: if (t != null && t instanceof Tag)
616: tmpVariable.setResetType(((Tag) t).getValue() + "");
617:
618: t = this .jComboBoxIncrementType.getSelectedItem();
619: if (t != null && t instanceof Tag)
620: tmpVariable.setIncrementType(((Tag) t).getValue() + "");
621:
622: //System.out.println(this.jComboBoxIncrementType.getSelectedItem()+" "+ tmpVariable.getIncrementType());
623: tmpVariable
624: .setIncrementerFactoryClass(this .jTextFieldNameIncrementerFactoryClass
625: .getText());
626:
627: if (this .jComboBoxClassType.getSelectedItem().toString().trim()
628: .length() == 0) {
629: tmpVariable.setClassType("java.lang.String");
630: }
631:
632: else {
633: tmpVariable.setClassType(this .jComboBoxClassType
634: .getSelectedItem().toString().trim());
635: }
636:
637: if (tmpVariable.getResetType().equals("Group")) {
638:
639: if (this .jComboBoxResetGroup.getSelectedItem() == null
640: || this .jComboBoxResetGroup.getSelectedItem()
641: .equals("")) {
642: javax.swing.JOptionPane
643: .showMessageDialog(
644: this ,
645: I18n
646: .getString(
647: "messages.jRVariableDialog.notValidGroup",
648: "Please choose a valid group for the reset type selected!"),
649: I18n
650: .getString(
651: "messages.jRVariableDialog.notValidGroupCaption",
652: "Invalid group!"),
653: javax.swing.JOptionPane.WARNING_MESSAGE);
654:
655: return;
656: }
657:
658: tmpVariable.setResetGroup(this .jComboBoxResetGroup
659: .getSelectedItem()
660: + "");
661: }
662:
663: if (tmpVariable.getIncrementType().equals("Group")) {
664:
665: if (this .jComboBoxIncrementGroup.getSelectedItem() == null
666: || this .jComboBoxIncrementGroup.getSelectedItem()
667: .equals("")) {
668: javax.swing.JOptionPane
669: .showMessageDialog(
670: this ,
671: I18n
672: .getString(
673: "messages.jRVariableDialog.notValidGroupIncrementType",
674: "Please choose a valid group for the increment type selected!"),
675: I18n
676: .getString(
677: "messages.jRVariableDialog.notValidGroupIncrementTypeCaption",
678: "Invalid group!"),
679: javax.swing.JOptionPane.WARNING_MESSAGE);
680:
681: return;
682: }
683:
684: tmpVariable.setIncrementGroup(this .jComboBoxIncrementGroup
685: .getSelectedItem()
686: + "");
687: }
688:
689: if (getSubDataset() != null) {
690: //check unique name...
691: String newName = this .jTextFieldName.getText();
692: if (getOriginalName() == null
693: || !getOriginalName().equals(newName)) {
694: for (int i = 0; i < getSubDataset().getVariables()
695: .size(); ++i) {
696: JRVariable f = (JRVariable) getSubDataset()
697: .getVariables().get(i);
698: if (f.getName().equals(newName)) {
699: javax.swing.JOptionPane
700: .showMessageDialog(
701: this ,
702: I18n
703: .getString(
704: "messages.JRVariableDialog.DuplicatedVariableName",
705: "A variable with this name already exists!"),
706: I18n
707: .getString(
708: "messages.JRVariableDialog.notValidVariableNameCaption",
709: "Invalid variable!"),
710: javax.swing.JOptionPane.WARNING_MESSAGE);
711: return;
712: }
713: }
714: }
715: }
716:
717: tmpVariable.setExpression(jRTextExpressionAreaExpression
718: .getText());
719:
720: tmpVariable
721: .setInitialValueExpression(jRTextExpressionAreaInitialExpression
722: .getText());
723:
724: setVisible(false);
725: this .setDialogResult(javax.swing.JOptionPane.OK_OPTION);
726: dispose();
727: }//GEN-LAST:event_jButtonOKActionPerformed
728:
729: /**
730: * Closes the dialog
731: * @param evt DOCUMENT ME!
732: */
733: private void closeDialog(java.awt.event.WindowEvent evt)//GEN-FIRST:event_closeDialog
734: {
735: setVisible(false);
736: this .setDialogResult(javax.swing.JOptionPane.CLOSED_OPTION);
737: dispose();
738: }//GEN-LAST:event_closeDialog
739:
740: /**
741: * @param args the command line arguments
742: */
743: public static void main(String[] args) {
744: new JRParameterDialog(new javax.swing.JFrame(), true)
745: .setVisible(true);
746: }
747:
748: /**
749: * Getter for property tmpParameter.
750: *
751: * @return Value of property tmpParameter.
752: */
753: public it.businesslogic.ireport.JRVariable getVariable() {
754:
755: return tmpVariable;
756: }
757:
758: /**
759: * Setter for property tmpParameter.
760: *
761: * @param tmpVariable New value of property tmpParameter.
762: */
763: public void setVariable(
764: it.businesslogic.ireport.JRVariable tmpVariable) {
765: originalName = tmpVariable.getName();
766: this .jTextFieldName.setText(new String(tmpVariable.getName()));
767:
768: this .jComboBoxClassType.setSelectedItem(new String(tmpVariable
769: .getClassType()));
770:
771: Misc.setComboboxSelectedTagValue(jComboBoxResetType,
772: tmpVariable.getResetType());
773: Misc.setComboboxSelectedTagValue(jComboBoxIncrementType,
774: tmpVariable.getIncrementType());
775: Misc.setComboboxSelectedTagValue(jComboBoxCalculationType,
776: tmpVariable.getCalculation());
777:
778: this .jComboBoxResetGroup.setSelectedItem(tmpVariable
779: .getResetGroup());
780: this .jComboBoxIncrementGroup.setSelectedItem(tmpVariable
781: .getIncrementGroup());
782:
783: this .jRTextExpressionAreaExpression.setText(new String(
784: tmpVariable.getExpression()));
785: this .jRTextExpressionAreaInitialExpression.setText(new String(
786: tmpVariable.getInitialValueExpression()));
787: this .jTextFieldNameIncrementerFactoryClass.setText(new String(
788: tmpVariable.getIncrementerFactoryClass()));
789: }
790:
791: /**
792: * Getter for property dialogResult.
793: *
794: * @return Value of property dialogResult.
795: */
796: public int getDialogResult() {
797:
798: return dialogResult;
799: }
800:
801: /**
802: * Setter for property dialogResult.
803: *
804: * @param dialogResult New value of property dialogResult.
805: */
806: public void setDialogResult(int dialogResult) {
807: this .dialogResult = dialogResult;
808: }
809:
810: // Variables declaration - do not modify//GEN-BEGIN:variables
811: private javax.swing.JButton jButtonCancel;
812: private javax.swing.JButton jButtonOK;
813: private javax.swing.JComboBox jComboBoxCalculationType;
814: private javax.swing.JComboBox jComboBoxClassType;
815: private javax.swing.JComboBox jComboBoxIncrementGroup;
816: private javax.swing.JComboBox jComboBoxIncrementType;
817: private javax.swing.JComboBox jComboBoxResetGroup;
818: private javax.swing.JComboBox jComboBoxResetType;
819: private javax.swing.JLabel jLabel1;
820: private javax.swing.JLabel jLabel10;
821: private javax.swing.JLabel jLabel2;
822: private javax.swing.JLabel jLabel3;
823: private javax.swing.JLabel jLabel4;
824: private javax.swing.JLabel jLabel5;
825: private javax.swing.JLabel jLabel6;
826: private javax.swing.JLabel jLabel7;
827: private javax.swing.JLabel jLabel8;
828: private javax.swing.JLabel jLabel9;
829: private javax.swing.JPanel jPanel1;
830: private it.businesslogic.ireport.gui.JRTextExpressionArea jRTextExpressionAreaExpression;
831: private it.businesslogic.ireport.gui.JRTextExpressionArea jRTextExpressionAreaInitialExpression;
832: private javax.swing.JTextField jTextFieldName;
833: private javax.swing.JTextField jTextFieldNameIncrementerFactoryClass;
834: // End of variables declaration//GEN-END:variables
835: private int dialogResult;
836:
837: public SubDataset getSubDataset() {
838: return subDataset;
839: }
840:
841: public void setSubDataset(SubDataset subDataset) {
842: this .subDataset = subDataset;
843: jRTextExpressionAreaExpression.setSubDataset(subDataset);
844: jRTextExpressionAreaInitialExpression.setSubDataset(subDataset);
845: jRTextExpressionAreaExpression.getTokenMarker()
846: .setKeywordLookup(subDataset.getKeywordLookup());
847: jRTextExpressionAreaInitialExpression.getTokenMarker()
848: .setKeywordLookup(subDataset.getKeywordLookup());
849: }
850:
851: public void applyI18n() {
852: // Start autogenerated code ----------------------
853: jButtonCancel.setText(I18n.getString(
854: "jRVariableDialog.buttonCancel", "Cancel"));
855: jButtonOK.setText(I18n.getString("jRVariableDialog.buttonOK",
856: "OK"));
857: jLabel1.setText(I18n.getString("jRVariableDialog.label1",
858: "Variable name"));
859: jLabel10.setText(I18n.getString("jRVariableDialog.label10",
860: "Increment group"));
861: jLabel2.setText(I18n.getString("jRVariableDialog.label2",
862: "Calculation type"));
863: jLabel3.setText(I18n.getString("jRVariableDialog.label3",
864: "Variable expression"));
865: jLabel4.setText(I18n.getString("jRVariableDialog.label4",
866: "Initial value expression"));
867: jLabel5.setText(I18n.getString("jRVariableDialog.label5",
868: "Variable class type"));
869: jLabel6.setText(I18n.getString("jRVariableDialog.label6",
870: "Reset group"));
871: jLabel7.setText(I18n.getString("jRVariableDialog.label7",
872: "Reset type"));
873: jLabel8.setText(I18n.getString("jRVariableDialog.label8",
874: "Custom Incrementer Factory Class"));
875: jLabel9.setText(I18n.getString("jRVariableDialog.label9",
876: "Increment type"));
877: // End autogenerated code ----------------------
878: this .setTitle(I18n.getString("jRVariableDialog.title",
879: "Add/modify variable"));
880: jButtonCancel
881: .setMnemonic(I18n.getString(
882: "jRVariableDialog.buttonCancelMnemonic", "c")
883: .charAt(0));
884: jButtonOK.setMnemonic(I18n.getString(
885: "jRVariableDialog.buttonOKMnemonic", "o").charAt(0));
886: }
887:
888: public String getOriginalName() {
889: return originalName;
890: }
891:
892: public void setOriginalName(String originalName) {
893: this.originalName = originalName;
894: }
895: }
|