PageRenderTime 283ms CodeModel.GetById 272ms app.highlight 7ms RepoModel.GetById 3ms app.codeStats 0ms

/jEdit/tags/jedit-4-1-pre5/org/gjt/sp/jedit/gui/ToolBarManager.java

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