001: /* SwingML
002: * Copyright (C) 2002 SwingML Team
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the
016: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
017: * Boston, MA 02111-1307, USA.
018: *
019: * Authors:
020: * Ezequiel Cuellar <ecuellar@crosslogic.com>
021: * Robert Morris <robertj@morris.net>
022: * Bram Stieperaere <bramez@users.sourceforge.net>
023: */
024:
025: package org.swingml.component;
026:
027: import java.awt.*;
028: import java.util.*;
029:
030: import javax.swing.*;
031: import javax.swing.border.*;
032:
033: import org.swingml.*;
034: import org.swingml.model.*;
035:
036: public class ButtonGroupComponent extends JPanel {
037:
038: ButtonGroup buttonGroup = new ButtonGroup();
039: ButtonGroupModel model;
040:
041: public ButtonGroupComponent(ButtonGroupModel aModel) {
042: this .model = aModel;
043: String theName = model.getName();
044: String theBorder = model.getBorder();
045: String theLayout = model.getLayout();
046: int theBevelType = model.getBevelType();
047: int theRows = model.getRows();
048: int theCols = model.getCols();
049: super .setName(theName);
050:
051: setEnabled(model.isEnabled());
052:
053: if (theBorder.equalsIgnoreCase(Constants.ETCHEDBORDER)) {
054: super .setBorder(new EtchedBorder());
055: }
056:
057: if (theBorder.equalsIgnoreCase(Constants.BEVELBORDER)) {
058: super .setBorder(new BevelBorder(theBevelType));
059: }
060:
061: if (theLayout.equalsIgnoreCase(Constants.FLOWLAYOUT)) {
062: super .setLayout(new FlowLayout());
063: }
064:
065: if (theLayout.equalsIgnoreCase(Constants.GRIDLAYOUT)) {
066: super .setLayout(new GridLayout(theRows, theCols));
067: }
068:
069: if (theLayout.equalsIgnoreCase(Constants.BORDERLAYOUT)) {
070: super .setLayout(new BorderLayout());
071: }
072:
073: if (theLayout.equalsIgnoreCase(Constants.NONE)) {
074: super .setLayout(null);
075: }
076: }
077:
078: public Component add(Component aButton) {
079: super .add(aButton);
080: buttonGroup.add((AbstractButton) aButton);
081: return aButton;
082: }
083:
084: public void add(Component aButton, Object orientation) {
085: super .add(aButton, orientation);
086: buttonGroup.add((AbstractButton) aButton);
087: }
088:
089: public void setEnabled(boolean enabled) {
090: super .setEnabled(enabled);
091:
092: // iterate buttongroup and enable them, too
093: Enumeration e = buttonGroup.getElements();
094: while (e.hasMoreElements()) {
095: Component component = (Component) e.nextElement();
096: if (component != null) {
097: component.setEnabled(enabled);
098: }
099: }
100: }
101: }
|