01: /* SwingML
02: * Copyright (C) 2002 SwingML Team
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the
16: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17: * Boston, MA 02111-1307, USA.
18: *
19: * Authors:
20: * Ezequiel Cuellar <ecuellar@crosslogic.com>
21: *
22: */
23:
24: package org.swingml.component;
25:
26: import java.awt.*;
27: import java.awt.event.*;
28:
29: import javax.swing.*;
30:
31: import org.swingml.*;
32: import org.swingml.event.*;
33: import org.swingml.model.*;
34:
35: public class JCheckBoxComponent extends JCheckBox implements
36: XMLTranslatable, ItemListener {
37:
38: private EventHandler eventHandler = EventHandler.getInstance();
39: private JCheckBoxModel model = null;
40:
41: public JCheckBoxComponent(JCheckBoxModel aModel) {
42: model = aModel;
43: super .setName(model.getName());
44: super .setText(model.getText());
45: super .setToolTipText(model.getTooltip());
46: super .setSelected(model.isChecked());
47: super .addItemListener(this );
48: super .setEnabled(aModel.isEnabled());
49: if (aModel.getAlign() != null) {
50: if (aModel.getAlign().equalsIgnoreCase(Constants.LEFT)) {
51: super .setHorizontalAlignment(SwingConstants.LEFT);
52: } else if (aModel.getAlign().equalsIgnoreCase(
53: Constants.CENTER)) {
54: super .setHorizontalAlignment(SwingConstants.CENTER);
55: } else if (aModel.getAlign().equalsIgnoreCase(
56: Constants.RIGHT)) {
57: super .setHorizontalAlignment(SwingConstants.RIGHT);
58: }
59: }
60:
61: Font newFont = FontFactory.getFontForModel(model, getFont());
62: super .setFont(newFont);
63: }
64:
65: public String getXMLValue() {
66: return Boolean.toString(super .isSelected());
67: }
68:
69: /**
70: * Don't allow focus if the field is not editable
71: */
72: public boolean isFocusable() {
73: return isEnabled();
74: }
75:
76: public void itemStateChanged(ItemEvent aEvt) {
77: if (aEvt.getStateChange() == ItemEvent.SELECTED) {
78: this.eventHandler.handleEvent(this.model,
79: Constants.ITEM_STATE_CHANGED_SELECTED, this);
80: } else if (aEvt.getStateChange() == ItemEvent.DESELECTED) {
81: this.eventHandler.handleEvent(this.model,
82: Constants.ITEM_STATE_CHANGED_DESELECTED, this);
83: }
84: }
85: }
|