KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > gui > ReportImportsDialog


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  * ReportImportsDialog.java
28  *
29  * Created on 29 settembre 2004, 0.56
30  *
31  */

32
33 package it.businesslogic.ireport.gui;
34 import it.businesslogic.ireport.gui.*;
35 import it.businesslogic.ireport.*;
36 import javax.swing.tree.*;
37 import javax.swing.table.*;
38 import javax.swing.*;
39 import it.businesslogic.ireport.chart.*;
40 import java.util.*;
41 import it.businesslogic.ireport.util.I18n;
42 /**
43  *
44  * @author Administrator
45  */

46 public class ReportImportsDialog extends javax.swing.JDialog JavaDoc {
47    
48     private int dialogResult = javax.swing.JOptionPane.CANCEL_OPTION;
49     private JReportFrame jReportFrame = null;
50     /** Creates new form IReportChartDialog */
51     public ReportImportsDialog(java.awt.Dialog JavaDoc parent, boolean modal) {
52         super(parent, modal);
53         initComponents();
54         initFrame();
55     }
56     
57     public void initFrame()
58     {
59         javax.swing.DefaultListModel JavaDoc dlm = new javax.swing.DefaultListModel JavaDoc() ;
60         jList1.setModel(dlm );
61         jList1.updateUI();
62         
63         this.setSize(500,400);
64         it.businesslogic.ireport.util.Misc.centerFrame(this);
65         
66         javax.swing.KeyStroke JavaDoc escape = javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0, false);
67         javax.swing.Action JavaDoc escapeAction = new javax.swing.AbstractAction JavaDoc() {
68             public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
69                 jButtonCloseActionPerformed(e);
70             }
71         };
72        
73         getRootPane().getInputMap(javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE");
74         getRootPane().getActionMap().put("ESCAPE", escapeAction);
75
76         applyI18n();
77         //to make the default button ...
78
this.getRootPane().setDefaultButton(this.jButtonClose);
79         
80     }
81     
82     public ReportImportsDialog(java.awt.Frame JavaDoc parent, boolean modal) {
83         super(parent, modal);
84         initComponents();
85         initFrame();
86         
87     }
88     
89     public void updateImportsList()
90     {
91         
92         Vector values = new Vector();
93         
94         javax.swing.DefaultListModel JavaDoc dlm = (javax.swing.DefaultListModel JavaDoc)jList1.getModel();
95         dlm.removeAllElements();
96
97         if (getJReportFrame() == null) { jList1.updateUI(); return; }
98
99         Enumeration var_enum = getJReportFrame().getReport().getImports().elements();
100         while (var_enum.hasMoreElements())
101         {
102             String JavaDoc var = (String JavaDoc)var_enum.nextElement();
103             dlm.addElement( var );
104         }
105         jList1.updateUI();
106     }
107
108     public JReportFrame getJReportFrame() {
109         
110         return jReportFrame;
111     }
112
113     public void setJReportFrame(JReportFrame jReportFrame) {
114
115         this.jReportFrame = jReportFrame;
116         updateImportsList();
117     }
118
119     public int getDialogResult() {
120         return dialogResult;
121     }
122
123     public void setDialogResult(int dialogResult) {
124         this.dialogResult = dialogResult;
125     }
126     
127     /** This method is called from within the constructor to
128      * initialize the form.
129      * WARNING: Do NOT modify this code. The content of this method is
130      * always regenerated by the Form Editor.
131      */

