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: * TimeSeriesDatasetPanel.java
028: *
029: * Created on 15 agosto 2005, 17.55
030: *
031: */
032:
033: package it.businesslogic.ireport.chart;
034:
035: import it.businesslogic.ireport.SubDataset;
036: import it.businesslogic.ireport.gui.sheet.Tag;
037: import java.awt.event.ActionEvent;
038: import java.util.*;
039: import it.businesslogic.ireport.util.Misc;
040: import it.businesslogic.ireport.util.I18n;
041:
042: /**
043: *
044: * @author Administrator
045: */
046: public class TimeSeriesDatasetPanel extends javax.swing.JPanel
047: implements ChartDatasetPanel {
048:
049: private TimeSeriesDataset timeSeriesDataset = null;
050: private boolean init = false;
051: private SubDataset subDataset = null;
052:
053: /** Creates new form PieDatasetPanel */
054: public TimeSeriesDatasetPanel() {
055: initComponents();
056: applyI18n();
057:
058: // Year | Quarter | Month | Week | Day | Hour | Minute | Second | Milisecond
059: this .jComboBoxPeriod.addItem(new Tag("Year",
060: it.businesslogic.ireport.util.I18n.getString(
061: "charts.timePeriod.Year", "Year")));
062: this .jComboBoxPeriod.addItem(new Tag("Quarter",
063: it.businesslogic.ireport.util.I18n.getString(
064: "charts.timePeriod.Quarter", "Quarter")));
065: this .jComboBoxPeriod.addItem(new Tag("Month",
066: it.businesslogic.ireport.util.I18n.getString(
067: "charts.timePeriod.Month", "Month")));
068: this .jComboBoxPeriod.addItem(new Tag("Week",
069: it.businesslogic.ireport.util.I18n.getString(
070: "charts.timePeriod.Week", "Week")));
071: this .jComboBoxPeriod.addItem(new Tag("Day",
072: it.businesslogic.ireport.util.I18n.getString(
073: "charts.timePeriod.Day", "Day")));
074: this .jComboBoxPeriod.addItem(new Tag("Hour",
075: it.businesslogic.ireport.util.I18n.getString(
076: "charts.timePeriod.Hour", "Hour")));
077: this .jComboBoxPeriod.addItem(new Tag("Minute",
078: it.businesslogic.ireport.util.I18n.getString(
079: "charts.timePeriod.Minute", "Minute")));
080: this .jComboBoxPeriod.addItem(new Tag("Second",
081: it.businesslogic.ireport.util.I18n.getString(
082: "charts.timePeriod.Second", "Second")));
083: this .jComboBoxPeriod.addItem(new Tag("Milisecond",
084: it.businesslogic.ireport.util.I18n.getString(
085: "charts.timePeriod.Milisecond", "Milisecond")));
086:
087: jList1.setModel(new javax.swing.DefaultListModel());
088: }
089:
090: public void setTimeSeriesDataset(TimeSeriesDataset timeSeriesDataset) {
091:
092: init = true;
093: this .timeSeriesDataset = timeSeriesDataset;
094:
095: jButtonModify.setEnabled(false);
096: jButtonModify.setEnabled(false);
097: javax.swing.DefaultListModel lm = (javax.swing.DefaultListModel) jList1
098: .getModel();
099:
100: lm.removeAllElements();
101:
102: Vector v = timeSeriesDataset.getTimeSeries();
103:
104: for (int i = 0; i < v.size(); ++i) {
105: lm.addElement(v.elementAt(i));
106: }
107:
108: Misc.setComboboxSelectedTagValue(jComboBoxPeriod,
109: timeSeriesDataset.getTimePeriod());
110: init = false;
111: }
112:
113: public TimeSeriesDataset getTimeSeriesDataset() {
114: return timeSeriesDataset;
115: }
116:
117: /** This method is called from within the constructor to
118: * initialize the form.
119: * WARNING: Do NOT modify this code. The content of this method is
120: * always regenerated by the Form Editor.
121: */
122: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
123: private void initComponents() {
124: java.awt.GridBagConstraints gridBagConstraints;
125:
126: jPopupMenuSeries = new javax.swing.JPopupMenu();
127: jMenuItemCopy = new javax.swing.JMenuItem();
128: jMenuItemPaste = new javax.swing.JMenuItem();
129: jPanelPeriod = new javax.swing.JPanel();
130: jLabelPeriod = new javax.swing.JLabel();
131: jComboBoxPeriod = new javax.swing.JComboBox();
132: jLabel1 = new javax.swing.JLabel();
133: jScrollPane1 = new javax.swing.JScrollPane();
134: jList1 = new javax.swing.JList();
135: jPanel1 = new javax.swing.JPanel();
136: jButtonAdd = new javax.swing.JButton();
137: jButtonModify = new javax.swing.JButton();
138: jButtonRemove = new javax.swing.JButton();
139: jPanel2 = new javax.swing.JPanel();
140:
141: jMenuItemCopy.setText("Copy series");
142: jMenuItemCopy
143: .addActionListener(new java.awt.event.ActionListener() {
144: public void actionPerformed(
145: java.awt.event.ActionEvent evt) {
146: jMenuItemCopyActionPerformed(evt);
147: }
148: });
149:
150: jPopupMenuSeries.add(jMenuItemCopy);
151:
152: jMenuItemPaste.setText("Paste series");
153: jMenuItemPaste
154: .addActionListener(new java.awt.event.ActionListener() {
155: public void actionPerformed(
156: java.awt.event.ActionEvent evt) {
157: jMenuItemPasteActionPerformed(evt);
158: }
159: });
160:
161: jPopupMenuSeries.add(jMenuItemPaste);
162:
163: setLayout(new java.awt.GridBagLayout());
164:
165: addComponentListener(new java.awt.event.ComponentAdapter() {
166: public void componentShown(java.awt.event.ComponentEvent evt) {
167: formComponentShown(evt);
168: }
169: });
170:
171: jPanelPeriod.setLayout(new java.awt.GridBagLayout());
172:
173: jLabelPeriod.setText("Time period");
174: gridBagConstraints = new java.awt.GridBagConstraints();
175: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
176: jPanelPeriod.add(jLabelPeriod, gridBagConstraints);
177:
178: jComboBoxPeriod
179: .addActionListener(new java.awt.event.ActionListener() {
180: public void actionPerformed(
181: java.awt.event.ActionEvent evt) {
182: jComboBoxPeriodActionPerformed(evt);
183: }
184: });
185:
186: gridBagConstraints = new java.awt.GridBagConstraints();
187: gridBagConstraints.gridx = 1;
188: gridBagConstraints.gridy = 0;
189: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
190: gridBagConstraints.weightx = 1.0;
191: gridBagConstraints.insets = new java.awt.Insets(4, 0, 4, 4);
192: jPanelPeriod.add(jComboBoxPeriod, gridBagConstraints);
193:
194: gridBagConstraints = new java.awt.GridBagConstraints();
195: gridBagConstraints.gridwidth = 2;
196: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
197: gridBagConstraints.weightx = 1.0;
198: add(jPanelPeriod, gridBagConstraints);
199:
200: jLabel1.setText("Time series");
201: gridBagConstraints = new java.awt.GridBagConstraints();
202: gridBagConstraints.gridy = 1;
203: gridBagConstraints.gridwidth = 2;
204: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
205: gridBagConstraints.weightx = 1.0;
206: gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 4);
207: add(jLabel1, gridBagConstraints);
208:
209: jList1
210: .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
211: public void valueChanged(
212: javax.swing.event.ListSelectionEvent evt) {
213: jList1ValueChanged(evt);
214: }
215: });
216: jList1.addMouseListener(new java.awt.event.MouseAdapter() {
217: public void mouseClicked(java.awt.event.MouseEvent evt) {
218: jList1MouseClicked(evt);
219: }
220: });
221:
222: jScrollPane1.setViewportView(jList1);
223:
224: gridBagConstraints = new java.awt.GridBagConstraints();
225: gridBagConstraints.gridy = 2;
226: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
227: gridBagConstraints.weightx = 1.0;
228: gridBagConstraints.weighty = 1.0;
229: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
230: add(jScrollPane1, gridBagConstraints);
231:
232: jPanel1.setLayout(new java.awt.GridBagLayout());
233:
234: jPanel1.setMinimumSize(new java.awt.Dimension(100, 0));
235: jPanel1.setPreferredSize(new java.awt.Dimension(100, 0));
236: jButtonAdd.setText("Add");
237: jButtonAdd
238: .addActionListener(new java.awt.event.ActionListener() {
239: public void actionPerformed(
240: java.awt.event.ActionEvent evt) {
241: jButtonAddActionPerformed(evt);
242: }
243: });
244:
245: gridBagConstraints = new java.awt.GridBagConstraints();
246: gridBagConstraints.gridy = 0;
247: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
248: gridBagConstraints.weightx = 1.0;
249: gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 4);
250: jPanel1.add(jButtonAdd, gridBagConstraints);
251:
252: jButtonModify.setText("Modify");
253: jButtonModify
254: .addActionListener(new java.awt.event.ActionListener() {
255: public void actionPerformed(
256: java.awt.event.ActionEvent evt) {
257: jButtonModifyActionPerformed(evt);
258: }
259: });
260:
261: gridBagConstraints = new java.awt.GridBagConstraints();
262: gridBagConstraints.gridy = 1;
263: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
264: gridBagConstraints.weightx = 1.0;
265: gridBagConstraints.insets = new java.awt.Insets(2, 0, 0, 4);
266: jPanel1.add(jButtonModify, gridBagConstraints);
267:
268: jButtonRemove.setText("Remove");
269: jButtonRemove
270: .addActionListener(new java.awt.event.ActionListener() {
271: public void actionPerformed(
272: java.awt.event.ActionEvent evt) {
273: jButtonRemoveActionPerformed(evt);
274: }
275: });
276:
277: gridBagConstraints = new java.awt.GridBagConstraints();
278: gridBagConstraints.gridy = 2;
279: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
280: gridBagConstraints.weightx = 1.0;
281: gridBagConstraints.insets = new java.awt.Insets(2, 0, 0, 4);
282: jPanel1.add(jButtonRemove, gridBagConstraints);
283:
284: gridBagConstraints = new java.awt.GridBagConstraints();
285: gridBagConstraints.gridy = 99;
286: gridBagConstraints.weighty = 1.0;
287: jPanel1.add(jPanel2, gridBagConstraints);
288:
289: gridBagConstraints = new java.awt.GridBagConstraints();
290: gridBagConstraints.gridy = 2;
291: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
292: add(jPanel1, gridBagConstraints);
293:
294: }// </editor-fold>//GEN-END:initComponents
295:
296: private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
297: openExtraWindows();
298: }//GEN-LAST:event_formComponentShown
299:
300: private void jList1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jList1MouseClicked
301: if (evt.getClickCount() == 1 && evt.getButton() == evt.BUTTON3) {
302: jMenuItemCopy.setEnabled(jList1.getSelectedIndex() >= 0);
303: jMenuItemPaste
304: .setEnabled(it.businesslogic.ireport.gui.MainFrame
305: .getMainInstance()
306: .getChartSeriesClipBoard() != null
307: && it.businesslogic.ireport.gui.MainFrame
308: .getMainInstance()
309: .getChartSeriesClipBoard().size() > 0);
310:
311: jPopupMenuSeries.show(jList1, evt.getPoint().x, evt
312: .getPoint().y);
313: } else if (evt.getClickCount() == 2
314: && evt.getButton() == evt.BUTTON1) {
315: jButtonModifyActionPerformed(null);
316: }
317: }//GEN-LAST:event_jList1MouseClicked
318:
319: private void jMenuItemPasteActionPerformed(
320: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemPasteActionPerformed
321:
322: Vector v = it.businesslogic.ireport.gui.MainFrame
323: .getMainInstance().getChartSeriesClipBoard();
324:
325: if (v != null && v.size() > 0) {
326: for (int i = 0; i < v.size(); ++i) {
327: if (v.elementAt(i) instanceof TimeSeries) {
328: TimeSeries cs = (TimeSeries) v.elementAt(i);
329: cs = cs.cloneMe();
330: getTimeSeriesDataset().getTimeSeries().addElement(
331: cs);
332: ((javax.swing.DefaultListModel) jList1.getModel())
333: .addElement(cs);
334: }
335: }
336: jList1.updateUI();
337: }
338: }//GEN-LAST:event_jMenuItemPasteActionPerformed
339:
340: private void jMenuItemCopyActionPerformed(
341: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemCopyActionPerformed
342: Object[] values = jList1.getSelectedValues();
343: Vector copy_c = new Vector();
344: for (int i = 0; i < values.length; ++i)
345: copy_c.add(((TimeSeries) values[i]).cloneMe());
346: it.businesslogic.ireport.gui.MainFrame.getMainInstance()
347: .setChartSeriesClipBoard(copy_c);
348: }//GEN-LAST:event_jMenuItemCopyActionPerformed
349:
350: private void jComboBoxPeriodActionPerformed(
351: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxPeriodActionPerformed
352:
353: if (init || timeSeriesDataset == null)
354: return;
355: timeSeriesDataset.setTimePeriod(((Tag) jComboBoxPeriod
356: .getSelectedItem()).getValue()
357: + "");
358:
359: }//GEN-LAST:event_jComboBoxPeriodActionPerformed
360:
361: private void jButtonModifyActionPerformed(
362: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonModifyActionPerformed
363:
364: if (jList1.getSelectedIndex() >= 0) {
365: TimeSeries cs = (TimeSeries) jList1.getSelectedValue();
366: TimeSeriesDialog csd = new TimeSeriesDialog(
367: it.businesslogic.ireport.gui.MainFrame
368: .getMainInstance(), true);
369:
370: csd.setSeriesExpression(cs.getSeriesExpression());
371: csd.setTimePeriodExpression(cs.getTimePeriodExpression());
372: csd.setValueExpression(cs.getValueExpression());
373: csd.setLabelExpression(cs.getLabelExpression());
374: csd.setSectionItemHyperlink(cs.getSectionItemHyperlink());
375:
376: csd.setSubDataset(this .getSubDataset());
377:
378: if (newInfo != null) {
379: csd.setFocusedExpression(newInfo);
380: }
381:
382: csd.setVisible(true);
383:
384: if (csd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) {
385: cs.setSeriesExpression(csd.getSeriesExpression());
386: cs.setTimePeriodExpression(csd
387: .getTimePeriodExpression());
388: cs.setValueExpression(csd.getValueExpression());
389: cs.setLabelExpression(csd.getLabelExpression());
390: cs.setSectionItemHyperlink(csd
391: .getSectionItemHyperlink());
392:
393: jList1.updateUI();
394: }
395:
396: }
397: }//GEN-LAST:event_jButtonModifyActionPerformed
398:
399: private void jButtonAddActionPerformed(
400: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAddActionPerformed
401:
402: TimeSeriesDialog csd = new TimeSeriesDialog(
403: it.businesslogic.ireport.gui.MainFrame
404: .getMainInstance(), true);
405: csd.setSubDataset(this .getSubDataset());
406: csd.setVisible(true);
407: if (csd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) {
408: TimeSeries cs = new TimeSeries();
409: cs.setSeriesExpression(csd.getSeriesExpression());
410: cs.setTimePeriodExpression(csd.getTimePeriodExpression());
411: cs.setValueExpression(csd.getValueExpression());
412: cs.setLabelExpression(csd.getLabelExpression());
413: cs.setSectionItemHyperlink(csd.getSectionItemHyperlink());
414:
415: getTimeSeriesDataset().getTimeSeries().addElement(cs);
416: ((javax.swing.DefaultListModel) jList1.getModel())
417: .addElement(cs);
418: }
419:
420: }//GEN-LAST:event_jButtonAddActionPerformed
421:
422: private void jButtonRemoveActionPerformed(
423: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRemoveActionPerformed
424:
425: while (jList1.getSelectedIndex() >= 0) {
426: getTimeSeriesDataset().getTimeSeries().remove(
427: jList1.getSelectedValue());
428: ((javax.swing.DefaultListModel) jList1.getModel())
429: .removeElementAt(jList1.getSelectedIndex());
430: }
431:
432: }//GEN-LAST:event_jButtonRemoveActionPerformed
433:
434: private void jList1ValueChanged(
435: javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jList1ValueChanged
436:
437: if (jList1.getSelectedIndex() >= 0) {
438: jButtonModify.setEnabled(true);
439: jButtonModify.setEnabled(true);
440: } else {
441: jButtonModify.setEnabled(false);
442: jButtonModify.setEnabled(false);
443: }
444: }//GEN-LAST:event_jList1ValueChanged
445:
446: // Variables declaration - do not modify//GEN-BEGIN:variables
447: private javax.swing.JButton jButtonAdd;
448: private javax.swing.JButton jButtonModify;
449: private javax.swing.JButton jButtonRemove;
450: private javax.swing.JComboBox jComboBoxPeriod;
451: private javax.swing.JLabel jLabel1;
452: private javax.swing.JLabel jLabelPeriod;
453: private javax.swing.JList jList1;
454: private javax.swing.JMenuItem jMenuItemCopy;
455: private javax.swing.JMenuItem jMenuItemPaste;
456: private javax.swing.JPanel jPanel1;
457: private javax.swing.JPanel jPanel2;
458: private javax.swing.JPanel jPanelPeriod;
459: private javax.swing.JPopupMenu jPopupMenuSeries;
460: private javax.swing.JScrollPane jScrollPane1;
461:
462: // End of variables declaration//GEN-END:variables
463:
464: public void applyI18n() {
465: // Start autogenerated code ----------------------
466: // End autogenerated code ----------------------
467: // Start autogenerated code ----------------------
468: jLabel1.setText(I18n.getString("timeSeriesDatasetPanel.label1",
469: "Time series"));
470: // End autogenerated code ----------------------
471: jButtonAdd.setText(it.businesslogic.ireport.util.I18n
472: .getString("charts.newseries", "Add series"));
473: jButtonModify.setText(it.businesslogic.ireport.util.I18n
474: .getString("charts.modifyseries", "Modify series"));
475: jButtonRemove.setText(it.businesslogic.ireport.util.I18n
476: .getString("charts.removeseries", "Remove series"));
477: jLabelPeriod.setText(it.businesslogic.ireport.util.I18n
478: .getString("charts.timePeriod", "Time period"));
479:
480: jMenuItemCopy.setText(it.businesslogic.ireport.util.I18n
481: .getString("charts.copyseries", "Copy series"));
482: jMenuItemPaste.setText(it.businesslogic.ireport.util.I18n
483: .getString("charts.pasteseries", "Paste series"));
484:
485: this .updateUI();
486:
487: }
488:
489: public SubDataset getSubDataset() {
490: return subDataset;
491: }
492:
493: public void setSubDataset(SubDataset subDataset) {
494: this .subDataset = subDataset;
495: }
496:
497: public static final int COMPONENT_NONE = 0;
498: public static final int COMPONENT_TIME_SERIES_LIST = 1;
499:
500: /**
501: * This variable is checked by openExtraWindows() called when the component is shown.
502: * If the value is != 0, the modify button will be action-performed.
503: */
504: public Object[] newInfo = null;
505:
506: /**
507: * This method set the focus on a specific component.
508: *
509: * For this kind of datasource otherInfo must be:
510: * [0] = Fixed to COMPONENT_PERIOD_SERIES_LIST (used for future extensions)
511: * [1] = Integer, the category series to edit
512: * [2] = The expression id in the category window to focus on
513: * [3] = The expression in the hyperlink...
514: * [4] = The hyperlink parameter
515: * [5] = The expression of the hyperlink parameter
516: */
517: public void setFocusedExpression(Object[] expressionInfo) {
518: if (expressionInfo == null)
519: return;
520: int expID = ((Integer) expressionInfo[0]).intValue();
521: switch (expID) {
522: case COMPONENT_TIME_SERIES_LIST:
523: int index = ((Integer) expressionInfo[1]).intValue();
524:
525: if (index >= 0 && jList1.getModel().getSize() > index) {
526: jList1.setSelectedIndex(index);
527: newInfo = new Object[expressionInfo.length - 2];
528: for (int i = 2; i < expressionInfo.length; ++i)
529: newInfo[i - 2] = expressionInfo[i];
530: break;
531: }
532: }
533: }
534:
535: /**
536: * This method checks for the variable subExpID. It is called when the component is shown.
537: * If the value is >= 0, the modify button will be action-performed
538: */
539: private void openExtraWindows() {
540: if (newInfo != null) {
541: jButtonModifyActionPerformed(new ActionEvent(jButtonModify,
542: 0, ""));
543: }
544: newInfo = null;
545: }
546:
547: public void containerWindowOpened() {
548: openExtraWindows();
549: }
550:
551: }
|