KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > gui > wizard > SubreportWizard


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  * SubreportWizard.java
28  *
29  * Created on March 22, 2006, 8:52 PM
30  *
31  */

32
33 package it.businesslogic.ireport.gui.wizard;
34
35 import it.businesslogic.ireport.SubReportElement;
36 import it.businesslogic.ireport.gui.JReportFrame;
37 import it.businesslogic.ireport.gui.MainFrame;
38 import it.businesslogic.ireport.gui.wizard.SubreportWizardExistingReport;
39 import it.businesslogic.ireport.util.Misc;
40 import javax.swing.JDialog JavaDoc;
41 import javax.swing.JFileChooser JavaDoc;
42 import javax.swing.JPanel JavaDoc;
43 import javax.swing.event.DocumentEvent JavaDoc;
44 import javax.swing.event.DocumentListener JavaDoc;
45 import it.businesslogic.ireport.util.I18n;
46
47 /**
48  *
49  * @author gtoffoli
50  */

51 public class SubreportWizard extends javax.swing.JPanel JavaDoc implements GenericWizard {
52     
53     private String JavaDoc reportFileName = null;
54     private SubReportElement subReportElement = null;
55     private JReportFrame jReportFrame = null;
56     private JDialog JavaDoc wizardDialog = null;
57     private BaseWizardPanel firstStep = null;
58    
59     
60     
61     /** Creates new form SubreportWizardPanes */
62     public SubreportWizard() {
63         initComponents();
64         applyI18n();
65         jTextFieldReportFileName.getDocument().addDocumentListener( new DocumentListener JavaDoc() {
66             public void changedUpdate(DocumentEvent JavaDoc e) {
67                 if (firstStep != null) firstStep.updateButtons();
68             }
69             public void insertUpdate(DocumentEvent JavaDoc e) {
70                 if (firstStep != null) firstStep.updateButtons();
71             }
72             public void removeUpdate(DocumentEvent JavaDoc e) {
73                 if (firstStep != null) firstStep.updateButtons();
74             }
75         });
76     }
77     
78     public void startWizard()
79     {
80         setJReportFrame(MainFrame.getMainInstance().getActiveReportFrame());
81         wizardDialog = new JDialog JavaDoc(MainFrame.getMainInstance(),true);
82         firstStep = new BaseWizardPanel();
83         firstStep.setGenericWizard(this);
84         wizardDialog.getContentPane().add(firstStep);
85         wizardDialog.pack();
86         Misc.centerFrame(wizardDialog);
87         
88         wizardDialog.setVisible(true);
89     }
90     
91     
92     /** This method is called from within the constructor to
93      * initialize the form.
94      * WARNING: Do NOT modify this code. The content of this method is
95      * always regenerated by the Form Editor.
96      */

97     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
98
private void initComponents() {
99         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
100
101         jPanel1 = new javax.swing.JPanel JavaDoc();
102         jRadioButton1 = new javax.swing.JRadioButton JavaDoc();
103         jLabel1 = new javax.swing.JLabel JavaDoc();
104         jRadioButton2 = new javax.swing.JRadioButton JavaDoc();
105         jPanel2 = new javax.swing.JPanel JavaDoc();
106         jTextFieldReportFileName = new javax.swing.JTextField JavaDoc();
107         jButtonBrowse = new javax.swing.JButton JavaDoc();
108         buttonGroup1 = new javax.swing.ButtonGroup JavaDoc();
109
110         jPanel1.setLayout(new java.awt.GridBagLayout JavaDoc());
111
112         jPanel1.addPropertyChangeListener(new java.beans.PropertyChangeListener JavaDoc() {
113             public void propertyChange(java.beans.PropertyChangeEvent JavaDoc evt) {
114                 jPanel1PropertyChange(evt);
115             }
116         });
117
118         buttonGroup1.add(jRadioButton1);
119         jRadioButton1.setSelected(true);
120         jRadioButton1.setText("Create a new report");
121         jRadioButton1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
122         jRadioButton1.setFocusPainted(false);
123         jRadioButton1.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
124         jRadioButton1.setMinimumSize(new java.awt.Dimension JavaDoc(115, 20));
125         jRadioButton1.setPreferredSize(new java.awt.Dimension JavaDoc(115, 20));
126         jRadioButton1.addItemListener(new java.awt.event.ItemListener JavaDoc() {
127             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
128                 jRadioButton1ItemStateChanged(evt);
129             }
130         });
131
132         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
133         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
134         gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
135         gridBagConstraints.weightx = 1.0;
136         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 20, 0, 0);
137         jPanel1.add(jRadioButton1, gridBagConstraints);
138
139         jLabel1.setForeground(new java.awt.Color JavaDoc(255, 0, 0));
140         jLabel1.setText("Save the current report first!");
141         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
142         gridBagConstraints.gridx = 0;
143         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
144         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 40, 0, 0);
145         jPanel1.add(jLabel1, gridBagConstraints);
146
147         buttonGroup1.add(jRadioButton2);
148         jRadioButton2.setText("Use an exsisting report");
149         jRadioButton2.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
150         jRadioButton2.setFocusPainted(false);
151         jRadioButton2.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
152         jRadioButton2.setPreferredSize(new java.awt.Dimension JavaDoc(129, 20));
153         jRadioButton2.addItemListener(new java.awt.event.ItemListener JavaDoc() {
154             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
155                 jRadioButton2ItemStateChanged(evt);
156             }
157         });
158
159         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
160         gridBagConstraints.gridx = 0;
161         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
162         gridBagConstraints.weightx = 1.0;
163         gridBagConstraints.insets = new java.awt.Insets JavaDoc(24, 20, 0, 0);
164         jPanel1.add(jRadioButton2, gridBagConstraints);
165
166         jPanel2.setLayout(new java.awt.GridBagLayout JavaDoc());
167
168         jTextFieldReportFileName.setMinimumSize(new java.awt.Dimension JavaDoc(100, 19));
169         jTextFieldReportFileName.setPreferredSize(new java.awt.Dimension JavaDoc(250, 19));
170         jTextFieldReportFileName.addActionListener(new java.awt.event.ActionListener JavaDoc() {
171             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
172                 jTextFieldReportFileNameActionPerformed(evt);
173             }
174         });
175
176         jPanel2.add(jTextFieldReportFileName, new java.awt.GridBagConstraints JavaDoc());
177
178         jButtonBrowse.setText("Browse");
179         jButtonBrowse.addActionListener(new java.awt.event.ActionListener JavaDoc() {
180             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
181                 jButtonBrowseActionPerformed(evt);
182             }
183         });
184
185         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
186         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
187         gridBagConstraints.weightx = 1.0;
188         jPanel2.add(jButtonBrowse, gridBagConstraints);
189
190         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
191         gridBagConstraints.gridx = 0;
192         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
193         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 40, 0, 0);
194         jPanel1.add(jPanel2, gridBagConstraints);
195
196         setLayout(new java.awt.BorderLayout JavaDoc());
197
198     }// </editor-fold>//GEN-END:initComponents
199

