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.button;
00023
00024 import java.awt.Graphics;
00025 import java.awt.Image;
00026 import org.jetbrains.annotations.NotNull;
00027
00034 public class ButtonImages {
00035
00039 @NotNull
00040 private final Image imageLeft;
00041
00045 @NotNull
00046 private final Image imageMiddle;
00047
00051 @NotNull
00052 private final Image imageRight;
00053
00057 private final int height;
00058
00065 public ButtonImages(@NotNull final Image imageLeft, @NotNull final Image imageMiddle, @NotNull final Image imageRight) {
00066 if (imageLeft.getHeight(null) != imageMiddle.getHeight(null)) {
00067 throw new IllegalArgumentException("left image height is "+imageLeft.getHeight(null)+" but middle image height is "+imageMiddle.getHeight(null));
00068 }
00069 if (imageMiddle.getHeight(null) != imageRight.getHeight(null)) {
00070 throw new IllegalArgumentException("middle image height is "+imageMiddle.getHeight(null)+" but right image height is "+imageRight.getHeight(null));
00071 }
00072
00073 this.imageLeft = imageLeft;
00074 this.imageMiddle = imageMiddle;
00075 this.imageRight = imageRight;
00076 height = imageMiddle.getHeight(null);
00077 }
00078
00083 public int getHeight() {
00084 return height;
00085 }
00086
00092 public void render(@NotNull final Graphics g, final int w) {
00093 g.drawImage(imageLeft, 0, 0, null);
00094 g.drawImage(imageRight, w-imageRight.getWidth(null), 0, null);
00095
00096 final int middleWidth = imageMiddle.getWidth(null);
00097 int tmpWidth = w-imageLeft.getWidth(null)-imageRight.getWidth(null);
00098 int tmpX = imageLeft.getWidth(null);
00099 while (tmpWidth > 0) {
00100 final int thisWidth = Math.min(tmpWidth, middleWidth);
00101 g.drawImage(imageMiddle, tmpX, 0, tmpX+thisWidth, height, 0, 0, thisWidth, height, null);
00102 tmpX += thisWidth;
00103 tmpWidth -= thisWidth;
00104 }
00105 }
00106
00107 }