1 32 33 package it.businesslogic.ireport.crosstab.gui; 34 35 import it.businesslogic.ireport.Style; 36 import it.businesslogic.ireport.crosstab.CrosstabCell; 37 import it.businesslogic.ireport.gui.MainFrame; 38 import it.businesslogic.ireport.gui.box.BoxPanel; 39 import it.businesslogic.ireport.util.Misc; 40 import java.awt.Color ; 41 import java.util.Vector ; 42 import it.businesslogic.ireport.util.I18n; 43 44 45 48 public class CrosstabCellDialog 49 extends javax.swing.JDialog  50 { 51 private CrosstabCell tmpCell = null; 52 private BoxPanel boxPanel = null; 53 private java.awt.Color bgcolor = null; 54 55 62 public CrosstabCellDialog(java.awt.Frame parent, boolean modal) 63 { 64 super(parent, modal); 65 initAll(); 66 } 67 68 public CrosstabCellDialog(java.awt.Dialog parent, boolean modal) 69 { 70 super(parent, modal); 71 initAll(); 72 } 73 74 public void initAll() 75 { 76 initComponents(); 77 78 boxPanel = new BoxPanel(); 79 boxPanel.addActionListener( new java.awt.event.ActionListener () { 80 public void actionPerformed(java.awt.event.ActionEvent evt) { 81 boxActionPerformed(evt); 82 } 83 }); 84 85 java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints (); 86 gridBagConstraints.gridx = 4; 87 gridBagConstraints.gridy = 2; 88 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 89 gridBagConstraints.insets = new java.awt.Insets (2, 4, 2, 4); 90 gridBagConstraints.weightx = 1.0; 91 gridBagConstraints.weighty = 1.0; 92 gridBagConstraints.fill = gridBagConstraints.BOTH; 93 jPanelBorder.add(boxPanel, gridBagConstraints); 94 95 pack(); 97 Misc.centerFrame(this); 98 99 java.awt.Font font = jLabel1.getFont(); 100 jLabel1.setFont(new java.awt.Font (font.getFontName(), 1, 14)); 101 102 javax.swing.KeyStroke escape = javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0, false); 103 javax.swing.Action escapeAction = new javax.swing.AbstractAction () { 104 public void actionPerformed(java.awt.event.ActionEvent e) { 105 jButtonCancelActionPerformed(e); 106 } 107 }; 108 109 getRootPane().getInputMap(javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE"); 110 getRootPane().getActionMap().put("ESCAPE", escapeAction); 111 112 applyI18n(); 113 this.getRootPane().setDefaultButton(this.jButtonOK); 115 116 } 117 118 119 public void boxActionPerformed(java.awt.event.ActionEvent evt) 120 { 121 122 123 } 124 125 130 131 132 private void initComponents() { 134 java.awt.GridBagConstraints gridBagConstraints; 135 136 jLabelWidth = new javax.swing.JLabel (); 137 jNumberFieldWidth = new it.businesslogic.ireport.gui.JNumberField(); 138 jLabelHeight = new javax.swing.JLabel (); 139 jNumberFieldHeight = new it.businesslogic.ireport.gui.JNumberField(); 140 jPanelBorder = new javax.swing.JPanel (); 141 jPanel2 = new javax.swing.JPanel (); 142 jLabelWidth1 = new javax.swing.JLabel (); 143 jButtonBackground = new javax.swing.JButton (); 144 jPanel1 = new javax.swing.JPanel (); 145 jPanel4 = new javax.swing.JPanel (); 146 jButtonOK = new javax.swing.JButton (); 147 jButtonCancel = new javax.swing.JButton (); 148 jLabel1 = new javax.swing.JLabel (); 149 jSeparator1 = new javax.swing.JSeparator (); 150 jCheckBoxTransparent = new javax.swing.JCheckBox (); 151 jLabelStyle = new javax.swing.JLabel (); 152 jComboBoxstyles = new javax.swing.JComboBox (); 153 154 getContentPane().setLayout(new java.awt.GridBagLayout ()); 155 156 setTitle("Modify cell"); 157 setModal(true); 158 addWindowListener(new java.awt.event.WindowAdapter () { 159 public void windowClosing(java.awt.event.WindowEvent evt) { 160 closeDialog(evt); 161 } 162 }); 163 164 jLabelWidth.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); 165 jLabelWidth.setText("Column width"); 166 gridBagConstraints = new java.awt.GridBagConstraints (); 167 gridBagConstraints.gridx = 0; 168 gridBagConstraints.gridy = 10; 169 gridBagConstraints.gridwidth = 2; 170 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 171 gridBagConstraints.insets = new java.awt.Insets (3, 5, 3, 3); 172 getContentPane().add(jLabelWidth, gridBagConstraints); 173 174 jNumberFieldWidth.setColumns(4); 175 jNumberFieldWidth.setHorizontalAlignment(javax.swing.JTextField.RIGHT); 176 try { 177 jNumberFieldWidth.setDecimals(0); 178 } catch (java.beans.PropertyVetoException e1) { 179 e1.printStackTrace(); 180 } 181 jNumberFieldWidth.setMinimumSize(new java.awt.Dimension (40, 21)); 182 jNumberFieldWidth.setPreferredSize(new java.awt.Dimension (38, 21)); 183 gridBagConstraints = new java.awt.GridBagConstraints (); 184 gridBagConstraints.gridx = 2; 185 gridBagConstraints.gridy = 10; 186 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 187 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 188 getContentPane().add(jNumberFieldWidth, gridBagConstraints); 189 190 jLabelHeight.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); 191 jLabelHeight.setText("Row height"); 192 gridBagConstraints = new java.awt.GridBagConstraints (); 193 gridBagConstraints.gridx = 0; 194 gridBagConstraints.gridy = 15; 195 gridBagConstraints.gridwidth = 2; 196 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 197 gridBagConstraints.insets = new java.awt.Insets (3, 5, 3, 3); 198 getContentPane().add(jLabelHeight, gridBagConstraints); 199 200 jNumberFieldHeight.setColumns(4); 201 jNumberFieldHeight.setHorizontalAlignment(javax.swing.JTextField.RIGHT); 202 try { 203 jNumberFieldHeight.setDecimals(0); 204 } catch (java.beans.PropertyVetoException e1) { 205 e1.printStackTrace(); 206 } 207 jNumberFieldHeight.setMinimumSize(new java.awt.Dimension (40, 21)); 208 jNumberFieldHeight.setPreferredSize(new java.awt.Dimension (38, 21)); 209 gridBagConstraints = new java.awt.GridBagConstraints (); 210 gridBagConstraints.gridx = 2; 211 gridBagConstraints.gridy = 15; 212 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 213 gridBagConstraints.insets = new java.awt.Insets (3, 3, 6, 3); 214 getContentPane().add(jNumberFieldHeight, gridBagConstraints); 215 216 jPanelBorder.setLayout(new java.awt.GridBagLayout ()); 217 218 gridBagConstraints = new java.awt.GridBagConstraints (); 219 gridBagConstraints.gridx = 0; 220 gridBagConstraints.gridy = 20; 221 gridBagConstraints.gridwidth = 4; 222 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 223 gridBagConstraints.weightx = 1.0; 224 gridBagConstraints.weighty = 1.0; 225 getContentPane().add(jPanelBorder, gridBagConstraints); 226 227 jPanel2.setLayout(new java.awt.GridBagLayout ()); 228 229 jLabelWidth1.setText("Cell background color"); 230 gridBagConstraints = new java.awt.GridBagConstraints (); 231 gridBagConstraints.gridx = 0; 232 gridBagConstraints.gridy = 0; 233 gridBagConstraints.insets = new java.awt.Insets (3, 14, 3, 3); 234 jPanel2.add(jLabelWidth1, gridBagConstraints); 235 236 jButtonBackground.setBackground(new java.awt.Color (0, 0, 0)); 237 jButtonBackground.setMaximumSize(new java.awt.Dimension (45, 20)); 238 jButtonBackground.setMinimumSize(new java.awt.Dimension (45, 20)); 239 jButtonBackground.setPreferredSize(new java.awt.Dimension (45, 20)); 240 jButtonBackground.addActionListener(new java.awt.event.ActionListener () { 241 public void actionPerformed(java.awt.event.ActionEvent evt) { 242 jButtonBackgroundActionPerformed(evt); 243 } 244 }); 245 246 gridBagConstraints = new java.awt.GridBagConstraints (); 247 gridBagConstraints.gridx = 1; 248 gridBagConstraints.gridy = 0; 249 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 250 gridBagConstraints.weightx = 1.0; 251 jPanel2.add(jButtonBackground, gridBagConstraints); 252 253 gridBagConstraints = new java.awt.GridBagConstraints (); 254 gridBagConstraints.gridx = 3; 255 gridBagConstraints.gridy = 15; 256 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 257 gridBagConstraints.weightx = 1.0; 258 getContentPane().add(jPanel2, gridBagConstraints); 259 260 jPanel1.setLayout(new java.awt.GridBagLayout ()); 261 262 jPanel1.setMinimumSize(new java.awt.Dimension (126, 40)); 263 jPanel1.setPreferredSize(new java.awt.Dimension (126, 40)); 264 gridBagConstraints = new java.awt.GridBagConstraints (); 265 gridBagConstraints.gridx = 0; 266 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 267 gridBagConstraints.weightx = 1.0; 268 gridBagConstraints.weighty = 1.0; 269 jPanel1.add(jPanel4, gridBagConstraints); 270 271 jButtonOK.setMnemonic('o'); 272 jButtonOK.setText("OK"); 273 jButtonOK.addActionListener(new java.awt.event.ActionListener () { 274 public void actionPerformed(java.awt.event.ActionEvent evt) { 275 jButtonOKActionPerformed(evt); 276 } 277 }); 278 279 gridBagConstraints = new java.awt.GridBagConstraints (); 280 gridBagConstraints.gridx = 1; 281 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST; 282 jPanel1.add(jButtonOK, gridBagConstraints); 283 284 jButtonCancel.setMnemonic('c'); 285 jButtonCancel.setText("Cancel"); 286 jButtonCancel.addActionListener(new java.awt.event.ActionListener () { 287 public void actionPerformed(java.awt.event.ActionEvent evt) { 288 jButtonCancelActionPerformed(evt); 289 } 290 }); 291 292 gridBagConstraints = new java.awt.GridBagConstraints (); 293 gridBagConstraints.gridx = 2; 294 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST; 295 gridBagConstraints.insets = new java.awt.Insets (0, 3, 0, 3); 296 jPanel1.add(jButtonCancel, gridBagConstraints); 297 298 gridBagConstraints = new java.awt.GridBagConstraints (); 299 gridBagConstraints.gridx = 0; 300 gridBagConstraints.gridy = 99; 301 gridBagConstraints.gridwidth = 4; 302 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 303 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST; 304 gridBagConstraints.weightx = 1.0; 305 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 306 getContentPane().add(jPanel1, gridBagConstraints); 307 308 jLabel1.setText("Cell name"); 309 jLabel1.setMaximumSize(new java.awt.Dimension (34, 23)); 310 jLabel1.setMinimumSize(new java.awt.Dimension (34, 23)); 311 jLabel1.setPreferredSize(new java.awt.Dimension (34, 23)); 312 gridBagConstraints = new java.awt.GridBagConstraints (); 313 gridBagConstraints.gridx = 0; 314 gridBagConstraints.gridy = 1; 315 gridBagConstraints.gridwidth = 4; 316 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 317 gridBagConstraints.insets = new java.awt.Insets (4, 4, 4, 4); 318 getContentPane().add(jLabel1, gridBagConstraints); 319 320 jSeparator1.setMinimumSize(new java.awt.Dimension (0, 2)); 321 gridBagConstraints = new java.awt.GridBagConstraints (); 322 gridBagConstraints.gridx = 0; 323 gridBagConstraints.gridy = 3; 324 gridBagConstraints.gridwidth = 4; 325 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 326 gridBagConstraints.insets = new java.awt.Insets (0, 0, 4, 0); 327 getContentPane().add(jSeparator1, gridBagConstraints); 328 329 jCheckBoxTransparent.setText("Transparent"); 330 jCheckBoxTransparent.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 331 jCheckBoxTransparent.setMargin(new java.awt.Insets (0, 0, 0, 0)); 332 gridBagConstraints = new java.awt.GridBagConstraints (); 333 gridBagConstraints.gridy = 10; 334 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 335 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 336 gridBagConstraints.weightx = 1.0; 337 gridBagConstraints.insets = new java.awt.Insets (0, 14, 0, 0); 338 getContentPane().add(jCheckBoxTransparent, gridBagConstraints); 339 340 jLabelStyle.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); 341 jLabelStyle.setText("Cell style"); 342 gridBagConstraints = new java.awt.GridBagConstraints (); 343 gridBagConstraints.gridx = 0; 344 gridBagConstraints.gridy = 40; 345 gridBagConstraints.gridwidth = 2; 346 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 347 gridBagConstraints.insets = new java.awt.Insets (3, 5, 3, 3); 348 getContentPane().add(jLabelStyle, gridBagConstraints); 349 350 jComboBoxstyles.setModel(new javax.swing.DefaultComboBoxModel (new String [] { "Item 1", "Item 2", "Item 3", "Item 4" })); 351 jComboBoxstyles.setPreferredSize(new java.awt.Dimension (200, 22)); 352 gridBagConstraints = new java.awt.GridBagConstraints (); 353 gridBagConstraints.gridx = 2; 354 gridBagConstraints.gridy = 40; 355 gridBagConstraints.gridwidth = 4; 356 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 357 gridBagConstraints.weightx = 1.0; 358 getContentPane().add(jComboBoxstyles, gridBagConstraints); 359 360 pack(); 361 java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); 362 java.awt.Dimension dialogSize = getSize(); 363 setLocation((screenSize.width-dialogSize.width)/2,(screenSize.height-dialogSize.height)/2); 364 } 366 private void jButtonBackgroundActionPerformed(java.awt.event.ActionEvent evt) { 368 bgcolor = javax.swing.JColorChooser.showDialog( null, "Select background color...", 369 this.jButtonBackground.getBackground()); 370 371 if (bgcolor != null) 372 { 373 this.jButtonBackground.setBackground( bgcolor ); 374 } 375 else 376 { 377 bgcolor = this.jButtonBackground.getBackground(); 378 } 379 380 } private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) { 383 setVisible(false); 384 this.setDialogResult(javax.swing.JOptionPane.CANCEL_OPTION); 385 dispose(); 386 } 388 private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) { 390 391 tmpCell = new CrosstabCell(); 392 tmpCell.setBox( boxPanel.getBox() ); 393 tmpCell.setWidth( (int)this.jNumberFieldWidth.getValue()); 394 tmpCell.setHeight( (int)this.jNumberFieldHeight.getValue()); 395 tmpCell.setBackcolor( bgcolor ); 396 tmpCell.setMode( (jCheckBoxTransparent.isSelected()) ? "Transparent" : "Opaque" ); 397 if (jComboBoxstyles.getSelectedIndex() > 0) 398 { 399 tmpCell.setStyle( (Style)jComboBoxstyles.getSelectedItem() ); 400 } 401 402 setVisible(false); 403 this.setDialogResult(javax.swing.JOptionPane.OK_OPTION); 404 dispose(); 405 } 407 411 private void closeDialog(java.awt.event.WindowEvent evt) { 413 setVisible(false); 414 this.setDialogResult(javax.swing.JOptionPane.CLOSED_OPTION); 415 dispose(); 416 } 418 419 424 public int getDialogResult() 425 { 426 427 return dialogResult; 428 } 429 430 435 public void setDialogResult(int dialogResult) 436 { 437 this.dialogResult = dialogResult; 438 } 439 440 441 private javax.swing.JButton jButtonBackground; 443 private javax.swing.JButton jButtonCancel; 444 private javax.swing.JButton jButtonOK; 445 private javax.swing.JCheckBox jCheckBoxTransparent; 446 private javax.swing.JComboBox jComboBoxstyles; 447 private javax.swing.JLabel jLabel1; 448 private javax.swing.JLabel jLabelHeight; 449 private javax.swing.JLabel jLabelStyle; 450 private javax.swing.JLabel jLabelWidth; 451 private javax.swing.JLabel jLabelWidth1; 452 private it.businesslogic.ireport.gui.JNumberField jNumberFieldHeight; 453 private it.businesslogic.ireport.gui.JNumberField jNumberFieldWidth; 454 private javax.swing.JPanel jPanel1; 455 private javax.swing.JPanel jPanel2; 456 private javax.swing.JPanel jPanel4; 457 private javax.swing.JPanel jPanelBorder; 458 private javax.swing.JSeparator jSeparator1; 459 private int dialogResult; 461 462 public CrosstabCell getTmpCell() { 463 return tmpCell; 464 } 465 466 public void setTmpCell(CrosstabCell selectedCell) { 467 468 469 this.jComboBoxstyles.removeAllItems(); 470 471 this.jComboBoxstyles.addItem(""); 472 Vector styles = MainFrame.getMainInstance().getActiveReportFrame().getReport().getStyles(); 473 for (int i=0; i < styles.size(); ++i) 474 { 475 jComboBoxstyles.addItem( styles.elementAt(i)); 476 } 477 478 this.setBgcolor( selectedCell.getBackcolor()); 479 if (bgcolor != null) this.jButtonBackground.setBackground( bgcolor ); 480 else this.jButtonBackground.setBackground( Color.WHITE ); 481 482 this.jLabel1.setText( selectedCell.getName() ); 483 484 this.boxPanel.setBox( selectedCell.getBox().cloneMe()); 485 486 this.jCheckBoxTransparent.setSelected( selectedCell.getMode().equals("Transparent")); 487 488 if (selectedCell.getTopIndex() < selectedCell.getBottomIndex() - 1) 490 { 491 this.jNumberFieldHeight.setEditable( false ); 492 } 493 494 if (selectedCell.getLeftIndex() < selectedCell.getRightIndex() - 1) 496 { 497 this.jNumberFieldWidth.setEditable( false ); 498 } 499 500 try { 501 this.jNumberFieldWidth.setValue( selectedCell.getWidth()); 502 this.jNumberFieldHeight.setValue( selectedCell.getHeight()); 503 } catch (Exception ex) 504 { 505 506 } 507 508 if (selectedCell.getStyle() != null) 509 { 510 jComboBoxstyles.setSelectedItem(selectedCell.getStyle()); 511 } 512 else jComboBoxstyles.setSelectedIndex(0); 513 514 } 515 516 public BoxPanel getBoxPanel() { 517 return boxPanel; 518 } 519 520 public void setBoxPanel(BoxPanel boxPanel) { 521 this.boxPanel = boxPanel; 522 } 523 524 public java.awt.Color getBgcolor() { 525 return bgcolor; 526 } 527 528 public void setBgcolor(java.awt.Color bgcolor) { 529 this.bgcolor = bgcolor; 530 } 531 532 public void applyI18n(){ 533 jCheckBoxTransparent.setText(I18n.getString("crosstabCellDialog.checkBoxTransparent","Transparent")); 535 jButtonCancel.setText(I18n.getString("crosstabCellDialog.buttonCancel","Cancel")); 538 jButtonOK.setText(I18n.getString("crosstabCellDialog.buttonOK","OK")); 539 jLabel1.setText(I18n.getString("crosstabCellDialog.label1","Cell name")); 540 jLabelHeight.setText(I18n.getString("crosstabCellDialog.labelHeight","Row height")); 541 jLabelStyle.setText(I18n.getString("crosstabCellDialog.labelStyle","Cell style")); 542 jLabelWidth.setText(I18n.getString("crosstabCellDialog.labelWidth","Column width")); 543 jLabelWidth1.setText(I18n.getString("crosstabCellDialog.labelWidth1","Cell background color")); 544 } 546 } 547 | Popular Tags |