001    /**
002     * Copyright (C) 2007-2008, Jens Lehmann
003     *
004     * This file is part of DL-Learner.
005     * 
006     * DL-Learner is free software; you can redistribute it and/or modify
007     * it under the terms of the GNU General Public License as published by
008     * the Free Software Foundation; either version 3 of the License, or
009     * (at your option) any later version.
010     *
011     * DL-Learner is distributed in the hope that it will be useful,
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014     * GNU General Public License for more details.
015     *
016     * You should have received a copy of the GNU General Public License
017     * along with this program.  If not, see <http://www.gnu.org/licenses/>.
018     *
019     */
020    package org.dllearner.gui.widgets;
021    
022    import java.awt.event.ActionEvent;
023    import java.awt.event.ActionListener;
024    
025    import javax.swing.JComboBox;
026    
027    import org.dllearner.core.Component;
028    import org.dllearner.core.options.BooleanConfigOption;
029    import org.dllearner.gui.Config;
030    
031    /**
032     * Panel for option Boolean, defined in
033     * {@link org.dllearner.core.options.BooleanConfigOption}.
034     * 
035     * @author Jens Lehmann
036     * @author Tilo Hielscher
037     */
038    public class WidgetPanelBoolean extends AbstractWidgetPanel<Boolean> implements ActionListener {
039    
040            private static final long serialVersionUID = -4800583253223939928L;
041    
042            private Boolean value;
043            private JComboBox cb;
044    
045            /**
046             * Provides a widget for boolean options.
047             * @param config Central config handler.
048             * @param component The component of this option.
049             * @param configOption The option to configure.
050             */     
051            public WidgetPanelBoolean(Config config, Component component, BooleanConfigOption configOption) {
052                    super(config, component, configOption);
053            }
054    
055            @Override
056            public void actionPerformed(ActionEvent e) {                    
057                    value = (cb.getSelectedIndex()==0);
058                    fireValueChanged(value);
059            }
060    
061            @Override
062            public void buildWidgetPanel() {
063                    add(getLabel());
064                    
065                    value = config.getConfigOptionValue(component, configOption);
066                    
067                    if (value == null) {
068                            value = false;
069                    }
070                    
071                    // set cb-index
072                    String[] kbBoxItems = { "true", "false" };
073                    cb = new JComboBox(kbBoxItems);
074                    if (value) {
075                            cb.setSelectedIndex(0);
076                    } else {
077                            cb.setSelectedIndex(1);
078                    }
079                    
080                    cb.addActionListener(this);
081                    add(cb);
082                    
083            }
084    
085    }