001: /*
002: * ToolBarManager.java - Handles tool bars for the View
003: * :tabSize=8:indentSize=8:noTabs=false:
004: * :folding=explicit:collapseFolds=1:
005: *
006: * Copyright (C) 2002 mike dillon
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: */
022:
023: package org.gjt.sp.jedit.gui;
024:
025: //{{{ Imports
026: import java.awt.*;
027: import java.util.*;
028: import org.gjt.sp.jedit.*;
029:
030: //}}}
031:
032: public class ToolBarManager {
033: //{{{ ToolBarManager constructor
034: public ToolBarManager(Container top, Container bottom) {
035: this .top = top;
036: this .bottom = bottom;
037: } //}}}
038:
039: //{{{ addToolBar() method
040: public void addToolBar(int group, int layer, Component toolbar) {
041: Entry entry = new Entry(layer, toolbar);
042:
043: if (group == View.TOP_GROUP)
044: addToolBar(top, topToolBars, entry);
045: else if (group == View.BOTTOM_GROUP)
046: addToolBar(bottom, bottomToolBars, entry);
047: else
048: throw new InternalError("Invalid tool bar group");
049: } //}}}
050:
051: //{{{ removeToolBar() method
052: public void removeToolBar(Component toolbar) {
053: removeToolBar(top, topToolBars, toolbar);
054: removeToolBar(bottom, bottomToolBars, toolbar);
055: } //}}}
056:
057: //{{{ Private members
058:
059: //{{{ Instance variables
060: private Container top;
061: private Container bottom;
062:
063: private ArrayList topToolBars = new ArrayList();
064: private ArrayList bottomToolBars = new ArrayList();
065:
066: //}}}
067:
068: //{{{ addToolBar() method
069: private void addToolBar(Container group, ArrayList toolbars,
070: Entry entry) {
071: // See if we should place this toolbar before any others
072: for (int i = 0; i < toolbars.size(); i++) {
073: if (entry.layer > ((Entry) toolbars.get(i)).layer) {
074: toolbars.add(i, entry);
075: group.add(entry.toolbar, i);
076: return;
077: }
078: }
079:
080: // Place the toolbar at the bottom of the group
081: toolbars.add(entry);
082: group.add(entry.toolbar);
083: } //}}}
084:
085: //{{{ removeToolBar() method
086: private void removeToolBar(Container group, ArrayList toolbars,
087: Component toolbar) {
088: for (int i = 0; i < toolbars.size(); i++) {
089: if (toolbar == ((Entry) toolbars.get(i)).toolbar) {
090: group.remove(toolbar);
091: toolbars.remove(i);
092:
093: return;
094: }
095: }
096: } //}}}
097:
098: //}}}
099:
100: //{{{ Entry class
101: static class Entry {
102: int layer;
103: Component toolbar;
104:
105: Entry(int layer, Component toolbar) {
106: this .layer = layer;
107: this .toolbar = toolbar;
108: }
109: } //}}}
110: }
|