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: * SerieDialog.java
028: *
029: * Created on 21 settembre 2004, 20.34
030: *
031: */
032:
033: package it.businesslogic.ireport.chart.gui;
034:
035: import it.businesslogic.ireport.gui.library.CustomExpression;
036: import it.businesslogic.ireport.gui.*;
037: import it.businesslogic.ireport.*;
038: import javax.swing.tree.*;
039: import it.businesslogic.ireport.util.I18n;
040:
041: /**
042: *
043: * @author Administrator
044: */
045: public class SerieDialog extends javax.swing.JDialog {
046:
047: int dialogResult = 0;
048:
049: private JReportFrame jrf = null;
050: private String serieExpression = null;
051: private String serieName = null;
052: private String serieReset = null;
053: private String serieType = null;
054:
055: /** Creates new form TotalObjectDialog */
056: public SerieDialog(java.awt.Dialog parent, boolean modal) {
057: super (parent, modal);
058: initComponents();
059:
060: initFrame();
061: }
062:
063: public void initFrame() {
064:
065: this .setSize(400, 450);
066:
067: this .setModal(true);
068:
069: org.syntax.jedit.SyntaxDocument sd = new org.syntax.jedit.SyntaxDocument();
070: sd
071: .setTokenMarker(new org.syntax.jedit.tokenmarker.JavaTokenMarker());
072:
073: this .jRTextExpressionAreaDefaultExpression.setDocument(sd);
074:
075: this .jComboBoxClassType.addItem("java.lang.String");
076: this .jComboBoxClassType.addItem("java.lang.Object");
077: this .jComboBoxClassType.addItem("java.lang.Boolean");
078: this .jComboBoxClassType.addItem("java.lang.Byte");
079: this .jComboBoxClassType.addItem("java.util.Date");
080: this .jComboBoxClassType.addItem("java.sql.Timestamp");
081: this .jComboBoxClassType.addItem("java.sql.Time");
082: this .jComboBoxClassType.addItem("java.lang.Double");
083: this .jComboBoxClassType.addItem("java.lang.Float");
084: this .jComboBoxClassType.addItem("java.lang.Integer");
085: this .jComboBoxClassType.addItem("java.io.InputStream");
086: this .jComboBoxClassType.addItem("java.lang.Long");
087: this .jComboBoxClassType.addItem("java.lang.Short");
088: this .jComboBoxClassType.addItem("java.math.BigDecimal");
089:
090: //jLabelTitle.setText( it.businesslogic.ireport.util.I18n.getString("gui.library.totalobject.title","Select object to sum") );
091:
092: this .dialogResult = javax.swing.JOptionPane.CANCEL_OPTION;
093:
094: it.businesslogic.ireport.util.Misc.centerFrame(this );
095:
096: javax.swing.KeyStroke escape = javax.swing.KeyStroke
097: .getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0,
098: false);
099: javax.swing.Action escapeAction = new javax.swing.AbstractAction() {
100: public void actionPerformed(java.awt.event.ActionEvent e) {
101: jButtonCancelActionPerformed(e);
102: }
103: };
104:
105: getRootPane().getInputMap(
106: javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(
107: escape, "ESCAPE");
108: getRootPane().getActionMap().put("ESCAPE", escapeAction);
109:
110: applyI18n();
111:
112: //to make the default button ...
113: this .getRootPane().setDefaultButton(this .jButtonOK);
114: }
115:
116: public void setVariable(it.businesslogic.ireport.JRVariable var) {
117: String var_name = var.getName();
118: var_name = var_name.substring("SERIE_".length());
119: if (var_name.startsWith("G_")) {
120: var_name = var_name.substring(2);
121: // Search the right group...
122: String grp_name = "";
123: java.util.Enumeration enum_groups = getJrf().getReport()
124: .getGroups().elements();
125: while (enum_groups.hasMoreElements()) {
126: Group g = (Group) enum_groups.nextElement();
127: grp_name = g.getName();
128: if (var_name.startsWith(grp_name + "_")) {
129: break;
130: }
131: }
132:
133: this .jComboBox1.setSelectedItem(grp_name);
134: var_name = var_name.substring(grp_name.length() + 1);
135: } else {
136: this .jComboBox1.setSelectedIndex(0);
137:
138: }
139: this .jTextFieldName.setText(var_name);
140: this .jComboBoxClassType.setSelectedItem(var.getClassType());
141: this .jRTextExpressionAreaDefaultExpression.setText(var
142: .getExpression());
143:
144: }
145:
146: /** This method is called from within the constructor to
147: * initialize the form.
148: * WARNING: Do NOT modify this code. The content of this method is
149: * always regenerated by the Form Editor.
150: */
151: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
152: private void initComponents() {
153: java.awt.GridBagConstraints gridBagConstraints;
154:
155: jLabelTitle = new javax.swing.JLabel();
156: jRTextExpressionAreaDefaultExpression = new it.businesslogic.ireport.gui.JRTextExpressionArea();
157: jPanel1 = new javax.swing.JPanel();
158: jPanel2 = new javax.swing.JPanel();
159: jButtonOK = new javax.swing.JButton();
160: jButtonCancel = new javax.swing.JButton();
161: jTextFieldName = new javax.swing.JTextField();
162: jLabelName = new javax.swing.JLabel();
163: jLabelName1 = new javax.swing.JLabel();
164: jComboBox1 = new javax.swing.JComboBox();
165: jLabelName2 = new javax.swing.JLabel();
166: jComboBoxClassType = new javax.swing.JComboBox();
167:
168: getContentPane().setLayout(new java.awt.GridBagLayout());
169:
170: setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
171: jLabelTitle
172: .setText("Serie expression (the single object of this serie)");
173: gridBagConstraints = new java.awt.GridBagConstraints();
174: gridBagConstraints.gridx = 0;
175: gridBagConstraints.gridy = 3;
176: gridBagConstraints.gridwidth = 2;
177: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
178: gridBagConstraints.insets = new java.awt.Insets(8, 4, 0, 4);
179: getContentPane().add(jLabelTitle, gridBagConstraints);
180:
181: jRTextExpressionAreaDefaultExpression
182: .setBorder(javax.swing.BorderFactory
183: .createEtchedBorder());
184: jRTextExpressionAreaDefaultExpression.setElectricScroll(0);
185: jRTextExpressionAreaDefaultExpression
186: .setMinimumSize(new java.awt.Dimension(0, 60));
187: jRTextExpressionAreaDefaultExpression
188: .setPreferredSize(new java.awt.Dimension(310, 60));
189: gridBagConstraints = new java.awt.GridBagConstraints();
190: gridBagConstraints.gridx = 0;
191: gridBagConstraints.gridy = 5;
192: gridBagConstraints.gridwidth = 2;
193: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
194: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
195: gridBagConstraints.weighty = 0.2;
196: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
197: getContentPane().add(jRTextExpressionAreaDefaultExpression,
198: gridBagConstraints);
199:
200: jPanel1.setLayout(new java.awt.GridBagLayout());
201:
202: jPanel1.setMinimumSize(new java.awt.Dimension(10, 30));
203: jPanel1.setPreferredSize(new java.awt.Dimension(10, 30));
204: gridBagConstraints = new java.awt.GridBagConstraints();
205: gridBagConstraints.gridx = 0;
206: gridBagConstraints.gridy = 0;
207: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
208: gridBagConstraints.weightx = 1.0;
209: jPanel1.add(jPanel2, gridBagConstraints);
210:
211: jButtonOK.setText("OK");
212: jButtonOK
213: .addActionListener(new java.awt.event.ActionListener() {
214: public void actionPerformed(
215: java.awt.event.ActionEvent evt) {
216: jButtonOKActionPerformed(evt);
217: }
218: });
219:
220: jPanel1.add(jButtonOK, new java.awt.GridBagConstraints());
221:
222: jButtonCancel.setText("Cancel");
223: jButtonCancel
224: .addActionListener(new java.awt.event.ActionListener() {
225: public void actionPerformed(
226: java.awt.event.ActionEvent evt) {
227: jButtonCancelActionPerformed(evt);
228: }
229: });
230:
231: gridBagConstraints = new java.awt.GridBagConstraints();
232: gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 0);
233: jPanel1.add(jButtonCancel, gridBagConstraints);
234:
235: gridBagConstraints = new java.awt.GridBagConstraints();
236: gridBagConstraints.gridx = 0;
237: gridBagConstraints.gridy = 6;
238: gridBagConstraints.gridwidth = 2;
239: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
240: gridBagConstraints.insets = new java.awt.Insets(0, 4, 4, 4);
241: getContentPane().add(jPanel1, gridBagConstraints);
242:
243: gridBagConstraints = new java.awt.GridBagConstraints();
244: gridBagConstraints.gridx = 1;
245: gridBagConstraints.gridy = 1;
246: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
247: gridBagConstraints.weightx = 0.75;
248: gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 4);
249: getContentPane().add(jTextFieldName, gridBagConstraints);
250:
251: jLabelName.setText("Serie name");
252: jLabelName.setMaximumSize(new java.awt.Dimension(40, 16));
253: jLabelName.setMinimumSize(new java.awt.Dimension(40, 16));
254: gridBagConstraints = new java.awt.GridBagConstraints();
255: gridBagConstraints.gridx = 0;
256: gridBagConstraints.gridy = 1;
257: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
258: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
259: gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 0);
260: getContentPane().add(jLabelName, gridBagConstraints);
261:
262: jLabelName1.setText("Reset when");
263: jLabelName1.setMaximumSize(new java.awt.Dimension(40, 16));
264: jLabelName1.setMinimumSize(new java.awt.Dimension(40, 16));
265: gridBagConstraints = new java.awt.GridBagConstraints();
266: gridBagConstraints.gridx = 0;
267: gridBagConstraints.gridy = 2;
268: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
269: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
270: gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 0);
271: getContentPane().add(jLabelName1, gridBagConstraints);
272:
273: gridBagConstraints = new java.awt.GridBagConstraints();
274: gridBagConstraints.gridx = 1;
275: gridBagConstraints.gridy = 2;
276: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
277: gridBagConstraints.weightx = 1.0;
278: gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 4);
279: getContentPane().add(jComboBox1, gridBagConstraints);
280:
281: jLabelName2.setText("Exp Class");
282: jLabelName2.setMaximumSize(new java.awt.Dimension(40, 16));
283: jLabelName2.setMinimumSize(new java.awt.Dimension(40, 16));
284: gridBagConstraints = new java.awt.GridBagConstraints();
285: gridBagConstraints.gridx = 0;
286: gridBagConstraints.gridy = 4;
287: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
288: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
289: gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 0);
290: getContentPane().add(jLabelName2, gridBagConstraints);
291:
292: jComboBoxClassType.setEditable(true);
293: gridBagConstraints = new java.awt.GridBagConstraints();
294: gridBagConstraints.gridx = 1;
295: gridBagConstraints.gridy = 4;
296: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
297: gridBagConstraints.weightx = 1.0;
298: gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 4);
299: getContentPane().add(jComboBoxClassType, gridBagConstraints);
300:
301: pack();
302: }// </editor-fold>//GEN-END:initComponents
303:
304: private void jButtonCancelActionPerformed(
305: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
306: this .dialogResult = javax.swing.JOptionPane.CANCEL_OPTION;
307: this .setVisible(false);
308: dispose(); // TODO add your handling code here:
309: }//GEN-LAST:event_jButtonCancelActionPerformed
310:
311: private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed
312:
313: if (this .jRTextExpressionAreaDefaultExpression.getText().trim()
314: .length() == 0) {
315: javax.swing.JOptionPane.showMessageDialog(this ,
316: it.businesslogic.ireport.util.I18n.getString(
317: "gui.chart.SerieDialog.selectexpression",
318: "Please specify an expression"));
319: return;
320: }
321:
322: if (this .jTextFieldName.getText().trim().length() == 0) {
323: javax.swing.JOptionPane.showMessageDialog(this ,
324: it.businesslogic.ireport.util.I18n.getString(
325: "gui.chart.SerieDialog.selectname",
326: "Please specify an name for this serie"));
327: return;
328: }
329:
330: this .serieExpression = jRTextExpressionAreaDefaultExpression
331: .getText();
332: this .serieName = jTextFieldName.getText();
333: this .serieReset = "";
334: this .setSerieType("" + jComboBoxClassType.getSelectedItem());
335: if (jComboBox1.getSelectedIndex() > 0) {
336: this .serieReset += "" + jComboBox1.getSelectedItem();
337: }
338:
339: this .dialogResult = javax.swing.JOptionPane.OK_OPTION;
340: this .setVisible(false);
341: dispose();
342:
343: }//GEN-LAST:event_jButtonOKActionPerformed
344:
345: /**
346: * @param args the command line arguments
347: */
348: public static void main(String args[]) {
349: java.awt.EventQueue.invokeLater(new Runnable() {
350: public void run() {
351: new SerieDialog(null, true).setVisible(true);
352: }
353: });
354: }
355:
356: /**
357: * Getter for property jrf.
358: * @return Value of property jrf.
359: */
360: public JReportFrame getJrf() {
361:
362: return this .jrf;
363: }
364:
365: /**
366: * Setter for property jrf.
367: * @param jrf New value of property jrf.
368: */
369: public void setJrf(JReportFrame jrf) {
370:
371: this .jrf = jrf;
372: jRTextExpressionAreaDefaultExpression.getTokenMarker()
373: .setKeywordLookup(jrf.getReport().getKeywordLookup());
374:
375: jComboBox1.removeAllItems();
376: jComboBox1
377: .addItem(I18n.getString("serieDialog.none", "<None>"));
378: if (jrf == null) {
379: jComboBox1.updateUI();
380: return;
381: }
382:
383: java.util.Enumeration e = jrf.getReport().getGroups()
384: .elements();
385: while (e.hasMoreElements()) {
386: jComboBox1.addItem("" + e.nextElement());
387: }
388:
389: }
390:
391: /**
392: * Getter for property dialogResult.
393: * @return Value of property dialogResult.
394: */
395: public int getDialogResult() {
396:
397: return this .dialogResult;
398: }
399:
400: /**
401: * Setter for property dialogResult.
402: * @param dialogResult New value of property dialogResult.
403: */
404: public void setDialogResult(int dialogResult) {
405:
406: this .dialogResult = dialogResult;
407: }
408:
409: public String getSerieName() {
410: return serieName;
411: }
412:
413: public void setSerieName(String serieName) {
414: this .serieName = serieName;
415: }
416:
417: public String getSerieReset() {
418: return serieReset;
419: }
420:
421: public void setSerieReset(String serieReset) {
422: this .serieReset = serieReset;
423: }
424:
425: public String getSerieType() {
426: return serieType;
427: }
428:
429: public void setSerieType(String serieType) {
430: this .serieType = serieType;
431: }
432:
433: public String getSerieExpression() {
434: return serieExpression;
435: }
436:
437: public void setSerieExpression(String serieExpression) {
438: this .serieExpression = serieExpression;
439: }
440:
441: // Variables declaration - do not modify//GEN-BEGIN:variables
442: private javax.swing.JButton jButtonCancel;
443: private javax.swing.JButton jButtonOK;
444: private javax.swing.JComboBox jComboBox1;
445: private javax.swing.JComboBox jComboBoxClassType;
446: private javax.swing.JLabel jLabelName;
447: private javax.swing.JLabel jLabelName1;
448: private javax.swing.JLabel jLabelName2;
449: private javax.swing.JLabel jLabelTitle;
450: private javax.swing.JPanel jPanel1;
451: private javax.swing.JPanel jPanel2;
452: private it.businesslogic.ireport.gui.JRTextExpressionArea jRTextExpressionAreaDefaultExpression;
453: private javax.swing.JTextField jTextFieldName;
454:
455: // End of variables declaration//GEN-END:variables
456:
457: public void applyI18n() {
458: // Start autogenerated code ----------------------
459: jButtonCancel.setText(I18n.getString(
460: "serieDialog.buttonCancel", "Cancel"));
461: jButtonOK.setText(I18n.getString("serieDialog.buttonOK", "OK"));
462: jLabelName.setText(I18n.getString("serieDialog.labelName",
463: "Serie name"));
464: jLabelName1.setText(I18n.getString("serieDialog.labelName1",
465: "Reset when"));
466: jLabelName2.setText(I18n.getString("serieDialog.labelName2",
467: "Exp Class"));
468: jLabelTitle.setText(I18n.getString("serieDialog.labelTitle",
469: "Serie expression (the single object of this serie)"));
470: // End autogenerated code ----------------------
471:
472: jButtonCancel.setMnemonic(I18n.getString(
473: "serieDialog.buttonCancelMnemonic", "c").charAt(0));
474: jButtonOK.setMnemonic(I18n.getString(
475: "serieDialog.buttonOKMnemonic", "o").charAt(0));
476: }
477: }
|