001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * CompatibilityDialog.java
028: *
029: * Created on 2 giugno 2003, 22.30
030: *
031: */
032:
033: package it.businesslogic.ireport.gui;
034:
035: import it.businesslogic.ireport.util.Misc;
036: import it.businesslogic.ireport.*;
037: import it.businesslogic.ireport.util.I18n;
038:
039: /**
040: *
041: * @author Administrator
042: */
043: public class CompatibilityDialog extends javax.swing.JDialog {
044:
045: MainFrame mf = null;
046:
047: public CompatibilityDialog(java.awt.Frame parent, boolean modal) {
048: super (parent, modal);
049: this .mf = (MainFrame) parent;
050: initComponents();
051: applyI18n();
052:
053: this .setSize(330, 150);
054:
055: jComboBox1.addItem(new JRVersionItem(
056: CompatibilitySupport.JR060, "JasperReports 0.6.0"));
057: jComboBox1.addItem(new JRVersionItem(
058: CompatibilitySupport.JR061, "JasperReports 0.6.1"));
059: jComboBox1.addItem(new JRVersionItem(
060: CompatibilitySupport.JR062, "JasperReports 0.6.2"));
061: jComboBox1.addItem(new JRVersionItem(
062: CompatibilitySupport.JR063, "JasperReports 0.6.3"));
063: jComboBox1.addItem(new JRVersionItem(
064: CompatibilitySupport.JR064,
065: "JasperReports 0.6.4 - 0.6.5"));
066: jComboBox1.addItem(new JRVersionItem(
067: CompatibilitySupport.JR066, "JasperReports 0.6.6"));
068: jComboBox1.addItem(new JRVersionItem(
069: CompatibilitySupport.JR067,
070: "JasperReports 0.6.7 - 0.6.8"));
071: jComboBox1.addItem(new JRVersionItem(
072: CompatibilitySupport.JR069, "JasperReports 0.6.9"));
073: jComboBox1.addItem(new JRVersionItem(
074: CompatibilitySupport.JR100, "JasperReports 1.0.0"));
075: jComboBox1.addItem(new JRVersionItem(
076: CompatibilitySupport.JR103, "JasperReports 1.0.3"));
077: jComboBox1.addItem(new JRVersionItem(
078: CompatibilitySupport.JR110, "JasperReports 1.1.0"));
079: jComboBox1.addItem(new JRVersionItem(
080: CompatibilitySupport.JR111, "JasperReports 1.1.1"));
081: jComboBox1.addItem(new JRVersionItem(
082: CompatibilitySupport.JR120, "JasperReports 1.2.0"));
083: jComboBox1.addItem(new JRVersionItem(
084: CompatibilitySupport.JR125, "JasperReports 1.2.5"));
085: jComboBox1.addItem(new JRVersionItem(
086: CompatibilitySupport.JR126, "JasperReports 1.2.6"));
087: jComboBox1.addItem(new JRVersionItem(
088: CompatibilitySupport.JR127, "JasperReports 1.2.7"));
089: jComboBox1.addItem(new JRVersionItem(
090: CompatibilitySupport.JR128, "JasperReports 1.2.8"));
091: jComboBox1.addItem(new JRVersionItem(
092: CompatibilitySupport.JR129, "JasperReports 1.2.9"));
093: jComboBox1.addItem(new JRVersionItem(
094: CompatibilitySupport.JR130, "JasperReports 1.3.0"));
095: jComboBox1.addItem(new JRVersionItem(
096: CompatibilitySupport.JR131, "JasperReports 1.3.1"));
097: jComboBox1.addItem(new JRVersionItem(
098: CompatibilitySupport.JR132, "JasperReports 1.3.2"));
099: jComboBox1.addItem(new JRVersionItem(
100: CompatibilitySupport.JR134, "JasperReports 1.3.4"));
101: jComboBox1.addItem(new JRVersionItem(
102: CompatibilitySupport.JR200,
103: "JasperReports 2.0.0 - 2.0.1"));
104: jComboBox1.addItem(new JRVersionItem(
105: CompatibilitySupport.JR204,
106: "JasperReports 2.0.2 - 2.0.4"));
107: jComboBox1.addItem(new JRVersionItem(
108: CompatibilitySupport.JR205, "JasperReports 2.0.5"));
109: jComboBox1.addItem(new JRVersionItem(
110: CompatibilitySupport.LAST_AVAILABLE_VERSION,
111: it.businesslogic.ireport.util.I18n
112: .getString("lastAvailableVersion")));
113:
114: load();
115: Misc.centerFrame(this );
116:
117: javax.swing.KeyStroke escape = javax.swing.KeyStroke
118: .getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0,
119: false);
120: javax.swing.Action escapeAction = new javax.swing.AbstractAction() {
121: public void actionPerformed(java.awt.event.ActionEvent e) {
122: jButtonCancelActionPerformed(e);
123: }
124: };
125:
126: getRootPane().getInputMap(
127: javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(
128: escape, "ESCAPE");
129: getRootPane().getActionMap().put("ESCAPE", escapeAction);
130:
131: //to make the default button ...
132: this .getRootPane().setDefaultButton(this .jButtonOk);
133: }
134:
135: /** This method is called from within the constructor to
136: * initialize the form.
137: * WARNING: Do NOT modify this code. The content of this method is
138: * always regenerated by the Form Editor.
139: */
140: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
141: private void initComponents() {
142: java.awt.GridBagConstraints gridBagConstraints;
143:
144: buttonGroup1 = new javax.swing.ButtonGroup();
145: jPanel1 = new javax.swing.JPanel();
146: jPanel9 = new javax.swing.JPanel();
147: jComboBox1 = new javax.swing.JComboBox();
148: jPanel2 = new javax.swing.JPanel();
149: jButtonOk = new javax.swing.JButton();
150: jButtonCancel = new javax.swing.JButton();
151:
152: setTitle(it.businesslogic.ireport.util.I18n.getString(
153: "compatibilityOptions", "Compatibility options"));
154: setResizable(false);
155: addWindowListener(new java.awt.event.WindowAdapter() {
156: public void windowClosing(java.awt.event.WindowEvent evt) {
157: closeDialog(evt);
158: }
159: });
160:
161: jPanel1.setLayout(new java.awt.BorderLayout());
162:
163: jPanel9.setLayout(new java.awt.GridBagLayout());
164:
165: jPanel9.setBorder(javax.swing.BorderFactory.createTitledBorder(
166: javax.swing.BorderFactory.createEtchedBorder(),
167: it.businesslogic.ireport.util.I18n.getString(
168: "jasperRepVerComp",
169: "JasperReports Version Compatibility"),
170: javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
171: javax.swing.border.TitledBorder.DEFAULT_POSITION,
172: new java.awt.Font("Dialog", 0, 11)));
173: jPanel9.setMinimumSize(new java.awt.Dimension(250, 150));
174: jPanel9.setPreferredSize(new java.awt.Dimension(250, 150));
175: gridBagConstraints = new java.awt.GridBagConstraints();
176: gridBagConstraints.gridx = 0;
177: gridBagConstraints.gridy = 0;
178: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
179: gridBagConstraints.weightx = 1.0;
180: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
181: jPanel9.add(jComboBox1, gridBagConstraints);
182:
183: jPanel1.add(jPanel9, java.awt.BorderLayout.CENTER);
184:
185: getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
186:
187: jPanel2.setLayout(new java.awt.FlowLayout(
188: java.awt.FlowLayout.RIGHT));
189:
190: jButtonOk.setMnemonic('o');
191: jButtonOk.setText("Ok");
192: jButtonOk
193: .addActionListener(new java.awt.event.ActionListener() {
194: public void actionPerformed(
195: java.awt.event.ActionEvent evt) {
196: jButtonOkActionPerformed(evt);
197: }
198: });
199:
200: jPanel2.add(jButtonOk);
201:
202: jButtonCancel.setText("Cancel");
203: jButtonCancel.setMnemonic('c');
204: jButtonCancel
205: .addActionListener(new java.awt.event.ActionListener() {
206: public void actionPerformed(
207: java.awt.event.ActionEvent evt) {
208: jButtonCancelActionPerformed(evt);
209: }
210: });
211:
212: jPanel2.add(jButtonCancel);
213:
214: getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);
215:
216: pack();
217: }// </editor-fold>//GEN-END:initComponents
218:
219: private void jButtonCancelActionPerformed(
220: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
221: close();
222: }//GEN-LAST:event_jButtonCancelActionPerformed
223:
224: private void jButtonOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOkActionPerformed
225: save();
226: close();
227: }//GEN-LAST:event_jButtonOkActionPerformed
228:
229: private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
230: // Add your handling code here:
231: }//GEN-LAST:event_closeDialog
232:
233: private void load() {
234: if (mf == null || mf.getProperties() == null) {
235: return;
236: }
237: java.util.Properties prop = mf.getProperties();
238:
239: try {
240:
241: for (int i = 0; i < jComboBox1.getItemCount(); ++i) {
242:
243: JRVersionItem jvi = (JRVersionItem) jComboBox1
244: .getItemAt(i);
245: if (jvi.getVersion() == CompatibilitySupport.version) {
246: jComboBox1.setSelectedIndex(i);
247: break;
248: }
249: }
250:
251: } catch (Exception ex) {
252: ex.printStackTrace();
253: }
254: }
255:
256: private void save() {
257: if (mf == null || mf.getProperties() == null) {
258: return;
259: }
260: java.util.Properties prop = mf.getProperties();
261:
262: try {
263: int compatibility = CompatibilitySupport.LAST_AVAILABLE_VERSION;
264:
265: if (jComboBox1.getSelectedItem() != null) {
266: compatibility = ((JRVersionItem) jComboBox1
267: .getSelectedItem()).getVersion();
268: }
269:
270: CompatibilitySupport.version = compatibility;
271: prop.put("Compatibility", "" + compatibility);
272:
273: } catch (Exception ex) {
274: ex.printStackTrace();
275: }
276: }
277:
278: private void close() {
279: setVisible(false);
280: dispose();
281: }
282:
283: /**
284: * @param args the command line arguments
285: */
286: public static void main(String args[]) {
287: new CompatibilityDialog(new javax.swing.JFrame(), true)
288: .setVisible(true);
289: }
290:
291: // Variables declaration - do not modify//GEN-BEGIN:variables
292: private javax.swing.ButtonGroup buttonGroup1;
293: private javax.swing.JButton jButtonCancel;
294: private javax.swing.JButton jButtonOk;
295: private javax.swing.JComboBox jComboBox1;
296: private javax.swing.JPanel jPanel1;
297: private javax.swing.JPanel jPanel2;
298: private javax.swing.JPanel jPanel9;
299:
300: // End of variables declaration//GEN-END:variables
301:
302: public void applyI18n() {
303: // Start autogenerated code ----------------------
304: jButtonCancel.setText(I18n.getString(
305: "compatibilityDialog.buttonCancel", "Cancel"));
306: jButtonOk.setText(I18n.getString(
307: "compatibilityDialog.buttonOk", "Ok"));
308: // End autogenerated code ----------------------
309: ((javax.swing.border.TitledBorder) jPanel9.getBorder())
310: .setTitle(it.businesslogic.ireport.util.I18n.getString(
311: "jasperRepVerComp",
312: "JasperReports Version Compatibility"));
313: jButtonCancel.setMnemonic(I18n.getString(
314: "compatibilityDialog.buttonCancelMnemonic", "c")
315: .charAt(0));
316: jButtonOk.setMnemonic(I18n.getString(
317: "compatibilityDialog.buttonOkMnemonic", "o").charAt(0));
318: }
319: }
320:
321: class JRVersionItem {
322: private int version = 0;
323: private String desc = "";
324:
325: public JRVersionItem(int version, String desc) {
326: this .version = version;
327: this .desc = desc;
328: }
329:
330: public int getVersion() {
331: return version;
332: }
333:
334: public void setVersion(int version) {
335: this .version = version;
336: }
337:
338: public String getDesc() {
339: return desc;
340: }
341:
342: public void setDesc(String desc) {
343: this .desc = desc;
344: }
345:
346: public String toString() {
347: return desc;
348: }
349: }
|