001: /*
002: * SwingML Copyright (C) 2002 SwingML Team
003: *
004: * This library is free software; you can redistribute it and/or modify it under
005: * the terms of the GNU Lesser General Public License as published by the Free
006: * Software Foundation; either version 2 of the License, or (at your option) any
007: * later version.
008: *
009: * This library is distributed in the hope that it will be useful, but WITHOUT
010: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011: * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012: * details.
013: *
014: * You should have received a copy of the GNU Lesser General Public License
015: * along with this library; if not, write to the Free Software Foundation, Inc.,
016: * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: * Authors: Ezequiel Cuellar <ecuellar@crosslogic.com> Bram Stieperaere
019: * <bramez@users.sourceforge.net>
020: */
021:
022: package org.swingml.model;
023:
024: import java.util.*;
025:
026: import org.swingml.*;
027: import org.swingml.system.*;
028:
029: public class JComboBoxModel extends SwingMLModel {
030:
031: private boolean editable = false;
032: private boolean enabled = true;
033:
034: public JComboBoxModel() {
035: super ();
036: }
037:
038: public int getSelectedIndex() {
039: int theIndex = 0;
040: Iterator theChildren = super .getChildren().iterator();
041: ItemModel theItem = null;
042: while (theChildren.hasNext()) {
043: theItem = (ItemModel) theChildren.next();
044: if (theItem.isSelected()) {
045: theIndex = super .getChildren().indexOf(theItem);
046: }
047: }
048: return theIndex;
049: }
050:
051: public String getText() {
052: ItemModel selectedItem = (ItemModel) getChildren().get(
053: getSelectedIndex());
054: if (selectedItem.getValue() != null) {
055: return selectedItem.getValue();
056: } else {
057: return selectedItem.getText();
058: }
059: }
060:
061: public boolean isEditable() {
062: return this .editable;
063: }
064:
065: public boolean isEnabled() {
066: return enabled;
067: }
068:
069: public void setEditable(boolean aEditable) {
070: this .editable = aEditable;
071: }
072:
073: public void setEnabled(boolean enable) {
074: this .enabled = enable;
075: }
076:
077: public void validate() {
078: if (super .getParent().getLayout() != null
079: && super .getParent().getLayout().equalsIgnoreCase(
080: Constants.BORDERLAYOUT)) {
081: if (super .getOrientation() == null) {
082: SwingMLLogger
083: .getInstance()
084: .log(
085: "Syntax error: The parameter ORIENTATION in the element "
086: + super .getName()
087: + " is required since its parent's LAYOUT is BorderLayout. Add the parameter ORIENTATION to the element "
088: + super .getName()
089: + " or change its parent's LAYOUT to other than BorderLayout.");
090: }
091: }
092: if (super .getParent().getLayout() != null
093: && !super .getParent().getLayout().equalsIgnoreCase(
094: Constants.BORDERLAYOUT)) {
095: if (super .getOrientation() != null) {
096: SwingMLLogger
097: .getInstance()
098: .log(
099: "Syntax error: The parameter ORIENTATION in the element "
100: + super .getName()
101: + " should be used only when its parent's LAYOUT is BorderLayout. Change its parent's LAYOUT to BorderLayout or delete the parameter ORIENTATION from the element "
102: + super .getName() + ".");
103: }
104: }
105: }
106: }
|