Crossfire JXClient, Trunk
AbstractGUIElement.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.gui.gui;
24 
27 import java.awt.event.MouseEvent;
28 import javax.swing.JComponent;
29 import org.jetbrains.annotations.NotNull;
30 import org.jetbrains.annotations.Nullable;
31 
37 public abstract class AbstractGUIElement extends JComponent implements GUIElement {
38 
42  private static final long serialVersionUID = 1;
43 
47  @NotNull
48  private final GuiFactory guiFactory;
49 
54  @Nullable
56 
61  private boolean isDefault;
62 
66  private boolean inhibitListeners;
67 
71  private boolean ignore;
72 
76  @NotNull
77  private final String name;
78 
82  @NotNull
84 
88  @NotNull
90 
94  private boolean pendingChange;
95 
100  @NotNull
101  private final Runnable setChangedRunnable = new Runnable() {
102 
103  @Override
104  public void run() {
105  synchronized (setChangedRunnable) {
106  pendingChange = false;
107  if (inhibitListeners) {
108  return;
109  }
110  }
111  final Gui parent = guiFactory.getGui(AbstractGUIElement.this);
112  if (parent != null) {
113  parent.repaint();
114  }
115  if (isVisible() && changedListener != null) {
117  }
118  }
119 
120  };
121 
130  protected AbstractGUIElement(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, final boolean opaque, @NotNull final GuiFactory guiFactory) {
131  this.guiFactory = guiFactory;
132  setDoubleBuffered(false);
133  this.tooltipManager = tooltipManager;
134  this.elementListener = elementListener;
135  this.name = name;
136  setOpaque(opaque);
137  setFocusable(false);
138  }
139 
140  @Override
141  public void dispose() {
142  }
143 
144  @NotNull
145  @Override
146  @SuppressWarnings("MethodDoesntCallSuperMethod")
147  public String toString() {
148  return name;
149  }
150 
151  @Override
152  public boolean isDefault() {
153  return isDefault;
154  }
155 
156  @Override
157  public void setDefault(final boolean isDefault) {
158  this.isDefault = isDefault;
159  }
160 
161  @Override
162  public void setIgnore() {
163  ignore = true;
164  }
165 
166  @Override
167  public boolean isIgnore() {
168  return ignore;
169  }
170 
171  @NotNull
172  @Override
173  @SuppressWarnings("MethodDoesntCallSuperMethod")
174  public String getName() {
175  return name;
176  }
177 
178  @Override
179  public void mouseClicked(@NotNull final MouseEvent e) {
180  if (isEnabled()) {
182  }
183  }
184 
185  @Override
186  public void mouseEntered(@NotNull final MouseEvent e) {
187  if (isEnabled()) {
189  }
190  }
191 
192  @Override
193  public void mouseExited(@NotNull final MouseEvent e) {
194  if (isEnabled()) {
196  }
197  }
198 
199  @Override
200  public void mousePressed(@NotNull final MouseEvent e) {
201  if (isEnabled()) {
203  }
204  }
205 
206  @Override
207  public void mouseReleased(@NotNull final MouseEvent e) {
208  }
209 
210  @Override
211  public void mouseMoved(@NotNull final MouseEvent e) {
212  }
213 
214  @Override
215  public void mouseDragged(@NotNull final MouseEvent e) {
216  }
217 
218  @Override
219  public void mouseWheelMoved(final int wheelRotation) {
220  }
221 
222  @Override
223  public void setChanged() {
224  synchronized (setChangedRunnable) {
225  if (!inhibitListeners && !pendingChange) {
226  pendingChange = true;
228  }
229  }
230  }
231 
236  @Nullable
237  public abstract TooltipText getTooltip();
238 
246  @Nullable
247  protected TooltipText newTooltipText(@Nullable final String tooltipText) {
248  if (tooltipText == null) {
249  return null;
250  }
251 
252  final Gui gui = guiFactory.getGui(this);
253  if (gui == null) {
254  return null;
255  }
256 
257  return new TooltipText(tooltipText, gui.getComponent().getX()+getX(), gui.getComponent().getY()+getY(), getWidth(), getHeight());
258 
259  }
260 
265  protected void tooltipChanged() {
266  if (isEnabled()) {
268  }
269  }
270 
271  @Override
273  this.changedListener = changedListener;
274  }
275 
279  public void inhibitListeners() {
280  synchronized (setChangedRunnable) {
281  inhibitListeners = true;
282  }
283  }
284 
289  public int getDialogBorderTop() {
290  return 0;
291  }
292 
297  public int getDialogBorderLeft() {
298  return 0;
299  }
300 
305  public int getDialogBorderRight() {
306  return 0;
307  }
308 
313  public int getDialogBorderBottom() {
314  return 0;
315  }
316 
317 }
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.newTooltipText
TooltipText newTooltipText(@Nullable final String tooltipText)
Definition: AbstractGUIElement.java:247
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.ignore
boolean ignore
Definition: AbstractGUIElement.java:71
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.name
final String name
Definition: AbstractGUIElement.java:77
com.realtime.crossfire.jxclient
com.realtime.crossfire.jxclient.skin.skin
Definition: DefaultJXCSkin.java:23
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.isDefault
boolean isDefault()
Definition: AbstractGUIElement.java:152
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.getTooltip
abstract TooltipText getTooltip()
com.realtime.crossfire.jxclient.gui.gui.Gui
Definition: Gui.java:49
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.setIgnore
void setIgnore()
Definition: AbstractGUIElement.java:162
com.realtime.crossfire.jxclient.gui.gui.GUIElementListener.raiseDialog
void raiseDialog(@NotNull AbstractGUIElement component)
com.realtime.crossfire.jxclient.skin
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.getDialogBorderBottom
int getDialogBorderBottom()
Definition: AbstractGUIElement.java:313
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.getDialogBorderRight
int getDialogBorderRight()
Definition: AbstractGUIElement.java:305
com.realtime.crossfire.jxclient.gui.gui.GUIElementChangedListener
Definition: GUIElementChangedListener.java:30
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.dispose
void dispose()
Definition: AbstractGUIElement.java:141
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.changedListener
GUIElementChangedListener changedListener
Definition: AbstractGUIElement.java:55
com.realtime.crossfire.jxclient.skin.skin.GuiFactory
Definition: GuiFactory.java:41
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.isIgnore
boolean isIgnore()
Definition: AbstractGUIElement.java:167
com.realtime.crossfire.jxclient.gui.gui.TooltipManager.tooltipTextChanged
void tooltipTextChanged(@NotNull GUIElement element)
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.tooltipChanged
void tooltipChanged()
Definition: AbstractGUIElement.java:265
com.realtime.crossfire.jxclient.gui.gui.GUIElementChangedListener.notifyChanged
void notifyChanged()
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.mouseClicked
void mouseClicked(@NotNull final MouseEvent e)
Definition: AbstractGUIElement.java:179
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.pendingChange
boolean pendingChange
Definition: AbstractGUIElement.java:94
com.realtime.crossfire.jxclient.skin.skin.GuiFactory.getGui
Gui getGui(@NotNull final AbstractGUIElement element)
Definition: GuiFactory.java:110
com.realtime.crossfire.jxclient.gui.gui.Gui.repaint
void repaint()
Definition: Gui.java:707
com.realtime.crossfire.jxclient.gui.gui.TooltipManager.unsetElement
void unsetElement(@NotNull AbstractGUIElement guiElement)
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.mouseMoved
void mouseMoved(@NotNull final MouseEvent e)
Definition: AbstractGUIElement.java:211
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.mouseExited
void mouseExited(@NotNull final MouseEvent e)
Definition: AbstractGUIElement.java:193
com.realtime.crossfire.jxclient.gui.gui.Gui.getComponent
JComponent getComponent()
Definition: Gui.java:161
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.serialVersionUID
static final long serialVersionUID
Definition: AbstractGUIElement.java:42
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.mouseReleased
void mouseReleased(@NotNull final MouseEvent e)
Definition: AbstractGUIElement.java:207
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.setChangedRunnable
final Runnable setChangedRunnable
Definition: AbstractGUIElement.java:101
com.realtime.crossfire.jxclient.util
Definition: Codec.java:23
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.elementListener
final GUIElementListener elementListener
Definition: AbstractGUIElement.java:89
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.AbstractGUIElement
AbstractGUIElement(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, final boolean opaque, @NotNull final GuiFactory guiFactory)
Definition: AbstractGUIElement.java:130
com.realtime.crossfire.jxclient.gui.gui.TooltipManager
Definition: TooltipManager.java:33
com.realtime.crossfire.jxclient.gui.gui.GUIElement
Definition: GUIElement.java:33
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.getDialogBorderTop
int getDialogBorderTop()
Definition: AbstractGUIElement.java:289
com.realtime.crossfire.jxclient.util.SwingUtilities2.invokeLater
static void invokeLater(@NotNull final Runnable runnable)
Definition: SwingUtilities2.java:73
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.setDefault
void setDefault(final boolean isDefault)
Definition: AbstractGUIElement.java:157
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.isDefault
boolean isDefault
Definition: AbstractGUIElement.java:61
com.realtime.crossfire.jxclient.gui.gui.TooltipText
Definition: TooltipText.java:31
com.realtime.crossfire
com.realtime
com
com.realtime.crossfire.jxclient.util.SwingUtilities2
Definition: SwingUtilities2.java:34
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.mousePressed
void mousePressed(@NotNull final MouseEvent e)
Definition: AbstractGUIElement.java:200
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.mouseWheelMoved
void mouseWheelMoved(final int wheelRotation)
Definition: AbstractGUIElement.java:219
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.setChangedListener
void setChangedListener(@Nullable final GUIElementChangedListener changedListener)
Definition: AbstractGUIElement.java:272
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.inhibitListeners
boolean inhibitListeners
Definition: AbstractGUIElement.java:66
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.setChanged
void setChanged()
Definition: AbstractGUIElement.java:223
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.getName
String getName()
Definition: AbstractGUIElement.java:174
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement
Definition: AbstractGUIElement.java:37
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.guiFactory
final GuiFactory guiFactory
Definition: AbstractGUIElement.java:48
com.realtime.crossfire.jxclient.gui.gui.TooltipManager.setElement
void setElement(@NotNull AbstractGUIElement guiElement)
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.inhibitListeners
void inhibitListeners()
Definition: AbstractGUIElement.java:279
com.realtime.crossfire.jxclient.gui.gui.GUIElementListener
Definition: GUIElementListener.java:32
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.toString
String toString()
Definition: AbstractGUIElement.java:147
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.tooltipManager
final TooltipManager tooltipManager
Definition: AbstractGUIElement.java:83
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.mouseDragged
void mouseDragged(@NotNull final MouseEvent e)
Definition: AbstractGUIElement.java:215
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.mouseEntered
void mouseEntered(@NotNull final MouseEvent e)
Definition: AbstractGUIElement.java:186
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.getDialogBorderLeft
int getDialogBorderLeft()
Definition: AbstractGUIElement.java:297