1 32 33 package it.businesslogic.ireport.gui; 34 35 import it.businesslogic.ireport.*; 36 import it.businesslogic.ireport.gui.sheet.Tag; 37 import it.businesslogic.ireport.util.*; 38 39 40 43 public class JRSubreportReturnValueDialog 44 extends javax.swing.JDialog 45 { 46 47 48 private JRSubreportReturnValue subreportReturnValue = null; 49 50 57 public JRSubreportReturnValueDialog(java.awt.Dialog parent, boolean modal) 58 { 59 super(parent, modal); 60 initComponents(); 61 applyI18n(); 62 setTypes(); 63 updateVariables(); 64 jComboBoxSubreportVariable.setSelectedItem(""); 65 this.setSize(380, 260); 66 Misc.centerFrame(this); 67 68 69 javax.swing.KeyStroke escape = javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0, false); 70 javax.swing.Action escapeAction = new javax.swing.AbstractAction () { 71 public void actionPerformed(java.awt.event.ActionEvent e) { 72 jButtonCancelActionPerformed(e); 73 } 74 }; 75 76 getRootPane().getInputMap(javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE"); 77 getRootPane().getActionMap().put("ESCAPE", escapeAction); 78 79 80 this.getRootPane().setDefaultButton(this.jButtonOK); 82 } 83 84 87 public void setTypes() 88 { 89 this.jComboBoxCalculationType.addItem(new Tag("Nothing", I18n.getString("variable.calculationType.Nothing", "Nothing") )); 90 this.jComboBoxCalculationType.addItem(new Tag("Count", I18n.getString("variable.calculationType.Count", "Count"))); 91 this.jComboBoxCalculationType.addItem(new Tag("DistinctCount", I18n.getString("variable.calculationType.DistinctCount", "Distinct count"))); 92 this.jComboBoxCalculationType.addItem(new Tag("Sum", I18n.getString("variable.calculationType.Sum", "Sum"))); 93 this.jComboBoxCalculationType.addItem(new Tag("Average", I18n.getString("variable.calculationType.Average", "Average"))); 94 this.jComboBoxCalculationType.addItem(new Tag("Lowest", I18n.getString("variable.calculationType.Lowest", "Lowest"))); 95 this.jComboBoxCalculationType.addItem(new Tag("Highest", I18n.getString("variable.calculationType.Highest", "Highest"))); 96 this.jComboBoxCalculationType.addItem(new Tag("StandardDeviation", I18n.getString("variable.calculationType.StandardDeviation", "Standard deviation"))); 97 this.jComboBoxCalculationType.addItem(new Tag("Variance", I18n.getString("variable.calculationType.Variance", "Variance") )); 98 this.jComboBoxCalculationType.addItem(new Tag("System", I18n.getString("variable.calculationType.System", "System") )); 99 this.jComboBoxCalculationType.addItem(new Tag("First", I18n.getString("variable.calculationType.First", "First") )); 100 } 101 102 105 public void updateVariables() 106 { 107 try { 108 Misc.updateComboBox(jComboBoxVariable, 109 it.businesslogic.ireport.gui.MainFrame.getMainInstance().getActiveReportFrame().getReport().getVariables(), false); 110 111 for (int i=0; i<jComboBoxVariable.getItemCount(); ++i) 113 { 114 115 Object var = jComboBoxVariable.getItemAt(i); 116 if (var instanceof JRVariable && ((JRVariable)var).isBuiltin()) 117 { 118 jComboBoxSubreportVariable.addItem( var+""); 119 jComboBoxVariable.removeItem(var); 120 --i; 121 } 122 } 123 124 } catch (Exception ex) 125 { 126 127 } 128 } 129 130 135 136 137 private void initComponents() { 139 java.awt.GridBagConstraints gridBagConstraints; 140 141 jLabel1 = new javax.swing.JLabel (); 142 jLabel2 = new javax.swing.JLabel (); 143 jLabel5 = new javax.swing.JLabel (); 144 jComboBoxCalculationType = new javax.swing.JComboBox (); 145 jComboBoxVariable = new javax.swing.JComboBox (); 146 jLabel8 = new javax.swing.JLabel (); 147 jTextFieldNameIncrementerFactoryClass = new javax.swing.JTextField (); 148 jPanel1 = new javax.swing.JPanel (); 149 jButtonOK = new javax.swing.JButton (); 150 jButtonCancel = new javax.swing.JButton (); 151 jComboBoxSubreportVariable = new javax.swing.JComboBox (); 152 153 getContentPane().setLayout(new java.awt.GridBagLayout ()); 154 155 setTitle("Add/modify variable"); 156 setModal(true); 157 addWindowListener(new java.awt.event.WindowAdapter () { 158 public void windowClosing(java.awt.event.WindowEvent evt) { 159 closeDialog(evt); 160 } 161 }); 162 163 jLabel1.setText("Subreport variable"); 164 gridBagConstraints = new java.awt.GridBagConstraints (); 165 gridBagConstraints.gridx = 0; 166 gridBagConstraints.gridy = 0; 167 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 168 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 169 getContentPane().add(jLabel1, gridBagConstraints); 170 171 jLabel2.setText("Calculation type"); 172 gridBagConstraints = new java.awt.GridBagConstraints (); 173 gridBagConstraints.gridx = 0; 174 gridBagConstraints.gridy = 4; 175 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 176 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 177 getContentPane().add(jLabel2, gridBagConstraints); 178 179 jLabel5.setText("Local destination variable"); 180 gridBagConstraints = new java.awt.GridBagConstraints (); 181 gridBagConstraints.gridx = 0; 182 gridBagConstraints.gridy = 2; 183 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 184 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 185 getContentPane().add(jLabel5, gridBagConstraints); 186 187 gridBagConstraints = new java.awt.GridBagConstraints (); 188 gridBagConstraints.gridx = 0; 189 gridBagConstraints.gridy = 5; 190 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 191 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 192 gridBagConstraints.weightx = 1.0; 193 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 194 getContentPane().add(jComboBoxCalculationType, gridBagConstraints); 195 196 gridBagConstraints = new java.awt.GridBagConstraints (); 197 gridBagConstraints.gridx = 0; 198 gridBagConstraints.gridy = 3; 199 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 200 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 201 gridBagConstraints.weightx = 1.0; 202 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 203 getContentPane().add(jComboBoxVariable, gridBagConstraints); 204 205 jLabel8.setText("Custom Incrementer Factory Class"); 206 gridBagConstraints = new java.awt.GridBagConstraints (); 207 gridBagConstraints.gridx = 0; 208 gridBagConstraints.gridy = 8; 209 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 210 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 211 getContentPane().add(jLabel8, gridBagConstraints); 212 213 gridBagConstraints = new java.awt.GridBagConstraints (); 214 gridBagConstraints.gridx = 0; 215 gridBagConstraints.gridy = 9; 216 gridBagConstraints.gridwidth = 2; 217 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 218 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 219 gridBagConstraints.weightx = 1.0; 220 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 221 getContentPane().add(jTextFieldNameIncrementerFactoryClass, gridBagConstraints); 222 223 jPanel1.setLayout(new java.awt.FlowLayout (java.awt.FlowLayout.RIGHT)); 224 225 jButtonOK.setMnemonic('o'); 226 jButtonOK.setText("OK"); 227 jButtonOK.addActionListener(new java.awt.event.ActionListener () { 228 public void actionPerformed(java.awt.event.ActionEvent evt) { 229 jButtonOKActionPerformed(evt); 230 } 231 }); 232 233 jPanel1.add(jButtonOK); 234 235 jButtonCancel.setText("Cancel"); 236 jButtonCancel.setMnemonic('c'); 237 jButtonCancel.addActionListener(new java.awt.event.ActionListener () { 238 public void actionPerformed(java.awt.event.ActionEvent evt) { 239 jButtonCancelActionPerformed(evt); 240 } 241 }); 242 243 jPanel1.add(jButtonCancel); 244 245 gridBagConstraints = new java.awt.GridBagConstraints (); 246 gridBagConstraints.gridx = 0; 247 gridBagConstraints.gridy = 14; 248 gridBagConstraints.gridwidth = 3; 249 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 250 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 251 gridBagConstraints.weightx = 1.0; 252 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 253 getContentPane().add(jPanel1, gridBagConstraints); 254 255 jComboBoxSubreportVariable.setEditable(true); 256 gridBagConstraints = new java.awt.GridBagConstraints (); 257 gridBagConstraints.gridx = 0; 258 gridBagConstraints.gridy = 1; 259 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 260 gridBagConstraints.insets = new java.awt.Insets (0, 4, 0, 4); 261 getContentPane().add(jComboBoxSubreportVariable, gridBagConstraints); 262 263 pack(); 264 java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); 265 java.awt.Dimension dialogSize = getSize(); 266 setLocation((screenSize.width-dialogSize.width)/2,(screenSize.height-dialogSize.height)/2); 267 } private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) { 270 setVisible(false); 271 this.setDialogResult(javax.swing.JOptionPane.CANCEL_OPTION); 272 dispose(); 273 } 275 private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) { 277 278 if ((this.jComboBoxSubreportVariable.getSelectedItem()+"").trim().length() <= 0) 279 { 280 javax.swing.JOptionPane.showMessageDialog(this, 281 I18n.getString( "messages.jRSubreportReturnValueDialog.notValidName","Please insert a valid subreport variable name!"), 282 I18n.getString( "messages.jRSubreportReturnValueDialog.notValidNameCaption","Invalid variable!"), 283 javax.swing.JOptionPane.WARNING_MESSAGE); 284 285 return; 286 } 287 288 subreportReturnValue = new JRSubreportReturnValue(); 289 290 subreportReturnValue.setSubreportVariable( this.jComboBoxSubreportVariable.getSelectedItem()+"" ); 291 292 293 if (this.jComboBoxVariable.getSelectedItem() == null) 294 { 295 javax.swing.JOptionPane.showMessageDialog(this, 296 I18n.getString( "messages.jRSubreportReturnValueDialog.notValidLocalVariable","Please insert a valid local variable! If no variables are available, please close this dialog and create one."), 297 I18n.getString( "messages.jRSubreportReturnValueDialog.notValidLocalVariableCaption","Invalid variable!"), 298 javax.swing.JOptionPane.WARNING_MESSAGE); 299 300 return; 301 } 302 subreportReturnValue.setToVariable( jComboBoxVariable.getSelectedItem()+""); 303 304 Object t = this.jComboBoxCalculationType.getSelectedItem(); 305 if (t != null && t instanceof Tag) subreportReturnValue.setCalculation( ((Tag)t).getValue()+"" ); 306 subreportReturnValue.setIncrementFactoryClass( this.jTextFieldNameIncrementerFactoryClass.getText()); 307 308 setVisible(false); 309 this.setDialogResult(javax.swing.JOptionPane.OK_OPTION); 310 dispose(); 311 } 313 317 private void closeDialog(java.awt.event.WindowEvent evt) { 319 setVisible(false); 320 this.setDialogResult(javax.swing.JOptionPane.CLOSED_OPTION); 321 dispose(); 322 } 324 329 public it.businesslogic.ireport.JRSubreportReturnValue getSubreportReturnValue() 330 { 331 332 return subreportReturnValue; 333 } 334 335 340 public void setSubreportReturnValue(it.businesslogic.ireport.JRSubreportReturnValue tmpSubreportReturnValue) 341 { 342 this.jComboBoxSubreportVariable.setSelectedItem(new String (tmpSubreportReturnValue.getSubreportVariable() )); 343 for (int i=0; i<jComboBoxVariable.getItemCount(); ++i) 344 { 345 346 Object var = jComboBoxVariable.getItemAt(i); 347 if ((var+"").equals( tmpSubreportReturnValue.getToVariable() )) 348 { 349 jComboBoxVariable.setSelectedIndex(i); 350 break; 351 } 352 } 353 354 Misc.setComboboxSelectedTagValue( jComboBoxCalculationType, tmpSubreportReturnValue.getCalculation() ); 355 this.jTextFieldNameIncrementerFactoryClass.setText(tmpSubreportReturnValue.getIncrementFactoryClass()); 356 } 357 358 363 public int getDialogResult() 364 { 365 366 return dialogResult; 367 } 368 369 374 public void setDialogResult(int dialogResult) 375 { 376 this.dialogResult = dialogResult; 377 } 378 379 380 private javax.swing.JButton jButtonCancel; 382 private javax.swing.JButton jButtonOK; 383 private javax.swing.JComboBox jComboBoxCalculationType; 384 private javax.swing.JComboBox jComboBoxSubreportVariable; 385 private javax.swing.JComboBox jComboBoxVariable; 386 private javax.swing.JLabel jLabel1; 387 private javax.swing.JLabel jLabel2; 388 private javax.swing.JLabel jLabel5; 389 private javax.swing.JLabel jLabel8; 390 private javax.swing.JPanel jPanel1; 391 private javax.swing.JTextField jTextFieldNameIncrementerFactoryClass; 392 private int dialogResult; 394 395 public void applyI18n(){ 396 jButtonCancel.setText(I18n.getString("jRSubreportReturnValueDialog.buttonCancel","Cancel")); 398 jButtonOK.setText(I18n.getString("jRSubreportReturnValueDialog.buttonOK","OK")); 399 jLabel1.setText(I18n.getString("jRSubreportReturnValueDialog.label1","Subreport variable")); 400 jLabel2.setText(I18n.getString("jRSubreportReturnValueDialog.label2","Calculation type")); 401 jLabel5.setText(I18n.getString("jRSubreportReturnValueDialog.label5","Local destination variable")); 402 jLabel8.setText(I18n.getString("jRSubreportReturnValueDialog.label8","Custom Incrementer Factory Class")); 403 } 405 } 406 | Popular Tags |