Package net.sf.freecol.client.gui
Class ChoiceItem<T>
- java.lang.Object
-
- net.sf.freecol.client.gui.ChoiceItem<T>
-
- Type Parameters:
T
- The type of the contained item.
- All Implemented Interfaces:
java.lang.Comparable<ChoiceItem<T>>
public class ChoiceItem<T> extends java.lang.Object implements java.lang.Comparable<ChoiceItem<T>>
Can be used as a single choice for theFreeColChoiceDialog
.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
enabled
private javax.swing.ImageIcon
icon
private T
object
private boolean
optionCancel
private boolean
optionDefault
private boolean
optionOK
private java.lang.String
text
-
Constructor Summary
Constructors Constructor Description ChoiceItem(java.lang.String text, T object)
Creates a newChoiceItem
with the given object.ChoiceItem(java.lang.String text, T object, boolean enable)
Creates a newChoiceItem
with the given object.ChoiceItem(T object)
Creates a newChoiceItem
with the given object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ChoiceItem<T>
cancelOption()
Make this choice the "cancel" option.int
compareTo(ChoiceItem<T> other)
ChoiceItem<T>
defaultOption()
Make this choice the default.boolean
equals(java.lang.Object o)
int
getChoice()
Gets the choice as anint
.javax.swing.ImageIcon
getIcon()
Get any icon associated with this choice.T
getObject()
Gets theObject
contained by this choice.int
hashCode()
boolean
isCancel()
Is this choice the "cancel" choice?boolean
isDefault()
Is this choice the default choice?boolean
isEnabled()
Should this item be enabled or not?boolean
isOK()
Is this choice the "OK" choice?ChoiceItem<T>
okOption()
Make this choice the "OK" option.ChoiceItem<T>
setIcon(javax.swing.ImageIcon icon)
Add an icon to this choice.java.lang.String
toString()
-
-
-
Field Detail
-
text
private java.lang.String text
-
object
private final T object
-
icon
private javax.swing.ImageIcon icon
-
enabled
private final boolean enabled
-
optionOK
private boolean optionOK
-
optionCancel
private boolean optionCancel
-
optionDefault
private boolean optionDefault
-
-
Constructor Detail
-
ChoiceItem
public ChoiceItem(java.lang.String text, T object, boolean enable)
Creates a newChoiceItem
with the given object.- Parameters:
text
- The text that should be used to represent this choice.object
- The object contained by this choice.enable
- Sets if the option should be enabled or not
-
ChoiceItem
public ChoiceItem(java.lang.String text, T object)
Creates a newChoiceItem
with the given object.- Parameters:
text
- The text that should be used to represent this choice.object
- The object contained by this choice.
-
ChoiceItem
public ChoiceItem(T object)
Creates a newChoiceItem
with the given object.- Parameters:
object
- The object contained by this choice.
-
-
Method Detail
-
getObject
public T getObject()
Gets theObject
contained by this choice.- Returns:
- The
Object
.
-
getChoice
public int getChoice()
Gets the choice as anint
.- Returns:
- The number representing this object.
- Throws:
java.lang.ClassCastException
- if theobject
is not anInteger
.
-
isEnabled
public boolean isEnabled()
Should this item be enabled or not?- Returns:
- The enable status.
-
getIcon
public javax.swing.ImageIcon getIcon()
Get any icon associated with this choice.- Returns:
- An icon if present, or null if not found.
-
setIcon
public ChoiceItem<T> setIcon(javax.swing.ImageIcon icon)
Add an icon to this choice.- Parameters:
icon
- TheImageIcon
to add.- Returns:
- This choice.
-
isOK
public boolean isOK()
Is this choice the "OK" choice?- Returns:
- True if this is the "OK" choice.
-
okOption
public ChoiceItem<T> okOption()
Make this choice the "OK" option.- Returns:
- This choice.
-
isCancel
public boolean isCancel()
Is this choice the "cancel" choice?- Returns:
- True if this is the "cancel" choice.
-
cancelOption
public ChoiceItem<T> cancelOption()
Make this choice the "cancel" option.- Returns:
- This choice.
-
isDefault
public boolean isDefault()
Is this choice the default choice?- Returns:
- True if this is the default choice.
-
defaultOption
public ChoiceItem<T> defaultOption()
Make this choice the default.- Returns:
- This choice.
-
compareTo
public int compareTo(ChoiceItem<T> other)
- Specified by:
compareTo
in interfacejava.lang.Comparable<T>
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-