KickJava   Java API By Example, From Geeks To Geeks.

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


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  * CompatibilityDialog.java
28  *
29  * Created on 2 giugno 2003, 22.30
30  *
31  */

32
33 package it.businesslogic.ireport.gui;
34
35 import it.businesslogic.ireport.util.Misc;
36 import it.businesslogic.ireport.*;
37 import it.businesslogic.ireport.util.I18n;
38 /**
39  *
40  * @author Administrator
41  */

42 public class CompatibilityDialog extends javax.swing.JDialog JavaDoc {
43
44     MainFrame mf = null;
45
46
47     public CompatibilityDialog(java.awt.Frame JavaDoc parent, boolean modal) {
48         super(parent, modal);
49         this.mf = (MainFrame)parent;
50         initComponents();
51         applyI18n();
52         
53         this.setSize(330, 150);
54
55         jComboBox1.addItem(new JRVersionItem( CompatibilitySupport.JR060, "JasperReports 0.6.0"));
56         jComboBox1.addItem(new JRVersionItem( CompatibilitySupport.JR061, "JasperReports 0.6.1"));
57         jComboBox1.addItem(new JRVersionItem( CompatibilitySupport.JR062, "JasperReports 0.6.2"));
58         jComboBox1.addItem(new JRVersionItem( CompatibilitySupport.JR063, "JasperReports 0.6.3"));
59         jComboBox1.addItem(new JRVersionItem( CompatibilitySupport.JR064, "JasperReports 0.6.4 - 0.6.5"));
60         jComboBox1.addItem(new JRVersionItem( CompatibilitySupport.JR066, "JasperReports 0.6.6"));
61         jComboBox1.addItem(new JRVersionItem( CompatibilitySupport.JR067, "JasperReports 0.6.7 - 0.6.8"));
62         jComboBox1.addItem(new JRVersionItem( CompatibilitySupport.JR069, "JasperReports 0.6.9"));
63         jComboBox1.addItem(new JRVersionItem( CompatibilitySupport.JR100, "JasperReports 1.0.0"));
64         jComboBox1.addItem(new JRVersionItem( CompatibilitySupport.JR103, "JasperReports 1.0.3"));
65         jComboBox1.addItem(new JRVersionItem( CompatibilitySupport.JR110, "JasperReports 1.1.0"));
66         jComboBox1.addItem(new JRVersionItem( CompatibilitySupport.JR111, "JasperReports 1.1.1"));
67         jComboBox1.addItem(new JRVersionItem( CompatibilitySupport.JR120, "JasperReports 1.2.0"));
68         jComboBox1.addItem(new JRVersionItem( CompatibilitySupport.JR125, "JasperReports 1.2.5"));
69         jComboBox1.addItem(new JRVersionItem( CompatibilitySupport.JR126, "JasperReports 1.2.6"));
70         jComboBox1.addItem(new JRVersionItem( CompatibilitySupport.JR127, "JasperReports 1.2.7"));
71         jComboBox1.addItem(new JRVersionItem( CompatibilitySupport.JR128, "JasperReports 1.2.8"));
72         jComboBox1.addItem(new JRVersionItem( CompatibilitySupport.JR129, "JasperReports 1.2.9"));
73         jComboBox1.addItem(new JRVersionItem( CompatibilitySupport.LAST_AVAILABLE_VERSION, it.businesslogic.ireport.util.I18n.getString("lastAvailableVersion")));
74
75         load();
76         Misc.centerFrame(this);
77
78
79
80         javax.swing.KeyStroke JavaDoc escape = javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0, false);
81         javax.swing.Action JavaDoc escapeAction = new javax.swing.AbstractAction JavaDoc() {
82             public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
83                 jButtonCancelActionPerformed(e);
84             }
85         };
86
87         getRootPane().getInputMap(javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE");
88         getRootPane().getActionMap().put("ESCAPE", escapeAction);
89
90
91         //to make the default button ...
92
this.getRootPane().setDefaultButton(this.jButtonOk);
93     }
94
95     /** This method is called from within the constructor to
96      * initialize the form.
97      * WARNING: Do NOT modify this code. The content of this method is
98      * always regenerated by the Form Editor.
99      */

