forked from Apple-2-Tools/jace
61 lines
2.0 KiB
Java
61 lines
2.0 KiB
Java
/*
|
|
* Copyright (C) 2012 Brendan Robert (BLuRry) brendan.robert@gmail.com.
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
* MA 02110-1301 USA
|
|
*/
|
|
package jace.config;
|
|
|
|
import jace.config.Configuration.ConfigNode;
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.ActionListener;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
import javax.swing.JCheckBox;
|
|
|
|
/**
|
|
*
|
|
* @author Brendan Robert (BLuRry) brendan.robert@gmail.com
|
|
*/
|
|
class BooleanComponent extends JCheckBox implements ActionListener {
|
|
ConfigNode node;
|
|
String fieldName;
|
|
|
|
public BooleanComponent(ConfigNode node, String fieldName) {
|
|
this.node = node;
|
|
this.fieldName = fieldName;
|
|
synchronizeValue();
|
|
addActionListener(this);
|
|
}
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
Boolean value = Boolean.valueOf(isSelected());
|
|
node.setFieldValue(fieldName, value);
|
|
}
|
|
|
|
public void synchronizeValue() {
|
|
try {
|
|
|
|
Object value = node.getFieldValue(fieldName);
|
|
if (value == null) {
|
|
setSelected(false);
|
|
} else {
|
|
setSelected(Boolean.valueOf(String.valueOf(value)).booleanValue());
|
|
}
|
|
} catch (IllegalArgumentException ex) {
|
|
Logger.getLogger(BooleanComponent.class.getName()).log(Level.SEVERE, null, ex);
|
|
}
|
|
}
|
|
} |