KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > window > toolbars > ToolBar


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.window.toolbars;
20
21 import java.awt.*;
22 import java.util.*;
23
24 import javax.swing.*;
25
26 import org.openharmonise.him.actions.*;
27 import org.openharmonise.him.actions.file.*;
28 import org.openharmonise.him.actions.publish.*;
29 import org.openharmonise.him.actions.xslt.*;
30 import org.openharmonise.vfs.context.*;
31
32
33 /**
34  *
35  * @author Matthew Large
36  * @version $Revision: 1.1 $
37  *
38  */

39 public class ToolBar extends JToolBar implements ContextListener {
40     
41     private ArrayList m_aActions = new ArrayList();
42     
43     /**
44      *
45      */

46     public ToolBar() {
47         super("Main toolbar");
48         this.setup();
49     }
50     
51     /**
52      * @param arg0
53      */

54     private ToolBar(int arg0) {
55         super(arg0);
56     }
57     
58     /**
59      * @param arg0
60      */

61     private ToolBar(String JavaDoc arg0) {
62         super(arg0);
63     }
64     
65     /**
66      * @param arg0
67      * @param arg1
68      */

69     private ToolBar(String JavaDoc arg0, int arg1) {
70         super(arg0, arg1);
71     }
72     
73     private void setup() {
74         HIMAction action = new ActionNewFile();
75         this.m_aActions.add(action);
76         this.add( action.getButton());
77         
78         action = new ActionOpen();
79         this.m_aActions.add(action);
80         this.add( action.getButton());
81         
82         this.addSeparator();
83         
84         action = new ActionPreview();
85         this.m_aActions.add(action);
86         this.add( action.getButton());
87         
88         this.addSeparator();
89         
90         action = new ActionPublishToInternet();
91         this.m_aActions.add(action);
92         this.add( action.getButton());
93         
94         this.addSeparator();
95         
96         action = new ActionSynchronise();
97         this.m_aActions.add(action);
98         this.add( action.getButton());
99         
100         this.addSeparator();
101         
102         action = new ActionDownloadImports();
103         this.m_aActions.add(action);
104         this.add( action.getButton());
105         
106         ContextHandler.getInstance().addListener(
107                 ContextType.CONTEXT_FILES,
108                 this);
109         ContextHandler.getInstance().addListener(
110                 ContextType.CONTEXT_DIRS,
111                 this);
112         ContextHandler.getInstance().addListener(
113                 ContextType.CONTEXT_TABS,
114                 this);
115         
116         this.setPreferredSize(new Dimension(this.getPreferredSize().width, 30) );
117     }
118     
119     /* (non-Javadoc)
120      * @see com.simulacramedia.contentmanager.context.ContextListener#contextMessage(com.simulacramedia.contentmanager.context.ContextEvent)
121      */

122     public void contextMessage(ContextEvent ce) {
123         if (ce.CONTEXT_TYPE == ContextType.CONTEXT_DIRS) {
124             Iterator itor = this.m_aActions.iterator();
125             while(itor.hasNext()) {
126                 HIMAction action = (HIMAction) itor.next();
127                 action.isEnabled(ce);
128             }
129         } else if (ce.CONTEXT_TYPE == ContextType.CONTEXT_FILES) {
130             Iterator itor = this.m_aActions.iterator();
131             while(itor.hasNext()) {
132                 HIMAction action = (HIMAction) itor.next();
133                 action.isEnabled(ce);
134             }
135         } else if (ce.CONTEXT_TYPE == ContextType.CONTEXT_TABS) {
136             Iterator itor = this.m_aActions.iterator();
137             while(itor.hasNext()) {
138                 HIMAction action = (HIMAction) itor.next();
139                 action.isEnabled(ce);
140             }
141         }
142     }
143     
144 }
145
Popular Tags