KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > apps > ConfirmPanel


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.apps;
15
16 import java.awt.BorderLayout JavaDoc;
17 import java.awt.Component JavaDoc;
18 import java.awt.FlowLayout JavaDoc;
19 import java.awt.Insets JavaDoc;
20 import java.awt.event.ActionEvent JavaDoc;
21 import java.awt.event.ActionListener JavaDoc;
22 import java.awt.event.KeyEvent JavaDoc;
23
24 import javax.swing.AbstractAction JavaDoc;
25 import javax.swing.Action JavaDoc;
26 import javax.swing.Icon JavaDoc;
27 import javax.swing.JButton JavaDoc;
28 import javax.swing.KeyStroke JavaDoc;
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 /**
36  * Application Confirm Panel.
37  * <code>
38  * if (e.getActionCommand().equals(ConfirmPanel.A_OK))
39  * </code>
40  * @author Jorg Janke
41  * @version $Id: ConfirmPanel.java,v 1.17 2003/10/27 15:22:03 jjanke Exp $
42  */

43 public final class ConfirmPanel extends CPanel
44 {
45     /**
46      * Create Confirmation Panel with OK Button
47      */

48     public ConfirmPanel()
49     {
50         this (false, false, false, false, false, false, true);
51     } // ConfirmPanel
52

53     /**
54      * Create Confirmation Panel with OK and Cancel Button
55      * @param withCancelButton with cancel
56      */

57     public ConfirmPanel(boolean withCancelButton)
58     {
59         this (withCancelButton, false, false, false, false, false, true);
60     } // ConfirmPanel
61

62     /**
63      * Create Confirmation Panel with different buttons
64      * @param withCancelButton with cancel
65      * @param withRefreshButton with refresh
66      * @param withResetButton with reset
67      * @param withCustomizeButton with customize
68      * @param withHistoryButton with history
69      * @param withZoomButton with zoom
70      * @param withText with text
71      */

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 JavaDoc mainLayout = new BorderLayout JavaDoc();
82         this.setLayout(mainLayout);
83         this.setName("confirmPanel");
84         //
85
CPanel okCancel = new CPanel(new FlowLayout JavaDoc(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         //
94
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     } // ConfirmPanel
120

121     /** Additional Buttons Panel */
122     private CPanel m_addlButtons = null;
123
124     private CButton bOK;
125     private CButton bCancel;
126     //
127
private CButton bRefresh;
128     private CButton bReset;
129     private CButton bCustomize;
130     private CButton bHistory;
131     private CButton bZoom;
132
133     /**
134      * Add Button to left side of confirmPanel
135      * @param button button
136      */

137     public void addComponent (Component JavaDoc button)
138     {
139         if (m_addlButtons == null)
140         {
141             m_addlButtons = new CPanel(new FlowLayout JavaDoc(FlowLayout.LEFT));
142             this.add(m_addlButtons, BorderLayout.WEST);
143         }
144         m_addlButtons.add(button);
145     } // addButton
146

147     /**
148      * Add Button to left side of confirmPanel
149      * @param action action command
150      * @param toolTipText tool tip text
151      * @param icon icon
152      * @param mnemonic mnemonic
153      * @return JButton
154      */

155     public JButton JavaDoc addButton (String JavaDoc action, String JavaDoc toolTipText, Icon JavaDoc icon, int mnemonic)
156     {
157         JButton JavaDoc b = new DialogButton (action, toolTipText, icon, mnemonic);
158         addComponent (b);
159         return b;
160     } // addButton
161

162     /**
163      * Add Button to left side of confirmPanel
164      * @param button button
165      * @return JButton
166      */

167     public JButton JavaDoc addButton (JButton JavaDoc button)
168     {
169         addComponent (button);
170         return button;
171     } // addButton
172

173     /*************************************************************************/
174
175     /** Action String OK */
176     public static final String JavaDoc A_OK = "OK";
177     /** Action String Cancel */
178     public static final String JavaDoc A_CANCEL = "Cancel";
179     /** Action String Refresh */
180     public static final String JavaDoc A_REFRESH = "Refresh";
181     /** Action String Reset */
182     public static final String JavaDoc A_RESET = "Reset";
183     /** Action String Customize */
184     public static final String JavaDoc A_CUSTOMIZE = "Customize";
185     /** Action String History */
186     public static final String JavaDoc A_HISTORY = "History";
187     /** Action String Zoom */
188     public static final String JavaDoc A_ZOOM = "Zoom";
189
190     /** Action String Process */
191     public static final String JavaDoc A_PROCESS = "Process";
192     /** Action String Print */
193     public static final String JavaDoc A_PRINT = "Print";
194     /** Action String Export */
195     public static final String JavaDoc A_EXPORT = "Export";
196     /** Action String Help */
197     public static final String JavaDoc A_HELP = "Help";
198     /** Action String Delete */
199     public static final String JavaDoc A_DELETE = "Delete";
200     /** Action String PAttribute */
201     public static final String JavaDoc A_PATTRIBUTE = "PAttribute";
202
203     /** Standard Insets used */
204     public static Insets JavaDoc s_insets = new Insets JavaDoc (0, 10, 0, 10);
205
206     /**
207      * Create OK Button with label text
208      * @param text text
209      * @return OK Button
210      */

211     public static final CButton createOKButton (String JavaDoc 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     } // createOKButton
217

218     /**
219      * Create OK Button with Standard text
220      * @param withText with text
221      * @return OK Button
222      */

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     } // createOKButton
229

230     /**
231      * Get OK Button
232      * @return OK Button
233      */

234     public CButton getOKButton()
235     {
236         return bOK;
237     } // getOKButton
238

239
240     /**
241      * Create Cancel Button wlth label text and register ESC and Alt-X as KeyStroke
242      * @param text text
243      * @return Cancel Button
244      */

245     public static final CButton createCancelButton (String JavaDoc text)
246     {
247         CButton cancel = new DialogButton (A_CANCEL, text, Env.getImageIcon("Cancel24.gif"), KeyEvent.VK_X);
248         // ESC = Ignore
249
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     } // createCancelButton
253

254     /**
255      * Create Cancel Button wlth Standard text
256      * @param withText with text
257      * @return Button
258      */

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     } // createCancelButton
265

