2 * Copyright (c) 2003-2004 Christopher Lenz and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * Christopher Lenz - initial API and implementation
11 * $Id: MutableRegion.java,v 1.1 2004-09-02 18:07:13 jsurfer Exp $
14 package net.sourceforge.phpeclipse.css.core.internal.parser;
16 import org.eclipse.jface.text.IRegion;
21 public class MutableRegion implements IRegion {
23 // Instance Variables ------------------------------------------------------
26 * The offset of the region.
28 private int offset = 0;
31 * The length of the region.
33 private int length = 0;
35 // Constructors ------------------------------------------------------------
38 * Default constructor.
40 public MutableRegion() {
45 * Constructor with partial initialization.
47 * @param offset the offset of the region
49 public MutableRegion(int offset) {
54 * Constructor with initialization.
56 * @param offset the offset of the region
57 * @param length the length of the region
59 public MutableRegion(int offset, int length) {
65 * Constructor with initialization.
67 * @param region another region to initialize this region with
69 public MutableRegion(IRegion region) {
70 this.offset = region.getOffset();
71 this.length = region.getLength();
74 // IRegion Implementation --------------------------------------------------
77 * @see org.eclipse.jface.text.IRegion#getLength()
79 public int getLength() {
84 * @see org.eclipse.jface.text.IRegion#getOffset()
86 public int getOffset() {
90 // Public Methods ----------------------------------------------------------
93 * Adds another region to this region, which will be enlarged so that the
94 * added region completely fits into this region.
96 * @param region the region to add
98 public void add(IRegion region) {
100 int end1 = offset + length;
101 int start2 = region.getOffset();
102 int end2 = start2 + region.getLength();
103 offset = (start1 < start2) ? start1 : start2;
104 length = (end1 > end2) ? (end1 - offset) : (end2 - offset);
108 * Sets the length of the region.
110 * @param length the length to set
112 public void setLength(int length) {
113 this.length = length;
117 * Sets the offset of the region.
119 * @param offset the offset to set
121 public void setOffset(int offset) {
122 this.offset = offset;