PageRenderTime 269ms CodeModel.GetById 265ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/org/gjt/sp/jedit/textarea/Anchor.java

#
Java | 94 lines | 57 code | 8 blank | 29 comment | 8 complexity | 07e17acfadaf4e03dec61f1933d7bbf6 MD5 | raw file
 1/*
 2 * Anchor.java - A base point for physical line <-> screen line conversion
 3 * :tabSize=8:indentSize=8:noTabs=false:
 4 * :folding=explicit:collapseFolds=1:
 5 *
 6 * Copyright (C) 2005 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
25/**
26 * A base point for physical line/screen line conversion.
27 */
28abstract class Anchor
29{
30	DisplayManager displayManager;
31	JEditTextArea textArea;
32
33	int physicalLine;
34	int scrollLine;
35	boolean callChanged;
36	boolean callReset;
37
38	//{{{ Anchor constructor
39	Anchor(DisplayManager displayManager,
40		JEditTextArea textArea)
41	{
42		this.displayManager = displayManager;
43		this.textArea = textArea;
44	} //}}}
45
46	abstract void reset();
47	abstract void changed();
48
49	//{{{ toString() method
50	public String toString()
51	{
52		return getClass().getName() + "[" + physicalLine + ","
53			+ scrollLine + "]";
54	} //}}}
55
56	//{{{ contentInserted() method
57	void contentInserted(int startLine, int numLines)
58	{
59		if(this.physicalLine >= startLine)
60		{
61			if(this.physicalLine != startLine)
62				this.physicalLine += numLines;
63			this.callChanged = true;
64		}
65	} //}}}
66
67	//{{{ preContentRemoved() method
68	void preContentRemoved(int startLine, int numLines)
69	{
70		if(this.physicalLine >= startLine)
71		{
72			if(this.physicalLine == startLine)
73				this.callChanged = true;
74			else
75			{
76				int end = Math.min(startLine + numLines,
77					this.physicalLine);
78				for(int i = startLine + 1; i <= end; i++)
79				{
80					//XXX
81					if(displayManager.isLineVisible(i - 1))
82					{
83						this.scrollLine -=
84							displayManager
85							.screenLineMgr
86							.getScreenLineCount(i);
87					}
88				}
89				this.physicalLine -= (end - startLine);
90				this.callChanged = true;
91			}
92		}
93	} //}}}
94}