200     private void jButtonBrowseActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonBrowseActionPerformed
201

202         // jfilechooser...
203
JFileChooser JavaDoc jfc = new JFileChooser JavaDoc();
204         jfc.setFileFilter( new javax.swing.filechooser.FileFilter JavaDoc() {
205             public boolean accept(java.io.File JavaDoc file) {
206                 String JavaDoc filename = file.getName().toLowerCase();
207                 return (filename.endsWith(".xml") || filename.endsWith(".jrxml") || filename.endsWith(".jasper") || file.isDirectory()) ;
208             }
209             public String JavaDoc getDescription() {
210                 return "JasperReports Report file *.xml;*jrxml;*.jasper";
211             }
212         });
213         if (jfc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
214             jTextFieldReportFileName.setText( jfc.getSelectedFile().getPath());
215                     jRadioButton2.setSelected(true);
216             }
217         firstStep.updateButtons();
218     }//GEN-LAST:event_jButtonBrowseActionPerformed
219

220     private void jRadioButton1ItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_jRadioButton1ItemStateChanged
221
firstStep.updateButtons();
222     }//GEN-LAST:event_jRadioButton1ItemStateChanged
223

224     private void jRadioButton2ItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_jRadioButton2ItemStateChanged
225

226         firstStep.updateButtons();
227     }//GEN-LAST:event_jRadioButton2ItemStateChanged
228

229     private void jPanel1PropertyChange(java.beans.PropertyChangeEvent JavaDoc evt) {//GEN-FIRST:event_jPanel1PropertyChange
230

231         
232         
233     }//GEN-LAST:event_jPanel1PropertyChange
234

235     private void jTextFieldReportFileNameActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jTextFieldReportFileNameActionPerformed
236

237         
238         firstStep.updateButtons();
239             
240             
241     }//GEN-LAST:event_jTextFieldReportFileNameActionPerformed
242

