KickJava   Java API By Example, From Geeks To Geeks.

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


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  * CategoryDatasetPanel.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 CategoryDatasetPanel extends javax.swing.JPanel JavaDoc implements ChartDatasetPanel {
42     
43     private CategoryDataset categoryDataset = null;
44     private SubDataset subDataset = null;
45     
46     /** Creates new form PieDatasetPanel */
47     public CategoryDatasetPanel() {
48         initComponents();
49         applyI18n();
50         jList1.setModel( new javax.swing.DefaultListModel JavaDoc());
51     }
52
53     public void setCategoryDataset(CategoryDataset categoryDataset) {
54         this.categoryDataset = categoryDataset;
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 = categoryDataset.getCategorySeries();
63                         
64         for (int i=0; i< v.size(); ++i)
65         {
66             lm.addElement(v.elementAt(i) );
67         }
68
69     }
70
71     public CategoryDataset getCategoryDataset() {
72         return categoryDataset;
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         jPopupMenuCategorySeries = 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         jPopupMenuCategorySeries.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         jPopupMenuCategorySeries.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             public void mousePressed(java.awt.event.MouseEvent JavaDoc evt) {
127                 jList1MousePressed(evt);
128             }
129         });
130
131         jScrollPane1.setViewportView(jList1);
132
133         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
134         gridBagConstraints.gridy = 1;
135         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
136         gridBagConstraints.weightx = 1.0;
137         gridBagConstraints.weighty = 1.0;
138         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 4, 4, 4);
139         add(jScrollPane1, gridBagConstraints);
140
141         jPanel1.setLayout(new java.awt.GridBagLayout JavaDoc());
142
143         jPanel1.setMinimumSize(new java.awt.Dimension JavaDoc(100, 0));
144         jPanel1.setPreferredSize(new java.awt.Dimension JavaDoc(100, 0));
145         jButtonAdd.setText("Add");
146         jButtonAdd.addActionListener(new java.awt.event.ActionListener JavaDoc() {
147             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
148                 jButtonAddActionPerformed(evt);
149             }
150         });
151
152         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
153         gridBagConstraints.gridy = 0;
154         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
155         gridBagConstraints.weightx = 1.0;
156         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 0, 0, 4);
157         jPanel1.add(jButtonAdd, gridBagConstraints);
158
159         jButtonModify.setText("Modify");
160         jButtonModify.addActionListener(new java.awt.event.ActionListener JavaDoc() {
161             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
162                 jButtonModifyActionPerformed(evt);
163             }
164         });
165
166         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
167         gridBagConstraints.gridy = 1;
168         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
169         gridBagConstraints.weightx = 1.0;
170         gridBagConstraints.insets = new java.awt.Insets JavaDoc(2, 0, 0, 4);
171         jPanel1.add(jButtonModify, gridBagConstraints);
172
173         jButtonRemove.setText("Remove");
174         jButtonRemove.addActionListener(new java.awt.event.ActionListener JavaDoc() {
175             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
176                 jButtonRemoveActionPerformed(evt);
177             }
178         });
179
180         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
181         gridBagConstraints.gridy = 2;
182         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
183         gridBagConstraints.weightx = 1.0;
184         gridBagConstraints.insets = new java.awt.Insets JavaDoc(2, 0, 0, 4);
185         jPanel1.add(jButtonRemove, gridBagConstraints);
186
187         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
188         gridBagConstraints.gridy = 99;
189         gridBagConstraints.weighty = 1.0;
190         jPanel1.add(jPanel2, gridBagConstraints);
191
192         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
193         gridBagConstraints.gridy = 1;
194         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
195         add(jPanel1, gridBagConstraints);
196
197         jLabel1.setText("Category series");
198         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
199         gridBagConstraints.gridwidth = 2;
200         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
201         gridBagConstraints.weightx = 1.0;
202         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 4, 0, 4);
203         add(jLabel1, gridBagConstraints);
204
205     }// </editor-fold>//GEN-END:initComponents
206

