Crossfire JXClient, Trunk
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-2017,2019-2023 Andreas Kirschbaum
20  * Copyright (C) 2010-2012,2014-2018,2020-2023 Nicolas Weeger
21  */
22 
23 package com.realtime.crossfire.jxclient.gui.gauge;
24 
29 public abstract class AbstractOrientation implements Orientation {
30 
34  private int width;
35 
39  private int height;
40 
44  private int cur;
45 
50  private int min;
51 
55  private int max;
56 
60  private int x;
61 
65  private int y;
66 
70  private int w;
71 
75  private int h;
76 
80  private boolean hasNegativeImage;
81 
85  protected AbstractOrientation() {
86  }
87 
88  @Override
89  public void setHasNegativeImage(final boolean hasNegativeImage) {
90  if (this.hasNegativeImage == hasNegativeImage) {
91  return;
92  }
93 
94  this.hasNegativeImage = hasNegativeImage;
95  reCalculate();
96  }
97 
98  @Override
99  public boolean setValues(final int cur, final int min, final int max) {
100  if (this.cur == cur && this.min == min && this.max == max) {
101  return false;
102  }
103 
104  this.cur = cur;
105  this.min = min;
106  this.max = max;
107  reCalculate();
108  return true;
109  }
110 
111  @Override
112  public boolean setExtends(final int width, final int height) {
113  if (this.width == width && this.height == height) {
114  return false;
115  }
116 
117  this.width = width;
118  this.height = height;
119  reCalculate();
120  return true;
121  }
122 
123  @Override
124  public int getX() {
125  return x;
126  }
127 
128  @Override
129  public int getY() {
130  return y;
131  }
132 
133  @Override
134  public int getW() {
135  return w;
136  }
137 
138  @Override
139  public int getH() {
140  return h;
141  }
142 
143  @Override
144  public boolean isNegativeImage() {
145  return cur < min && hasNegativeImage;
146  }
147 
148  @Override
149  public boolean isLowImage() {
150  return !isNegativeImage() && 10*cur < 7*min+3*max;
151  }
152 
153  @Override
154  public boolean isValid() {
155  return min < max;
156  }
157 
161  protected abstract void reCalculate();
162 
170  protected static int calculate(final int val, final int max, final int size) {
171  if (val <= 0 || max <= 0) {
172  return 0;
173  }
174  if (val >= max) {
175  return size;
176  }
177  return (size*val+max/2)/max;
178  }
179 
184  public int getWidth() {
185  return width;
186  }
187 
192  public int getHeight() {
193  return height;
194  }
195 
200  public int getCur() {
201  return cur;
202  }
203 
208  public int getMin() {
209  return min;
210  }
211 
216  public int getMax() {
217  return max;
218  }
219 
227  protected void setExtent(final int x, final int y, final int w, final int h) {
228  this.x = x;
229  this.y = y;
230  this.w = w;
231  this.h = h;
232  }
233 
234 }
com.realtime.crossfire.jxclient.gui.gauge.AbstractOrientation.getH
int getH()
Returns the height of the highlighted part of the image.
Definition: AbstractOrientation.java:139
com.realtime.crossfire.jxclient.gui.gauge.AbstractOrientation.w
int w
The width of the highlighted part of the image.
Definition: AbstractOrientation.java:70
com.realtime.crossfire.jxclient.gui.gauge.AbstractOrientation.getX
int getX()
Returns the x-coordinate of the highlighted part of the image.
Definition: AbstractOrientation.java:124
com.realtime.crossfire.jxclient.gui.gauge.AbstractOrientation.getMax
int getMax()
Returns the maximum value.
Definition: AbstractOrientation.java:216
com.realtime.crossfire.jxclient.gui.gauge.AbstractOrientation.h
int h
The height of the highlighted part of the image.
Definition: AbstractOrientation.java:75
com.realtime.crossfire.jxclient.gui.gauge.AbstractOrientation.cur
int cur
The current value.
Definition: AbstractOrientation.java:44
com.realtime.crossfire.jxclient.gui.gauge.AbstractOrientation.setExtent
void setExtent(final int x, final int y, final int w, final int h)
Sets the extent of the highlighted part of the image.
Definition: AbstractOrientation.java:227
com.realtime.crossfire.jxclient.gui.gauge.AbstractOrientation.width
int width
The total width of the image.
Definition: AbstractOrientation.java:34
com.realtime.crossfire.jxclient.gui.gauge.Orientation
Interface for orientation images.
Definition: Orientation.java:29
com.realtime.crossfire.jxclient.gui.gauge.AbstractOrientation.getY
int getY()
Returns the y-coordinate of the highlighted part of the image.
Definition: AbstractOrientation.java:129
com.realtime.crossfire.jxclient.gui.gauge.AbstractOrientation.calculate
static int calculate(final int val, final int max, final int size)
Returns the fraction.
Definition: AbstractOrientation.java:170
com.realtime.crossfire.jxclient.gui.gauge.AbstractOrientation.getW
int getW()
Returns the width of the highlighted part of the image.
Definition: AbstractOrientation.java:134
com.realtime.crossfire.jxclient.gui.gauge.AbstractOrientation.AbstractOrientation
AbstractOrientation()
Creates a new instance.
Definition: AbstractOrientation.java:85
com.realtime.crossfire.jxclient.gui.gauge.AbstractOrientation.setExtends
boolean setExtends(final int width, final int height)
Sets the extends of the image.
Definition: AbstractOrientation.java:112
com.realtime.crossfire.jxclient.gui.gauge.AbstractOrientation.getMin
int getMin()
Returns the minimum value.
Definition: AbstractOrientation.java:208
com.realtime.crossfire.jxclient.gui.gauge.AbstractOrientation
Abstract base class for implementing Orientation instances.
Definition: AbstractOrientation.java:29
com.realtime.crossfire.jxclient.gui.gauge.AbstractOrientation.getCur
int getCur()
Returns the current value.
Definition: AbstractOrientation.java:200
com.realtime.crossfire.jxclient.gui.gauge.AbstractOrientation.max
int max
The maximum value; the gauge is displayed as full if.
Definition: AbstractOrientation.java:55
com.realtime.crossfire.jxclient.gui.gauge.AbstractOrientation.hasNegativeImage
boolean hasNegativeImage
Whether the gauge can display negative images.
Definition: AbstractOrientation.java:80
com.realtime.crossfire.jxclient.gui.gauge.AbstractOrientation.isLowImage
boolean isLowImage()
Returns whether the low image should be shown.
Definition: AbstractOrientation.java:149
com.realtime.crossfire.jxclient.gui.gauge.AbstractOrientation.y
int y
The y-coordinate of the highlighted part of the image.
Definition: AbstractOrientation.java:65
com.realtime.crossfire.jxclient.gui.gauge.AbstractOrientation.x
int x
The x-coordinate of the highlighted part of the image.
Definition: AbstractOrientation.java:60
com.realtime.crossfire.jxclient.gui.gauge.AbstractOrientation.isNegativeImage
boolean isNegativeImage()
Returns whether the negative image should be shown.
Definition: AbstractOrientation.java:144
com.realtime.crossfire.jxclient.gui.gauge.AbstractOrientation.isValid
boolean isValid()
Returns whether the gauge's values are valid.
Definition: AbstractOrientation.java:154
com.realtime.crossfire.jxclient.gui.gauge.AbstractOrientation.getHeight
int getHeight()
Returns the total height of the image.
Definition: AbstractOrientation.java:192
com.realtime.crossfire.jxclient.gui.gauge.AbstractOrientation.height
int height
The total height of the image.
Definition: AbstractOrientation.java:39
com.realtime.crossfire.jxclient.gui.gauge.AbstractOrientation.setHasNegativeImage
void setHasNegativeImage(final boolean hasNegativeImage)
Sets whether the gauge can display negative images.
Definition: AbstractOrientation.java:89
com.realtime.crossfire.jxclient.gui.gauge.AbstractOrientation.getWidth
int getWidth()
Returns the total width of the image.
Definition: AbstractOrientation.java:184
com.realtime.crossfire.jxclient.gui.gauge.AbstractOrientation.reCalculate
abstract void reCalculate()
Recalculate the extents of the highlighted image part.
com.realtime.crossfire.jxclient.gui.gauge.AbstractOrientation.min
int min
The minimum value; the gauge is displayed as empty if.
Definition: AbstractOrientation.java:50
com.realtime.crossfire.jxclient.gui.gauge.AbstractOrientation.setValues
boolean setValues(final int cur, final int min, final int max)
Sets the gauge's values.
Definition: AbstractOrientation.java:99