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.skin.factory;
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 com.realtime.crossfire.jxclient.gui.label.GUIDialogTitle;
00028 import com.realtime.crossfire.jxclient.gui.label.JXCWindowRenderer;
00029 import com.realtime.crossfire.jxclient.gui.misc.GUIDialogBackground;
00030 import java.awt.Color;
00031 import java.awt.Font;
00032 import java.awt.Image;
00033 import java.util.ArrayList;
00034 import java.util.Collection;
00035 import org.jetbrains.annotations.NotNull;
00036 import org.jetbrains.annotations.Nullable;
00037
00042 public class DialogFactory {
00043
00047 @NotNull
00048 private final Image frameNW;
00049
00053 @NotNull
00054 private final Image frameN;
00055
00059 @NotNull
00060 private final Image frameNE;
00061
00065 @NotNull
00066 private final Image frameW;
00067
00071 @NotNull
00072 private final Image frameC;
00073
00077 @NotNull
00078 private final Image frameE;
00079
00083 @NotNull
00084 private final Image frameSW;
00085
00089 @NotNull
00090 private final Image frameS;
00091
00095 @NotNull
00096 private final Image frameSE;
00097
00101 private final Font titleFont;
00102
00106 private final Color titleColor;
00107
00111 @Nullable
00112 private final Color titleBackgroundColor;
00113
00118 private final float frameAlpha;
00119
00137 public DialogFactory(@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, @NotNull final Font titleFont, @NotNull final Color titleColor, @NotNull final Color titleBackgroundColor, final float frameAlpha) {
00138 this.frameNW = frameNW;
00139 this.frameN = frameN;
00140 this.frameNE = frameNE;
00141 this.frameW = frameW;
00142 this.frameC = frameC;
00143 this.frameE = frameE;
00144 this.frameSW = frameSW;
00145 this.frameS = frameS;
00146 this.frameSE = frameSE;
00147 this.frameAlpha = frameAlpha;
00148 if (frameAlpha < 0F || frameAlpha > 1F) {
00149 throw new IllegalArgumentException("alpha transparency should be between 0 and 1 inclusive");
00150 }
00151 final int sizeN = frameN.getHeight(null);
00152 final int sizeS = frameS.getHeight(null);
00153 final int sizeW = frameW.getWidth(null);
00154 final int sizeE = frameE.getWidth(null);
00155 if (frameNW.getHeight(null) != sizeN) {
00156 throw new IllegalArgumentException("height of NW ("+frameNW.getHeight(null)+") does not match height of N ("+sizeN+")");
00157 }
00158 if (frameNE.getHeight(null) != sizeN) {
00159 throw new IllegalArgumentException("height of NE ("+frameNE.getHeight(null)+") does not match height of N ("+sizeN+")");
00160 }
00161 if (frameSW.getHeight(null) != sizeS) {
00162 throw new IllegalArgumentException("height of SW ("+frameSW.getHeight(null)+") does not match height of N ("+sizeS+")");
00163 }
00164 if (frameSE.getHeight(null) != sizeS) {
00165 throw new IllegalArgumentException("height of SE ("+frameSE.getHeight(null)+") does not match height of N ("+sizeS+")");
00166 }
00167 if (frameNW.getWidth(null) != sizeW) {
00168 throw new IllegalArgumentException("width of NW ("+frameNW.getWidth(null)+") does not match width of W");
00169 }
00170 if (frameNE.getWidth(null) != sizeE) {
00171 throw new IllegalArgumentException("width of NE ("+frameNE.getWidth(null)+") does not match width of E");
00172 }
00173 if (frameSW.getWidth(null) != sizeW) {
00174 throw new IllegalArgumentException("width of SW ("+frameSW.getWidth(null)+") does not match width of W");
00175 }
00176 if (frameSE.getWidth(null) != sizeE) {
00177 throw new IllegalArgumentException("width of SE ("+frameSE.getWidth(null)+") does not match width of E");
00178 }
00179 final int contentWidth = frameC.getWidth(null);
00180 final int contentHeight = frameC.getHeight(null);
00181 if (frameN.getWidth(null) != contentWidth) {
00182 throw new IllegalArgumentException("width of N ("+frameN.getWidth(null)+") does not match width of C ("+contentWidth+")");
00183 }
00184 if (frameS.getWidth(null) != contentWidth) {
00185 throw new IllegalArgumentException("width of S ("+frameS.getWidth(null)+") does not match width of C ("+contentWidth+")");
00186 }
00187 if (frameW.getHeight(null) != contentHeight) {
00188 throw new IllegalArgumentException("width of W ("+frameW.getHeight(null)+") does not match height of C ("+contentHeight+")");
00189 }
00190 if (frameE.getHeight(null) != contentHeight) {
00191 throw new IllegalArgumentException("width of E ("+frameE.getHeight(null)+") does not match height of C ("+contentHeight+")");
00192 }
00193 this.titleFont = titleFont;
00194 this.titleColor = titleColor;
00195 final int intAlpha = (int)(255*frameAlpha);
00196 this.titleBackgroundColor = intAlpha == 0 ? null : new Color(titleBackgroundColor.getRed(), titleBackgroundColor.getGreen(), titleBackgroundColor.getBlue(), intAlpha);
00197 }
00198
00207 @NotNull
00208 public Iterable<AbstractGUIElement> newDialog(@NotNull final TooltipManager tooltipManager, @NotNull final JXCWindowRenderer windowRenderer, @NotNull final GUIElementListener elementListener, @NotNull final String title) {
00209 final Collection<AbstractGUIElement> result = new ArrayList<AbstractGUIElement>();
00210 result.add(new GUIDialogBackground(tooltipManager, elementListener, "dialog_background", frameAlpha, frameNW, frameN, frameNE, frameW, frameC, frameE, frameSW, frameS, frameSE));
00211
00212 if (title.length() > 0) {
00213 result.add(new GUIDialogTitle(tooltipManager, windowRenderer, elementListener, "dialog_title", titleFont, titleColor, titleBackgroundColor, title));
00214 }
00215
00216 return result;
00217 }
00218
00223 public float getFrameAlpha() {
00224 return frameAlpha;
00225 }
00226 }