KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > chart > TimePeriodDatasetPanel


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * TimePeriodDatasetPanel.java
28  *
29  * Created on 15 agosto 2005, 17.55
30  *
31  */

32
33 package it.businesslogic.ireport.chart;
34 import it.businesslogic.ireport.SubDataset;
35 import java.util.*;
36 import it.businesslogic.ireport.util.I18n;
37 /**
38  *
39  * @author Administrator
40  */

41 public class TimePeriodDatasetPanel extends javax.swing.JPanel JavaDoc implements ChartDatasetPanel {
42     
43     private TimePeriodDataset timePeriodDataset = null;
44     private SubDataset subDataset = null;
45     
46     /** Creates new form PieDatasetPanel */
47     public TimePeriodDatasetPanel() {
48         initComponents();
49         applyI18n();
50         jList1.setModel( new javax.swing.DefaultListModel JavaDoc());
51     }
52
53     public void setTimePeriodDataset(TimePeriodDataset timePeriodDataset) {
54         this.timePeriodDataset = timePeriodDataset;
55         
56         jButtonModify.setEnabled( false );
57         jButtonModify.setEnabled( false );
58         javax.swing.DefaultListModel JavaDoc lm = (javax.swing.DefaultListModel JavaDoc)jList1.getModel();
59         
60         lm.removeAllElements();
61         
62         Vector v = timePeriodDataset.getTimePeriodSeries();
63                         
64         for (int i=0; i< v.size(); ++i)
65         {
66             lm.addElement(v.elementAt(i) );
67         }
68
69     }
70
71     public TimePeriodDataset getTimePeriodDataset() {
72         return timePeriodDataset;
73     }
74   
75     
76     /** This method is called from within the constructor to
77      * initialize the form.
78      * WARNING: Do NOT modify this code. The content of this method is
79      * always regenerated by the Form Editor.
80      */

81     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
82
private void initComponents() {
83         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
84
85         jPopupMenuSeries = new javax.swing.JPopupMenu JavaDoc();
86         jMenuItemCopy = new javax.swing.JMenuItem JavaDoc();
87         jMenuItemPaste = new javax.swing.JMenuItem JavaDoc();
88         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
89         jList1 = new javax.swing.JList JavaDoc();
90         jPanel1 = new javax.swing.JPanel JavaDoc();
91         jButtonAdd = new javax.swing.JButton JavaDoc();
92         jButtonModify = new javax.swing.JButton JavaDoc();
93         jButtonRemove = new javax.swing.JButton JavaDoc();
94         jPanel2 = new javax.swing.JPanel JavaDoc();
95         jLabel1 = new javax.swing.JLabel JavaDoc();
96
97         jMenuItemCopy.setText("Copy series");
98         jMenuItemCopy.addActionListener(new java.awt.event.ActionListener JavaDoc() {
99             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
100                 jMenuItemCopyActionPerformed(evt);
101             }
102         });
103
104         jPopupMenuSeries.add(jMenuItemCopy);
105
106         jMenuItemPaste.setText("Paste series");
107         jMenuItemPaste.addActionListener(new java.awt.event.ActionListener JavaDoc() {
108             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
109                 jMenuItemPasteActionPerformed(evt);
110             }
111         });
112
113         jPopupMenuSeries.add(jMenuItemPaste);
114
115         setLayout(new java.awt.GridBagLayout JavaDoc());
116
117         jList1.addListSelectionListener(new javax.swing.event.ListSelectionListener JavaDoc() {
118             public void valueChanged(javax.swing.event.ListSelectionEvent JavaDoc evt) {
119                 jList1ValueChanged(evt);
120             }
121         });
122         jList1.addMouseListener(new java.awt.event.MouseAdapter JavaDoc() {
123             public void mouseClicked(java.awt.event.MouseEvent JavaDoc evt) {
124                 jList1MouseClicked(evt);
125             }
126         });
127
128         jScrollPane1.setViewportView(jList1);
129
130         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
131         gridBagConstraints.gridy = 1;
132         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
133         gridBagConstraints.weightx = 1.0;
134         gridBagConstraints.weighty = 1.0;
135         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 4, 4, 4);
136         add(jScrollPane1, gridBagConstraints);
137
138         jPanel1.setLayout(new java.awt.GridBagLayout JavaDoc());
139
140         jPanel1.setMinimumSize(new java.awt.Dimension JavaDoc(100, 0));
141         jPanel1.setPreferredSize(new java.awt.Dimension JavaDoc(100, 0));
142         jButtonAdd.setText("Add");
143         jButtonAdd.addActionListener(new java.awt.event.ActionListener JavaDoc() {
144             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
145                 jButtonAddActionPerformed(evt);
146             }
147         });
148
149         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
150         gridBagConstraints.gridy = 0;
151         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
152         gridBagConstraints.weightx = 1.0;
153         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 0, 0, 4);
154         jPanel1.add(jButtonAdd, gridBagConstraints);
155
156         jButtonModify.setText("Modify");
157         jButtonModify.addActionListener(new java.awt.event.ActionListener JavaDoc() {
158             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
159                 jButtonModifyActionPerformed(evt);
160             }
161         });
162
163         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
164         gridBagConstraints.gridy = 1;
165         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
166         gridBagConstraints.weightx = 1.0;
167         gridBagConstraints.insets = new java.awt.Insets JavaDoc(2, 0, 0, 4);
168         jPanel1.add(jButtonModify, gridBagConstraints);
169
170         jButtonRemove.setText("Remove");
171         jButtonRemove.addActionListener(new java.awt.event.ActionListener JavaDoc() {
172             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
173                 jButtonRemoveActionPerformed(evt);
174             }
175         });
176
177         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
178         gridBagConstraints.gridy = 2;
179         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
180         gridBagConstraints.weightx = 1.0;
181         gridBagConstraints.insets = new java.awt.Insets JavaDoc(2, 0, 0, 4);
182         jPanel1.add(jButtonRemove, gridBagConstraints);
183
184         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
185         gridBagConstraints.gridy = 99;
186         gridBagConstraints.weighty = 1.0;
187         jPanel1.add(jPanel2, gridBagConstraints);
188
189         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
190         gridBagConstraints.gridy = 1;
191         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
192         add(jPanel1, gridBagConstraints);
193
194         jLabel1.setText("Time period series");
195         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
196         gridBagConstraints.gridwidth = 2;
197         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
198         gridBagConstraints.weightx = 1.0;
199         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 4, 0, 4);
200         add(jLabel1, gridBagConstraints);
201
202     }// </editor-fold>//GEN-END:initComponents
203

