PageRenderTime 73ms CodeModel.GetById 66ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre5/org/gjt/sp/jedit/textarea/ExtensionManager.java

#
Java | 140 lines | 92 code | 15 blank | 33 comment | 10 complexity | 286c85e99641ee1010d0a448ee6b10ec MD5 | raw file
  1/*
  2 * ExtensionManager.java - Handles 'layers'
  3 * :tabSize=8:indentSize=8:noTabs=false:
  4 * :folding=explicit:collapseFolds=1:
  5 *
  6 * Copyright (C) 2002 Slava Pestov
  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.textarea;
 24
 25import java.awt.Graphics2D;
 26import java.util.ArrayList;
 27import org.gjt.sp.util.Log;
 28
 29class ExtensionManager
 30{
 31	//{{{ addExtension() method
 32	void addExtension(int layer, TextAreaExtension ext)
 33	{
 34		Entry entry = new Entry(layer,ext);
 35
 36		for(int i = 0; i < extensions.size(); i++)
 37		{
 38			int _layer = ((Entry)extensions.get(i)).layer;
 39			if(layer < _layer)
 40			{
 41				extensions.add(i,entry);
 42				return;
 43			}
 44		}
 45
 46		extensions.add(entry);
 47	} //}}}
 48
 49	//{{{ removeExtension() method
 50	void removeExtension(TextAreaExtension ext)
 51	{
 52		for(int i = 0; i < extensions.size(); i++)
 53		{
 54			Entry entry = (Entry)extensions.get(i);
 55			if(entry.ext == ext)
 56			{
 57				extensions.remove(i);
 58				return;
 59			}
 60		}
 61	} //}}}
 62
 63	//{{{ paintValidLine() method
 64	void paintValidLine(Graphics2D gfx, int screenLine,
 65		int physicalLine, int start, int end, int y)
 66	{
 67		for(int i = 0; i < extensions.size(); i++)
 68		{
 69			TextAreaExtension ext = ((Entry)extensions.get(i)).ext;
 70			try
 71			{
 72				ext.paintValidLine(gfx,screenLine,
 73					physicalLine,start,end,y);
 74			}
 75			catch(Throwable t)
 76			{
 77				Log.log(Log.ERROR,this,t);
 78
 79				// remove it so editor can continue
 80				// functioning
 81				extensions.remove(i);
 82				i--;
 83			}
 84		}
 85	} //}}}
 86
 87	//{{{ paintInvalidLine() method
 88	void paintInvalidLine(Graphics2D gfx, int screenLine,
 89		int y)
 90	{
 91		for(int i = 0; i < extensions.size(); i++)
 92		{
 93			TextAreaExtension ext = ((Entry)extensions.get(i)).ext;
 94			try
 95			{
 96				ext.paintInvalidLine(gfx,screenLine,y);
 97			}
 98			catch(Throwable t)
 99			{
100				Log.log(Log.ERROR,this,t);
101
102				// remove it so editor can continue
103				// functioning
104				extensions.remove(i);
105				i--;
106			}
107		}
108	} //}}}
109
110	//{{{ getToolTipText() method
111	String getToolTipText(int x, int y)
112	{
113		for(int i = 0; i < extensions.size(); i++)
114		{
115			TextAreaExtension ext = ((Entry)extensions.get(i)).ext;
116			String toolTip = ext.getToolTipText(x,y);
117			if(toolTip != null)
118				return toolTip;
119		}
120
121		return null;
122	} //}}}
123
124	//{{{ Private members
125	private ArrayList extensions = new ArrayList();
126	//}}}
127
128	//{{{ Entry class
129	static class Entry
130	{
131		int layer;
132		TextAreaExtension ext;
133
134		Entry(int layer, TextAreaExtension ext)
135		{
136			this.layer = layer;
137			this.ext = ext;
138		}
139	} //}}}
140}