266     /**
267      * Get Cancel Button
268      * @return Cancel Button
269      */

270     public CButton getCancelButton()
271     {
272         return bCancel;
273     } // getCancelButton
274

275
276     /**
277      * Show OK button
278      * @param value true for visible
279      */

280     public void setOKVisible (boolean value)
281     {
282         bOK.setVisible(value);
283         bOK.setEnabled(value);
284     } // setOKVisible
285

286     /**
287      * Is OK Visible
288      * @return true of OK visisble
289      */

290     public boolean isOKVisible()
291     {
292         return bOK.isVisible();
293     } // isOKVisible
294

295     /**
296      * Show Cancel button
297      * @param value trie for visible
298      */

299     public void setCancelVisible (boolean value)
300     {
301         bCancel.setVisible(value);
302         bCancel.setEnabled(value);
303     } // setCancelVisible
304

305     /**
306      * Is Cancel Visible
307      * @return true if Canvel is visible
308      */

309     public boolean isCancelVisible()
310     {
311         return bCancel.isVisible();
312     } // isCancelVisible
313

314     /*************************************************************************/
315
316     /**
317      * Create Refresh Button wlth label text
318      * @param text text
319      * @return button
320      */

321     public static final CButton createRefreshButton (String JavaDoc text)
322     {
323         CButton refresh = new DialogButton (A_REFRESH, text, Env.getImageIcon("Refresh24.gif"), 0);
324         // F5 = Refresh
325
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     } // createRefreshButton
329

330     /**
331      * Create Refresh Button wlth Standard text
332      * @param withText with text
333      * @return Button
334      */

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     } // createRefreshButton
341

342     /**
343      * Get Refresh Button
344      * @return Button
345      */

346     public CButton getRefreshButton()
347     {
348         return bRefresh;
349     } // getRefreshButton
350

351     /*************************************************************************/
352
353     /**
354      * Create Reset Button wlth label text
355      * @param text text
356      * @return button
357      */

358     public static final CButton createResetButton (String JavaDoc text)
359     {
360         return new DialogButton (A_RESET, text, Env.getImageIcon("Reset24.gif"), 0);
361     } // createResetButton
362

363     /**
364      * Create Reset Button wlth Standard text
365      * @param withText with text
366      * @return Button
367      */

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     } // createRefreshButton
374

375     /**
376      * Get Reset Button
377      * @return Button
378      */

