This PR adds a new method to GenericDialog for adding enum-based choices to dialogs. The existing method void addEnumChoice(String label, E defaultItem) includes all items defined by an enum class in the list of choices. While this creates very simple and elegant code, I found that this is not always desirable. Therefore, the new method
void addEnumChoice(String label, E[] enumArray, E defaultItem)
includes only a subset of the available enum items, as specified in enumArray. Note that its signature is completely analogous to the original string-based method addChoice(String, String[], String). This can also be used to present the items in a different order than used in the enum definition. In this case, defaultItem may be null, in which case the first item in enumArray is used instead. The same happens if defaultItem is not contained in enumArray.
The existing "get" method getNextEnumChoice(Class<E> enumClass) works without modification.
I have also included usage examples for both methods, e.g.,
There are other modifications in file GenericDialog.java, since my IDE expands imports and inserts @Override annotations automatically. Sorry if this is any inconvenience.
This PR adds a new method to
GenericDialog
for adding enum-based choices to dialogs. The existing methodvoid addEnumChoice(String label, E defaultItem)
includes all items defined by an enum class in the list of choices. While this creates very simple and elegant code, I found that this is not always desirable. Therefore, the new methodvoid addEnumChoice(String label, E[] enumArray, E defaultItem)
includes only a subset of the available enum items, as specified in
enumArray
. Note that its signature is completely analogous to the original string-based methodaddChoice(String, String[], String)
. This can also be used to present the items in a different order than used in the enum definition. In this case,defaultItem
may benull
, in which case the first item inenumArray
is used instead. The same happens ifdefaultItem
is not contained inenumArray
.The existing "get" method
getNextEnumChoice(Class<E> enumClass)
works without modification.I have also included usage examples for both methods, e.g.,
There are other modifications in file
GenericDialog.java
, since my IDE expands imports and inserts@Override
annotations automatically. Sorry if this is any inconvenience.Regards, Wilhelm