00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 package com.realtime.crossfire.jxclient.gui.gauge;
00023
00028 public abstract class AbstractOrientation implements Orientation {
00029
00033 private int width = 0;
00034
00038 private int height = 0;
00039
00043 private int cur = 0;
00044
00049 private int min = 0;
00050
00055 private int max = 0;
00056
00060 private int x = 0;
00061
00065 private int y = 0;
00066
00070 private int w = 0;
00071
00075 private int h = 0;
00076
00080 private boolean hasNegativeImage = false;
00081
00085 protected AbstractOrientation() {
00086 }
00087
00091 @Override
00092 public void setHasNegativeImage(final boolean hasNegativeImage) {
00093 if (this.hasNegativeImage == hasNegativeImage) {
00094 return;
00095 }
00096
00097 this.hasNegativeImage = hasNegativeImage;
00098 reCalculate();
00099 }
00100
00104 @Override
00105 public boolean setValues(final int cur, final int min, final int max) {
00106 if (this.cur == cur && this.min == min && this.max == max) {
00107 return false;
00108 }
00109
00110 this.cur = cur;
00111 this.min = min;
00112 this.max = max;
00113 reCalculate();
00114 return true;
00115 }
00116
00120 @Override
00121 public boolean setExtends(final int width, final int height) {
00122 if (this.width == width && this.height == height) {
00123 return false;
00124 }
00125
00126 this.width = width;
00127 this.height = height;
00128 reCalculate();
00129 return true;
00130 }
00131
00135 @Override
00136 public int getX() {
00137 return x;
00138 }
00139
00143 @Override
00144 public int getY() {
00145 return y;
00146 }
00147
00151 @Override
00152 public int getW() {
00153 return w;
00154 }
00155
00159 @Override
00160 public int getH() {
00161 return h;
00162 }
00163
00167 @Override
00168 public boolean isNegativeImage() {
00169 return cur < min && hasNegativeImage;
00170 }
00171
00175 @Override
00176 public boolean isValid() {
00177 return min < max;
00178 }
00179
00183 protected abstract void reCalculate();
00184
00193 protected static int calculate(final int val, final int max, final int size) {
00194 if (val <= 0 || max <= 0) {
00195 return 0;
00196 } else if (val >= max) {
00197 return size;
00198 } else {
00199 return (size*val+max/2)/max;
00200 }
00201 }
00202
00207 public int getWidth() {
00208 return width;
00209 }
00210
00215 public int getHeight() {
00216 return height;
00217 }
00218
00223 public int getCur() {
00224 return cur;
00225 }
00226
00231 public int getMin() {
00232 return min;
00233 }
00234
00239 public int getMax() {
00240 return max;
00241 }
00242
00250 protected void setExtent(final int x, final int y, final int w, final int h) {
00251 this.x = x;
00252 this.y = y;
00253 this.w = w;
00254 this.h = h;
00255 }
00256
00257 }