Crossfire JXClient, Trunk
DialogFactory.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff
19  * Copyright (C) 2006-2017,2019-2023 Andreas Kirschbaum
20  * Copyright (C) 2010-2012,2014-2018,2020-2023 Nicolas Weeger
21  */
22 
23 package com.realtime.crossfire.jxclient.skin.factory;
24 
32 import java.awt.Color;
33 import java.awt.Font;
34 import java.awt.Image;
35 import java.util.ArrayList;
36 import java.util.Collection;
37 import org.jetbrains.annotations.NotNull;
38 import org.jetbrains.annotations.Nullable;
39 
44 public class DialogFactory {
45 
49  @NotNull
50  private final Image frameNW;
51 
55  @NotNull
56  private final Image frameN;
57 
61  @NotNull
62  private final Image frameNE;
63 
67  @NotNull
68  private final Image frameW;
69 
73  @NotNull
74  private final Image frameC;
75 
79  @NotNull
80  private final Image frameE;
81 
85  @NotNull
86  private final Image frameSW;
87 
91  @NotNull
92  private final Image frameS;
93 
97  @NotNull
98  private final Image frameSE;
99 
103  private final Font titleFont;
104 
108  private final Color titleColor;
109 
113  @Nullable
114  private final Color titleBackgroundColor;
115 
120  private final float frameAlpha;
121 
125  @NotNull
126  private final GuiFactory guiFactory;
127 
146  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, @NotNull final GuiFactory guiFactory) {
147  this.frameNW = frameNW;
148  this.frameN = frameN;
149  this.frameNE = frameNE;
150  this.frameW = frameW;
151  this.frameC = frameC;
152  this.frameE = frameE;
153  this.frameSW = frameSW;
154  this.frameS = frameS;
155  this.frameSE = frameSE;
156  this.frameAlpha = frameAlpha;
157  this.guiFactory = guiFactory;
158  if (frameAlpha < 0.0F || frameAlpha > 1.0F) {
159  throw new IllegalArgumentException("alpha transparency should be between 0 and 1 inclusive");
160  }
161  final int sizeN = frameN.getHeight(null);
162  final int sizeS = frameS.getHeight(null);
163  final int sizeW = frameW.getWidth(null);
164  final int sizeE = frameE.getWidth(null);
165  if (frameNW.getHeight(null) != sizeN) {
166  throw new IllegalArgumentException("height of NW ("+frameNW.getHeight(null)+") does not match height of N ("+sizeN+")");
167  }
168  if (frameNE.getHeight(null) != sizeN) {
169  throw new IllegalArgumentException("height of NE ("+frameNE.getHeight(null)+") does not match height of N ("+sizeN+")");
170  }
171  if (frameSW.getHeight(null) != sizeS) {
172  throw new IllegalArgumentException("height of SW ("+frameSW.getHeight(null)+") does not match height of N ("+sizeS+")");
173  }
174  if (frameSE.getHeight(null) != sizeS) {
175  throw new IllegalArgumentException("height of SE ("+frameSE.getHeight(null)+") does not match height of N ("+sizeS+")");
176  }
177  if (frameNW.getWidth(null) != sizeW) {
178  throw new IllegalArgumentException("width of NW ("+frameNW.getWidth(null)+") does not match width of W");
179  }
180  if (frameNE.getWidth(null) != sizeE) {
181  throw new IllegalArgumentException("width of NE ("+frameNE.getWidth(null)+") does not match width of E");
182  }
183  if (frameSW.getWidth(null) != sizeW) {
184  throw new IllegalArgumentException("width of SW ("+frameSW.getWidth(null)+") does not match width of W");
185  }
186  if (frameSE.getWidth(null) != sizeE) {
187  throw new IllegalArgumentException("width of SE ("+frameSE.getWidth(null)+") does not match width of E");
188  }
189  final int contentWidth = frameC.getWidth(null);
190  final int contentHeight = frameC.getHeight(null);
191  if (frameN.getWidth(null) != contentWidth) {
192  throw new IllegalArgumentException("width of N ("+frameN.getWidth(null)+") does not match width of C ("+contentWidth+")");
193  }
194  if (frameS.getWidth(null) != contentWidth) {
195  throw new IllegalArgumentException("width of S ("+frameS.getWidth(null)+") does not match width of C ("+contentWidth+")");
196  }
197  if (frameW.getHeight(null) != contentHeight) {
198  throw new IllegalArgumentException("width of W ("+frameW.getHeight(null)+") does not match height of C ("+contentHeight+")");
199  }
200  if (frameE.getHeight(null) != contentHeight) {
201  throw new IllegalArgumentException("width of E ("+frameE.getHeight(null)+") does not match height of C ("+contentHeight+")");
202  }
203  this.titleFont = titleFont;
204  this.titleColor = titleColor;
205  final int intAlpha = (int)(255*frameAlpha);
206  this.titleBackgroundColor = intAlpha == 0 ? null : new Color(titleBackgroundColor.getRed(), titleBackgroundColor.getGreen(), titleBackgroundColor.getBlue(), intAlpha);
207  }
208 
217  @NotNull
218  public Iterable<AbstractGUIElement> newDialog(@NotNull final TooltipManager tooltipManager, @NotNull final JXCWindowRenderer windowRenderer, @NotNull final GUIElementListener elementListener, @NotNull final String title) {
219  final Collection<AbstractGUIElement> result = new ArrayList<>();
220  result.add(new GUIDialogBackground(tooltipManager, windowRenderer, elementListener, "dialog_background", frameAlpha, frameNW, frameN, frameNE, frameW, frameC, frameE, frameSW, frameS, frameSE, guiFactory));
221 
222  if (!title.isEmpty()) {
223  result.add(new GUIDialogTitle(tooltipManager, windowRenderer, elementListener, "dialog_title", titleFont, titleColor, titleBackgroundColor, title, guiFactory));
224  }
225 
226  return result;
227  }
228 
233  public float getFrameAlpha() {
234  return frameAlpha;
235  }
236 
237 }
com.realtime.crossfire.jxclient
com.realtime.crossfire.jxclient.skin.skin
Definition: DefaultJXCSkin.java:23
com.realtime.crossfire.jxclient.skin.factory.DialogFactory.newDialog
Iterable< AbstractGUIElement > newDialog(@NotNull final TooltipManager tooltipManager, @NotNull final JXCWindowRenderer windowRenderer, @NotNull final GUIElementListener elementListener, @NotNull final String title)
Definition: DialogFactory.java:218
com.realtime.crossfire.jxclient.skin
com.realtime.crossfire.jxclient.gui.misc.GUIDialogBackground
Definition: GUIDialogBackground.java:46
com.realtime.crossfire.jxclient.skin.skin.GuiFactory
Definition: GuiFactory.java:41
com.realtime.crossfire.jxclient.skin.factory.DialogFactory.titleFont
final Font titleFont
Definition: DialogFactory.java:103
com.realtime.crossfire.jxclient.skin.factory.DialogFactory.frameW
final Image frameW
Definition: DialogFactory.java:68
com.realtime.crossfire.jxclient.skin.factory.DialogFactory.getFrameAlpha
float getFrameAlpha()
Definition: DialogFactory.java:233
com.realtime.crossfire.jxclient.skin.factory.DialogFactory.frameNE
final Image frameNE
Definition: DialogFactory.java:62
com.realtime.crossfire.jxclient.gui.misc.JXCWindowRenderer
Definition: JXCWindowRenderer.java:87
com.realtime.crossfire.jxclient.skin.factory.DialogFactory.frameS
final Image frameS
Definition: DialogFactory.java:92
com.realtime.crossfire.jxclient.skin.factory.DialogFactory.frameAlpha
final float frameAlpha
Definition: DialogFactory.java:120
com.realtime.crossfire.jxclient.skin.factory.DialogFactory.titleBackgroundColor
final Color titleBackgroundColor
Definition: DialogFactory.java:114
com.realtime.crossfire.jxclient.gui
com.realtime.crossfire.jxclient.skin.factory.DialogFactory.frameSE
final Image frameSE
Definition: DialogFactory.java:98
com.realtime.crossfire.jxclient.skin.factory.DialogFactory.frameN
final Image frameN
Definition: DialogFactory.java:56
com.realtime.crossfire.jxclient.gui.gui.TooltipManager
Definition: TooltipManager.java:33
com.realtime.crossfire.jxclient.gui.gui
Definition: AbstractGUIElement.java:23
com.realtime.crossfire
com.realtime
com.realtime.crossfire.jxclient.skin.factory.DialogFactory.frameNW
final Image frameNW
Definition: DialogFactory.java:50
com.realtime.crossfire.jxclient.skin.factory.DialogFactory.frameSW
final Image frameSW
Definition: DialogFactory.java:86
com
com.realtime.crossfire.jxclient.skin.factory.DialogFactory.frameE
final Image frameE
Definition: DialogFactory.java:80
com.realtime.crossfire.jxclient.skin.factory.DialogFactory.frameC
final Image frameC
Definition: DialogFactory.java:74
com.realtime.crossfire.jxclient.gui.misc.GUIDialogTitle
Definition: GUIDialogTitle.java:43
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement
Definition: AbstractGUIElement.java:37
com.realtime.crossfire.jxclient.skin.factory.DialogFactory
Definition: DialogFactory.java:44
com.realtime.crossfire.jxclient.skin.factory.DialogFactory.titleColor
final Color titleColor
Definition: DialogFactory.java:108
com.realtime.crossfire.jxclient.gui.misc
Definition: GUICheckBox.java:23
com.realtime.crossfire.jxclient.skin.factory.DialogFactory.guiFactory
final GuiFactory guiFactory
Definition: DialogFactory.java:126
com.realtime.crossfire.jxclient.skin.factory.DialogFactory.DialogFactory
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, @NotNull final GuiFactory guiFactory)
Definition: DialogFactory.java:146
com.realtime.crossfire.jxclient.gui.gui.GUIElementListener
Definition: GUIElementListener.java:32