Gridarta Editor
ClosingListener.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.event.MouseAdapter;
23 import java.awt.event.MouseEvent;
24 import javax.swing.JTabbedPane;
25 import org.jetbrains.annotations.NotNull;
26 
27 public class ClosingListener extends MouseAdapter {
28 
32  @NotNull
33  private final JTabbedPane tabbedPane;
34 
39  public ClosingListener(@NotNull final JTabbedPane tabbedPane) {
40  this.tabbedPane = tabbedPane;
41  }
42 
46  @Override
47  public void mouseReleased(@NotNull final MouseEvent e) {
48  final int i = tabbedPane.getSelectedIndex();
49 
50  // nothing selected
51  if (i == -1) {
52  return;
53  }
54 
55  final ClosingIcon icon = (ClosingIcon) tabbedPane.getIconAt(i);
56 
57  // close tab, if icon was clicked
58  if (icon != null && icon.contains(e.getX(), e.getY())) {
59  tabbedPane.removeTabAt(i);
60  }
61  }
62 
63 }
net.sf.gridarta.gui.dialog.plugin.ClosingListener.tabbedPane
final JTabbedPane tabbedPane
Definition: ClosingListener.java:33
net.sf.gridarta.gui.dialog.plugin.ClosingListener
Definition: ClosingListener.java:27
net.sf.gridarta.gui.dialog.plugin.ClosingIcon.contains
boolean contains(final int xEvent, final int yEvent)
Definition: ClosingIcon.java:83
net.sf.gridarta.gui.dialog.plugin.ClosingListener.ClosingListener
ClosingListener(@NotNull final JTabbedPane tabbedPane)
Definition: ClosingListener.java:39
net.sf.gridarta.gui.dialog.plugin.ClosingListener.mouseReleased
void mouseReleased(@NotNull final MouseEvent e)
Definition: ClosingListener.java:47
net.sf.gridarta.gui.dialog.plugin.ClosingIcon
Definition: ClosingIcon.java:31