Crossfire JXClient, Trunk  R20561
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-2011 Andreas Kirschbaum.
20  */
21 
22 package com.realtime.crossfire.jxclient.gui.gui;
23 
24 import java.awt.event.MouseEvent;
25 import org.jetbrains.annotations.NotNull;
26 
31 public abstract class ActivatableGUIElement extends AbstractGUIElement {
32 
36  private static final long serialVersionUID = 1;
37 
41  @NotNull
43 
49  private boolean pendingInactive;
50 
58  protected ActivatableGUIElement(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, final int transparency) {
59  super(tooltipManager, elementListener, name, transparency);
60  this.elementListener = elementListener;
61  }
62 
66  protected abstract void activeChanged();
67 
72  @Override
73  public void mousePressed(@NotNull final MouseEvent e) {
74  setActive(true);
75  }
76 
80  protected void markInactivePending() {
81  pendingInactive = true;
82  }
83 
87  protected void setInactiveIfPending() {
88  if (pendingInactive) {
89  setActive(false);
90  }
91  }
92 
97  public void setActive(final boolean active) {
98  pendingInactive = false;
99  elementListener.activeChanged(this, active);
100  }
101 
106  public boolean isActive() {
107  return elementListener.isActive(this);
108  }
109 
114  public abstract void execute();
115 
116 }
final TooltipManager tooltipManager
The TooltipManager to update.
ActivatableGUIElement(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, final int transparency)
Creates a new instance.
final GUIElementListener elementListener
The GUIElementListener to notify.
void setActive(final boolean active)
Sets the active state of a GUI element.
void markInactivePending()
Marks this GUI element as pending inactive.
A GUIElement that can be set to active or inactive.
boolean isActive(@NotNull ActivatableGUIElement element)
Returns whether an ActivatableGUIElement is active.
void setInactiveIfPending()
Unsets the active state of this GUI element if is is pending.
void mousePressed(@NotNull final MouseEvent e)
Will be called when the user has pressed the mouse inside this element.
void activeChanged(@NotNull ActivatableGUIElement element, boolean active)
The active state of an AbstractGUIElement has changed.
Abstract base class for GUI elements to be shown in Guis.
abstract void activeChanged()
Will be called whenever the active state has changed.
boolean pendingInactive
Set if the next call to setInactiveIfPending() will deactivate this GUI element.
abstract void execute()
Executes the actions associated with this GUI element.
boolean isActive()
Returns whether a GUI element is active.