204     private void jMenuItemPasteActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jMenuItemPasteActionPerformed
205
Vector v = it.businesslogic.ireport.gui.MainFrame.getMainInstance().getChartSeriesClipBoard();
206         
207         if (v != null && v.size() > 0)
208         {
209             for (int i=0; i<v.size(); ++i)
210             {
211                 if (v.elementAt(i) instanceof TimePeriodSeries)
212                 {
213                     TimePeriodSeries cs = (TimePeriodSeries)v.elementAt(i);
214                     cs = cs.cloneMe();
215                     timePeriodDataset.getTimePeriodSeries().addElement(cs);
216                     ((javax.swing.DefaultListModel JavaDoc)jList1.getModel()).addElement(cs);
217                 }
218             }
219             jList1.updateUI();
220         }
221     }//GEN-LAST:event_jMenuItemPasteActionPerformed
222

223     private void jMenuItemCopyActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jMenuItemCopyActionPerformed
224
Object JavaDoc[] values = jList1.getSelectedValues();
225         Vector copy_c = new Vector();
226         for (int i=0; i<values.length; ++i) copy_c.add( ((TimePeriodSeries)values[i]).cloneMe() );
227         it.businesslogic.ireport.gui.MainFrame.getMainInstance().setChartSeriesClipBoard(copy_c);
228     }//GEN-LAST:event_jMenuItemCopyActionPerformed
229

230     private void jList1MouseClicked(java.awt.event.MouseEvent JavaDoc evt) {//GEN-FIRST:event_jList1MouseClicked
231
if (evt.getClickCount() == 1 && evt.getButton() == evt.BUTTON3)
232         {
233             jMenuItemCopy.setEnabled(jList1.getSelectedIndex() >= 0);
234             jMenuItemPaste.setEnabled( it.businesslogic.ireport.gui.MainFrame.getMainInstance().getChartSeriesClipBoard() != null &&
235                                        it.businesslogic.ireport.gui.MainFrame.getMainInstance().getChartSeriesClipBoard().size() > 0);
236             
237             jPopupMenuSeries.show(jList1, evt.getPoint().x, evt.getPoint().y);
238         }
239         else if (evt.getClickCount() == 2 && evt.getButton() == evt.BUTTON1)
240         {
241             jButtonModifyActionPerformed(null);
242         }
243     }//GEN-LAST:event_jList1MouseClicked
244

245     private void jButtonModifyActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonModifyActionPerformed
246

247         if (jList1.getSelectedIndex() >= 0)
248         {
249             TimePeriodSeries cs = (TimePeriodSeries)jList1.getSelectedValue();
250             TimePeriodSeriesDialog csd = new TimePeriodSeriesDialog(it.businesslogic.ireport.gui.MainFrame.getMainInstance() ,true);
251             
252             csd.setSeriesExpression( cs.getSeriesExpression() );
253             csd.setStartDateExpression( cs.getStartDateExpression() );
254             csd.setEndDateExpression( cs.getEndDateExpression() );
255             csd.setValueExpression( cs.getValueExpression() );
256             csd.setLabelExpression( cs.getLabelExpression() );
257             csd.setSectionItemHyperlink( cs.getSectionItemHyperlink() );
258             
259             csd.setSubDataset( this.getSubDataset() );
260             csd.setVisible(true);
261             
262             if (csd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION)
263             {
264                 cs.setSeriesExpression( csd.getSeriesExpression() );
265                 cs.setStartDateExpression( csd.getStartDateExpression() );
266                 cs.setEndDateExpression( csd.getEndDateExpression() );
267                 cs.setValueExpression( csd.getValueExpression() );
268                 cs.setLabelExpression( csd.getLabelExpression() );
269                 cs.setSectionItemHyperlink( csd.getSectionItemHyperlink() );
270
271                 jList1.updateUI();
272             }
273         
274         }
275     }//GEN-LAST:event_jButtonModifyActionPerformed
276

