intial source from ttp://www.sf.net/projects/wdte
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.css.core / src / net / sourceforge / phpeclipse / css / core / internal / parser / MutableRegion.java
diff --git a/archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/internal/parser/MutableRegion.java b/archive/net.sourceforge.phpeclipse.css.core/src/net/sourceforge/phpeclipse/css/core/internal/parser/MutableRegion.java
new file mode 100644 (file)
index 0000000..41a7210
--- /dev/null
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2003-2004 Christopher Lenz and others.
+ * All rights reserved. This program and the accompanying materials 
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ * 
+ * Contributors:
+ *     Christopher Lenz - initial API and implementation
+ * 
+ * $Id: MutableRegion.java,v 1.1 2004-09-02 18:07:13 jsurfer Exp $
+ */
+
+package net.sourceforge.phpeclipse.css.core.internal.parser;
+
+import org.eclipse.jface.text.IRegion;
+
+/**
+ * 
+ */
+public class MutableRegion implements IRegion {
+
+       // Instance Variables ------------------------------------------------------
+
+       /**
+        * The offset of the region.
+        */
+       private int offset = 0;
+
+       /**
+        * The length of the region.
+        */
+       private int length = 0;
+
+       // Constructors ------------------------------------------------------------
+
+       /**
+        * Default constructor.
+        */
+       public MutableRegion() {
+               this(0);
+       }
+
+       /**
+        * Constructor with partial initialization.
+        * 
+        * @param offset the offset of the region
+        */
+       public MutableRegion(int offset) {
+               this.offset = offset;
+       }
+
+       /**
+        * Constructor with initialization.
+        * 
+        * @param offset the offset of the region
+        * @param length the length of the region
+        */
+       public MutableRegion(int offset, int length) {
+               this.offset = offset;
+               this.length = length;
+       }
+
+       /**
+        * Constructor with initialization.
+        * 
+        * @param region another region to initialize this region with
+        */
+       public MutableRegion(IRegion region) {
+               this.offset = region.getOffset();
+               this.length = region.getLength();
+       }
+
+       // IRegion Implementation --------------------------------------------------
+
+       /*
+        * @see org.eclipse.jface.text.IRegion#getLength()
+        */
+       public int getLength() {
+               return length;
+       }
+
+       /*
+        * @see org.eclipse.jface.text.IRegion#getOffset()
+        */
+       public int getOffset() {
+               return offset;
+       }
+
+       // Public Methods ----------------------------------------------------------
+
+       /**
+        * Adds another region to this region, which will be enlarged so that the
+        * added region completely fits into this region.
+        * 
+        * @param region the region to add 
+        */
+       public void add(IRegion region) {
+               int start1 = offset;
+               int end1 = offset + length;
+               int start2 = region.getOffset();
+               int end2 = start2 + region.getLength();
+               offset = (start1 < start2) ? start1 : start2;
+               length = (end1 > end2) ? (end1 - offset) : (end2 - offset);
+       }
+
+       /**
+        * Sets the length of the region.
+        * 
+        * @param length the length to set
+        */
+       public void setLength(int length) {
+               this.length = length;
+       }
+
+       /**
+        * Sets the offset of the region.
+        * 
+        * @param offset the offset to set
+        */
+       public void setOffset(int offset) {
+               this.offset = offset;
+       }
+
+}