PageRenderTime 112ms CodeModel.GetById 104ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/gui/ToolBarManager.java

#
Java | 122 lines | 70 code | 17 blank | 35 comment | 10 complexity | 05cd2be05242c1fdd648ea9ac09e44c7 MD5 | raw file
  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
 23package org.gjt.sp.jedit.gui;
 24
 25//{{{ Imports
 26import java.awt.*;
 27import java.util.*;
 28import java.util.List;
 29
 30import org.gjt.sp.jedit.*;
 31//}}}
 32
 33public class ToolBarManager
 34{
 35	//{{{ ToolBarManager constructor
 36	public ToolBarManager(Container top, Container bottom)
 37	{
 38		this.top = top;
 39		this.bottom = bottom;
 40	} //}}}
 41
 42	//{{{ addToolBar() method
 43	public void addToolBar(int group, int layer, Component toolbar)
 44	{
 45		Entry entry = new Entry(layer, toolbar);
 46
 47		if (group == View.TOP_GROUP)
 48			addToolBar(top, topToolBars, entry);
 49		else if (group == View.BOTTOM_GROUP)
 50			addToolBar(bottom, bottomToolBars, entry);
 51		else
 52			throw new InternalError("Invalid tool bar group");
 53	} //}}}
 54
 55	//{{{ removeToolBar() method
 56	public void removeToolBar(Component toolbar)
 57	{
 58		removeToolBar(top, topToolBars, toolbar);
 59		removeToolBar(bottom, bottomToolBars, toolbar);
 60	} //}}}
 61
 62	//{{{ Private members
 63
 64	//{{{ Instance variables
 65	private Container top;
 66	private Container bottom;
 67
 68	private List<Entry> topToolBars = new ArrayList<Entry>();
 69	private List<Entry> bottomToolBars = new ArrayList<Entry>();
 70	//}}}
 71
 72	//{{{ addToolBar() method
 73	private static void addToolBar(Container group, List<Entry> toolbars,
 74		Entry entry)
 75	{
 76		// See if we should place this toolbar before any others
 77		for(int i = 0; i < toolbars.size(); i++)
 78		{
 79			if(entry.layer > toolbars.get(i).layer)
 80			{
 81				toolbars.add(i,entry);
 82				group.add(entry.toolbar,i);
 83				return;
 84			}
 85		}
 86
 87		// Place the toolbar at the bottom of the group
 88		toolbars.add(entry);
 89		group.add(entry.toolbar);
 90	} //}}}
 91
 92	//{{{ removeToolBar() method
 93	private static void removeToolBar(Container group, List<Entry> toolbars,
 94		Component toolbar)
 95	{
 96		for(int i = 0; i < toolbars.size(); i++)
 97		{
 98			if(toolbar == toolbars.get(i).toolbar)
 99			{
100				group.remove(toolbar);
101				toolbars.remove(i);
102
103				return;
104			}
105		}
106	} //}}}
107
108	//}}}
109
110	//{{{ Entry class
111	private static class Entry
112	{
113		int layer;
114		Component toolbar;
115
116		Entry(int layer, Component toolbar)
117		{
118			this.layer = layer;
119			this.toolbar = toolbar;
120		}
121	} //}}}
122}