01: /* SwingML
02: * Copyright (C) 2002 Bram Stieperaere.
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: * Bram Stieperaere <bramez@users.sourceforge.net>
21: *
22: */
23:
24: package org.swingml.component;
25:
26: import java.awt.event.*;
27:
28: import javax.swing.*;
29:
30: import org.swingml.*;
31: import org.swingml.event.*;
32: import org.swingml.model.*;
33:
34: public class JRadioButtonComponent extends JRadioButton implements
35: XMLTranslatable, ItemListener {
36:
37: private EventHandler eventHandler = EventHandler.getInstance();
38: private JRadioButtonModel model;
39:
40: public JRadioButtonComponent(final JRadioButtonModel jrbm) {
41: model = jrbm;
42:
43: setEnabled(model.isEnabled());
44: setName(model.getName());
45: setText(model.getText());
46: setToolTipText(model.getTooltip());
47: setSelected(model.isChecked());
48: setFont(FontFactory.getFontForModel(model, getFont()));
49: addItemListener(this );
50:
51: if (jrbm.getAlign() != null) {
52: if (jrbm.getAlign().equalsIgnoreCase(Constants.LEFT)) {
53: setHorizontalAlignment(SwingConstants.LEFT);
54: } else if (jrbm.getAlign().equalsIgnoreCase(
55: Constants.CENTER)) {
56: setHorizontalAlignment(SwingConstants.CENTER);
57: } else if (jrbm.getAlign()
58: .equalsIgnoreCase(Constants.RIGHT)) {
59: setHorizontalAlignment(SwingConstants.RIGHT);
60: }
61: }
62: }
63:
64: public String getXMLValue() {
65: return Boolean.toString(super .isSelected());
66: }
67:
68: public void itemStateChanged(ItemEvent aEvt) {
69: if (aEvt.getStateChange() == ItemEvent.SELECTED) {
70: this.eventHandler.handleEvent(this.model,
71: Constants.ITEM_STATE_CHANGED_SELECTED, this);
72: } else if (aEvt.getStateChange() == ItemEvent.DESELECTED) {
73: this.eventHandler.handleEvent(this.model,
74: Constants.ITEM_STATE_CHANGED_DESELECTED, this);
75: }
76: }
77: }
|