132     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
133
private void initComponents() {
134         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
135
136         jPanelData = new javax.swing.JPanel JavaDoc();
137         jScrollPane3 = new javax.swing.JScrollPane JavaDoc();
138         jList1 = new javax.swing.JList JavaDoc();
139         jPanel2 = new javax.swing.JPanel JavaDoc();
140         jButtonNewImport = new javax.swing.JButton JavaDoc();
141         jButtonModifyImport = new javax.swing.JButton JavaDoc();
142         jButtonDeleteImport = new javax.swing.JButton JavaDoc();
143         jPanel3 = new javax.swing.JPanel JavaDoc();
144         jButtonClose = new javax.swing.JButton JavaDoc();
145
146         setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
147         setTitle("Report Imports");
148         jPanelData.setLayout(new java.awt.GridBagLayout JavaDoc());
149
150         jList1.addListSelectionListener(new javax.swing.event.ListSelectionListener JavaDoc() {
151             public void valueChanged(javax.swing.event.ListSelectionEvent JavaDoc evt) {
152                 jList1ValueChanged(evt);
153             }
154         });
155
156         jScrollPane3.setViewportView(jList1);
157
158         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
159         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
160         gridBagConstraints.weightx = 1.0;
161         gridBagConstraints.weighty = 1.0;
162         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 4, 4, 4);
163         jPanelData.add(jScrollPane3, gridBagConstraints);
164
165         jPanel2.setLayout(new java.awt.GridBagLayout JavaDoc());
166
167         jPanel2.setMinimumSize(new java.awt.Dimension JavaDoc(100, 151));
168         jPanel2.setPreferredSize(new java.awt.Dimension JavaDoc(140, 100));
169         jButtonNewImport.setText("New import");
170         jButtonNewImport.addActionListener(new java.awt.event.ActionListener JavaDoc() {
171             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
172                 jButtonNewImportActionPerformed(evt);
173             }
174         });
175
176         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
177         gridBagConstraints.gridx = 0;
178         gridBagConstraints.gridy = 1;
179         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
180         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
181         gridBagConstraints.weightx = 1.0;
182         jPanel2.add(jButtonNewImport, gridBagConstraints);
183
184         jButtonModifyImport.setText("Modify import");
185         jButtonModifyImport.setEnabled(false);
186         jButtonModifyImport.addActionListener(new java.awt.event.ActionListener JavaDoc() {
187             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
188                 jButtonModifyImportActionPerformed(evt);
189             }
190         });
191
192         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
193         gridBagConstraints.gridx = 0;
194         gridBagConstraints.gridy = 2;
195         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
196         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
197         gridBagConstraints.weightx = 1.0;
198         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 0, 0, 0);
199         jPanel2.add(jButtonModifyImport, gridBagConstraints);
200
201         jButtonDeleteImport.setText("Remove import");
202         jButtonDeleteImport.setEnabled(false);
203         jButtonDeleteImport.addActionListener(new java.awt.event.ActionListener JavaDoc() {
204             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
205                 jButtonDeleteImportActionPerformed(evt);
206             }
207         });
208
209         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
210         gridBagConstraints.gridx = 0;
211         gridBagConstraints.gridy = 3;
212         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
213         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
214         gridBagConstraints.weightx = 1.0;
215         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 0, 0, 0);
216         jPanel2.add(jButtonDeleteImport, gridBagConstraints);
217
218         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
219         gridBagConstraints.gridx = 0;
220         gridBagConstraints.gridy = 10;
221         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
222         gridBagConstraints.weightx = 1.0;
223         gridBagConstraints.weighty = 1.0;
224         jPanel2.add(jPanel3, gridBagConstraints);
225
226         jButtonClose.setText("Close");
227         jButtonClose.addActionListener(new java.awt.event.ActionListener JavaDoc() {
228             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
229                 jButtonCloseActionPerformed(evt);
230             }
231         });
232
233         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
234         gridBagConstraints.gridx = 0;
235         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
236         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
237         gridBagConstraints.weightx = 1.0;
238         jPanel2.add(jButtonClose, gridBagConstraints);
239
240         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
241         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
242         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 0, 4, 4);
243         jPanelData.add(jPanel2, gridBagConstraints);
244
245         getContentPane().add(jPanelData, java.awt.BorderLayout.CENTER);
246
247         pack();
248     }// </editor-fold>//GEN-END:initComponents
249

250     private void jButtonDeleteImportActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonDeleteImportActionPerformed
251

