Merge commit '42b2e5ca519766e37ce6941ba4faecc9691cc403' into upstream
[debian/openrocket] / android-libraries / achartengine / src / org / achartengine / tools / AbstractTool.java
diff --git a/android-libraries/achartengine/src/org/achartengine/tools/AbstractTool.java b/android-libraries/achartengine/src/org/achartengine/tools/AbstractTool.java
new file mode 100644 (file)
index 0000000..99841ed
--- /dev/null
@@ -0,0 +1,111 @@
+/**\r
+ * Copyright (C) 2009 - 2012 SC 4ViewSoft SRL\r
+ *  \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *  \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *  \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.achartengine.tools;\r
+\r
+import org.achartengine.chart.AbstractChart;\r
+import org.achartengine.chart.XYChart;\r
+import org.achartengine.renderer.XYMultipleSeriesRenderer;\r
+\r
+/**\r
+ * Abstract class for being extended by graphical view tools.\r
+ */\r
+public abstract class AbstractTool {\r
+  /** The chart. */\r
+  protected AbstractChart mChart;\r
+  /** The renderer. */\r
+  protected XYMultipleSeriesRenderer mRenderer;\r
+\r
+  /**\r
+   * Abstract tool constructor.\r
+   * \r
+   * @param chart the chart\r
+   */\r
+  public AbstractTool(AbstractChart chart) {\r
+    mChart = chart;\r
+    if (chart instanceof XYChart) {\r
+      mRenderer = ((XYChart) chart).getRenderer();\r
+    }\r
+  }\r
+\r
+  /**\r
+   * Returns the current chart range.\r
+   * \r
+   * @param scale the scale\r
+   * @return the chart range\r
+   */\r
+  public double[] getRange(int scale) {\r
+    double minX = mRenderer.getXAxisMin(scale);\r
+    double maxX = mRenderer.getXAxisMax(scale);\r
+    double minY = mRenderer.getYAxisMin(scale);\r
+    double maxY = mRenderer.getYAxisMax(scale);\r
+    return new double[] { minX, maxX, minY, maxY };\r
+  }\r
+\r
+  /**\r
+   * Sets the range to the calculated one, if not already set.\r
+   * \r
+   * @param range the range\r
+   * @param scale the scale\r
+   */\r
+  public void checkRange(double[] range, int scale) {\r
+    if (mChart instanceof XYChart) {\r
+      double[] calcRange = ((XYChart) mChart).getCalcRange(scale);\r
+      if (calcRange != null) {\r
+        if (!mRenderer.isMinXSet(scale)) {\r
+          range[0] = calcRange[0];\r
+          mRenderer.setXAxisMin(range[0], scale);\r
+        }\r
+        if (!mRenderer.isMaxXSet(scale)) {\r
+          range[1] = calcRange[1];\r
+          mRenderer.setXAxisMax(range[1], scale);\r
+        }\r
+        if (!mRenderer.isMinYSet(scale)) {\r
+          range[2] = calcRange[2];\r
+          mRenderer.setYAxisMin(range[2], scale);\r
+        }\r
+        if (!mRenderer.isMaxYSet(scale)) {\r
+          range[3] = calcRange[3];\r
+          mRenderer.setYAxisMax(range[3], scale);\r
+        }\r
+      }\r
+    }\r
+  }\r
+\r
+  /**\r
+   * Sets a new range on the X axis.\r
+   * \r
+   * @param min the minimum value\r
+   * @param max the maximum value\r
+   * @param scale the scale\r
+   */\r
+  protected void setXRange(double min, double max, int scale) {\r
+    mRenderer.setXAxisMin(min, scale);\r
+    mRenderer.setXAxisMax(max, scale);\r
+  }\r
+\r
+  /**\r
+   * Sets a new range on the Y axis.\r
+   * \r
+   * @param min the minimum value\r
+   * @param max the maximum value\r
+   * @param scale the scale\r
+   */\r
+  protected void setYRange(double min, double max, int scale) {\r
+    mRenderer.setYAxisMin(min, scale);\r
+    mRenderer.setYAxisMax(max, scale);\r
+  }\r
+\r
+}\r