22 package com.realtime.crossfire.jxclient.gui.list;
33 import java.awt.event.MouseEvent;
34 import javax.swing.JList;
35 import javax.swing.SwingUtilities;
36 import org.jetbrains.annotations.NotNull;
37 import org.jetbrains.annotations.Nullable;
92 super(tooltipManager, elementListener, name, cellWidth, cellHeight,
new ItemItemCellRenderer<>(templateItem), null);
96 this.itemView.addLocationsListener(locationsListener);
113 private void rebuildList(@Nullable
final Integer[] changedSlots) {
114 synchronized (getTreeLock()) {
115 final int newSize = itemView.
getSize();
117 if (oldSize < newSize) {
118 for (
int i = oldSize; i < newSize; i++) {
121 item.setChangedListener(itemChangedListener);
137 private void setChanged(@Nullable
final Integer[] changedSlots,
final int limit) {
138 if (changedSlots == null) {
139 for (
int i = 0; i < limit; i++) {
143 for (
final int i : changedSlots) {
164 if (currentItem != null) {
173 if (tooltipText3.isEmpty()) {
174 currentItem.
setText(tooltipText1+
" "+tooltipText3);
176 currentItem.
setText(tooltipText1+
" ["+tooltipText2+
"] "+tooltipText3);
187 protected void updateTooltip(
final int index,
final int x,
final int y,
final int w,
final int h) {
189 setTooltipText(item == null ? null : item.
getTooltipText(), x, y, w, h);
204 super.mouseClicked(e);
205 switch (e.getButton()) {
206 case MouseEvent.BUTTON1:
211 case MouseEvent.BUTTON2:
215 case MouseEvent.BUTTON3:
227 if (guiItem == null) {
240 if (guiItem == null) {
253 if (guiItem == null) {
275 protected abstract T
newItem(
final int index);
Listener for GUIElement related events.
String getTooltipText1()
Returns the first line of the tooltip text.
Abstract base class for all label classes.
String getTooltipText()
Returns a description suitable for a tooltip text.
void setText(@NotNull final String text)
The label text.
void rebuildList(@Nullable final Integer[] changedSlots)
Rebuilds the list cells.
GUIItemItem getSelectedItem()
Returns the selected GUIItemItem instance.
abstract void button1Clicked(final int modifiers)
Called when the left mouse button was pressed.
final int cellHeight
The height of a list cell in pixels.
void updateTooltip(final int index, final int x, final int y, final int w, final int h)
A ListCellRenderer that renders GUIMetaElement instances.
void setLayoutOrientation(final int layoutOrientation, final int visibleRowCount)
Sets the layout orientation.
String getTooltipText3()
Returns the third line of the tooltip text.
void setChanged(@Nullable final Integer[] changedSlots, final int limit)
Marks some slots as modified.
GUIItemList(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, final int cellWidth, final int cellHeight, @NotNull final ItemView itemView, @Nullable final AbstractLabel currentItem, @NotNull final GUIItemItem templateItem)
Creates a new instance.
void button3Clicked(final int modifiers)
Called if the user has clicked the right mouse button.
void button2Clicked(final int modifiers)
Called if the user has clicked the middle mouse button.
A GUIElement instance representing an in-game item.
T getElement(final int index)
Returns the GUIElement for a given index.
void removeLocationsListener(@NotNull LocationsListener locationsListener)
Removes a LocationsListener to be notified when any displayed item has changed.
void mouseClicked(@NotNull final MouseEvent e)
abstract void button2Clicked(final int modifiers)
Called when the middle mouse button was pressed.
Interface defining an abstract GUI element.
int resizeElements(final int newSize)
Changes the number of list elements.
final ItemView itemView
The ItemView to monitor.
Interface for listeners interested in changed item locations.
final GUIElementChangedListener itemChangedListener
The GUIElementChangedListener attached to all GUIItemItem instances in the list.
abstract void button3Clicked(final int modifiers)
Called when the right mouse button was pressed.
void addElement( @NotNull final T element)
Adds an GUIElement to the list.
void setChanged(final int index)
Marks one slot as modified.
A GUIList instance that displays GUIItemItem instances.
void setTooltipText(@Nullable final String tooltipText)
Sets the tooltip text to show when the mouse is inside this element.the text to show ornull to disab...
int getSize()
Returns the number of items.
String getTooltipText2()
Returns the second line of the tooltip text.
void selectionChanged()
Called whenever the selected list entry has changed.
void selectionChanged(final int selectedIndex)
Interface for listeners interested in the changed flag of GUIElement instances.
CfItem getItem(int index)
Returns the CfItem in a given slot.
abstract T newItem(final int index)
Creates a new GUIElement instance.
Object getSelectedObject()
Returns the selected list object.
static final long serialVersionUID
The serial version UID.
void button1Clicked(final int modifiers)
Called if the user has clicked the left mouse button.
The representation of a Crossfire Item, client-side.
final LocationsListener locationsListener
The LocationsListener to be notified about changes.
A GUIElement that displays a list of entries.
final AbstractLabel currentItem
The label to update with information about the selected item.