100     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
101
private void initComponents() {
102         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
103
104         buttonGroup1 = new javax.swing.ButtonGroup JavaDoc();
105         jPanel1 = new javax.swing.JPanel JavaDoc();
106         jPanel9 = new javax.swing.JPanel JavaDoc();
107         jComboBox1 = new javax.swing.JComboBox JavaDoc();
108         jPanel2 = new javax.swing.JPanel JavaDoc();
109         jButtonOk = new javax.swing.JButton JavaDoc();
110         jButtonCancel = new javax.swing.JButton JavaDoc();
111
112         setTitle(it.businesslogic.ireport.util.I18n.getString("compatibilityOptions", "Compatibility options"));
113         setResizable(false);
114         addWindowListener(new java.awt.event.WindowAdapter JavaDoc() {
115             public void windowClosing(java.awt.event.WindowEvent JavaDoc evt) {
116                 closeDialog(evt);
117             }
118         });
119
120         jPanel1.setLayout(new java.awt.BorderLayout JavaDoc());
121
122         jPanel9.setLayout(new java.awt.GridBagLayout JavaDoc());
123
124         jPanel9.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), it.businesslogic.ireport.util.I18n.getString("jasperRepVerComp", "JasperReports Version Compatibility"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font JavaDoc("Dialog", 0, 11)));
125         jPanel9.setMinimumSize(new java.awt.Dimension JavaDoc(250, 150));
126         jPanel9.setPreferredSize(new java.awt.Dimension JavaDoc(250, 150));
127         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
128         gridBagConstraints.gridx = 0;
129         gridBagConstraints.gridy = 0;
130         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
131         gridBagConstraints.weightx = 1.0;
132         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 4, 4, 4);
133         jPanel9.add(jComboBox1, gridBagConstraints);
134
135         jPanel1.add(jPanel9, java.awt.BorderLayout.CENTER);
136
137         getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
138
139         jPanel2.setLayout(new java.awt.FlowLayout JavaDoc(java.awt.FlowLayout.RIGHT));
140
141         jButtonOk.setMnemonic('o');
142         jButtonOk.setText("Ok");
143         jButtonOk.addActionListener(new java.awt.event.ActionListener JavaDoc() {
144             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
145                 jButtonOkActionPerformed(evt);
146             }
147         });
148
149         jPanel2.add(jButtonOk);
150
151         jButtonCancel.setText("Cancel");
152         jButtonCancel.setMnemonic('c');
153         jButtonCancel.addActionListener(new java.awt.event.ActionListener JavaDoc() {
154             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
155                 jButtonCancelActionPerformed(evt);
156             }
157         });
158
159         jPanel2.add(jButtonCancel);
160
161         getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);
162
163         pack();
164     }// </editor-fold>//GEN-END:initComponents
165

166     private void jButtonCancelActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
167
close();
168     }//GEN-LAST:event_jButtonCancelActionPerformed
169

170     private void jButtonOkActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonOkActionPerformed
171
save();
172         close();
173     }//GEN-LAST:event_jButtonOkActionPerformed
174

175     private void closeDialog(java.awt.event.WindowEvent JavaDoc evt) {//GEN-FIRST:event_closeDialog
176
// Add your handling code here:
177
}//GEN-LAST:event_closeDialog
178

179     private void load(){
180         if (mf == null || mf.getProperties() == null) {
181             return;
182         }
183         java.util.Properties JavaDoc prop = mf.getProperties();
184
185         try {
186
187             for (int i=0; i<jComboBox1.getItemCount(); ++i)
188             {
189
190                 JRVersionItem jvi = (JRVersionItem)jComboBox1.getItemAt(i);
191                 if (jvi.getVersion() == CompatibilitySupport.version)
192                 {
193                     jComboBox1.setSelectedIndex(i);
194                     break;
195                 }
196             }
197
198
199         } catch (Exception JavaDoc ex) {
200             ex.printStackTrace();
201         }
202     }
203
204     private void save(){
205         if (mf == null || mf.getProperties() == null) {
206             return;
207         }
208         java.util.Properties JavaDoc prop = mf.getProperties();
209
210         try {
211             int compatibility = CompatibilitySupport.LAST_AVAILABLE_VERSION;
212
213             if (jComboBox1.getSelectedItem() != null)
214             {
215                 compatibility = ((JRVersionItem)jComboBox1.getSelectedItem()).getVersion();
216             }
217
218            CompatibilitySupport.version = compatibility;
219             prop.put("Compatibility", ""+compatibility);
220
221         } catch (Exception JavaDoc ex) {
222             ex.printStackTrace();
223         }
224     }
225     private void close(){
226         setVisible(false);
227         dispose();
228     }
229
230     /**
231      * @param args the command line arguments
232      */

233     public static void main(String JavaDoc args[]) {
234         new CompatibilityDialog(new javax.swing.JFrame JavaDoc(), true).setVisible(true);
235     }
236
237
238     // Variables declaration - do not modify//GEN-BEGIN:variables
239
private javax.swing.ButtonGroup JavaDoc buttonGroup1;
240     private javax.swing.JButton JavaDoc jButtonCancel;
241     private javax.swing.JButton JavaDoc jButtonOk;
242     private javax.swing.JComboBox JavaDoc jComboBox1;
243     private javax.swing.JPanel JavaDoc jPanel1;
244     private javax.swing.JPanel JavaDoc jPanel2;
245     private javax.swing.JPanel JavaDoc jPanel9;
246     // End of variables declaration//GEN-END:variables
247

248     public void applyI18n(){
249                 // Start autogenerated code ----------------------
250
jButtonCancel.setText(I18n.getString("compatibilityDialog.buttonCancel","Cancel"));
251                 jButtonOk.setText(I18n.getString("compatibilityDialog.buttonOk","Ok"));
252                 // End autogenerated code ----------------------
253
((javax.swing.border.TitledBorder JavaDoc)jPanel9.getBorder()).setTitle( it.businesslogic.ireport.util.I18n.getString("jasperRepVerComp", "JasperReports Version Compatibility") );
254     }
255 }
256
257
258 class JRVersionItem
259 {
260     private int version = 0;
261     private String JavaDoc desc = "";
262
263     public JRVersionItem(int version, String JavaDoc desc)
264     {
265         this.version = version;
266         this.desc = desc;
267     }
268
269     public int getVersion() {
270         return version;
271     }
272
273     public void setVersion(int version) {
274         this.version = version;
275     }
276
277     public String JavaDoc getDesc() {
278         return desc;
279     }
280
281     public void setDesc(String JavaDoc desc) {
282         this.desc = desc;
283     }
284
285     public String JavaDoc toString()
286     {
287         return desc;
288     }
289 }
290
Popular Tags