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: * Marcelo W. Lopez Cremona <marcelo_java@argentina.com>
022: */
023:
024: package org.swingml.model;
025:
026: import java.util.*;
027:
028: import org.swingml.*;
029: import org.swingml.system.*;
030:
031: public class JListModel extends SwingMLModel {
032:
033: private boolean dndEnabled = false;
034: private int[] indexes = null;
035: private int mode = 0;
036: private String postStyle = Constants.POST_SELECTED;
037: private int visibleRowCount = 1;
038:
039: public JListModel() {
040: super ();
041: }
042:
043: public int getMode() {
044: return mode;
045: }
046:
047: public String getPostStyle() {
048: return this .postStyle;
049: }
050:
051: public int[] getSelectedIndexes() {
052: if (indexes == null) {
053: ArrayList theIndexes = new ArrayList();
054: Iterator theItems = super .getChildren().iterator();
055: ItemModel theItem = null;
056: while (theItems.hasNext()) {
057: theItem = (ItemModel) theItems.next();
058: if (theItem.isSelected()) {
059: theIndexes.add(super .getChildren().indexOf(theItem)
060: + "");
061: }
062: }
063: indexes = new int[theIndexes.size()];
064: for (int i = 0; i < theIndexes.size(); i++) {
065: indexes[i] = Integer.parseInt(theIndexes.get(i)
066: .toString());
067: }
068: }
069: return indexes;
070: }
071:
072: public int getVisibleRowCount() {
073: return visibleRowCount;
074: }
075:
076: public boolean isDndEnabled() {
077: return this .dndEnabled;
078: }
079:
080: public void setDndEnabled(boolean aDndEnabled) {
081: this .dndEnabled = aDndEnabled;
082: }
083:
084: public void setMode(int aMode) {
085: this .mode = aMode;
086: }
087:
088: public void setPostStyle(String aPostStyle) {
089: this .postStyle = aPostStyle;
090: }
091:
092: public void setSelectedIndexes(int[] aIndices) {
093: this .indexes = aIndices;
094: }
095:
096: public void setVisibleRowCount(int visibleRowCount) {
097: this .visibleRowCount = visibleRowCount;
098: }
099:
100: public void validate() {
101: if (super .getParent().getLayout() != null
102: && super .getParent().getLayout().equalsIgnoreCase(
103: Constants.BORDERLAYOUT)) {
104: if (super .getOrientation() == null) {
105: SwingMLLogger
106: .getInstance()
107: .log(
108: "Syntax error: The parameter ORIENTATION in the element "
109: + super .getName()
110: + " is required since its parent's LAYOUT is BorderLayout. Add the parameter ORIENTATION to the element "
111: + super .getName()
112: + " or change its parent's LAYOUT to other than BorderLayout.");
113: }
114: }
115: if (super .getParent().getLayout() != null
116: && !super .getParent().getLayout().equalsIgnoreCase(
117: Constants.BORDERLAYOUT)) {
118: if (super .getOrientation() != null) {
119: SwingMLLogger
120: .getInstance()
121: .log(
122: "Syntax error: The parameter ORIENTATION in the element "
123: + super .getName()
124: + " 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 "
125: + super .getName() + ".");
126: }
127: }
128: }
129: }
|