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