Gridarta Editor
ClosingIcon.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2015 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.gui.dialog.plugin;
21 
22 import java.awt.Component;
23 import java.awt.Graphics;
24 import javax.swing.Icon;
25 import org.jetbrains.annotations.NotNull;
26 
31 public class ClosingIcon implements Icon {
32 
33  @NotNull
34  private final Icon icon;
35 
36  private int x;
37 
38  private int y;
39 
40  private final int height;
41 
42  private final int width;
43 
44  public ClosingIcon(@NotNull final Icon icon) {
45  this.icon = icon;
46  height = icon.getIconHeight();
47  width = icon.getIconWidth();
48  }
49 
50  @Override
51  public int getIconHeight() {
52  return height;
53  }
54 
55  @Override
56  public int getIconWidth() {
57  return width;
58  }
59 
64  @Override
65  public void paintIcon(@NotNull final Component c, @NotNull final Graphics g, final int x, final int y) {
66  this.x = x;
67  this.y = y;
68  icon.paintIcon(c, g, x, y + 1);
69  }
70 
83  public boolean contains(final int xEvent, final int yEvent) {
84  return x <= xEvent && xEvent <= x + width && y <= yEvent && yEvent <= y + height;
85  }
86 
87 }
the idea for this class stems from limewire&#39;s CancelSearchIconProxy class, thanks for going open sour...
boolean contains(final int xEvent, final int yEvent)
Returns whether.
void paintIcon(@NotNull final Component c, @NotNull final Graphics g, final int x, final int y)
Overwrites paintIcon to get hold of the coordinates of the icon, this is a rather rude approach just ...