Crossfire JXClient, Trunk
GUIDialogTitle.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.misc;
24 
31 import java.awt.Color;
32 import java.awt.Font;
33 import java.awt.Point;
34 import java.awt.event.MouseEvent;
35 import javax.swing.JComponent;
36 import org.jetbrains.annotations.NotNull;
37 import org.jetbrains.annotations.Nullable;
38 
43 public class GUIDialogTitle extends GUIOneLineLabel {
44 
48  private static final long serialVersionUID = 1;
49 
53  @NotNull
55 
59  @NotNull
60  private final GuiFactory guiFactory;
61 
66  @Nullable
67  private Point offset;
68 
81  public GUIDialogTitle(@NotNull final TooltipManager tooltipManager, @NotNull final JXCWindowRenderer windowRenderer, @NotNull final GUIElementListener elementListener, @NotNull final String name, @NotNull final Font textFont, @NotNull final Color textColor, @Nullable final Color backgroundColor, @NotNull final String title, @NotNull final GuiFactory guiFactory) {
83  this.windowRenderer = windowRenderer;
84  this.guiFactory = guiFactory;
85  }
86 
87  @Override
88  public void mousePressed(@NotNull final MouseEvent e) {
89  super.mousePressed(e);
90 
91  if (!isEnabled()) {
92  return;
93  }
94 
95  final Gui gui = guiFactory.getGui(this);
96  if (gui == null) {
97  offset = null;
98  return;
99  }
100 
101  final Point point = e.getLocationOnScreen();
102  offset = new Point(gui.getComponent().getX()-point.x, gui.getComponent().getY()-point.y);
103  }
104 
105  @Override
106  public void mouseReleased(@NotNull final MouseEvent e) {
107  super.mouseReleased(e);
108  if (isEnabled()) {
109  moveTo(e);
110  offset = null;
111  }
112  }
113 
114  @Override
115  public void mouseDragged(@NotNull final MouseEvent e) {
116  super.mouseDragged(e);
117  if (isEnabled()) {
118  moveTo(e);
119  }
120  }
121 
126  private void moveTo(@NotNull final MouseEvent e) {
127  final Point tmpOffset = offset;
128  if (tmpOffset == null) {
129  return;
130  }
131 
132  final Gui gui = guiFactory.getGui(this);
133  if (gui == null || gui.isAutoSize()) {
134  offset = null;
135  return;
136  }
137 
138  final Point point = e.getLocationOnScreen();
139  final JComponent component = gui.getComponent();
140  gui.setBounds(point.x+tmpOffset.x, point.y+tmpOffset.y, component.getWidth(), component.getHeight(), windowRenderer.getWindowWidth(), windowRenderer.getWindowHeight());
141  }
142 
143 }
com.realtime.crossfire.jxclient.gui.misc.GUIDialogTitle.mouseDragged
void mouseDragged(@NotNull final MouseEvent e)
Definition: GUIDialogTitle.java:115
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.Gui.isAutoSize
boolean isAutoSize()
Definition: Gui.java:179
com.realtime.crossfire.jxclient.gui.gui.Gui
Definition: Gui.java:49
com.realtime.crossfire.jxclient.gui.misc.GUIDialogTitle.guiFactory
final GuiFactory guiFactory
Definition: GUIDialogTitle.java:60
com.realtime.crossfire.jxclient.skin
com.realtime.crossfire.jxclient.gui.label
Definition: AbstractLabel.java:23
com.realtime.crossfire.jxclient.gui.gui.Gui.setBounds
void setBounds(final int x, final int y, final int width, final int height, final int windowWidth, final int windowHeight)
Definition: Gui.java:662
com.realtime.crossfire.jxclient.skin.skin.GuiFactory
Definition: GuiFactory.java:41
com.realtime.crossfire.jxclient.gui.misc.GUIDialogTitle.mousePressed
void mousePressed(@NotNull final MouseEvent e)
Definition: GUIDialogTitle.java:88
com.realtime.crossfire.jxclient.gui.label.Alignment
Definition: Alignment.java:29
com.realtime.crossfire.jxclient.gui.misc.GUIDialogTitle.mouseReleased
void mouseReleased(@NotNull final MouseEvent e)
Definition: GUIDialogTitle.java:106
com.realtime.crossfire.jxclient.gui.label.AbstractLabel.textFont
final Font textFont
Definition: AbstractLabel.java:60
com.realtime.crossfire.jxclient.gui.misc.GUIDialogTitle.windowRenderer
final JXCWindowRenderer windowRenderer
Definition: GUIDialogTitle.java:54
com.realtime.crossfire.jxclient.gui.misc.JXCWindowRenderer
Definition: JXCWindowRenderer.java:87
com.realtime.crossfire.jxclient.skin.skin.GuiFactory.getGui
Gui getGui(@NotNull final AbstractGUIElement element)
Definition: GuiFactory.java:110
com.realtime.crossfire.jxclient.gui.misc.GUIDialogTitle.offset
Point offset
Definition: GUIDialogTitle.java:67
com.realtime.crossfire.jxclient.gui.gui.Gui.getComponent
JComponent getComponent()
Definition: Gui.java:161
com.realtime.crossfire.jxclient.gui.label.AbstractLabel.backgroundColor
final Color backgroundColor
Definition: AbstractLabel.java:85
com.realtime.crossfire.jxclient.gui.misc.GUIDialogTitle.serialVersionUID
static final long serialVersionUID
Definition: GUIDialogTitle.java:48
com.realtime.crossfire.jxclient.gui
com.realtime.crossfire.jxclient.gui.label.Alignment.LEFT
LEFT
Definition: Alignment.java:34
com.realtime.crossfire.jxclient.gui.misc.JXCWindowRenderer.getWindowHeight
int getWindowHeight()
Definition: JXCWindowRenderer.java:1116
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.elementListener
final GUIElementListener elementListener
Definition: AbstractGUIElement.java:89
com.realtime.crossfire.jxclient.gui.gui.TooltipManager
Definition: TooltipManager.java:33
com.realtime.crossfire.jxclient.gui.gui
Definition: AbstractGUIElement.java:23
com.realtime.crossfire.jxclient.gui.misc.GUIDialogTitle.GUIDialogTitle
GUIDialogTitle(@NotNull final TooltipManager tooltipManager, @NotNull final JXCWindowRenderer windowRenderer, @NotNull final GUIElementListener elementListener, @NotNull final String name, @NotNull final Font textFont, @NotNull final Color textColor, @Nullable final Color backgroundColor, @NotNull final String title, @NotNull final GuiFactory guiFactory)
Definition: GUIDialogTitle.java:81
com.realtime.crossfire
com.realtime
com
com.realtime.crossfire.jxclient.gui.misc.GUIDialogTitle
Definition: GUIDialogTitle.java:43
com.realtime.crossfire.jxclient.gui.label.AbstractLabel.textColor
final Color textColor
Definition: AbstractLabel.java:66
com.realtime.crossfire.jxclient.gui.misc.JXCWindowRenderer.getWindowWidth
int getWindowWidth()
Definition: JXCWindowRenderer.java:1108
com.realtime.crossfire.jxclient.gui.misc.GUIDialogTitle.moveTo
void moveTo(@NotNull final MouseEvent e)
Definition: GUIDialogTitle.java:126
com.realtime.crossfire.jxclient.gui.label.GUIOneLineLabel
Definition: GUIOneLineLabel.java:43
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