001: /*
002: * Copyright 2007 Google Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016: package com.google.gwt.user.client.ui;
017:
018: import com.google.gwt.user.client.ui.HTMLTable.ColumnFormatter;
019:
020: import java.util.HashMap;
021:
022: /**
023: * TODO: document me.
024: */
025: public abstract class HTMLTableProfile extends WidgetProfile {
026:
027: public abstract HTMLTable createTable(int rows, int columns);
028:
029: public void addStyleName(int rows, int columns) {
030: HTMLTable HTMLTable = createTable(rows, columns);
031: resetTimer();
032: for (int row = 0; row < rows; row++) {
033: for (int column = 0; column < columns; column++) {
034: HTMLTable.getCellFormatter().addStyleName(row, column,
035: "foo");
036: }
037: }
038: timing("addStyleName(" + rows + "," + columns + ")");
039: }
040:
041: public void setStyleName(int rows, int columns) {
042: System.out.println("Hybrid mode");
043: HTMLTable HTMLTable = createTable(rows, columns);
044: resetTimer();
045: for (int row = 0; row < rows; row++) {
046: for (int column = 0; column < columns; column++) {
047: HTMLTable.getCellFormatter().setStyleName(row, column,
048: row + "," + column);
049: }
050: }
051: timing("setStyleName(" + rows + "," + columns + ")");
052: }
053:
054: public void createTableTiming(int rows, int columns) {
055: resetTimer();
056: createTable(rows, columns);
057: timing("createTable(" + rows + "," + columns + ")");
058: }
059:
060: public void getStyleName(int rows, int columns) {
061: System.out.println("Hybrid mode");
062: HTMLTable HTMLTable = createTable(rows, columns);
063: resetTimer();
064: for (int row = 0; row < rows; row++) {
065: for (int column = 0; column < columns; column++) {
066: HTMLTable.getCellFormatter().getStyleName(row, column);
067: }
068: }
069: timing("getStyleName(" + rows + "," + columns + ")");
070: }
071:
072: public void hashMapShare(int rows, int columns) {
073: resetTimer();
074: HashMap m = new HashMap();
075: for (int row = 0; row < rows; row++) {
076: for (int column = 0; column < columns; column++) {
077: Label label = new Label(column + "i");
078: m.put(row + "," + column, label);
079: }
080: }
081: timing("hashMapShare(" + rows + "," + columns + ")");
082: }
083:
084: public void setHTMLTiming(int rows, int columns) {
085: resetTimer();
086: HTMLTable HTMLTable = createTable(rows, columns);
087: for (int row = 0; row < rows; row++) {
088: for (int column = 0; column < columns; column++) {
089: HTMLTable.setHTML(row, column, "test");
090: }
091: }
092: timing("setHTML(" + rows + "," + columns + ")");
093: }
094:
095: public void setTextTiming(int rows, int columns) {
096: resetTimer();
097: HTMLTable HTMLTable = createTable(rows, columns);
098: for (int row = 0; row < rows; row++) {
099: for (int column = 0; column < columns; column++) {
100: HTMLTable.setText(row, column, "test");
101: }
102: }
103: timing(" setText(" + rows + "," + columns + ")");
104: }
105:
106: public void setWidgetTiming(int rows, int columns) {
107: resetTimer();
108: HTMLTable HTMLTable = createTable(rows, columns);
109: RootPanel.get().add(HTMLTable);
110: for (int row = 0; row < rows; row++) {
111: for (int column = 0; column < columns; column++) {
112: Label label = new Label(column + "i");
113: HTMLTable.setWidget(row, column, label);
114: }
115: }
116: timing("setWidgetTiming(" + rows + "," + columns + ")");
117: }
118:
119: public void columnAddStyleName(int rows, int cols) {
120: HTMLTable table = createTable(rows, cols);
121: resetTimer();
122: ColumnFormatter formatter = table.getColumnFormatter();
123: for (int i = 0; i < cols; i++) {
124: formatter.addStyleName(i, "fooStyle");
125: }
126: timing("column.addStyleName(" + rows + ", " + cols + ")");
127: }
128:
129: public void testTimings() throws Exception {
130: timing(10, 10);
131: timing(20, 10);
132: timing(20, 20);
133: timing(40, 20);
134: timing(40, 40);
135: timing(80, 40);
136: timing(80, 80);
137:
138: throw new Exception("Finished Profile");
139: }
140:
141: public void timing(int rows, int columns) {
142: columnAddStyleName(rows, columns);
143: }
144:
145: }
|