01: /*
02: * Copyright 2006 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.dev.shell;
17:
18: import org.eclipse.swt.SWT;
19: import org.eclipse.swt.layout.GridData;
20: import org.eclipse.swt.layout.GridLayout;
21: import org.eclipse.swt.widgets.Composite;
22: import org.eclipse.swt.widgets.Control;
23:
24: /**
25: * Shared boilerplate for grid-style UIs.
26: */
27: public class GridPanel extends Composite {
28:
29: protected static final int FILL = GridData.FILL;
30:
31: protected static final int CENTER = GridData.CENTER;
32:
33: protected static final int MIDDLE = GridData.CENTER;
34:
35: protected static final int LEFT = GridData.BEGINNING;
36:
37: protected static final int RIGHT = GridData.END;
38:
39: protected static final int TOP = GridData.BEGINNING;
40: protected static final int BOTTOM = GridData.END;
41:
42: public GridPanel(Composite parent, int style, int numCols,
43: boolean equalWidthCols) {
44: this (parent, style, numCols, equalWidthCols, 5, 5);
45: }
46:
47: public GridPanel(Composite parent, int style, int numCols,
48: boolean equalWidthCols, int marginWidth, int marginHeight) {
49: super (parent, style);
50: GridLayout gridLayout = new GridLayout();
51: gridLayout.numColumns = numCols;
52: gridLayout.makeColumnsEqualWidth = equalWidthCols;
53: gridLayout.marginWidth = marginWidth;
54: gridLayout.marginHeight = marginHeight;
55: gridLayout.horizontalSpacing = 1;
56: gridLayout.verticalSpacing = 1;
57: setLayout(gridLayout);
58: }
59:
60: protected GridData getGridData(Control control) {
61: GridData gridData = (GridData) control.getLayoutData();
62: if (gridData == null) {
63: gridData = new GridData();
64: control.setLayoutData(gridData);
65: }
66: return gridData;
67: }
68:
69: protected GridData setGridData(Control control, int rowSpan,
70: int colSpan, int hAlign, int vAlign, boolean hGrab,
71: boolean vGrab) {
72: return setGridData(control, rowSpan, colSpan, hAlign, vAlign,
73: hGrab, vGrab, SWT.DEFAULT, SWT.DEFAULT);
74: }
75:
76: protected GridData setGridData(Control control, int rowSpan,
77: int colSpan, int hAlign, int vAlign, boolean hGrab,
78: boolean vGrab, int widthHint, int heightHint) {
79: GridData gridData = getGridData(control);
80: gridData.horizontalSpan = colSpan;
81: gridData.verticalSpan = rowSpan;
82: gridData.horizontalAlignment = hAlign;
83: gridData.verticalAlignment = vAlign;
84: gridData.grabExcessHorizontalSpace = hGrab;
85: gridData.grabExcessVerticalSpace = vGrab;
86: if (heightHint != SWT.DEFAULT) {
87: gridData.heightHint = heightHint;
88: }
89:
90: if (widthHint != SWT.DEFAULT) {
91: gridData.widthHint = widthHint;
92: }
93:
94: control.setLayoutData(gridData);
95: return gridData;
96: }
97: }
|