207     private void jList1MouseClicked(java.awt.event.MouseEvent JavaDoc evt) {//GEN-FIRST:event_jList1MouseClicked
208

209         if (evt.getClickCount() == 1 && evt.getButton() == evt.BUTTON3)
210         {
211             jMenuItemCopy.setEnabled(jList1.getSelectedIndex() >= 0);
212             jMenuItemPaste.setEnabled( it.businesslogic.ireport.gui.MainFrame.getMainInstance().getChartSeriesClipBoard() != null &&
213                                        it.businesslogic.ireport.gui.MainFrame.getMainInstance().getChartSeriesClipBoard().size() > 0);
214             
215             jPopupMenuCategorySeries.show(jList1, evt.getPoint().x, evt.getPoint().y);
216         }
217         else if (evt.getClickCount() == 2 && evt.getButton() == evt.BUTTON1)
218         {
219             jButtonModifyActionPerformed(null);
220         }
221     }//GEN-LAST:event_jList1MouseClicked
222

223     private void jList1MousePressed(java.awt.event.MouseEvent JavaDoc evt) {//GEN-FIRST:event_jList1MousePressed
224

225        
226         
227     }//GEN-LAST:event_jList1MousePressed
228

229     private void jMenuItemCopyActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jMenuItemCopyActionPerformed
230

231         Object JavaDoc[] values = jList1.getSelectedValues();
232         Vector copy_c = new Vector();
233         for (int i=0; i<values.length; ++i) copy_c.add( ((CategorySeries)values[i]).cloneMe() );
234         it.businesslogic.ireport.gui.MainFrame.getMainInstance().setChartSeriesClipBoard(copy_c);
235     }//GEN-LAST:event_jMenuItemCopyActionPerformed
236

237     private void jMenuItemPasteActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jMenuItemPasteActionPerformed
238

239         Vector v = it.businesslogic.ireport.gui.MainFrame.getMainInstance().getChartSeriesClipBoard();
240         
241         if (v != null && v.size() > 0)
242         {
243             for (int i=0; i<v.size(); ++i)
244             {
245                 if (v.elementAt(i) instanceof CategorySeries)
246                 {
247                     CategorySeries cs = (CategorySeries)v.elementAt(i);
248                     cs = cs.cloneMe();
249                     categoryDataset.getCategorySeries().addElement(cs);
250                     ((javax.swing.DefaultListModel JavaDoc)jList1.getModel()).addElement(cs);
251                 }
252             }
253         }
254         
255         
256     }//GEN-LAST:event_jMenuItemPasteActionPerformed
257

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

260         if (jList1.getSelectedIndex() >= 0)
261         {
262             CategorySeries cs = (CategorySeries)jList1.getSelectedValue();
263             CategorySeriesDialog csd = new CategorySeriesDialog(it.businesslogic.ireport.gui.MainFrame.getMainInstance() ,true);
264             
265             csd.setSeriesExpression( cs.getSeriesExpression() );
266             csd.setCategoryExpression( cs.getCategoryExpression() );
267             csd.setValueExpression( cs.getValueExpression() );
268             csd.setLabelExpression( cs.getLabelExpression() );
269             csd.setSectionItemHyperlink( cs.getSectionItemHyperlink() );
270             csd.setSubDataset( this.getSubDataset() );
271             csd.setVisible(true);
272             
273             
274             if (csd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION)
275             {
276                 cs.setSeriesExpression( csd.getSeriesExpression() );
277                 cs.setCategoryExpression( csd.getCategoryExpression() );
278                 cs.setValueExpression( csd.getValueExpression() );
279                 cs.setLabelExpression( csd.getLabelExpression() );
280                 cs.setSectionItemHyperlink( csd.getSectionItemHyperlink() );
281
282                 jList1.updateUI();
283             }
284         
285         }
286     }//GEN-LAST:event_jButtonModifyActionPerformed
287

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

