001// License: GPL. For details, see Readme.txt file.
002package org.openstreetmap.gui.jmapviewer.checkBoxTree;
003
004import java.awt.BorderLayout;
005import java.awt.Insets;
006
007import javax.swing.JCheckBox;
008import javax.swing.JLabel;
009import javax.swing.JPanel;
010
011/**
012 * Node Panel for checkBox Tree
013 *
014 * @author galo
015 */
016public class CheckBoxNodePanel extends JPanel {
017    /** Serial Version UID */
018    private static final long serialVersionUID = -7236481597785619029L;
019    private final JLabel label = new JLabel();
020    private CheckBoxNodeData data;
021    public final JCheckBox check = new JCheckBox();
022
023    public CheckBoxNodePanel() {
024        this.check.setMargin(new Insets(0, 0, 0, 0));
025        setLayout(new BorderLayout());
026        add(check, BorderLayout.WEST);
027        add(label, BorderLayout.CENTER);
028    }
029
030    public void setSelected(Boolean bool) {
031        if (bool == null) {
032            check.getModel().setPressed(true);
033            check.getModel().setArmed(true);
034        } else {
035            check.setSelected(bool.booleanValue());
036            check.getModel().setArmed(false);
037        }
038    }
039
040    public CheckBoxNodeData getData() {
041        data.setSelected(check.isSelected());
042        return data;
043    }
044
045    public void setData(CheckBoxNodeData data) {
046        this.data = data;
047        label.setText(data.getText());
048    }
049
050    public JLabel getLabel() {
051        return label;
052    }
053}