Crossfire JXClient, Trunk
ActivatableGUIElement.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 
26 import java.awt.event.MouseEvent;
27 import org.jetbrains.annotations.NotNull;
28 
33 public abstract class ActivatableGUIElement extends AbstractGUIElement {
34 
38  private static final long serialVersionUID = 1;
39 
43  @NotNull
45 
51  private boolean pendingInactive;
52 
56  @NotNull
57  private ActivatableGUIElement next = this;
58 
62  @NotNull
63  private ActivatableGUIElement prev = this;
64 
73  protected ActivatableGUIElement(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, final boolean opaque, @NotNull final GuiFactory guiFactory) {
75  this.elementListener = elementListener;
76  }
77 
81  protected abstract void activeChanged();
82 
87  @Override
88  public void mousePressed(@NotNull final MouseEvent e) {
89  super.mousePressed(e);
90  if (isEnabled()) {
91  setActive(true);
92  }
93  }
94 
98  protected void markInactivePending() {
99  pendingInactive = true;
100  }
101 
105  protected void setInactiveIfPending() {
106  if (pendingInactive) {
107  setActive(false);
108  }
109  }
110 
115  public void setActive(final boolean active) {
116  pendingInactive = false;
117  elementListener.activeChanged(this, active);
118  }
119 
124  public boolean isActive() {
125  return elementListener.isActive(this);
126  }
127 
132  public abstract void execute();
133 
137  public void activateNextElement() {
138  setActive(false);
139  next.setActive(true);
140  }
141 
145  public void activatePrevElement() {
146  setActive(false);
147  prev.setActive(true);
148  }
149 
154  public void setNextActive(@NotNull final ActivatableGUIElement next) {
155  this.next = next;
156  }
157 
162  public void setPrevActive(@NotNull final ActivatableGUIElement prev) {
163  this.prev = prev;
164  }
165 
166 }
com.realtime.crossfire.jxclient
com.realtime.crossfire.jxclient.skin.skin
Definition: DefaultJXCSkin.java:23
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.activeChanged
abstract void activeChanged()
Will be called whenever the active state has changed.
com.realtime.crossfire.jxclient.skin
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.prev
ActivatableGUIElement prev
The previous activatable GUI element in the same dialog.
Definition: ActivatableGUIElement.java:63
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.execute
abstract void execute()
Executes the actions associated with this GUI element.
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.activateNextElement
void activateNextElement()
Activates the following element.
Definition: ActivatableGUIElement.java:137
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement
Abstract base class for GUI elements to be shown in Guis.
Definition: AbstractGUIElement.java:37
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement
A GUIElement that can be set to active or inactive.
Definition: ActivatableGUIElement.java:33
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.ActivatableGUIElement
ActivatableGUIElement(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, final boolean opaque, @NotNull final GuiFactory guiFactory)
Creates a new instance.
Definition: ActivatableGUIElement.java:73
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.pendingInactive
boolean pendingInactive
Set if the next call to setInactiveIfPending() will deactivate this GUI element.
Definition: ActivatableGUIElement.java:51
com.realtime.crossfire.jxclient.gui.gui.GUIElementListener.isActive
boolean isActive(@NotNull ActivatableGUIElement element)
Returns whether an ActivatableGUIElement is active.
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.setPrevActive
void setPrevActive(@NotNull final ActivatableGUIElement prev)
Sets the previous activatable GUI element in the same dialog.
Definition: ActivatableGUIElement.java:162
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.isActive
boolean isActive()
Returns whether a GUI element is active.
Definition: ActivatableGUIElement.java:124
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.next
ActivatableGUIElement next
The next activatable GUI element in the same dialog.
Definition: ActivatableGUIElement.java:57
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.mousePressed
void mousePressed(@NotNull final MouseEvent e)
Will be called when the user has pressed the mouse inside this element.
Definition: ActivatableGUIElement.java:88
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.markInactivePending
void markInactivePending()
Marks this GUI element as pending inactive.
Definition: ActivatableGUIElement.java:98
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.setNextActive
void setNextActive(@NotNull final ActivatableGUIElement next)
Sets the next activatable GUI element in the same dialog.
Definition: ActivatableGUIElement.java:154
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.activatePrevElement
void activatePrevElement()
Activates the previous element.
Definition: ActivatableGUIElement.java:145
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.guiFactory
final GuiFactory guiFactory
The global GuiFactory instance.
Definition: AbstractGUIElement.java:48
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.elementListener
final GUIElementListener elementListener
The GUIElementListener to notify.
Definition: ActivatableGUIElement.java:44
com.realtime.crossfire.jxclient.skin.skin.GuiFactory
Factory for creating Gui instances.
Definition: GuiFactory.java:41
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.name
final String name
The name of this element.
Definition: AbstractGUIElement.java:77
com.realtime.crossfire.jxclient.gui.gui.GUIElementListener.activeChanged
void activeChanged(@NotNull ActivatableGUIElement element, boolean active)
The active state of an AbstractGUIElement has changed.
com.realtime.crossfire
com.realtime.crossfire.jxclient.gui.gui.TooltipManager
Manages the tooltip display.
Definition: TooltipManager.java:33
com.realtime
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.serialVersionUID
static final long serialVersionUID
The serial version UID.
Definition: ActivatableGUIElement.java:38
com
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.tooltipManager
final TooltipManager tooltipManager
The TooltipManager to update.
Definition: AbstractGUIElement.java:83
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.setActive
void setActive(final boolean active)
Sets the active state of a GUI element.
Definition: ActivatableGUIElement.java:115
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.setInactiveIfPending
void setInactiveIfPending()
Unsets the active state of this GUI element if it is pending.
Definition: ActivatableGUIElement.java:105
com.realtime.crossfire.jxclient.gui.gui.GUIElementListener
Listener for GUIElement related events.
Definition: GUIElementListener.java:32