KickJava   Java API By Example, From Geeks To Geeks.

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


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  * XYZDatasetPanel.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 XYZDatasetPanel extends javax.swing.JPanel JavaDoc implements ChartDatasetPanel {
42     
43     private XYZDataset xyzDataset = null;
44     private SubDataset subDataset = null;
45     
46     /** Creates new form PieDatasetPanel */
47     public XYZDatasetPanel() {
48         initComponents();
49         applyI18n();
50         jList1.setModel( new javax.swing.DefaultListModel JavaDoc());
51     }
52
53     public void setXYZDataset(XYZDataset xyzDataset) {
54         this.xyzDataset = xyzDataset;
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 = xyzDataset.getXYZSeries();
63                         
64         for (int i=0; i< v.size(); ++i)
65         {
66             lm.addElement(v.elementAt(i) );
67         }
68
69     }
70
71     public XYZDataset getXYZDataset() {
72         return xyzDataset;
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("XYZ 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 jList1MouseClicked(java.awt.event.MouseEvent JavaDoc evt) {//GEN-FIRST:event_jList1MouseClicked
205
if (evt.getClickCount() == 1 && evt.getButton() == evt.BUTTON3)
206         {
207             jMenuItemCopy.setEnabled(jList1.getSelectedIndex() >= 0);
208             jMenuItemPaste.setEnabled( it.businesslogic.ireport.gui.MainFrame.getMainInstance().getChartSeriesClipBoard() != null &&
209                                        it.businesslogic.ireport.gui.MainFrame.getMainInstance().getChartSeriesClipBoard().size() > 0);
210             
211             jPopupMenuSeries.show(jList1, evt.getPoint().x, evt.getPoint().y);
212         }
213         else if (evt.getClickCount() == 2 && evt.getButton() == evt.BUTTON1)
214         {
215             jButtonModifyActionPerformed(null);
216         }
217     }//GEN-LAST:event_jList1MouseClicked
218

219     private void jMenuItemPasteActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jMenuItemPasteActionPerformed
220
Vector v = it.businesslogic.ireport.gui.MainFrame.getMainInstance().getChartSeriesClipBoard();
221         
222         if (v != null && v.size() > 0)
223         {
224             for (int i=0; i<v.size(); ++i)
225             {
226                 if (v.elementAt(i) instanceof XYZSeries)
227                 {
228                     XYZSeries cs = (XYZSeries)v.elementAt(i);
229                     cs = cs.cloneMe();
230                     getXYZDataset().getXYZSeries().addElement(cs);
231                     ((javax.swing.DefaultListModel JavaDoc)jList1.getModel()).addElement(cs);
232                 }
233             }
234             jList1.updateUI();
235         }
236     }//GEN-LAST:event_jMenuItemPasteActionPerformed
237

238     private void jMenuItemCopyActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jMenuItemCopyActionPerformed
239
Object JavaDoc[] values = jList1.getSelectedValues();
240         Vector copy_c = new Vector();
241         for (int i=0; i<values.length; ++i) copy_c.add( ((XYZSeries)values[i]).cloneMe() );
242         it.businesslogic.ireport.gui.MainFrame.getMainInstance().setChartSeriesClipBoard(copy_c);
243     }//GEN-LAST:event_jMenuItemCopyActionPerformed
244

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

247         if (jList1.getSelectedIndex() >= 0)
248         {
249             XYZSeries cs = (XYZSeries)jList1.getSelectedValue();
250             XYZSeriesDialog csd = new XYZSeriesDialog(it.businesslogic.ireport.gui.MainFrame.getMainInstance() ,true);
251             
252             csd.setSeriesExpression( cs.getSeriesExpression() );
253             csd.setXValueExpression( cs.getXValueExpression() );
254             csd.setYValueExpression( cs.getYValueExpression() );
255             csd.setZValueExpression( cs.getZValueExpression() );
256             csd.setSectionItemHyperlink( cs.getSectionItemHyperlink() );
257             
258             csd.setSubDataset( this.getSubDataset() );
259             csd.setVisible(true);
260             
261             if (csd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION)
262             {
263                 cs.setSeriesExpression( csd.getSeriesExpression() );
264                 cs.setXValueExpression( csd.getXValueExpression() );
265                 cs.setYValueExpression( csd.getYValueExpression() );
266                 cs.setZValueExpression( csd.getZValueExpression() );
267                 cs.setSectionItemHyperlink( csd.getSectionItemHyperlink() );
268
269                 jList1.updateUI();
270             }
271         
272         }
273     }//GEN-LAST:event_jButtonModifyActionPerformed
274

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

277         XYZSeriesDialog csd = new XYZSeriesDialog(it.businesslogic.ireport.gui.MainFrame.getMainInstance() ,true);
278         csd.setSubDataset( this.getSubDataset() );
279         csd.setVisible(true);
280         
281         if (csd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION)
282         {
283             XYZSeries cs = new XYZSeries();
284             cs.setSeriesExpression( csd.getSeriesExpression() );
285             cs.setXValueExpression( csd.getXValueExpression() );
286             cs.setYValueExpression( csd.getYValueExpression() );
287             cs.setZValueExpression( csd.getZValueExpression() );
288             cs.setSectionItemHyperlink( csd.getSectionItemHyperlink() );
289             
290             getXYZDataset().getXYZSeries().addElement(cs);
291             ((javax.swing.DefaultListModel JavaDoc)jList1.getModel()).addElement(cs);
292         }
293         
294     }//GEN-LAST:event_jButtonAddActionPerformed
295

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

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

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

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

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

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