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: * TimeSeriesDialog.java
028: *
029: * Created on 17 agosto 2005, 11.19
030: *
031: */
032:
033: package it.businesslogic.ireport.chart;
034:
035: import it.businesslogic.ireport.SubDataset;
036: import it.businesslogic.ireport.util.I18n;
037: import it.businesslogic.ireport.util.Misc;
038:
039: /**
040: *
041: * @author Administrator
042: */
043: public class TimeSeriesDialog extends javax.swing.JDialog {
044:
045: private String seriesExpression = "";
046: private String timePeriodExpression = "";
047: private String valueExpression = "";
048: private String labelExpression = "";
049:
050: private int dialogResult = javax.swing.JOptionPane.CANCEL_OPTION;
051:
052: /** Creates new form CategorySeriesDialog */
053: public TimeSeriesDialog(java.awt.Frame parent, boolean modal) {
054: super (parent, modal);
055: initComponents();
056: applyI18n();
057:
058: this .setSize(500, 500);
059: it.businesslogic.ireport.util.Misc.centerFrame(this );
060:
061: javax.swing.KeyStroke escape = javax.swing.KeyStroke
062: .getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0,
063: false);
064: javax.swing.Action escapeAction = new javax.swing.AbstractAction() {
065: public void actionPerformed(java.awt.event.ActionEvent e) {
066: jButtonCancelActionPerformed(e);
067: }
068: };
069:
070: getRootPane().getInputMap(
071: javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(
072: escape, "ESCAPE");
073: getRootPane().getActionMap().put("ESCAPE", escapeAction);
074:
075: //to make the default button ...
076: this .getRootPane().setDefaultButton(this .jButtonOK);
077: }
078:
079: /**
080: * this method is used to pass the correct subdataset to the expression editor
081: */
082: public void setSubDataset(SubDataset sds) {
083: jRTextExpressionLabel.setSubDataset(sds);
084: jRTextExpressionSeries.setSubDataset(sds);
085: jRTextExpressionTimePeriod.setSubDataset(sds);
086: jRTextExpressionValue.setSubDataset(sds);
087: sectionItemHyperlinkPanel1.setSubDataset(sds);
088: }
089:
090: /** This method is called from within the constructor to
091: * initialize the form.
092: * WARNING: Do NOT modify this code. The content of this method is
093: * always regenerated by the Form Editor.
094: */
095: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
096: private void initComponents() {
097: java.awt.GridBagConstraints gridBagConstraints;
098:
099: jTabbedPane1 = new javax.swing.JTabbedPane();
100: jPanel1 = new javax.swing.JPanel();
101: jLabelSeriesExpression = new javax.swing.JLabel();
102: jLabelTimePeriodExpression = new javax.swing.JLabel();
103: jLabelValueExpression = new javax.swing.JLabel();
104: jLabelLabelExpression = new javax.swing.JLabel();
105: jRTextExpressionSeries = new it.businesslogic.ireport.gui.JRTextExpressionArea();
106: jRTextExpressionTimePeriod = new it.businesslogic.ireport.gui.JRTextExpressionArea();
107: jRTextExpressionValue = new it.businesslogic.ireport.gui.JRTextExpressionArea();
108: jRTextExpressionLabel = new it.businesslogic.ireport.gui.JRTextExpressionArea();
109: sectionItemHyperlinkPanel1 = new it.businesslogic.ireport.chart.gui.SectionItemHyperlinkPanel();
110: jPanel6 = new javax.swing.JPanel();
111: jPanel7 = new javax.swing.JPanel();
112: jButtonOK = new javax.swing.JButton();
113: jButtonCancel = new javax.swing.JButton();
114:
115: getContentPane().setLayout(new java.awt.GridBagLayout());
116:
117: setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
118: setTitle("Time series");
119: addWindowListener(new java.awt.event.WindowAdapter() {
120: public void windowOpened(java.awt.event.WindowEvent evt) {
121: formWindowOpened(evt);
122: }
123: });
124:
125: jPanel1.setLayout(new java.awt.GridBagLayout());
126:
127: jLabelSeriesExpression.setText("Series expression (required)");
128: gridBagConstraints = new java.awt.GridBagConstraints();
129: gridBagConstraints.gridx = 0;
130: gridBagConstraints.gridy = 0;
131: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
132: gridBagConstraints.weightx = 1.0;
133: jPanel1.add(jLabelSeriesExpression, gridBagConstraints);
134:
135: jLabelTimePeriodExpression.setText("Time period expression");
136: gridBagConstraints = new java.awt.GridBagConstraints();
137: gridBagConstraints.gridx = 0;
138: gridBagConstraints.gridy = 2;
139: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
140: gridBagConstraints.weightx = 1.0;
141: gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 0);
142: jPanel1.add(jLabelTimePeriodExpression, gridBagConstraints);
143:
144: jLabelValueExpression.setText("Value expression (required)");
145: gridBagConstraints = new java.awt.GridBagConstraints();
146: gridBagConstraints.gridx = 0;
147: gridBagConstraints.gridy = 10;
148: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
149: gridBagConstraints.weightx = 1.0;
150: gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 0);
151: jPanel1.add(jLabelValueExpression, gridBagConstraints);
152:
153: jLabelLabelExpression.setText("Label expression");
154: gridBagConstraints = new java.awt.GridBagConstraints();
155: gridBagConstraints.gridx = 0;
156: gridBagConstraints.gridy = 14;
157: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
158: gridBagConstraints.weightx = 1.0;
159: gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 0);
160: jPanel1.add(jLabelLabelExpression, gridBagConstraints);
161:
162: jRTextExpressionSeries.setBorder(javax.swing.BorderFactory
163: .createEtchedBorder());
164: jRTextExpressionSeries.setElectricScroll(0);
165: jRTextExpressionSeries.setMinimumSize(new java.awt.Dimension(
166: 10, 10));
167: jRTextExpressionSeries.setPreferredSize(new java.awt.Dimension(
168: 10, 10));
169: gridBagConstraints = new java.awt.GridBagConstraints();
170: gridBagConstraints.gridx = 0;
171: gridBagConstraints.gridy = 1;
172: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
173: gridBagConstraints.weightx = 1.0;
174: gridBagConstraints.weighty = 1.0;
175: jPanel1.add(jRTextExpressionSeries, gridBagConstraints);
176:
177: jRTextExpressionTimePeriod.setBorder(javax.swing.BorderFactory
178: .createEtchedBorder());
179: jRTextExpressionTimePeriod.setElectricScroll(0);
180: jRTextExpressionTimePeriod
181: .setMinimumSize(new java.awt.Dimension(10, 10));
182: jRTextExpressionTimePeriod
183: .setPreferredSize(new java.awt.Dimension(10, 10));
184: gridBagConstraints = new java.awt.GridBagConstraints();
185: gridBagConstraints.gridx = 0;
186: gridBagConstraints.gridy = 3;
187: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
188: gridBagConstraints.weightx = 1.0;
189: gridBagConstraints.weighty = 1.0;
190: jPanel1.add(jRTextExpressionTimePeriod, gridBagConstraints);
191:
192: jRTextExpressionValue.setBorder(javax.swing.BorderFactory
193: .createEtchedBorder());
194: jRTextExpressionValue.setElectricScroll(0);
195: jRTextExpressionValue.setMinimumSize(new java.awt.Dimension(10,
196: 10));
197: jRTextExpressionValue.setPreferredSize(new java.awt.Dimension(
198: 10, 10));
199: gridBagConstraints = new java.awt.GridBagConstraints();
200: gridBagConstraints.gridx = 0;
201: gridBagConstraints.gridy = 11;
202: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
203: gridBagConstraints.weightx = 1.0;
204: gridBagConstraints.weighty = 1.0;
205: jPanel1.add(jRTextExpressionValue, gridBagConstraints);
206:
207: jRTextExpressionLabel.setBorder(javax.swing.BorderFactory
208: .createEtchedBorder());
209: jRTextExpressionLabel.setElectricScroll(0);
210: jRTextExpressionLabel.setMinimumSize(new java.awt.Dimension(10,
211: 10));
212: jRTextExpressionLabel.setPreferredSize(new java.awt.Dimension(
213: 10, 10));
214: gridBagConstraints = new java.awt.GridBagConstraints();
215: gridBagConstraints.gridx = 0;
216: gridBagConstraints.gridy = 15;
217: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
218: gridBagConstraints.weightx = 1.0;
219: gridBagConstraints.weighty = 1.0;
220: jPanel1.add(jRTextExpressionLabel, gridBagConstraints);
221:
222: jTabbedPane1.addTab("Data", jPanel1);
223:
224: jTabbedPane1.addTab("Item hyperlink",
225: sectionItemHyperlinkPanel1);
226:
227: gridBagConstraints = new java.awt.GridBagConstraints();
228: gridBagConstraints.gridwidth = 2;
229: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
230: gridBagConstraints.weightx = 1.0;
231: gridBagConstraints.weighty = 1.0;
232: getContentPane().add(jTabbedPane1, gridBagConstraints);
233:
234: jPanel6.setLayout(new java.awt.GridBagLayout());
235:
236: gridBagConstraints = new java.awt.GridBagConstraints();
237: gridBagConstraints.gridheight = 2;
238: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
239: gridBagConstraints.weightx = 1.0;
240: gridBagConstraints.weighty = 1.0;
241: jPanel6.add(jPanel7, gridBagConstraints);
242:
243: jButtonOK.setMnemonic('o');
244: jButtonOK.setText("OK");
245: jButtonOK
246: .addActionListener(new java.awt.event.ActionListener() {
247: public void actionPerformed(
248: java.awt.event.ActionEvent evt) {
249: jButtonOKActionPerformed(evt);
250: }
251: });
252:
253: gridBagConstraints = new java.awt.GridBagConstraints();
254: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
255: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
256: jPanel6.add(jButtonOK, gridBagConstraints);
257:
258: jButtonCancel.setMnemonic('c');
259: jButtonCancel.setText("Cancel");
260: jButtonCancel
261: .addActionListener(new java.awt.event.ActionListener() {
262: public void actionPerformed(
263: java.awt.event.ActionEvent evt) {
264: jButtonCancelActionPerformed(evt);
265: }
266: });
267:
268: gridBagConstraints = new java.awt.GridBagConstraints();
269: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
270: gridBagConstraints.insets = new java.awt.Insets(4, 0, 4, 0);
271: jPanel6.add(jButtonCancel, gridBagConstraints);
272:
273: gridBagConstraints = new java.awt.GridBagConstraints();
274: gridBagConstraints.gridx = 0;
275: gridBagConstraints.gridy = 18;
276: gridBagConstraints.gridwidth = 2;
277: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
278: gridBagConstraints.weightx = 1.0;
279: getContentPane().add(jPanel6, gridBagConstraints);
280:
281: pack();
282: }// </editor-fold>//GEN-END:initComponents
283:
284: private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
285: sectionItemHyperlinkPanel1.openExtraWindows();
286: }//GEN-LAST:event_formWindowOpened
287:
288: private void jButtonCancelActionPerformed(
289: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
290: this .setVisible(false);
291: this .dispose();
292: }//GEN-LAST:event_jButtonCancelActionPerformed
293:
294: private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed
295:
296: seriesExpression = jRTextExpressionSeries.getText();
297: setTimePeriodExpression(jRTextExpressionTimePeriod.getText());
298: valueExpression = jRTextExpressionValue.getText();
299: labelExpression = jRTextExpressionLabel.getText();
300:
301: java.text.MessageFormat formatter = new java.text.MessageFormat(
302: it.businesslogic.ireport.util.I18n.getString(
303: "gui.notvalidexp", "{0} cannot be blank!"));
304:
305: if (seriesExpression.trim().length() == 0) {
306:
307: javax.swing.JOptionPane
308: .showMessageDialog(
309: this ,
310: formatter
311: .format(new Object[] { it.businesslogic.ireport.util.I18n
312: .getString(
313: "charts.seriesExpression",
314: "Series expression") }),
315: I18n.getString(
316: "message.title.invalidExpression",
317: "Invalid expression"),
318: javax.swing.JOptionPane.ERROR_MESSAGE);
319: return;
320: }
321:
322: if (getTimePeriodExpression().trim().length() == 0) {
323: javax.swing.JOptionPane
324: .showMessageDialog(
325: this ,
326: formatter
327: .format(new Object[] { it.businesslogic.ireport.util.I18n
328: .getString(
329: "charts.timePeriodExpression",
330: "Time period expression") }),
331: I18n.getString(
332: "message.title.invalidExpression",
333: "Invalid expression"),
334: javax.swing.JOptionPane.ERROR_MESSAGE);
335: return;
336: }
337:
338: if (valueExpression.trim().length() == 0) {
339: javax.swing.JOptionPane
340: .showMessageDialog(
341: this ,
342: formatter
343: .format(new Object[] { it.businesslogic.ireport.util.I18n
344: .getString(
345: "charts.valueExpression",
346: "Value expression") }),
347: I18n.getString(
348: "message.title.invalidExpression",
349: "Invalid expression"),
350: javax.swing.JOptionPane.ERROR_MESSAGE);
351: return;
352: }
353:
354: this .setDialogResult(javax.swing.JOptionPane.OK_OPTION);
355: this .setVisible(false);
356: this .dispose();
357: }//GEN-LAST:event_jButtonOKActionPerformed
358:
359: public String getSeriesExpression() {
360: return seriesExpression;
361: }
362:
363: public void setSeriesExpression(String seriesExpression) {
364: this .seriesExpression = seriesExpression;
365: jRTextExpressionSeries.setText(seriesExpression);
366: }
367:
368: public String getValueExpression() {
369: return valueExpression;
370: }
371:
372: public void setValueExpression(String valueExpression) {
373: this .valueExpression = valueExpression;
374: jRTextExpressionValue.setText(valueExpression);
375: }
376:
377: public String getLabelExpression() {
378: return labelExpression;
379: }
380:
381: public void setLabelExpression(String labelExpression) {
382: this .labelExpression = labelExpression;
383: jRTextExpressionLabel.setText(labelExpression);
384: }
385:
386: public void setSectionItemHyperlink(
387: SectionItemHyperlink sectionItemHyperlink) {
388: sectionItemHyperlinkPanel1
389: .setSectionItemHyperlink(sectionItemHyperlink.cloneMe());
390: }
391:
392: public SectionItemHyperlink getSectionItemHyperlink() {
393: return sectionItemHyperlinkPanel1.getSectionItemHyperlink();
394: }
395:
396: public int getDialogResult() {
397: return dialogResult;
398: }
399:
400: public void setDialogResult(int dialogResult) {
401: this .dialogResult = dialogResult;
402: }
403:
404: // Variables declaration - do not modify//GEN-BEGIN:variables
405: private javax.swing.JButton jButtonCancel;
406: private javax.swing.JButton jButtonOK;
407: private javax.swing.JLabel jLabelLabelExpression;
408: private javax.swing.JLabel jLabelSeriesExpression;
409: private javax.swing.JLabel jLabelTimePeriodExpression;
410: private javax.swing.JLabel jLabelValueExpression;
411: private javax.swing.JPanel jPanel1;
412: private javax.swing.JPanel jPanel6;
413: private javax.swing.JPanel jPanel7;
414: private it.businesslogic.ireport.gui.JRTextExpressionArea jRTextExpressionLabel;
415: private it.businesslogic.ireport.gui.JRTextExpressionArea jRTextExpressionSeries;
416: private it.businesslogic.ireport.gui.JRTextExpressionArea jRTextExpressionTimePeriod;
417: private it.businesslogic.ireport.gui.JRTextExpressionArea jRTextExpressionValue;
418: private javax.swing.JTabbedPane jTabbedPane1;
419: private it.businesslogic.ireport.chart.gui.SectionItemHyperlinkPanel sectionItemHyperlinkPanel1;
420:
421: // End of variables declaration//GEN-END:variables
422:
423: public void applyI18n() {
424: // Start autogenerated code ----------------------
425: // End autogenerated code ----------------------
426: jButtonOK.setText(it.businesslogic.ireport.util.I18n.getString(
427: "ok", "Ok"));
428: jButtonCancel.setText(it.businesslogic.ireport.util.I18n
429: .getString("cancel", "Cancel"));
430:
431: jLabelTimePeriodExpression
432: .setText(it.businesslogic.ireport.util.I18n.getString(
433: "charts.timePeriodExpression",
434: "Time period expression"));
435: jLabelSeriesExpression
436: .setText(it.businesslogic.ireport.util.I18n.getString(
437: "charts.seriesExpression", "Series expression"));
438: jLabelValueExpression
439: .setText(it.businesslogic.ireport.util.I18n.getString(
440: "charts.valueExpression", "Value expression"));
441: jLabelLabelExpression
442: .setText(it.businesslogic.ireport.util.I18n.getString(
443: "charts.labelExpression", "Label expression"));
444:
445: jTabbedPane1.setTitleAt(0, I18n.getString(
446: "chartSeries.tab.Data", "Data"));
447: jTabbedPane1.setTitleAt(1, I18n.getString(
448: "chartSeries.tab.ItemHyperlink", "Item hyperlink"));
449:
450: this .setTitle(I18n.getString("timeSeriesDialog.title",
451: "Time series"));
452: jButtonCancel
453: .setMnemonic(I18n.getString(
454: "timeSeriesDialog.buttonCancelMnemonic", "c")
455: .charAt(0));
456: jButtonOK.setMnemonic(I18n.getString(
457: "timeSeriesDialog.buttonOKMnemonic", "o").charAt(0));
458:
459: this .getRootPane().updateUI();
460: }
461:
462: public String getTimePeriodExpression() {
463: return timePeriodExpression;
464: }
465:
466: public void setTimePeriodExpression(String timePeriodExpression) {
467: this .timePeriodExpression = timePeriodExpression;
468: jRTextExpressionTimePeriod.setText(timePeriodExpression);
469: }
470:
471: public static final int COMPONENT_NONE = 0;
472: public static final int COMPONENT_SERIES_EXPRESSION = 1;
473: public static final int COMPONENT_TIME_EXPRESSION = 2;
474: public static final int COMPONENT_VALUE_EXPRESSION = 3;
475: public static final int COMPONENT_LABEL_EXPRESSION = 4;
476: public static final int COMPONENT_HYPERLINK = 100;
477:
478: /**
479: * This method set the focus on a specific component.
480: *
481: * expressionInfo[0] can be something like:
482: * COMPONENT_SERIES_EXPRESSION, ...
483: *
484: * If it is COMPONENT_HYPERLINK, other parameters are expected...
485: * otherInfo is used here only for COMPONENT_HYPERLINK
486: * otherInfo[0] = expression ID
487: * otherInfo[1] = parameter #
488: * otherInfo[2] = parameter expression ID
489: */
490: public void setFocusedExpression(Object[] expressionInfo) {
491: if (expressionInfo == null)
492: return;
493: int expID = ((Integer) expressionInfo[0]).intValue();
494:
495: switch (expID) {
496: case COMPONENT_SERIES_EXPRESSION:
497: Misc.selectTextAndFocusArea(jRTextExpressionSeries);
498: break;
499: case COMPONENT_TIME_EXPRESSION:
500: Misc.selectTextAndFocusArea(jRTextExpressionTimePeriod);
501: break;
502: case COMPONENT_VALUE_EXPRESSION:
503: Misc.selectTextAndFocusArea(jRTextExpressionValue);
504: break;
505: case COMPONENT_LABEL_EXPRESSION:
506: Misc.selectTextAndFocusArea(jRTextExpressionLabel);
507: break;
508: case COMPONENT_HYPERLINK:
509: jTabbedPane1
510: .setSelectedComponent(sectionItemHyperlinkPanel1);
511: Object newInfo[] = new Object[expressionInfo.length - 1];
512: for (int i = 1; i < expressionInfo.length; ++i)
513: newInfo[i - 1] = expressionInfo[i];
514: sectionItemHyperlinkPanel1.setFocusedExpression(newInfo);
515: break;
516: }
517: }
518: }
|