001: /*
002: * This file is part of the Echo Web Application Framework (hereinafter "Echo").
003: * Copyright (C) 2002-2005 NextApp, Inc.
004: *
005: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
006: *
007: * The contents of this file are subject to the Mozilla Public License Version
008: * 1.1 (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: * http://www.mozilla.org/MPL/
011: *
012: * Software distributed under the License is distributed on an "AS IS" basis,
013: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
014: * for the specific language governing rights and limitations under the
015: * License.
016: *
017: * Alternatively, the contents of this file may be used under the terms of
018: * either the GNU General Public License Version 2 or later (the "GPL"), or
019: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020: * in which case the provisions of the GPL or the LGPL are applicable instead
021: * of those above. If you wish to allow use of your version of this file only
022: * under the terms of either the GPL or the LGPL, and not to allow others to
023: * use your version of this file under the terms of the MPL, indicate your
024: * decision by deleting the provisions above and replace them with the notice
025: * and other provisions required by the GPL or the LGPL. If you do not delete
026: * the provisions above, a recipient may use your version of this file under
027: * the terms of any one of the MPL, the GPL or the LGPL.
028: */
029:
030: package nextapp.echo2.testapp.interactive.testscreen;
031:
032: import nextapp.echo2.app.Column;
033: import nextapp.echo2.app.Component;
034: import nextapp.echo2.app.Extent;
035: import nextapp.echo2.app.Insets;
036: import nextapp.echo2.app.SelectField;
037: import nextapp.echo2.app.Table;
038: import nextapp.echo2.app.TextField;
039: import nextapp.echo2.app.layout.SplitPaneLayoutData;
040: import nextapp.echo2.app.list.AbstractListModel;
041: import nextapp.echo2.app.list.DefaultListModel;
042: import nextapp.echo2.app.list.ListModel;
043: import nextapp.echo2.app.table.DefaultTableModel;
044: import nextapp.echo2.app.table.TableCellRenderer;
045: import nextapp.echo2.app.text.StringDocument;
046:
047: /**
048: * A test to determine bandwidth consumption of large numbers of list boxes
049: * with identical models.
050: */
051: public class ListRenderTableTest extends Column {
052:
053: private ListModel monthModel = new DefaultListModel(new Object[] {
054: "January", "Februrary", "March", "April", "May", "June",
055: "July", "August", "September", "October", "November",
056: "December" });
057:
058: private ListModel dayModel = new AbstractListModel() {
059:
060: /**
061: * @see nextapp.echo2.app.list.ListModel#size()
062: */
063: public int size() {
064: return 31;
065: }
066:
067: /**
068: * @see nextapp.echo2.app.list.ListModel#get(int)
069: */
070: public Object get(int index) {
071: return Integer.toString(index + 1);
072: }
073: };
074:
075: private ListModel yearModel = new AbstractListModel() {
076:
077: /**
078: * @see nextapp.echo2.app.list.ListModel#size()
079: */
080: public int size() {
081: return 200;
082: }
083:
084: /**
085: * @see nextapp.echo2.app.list.ListModel#get(int)
086: */
087: public Object get(int index) {
088: return Integer.toString(index + 1850);
089: }
090: };
091:
092: public ListRenderTableTest() {
093: setCellSpacing(new Extent(10));
094:
095: SplitPaneLayoutData splitPaneLayoutData = new SplitPaneLayoutData();
096: splitPaneLayoutData.setInsets(new Insets(10));
097: setLayoutData(splitPaneLayoutData);
098:
099: DefaultTableModel model = new DefaultTableModel();
100: model.setColumnCount(4);
101: for (int i = 0; i < 10; ++i) {
102: model.addRow(new Object[] { "John Smith", new Integer(0),
103: new Integer(4), new Integer(1982) });
104: }
105:
106: TableCellRenderer renderer = new TableCellRenderer() {
107:
108: public Component getTableCellRendererComponent(Table table,
109: Object value, int column, int row) {
110: switch (column) {
111: case 0:
112: TextField tf = new TextField(new StringDocument(),
113: value.toString(), 30);
114: return tf;
115: case 1:
116: SelectField monthField = new SelectField(monthModel);
117: monthField.setSelectedIndex(((Integer) value)
118: .intValue());
119: return monthField;
120: case 2:
121: SelectField dayField = new SelectField(dayModel);
122: dayField.setSelectedIndex(((Integer) value)
123: .intValue() - 1);
124: return dayField;
125: case 3:
126: SelectField yearField = new SelectField(yearModel);
127: yearField.setSelectedIndex(((Integer) value)
128: .intValue() - 1850);
129: return yearField;
130: }
131: return null;
132: }
133: };
134:
135: Table table = new Table(model);
136: table.setStyleName("Default");
137: table.setDefaultRenderer(Object.class, renderer);
138: add(table);
139: }
140: }
|