001package jmri;
002
003import java.util.Arrays;
004import java.util.List;
005
006import javax.annotation.Nonnull;
007import javax.swing.JComboBox;
008
009/**
010 * Implementation of NamedBeanPropertyDescriptor for multiple choice properties.
011 * @author Steve Young Copyright (C) 2020
012 * @since 4.21.3
013 */
014public abstract class SelectionPropertyDescriptor extends NamedBeanPropertyDescriptor<String> {
015    
016    private final String[] values;
017    private final String[] valueToolTips;
018    
019    /**
020     * Create a new SelectionPropertyDescriber.
021     * @param key Property Key - used to identify the property in Bean.getProperty(String).
022     * @param options Options for the property in String array.
023     * @param optionTips Tool-tips for options of the property in String array.
024     * @param defVal Default property value.
025     */
026    public SelectionPropertyDescriptor(
027            @Nonnull String key,
028            @Nonnull String[] options,
029            @Nonnull String[] optionTips,
030            @Nonnull String defVal ) {
031        super(key, defVal );
032        values = options;
033        valueToolTips = optionTips;
034    }
035    
036    /** 
037     * Get the Class of the property.
038     * <p>
039     * SelectionPropertyDescriber uses JComboBox.class
040     * @return JComboBox.class.
041     */
042    @Override
043    public Class<?> getValueClass() {
044        return JComboBox.class;
045    }
046    
047    /**
048     * Get the property options.
049     * Should be same length as getOptionToolTips()
050     * @return copy of the property options.
051     */
052    public String[] getOptions(){
053        return Arrays.copyOf(values,values.length);
054    }
055    
056    /**
057     * Get Tool-tips for the options.
058     * Should be same length as getOptions()
059     * @return list of tool-tips.
060     */
061    public List<String> getOptionToolTips(){
062        return Arrays.asList(valueToolTips);
063    }
064    
065}