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