KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > sp > jedit > textarea > Anchor


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
23 package org.gjt.sp.jedit.textarea;
24
25 /**
26  * A base point for physical line/screen line conversion.
27  * @author Slava Pestov
28  * @version $Id: Anchor.java 7156 2006-10-02 21:33:17Z kpouer $
29  */

30 abstract class Anchor
31 {
32     DisplayManager displayManager;
33     TextArea textArea;
34
35     int physicalLine;
36     int scrollLine;
37     boolean callChanged;
38     boolean callReset;
39
40     //{{{ Anchor constructor
41
Anchor(DisplayManager displayManager,
42         TextArea textArea)
43     {
44         this.displayManager = displayManager;
45         this.textArea = textArea;
46     } //}}}
47

48     abstract void reset();
49     abstract void changed();
50
51     //{{{ toString() method
52
public String JavaDoc toString()
53     {
54         return getClass().getName() + "[" + physicalLine + ","
55             + scrollLine + "]";
56     } //}}}
57

58     //{{{ contentInserted() method
59
void contentInserted(int startLine, int numLines)
60     {
61         if(this.physicalLine >= startLine)
62         {
63             if(this.physicalLine != startLine)
64                 this.physicalLine += numLines;
65             this.callChanged = true;
66         }
67     } //}}}
68

69     //{{{ preContentRemoved() method
70
void preContentRemoved(int startLine, int numLines)
71     {
72         if(this.physicalLine >= startLine)
73         {
74             if(this.physicalLine == startLine)
75                 this.callChanged = true;
76             else
77             {
78                 int end = Math.min(startLine + numLines,
79                     this.physicalLine);
80                 for(int i = startLine + 1; i <= end; i++)
81                 {
82                     //XXX
83
if(displayManager.isLineVisible(i - 1))
84                     {
85                         this.scrollLine -=
86                             displayManager
87                             .screenLineMgr
88                             .getScreenLineCount(i);
89                     }
90                 }
91                 this.physicalLine -= (end - startLine);
92                 this.callChanged = true;
93             }
94         }
95     } //}}}
96
}
97
Popular Tags