379     public CButton getResetButton()
380     {
381         return bReset;
382     } // getResetButton
383

384     /*************************************************************************/
385
386     /**
387      * Create Customize Button wlth label text
388      * @param text text
389      * @return button
390      */

391     public static final CButton createCustomizeButton (String JavaDoc text)
392     {
393         return new DialogButton (A_CUSTOMIZE, text, Env.getImageIcon("Preference24.gif"), 0);
394     } // createCustomizeButton
395

396     /**
397      * Create Customize Button wlth Standard text
398      * @param withText with text
399      * @return Button
400      */

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     } // createCustomizeButton
407

408     /**
409      * Get Customize Button
410      * @return Button
411      */

412     public CButton getCustomizeButton()
413     {
414         return bCustomize;
415     } // getCustomizeButton
416

417     /*************************************************************************/
418
419     /**
420      * Create History Button wlth label text
421      * @param text text
422      * @return button
423      */

424     public static final CButton createHistoryButton (String JavaDoc text)
425     {
426         CButton history = new DialogButton (A_HISTORY, text, Env.getImageIcon("HistoryX24.gif"), 0);
427         // F9 = History
428
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     } // createHistoryButton
432

433     /**
434      * Create History Button wlth Standard text
435      * @param withText with text
436      * @return Button
437      */

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     } // createHistoryButton
444

445     /**
446      * Get History Button
447      * @return Button
448      */

449     public CButton getHistoryButton()
450     {
451         return bHistory;
452     } // getHistoryButton
453

454     /*************************************************************************/
455
456     /**
457      * Create Zoom Button wlth label text
458      * @param text text
459      * @return button
460      */

461     public static final CButton createZoomButton (String JavaDoc text)
462     {
463         return new DialogButton (A_ZOOM, text, Env.getImageIcon("Zoom24.gif"), KeyEvent.VK_Z);
464     } // createZoomButton
465

466     /**
467      * Create Zoom Button wlth Standard text
468      * @param withText with text
469      * @return Button
470      */

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     } // createZoomButton
477

478     /**
479      * Get Zoom Button
480      * @return Button
481      */

482     public CButton getZoomButton()
483     {
484         return bZoom;
485     } // getZoomyButton
486

487     /*************************************************************************/
488
489     /**
490      * Create Process Button wlth label text
491      * @param text text
492      * @return button
493      */

494     public static final CButton createProcessButton (String JavaDoc text)
495     {
496         return new DialogButton (A_PROCESS, text, Env.getImageIcon("Process24.gif"), 0);
497     } // createProcessButton
498

499     /**
500      * Create Process Button wlth Standard text
501      * @param withText with text
502      * @return Button
503      */

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     } // createProcessButton
510

511     /**
512      * Create Print Button wlth label text
513      * @param text text
514      * @return button
515      */

516     public static final CButton createPrintButton (String JavaDoc text)
517     {
518         return new DialogButton (A_PRINT, text, Env.getImageIcon("Print24.gif"), KeyEvent.VK_P);
519     } // createPrintButton
520

521     /**
522      * Create Print Button wlth Standard text
523      * @param withText with text
524      * @return Button
525      */

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     } // createPrintButton
532

533     /**
534      * Create Help Button wlth label text
535      * @param text text
536      * @return Button
537      */

538     public static final CButton createHelpButton (String JavaDoc text)
539     {
540         CButton help = new DialogButton (A_HELP, text, Env.getImageIcon("Help24.gif"), KeyEvent.VK_H);
541         // F1 = Help
542
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     } // createHelpButton
546

547     /**
548      * Create Help Button wlth Standard text
549      * @param withText with text
550      * @return Button
551      */

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     } // createHelpButton
558

559     /**
560      * Create Export Button wlth label text
561      * @param text text
562      * @return Button
563      */

564     public static final CButton createExportButton (String JavaDoc text)
565     {
566         return new DialogButton (A_EXPORT, text, Env.getImageIcon("Export24.gif"), 0);
567     } // createExportButton
568

569     /**
570      * Create Export Button wlth Standard text
571      * @param withText with text
572      * @return Button
573      */

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     } // createExportButton
580

581     /**
582      * Create Delete Button with label text
583      * @param text text
584      * @return Delete Button
585      */

