KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > openide > util > AWTBridge


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.openide.util;
21
22 import java.awt.Component JavaDoc;
23 import javax.swing.Action JavaDoc;
24 import javax.swing.JButton JavaDoc;
25 import javax.swing.JMenuItem JavaDoc;
26 import javax.swing.JPopupMenu JavaDoc;
27 import org.openide.util.Lookup;
28
29 /** Provider of action presentations. Based on type of the action
30  * should be able to derive its menu, popup menu and toolbar
31  * presenter.
32  * <P>
33  * In order to provide greater flexibility is made as a pluggable component
34  * to allow more enhanced parts of the system to provide more enhanced
35  * visualitions.
36  */

37 public abstract class AWTBridge extends Object JavaDoc {
38     /** Finds out the global implementtion of the object
39      * @return the presenter
40      */

41     public static AWTBridge getDefault () {
42         AWTBridge ap = Lookup.getDefault().lookup(AWTBridge.class);
43         return ap == null ? new Default () : ap;
44     }
45     
46     /** Creates a default empty implementation of popup menu.
47      * @return popup menu
48      */

49     public abstract JPopupMenu JavaDoc createEmptyPopup();
50     
51     /** Creates a menu item that can present this action in a {@link javax.swing.JMenu}.
52      * @param action the action to represent
53      * @return the representation for this action
54      */

55     public abstract JMenuItem JavaDoc createMenuPresenter (Action JavaDoc action);
56     
57     /** Get a menu item that can present this action in a {@link javax.swing.JPopupMenu}.
58      * @param action the action to represent
59     * @return the representation for this action
60     */

61     public abstract JMenuItem JavaDoc createPopupPresenter (Action JavaDoc action);
62     
63     /** Get a component that can present this action in a {@link javax.swing.JToolBar}.
64      * @param action the action to represent
65     * @return the representation for this action
66     */

67     public abstract Component JavaDoc createToolbarPresenter (Action JavaDoc action);
68     
69     
70     public abstract Component JavaDoc[] convertComponents(Component JavaDoc comp);
71     
72     //
73
// Default implementation of the the presenter
74
//
75

76     private static final class Default extends AWTBridge {
77         
78         public JMenuItem JavaDoc createMenuPresenter(Action JavaDoc action) {
79             return new JMenuItem JavaDoc(action);
80         }
81         
82         public JMenuItem JavaDoc createPopupPresenter(Action JavaDoc action) {
83             return new JMenuItem JavaDoc(action);
84         }
85         
86         public Component JavaDoc createToolbarPresenter(Action JavaDoc action) {
87             return new JButton JavaDoc(action);
88         }
89         
90         public JPopupMenu JavaDoc createEmptyPopup() {
91             return new JPopupMenu JavaDoc();
92         }
93         
94         public Component JavaDoc[] convertComponents(Component JavaDoc comp) {
95             return new Component JavaDoc[] {comp};
96         }
97     }
98 }
99
Popular Tags