1 14 package org.compiere.apps; 15 16 import java.awt.BorderLayout ; 17 import java.awt.Component ; 18 import java.awt.FlowLayout ; 19 import java.awt.Insets ; 20 import java.awt.event.ActionEvent ; 21 import java.awt.event.ActionListener ; 22 import java.awt.event.KeyEvent ; 23 24 import javax.swing.AbstractAction ; 25 import javax.swing.Action ; 26 import javax.swing.Icon ; 27 import javax.swing.JButton ; 28 import javax.swing.KeyStroke ; 29 30 import org.compiere.swing.CButton; 31 import org.compiere.swing.CPanel; 32 import org.compiere.util.Env; 33 import org.compiere.util.Msg; 34 35 43 public final class ConfirmPanel extends CPanel 44 { 45 48 public ConfirmPanel() 49 { 50 this (false, false, false, false, false, false, true); 51 } 53 57 public ConfirmPanel(boolean withCancelButton) 58 { 59 this (withCancelButton, false, false, false, false, false, true); 60 } 62 72 public ConfirmPanel(boolean withCancelButton, 73 boolean withRefreshButton, 74 boolean withResetButton, 75 boolean withCustomizeButton, 76 boolean withHistoryButton, 77 boolean withZoomButton, 78 boolean withText) 79 { 80 super(); 81 BorderLayout mainLayout = new BorderLayout (); 82 this.setLayout(mainLayout); 83 this.setName("confirmPanel"); 84 CPanel okCancel = new CPanel(new FlowLayout (FlowLayout.RIGHT)); 86 okCancel.setOpaque(false); 87 bCancel = createCancelButton(withText); 88 okCancel.add(bCancel); 89 bOK = createOKButton(withText); 90 okCancel.add(bOK); 91 setCancelVisible(withCancelButton); 92 this.add(okCancel, BorderLayout.EAST); 93 if (withRefreshButton) 95 { 96 bRefresh = createRefreshButton(withText); 97 addComponent(bRefresh); 98 } 99 if (withResetButton) 100 { 101 bReset = createResetButton(withText); 102 addComponent(bReset); 103 } 104 if (withCustomizeButton) 105 { 106 bCustomize = createCustomizeButton(withText); 107 addComponent(bCustomize); 108 } 109 if (withHistoryButton) 110 { 111 bHistory = createHistoryButton(withText); 112 addComponent(bHistory); 113 } 114 if (withZoomButton) 115 { 116 bZoom = createZoomButton(withText); 117 addComponent(bZoom); 118 } 119 } 121 122 private CPanel m_addlButtons = null; 123 124 private CButton bOK; 125 private CButton bCancel; 126 private CButton bRefresh; 128 private CButton bReset; 129 private CButton bCustomize; 130 private CButton bHistory; 131 private CButton bZoom; 132 133 137 public void addComponent (Component button) 138 { 139 if (m_addlButtons == null) 140 { 141 m_addlButtons = new CPanel(new FlowLayout (FlowLayout.LEFT)); 142 this.add(m_addlButtons, BorderLayout.WEST); 143 } 144 m_addlButtons.add(button); 145 } 147 155 public JButton addButton (String action, String toolTipText, Icon icon, int mnemonic) 156 { 157 JButton b = new DialogButton (action, toolTipText, icon, mnemonic); 158 addComponent (b); 159 return b; 160 } 162 167 public JButton addButton (JButton button) 168 { 169 addComponent (button); 170 return button; 171 } 173 174 175 176 public static final String A_OK = "OK"; 177 178 public static final String A_CANCEL = "Cancel"; 179 180 public static final String A_REFRESH = "Refresh"; 181 182 public static final String A_RESET = "Reset"; 183 184 public static final String A_CUSTOMIZE = "Customize"; 185 186 public static final String A_HISTORY = "History"; 187 188 public static final String A_ZOOM = "Zoom"; 189 190 191 public static final String A_PROCESS = "Process"; 192 193 public static final String A_PRINT = "Print"; 194 195 public static final String A_EXPORT = "Export"; 196 197 public static final String A_HELP = "Help"; 198 199 public static final String A_DELETE = "Delete"; 200 201 public static final String A_PATTRIBUTE = "PAttribute"; 202 203 204 public static Insets s_insets = new Insets (0, 10, 0, 10); 205 206 211 public static final CButton createOKButton (String text) 212 { 213 CButton okButton = new DialogButton (A_OK, text, Env.getImageIcon("Ok24.gif"), KeyEvent.VK_O); 214 okButton.setDefaultCapable(true); 215 return okButton; 216 } 218 223 public static final CButton createOKButton (boolean withText) 224 { 225 if (withText) 226 return createOKButton(Msg.getMsg(Env.getCtx(), A_OK)); 227 return createOKButton(null); 228 } 230 234 public CButton getOKButton() 235 { 236 return bOK; 237 } 239 240 245 public static final CButton createCancelButton (String text) 246 { 247 CButton cancel = new DialogButton (A_CANCEL, text, Env.getImageIcon("Cancel24.gif"), KeyEvent.VK_X); 248 cancel.getInputMap(CButton.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), A_CANCEL); 250 cancel.getActionMap().put(A_CANCEL, cancel.getAction()); 251 return cancel; 252 } 254 259 public static final CButton createCancelButton(boolean withText) 260 { 261 if (withText) 262 return createCancelButton(Msg.getMsg(Env.getCtx(), A_CANCEL)); 263 return createCancelButton(null); 264 } 266 270 public CButton getCancelButton() 271 { 272 return bCancel; 273 } 275 276 280 public void setOKVisible (boolean value) 281 { 282 bOK.setVisible(value); 283 bOK.setEnabled(value); 284 } 286 290 public boolean isOKVisible() 291 { 292 return bOK.isVisible(); 293 } 295 299 public void setCancelVisible (boolean value) 300 { 301 bCancel.setVisible(value); 302 bCancel.setEnabled(value); 303 } 305 309 public boolean isCancelVisible() 310 { 311 return bCancel.isVisible(); 312 } 314 315 316 321 public static final CButton createRefreshButton (String text) 322 { 323 CButton refresh = new DialogButton (A_REFRESH, text, Env.getImageIcon("Refresh24.gif"), 0); 324 refresh.getInputMap(CButton.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0), A_REFRESH); 326 refresh.getActionMap().put(A_REFRESH, refresh.getAction()); 327 return refresh; 328 } 330 335 public static final CButton createRefreshButton (boolean withText) 336 { 337 if (withText) 338 return createRefreshButton(Msg.getMsg(Env.getCtx(), A_REFRESH)); 339 return createRefreshButton(null); 340 } 342 346 public CButton getRefreshButton() 347 { 348 return bRefresh; 349 } 351 352 353 358 public static final CButton createResetButton (String text) 359 { 360 return new DialogButton (A_RESET, text, Env.getImageIcon("Reset24.gif"), 0); 361 } 363 368 public static final CButton createResetButton (boolean withText) 369 { 370 if (withText) 371 return createResetButton(Msg.getMsg(Env.getCtx(), A_RESET)); 372 return createResetButton(null); 373 } 375 379 public CButton getResetButton() 380 { 381 return bReset; 382 } 384 385 386 391 public static final CButton createCustomizeButton (String text) 392 { 393 return new DialogButton (A_CUSTOMIZE, text, Env.getImageIcon("Preference24.gif"), 0); 394 } 396 401 public static final CButton createCustomizeButton (boolean withText) 402 { 403 if (withText) 404 return createCustomizeButton(Msg.getMsg(Env.getCtx(), A_CUSTOMIZE)); 405 return createCustomizeButton(null); 406 } 408 412 public CButton getCustomizeButton() 413 { 414 return bCustomize; 415 } 417 418 419 424 public static final CButton createHistoryButton (String text) 425 { 426 CButton history = new DialogButton (A_HISTORY, text, Env.getImageIcon("HistoryX24.gif"), 0); 427 history.getInputMap(CButton.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_F9, 0), A_HISTORY); 429 history.getActionMap().put(A_HISTORY, history.getAction()); 430 return history; 431 } 433 438 public static final CButton createHistoryButton (boolean withText) 439 { 440 if (withText) 441 return createHistoryButton(Msg.getMsg(Env.getCtx(), A_HISTORY)); 442 return createHistoryButton(null); 443 } 445 449 public CButton getHistoryButton() 450 { 451 return bHistory; 452 } 454 455 456 461 public static final CButton createZoomButton (String text) 462 { 463 return new DialogButton (A_ZOOM, text, Env.getImageIcon("Zoom24.gif"), KeyEvent.VK_Z); 464 } 466 471 public static final CButton createZoomButton (boolean withText) 472 { 473 if (withText) 474 return createZoomButton(Msg.getMsg(Env.getCtx(), A_ZOOM)); 475 return createZoomButton(null); 476 } 478 482 public CButton getZoomButton() 483 { 484 return bZoom; 485 } 487 488 489 494 public static final CButton createProcessButton (String text) 495 { 496 return new DialogButton (A_PROCESS, text, Env.getImageIcon("Process24.gif"), 0); 497 } 499 504 public static final CButton createProcessButton (boolean withText) 505 { 506 if (withText) 507 return createProcessButton(Msg.getMsg(Env.getCtx(), A_PROCESS)); 508 return createProcessButton(null); 509 } 511 516 public static final CButton createPrintButton (String text) 517 { 518 return new DialogButton (A_PRINT, text, Env.getImageIcon("Print24.gif"), KeyEvent.VK_P); 519 } 521 526 public static final CButton createPrintButton (boolean withText) 527 { 528 if (withText) 529 return createPrintButton(Msg.getMsg(Env.getCtx(), A_PRINT)); 530 return createPrintButton(null); 531 } 533 538 public static final CButton createHelpButton (String text) 539 { 540 CButton help = new DialogButton (A_HELP, text, Env.getImageIcon("Help24.gif"), KeyEvent.VK_H); 541 help.getInputMap(CButton.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0), A_HELP); 543 help.getActionMap().put(A_HELP, help.getAction()); 544 return help; 545 } 547 552 public static final CButton createHelpButton (boolean withText) 553 { 554 if (withText) 555 return createHelpButton(Msg.getMsg(Env.getCtx(), A_HELP)); 556 return createHelpButton(null); 557 } 559 564 public static final CButton createExportButton (String text) 565 { 566 return new DialogButton (A_EXPORT, text, Env.getImageIcon("Export24.gif"), 0); 567 } 569 574 public static final CButton createExportButton (boolean withText) 575 { 576 if (withText) 577 return createExportButton(Msg.getMsg(Env.getCtx(), A_EXPORT)); 578 return createExportButton(null); 579 } 581 586 public static final CButton createDeleteButton (String text) 587 { 588 CButton dButton = new DialogButton (A_DELETE, text, Env.getImageIcon("Delete24.gif"), KeyEvent.VK_O); 589 return dButton; 590 } 592 597 public static final CButton createDeleteButton (boolean withText) 598 { 599 if (withText) 600 return createDeleteButton(Msg.getMsg(Env.getCtx(), A_DELETE)); 601 return createDeleteButton(null); 602 } 604 609 public static final CButton createPAttributeButton (boolean withText) 610 { 611 if (withText) 612 return createPAttributeButton(Msg.getMsg(Env.getCtx(), A_PATTRIBUTE)); 613 return createPAttributeButton(null); 614 } 616 621 public static final CButton createPAttributeButton (String text) 622 { 623 CButton button = new DialogButton (A_PATTRIBUTE, text, Env.getImageIcon("PAttribute24.gif"), 0); 624 return button; 625 } 627 628 629 636 public void addActionListener(ActionListener al) 637 { 638 bOK.addActionListener(al); 639 bCancel.addActionListener(al); 640 if (bRefresh != null) 642 bRefresh.addActionListener(al); 643 if (bCustomize != null) 644 bCustomize.addActionListener(al); 645 if (bHistory != null) 646 bHistory.addActionListener(al); 647 if (bZoom != null) 648 bZoom.addActionListener(al); 649 } 651 655 public void setEnabled (boolean enabled) 656 { 657 super.setEnabled(enabled); 658 bOK.setEnabled(enabled); 659 bCancel.setEnabled(enabled); 660 if (bRefresh != null) 662 bRefresh.setEnabled(enabled); 663 if (bCustomize != null) 664 bCustomize.setEnabled(enabled); 665 if (bHistory != null) 666 bHistory.setEnabled(enabled); 667 if (bZoom != null) 668 bZoom.setEnabled(enabled); 669 } 671 672 673 676 public static class DialogButton extends CButton 677 { 678 685 public DialogButton (String action, String toolTipText, Icon icon, int mnemonic) 686 { 687 super (new DialogAction (action, toolTipText, icon, mnemonic)); 688 super.setMargin(s_insets); 689 super.setDefaultCapable(false); 690 } 692 696 public void addActionListener(ActionListener al) 697 { 698 super.addActionListener(al); 704 } } 707 710 public static class DialogAction extends AbstractAction 711 { 712 719 public DialogAction (String action, String toolTipText, Icon icon, int mnemonic) 720 { 721 super (); 722 putValue(Action.SMALL_ICON, icon); 725 putValue(Action.SHORT_DESCRIPTION, toolTipText); putValue(Action.ACTION_COMMAND_KEY, action); 727 if (mnemonic != 0) 728 putValue(Action.MNEMONIC_KEY, new Integer (mnemonic)); 729 } 731 732 private ActionListener m_delegate = null; 733 734 738 public void setDelegate (ActionListener al) 739 { 740 m_delegate = al; 741 } 743 747 public void actionPerformed (ActionEvent e) 748 { 749 if (m_delegate != null) 751 m_delegate.actionPerformed(e); 752 } } 755 } | Popular Tags |