22 package com.realtime.crossfire.jxclient.gui.combobox;
30 import java.awt.Component;
31 import java.awt.Dimension;
32 import java.awt.Transparency;
33 import java.awt.event.ActionListener;
34 import javax.swing.DefaultComboBoxModel;
35 import javax.swing.JComboBox;
36 import javax.swing.JList;
37 import javax.swing.ListCellRenderer;
38 import org.jetbrains.annotations.NotNull;
39 import org.jetbrains.annotations.Nullable;
57 private final DefaultComboBoxModel<T>
model =
new DefaultComboBoxModel<>();
75 @SuppressWarnings(
"FieldCanBeLocal")
92 super(tooltipManager, elementListener, name, Transparency.TRANSLUCENT);
94 comboBox.setFocusable(
false);
114 final Dimension result = comboBox.getPreferredSize();
115 return result == null ? super.getPreferredSize() : result;
123 final Dimension result = comboBox.getMinimumSize();
124 return result == null ? super.getMinimumSize() : result;
131 public void setBounds(
final int x,
final int y,
final int width,
final int height) {
132 super.setBounds(x, y, width, height);
133 comboBox.setSize(width, height);
141 model.removeAllElements();
142 for (
final T element : elements) {
143 model.addElement(element);
157 protected abstract Component
getListCellRendererComponent(@NotNull
final JList<? extends T> list, @Nullable
final T value,
final int index,
final boolean selected,
final boolean cellHasFocus);
168 @SuppressWarnings(
"unchecked")
final T item = (T)comboBox.getSelectedItem();
Listener for GUIElement related events.
final JComboBox< T > comboBox
The Swing component that implements the combo box.
final TooltipManager tooltipManager
The TooltipManager to update.
final GUILabelLog label
The GUILog to update or.
void setChanged()
Records that the contents have changed and must be repainted.
void dispose()
Releases all allocated resources.
void updateModel(@NotNull final Iterable< T > elements)
Updates entries shown in the combo box.
final GUIElementListener elementListener
The GUIElementListener to notify.
Dimension getPreferredSize()
void updateText(@NotNull final CharSequence string)
Sets the displayed text by parsing a string.
Dimension getMinimumSize()
A gui element implementing a static text field which may contain media tags.
abstract Component getListCellRendererComponent(@NotNull final JList<? extends T > list, @Nullable final T value, final int index, final boolean selected, final boolean cellHasFocus)
Returns a Component that displays the.
final String name
The name of this element.
void setBounds(final int x, final int y, final int width, final int height)
Interface defining an abstract GUI element.
static final long serialVersionUID
The serial version UID.
final ListCellRenderer< T > renderer
The ListCellRenderer for comboBox.
abstract String getDescription(@NotNull T item)
Returns the description for an item.
void updateSelectedItem()
Called whenever the selected item has changed.
final DefaultComboBoxModel< T > model
The model for comboBox.
final ActionListener actionListener
The ActionListener for comboBox.
A GUIElement that displays a combo box.
Abstract base class for GUI elements to be shown in Guis.
Abstract base class for gui elements implementing text fields.