KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > sp > jedit > gui > ToolBarManager


1 /*
2  * ToolBarManager.java - Handles tool bars for the View
3  * :tabSize=8:indentSize=8:noTabs=false:
4  * :folding=explicit:collapseFolds=1:
5  *
6  * Copyright (C) 2002 mike dillon
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  */

22
23 package org.gjt.sp.jedit.gui;
24
25 //{{{ Imports
26
import java.awt.*;
27 import java.util.*;
28 import org.gjt.sp.jedit.*;
29 //}}}
30

31 public class ToolBarManager
32 {
33     //{{{ ToolBarManager constructor
34
public ToolBarManager(Container top, Container bottom)
35     {
36         this.top = top;
37         this.bottom = bottom;
38     } //}}}
39

40     //{{{ addToolBar() method
41
public void addToolBar(int group, int layer, Component toolbar)
42     {
43         Entry entry = new Entry(layer, toolbar);
44
45         if (group == View.TOP_GROUP)
46             addToolBar(top, topToolBars, entry);
47         else if (group == View.BOTTOM_GROUP)
48             addToolBar(bottom, bottomToolBars, entry);
49         else
50             throw new InternalError JavaDoc("Invalid tool bar group");
51     } //}}}
52

53     //{{{ removeToolBar() method
54
public void removeToolBar(Component toolbar)
55     {
56         removeToolBar(top, topToolBars, toolbar);
57         removeToolBar(bottom, bottomToolBars, toolbar);
58     } //}}}
59

60     //{{{ Private members
61

62     //{{{ Instance variables
63
private Container top;
64     private Container bottom;
65
66     private ArrayList topToolBars = new ArrayList();
67     private ArrayList bottomToolBars = new ArrayList();
68     //}}}
69

70     //{{{ addToolBar() method
71
private void addToolBar(Container group, ArrayList toolbars,
72         Entry entry)
73     {
74         // See if we should place this toolbar before any others
75
for(int i = 0; i < toolbars.size(); i++)
76         {
77             if(entry.layer > ((Entry)toolbars.get(i)).layer)
78             {
79                 toolbars.add(i,entry);
80                 group.add(entry.toolbar,i);
81                 return;
82             }
83         }
84
85         // Place the toolbar at the bottom of the group
86
toolbars.add(entry);
87         group.add(entry.toolbar);
88     } //}}}
89

90     //{{{ removeToolBar() method
91
private void removeToolBar(Container group, ArrayList toolbars,
92         Component toolbar)
93     {
94         for(int i = 0; i < toolbars.size(); i++)
95         {
96             if(toolbar == ((Entry)toolbars.get(i)).toolbar)
97             {
98                 group.remove(toolbar);
99                 toolbars.remove(i);
100
101                 return;
102             }
103         }
104     } //}}}
105

106     //}}}
107

108     //{{{ Entry class
109
static class Entry
110     {
111         int layer;
112         Component toolbar;
113
114         Entry(int layer, Component toolbar)
115         {
116             this.layer = layer;
117             this.toolbar = toolbar;
118         }
119     } //}}}
120
}
121
Popular Tags