Package lipstone.joshua.parser.plugin.settings

Source Code of lipstone.joshua.parser.plugin.settings.ParserSettingsComboBox

package lipstone.joshua.parser.plugin.settings;

import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.JComboBox;

import lipstone.joshua.parser.Tokenizer;
import lipstone.joshua.parser.exceptions.SyntaxException;
import lipstone.joshua.parser.exceptions.UnbalancedParenthesesException;
import lipstone.joshua.parser.plugin.ParserPlugin;
import lipstone.joshua.parser.util.ConsCell;

public class ParserSettingsComboBox<T> extends ParserSettingsItem<JComboBox<T>> {
 
  public ParserSettingsComboBox(String name, ParserPlugin plugin, boolean editable, T... initialItems) {
    super(name, new JComboBox<T>(initialItems), plugin);
    guiItem.setEditable(editable);
  }
 
  @Override
  protected void addListeners() {
    guiItem.addItemListener(new ItemListener() {
     
      @Override
      public void itemStateChanged(ItemEvent e) {
        onEnter();
      }
    });
  }
 
  @Override
  public ConsCell getValue() {
    try {
      return Tokenizer.tokenizeString(guiItem.getSelectedItem().toString());
    }
    catch (SyntaxException | UnbalancedParenthesesException e) {
      getPlugin().getParser().getLog().logError("Unable to tokenize the selected item in " + getName() + " in " + getPlugin().getID());
      return new ConsCell();
    }
  }
 
  @Override
  public void setValue(ConsCell value) {
    guiItem.setSelectedItem(value.toString());
  }
 
}
TOP

Related Classes of lipstone.joshua.parser.plugin.settings.ParserSettingsComboBox

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.