252         Object JavaDoc[] vars = jList1.getSelectedValues();
253         
254         for (int i=0; i<vars.length; ++i)
255         {
256             String JavaDoc var = (String JavaDoc)vars[i];
257             this.getJReportFrame().getReport().getImports().remove(var);
258         }
259         
260         this.updateImportsList();
261         
262     }//GEN-LAST:event_jButtonDeleteImportActionPerformed
263

264     private void jButtonModifyImportActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonModifyImportActionPerformed
265

266         ImportDialog idialog = new ImportDialog(this, true);
267         String JavaDoc var = (String JavaDoc)jList1.getSelectedValue() ;
268         idialog.setImport( var );
269         idialog.setVisible(true);
270         if (idialog.getDialogResult() == javax.swing.JOptionPane.OK_OPTION)
271         {
272             this.getJReportFrame().getReport().getImports().remove(var);
273             String JavaDoc var_new = idialog.getImport();
274             if (!this.getJReportFrame().getReport().getImports().contains(var_new ))
275             {
276                 this.getJReportFrame().getReport().getImports().add(var_new);
277             }
278             this.updateImportsList();
279          }
280         
281         
282     }//GEN-LAST:event_jButtonModifyImportActionPerformed
283

284     private void jButtonNewImportActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonNewImportActionPerformed
285
ImportDialog idialog = new ImportDialog(this, true);
286         idialog.setVisible(true);
287         if (idialog.getDialogResult() == javax.swing.JOptionPane.OK_OPTION)
288         {
289             String JavaDoc var_new = idialog.getImport();
290             if (!this.getJReportFrame().getReport().getImports().contains(var_new ))
291             {
292                 this.getJReportFrame().getReport().getImports().add(var_new);
293             }
294             this.updateImportsList();
295          }
296         
297     }//GEN-LAST:event_jButtonNewImportActionPerformed
298

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

301          if (this.jList1.getSelectedIndex() >= 0) {
302             this.jButtonModifyImport.setEnabled(true);
303             this.jButtonDeleteImport.setEnabled(true);
304         }
305         else {
306             this.jButtonModifyImport.setEnabled(false);
307             this.jButtonDeleteImport.setEnabled(false);
308         }
309         
310         
311     }//GEN-LAST:event_jList1ValueChanged
312

313     private void jButtonCloseActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonCloseActionPerformed
314

315         this.setDialogResult( javax.swing.JOptionPane.OK_OPTION);
316         this.setVisible(false);
317     }//GEN-LAST:event_jButtonCloseActionPerformed
318

319
320     
321     // Variables declaration - do not modify//GEN-BEGIN:variables
322
private javax.swing.JButton JavaDoc jButtonClose;
323     private javax.swing.JButton JavaDoc jButtonDeleteImport;
324     private javax.swing.JButton JavaDoc jButtonModifyImport;
325     private javax.swing.JButton JavaDoc jButtonNewImport;
326     private javax.swing.JList JavaDoc jList1;
327     private javax.swing.JPanel JavaDoc jPanel2;
328     private javax.swing.JPanel JavaDoc jPanel3;
329     private javax.swing.JPanel JavaDoc jPanelData;
330     private javax.swing.JScrollPane JavaDoc jScrollPane3;
331     // End of variables declaration//GEN-END:variables
332

333     public void applyI18n(){
334                 // Start autogenerated code ----------------------
335
jButtonClose.setText(I18n.getString("reportImportsDialog.buttonClose","Close"));
336                 jButtonDeleteImport.setText(I18n.getString("reportImportsDialog.buttonDeleteImport","Remove import"));
337                 jButtonModifyImport.setText(I18n.getString("reportImportsDialog.buttonModifyImport","Modify import"));
338                 jButtonNewImport.setText(I18n.getString("reportImportsDialog.buttonNewImport","New import"));
339                 // End autogenerated code ----------------------
340
}
341 }
342
Popular Tags