KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > antlr > works > project > ProjectToolbar


1 package org.antlr.works.project;
2
3 import org.antlr.works.components.project.CContainerProject;
4
5 import javax.swing.*;
6 import java.awt.*;
7 import java.awt.event.ActionEvent JavaDoc;
8 import java.awt.event.ActionListener JavaDoc;
9 /*
10
11 [The "BSD licence"]
12 Copyright (c) 2005-2006 Jean Bovet
13 All rights reserved.
14
15 Redistribution and use in source and binary forms, with or without
16 modification, are permitted provided that the following conditions
17 are met:
18
19 1. Redistributions of source code must retain the above copyright
20 notice, this list of conditions and the following disclaimer.
21 2. Redistributions in binary form must reproduce the above copyright
22 notice, this list of conditions and the following disclaimer in the
23 documentation and/or other materials provided with the distribution.
24 3. The name of the author may not be used to endorse or promote products
25 derived from this software without specific prior written permission.
26
27 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
28 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
29 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
31 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
32 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
36 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
38 */

39
40 public class ProjectToolbar {
41
42     public static final int CUSTOM_TOOLBAR_INDEX = 1;
43
44     public Box toolbar;
45
46     public JButton clean;
47     public JButton buildFile;
48     public JButton buildAll;
49     public JButton run;
50
51     public JPanel customToolbar;
52
53     public CContainerProject project;
54
55     public ProjectToolbar(CContainerProject project) {
56         this.project = project;
57
58         createInterface();
59         addActions();
60     }
61
62     public JComponent getToolbar() {
63         return toolbar;
64     }
65
66     public void createInterface() {
67         customToolbar = new JPanel();
68
69         toolbar = Box.createHorizontalBox();
70         toolbar.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.gray));
71         toolbar.add(Box.createHorizontalStrut(5));
72         toolbar.add(customToolbar);
73         toolbar.add(Box.createHorizontalGlue());
74         toolbar.add(clean = (JButton)createNewButton("Clean", "Clean Project Directory"));
75         toolbar.add(buildFile = (JButton)createNewButton("Build File", "Build Current File"));
76         toolbar.add(buildAll = (JButton)createNewButton("Build All", "Build Project"));
77         toolbar.add(run = (JButton)createNewButton("Run", "Run Project"));
78     }
79
80     public void setCustomToolbar(JComponent tb) {
81         if(tb != null) {
82             if(tb.getBorder() != null)
83                 tb.setBorder(null);
84
85             toolbar.remove(CUSTOM_TOOLBAR_INDEX);
86             toolbar.add(tb, CUSTOM_TOOLBAR_INDEX);
87         } else {
88             toolbar.remove(CUSTOM_TOOLBAR_INDEX);
89             toolbar.add(customToolbar, CUSTOM_TOOLBAR_INDEX);
90         }
91
92         toolbar.revalidate();
93         toolbar.repaint();
94     }
95
96     public void addActions() {
97         clean.addActionListener(new ActionListener JavaDoc() {
98             public void actionPerformed(ActionEvent JavaDoc e) {
99                 project.clean();
100             }
101         });
102
103         buildFile.addActionListener(new ActionListener JavaDoc() {
104             public void actionPerformed(ActionEvent JavaDoc e) {
105                 project.buildFile();
106             }
107         });
108
109         buildAll.addActionListener(new ActionListener JavaDoc() {
110             public void actionPerformed(ActionEvent JavaDoc e) {
111                 project.buildAll();
112             }
113         });
114
115         run.addActionListener(new ActionListener JavaDoc() {
116             public void actionPerformed(ActionEvent JavaDoc e) {
117                 project.run();
118             }
119         });
120
121     }
122
123     public AbstractButton createNewButton(String JavaDoc title, String JavaDoc tooltip) {
124         AbstractButton button;
125         button = new JButton(title);
126         button.setToolTipText(tooltip);
127         button.setFocusable(false);
128         return button;
129     }
130
131     public AbstractButton createNewButton(ImageIcon icon, String JavaDoc tooltip, boolean toggle) {
132         AbstractButton button;
133         if(toggle)
134             button = new JToggleButton(icon);
135         else
136             button = new JButton(icon);
137         button.setToolTipText(tooltip);
138         Dimension d = new Dimension(32, 32);
139         button.setMinimumSize(d);
140         button.setMaximumSize(d);
141         button.setPreferredSize(d);
142         button.setFocusable(false);
143         return button;
144     }
145
146 }
147
Popular Tags