KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > LineSegment


1 /*
2  * LineSegment.java
3  *
4  * Copyright (C) 1998-2004 Peter Graves
5  * $Id: LineSegment.java,v 1.4 2004/04/02 03:31:05 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */

21
22 package org.armedbear.j;
23
24 public class LineSegment
25 {
26     private String JavaDoc text;
27     private int begin;
28     private int end;
29     private int format;
30
31     public LineSegment(String JavaDoc text, int format)
32     {
33         this.text = text;
34         begin = 0;
35         end = text.length();
36         this.format = format;
37     }
38
39     public LineSegment(String JavaDoc text, int begin, int end, int format)
40     {
41         this.text = text;
42         this.begin = begin;
43         this.end = end;
44         this.format = format;
45     }
46
47     public final String JavaDoc getText()
48     {
49         return text.substring(begin, end);
50     }
51
52     public final int getFormat()
53     {
54         return format;
55     }
56
57     public final void setFormat(int format)
58     {
59         this.format = format;
60     }
61
62     public final int length()
63     {
64         return end - begin;
65     }
66
67     public final void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
68     {
69         text.getChars(begin + srcBegin, begin + srcEnd, dst, dstBegin);
70     }
71
72     public final String JavaDoc substring(int beginIndex)
73     {
74         return text.substring(begin + beginIndex, end);
75     }
76 }
77
Popular Tags