• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.sdkuilib.ui;
18 
19 import org.eclipse.jface.dialogs.Dialog;
20 import org.eclipse.jface.dialogs.IDialogConstants;
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.layout.GridData;
23 import org.eclipse.swt.layout.GridLayout;
24 import org.eclipse.swt.widgets.Composite;
25 import org.eclipse.swt.widgets.Control;
26 import org.eclipse.swt.widgets.Shell;
27 
28 /**
29  * jface-based dialog that properly sets up a {@link GridLayout} top composite with the proper
30  * margin.
31  *
32  * Implementing dialog must create the content of the dialog in
33  * {@link #createDialogContent(Composite)}.
34  *
35  */
36 public abstract class GridDialog extends Dialog {
37 
38     private final int mNumColumns;
39     private final boolean mMakeColumnsEqualWidth;
40 
41     /**
42      * Creates the dialog
43      * @param parentShell the parent {@link Shell}.
44      * @param numColumns the number of columns in the grid
45      * @param makeColumnsEqualWidth whether or not the columns will have equal width
46      */
GridDialog(Shell parentShell, int numColumns, boolean makeColumnsEqualWidth)47     public GridDialog(Shell parentShell, int numColumns, boolean makeColumnsEqualWidth) {
48         super(parentShell);
49         mNumColumns = numColumns;
50         mMakeColumnsEqualWidth = makeColumnsEqualWidth;
51     }
52 
53     /**
54      * Creates the content of the dialog. The <var>parent</var> composite is a {@link GridLayout}
55      * created with the <var>numColumn</var> and <var>makeColumnsEqualWidth</var> parameters
56      * passed to {@link #GridDialog(Shell, int, boolean)}.
57      * @param parent the parent composite.
58      */
createDialogContent(Composite parent)59     public abstract void createDialogContent(Composite parent);
60 
61     @Override
createDialogArea(Composite parent)62     protected Control createDialogArea(Composite parent) {
63         Composite top = new Composite(parent, SWT.NONE);
64         GridLayout layout = new GridLayout(mNumColumns, mMakeColumnsEqualWidth);
65         layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
66         layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
67         layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
68         layout.horizontalSpacing = convertHorizontalDLUsToPixels(
69                 IDialogConstants.HORIZONTAL_SPACING);
70         top.setLayout(layout);
71         top.setLayoutData(new GridData(GridData.FILL_BOTH));
72 
73         createDialogContent(top);
74 
75         applyDialogFont(top);
76         return top;
77     }
78 }
79