 |
Crossfire JXClient, Trunk
|
Go to the documentation of this file.
23 package com.realtime.crossfire.jxclient.gui.combobox;
34 import java.awt.Component;
35 import java.awt.Dimension;
36 import java.awt.event.ActionListener;
37 import java.util.List;
38 import java.util.regex.Pattern;
39 import javax.swing.DefaultComboBoxModel;
40 import javax.swing.JComboBox;
41 import javax.swing.JList;
42 import org.jetbrains.annotations.NotNull;
43 import org.jetbrains.annotations.Nullable;
73 private final DefaultComboBoxModel<T>
model =
new DefaultComboBoxModel<>();
110 comboBox.setRenderer(this::getListCellRendererComponent);
124 final Dimension result =
comboBox.getPreferredSize();
125 return result ==
null ? super.getPreferredSize() : result;
130 final Dimension result =
comboBox.getMinimumSize();
131 return result ==
null ? super.getMinimumSize() : result;
135 public void setBounds(
final int x,
final int y,
final int width,
final int height) {
136 super.setBounds(x, y, width, height);
146 if (elements ==
null) {
149 final int size =
model.getSize();
150 if (size == elements.size()) {
152 for (i = 0; i < size; i++) {
153 if (!
model.getElementAt(i).equals(elements.get(i))) {
163 setVisible(elements !=
null);
167 model.removeAllElements();
168 if (elements !=
null) {
169 for (T element : elements) {
170 model.addElement(element);
190 protected abstract Component
getListCellRendererComponent(@NotNull
final JList<? extends T> list, @Nullable
final T value,
final int index,
final boolean selected,
final boolean cellHasFocus);
200 @SuppressWarnings(
"unchecked")
final T item = (T)
comboBox.getSelectedItem();
236 @SuppressWarnings(
"unchecked")
final T item = (T)
comboBox.getSelectedItem();
238 if (text.isEmpty()) {
242 final StringBuilder sb =
new StringBuilder();
243 for (
final String line0 : text.split(
"\n")) {
244 final String line = line0.trim();
247 while (line.length() > index+80) {
248 int nextIndex = line.lastIndexOf(
' ', index+80);
249 if (nextIndex == -1) {
250 nextIndex = line.indexOf(
' ', index+80);
251 if (nextIndex == -1) {
252 nextIndex = line.length();
254 if (nextIndex > index+140) {
255 nextIndex = index+140;
258 sb.append(sb.isEmpty() ?
"<html>" :
"<br>").append(line, index, nextIndex);
261 while (index < line.length() && line.charAt(index) ==
' ') {
265 sb.append(sb.isEmpty() ?
"<html>" :
"<br>").append(line, index, line.length());
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.
void tooltipChanged()
Must be called whenever the tooltip may have changed.
static final int MSG_TYPE_JXCLIENT
Internally used drawextinfo message type: a message has been generated by the client.
Abstract base class for gui elements implementing text fields.
void dispose()
Releases all allocated resources.
void setChanged()
Records that the contents have changed and must be repainted.
Dimension getPreferredSize()
Abstract base class for GUI elements to be shown in Guis.
final ActionListener actionListener
The ActionListener for comboBox.
GUIComboBox(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, @Nullable final GUILabelLog label, @NotNull final GuiFactory guiFactory)
Creates a new instance.
static final int MSG_SUBTYPE_JXCLIENT_COMBOBOX
A text was generated by selecting an entry in a combobox.
final GUIElementListener elementListener
The GUIElementListener to notify.
final GUILabelLog label
The GUILog to update or.
Encapsulates the message type numbers for drawextinfo messages.
static final long serialVersionUID
The serial version UID.
boolean inhibitActionListener
If set, ignores calls to actionListener.
Dimension getMinimumSize()
void updateSelectedItem()
Called whenever the selected item has changed.
A GUIElement that displays a combo box.
void setBounds(final int x, final int y, final int width, final int height)
Interface defining an abstract GUI element.
abstract String getDescription(@Nullable T item)
Returns the description for an item.
final DefaultComboBoxModel< T > model
The model for comboBox.
static final Pattern PATTERN_BOLD_BEGIN
A Pattern that matches "[b]".
final GuiFactory guiFactory
The global GuiFactory instance.
TooltipText newTooltipText(@Nullable final String tooltipText)
Creates a TooltipText instance relative to this instance.
Information for displaying tooltips.
static final Pattern PATTERN_BOLD_END
A Pattern that matches "[/b]".
Factory for creating Gui instances.
final String name
The name of this element.
TooltipText getTooltip()
Returns the current tooltip text.
void updateModel(@Nullable final List< T > elements)
Updates entries shown in the combo box.
void setSelectedItem(@NotNull final T item)
Updates the selected item.
void updateText(@NotNull final CharSequence string, final int type, final int subtype)
Sets the displayed text by parsing a string.
final TooltipManager tooltipManager
The TooltipManager to update.
A gui element implementing a static text field which may contain media tags.
final JComboBox< T > comboBox
The Swing component that implements the combo box.
Listener for GUIElement related events.