001 /*
002 * Copyright 2006 Mat Gessel <mat.gessel@gmail.com>
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 asquare.gwt.tk.client.ui;
017
018 import asquare.gwt.tk.client.util.GwtUtil;
019
020 import com.google.gwt.user.client.DOM;
021 import com.google.gwt.user.client.Element;
022 import com.google.gwt.user.client.ui.Widget;
023
024 /**
025 * A table-based panel which stacks cells horizontally in columns and permits
026 * multiple widgets per cell. Empty cells are supported.
027 * {@link #add(Widget) add(Widget)},
028 * {@link #insert(Widget, int) insert(Widget, int)} and
029 * {@link #remove(Widget) remove(Widget)} behave the same as in
030 * {@link com.google.gwt.user.client.ui.HorizontalPanel HorizontalPanel}. That
031 * is, the table cell and the widget are treated as one. Other methods have
032 * options for cell addition, insertion and deletion.
033 * </p>
034 */
035 public class ColumnPanel extends ExposedCellPanel
036 {
037 private final Element m_tr;
038
039 /**
040 * Creates an empty panel with no columns.
041 */
042 public ColumnPanel()
043 {
044 m_tr = DOM.createTR();
045 DOM.appendChild(getBody(), m_tr);
046 }
047
048 /*
049 * (non-Javadoc)
050 * @see asquare.gwt.tk.client.ui.ExposedCellPanel#insertCellStructure(int)
051 */
052 protected void insertCellStructure(int cellIndex)
053 {
054 Element td = DOM.createTD();
055 DOM.insertChild(m_tr, td, cellIndex);
056 }
057
058 /*
059 * (non-Javadoc)
060 * @see asquare.gwt.tk.client.ui.ExposedCellPanel#removeCellStructure(int)
061 */
062 protected void removeCellStructure(int cellIndex)
063 {
064 Element td = getCellElement(cellIndex);
065 DOM.removeChild(m_tr, td);
066 }
067
068 /*
069 * (non-Javadoc)
070 * @see asquare.gwt.tk.client.ui.ExposedCellPanel#getCellElement(int)
071 */
072 public Element getCellElement(int cellIndex)
073 {
074 GwtUtil.rangeCheck(0, getCellCount(), cellIndex, false);
075
076 return DOM.getChild(m_tr, cellIndex);
077 }
078 }