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
00024 import java.awt.Dimension;
00025 import java.awt.Graphics;
00026 import java.awt.Image;
00027 import org.jetbrains.annotations.NotNull;
00028 import org.jetbrains.annotations.Nullable;
00029
00034 public class GaugeState {
00035
00039 @Nullable
00040 private final Image fullImage;
00041
00045 @Nullable
00046 private final Image negativeImage;
00047
00051 @NotNull
00052 private final Dimension preferredSize;
00053
00057 private final int dx;
00058
00062 private int dy;
00063
00067 private int filledW = 0;
00068
00072 private int filledH = 0;
00073
00077 private int filledX = 0;
00078
00082 private int filledY = 0;
00083
00087 @Nullable
00088 private Image filledPicture = null;
00089
00098 public GaugeState(@Nullable final Image fullImage, @Nullable final Image negativeImage, final int dx, final int dy) {
00099 this.fullImage = fullImage;
00100 this.negativeImage = negativeImage;
00101 final int preferredWidth = Math.max(Math.max(fullImage == null ? 1 : fullImage.getWidth(null), negativeImage == null ? 1 : negativeImage.getWidth(null)), 1);
00102 final int preferredHeight = Math.max(Math.max(fullImage == null ? 1 : fullImage.getHeight(null), negativeImage == null ? 1 : negativeImage.getHeight(null)), 1);
00103 preferredSize = new Dimension(preferredWidth, preferredHeight);
00104 this.dx = dx;
00105 this.dy = dy;
00106 }
00107
00112 public void setDy(final int dy) {
00113 this.dy = dy;
00114 }
00115
00121 public boolean setValues(@NotNull final Orientation orientation) {
00122 final int newFilledX = orientation.getX();
00123 final int newFilledY = orientation.getY();
00124 final int newFilledW = orientation.getW();
00125 final int newFilledH = orientation.getH();
00126 final Image newFilledPicture = orientation.isValid() ? orientation.isNegativeImage() ? negativeImage : fullImage : null;
00127
00128 if (filledX == newFilledX && filledY == newFilledY && filledW == newFilledW && filledH == newFilledH && filledPicture == newFilledPicture) {
00129 return false;
00130 }
00131
00132 filledX = newFilledX;
00133 filledY = newFilledY;
00134 filledW = newFilledW;
00135 filledH = newFilledH;
00136 filledPicture = newFilledPicture;
00137 return true;
00138 }
00139
00144 public void draw(@NotNull final Graphics g) {
00145 if (filledPicture != null) {
00146 g.drawImage(filledPicture, filledX+dx, filledY+dy, filledX+dx+filledW, filledY+dy+filledH, filledX, filledY, filledX+filledW, filledY+filledH, null);
00147 }
00148 }
00149
00154 @NotNull
00155 public Dimension getPreferredSize() {
00156 return new Dimension(preferredSize);
00157 }
00158
00159 }