]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/Range.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.spreadsheet / src / org / simantics / spreadsheet / Range.java
diff --git a/bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/Range.java b/bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/Range.java
new file mode 100644 (file)
index 0000000..f10e9df
--- /dev/null
@@ -0,0 +1,88 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.spreadsheet;\r
+\r
+\r
+public class Range {\r
+       public static final int MAXROWSPEC = Integer.MAX_VALUE;//1048576;//\r
+       public static final int MAXCOLUMNSPEC = Integer.MAX_VALUE;//16384;//\r
+       \r
+    public int startRow;\r
+    public int endRow;\r
+    public int startColumn;\r
+    public int endColumn;\r
+    \r
+    public Range(int startRow, int endRow, int startColumn, int endColumn) {\r
+        this.startRow = startRow;\r
+        this.endRow = endRow;\r
+        this.startColumn = startColumn;\r
+        this.endColumn = endColumn;\r
+        \r
+        if(startRow == -1) this.startRow = MAXROWSPEC;\r
+       if(endRow == -1) this.endRow = MAXROWSPEC;\r
+       if(startColumn == -1) this.startColumn = MAXCOLUMNSPEC;\r
+       if(endColumn == -1) this.endColumn = MAXCOLUMNSPEC;\r
+    }\r
+    \r
+    public Range(Range copy) {\r
+        this.startRow = copy.startRow;\r
+        this.endRow = copy.endRow;\r
+        this.startColumn = copy.startColumn;\r
+        this.endColumn = copy.endColumn;\r
+    }\r
+\r
+    public static Range combine(Range from, Range to) {\r
+        return new Range(from.startRow, to.endRow, from.startColumn, to.endColumn);\r
+    }\r
+    \r
+    public boolean isFull() {\r
+       return endRow == MAXROWSPEC && endColumn == MAXCOLUMNSPEC;\r
+    }\r
+\r
+    public boolean isFullRows() {\r
+       return endRow == MAXROWSPEC;\r
+    }\r
+\r
+    public boolean isFullColumns() {\r
+       return endColumn == MAXCOLUMNSPEC;\r
+    }\r
+\r
+    public int size() {\r
+        return (endRow-startRow + 1) * (endColumn - startColumn + 1);\r
+    }\r
+    \r
+    public int width() {\r
+       return (endColumn - startColumn + 1);\r
+    }\r
+    \r
+    public int height() {\r
+       return (endRow-startRow + 1);\r
+    }\r
+    \r
+    public boolean contains(Range r) {\r
+       if(endRow >= 0) {\r
+               if(r.endRow > endRow) return false;\r
+               if(r.startRow < startRow) return false;\r
+       }\r
+       if(endColumn >= 0) {\r
+               if(r.startColumn < startColumn) return false;\r
+               if(r.endColumn > endColumn) return false;\r
+       }\r
+       return true;\r
+    }\r
+    \r
+    @Override\r
+    public String toString() {\r
+        return "Range[(" + startRow + "," + startColumn + ")-(" + endRow + "," + endColumn + ")]";\r
+    }\r
+    \r
+}\r