Crossfire JXClient, Trunk  R20561
AbstractOrientation.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff.
19  * Copyright (C) 2006-2011 Andreas Kirschbaum.
20  */
21 
22 package com.realtime.crossfire.jxclient.gui.gauge;
23 
28 public abstract class AbstractOrientation implements Orientation {
29 
33  private int width;
34 
38  private int height;
39 
43  private int cur;
44 
49  private int min;
50 
54  private int max;
55 
59  private int x;
60 
64  private int y;
65 
69  private int w;
70 
74  private int h;
75 
79  private boolean hasNegativeImage;
80 
84  protected AbstractOrientation() {
85  }
86 
90  @Override
91  public void setHasNegativeImage(final boolean hasNegativeImage) {
92  if (this.hasNegativeImage == hasNegativeImage) {
93  return;
94  }
95 
96  this.hasNegativeImage = hasNegativeImage;
97  reCalculate();
98  }
99 
103  @Override
104  public boolean setValues(final int cur, final int min, final int max) {
105  if (this.cur == cur && this.min == min && this.max == max) {
106  return false;
107  }
108 
109  this.cur = cur;
110  this.min = min;
111  this.max = max;
112  reCalculate();
113  return true;
114  }
115 
119  @Override
120  public boolean setExtends(final int width, final int height) {
121  if (this.width == width && this.height == height) {
122  return false;
123  }
124 
125  this.width = width;
126  this.height = height;
127  reCalculate();
128  return true;
129  }
130 
134  @Override
135  public int getX() {
136  return x;
137  }
138 
142  @Override
143  public int getY() {
144  return y;
145  }
146 
150  @Override
151  public int getW() {
152  return w;
153  }
154 
158  @Override
159  public int getH() {
160  return h;
161  }
162 
166  @Override
167  public boolean isNegativeImage() {
168  return cur < min && hasNegativeImage;
169  }
170 
174  @Override
175  public boolean isValid() {
176  return min < max;
177  }
178 
182  protected abstract void reCalculate();
183 
191  protected static int calculate(final int val, final int max, final int size) {
192  if (val <= 0 || max <= 0) {
193  return 0;
194  }
195  if (val >= max) {
196  return size;
197  }
198  return (size*val+max/2)/max;
199  }
200 
205  public int getWidth() {
206  return width;
207  }
208 
213  public int getHeight() {
214  return height;
215  }
216 
221  public int getCur() {
222  return cur;
223  }
224 
229  public int getMin() {
230  return min;
231  }
232 
237  public int getMax() {
238  return max;
239  }
240 
248  protected void setExtent(final int x, final int y, final int w, final int h) {
249  this.x = x;
250  this.y = y;
251  this.w = w;
252  this.h = h;
253  }
254 
255 }
void setExtent(final int x, final int y, final int w, final int h)
Sets the extent of the highlighted part of the image.
boolean isNegativeImage()
Returns whether the negative image should be shown.whether the negative image should be shown ...
int getHeight()
Returns the total height of the image.
boolean hasNegativeImage
Whether the gauge can display negative images.
int h
The height of the highlighted part of the image.
int w
The width of the highlighted part of the image.
static int calculate(final int val, final int max, final int size)
Returns the fraction.
int y
The y-coordinate of the highlighted part of the image.
int min
The minimum value; the gauge is displayed as empty if.
void setHasNegativeImage(final boolean hasNegativeImage)
Sets whether the gauge can display negative images.By default negative images are not supported...
boolean isValid()
Returns whether the gauge&#39;s values are valid.whether the values are valid
abstract void reCalculate()
Recalculate the extents of the highlighted image part.
int getX()
Returns the x-coordinate of the highlighted part of the image.the x-coordinate
boolean setValues(final int cur, final int min, final int max)
Sets the gauge&#39;s values.the current value the minimum value the maximum value whether the values have...
int getW()
Returns the width of the highlighted part of the image.the width
Abstract base class for implementing Orientation instances.
int max
The maximum value; the gauge is displayed as full if.
int x
The x-coordinate of the highlighted part of the image.
int getH()
Returns the height of the highlighted part of the image.the height
int getY()
Returns the y-coordinate of the highlighted part of the image.the y-coordinate
boolean setExtends(final int width, final int height)
Sets the extends of the image.the width the height true if the size changed, false else ...