Crossfire JXClient, Trunk  R20561
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-2011 Andreas Kirschbaum.
20  */
21 
22 package com.realtime.crossfire.jxclient.gui.misc;
23 
30 import java.awt.Color;
31 import java.awt.Component;
32 import java.awt.Font;
33 import java.awt.Point;
34 import java.awt.event.MouseEvent;
35 import org.jetbrains.annotations.NotNull;
36 import org.jetbrains.annotations.Nullable;
37 
42 public class GUIDialogTitle extends GUIOneLineLabel {
43 
47  private static final long serialVersionUID = 1;
48 
52  @NotNull
54 
59  @Nullable
60  private Point offset;
61 
73  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) {
74  super(tooltipManager, elementListener, name, null, textFont, textColor, backgroundColor, Alignment.LEFT, title);
75  this.windowRenderer = windowRenderer;
76  }
77 
81  @Override
82  public void mousePressed(@NotNull final MouseEvent e) {
83  super.mousePressed(e);
84  final Component gui = GuiUtils.getGui(this);
85  if (gui == null) {
86  offset = null;
87  return;
88  }
89 
90  final Point point = e.getLocationOnScreen();
91  offset = new Point(gui.getX()-point.x, gui.getY()-point.y);
92  }
93 
97  @Override
98  public void mouseReleased(@NotNull final MouseEvent e) {
99  super.mouseReleased(e);
100  moveTo(e);
101  offset = null;
102  }
103 
107  @Override
108  public void mouseDragged(@NotNull final MouseEvent e) {
109  super.mouseDragged(e);
110  moveTo(e);
111  }
112 
117  private void moveTo(@NotNull final MouseEvent e) {
118  final Point tmpOffset = offset;
119  if (tmpOffset == null) {
120  return;
121  }
122 
123  final Gui gui = GuiUtils.getGui(this);
124  if (gui == null || gui.isAutoSize()) {
125  offset = null;
126  return;
127  }
128 
129  final Point point = e.getLocationOnScreen();
130  gui.showDialog(point.x+tmpOffset.x, point.y+tmpOffset.y, windowRenderer.getWindowWidth(), windowRenderer.getWindowHeight());
131  }
132 
133 }
static Gui getGui(@NotNull final Component element)
Returns the Gui an element is part of.
Definition: GuiUtils.java:91
A AbstractLabel that renders the text as a plain string.
final JXCWindowRenderer windowRenderer
The JXCWindowRenderer this element belongs to.
Combines a list of GUIElements to for a gui.
Definition: Gui.java:43
Point offset
Set to the distance of the dialog coordinates relative to the mouse position while dragging start...
final TooltipManager tooltipManager
The TooltipManager to update.
final Font textFont
The font for rendering the label text.
void showDialog(final int x, final int y, final int windowWidth, final int windowHeight)
Sets the position of a dialog but makes sure the dialog is fully visible.
Definition: Gui.java:569
final GUIElementListener elementListener
The GUIElementListener to notify.
int getWindowHeight()
Returns the height of the client area.
final Color backgroundColor
If set, the opaque background color.
void moveTo(@NotNull final MouseEvent e)
Moves the dialog the given point.
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)
Creates a new instance.
Utility class for Gui related functions.
Definition: GuiUtils.java:35
A dialog title that allows to move the dialog.
boolean isAutoSize()
Returns whether this dialog is an auto-size dialog.
Definition: Gui.java:159
static final long serialVersionUID
The serial version UID.
void mouseDragged(@NotNull final MouseEvent e)
Will be called when the mouse moves within this component while the button is pressed.This event will be delivered after mouseMoved(MouseEvent). Note: if the mouse leaves this element's bounding box while the mouse button is still pressed, furthermouseDragged (but nomouseMoved ) events will be generated. the mouse event relative to this element
int getWindowWidth()
Returns the width of the client area.
void mouseReleased(@NotNull final MouseEvent e)
Will be called when the user has released the mouse.This event may be delivered even if no previous m...
void mousePressed(@NotNull final MouseEvent e)
Will be called when the user has pressed the mouse inside this element.the mouse event relative to th...