243     
244     // Variables declaration - do not modify//GEN-BEGIN:variables
245
private javax.swing.ButtonGroup JavaDoc buttonGroup1;
246     private javax.swing.JButton JavaDoc jButtonBrowse;
247     private javax.swing.JLabel JavaDoc jLabel1;
248     private javax.swing.JPanel JavaDoc jPanel1;
249     private javax.swing.JPanel JavaDoc jPanel2;
250     private javax.swing.JRadioButton JavaDoc jRadioButton1;
251     private javax.swing.JRadioButton JavaDoc jRadioButton2;
252     private javax.swing.JTextField JavaDoc jTextFieldReportFileName;
253     // End of variables declaration//GEN-END:variables
254

255
256     public String JavaDoc[] getStepsNames() {
257         
258         String JavaDoc[] names = new String JavaDoc[1];
259         names[0] = "Report selection";
260         
261         return names;
262     }
263
264     public String JavaDoc getStepDescription(int step) {
265         
266         if (step==0) return "New or exsisting report...";
267         return "";
268     }
269
270     public void initWizard() {
271         
272         jLabel1.setVisible(!(MainFrame.getMainInstance().getActiveReportFrame().getReport().getFilename() != null &&
273             MainFrame.getMainInstance().getActiveReportFrame().getReport().getFilename().trim().length() > 0));
274     }
275
276     public void finish(int currentStep) {
277         
278         if (currentStep == -1)
279         {
280             wizardDialog.setVisible(false);
281             wizardDialog.dispose();
282         }
283     }
284     
285     public boolean nextStep(int nextStep) {
286         
287         if (nextStep == 1) // First step == 0
288
{
289             if (jRadioButton1.isSelected())
290             {
291                 // Close the current wizard and start the new wizard 2...
292
SubreportWizardNewReport wizard2 = new SubreportWizardNewReport();
293                 wizard2.setSubReportElement(getSubReportElement());
294                 wizard2.setReportFileName( jTextFieldReportFileName.getText());
295                 wizard2.setWizardPanel( firstStep );
296                 wizard2.setWizardDialog( wizardDialog);
297                 firstStep.setGenericWizard( wizard2 );
298             }
299             else
300             {
301                 // Close the current wizard and start the new wizard 3...
302
SubreportWizardExistingReport wizard2 = new SubreportWizardExistingReport();
303                 wizard2.setSubReportElement(getSubReportElement());
304                 wizard2.setReportFileName( jTextFieldReportFileName.getText());
305                 wizard2.setWizardPanel( firstStep );
306                 wizard2.setWizardDialog( wizardDialog);
307                 firstStep.setGenericWizard( wizard2 );
308             }
309             return false;
310         }
311         return true;
312     }
313
314     public boolean previousStep(int previousStep) {
315         return true;
316     }
317
318     public boolean canFinish(int currentStep) {
319         return false;
320     }
321
322     public boolean canNext(int currentStep) {
323         
324         if (jRadioButton1.isSelected() &&
325             MainFrame.getMainInstance().getActiveReportFrame().getReport().getFilename() != null &&
326             MainFrame.getMainInstance().getActiveReportFrame().getReport().getFilename().trim().length() > 0)
327         {
328             return true;
329         }
330         if (jTextFieldReportFileName.getText().trim().length() > 0) return true;
331         
332         return false;
333     }
334
335     public boolean canPrevious(int currentStep) {
336         return false;
337     }
338
339     public JPanel JavaDoc getStepPanel(int step) {
340        return jPanel1;
341     }
342
343     public String JavaDoc getReportFileName() {
344         return reportFileName;
345     }
346
347     public void setReportFileName(String JavaDoc reportFileName) {
348         this.reportFileName = reportFileName;
349     }
350
351     public SubReportElement getSubReportElement() {
352         return subReportElement;
353     }
354
355     public void setSubReportElement(SubReportElement subReportElement) {
356         this.subReportElement = subReportElement;
357     }
358
359     public JReportFrame getJReportFrame() {
360         return jReportFrame;
361     }
362
363     public void setJReportFrame(JReportFrame jReportFrame) {
364         this.jReportFrame = jReportFrame;
365     }
366     
367     public void applyI18n(){
368                 // Start autogenerated code ----------------------
369
jRadioButton1.setText(I18n.getString("subreportWizard.radioButton1","Create a new report"));
370                 jRadioButton2.setText(I18n.getString("subreportWizard.radioButton2","Use an exsisting report"));
371                 // End autogenerated code ----------------------
372
// Start autogenerated code ----------------------
373
jButtonBrowse.setText(I18n.getString("subreportWizard.buttonBrowse","Browse"));
374                 jLabel1.setText(I18n.getString("subreportWizard.label1","Save the current report first!"));
375                 // End autogenerated code ----------------------
376
}
377 }
378
Popular Tags