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.misc;
00023
00024 import com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement;
00025 import com.realtime.crossfire.jxclient.gui.gui.GUIElementListener;
00026 import com.realtime.crossfire.jxclient.gui.gui.TooltipManager;
00027 import java.awt.AlphaComposite;
00028 import java.awt.Dimension;
00029 import java.awt.Graphics;
00030 import java.awt.Graphics2D;
00031 import java.awt.Image;
00032 import java.awt.Transparency;
00033 import org.jetbrains.annotations.NotNull;
00034 import org.jetbrains.annotations.Nullable;
00035
00040 public class GUIDialogBackground extends AbstractGUIElement {
00041
00045 private static final long serialVersionUID = 1L;
00046
00050 @NotNull
00051 private final Image frameNW;
00052
00056 @NotNull
00057 private final Image frameN;
00058
00062 @NotNull
00063 private final Image frameNE;
00064
00068 @NotNull
00069 private final Image frameW;
00070
00074 @NotNull
00075 private final Image frameC;
00076
00080 @NotNull
00081 private final Image frameE;
00082
00086 @NotNull
00087 private final Image frameSW;
00088
00092 @NotNull
00093 private final Image frameS;
00094
00098 @NotNull
00099 private final Image frameSE;
00100
00104 private final int heightN;
00105
00109 private final int heightS;
00110
00114 private final int widthW;
00115
00119 private final int widthE;
00120
00124 private final float alpha;
00125
00143 public GUIDialogBackground(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, final float alpha, @NotNull final Image frameNW, @NotNull final Image frameN, @NotNull final Image frameNE, @NotNull final Image frameW, @NotNull final Image frameC, @NotNull final Image frameE, @NotNull final Image frameSW, @NotNull final Image frameS, @NotNull final Image frameSE) {
00144 super(tooltipManager, elementListener, name, alpha < 1F ? Transparency.TRANSLUCENT : Transparency.OPAQUE);
00145 this.frameNW = frameNW;
00146 this.frameN = frameN;
00147 this.frameNE = frameNE;
00148 this.frameW = frameW;
00149 this.frameC = frameC;
00150 this.frameE = frameE;
00151 this.frameSW = frameSW;
00152 this.frameS = frameS;
00153 this.frameSE = frameSE;
00154 this.alpha = alpha;
00155 heightN = frameN.getHeight(null);
00156 heightS = frameS.getHeight(null);
00157 widthW = frameW.getWidth(null);
00158 widthE = frameE.getWidth(null);
00159 if (frameNW.getWidth(null) != widthW) {
00160 throw new IllegalArgumentException();
00161 }
00162 if (frameSW.getWidth(null) != widthW) {
00163 throw new IllegalArgumentException();
00164 }
00165 if (frameNE.getWidth(null) != widthE) {
00166 throw new IllegalArgumentException();
00167 }
00168 if (frameSE.getWidth(null) != widthE) {
00169 throw new IllegalArgumentException();
00170 }
00171 if (frameNW.getHeight(null) != heightN) {
00172 throw new IllegalArgumentException();
00173 }
00174 if (frameSW.getHeight(null) != heightS) {
00175 throw new IllegalArgumentException();
00176 }
00177 if (frameNE.getHeight(null) != heightN) {
00178 throw new IllegalArgumentException();
00179 }
00180 if (frameSE.getHeight(null) != heightS) {
00181 throw new IllegalArgumentException();
00182 }
00183 }
00184
00188 @Override
00189 public void paintComponent(@NotNull final Graphics g) {
00190 final Graphics paint;
00191 if (alpha < 1F) {
00192 final Graphics2D g2d = (Graphics2D)g.create();
00193 g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
00194 paint = g2d;
00195 } else {
00196 paint = g;
00197 }
00198
00199 super.paintComponent(paint);
00200 final int w = Math.max(1, getWidth()-widthW-widthE);
00201 final int h = Math.max(1, getHeight()-heightN-heightS);
00202 paint.drawImage(frameNW, 0, 0, null);
00203 paint.drawImage(frameN, widthW, 0, widthW+w, heightN, 0, 0, w, heightN, null);
00204 paint.drawImage(frameNE, widthW+w, 0, null);
00205 paint.drawImage(frameW, 0, heightN, widthW, heightN+h, 0, 0, widthW, h, null);
00206 paint.drawImage(frameC, widthW, heightN, widthW+w, heightN+h, 0, 0, w, h, null);
00207 paint.drawImage(frameE, widthW+w, heightN, widthW+w+widthE, heightN+h, 0, 0, widthE, h, null);
00208 paint.drawImage(frameSW, 0, heightN+h, null);
00209 paint.drawImage(frameS, widthW, heightN+h, widthW+w, heightN+h+heightS, 0, 0, w, heightS, null);
00210 paint.drawImage(frameSE, widthW+w, heightN+h, null);
00211 if (paint != g) {
00212 paint.dispose();
00213 }
00214 }
00215
00219 @Nullable
00220 @Override
00221 public Dimension getPreferredSize() {
00222 return getMinimumSize();
00223 }
00224
00228 @Nullable
00229 @Override
00230 public Dimension getMinimumSize() {
00231 return new Dimension(widthW+1+widthE, heightN+1+heightS);
00232 }
00233
00237 @Override
00238 public void execute() {
00239
00240 }
00241
00242 }