22 package com.realtime.crossfire.jxclient.gui.gauge;
24 import java.awt.Dimension;
25 import java.awt.Graphics;
26 import java.awt.Image;
27 import org.jetbrains.annotations.NotNull;
28 import org.jetbrains.annotations.Nullable;
98 public GaugeState(@Nullable
final Image fullImage, @Nullable
final Image negativeImage,
final int dx,
final int dy) {
101 final int preferredWidth = Math.max(Math.max(fullImage == null ? 1 : fullImage.getWidth(null), negativeImage == null ? 1 : negativeImage.getWidth(null)), 1);
102 final int preferredHeight = Math.max(Math.max(fullImage == null ? 1 : fullImage.getHeight(null), negativeImage == null ? 1 : negativeImage.getHeight(null)), 1);
103 preferredSize =
new Dimension(preferredWidth, preferredHeight);
122 final int newFilledX = orientation.getX();
123 final int newFilledY = orientation.getY();
124 final int newFilledW = orientation.getW();
125 final int newFilledH = orientation.getH();
126 final Image newFilledPicture = orientation.isValid() ? orientation.isNegativeImage() ?
negativeImage :
fullImage : null;
128 if (filledX == newFilledX && filledY == newFilledY && filledW == newFilledW && filledH == newFilledH && filledPicture == newFilledPicture) {
132 filledX = newFilledX;
133 filledY = newFilledY;
134 filledW = newFilledW;
135 filledH = newFilledH;
136 filledPicture = newFilledPicture;
144 public void draw(@NotNull
final Graphics g) {
145 if (filledPicture != null) {
146 g.drawImage(filledPicture, filledX+dx, filledY+dy, filledX+dx+filledW, filledY+dy+filledH, filledX, filledY, filledX+filledW, filledY+filledH, null);
156 return new Dimension(preferredSize);
final Dimension preferredSize
The preferred size of this component.
void draw(@NotNull final Graphics g)
Draws the gauge image into the given graphics context.
final int dx
The x-offset for drawing.
Interface for orientation images.
Dimension getPreferredSize()
Returns the preferred size.
final Image fullImage
The image representing a full gauge.
int filledY
The y-coordinate of the "filled" area.
int filledH
The height of the "filled" area.
void setDy(final int dy)
Sets the y-offset for drawing.
int filledX
The x-coordinate of the "filled" area.
GaugeState(@Nullable final Image fullImage, @Nullable final Image negativeImage, final int dx, final int dy)
Creates a new instance.
int filledW
The width of the "filled" area.
Image filledPicture
The image for painting the "filled" area.
int dy
The y-offset for drawing.
boolean setValues(@NotNull final Orientation orientation)
Updates the values from a Orientation state.
final Image negativeImage
The image representing a more-than-empty gauge.