001package jmri.script.swing; 002 003import javax.swing.JComboBox; 004 005import jmri.script.ScriptEngineSelector; 006import jmri.script.ScriptEngineSelector.Engine; 007 008/** 009 * A JComboBox for selecting a valid scripting engine. 010 * 011 * Persistence of settings, if desired, should be handled in the using class. 012 * 013 * @author Bob Jacobsen Copyright (C) 2004, 2021, 2022 014 */ 015public class ScriptEngineSelectorSwing { 016 017 private final JComboBox<Engine> comboBox = 018 new JComboBox<>(ScriptEngineSelector.getAllEngines().toArray(new Engine[0])); 019 020 private final ScriptEngineSelector _selector; 021 022 public ScriptEngineSelectorSwing(ScriptEngineSelector selector) { 023 _selector = selector; 024 updateSetComboBoxSelection(); 025 } 026 027 public final void updateSetComboBoxSelection() { 028 comboBox.setSelectedItem(_selector.getSelectedEngine()); 029 } 030 031 public JComboBox<Engine> getComboBox() { 032 return comboBox; 033 } 034 035 public void update() { 036 _selector.setSelectedEngine(comboBox.getItemAt(comboBox.getSelectedIndex())); 037 } 038 039}