001: package org.enhydra.jawe.base.panel.panels;
002:
003: import java.awt.Color;
004: import java.awt.Component;
005: import java.awt.event.ItemEvent;
006: import java.awt.event.ItemListener;
007: import java.util.List;
008:
009: import javax.swing.BorderFactory;
010: import javax.swing.Box;
011: import javax.swing.JCheckBox;
012: import javax.swing.JLabel;
013: import javax.swing.SwingConstants;
014:
015: import org.enhydra.jawe.Settings;
016: import org.enhydra.jawe.base.panel.PanelContainer;
017: import org.enhydra.jawe.base.panel.PanelSettings;
018: import org.enhydra.shark.xpdl.XMLAttribute;
019: import org.enhydra.shark.xpdl.XMLElement;
020:
021: /**
022: * Creates a panel with a checkbox which represents a boolean value.
023: * @author Harald Meister
024: * @author Sasa Bojanic
025: */
026: public class XMLCheckboxPanel extends XMLBasicPanel {
027: protected JLabel jl;
028:
029: protected JCheckBox jcb;
030:
031: public XMLCheckboxPanel(PanelContainer pc, XMLElement myOwner,
032: String title, boolean isVertical, boolean isEnabled) {
033:
034: super (pc, myOwner, "", isVertical, false, true);
035:
036: boolean rightAllignment = false;
037:
038: Color bkgCol = new Color(245, 245, 245);
039: if (pc != null) {
040: Settings settings = pc.getSettings();
041:
042: rightAllignment = settings
043: .getSettingBoolean("XMLBasicPanel.RightAllignment");
044:
045: if (settings instanceof PanelSettings) {
046: bkgCol = ((PanelSettings) settings)
047: .getBackgroundColor();
048: }
049:
050: }
051:
052: if (title != null && !title.equals("")) {
053: jl = new JLabel(title);
054: } else {
055: jl = new JLabel(pc.getLabelGenerator().getLabel(myOwner));
056: }
057: jl.setAlignmentX(Component.LEFT_ALIGNMENT);
058: jl.setAlignmentY(Component.BOTTOM_ALIGNMENT);
059: if (rightAllignment) {
060: jl.setHorizontalAlignment(SwingConstants.RIGHT);
061: } else {
062: jl.setHorizontalAlignment(SwingConstants.LEFT);
063: }
064:
065: jcb = new JCheckBox();
066: jcb.setBorder(BorderFactory.createEmptyBorder());
067: jcb.setSelected(new Boolean(myOwner.toValue()).booleanValue());
068: jcb.setAlignmentX(Component.LEFT_ALIGNMENT);
069: jcb.setAlignmentY(Component.BOTTOM_ALIGNMENT);
070:
071: jcb.setEnabled(isEnabled);
072: // jcb.setBackground(bkgCol);
073:
074: final XMLPanel p = this ;
075: jcb.addItemListener(new ItemListener() {
076: public void itemStateChanged(ItemEvent e) {
077: if (getPanelContainer() == null)
078: return;
079: getPanelContainer().panelChanged(p, e);
080: }
081: });
082:
083: if (rightAllignment && !isVertical) {
084: add(Box.createHorizontalGlue());
085: }
086: if (isVertical) {
087: add(jl);
088: add(Box.createVerticalStrut(5));
089: add(jcb);
090: } else {
091: add(jcb);
092: add(Box.createHorizontalStrut(5));
093: add(jl);
094: }
095: if (!rightAllignment && !isVertical) {
096: add(Box.createHorizontalGlue());
097: }
098: }
099:
100: public void setElements() {
101: if (getOwner() instanceof XMLAttribute
102: && ((XMLAttribute) getOwner()).getChoices() != null) {
103: List choices = ((XMLAttribute) getOwner()).getChoices();
104: if (jcb.isSelected()) {
105: getOwner().setValue((String) choices.get(0));
106: } else {
107: getOwner().setValue((String) choices.get(1));
108: }
109: } else {
110: if (jcb.isSelected()) {
111: getOwner().setValue("true");
112: } else {
113: getOwner().setValue("false");
114: }
115: }
116: }
117:
118: public boolean getCheckboxStatus() {
119: return (jcb.isSelected());
120: }
121:
122: public Object getValue() {
123: if (jcb.isSelected()) {
124: return "true";
125: }
126: return "false";
127: }
128:
129: }
|