586     public static final CButton createDeleteButton (String JavaDoc text)
587     {
588         CButton dButton = new DialogButton (A_DELETE, text, Env.getImageIcon("Delete24.gif"), KeyEvent.VK_O);
589         return dButton;
590     } // createDeleteButton
591

592     /**
593      * Create Delete Button with Standard text
594      * @param withText with text
595      * @return Delete Button
596      */

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     } // createDeleteButton
603

604     /**
605      * Create Product Attribute Button with Standard text
606      * @param withText with text
607      * @return Product Attribute Button
608      */

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     } // createPAttributeButton
615

616     /**
617      * Create Product Attribute Button with label text
618      * @param text text
619      * @return Product Attribute Button
620      */

621     public static final CButton createPAttributeButton (String JavaDoc text)
622     {
623         CButton button = new DialogButton (A_PATTRIBUTE, text, Env.getImageIcon("PAttribute24.gif"), 0);
624         return button;
625     } // createPAttributeButton
626

627     /*************************************************************************/
628
629     /**
630      * Add Action Listener
631      * <code>
632      * if (e.getActionCommand().equals(ConfirmPanel.A_OK))
633      * </code>
634      * @param al listener
635      */

636     public void addActionListener(ActionListener JavaDoc al)
637     {
638         bOK.addActionListener(al);
639         bCancel.addActionListener(al);
640         //
641
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     } // addActionListener
650

651     /**
652      * Enable all components
653      * @param enabled trie if enabled
654      */

655     public void setEnabled (boolean enabled)
656     {
657         super.setEnabled(enabled);
658         bOK.setEnabled(enabled);
659         bCancel.setEnabled(enabled);
660         //
661
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     } // setEnabled
670

671     /*************************************************************************/
672
673     /**
674      * Dialog Button
675      */

676     public static class DialogButton extends CButton
677     {
678         /**
679          * Create Dialog Button
680          * @param action action command
681          * @param toolTipText toole tip text
682          * @param icon icon
683          * @param mnemonic mnemonic
684          */

685         public DialogButton (String JavaDoc action, String JavaDoc toolTipText, Icon JavaDoc icon, int mnemonic)
686         {
687             super (new DialogAction (action, toolTipText, icon, mnemonic));
688             super.setMargin(s_insets);
689             super.setDefaultCapable(false);
690         } // DialogButton
691

692         /**
693          * Add Action Listener
694          * @param al listener
695          */

696         public void addActionListener(ActionListener JavaDoc al)
697         {
698         // if delegate is set and action listener is set, target.actionPerformed is
699
// called twice. If only delegate is set, nothing happens.
700
// It seems that the button is not 'registered' with the Action.
701
// if (getAction() != null)
702
// ((DialogAction)getAction()).setDelegate(al);
703
super.addActionListener(al);
704         } // addActionListener
705
} // DialogButton
706

707     /**
708      * Dialog Button Action
709      */

710     public static class DialogAction extends AbstractAction JavaDoc
711     {
712         /**
713          * Create Dialog Action
714          * @param action action command
715          * @param toolTipText tool tip text
716          * @param icon icon
717          * @param mnemonic mnemonic
718          */

719         public DialogAction (String JavaDoc action, String JavaDoc toolTipText, Icon JavaDoc icon, int mnemonic)
720         {
721             super ();
722             // Attributes
723
// putValue(Action.NAME, text); // Display
724
putValue(Action.SMALL_ICON, icon);
725             putValue(Action.SHORT_DESCRIPTION, toolTipText); // Tooltip
726
putValue(Action.ACTION_COMMAND_KEY, action);
727             if (mnemonic != 0)
728                 putValue(Action.MNEMONIC_KEY, new Integer JavaDoc(mnemonic));
729         } // DialogAction
730

731         /** Target ActionListener */
732         private ActionListener JavaDoc m_delegate = null;
733
734         /**
735          * Set Action Listener for this Button
736          * @param al listener
737          */

738         public void setDelegate (ActionListener JavaDoc al)
739         {
740             m_delegate = al;
741         } // setDelegate
742

743         /**
744          * ActionListener - call Delegate
745          * @param e event
746          */

747         public void actionPerformed (ActionEvent JavaDoc e)
748         {
749         // System.out.println(">>> Action: actionPerformed");
750
if (m_delegate != null)
751                 m_delegate.actionPerformed(e);
752         } // actionPerformed
753
} // DialogAction
754

755 } // ConfirmPanel
756
Popular Tags