277     private void jButtonAddActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonAddActionPerformed
278

279         TimePeriodSeriesDialog csd = new TimePeriodSeriesDialog(it.businesslogic.ireport.gui.MainFrame.getMainInstance() ,true);
280         csd.setSubDataset( this.getSubDataset() );
281         csd.setVisible(true);
282         if (csd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION)
283         {
284             TimePeriodSeries cs = new TimePeriodSeries();
285             cs.setSeriesExpression( csd.getSeriesExpression() );
286             cs.setStartDateExpression( csd.getStartDateExpression() );
287             cs.setEndDateExpression( csd.getEndDateExpression() );
288             cs.setValueExpression( csd.getValueExpression() );
289             cs.setLabelExpression( csd.getLabelExpression() );
290             cs.setSectionItemHyperlink( csd.getSectionItemHyperlink() );
291             
292             getTimePeriodDataset().getTimePeriodSeries().addElement(cs);
293             ((javax.swing.DefaultListModel JavaDoc)jList1.getModel()).addElement(cs);
294         }
295         
296     }//GEN-LAST:event_jButtonAddActionPerformed
297

298     private void jButtonRemoveActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonRemoveActionPerformed
299

300         while (jList1.getSelectedIndex() >= 0)
301         {
302             getTimePeriodDataset().getTimePeriodSeries().remove( jList1.getSelectedValue() );
303             ((javax.swing.DefaultListModel JavaDoc)jList1.getModel()).removeElementAt(jList1.getSelectedIndex());
304         }
305         
306     }//GEN-LAST:event_jButtonRemoveActionPerformed
307

308     private void jList1ValueChanged(javax.swing.event.ListSelectionEvent JavaDoc evt) {//GEN-FIRST:event_jList1ValueChanged
309

310         if (jList1.getSelectedIndex() >= 0)
311         {
312             jButtonModify.setEnabled( true );
313             jButtonModify.setEnabled( true );
314         }
315         else
316         {
317             jButtonModify.setEnabled( false );
318             jButtonModify.setEnabled( false );
319         }
320     }//GEN-LAST:event_jList1ValueChanged
321

322     
323     // Variables declaration - do not modify//GEN-BEGIN:variables
324
private javax.swing.JButton JavaDoc jButtonAdd;
325     private javax.swing.JButton JavaDoc jButtonModify;
326     private javax.swing.JButton JavaDoc jButtonRemove;
327     private javax.swing.JLabel JavaDoc jLabel1;
328     private javax.swing.JList JavaDoc jList1;
329     private javax.swing.JMenuItem JavaDoc jMenuItemCopy;
330     private javax.swing.JMenuItem JavaDoc jMenuItemPaste;
331     private javax.swing.JPanel JavaDoc jPanel1;
332     private javax.swing.JPanel JavaDoc jPanel2;
333     private javax.swing.JPopupMenu JavaDoc jPopupMenuSeries;
334     private javax.swing.JScrollPane JavaDoc jScrollPane1;
335     // End of variables declaration//GEN-END:variables
336

337      public void applyI18n()
338     {
339                 // Start autogenerated code ----------------------
340
// End autogenerated code ----------------------
341
// Start autogenerated code ----------------------
342
jLabel1.setText(I18n.getString("timePeriodDatasetPanel.label1","Time period series"));
343                 // End autogenerated code ----------------------
344
jButtonAdd.setText(it.businesslogic.ireport.util.I18n.getString("charts.newseries", "Add series"));
345         jButtonModify.setText(it.businesslogic.ireport.util.I18n.getString("charts.modifyseries", "Modify series"));
346         jButtonRemove.setText(it.businesslogic.ireport.util.I18n.getString("charts.removeseries", "Remove series"));
347         
348         jMenuItemCopy.setText(it.businesslogic.ireport.util.I18n.getString("charts.copyseries", "Copy series"));
349         jMenuItemPaste.setText(it.businesslogic.ireport.util.I18n.getString("charts.pasteseries", "Paste series"));
350         
351         this.updateUI();
352         
353     }
354
355     public SubDataset getSubDataset() {
356         return subDataset;
357     }
358
359     public void setSubDataset(SubDataset subDataset) {
360         this.subDataset = subDataset;
361     }
362
363      
364 }
365
Popular Tags