00001 /******************************************************************************* 00002 * Copyright (c) 2008-2014 SWTChart project. All rights reserved. 00003 * 00004 * This code is distributed under the terms of the Eclipse Public License v1.0 00005 * which is available at http://www.eclipse.org/legal/epl-v10.html 00006 *******************************************************************************/ 00007 package org.swtchart.internal.compress; 00008 00012 public class CompressConfig { 00013 00015 private long widthInPixels; 00016 00018 private long heightInPixels; 00019 00021 private double xLowerValue; 00022 00024 private double xUpperValue; 00025 00027 private double yLowerValue; 00028 00030 private double yUpperValue; 00031 00033 private boolean xLogScale; 00034 00036 private boolean yLogScale; 00037 00041 public CompressConfig() { 00042 widthInPixels = 1024; 00043 heightInPixels = 512; 00044 xLogScale = false; 00045 yLogScale = false; 00046 } 00047 00054 public CompressConfig(CompressConfig config) { 00055 widthInPixels = config.getWidthInPixel(); 00056 heightInPixels = config.getHeightInPixel(); 00057 00058 xLowerValue = config.getXLowerValue(); 00059 xUpperValue = config.getXUpperValue(); 00060 yLowerValue = config.getYLowerValue(); 00061 yUpperValue = config.getYUpperValue(); 00062 00063 xLogScale = config.isXLogScale(); 00064 yLogScale = config.isYLogScale(); 00065 } 00066 00067 /* 00068 * @see Object#equals(Object) 00069 */ 00070 @Override 00071 public boolean equals(Object obj) { 00072 if (obj == null || !(obj instanceof CompressConfig)) { 00073 return false; 00074 } 00075 00076 CompressConfig config = (CompressConfig) obj; 00077 00078 if (widthInPixels != config.getWidthInPixel() 00079 || heightInPixels != config.getHeightInPixel()) { 00080 return false; 00081 } 00082 00083 double diff = Math.abs(xLowerValue - config.getXLowerValue()) 00084 / (xUpperValue - xLowerValue); 00085 if (diff > 1.0 / widthInPixels) { 00086 return false; 00087 } 00088 00089 diff = Math.abs(xUpperValue - config.getXUpperValue()) 00090 / (xUpperValue - xLowerValue); 00091 if (diff > 1.0 / widthInPixels) { 00092 return false; 00093 } 00094 00095 diff = Math.abs(yLowerValue - config.getYLowerValue()) 00096 / (yUpperValue - yLowerValue); 00097 if (diff > 1.0 / heightInPixels) { 00098 return false; 00099 } 00100 00101 diff = Math.abs(yUpperValue - config.getYUpperValue()) 00102 / (yUpperValue - yLowerValue); 00103 if (diff > 1.0 / heightInPixels) { 00104 return false; 00105 } 00106 00107 if (config.isXLogScale() != xLogScale) { 00108 return false; 00109 } 00110 00111 if (config.isYLogScale() != yLogScale) { 00112 return false; 00113 } 00114 00115 return true; 00116 } 00117 00118 /* 00119 * @see Object#hashCode() 00120 */ 00121 @Override 00122 public int hashCode() { 00123 return 0; 00124 } 00125 00134 public void setSizeInPixel(long width, long height) { 00135 widthInPixels = width; 00136 heightInPixels = height; 00137 } 00138 00144 public long getWidthInPixel() { 00145 return widthInPixels; 00146 } 00147 00153 public long getHeightInPixel() { 00154 return heightInPixels; 00155 } 00156 00165 public void setXRange(double lower, double upper) { 00166 xLowerValue = lower; 00167 xUpperValue = upper; 00168 } 00169 00178 public void setYRange(double lower, double upper) { 00179 yLowerValue = lower; 00180 yUpperValue = upper; 00181 } 00182 00188 public double getXLowerValue() { 00189 return xLowerValue; 00190 } 00191 00197 public double getXUpperValue() { 00198 return xUpperValue; 00199 } 00200 00206 public double getYLowerValue() { 00207 return yLowerValue; 00208 } 00209 00215 public double getYUpperValue() { 00216 return yUpperValue; 00217 } 00218 00224 public boolean isXLogScale() { 00225 return xLogScale; 00226 } 00227 00234 public void setXLogScale(boolean value) { 00235 this.xLogScale = value; 00236 } 00237 00243 public boolean isYLogScale() { 00244 return yLogScale; 00245 } 00246 00253 public void setYLogScale(boolean value) { 00254 this.yLogScale = value; 00255 } 00256 00257 /* 00258 * @see Object#toString() 00259 */ 00260 @Override 00261 public String toString() { 00262 return "pixelWidth = " + widthInPixels + ", " + "pixelHeight = " 00263 + heightInPixels + ", " + "xLowerValue = " + xLowerValue + ", " 00264 + "xUpperValue = " + xUpperValue + ", " + "yLowerValue = " 00265 + yLowerValue + ", " + "yUpperValue = " + yUpperValue + ", " 00266 + yLogScale; 00267 } 00268 }