290         CategorySeriesDialog csd = new CategorySeriesDialog(it.businesslogic.ireport.gui.MainFrame.getMainInstance() ,true);
291         csd.setSubDataset( this.getSubDataset() );
292         csd.setVisible(true);
293         if (csd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION)
294         {
295             CategorySeries cs = new CategorySeries();
296             cs.setSeriesExpression( csd.getSeriesExpression() );
297             cs.setCategoryExpression( csd.getCategoryExpression() );
298             cs.setValueExpression( csd.getValueExpression() );
299             cs.setLabelExpression( csd.getLabelExpression() );
300             cs.setSectionItemHyperlink( csd.getSectionItemHyperlink() );
301             
302             categoryDataset.getCategorySeries().addElement(cs);
303             ((javax.swing.DefaultListModel JavaDoc)jList1.getModel()).addElement(cs);
304         }
305         
306     }//GEN-LAST:event_jButtonAddActionPerformed
307

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

310         while (jList1.getSelectedIndex() >= 0)
311         {
312             categoryDataset.getCategorySeries().remove( jList1.getSelectedValue() );
313             ((javax.swing.DefaultListModel JavaDoc)jList1.getModel()).removeElementAt(jList1.getSelectedIndex());
314         }
315         
316     }//GEN-LAST:event_jButtonRemoveActionPerformed
317

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

320         if (jList1.getSelectedIndex() >= 0)
321         {
322             jButtonModify.setEnabled( true );
323             jButtonModify.setEnabled( true );
324         }
325         else
326         {
327             jButtonModify.setEnabled( false );
328             jButtonModify.setEnabled( false );
329         }
330     }//GEN-LAST:event_jList1ValueChanged
331

332     
333     // Variables declaration - do not modify//GEN-BEGIN:variables
334
private javax.swing.JButton JavaDoc jButtonAdd;
335     private javax.swing.JButton JavaDoc jButtonModify;
336     private javax.swing.JButton JavaDoc jButtonRemove;
337     private javax.swing.JLabel JavaDoc jLabel1;
338     private javax.swing.JList JavaDoc jList1;
339     private javax.swing.JMenuItem JavaDoc jMenuItemCopy;
340     private javax.swing.JMenuItem JavaDoc jMenuItemPaste;
341     private javax.swing.JPanel JavaDoc jPanel1;
342     private javax.swing.JPanel JavaDoc jPanel2;
343     private javax.swing.JPopupMenu JavaDoc jPopupMenuCategorySeries;
344     private javax.swing.JScrollPane JavaDoc jScrollPane1;
345     // End of variables declaration//GEN-END:variables
346

347      public void applyI18n()
348     {
349                 // Start autogenerated code ----------------------
350
// End autogenerated code ----------------------
351
// Start autogenerated code ----------------------
352
jLabel1.setText(I18n.getString("categoryDatasetPanel.label1","Category series"));
353                 // End autogenerated code ----------------------
354
jButtonAdd.setText(it.businesslogic.ireport.util.I18n.getString("charts.newseries", "Add series"));
355         jButtonModify.setText(it.businesslogic.ireport.util.I18n.getString("charts.modifyseries", "Modify series"));
356         jButtonRemove.setText(it.businesslogic.ireport.util.I18n.getString("charts.removeseries", "Remove series"));
357         
358         jMenuItemCopy.setText(it.businesslogic.ireport.util.I18n.getString("charts.copyseries", "Copy series"));
359         jMenuItemPaste.setText(it.businesslogic.ireport.util.I18n.getString("charts.pasteseries", "Paste series"));
360         
361         this.updateUI();
362         
363     }
364
365     public SubDataset getSubDataset() {
366         return subDataset;
367     }
368
369     public void setSubDataset(SubDataset subDataset) {
370         this.subDataset = subDataset;
371     }
372
373      
374 }
375
Popular Tags