Gridarta Editor
GList.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.utils;
21 
22 import java.awt.Rectangle;
23 import java.awt.event.MouseEvent;
24 import javax.swing.JList;
25 import javax.swing.ListModel;
26 import org.jetbrains.annotations.NotNull;
27 import org.jetbrains.annotations.Nullable;
28 
36 public class GList<T> extends JList<T> {
37 
41  private static final long serialVersionUID = 1L;
42 
47  @Nullable
49 
54  public GList(@NotNull final ListModel<T> dataModel) {
55  super(dataModel);
56  }
57 
63  public void setToolTipProvider(@Nullable final ToolTipProvider<T> toolTipProvider) {
64  this.toolTipProvider = toolTipProvider;
65  }
66 
67  @Nullable
68  @Override
69  public String getToolTipText(@NotNull final MouseEvent event) {
70  final int index = locationToIndex(event.getPoint());
71  if (index == -1) {
72  return super.getToolTipText(event);
73  }
74 
75  final Rectangle rectangle = getCellBounds(index, index);
76  if (!rectangle.contains(event.getPoint())) {
77  return super.getToolTipText(event);
78  }
79 
80  if (toolTipProvider == null) {
81  return super.getToolTipText(event);
82  }
83  return toolTipProvider.getToolTipText(getModel().getElementAt(index));
84  }
85 
86 }
GList(@NotNull final ListModel< T > dataModel)
Creates a new instance.
Definition: GList.java:54
ToolTipProvider< T > toolTipProvider
The ToolTipProvider for per-item tooltips.
Definition: GList.java:48
void setToolTipProvider(@Nullable final ToolTipProvider< T > toolTipProvider)
Sets or clears the ToolTipProvider.
Definition: GList.java:63
String getToolTipText(@NotNull T element)
Returns the tooltip text for an element.
String getToolTipText(@NotNull final MouseEvent event)
Definition: GList.java:69
Interface for classes providing per-item tooltip text for GList instances.
static final long serialVersionUID
The serial version UID.
Definition: GList.java:41
An extended JList.
Definition: GList.java:36