Crossfire JXClient, Trunk  R20561
GUIItem.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.item;
23 
29 import java.awt.Transparency;
30 import java.awt.event.MouseEvent;
31 import org.jetbrains.annotations.NotNull;
32 
38 public abstract class GUIItem extends ActivatableGUIElement implements GUIScrollable {
39 
43  private static final long serialVersionUID = 1;
44 
51  protected GUIItem(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name) {
52  super(tooltipManager, elementListener, name, Transparency.TRANSLUCENT);
53  }
54 
58  @Override
59  public void mouseClicked(@NotNull final MouseEvent e) {
60  super.mouseClicked(e);
61  switch (e.getButton()) {
62  case MouseEvent.BUTTON1:
63  setActive(true);
64  button1Clicked(e.getModifiersEx());
65  break;
66 
67  case MouseEvent.BUTTON2:
68  button2Clicked(e.getModifiersEx());
69  break;
70 
71  case MouseEvent.BUTTON3:
72  button3Clicked(e.getModifiersEx());
73  break;
74  }
75  }
76 
80  @Override
81  public void execute() {
82  // ignore
83  }
84 
89  public abstract void button1Clicked(final int modifiers);
90 
95  public abstract void button2Clicked(final int modifiers);
96 
101  public abstract void button3Clicked(final int modifiers);
102 
106  @Override
107  public void activeChanged() {
108  setChanged();
109  }
110 
114  @Override
115  public void setVisible(final boolean aFlag) {
116  super.setVisible(aFlag);
117  setChanged();
118  }
119 
120 }
GUIItem(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name)
Creates a new instance.
Definition: GUIItem.java:51
final TooltipManager tooltipManager
The TooltipManager to update.
abstract void button1Clicked(final int modifiers)
Called when the left mouse button was pressed.
final GUIElementListener elementListener
The GUIElementListener to notify.
void setChanged()
Records that the contents have changed and must be repainted.
static final long serialVersionUID
The serial version UID.
Definition: GUIItem.java:43
A GUIElement representing an in-game object.
Definition: GUIItem.java:38
void setActive(final boolean active)
Sets the active state of a GUI element.
void mouseClicked(@NotNull final MouseEvent e)
Will be called when the user has clicked (pressed+released) this element.This event will be delivered...
Definition: GUIItem.java:59
abstract void button2Clicked(final int modifiers)
Called when the middle mouse button was pressed.
Interface defining an abstract GUI element.
Definition: GUIElement.java:32
A GUIElement that can be set to active or inactive.
abstract void button3Clicked(final int modifiers)
Called when the right mouse button was pressed.
Interface for GUIElements that support scrolling.