/* * Copyright (C) 2010 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.sdkuilib.ui; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; /** * A little helper to create a new {@link GridLayout}, associate to a {@link Composite} * and set its common attributes. *
* Example of usage:
* GridLayoutHelper.create(myComposite).noMargins().vSpacing(0).columns(2);
*
*/
public final class GridLayoutBuilder {
private static GridLayout mGL;
private GridLayoutBuilder() {
mGL = new GridLayout();
}
/**
* Creates new {@link GridLayout} and associates it on the parent
composite.
*/
static public GridLayoutBuilder create(Composite parent) {
GridLayoutBuilder glh = new GridLayoutBuilder();
parent.setLayout(GridLayoutBuilder.mGL);
return glh;
}
/** Sets all margins to 0. */
public GridLayoutBuilder noMargins() {
mGL.marginHeight = 0;
mGL.marginWidth = 0;
mGL.marginLeft = 0;
mGL.marginTop = 0;
mGL.marginRight = 0;
mGL.marginBottom = 0;
return this;
}
/** Sets all margins to n
. */
public GridLayoutBuilder margins(int n) {
mGL.marginHeight = n;
mGL.marginWidth = n;
mGL.marginLeft = n;
mGL.marginTop = n;
mGL.marginRight = n;
mGL.marginBottom = n;
return this;
}
/** Sets numColumns
to n
. */
public GridLayoutBuilder columns(int n) {
mGL.numColumns = n;
return this;
}
/** Sets makeColumnsEqualWidth
to true. */
public GridLayoutBuilder columnsEqual() {
mGL.makeColumnsEqualWidth = true;
return this;
}
/** Sets verticalSpacing
to v
. */
public GridLayoutBuilder vSpacing(int v) {
mGL.verticalSpacing = v;
return this;
}
/** Sets horizontalSpacing
to h
. */
public GridLayoutBuilder hSpacing(int h) {
mGL.horizontalSpacing = h;
return this;
}
/**
* Sets horizontalSpacing
and verticalSpacing
* to s
.
*/
public GridLayoutBuilder spacing(int s) {
mGL.verticalSpacing = s;
mGL.horizontalSpacing = s;
return this;
}
}