001 /*
002 * Copyright 2006 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.DOM;
019 import com.google.gwt.user.client.Element;
020 import com.google.gwt.user.client.ui.HasHorizontalAlignment.HorizontalAlignmentConstant;
021 import com.google.gwt.user.client.ui.HasVerticalAlignment.VerticalAlignmentConstant;
022
023 /**
024 * A panel whose child widgets are contained within the cells of a table. Each
025 * cell's size may be set independently. Each child widget can take up a subset
026 * of its cell and can be aligned within it.
027 */
028 public abstract class CellPanel extends ComplexPanel {
029
030 private int spacing;
031 private Element table;
032
033 protected CellPanel() {
034 table = DOM.createTable();
035 setElement(table);
036 }
037
038 /**
039 * Sets the width of the border to be applied to all cells in this panel. This
040 * is particularly useful when debugging layouts, in that it allows you to see
041 * explicitly the cells that contain this panel's children.
042 *
043 * @param width the width of the panel's cell borders, in pixels
044 */
045 public void setBorderWidth(int width) {
046 DOM.setAttribute(table, "border", "" + width);
047 }
048
049 /**
050 * Gets the amount of spacing between this panel's cells.
051 *
052 * @return the inter-cell spacing, in pixels
053 */
054 public int getSpacing() {
055 return spacing;
056 }
057
058 /**
059 * Sets the height of the cell associated with the given widget, related to
060 * the panel as a whole.
061 *
062 * @param w the widget whose cell height is to be set
063 * @param height the cell's height, in CSS units
064 */
065 public abstract void setCellHeight(Widget w, String height);
066
067 /**
068 * Sets the horizontal alignment of the given widget within its cell
069 *
070 * @param w the widget whose horizontal alignment is to be set
071 * @param align the widget's horizontal alignment, as defined in
072 * {@link HasHorizontalAlignment}.
073 */
074 public abstract void setCellHorizontalAlignment(Widget w,
075 HorizontalAlignmentConstant align);
076
077 /**
078 * Sets the vertical alignment of the given widget within its cell
079 *
080 * @param w the widget whose vertical alignment is to be set
081 * @param align the widget's vertical alignment, as defined in
082 * {@link HasVerticalAlignment}.
083 */
084 public abstract void setCellVerticalAlignment(Widget w,
085 VerticalAlignmentConstant align);
086
087 /**
088 * Sets the width of the cell associated with the given widget, related to the
089 * panel as a whole.
090 *
091 * @param w the widget whose cell width is to be set
092 * @param width the cell's width, in CSS units
093 */
094 public abstract void setCellWidth(Widget w, String width);
095
096 /**
097 * Sets the amount of spacing between this panel's cells.
098 *
099 * @param spacing the inter-cell spacing, in pixels
100 */
101 public void setSpacing(int spacing) {
102 this.spacing = spacing;
103 DOM.setIntAttribute(table, "cellSpacing", spacing);
104 }
105
106 /**
107 * Accessor for subclasses to get this panel's table element.
108 *
109 * @return the cell panel's table element
110 */
111 protected Element getTable() {
112 return table;
113 }
114 }