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.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.ActivatableGUIElement.mousePressed
void mousePressed(@NotNull final MouseEvent e)
Definition: ActivatableGUIElement.java:88
com.realtime.crossfire.jxclient.skin
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement
Definition: ActivatableGUIElement.java:33
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.setInactiveIfPending
void setInactiveIfPending()
Definition: ActivatableGUIElement.java:105
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.next
ActivatableGUIElement next
Definition: ActivatableGUIElement.java:57
com.realtime.crossfire.jxclient.skin.skin.GuiFactory
Definition: GuiFactory.java:41
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.setNextActive
void setNextActive(@NotNull final ActivatableGUIElement next)
Definition: ActivatableGUIElement.java:154
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.setPrevActive
void setPrevActive(@NotNull final ActivatableGUIElement prev)
Definition: ActivatableGUIElement.java:162
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.serialVersionUID
static final long serialVersionUID
Definition: ActivatableGUIElement.java:38
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.activeChanged
abstract void activeChanged()
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.pendingInactive
boolean pendingInactive
Definition: ActivatableGUIElement.java:51
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.markInactivePending
void markInactivePending()
Definition: ActivatableGUIElement.java:98
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.elementListener
final GUIElementListener elementListener
Definition: ActivatableGUIElement.java:44
com.realtime.crossfire.jxclient.gui.gui.GUIElementListener.isActive
boolean isActive(@NotNull ActivatableGUIElement element)
com.realtime.crossfire.jxclient.gui.gui.TooltipManager
Definition: TooltipManager.java:33
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.activatePrevElement
void activatePrevElement()
Definition: ActivatableGUIElement.java:145
com.realtime.crossfire
com.realtime
com
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.activateNextElement
void activateNextElement()
Definition: ActivatableGUIElement.java:137
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.setActive
void setActive(final boolean active)
Definition: ActivatableGUIElement.java:115
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.execute
abstract void execute()
com.realtime.crossfire.jxclient.gui.gui.GUIElementListener.activeChanged
void activeChanged(@NotNull ActivatableGUIElement element, boolean active)
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.prev
ActivatableGUIElement prev
Definition: ActivatableGUIElement.java:63
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)
Definition: ActivatableGUIElement.java:73
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.GUIElementListener
Definition: GUIElementListener.java:32
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.tooltipManager
final TooltipManager tooltipManager
Definition: AbstractGUIElement.java:83
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.isActive
boolean isActive()
Definition: ActivatableGUIElement.java:124