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: * CategoryDatasetPanel.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 CategoryDatasetPanel extends javax.swing.JPanel implements
045: ChartDatasetPanel {
046:
047: private CategoryDataset categoryDataset = null;
048: private SubDataset subDataset = null;
049:
050: /** Creates new form PieDatasetPanel */
051: public CategoryDatasetPanel() {
052: initComponents();
053: applyI18n();
054: jList1.setModel(new javax.swing.DefaultListModel());
055: }
056:
057: public void setCategoryDataset(CategoryDataset categoryDataset) {
058: this .categoryDataset = categoryDataset;
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 = categoryDataset.getCategorySeries();
068:
069: for (int i = 0; i < v.size(); ++i) {
070: lm.addElement(v.elementAt(i));
071: }
072:
073: }
074:
075: public CategoryDataset getCategoryDataset() {
076: return categoryDataset;
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: jPopupMenuCategorySeries = 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: jPopupMenuCategorySeries.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: jPopupMenuCategorySeries.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: public void mousePressed(java.awt.event.MouseEvent evt) {
143: jList1MousePressed(evt);
144: }
145: });
146:
147: jScrollPane1.setViewportView(jList1);
148:
149: gridBagConstraints = new java.awt.GridBagConstraints();
150: gridBagConstraints.gridy = 1;
151: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
152: gridBagConstraints.weightx = 1.0;
153: gridBagConstraints.weighty = 1.0;
154: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
155: add(jScrollPane1, gridBagConstraints);
156:
157: jPanel1.setLayout(new java.awt.GridBagLayout());
158:
159: jPanel1.setMinimumSize(new java.awt.Dimension(100, 0));
160: jPanel1.setPreferredSize(new java.awt.Dimension(100, 0));
161: jButtonAdd.setText("Add");
162: jButtonAdd
163: .addActionListener(new java.awt.event.ActionListener() {
164: public void actionPerformed(
165: java.awt.event.ActionEvent evt) {
166: jButtonAddActionPerformed(evt);
167: }
168: });
169:
170: gridBagConstraints = new java.awt.GridBagConstraints();
171: gridBagConstraints.gridy = 0;
172: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
173: gridBagConstraints.weightx = 1.0;
174: gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 4);
175: jPanel1.add(jButtonAdd, gridBagConstraints);
176:
177: jButtonModify.setText("Modify");
178: jButtonModify
179: .addActionListener(new java.awt.event.ActionListener() {
180: public void actionPerformed(
181: java.awt.event.ActionEvent evt) {
182: jButtonModifyActionPerformed(evt);
183: }
184: });
185:
186: gridBagConstraints = new java.awt.GridBagConstraints();
187: gridBagConstraints.gridy = 1;
188: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
189: gridBagConstraints.weightx = 1.0;
190: gridBagConstraints.insets = new java.awt.Insets(2, 0, 0, 4);
191: jPanel1.add(jButtonModify, gridBagConstraints);
192:
193: jButtonRemove.setText("Remove");
194: jButtonRemove
195: .addActionListener(new java.awt.event.ActionListener() {
196: public void actionPerformed(
197: java.awt.event.ActionEvent evt) {
198: jButtonRemoveActionPerformed(evt);
199: }
200: });
201:
202: gridBagConstraints = new java.awt.GridBagConstraints();
203: gridBagConstraints.gridy = 2;
204: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
205: gridBagConstraints.weightx = 1.0;
206: gridBagConstraints.insets = new java.awt.Insets(2, 0, 0, 4);
207: jPanel1.add(jButtonRemove, gridBagConstraints);
208:
209: gridBagConstraints = new java.awt.GridBagConstraints();
210: gridBagConstraints.gridy = 99;
211: gridBagConstraints.weighty = 1.0;
212: jPanel1.add(jPanel2, gridBagConstraints);
213:
214: gridBagConstraints = new java.awt.GridBagConstraints();
215: gridBagConstraints.gridy = 1;
216: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
217: add(jPanel1, gridBagConstraints);
218:
219: jLabel1.setText("Category series");
220: gridBagConstraints = new java.awt.GridBagConstraints();
221: gridBagConstraints.gridwidth = 2;
222: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
223: gridBagConstraints.weightx = 1.0;
224: gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 4);
225: add(jLabel1, gridBagConstraints);
226:
227: }// </editor-fold>//GEN-END:initComponents
228:
229: private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
230:
231: }//GEN-LAST:event_formComponentShown
232:
233: private void jList1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jList1MouseClicked
234:
235: if (evt.getClickCount() == 1 && evt.getButton() == evt.BUTTON3) {
236: jMenuItemCopy.setEnabled(jList1.getSelectedIndex() >= 0);
237: jMenuItemPaste
238: .setEnabled(it.businesslogic.ireport.gui.MainFrame
239: .getMainInstance()
240: .getChartSeriesClipBoard() != null
241: && it.businesslogic.ireport.gui.MainFrame
242: .getMainInstance()
243: .getChartSeriesClipBoard().size() > 0);
244:
245: jPopupMenuCategorySeries.show(jList1, evt.getPoint().x, evt
246: .getPoint().y);
247: } else if (evt.getClickCount() == 2
248: && evt.getButton() == evt.BUTTON1) {
249: jButtonModifyActionPerformed(null);
250: }
251: }//GEN-LAST:event_jList1MouseClicked
252:
253: private void jList1MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jList1MousePressed
254:
255: }//GEN-LAST:event_jList1MousePressed
256:
257: private void jMenuItemCopyActionPerformed(
258: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemCopyActionPerformed
259:
260: Object[] values = jList1.getSelectedValues();
261: Vector copy_c = new Vector();
262: for (int i = 0; i < values.length; ++i)
263: copy_c.add(((CategorySeries) values[i]).cloneMe());
264: it.businesslogic.ireport.gui.MainFrame.getMainInstance()
265: .setChartSeriesClipBoard(copy_c);
266: }//GEN-LAST:event_jMenuItemCopyActionPerformed
267:
268: private void jMenuItemPasteActionPerformed(
269: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemPasteActionPerformed
270:
271: Vector v = it.businesslogic.ireport.gui.MainFrame
272: .getMainInstance().getChartSeriesClipBoard();
273:
274: if (v != null && v.size() > 0) {
275: for (int i = 0; i < v.size(); ++i) {
276: if (v.elementAt(i) instanceof CategorySeries) {
277: CategorySeries cs = (CategorySeries) v.elementAt(i);
278: cs = cs.cloneMe();
279: categoryDataset.getCategorySeries().addElement(cs);
280: ((javax.swing.DefaultListModel) jList1.getModel())
281: .addElement(cs);
282: }
283: }
284: }
285:
286: }//GEN-LAST:event_jMenuItemPasteActionPerformed
287:
288: private void jButtonModifyActionPerformed(
289: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonModifyActionPerformed
290:
291: if (jList1.getSelectedIndex() >= 0) {
292: CategorySeries cs = (CategorySeries) jList1
293: .getSelectedValue();
294: CategorySeriesDialog csd = new CategorySeriesDialog(
295: it.businesslogic.ireport.gui.MainFrame
296: .getMainInstance(), true);
297:
298: csd.setSeriesExpression(cs.getSeriesExpression());
299: csd.setCategoryExpression(cs.getCategoryExpression());
300: csd.setValueExpression(cs.getValueExpression());
301: csd.setLabelExpression(cs.getLabelExpression());
302: csd.setSectionItemHyperlink(cs.getSectionItemHyperlink());
303: csd.setSubDataset(this .getSubDataset());
304: if (newInfo != null) {
305: csd.setFocusedExpression(newInfo);
306: }
307: csd.setVisible(true);
308:
309: if (csd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) {
310: cs.setSeriesExpression(csd.getSeriesExpression());
311: cs.setCategoryExpression(csd.getCategoryExpression());
312: cs.setValueExpression(csd.getValueExpression());
313: cs.setLabelExpression(csd.getLabelExpression());
314: cs.setSectionItemHyperlink(csd
315: .getSectionItemHyperlink());
316:
317: jList1.updateUI();
318: }
319:
320: }
321: }//GEN-LAST:event_jButtonModifyActionPerformed
322:
323: private void jButtonAddActionPerformed(
324: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAddActionPerformed
325:
326: CategorySeriesDialog csd = new CategorySeriesDialog(
327: it.businesslogic.ireport.gui.MainFrame
328: .getMainInstance(), true);
329: csd.setSubDataset(this .getSubDataset());
330: csd.setVisible(true);
331: if (csd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) {
332: CategorySeries cs = new CategorySeries();
333: cs.setSeriesExpression(csd.getSeriesExpression());
334: cs.setCategoryExpression(csd.getCategoryExpression());
335: cs.setValueExpression(csd.getValueExpression());
336: cs.setLabelExpression(csd.getLabelExpression());
337: cs.setSectionItemHyperlink(csd.getSectionItemHyperlink());
338:
339: categoryDataset.getCategorySeries().addElement(cs);
340: ((javax.swing.DefaultListModel) jList1.getModel())
341: .addElement(cs);
342: }
343:
344: }//GEN-LAST:event_jButtonAddActionPerformed
345:
346: private void jButtonRemoveActionPerformed(
347: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRemoveActionPerformed
348:
349: while (jList1.getSelectedIndex() >= 0) {
350: categoryDataset.getCategorySeries().remove(
351: jList1.getSelectedValue());
352: ((javax.swing.DefaultListModel) jList1.getModel())
353: .removeElementAt(jList1.getSelectedIndex());
354: }
355:
356: }//GEN-LAST:event_jButtonRemoveActionPerformed
357:
358: private void jList1ValueChanged(
359: javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jList1ValueChanged
360:
361: if (jList1.getSelectedIndex() >= 0) {
362: jButtonModify.setEnabled(true);
363: jButtonModify.setEnabled(true);
364: } else {
365: jButtonModify.setEnabled(false);
366: jButtonModify.setEnabled(false);
367: }
368: }//GEN-LAST:event_jList1ValueChanged
369:
370: // Variables declaration - do not modify//GEN-BEGIN:variables
371: private javax.swing.JButton jButtonAdd;
372: private javax.swing.JButton jButtonModify;
373: private javax.swing.JButton jButtonRemove;
374: private javax.swing.JLabel jLabel1;
375: private javax.swing.JList jList1;
376: private javax.swing.JMenuItem jMenuItemCopy;
377: private javax.swing.JMenuItem jMenuItemPaste;
378: private javax.swing.JPanel jPanel1;
379: private javax.swing.JPanel jPanel2;
380: private javax.swing.JPopupMenu jPopupMenuCategorySeries;
381: private javax.swing.JScrollPane jScrollPane1;
382:
383: // End of variables declaration//GEN-END:variables
384:
385: public void applyI18n() {
386: // Start autogenerated code ----------------------
387: // End autogenerated code ----------------------
388: // Start autogenerated code ----------------------
389: jLabel1.setText(I18n.getString("categoryDatasetPanel.label1",
390: "Category series"));
391: // End autogenerated code ----------------------
392: jButtonAdd.setText(it.businesslogic.ireport.util.I18n
393: .getString("charts.newseries", "Add series"));
394: jButtonModify.setText(it.businesslogic.ireport.util.I18n
395: .getString("charts.modifyseries", "Modify series"));
396: jButtonRemove.setText(it.businesslogic.ireport.util.I18n
397: .getString("charts.removeseries", "Remove series"));
398:
399: jMenuItemCopy.setText(it.businesslogic.ireport.util.I18n
400: .getString("charts.copyseries", "Copy series"));
401: jMenuItemPaste.setText(it.businesslogic.ireport.util.I18n
402: .getString("charts.pasteseries", "Paste series"));
403:
404: this .updateUI();
405:
406: }
407:
408: public SubDataset getSubDataset() {
409: return subDataset;
410: }
411:
412: public void setSubDataset(SubDataset subDataset) {
413: this .subDataset = subDataset;
414: }
415:
416: public static final int COMPONENT_NONE = 0;
417: public static final int COMPONENT_CATEGORY_SERIES_LIST = 1;
418:
419: /**
420: * This variable is checked by openExtraWindows() called when the component is shown.
421: * If the value is != 0, the modify button will be action-performed.
422: */
423: public Object[] newInfo = null;
424:
425: /**
426: * This method set the focus on a specific component.
427: *
428: * For this kind of datasource otherInfo must be:
429: * [0] = Fixed to COMPONENT_CATEGORY_SERIES_LIST (used for future extensions)
430: * [1] = Integer, the category series to edit
431: * [2] = The expression id in the category window to focus on
432: * [3] = The expression in the hyperlink...
433: * [4] = The hyperlink parameter
434: * [5] = The expression of the hyperlink parameter
435: */
436: public void setFocusedExpression(Object[] expressionInfo) {
437: if (expressionInfo == null)
438: return;
439: int expID = ((Integer) expressionInfo[0]).intValue();
440: switch (expID) {
441: case COMPONENT_CATEGORY_SERIES_LIST:
442: int index = ((Integer) expressionInfo[1]).intValue();
443:
444: if (index >= 0 && jList1.getModel().getSize() > index) {
445: jList1.setSelectedIndex(index);
446: newInfo = new Object[expressionInfo.length - 2];
447: for (int i = 2; i < expressionInfo.length; ++i)
448: newInfo[i - 2] = expressionInfo[i];
449: break;
450: }
451: }
452: }
453:
454: /**
455: * This method checks for the variable subExpID. It is called when the component is shown.
456: * If the value is >= 0, the modify button will be action-performed
457: */
458: private void openExtraWindows() {
459: if (newInfo != null) {
460: jButtonModifyActionPerformed(new ActionEvent(jButtonModify,
461: 0, ""));
462: }
463: newInfo = null;
464: }
465:
466: public void containerWindowOpened() {
467: openExtraWindows();
468: }
469: }
|