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 booleanenabledprivate javax.swing.ImageIconiconprivate Tobjectprivate booleanoptionCancelprivate booleanoptionDefaultprivate booleanoptionOKprivate java.lang.Stringtext
-
Constructor Summary
Constructors Constructor Description ChoiceItem(java.lang.String text, T object)Creates a newChoiceItemwith the given object.ChoiceItem(java.lang.String text, T object, boolean enable)Creates a newChoiceItemwith the given object.ChoiceItem(T object)Creates a newChoiceItemwith 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.intcompareTo(ChoiceItem<T> other)ChoiceItem<T>defaultOption()Make this choice the default.booleanequals(java.lang.Object o)intgetChoice()Gets the choice as anint.javax.swing.ImageIcongetIcon()Get any icon associated with this choice.TgetObject()Gets theObjectcontained by this choice.inthashCode()booleanisCancel()Is this choice the "cancel" choice?booleanisDefault()Is this choice the default choice?booleanisEnabled()Should this item be enabled or not?booleanisOK()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.StringtoString()
-
-
-
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 newChoiceItemwith 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 newChoiceItemwith 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 newChoiceItemwith the given object.- Parameters:
object- The object contained by this choice.
-
-
Method Detail
-
getObject
public T getObject()
Gets theObjectcontained 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 theobjectis 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- TheImageIconto 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:
compareToin interfacejava.lang.Comparable<T>
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-