1 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 42 public class CompatibilityDialog extends javax.swing.JDialog { 43 44 MainFrame mf = null; 45 46 47 public CompatibilityDialog(java.awt.Frame 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 escape = javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0, false); 81 javax.swing.Action escapeAction = new javax.swing.AbstractAction () { 82 public void actionPerformed(java.awt.event.ActionEvent 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 this.getRootPane().setDefaultButton(this.jButtonOk); 93 } 94 95 100 private void initComponents() { 102 java.awt.GridBagConstraints gridBagConstraints; 103 104 buttonGroup1 = new javax.swing.ButtonGroup (); 105 jPanel1 = new javax.swing.JPanel (); 106 jPanel9 = new javax.swing.JPanel (); 107 jComboBox1 = new javax.swing.JComboBox (); 108 jPanel2 = new javax.swing.JPanel (); 109 jButtonOk = new javax.swing.JButton (); 110 jButtonCancel = new javax.swing.JButton (); 111 112 setTitle(it.businesslogic.ireport.util.I18n.getString("compatibilityOptions", "Compatibility options")); 113 setResizable(false); 114 addWindowListener(new java.awt.event.WindowAdapter () { 115 public void windowClosing(java.awt.event.WindowEvent evt) { 116 closeDialog(evt); 117 } 118 }); 119 120 jPanel1.setLayout(new java.awt.BorderLayout ()); 121 122 jPanel9.setLayout(new java.awt.GridBagLayout ()); 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 ("Dialog", 0, 11))); 125 jPanel9.setMinimumSize(new java.awt.Dimension (250, 150)); 126 jPanel9.setPreferredSize(new java.awt.Dimension (250, 150)); 127 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (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 (java.awt.FlowLayout.RIGHT)); 140 141 jButtonOk.setMnemonic('o'); 142 jButtonOk.setText("Ok"); 143 jButtonOk.addActionListener(new java.awt.event.ActionListener () { 144 public void actionPerformed(java.awt.event.ActionEvent 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 () { 154 public void actionPerformed(java.awt.event.ActionEvent evt) { 155 jButtonCancelActionPerformed(evt); 156 } 157 }); 158 159 jPanel2.add(jButtonCancel); 160 161 getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH); 162 163 pack(); 164 } 166 private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) { close(); 168 } 170 private void jButtonOkActionPerformed(java.awt.event.ActionEvent evt) { save(); 172 close(); 173 } 175 private void closeDialog(java.awt.event.WindowEvent evt) { } 179 private void load(){ 180 if (mf == null || mf.getProperties() == null) { 181 return; 182 } 183 java.util.Properties 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 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 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 ex) { 222 ex.printStackTrace(); 223 } 224 } 225 private void close(){ 226 setVisible(false); 227 dispose(); 228 } 229 230 233 public static void main(String args[]) { 234 new CompatibilityDialog(new javax.swing.JFrame (), true).setVisible(true); 235 } 236 237 238 private javax.swing.ButtonGroup buttonGroup1; 240 private javax.swing.JButton jButtonCancel; 241 private javax.swing.JButton jButtonOk; 242 private javax.swing.JComboBox jComboBox1; 243 private javax.swing.JPanel jPanel1; 244 private javax.swing.JPanel jPanel2; 245 private javax.swing.JPanel jPanel9; 246 248 public void applyI18n(){ 249 jButtonCancel.setText(I18n.getString("compatibilityDialog.buttonCancel","Cancel")); 251 jButtonOk.setText(I18n.getString("compatibilityDialog.buttonOk","Ok")); 252 ((javax.swing.border.TitledBorder )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 desc = ""; 262 263 public JRVersionItem(int version, String 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 getDesc() { 278 return desc; 279 } 280 281 public void setDesc(String desc) { 282 this.desc = desc; 283 } 284 285 public String toString() 286 { 287 return desc; 288 } 289 } 290 | Popular Tags |