KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > css > actions > CssStyleBuilderViewAction


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * CssStyleBuilderShowHideAction.java
22  *
23  * Created on February 01, 2005, 4:49 PM
24  */

25
26 package org.netbeans.modules.css.actions;
27
28 import org.netbeans.modules.css.visual.model.CssMetaModel;
29 import java.awt.Component JavaDoc;
30 import java.awt.Dimension JavaDoc;
31 import java.awt.event.ActionEvent JavaDoc;
32 import java.awt.event.ActionListener JavaDoc;
33 import javax.swing.ImageIcon JavaDoc;
34 import javax.swing.JPanel JavaDoc;
35 import javax.swing.JToggleButton JavaDoc;
36 import org.openide.nodes.Node;
37 import org.openide.util.HelpCtx;
38 import org.openide.util.NbBundle;
39 import org.openide.util.actions.CookieAction;
40
41 /**
42  * Action to present the list of CSS classes in the CSS editor toolbar
43  * @author Winston Prakash
44  * @version 1.0
45  */

46 public class CssStyleBuilderViewAction extends CookieAction {
47
48     /**
49      * Cookies required for this action to be activated.
50      */

51     private static final Class JavaDoc[] REQUIRED_COOKIES = new Class JavaDoc[] {
52
53     };
54
55
56     public HelpCtx getHelpCtx() {
57         return HelpCtx.DEFAULT_HELP;
58     }
59
60     /**
61      * Return the display name for the action.
62      */

63     public String JavaDoc getName() {
64         return NbBundle.getMessage(CssStyleBuilderViewAction.class, "STYLE_BUILDER_VIEW_ACTION");
65     }
66
67     /**
68      * The action accepts only one node with a java source on it.
69      */

70     protected int mode() {
71         return MODE_EXACTLY_ONE;
72     }
73
74     protected Class JavaDoc[] cookieClasses() {
75         return REQUIRED_COOKIES;
76     }
77
78     /**
79      * Perform the Action
80      */

81     protected void performAction(Node[] activatedNodes) {
82         // Do nothing toolbar presenter will take care of it
83
}
84
85     public Component JavaDoc getToolbarPresenter() {
86         Component JavaDoc viewToggle = new ToolbarPresenter();
87         return viewToggle;
88     }
89
90     private static class ToolbarPresenter extends JPanel JavaDoc{
91         private String JavaDoc imgName = "/org/netbeans/modules/css/resources/style_builder_view_toolbar.png";
92         private ImageIcon JavaDoc imgIcon = new ImageIcon JavaDoc(CssStyleBuilderViewAction.class.getResource(imgName));
93         private JToggleButton JavaDoc viewToggle = new JToggleButton JavaDoc(null,imgIcon);
94         private static final int FIXED_WIDTH = 30;
95
96         ToolbarPresenter() {
97             initComponents();
98         }
99
100         private void initComponents() {
101             viewToggle.setToolTipText(NbBundle.getMessage(CssStyleBuilderViewAction.class, "VIEW_STYLE_BUILDER_TOOLTIP"));
102             viewToggle.setSelected(true);
103             viewToggle.setFocusable(false);
104             viewToggle.setPreferredSize(new Dimension JavaDoc(25,20));
105             viewToggle.addActionListener(new ActionListener JavaDoc() {
106                 public void actionPerformed(ActionEvent JavaDoc evt) {
107                     CssMetaModel.getInstance().setStyleBuilderVisibility(viewToggle.isSelected());
108                 }
109             });
110             viewToggle.setRolloverEnabled(true);
111             add(viewToggle);
112         }
113
114         public java.awt.Dimension JavaDoc getMinimumSize() {
115             return new java.awt.Dimension JavaDoc(FIXED_WIDTH, getPreferredSize().height);
116         }
117
118         public java.awt.Dimension JavaDoc getMaximumSize() {
119             return new java.awt.Dimension JavaDoc(FIXED_WIDTH, getPreferredSize().height);
120         }
121     }
122 }
123
Popular Tags