New based dialog class.

This simply (for now) extends the jface dialog to properly
set it up.

Change-Id: I0d2bc2d10aad3811201f9d1df3efbfc87be50cb4
This commit is contained in:
Xavier Ducrohet
2009-10-07 14:30:42 -07:00
parent 7ce7a7835d
commit 5e5e423346
3 changed files with 99 additions and 50 deletions

View File

@@ -19,6 +19,7 @@ package com.android.sdkuilib.internal.widgets;
import com.android.sdklib.internal.avd.AvdManager; import com.android.sdklib.internal.avd.AvdManager;
import com.android.sdklib.internal.avd.AvdManager.AvdInfo; import com.android.sdklib.internal.avd.AvdManager.AvdInfo;
import com.android.sdkuilib.internal.repository.SettingsController; import com.android.sdkuilib.internal.repository.SettingsController;
import com.android.sdkuilib.ui.GridDialog;
import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IDialogConstants;
@@ -60,7 +61,7 @@ import java.util.regex.Pattern;
* Values are stored (in the class as static field) to be reused while the app is still running. * Values are stored (in the class as static field) to be reused while the app is still running.
* The Monitor dpi is stored in the settings if availabe. * The Monitor dpi is stored in the settings if availabe.
*/ */
final class AvdStartDialog extends Dialog { final class AvdStartDialog extends GridDialog {
// static field to reuse values during the same session. // static field to reuse values during the same session.
private static boolean sWipeData = false; private static boolean sWipeData = false;
private static int sMonitorDpi = 72; // used if there's no setting controller. private static int sMonitorDpi = 72; // used if there's no setting controller.
@@ -86,7 +87,7 @@ final class AvdStartDialog extends Dialog {
AvdStartDialog(Shell parentShell, AvdInfo avd, String sdkLocation, AvdStartDialog(Shell parentShell, AvdInfo avd, String sdkLocation,
SettingsController settingsController) { SettingsController settingsController) {
super(parentShell); super(parentShell, 2, false);
mAvd = avd; mAvd = avd;
mSdkLocation = sdkLocation; mSdkLocation = sdkLocation;
mSettingsController = settingsController; mSettingsController = settingsController;
@@ -112,42 +113,31 @@ final class AvdStartDialog extends Dialog {
} }
@Override @Override
protected Control createDialogArea(final Composite parent) { public void createDialogContent(final Composite parent) {
GridData gd; GridData gd;
// create a composite with standard margins and spacing Label l = new Label(parent, SWT.NONE);
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(2, false);
layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
layout.horizontalSpacing = convertHorizontalDLUsToPixels(
IDialogConstants.HORIZONTAL_SPACING);
composite.setLayout(layout);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
Label l = new Label(composite, SWT.NONE);
l.setText("Skin:"); l.setText("Skin:");
l = new Label(composite, SWT.NONE); l = new Label(parent, SWT.NONE);
l.setText(mSkinDisplay); l.setText(mSkinDisplay);
l.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); l.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
l = new Label(composite, SWT.NONE); l = new Label(parent, SWT.NONE);
l.setText("Density:"); l.setText("Density:");
l = new Label(composite, SWT.NONE); l = new Label(parent, SWT.NONE);
l.setText(getDensityText()); l.setText(getDensityText());
l.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); l.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
mScaleButton = new Button(composite, SWT.CHECK); mScaleButton = new Button(parent, SWT.CHECK);
mScaleButton.setText("Scale display to real size"); mScaleButton.setText("Scale display to real size");
mScaleButton.setEnabled(mEnableScaling); mScaleButton.setEnabled(mEnableScaling);
boolean defaultState = mEnableScaling && sSkinScaling.get(mAvd.getName()) != null; boolean defaultState = mEnableScaling && sSkinScaling.get(mAvd.getName()) != null;
mScaleButton.setSelection(defaultState); mScaleButton.setSelection(defaultState);
mScaleButton.setLayoutData(gd = new GridData(GridData.FILL_HORIZONTAL)); mScaleButton.setLayoutData(gd = new GridData(GridData.FILL_HORIZONTAL));
gd.horizontalSpan = 2; gd.horizontalSpan = 2;
final Group scaleGroup = new Group(composite, SWT.NONE); final Group scaleGroup = new Group(parent, SWT.NONE);
scaleGroup.setLayoutData(gd = new GridData(GridData.FILL_HORIZONTAL)); scaleGroup.setLayoutData(gd = new GridData(GridData.FILL_HORIZONTAL));
gd.horizontalIndent = 30; gd.horizontalIndent = 30;
gd.horizontalSpan = 2; gd.horizontalSpan = 2;
@@ -229,7 +219,7 @@ final class AvdStartDialog extends Dialog {
} }
}); });
final Button wipeButton = new Button(composite, SWT.CHECK); final Button wipeButton = new Button(parent, SWT.CHECK);
wipeButton.setLayoutData(gd = new GridData(GridData.FILL_HORIZONTAL)); wipeButton.setLayoutData(gd = new GridData(GridData.FILL_HORIZONTAL));
gd.horizontalSpan = 2; gd.horizontalSpan = 2;
wipeButton.setText("Wipe user data"); wipeButton.setText("Wipe user data");
@@ -241,18 +231,14 @@ final class AvdStartDialog extends Dialog {
} }
}); });
l = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL); l = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
l.setLayoutData(gd = new GridData(GridData.FILL_HORIZONTAL)); l.setLayoutData(gd = new GridData(GridData.FILL_HORIZONTAL));
gd.horizontalSpan = 2; gd.horizontalSpan = 2;
applyDialogFont(composite);
// if the scaling is enabled by default, we must initialize the value of mScale // if the scaling is enabled by default, we must initialize the value of mScale
if (defaultState) { if (defaultState) {
onScaleChange(); onScaleChange();
} }
return composite;
} }
@Override @Override

View File

@@ -16,14 +16,13 @@
package com.android.sdkuilib.internal.widgets; package com.android.sdkuilib.internal.widgets;
import org.eclipse.jface.dialogs.Dialog; import com.android.sdkuilib.ui.GridDialog;
import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
@@ -40,7 +39,7 @@ import org.eclipse.swt.widgets.Shell;
* After the dialog as returned, one can query {@link #getDensity()} to get the chosen monitor * After the dialog as returned, one can query {@link #getDensity()} to get the chosen monitor
* pixel density. * pixel density.
*/ */
class ResolutionChooserDialog extends Dialog { class ResolutionChooserDialog extends GridDialog {
public final static float[] MONITOR_SIZES = new float[] { public final static float[] MONITOR_SIZES = new float[] {
13.3f, 14, 15.4f, 15.6f, 17, 19, 20, 21, 24, 30, 13.3f, 14, 15.4f, 15.6f, 17, 19, 20, 21, 24, 30,
}; };
@@ -54,7 +53,7 @@ class ResolutionChooserDialog extends Dialog {
private int mMonitorIndex = 0; private int mMonitorIndex = 0;
ResolutionChooserDialog(Shell parentShell) { ResolutionChooserDialog(Shell parentShell) {
super(parentShell); super(parentShell, 2, false);
} }
/** /**
@@ -84,22 +83,11 @@ class ResolutionChooserDialog extends Dialog {
} }
@Override @Override
protected Control createDialogArea(Composite parent) { public void createDialogContent(Composite parent) {
// create a composite with standard margins and spacing Label l = new Label(parent, SWT.NONE);
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(2, false);
layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
layout.horizontalSpacing = convertHorizontalDLUsToPixels(
IDialogConstants.HORIZONTAL_SPACING);
composite.setLayout(layout);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
Label l = new Label(composite, SWT.NONE);
l.setText("Screen Size:"); l.setText("Screen Size:");
mScreenSizeCombo = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY); mScreenSizeCombo = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
for (float size : MONITOR_SIZES) { for (float size : MONITOR_SIZES) {
if (Math.round(size) == size) { if (Math.round(size) == size) {
mScreenSizeCombo.add(String.format("%.0f\"", size)); mScreenSizeCombo.add(String.format("%.0f\"", size));
@@ -115,10 +103,10 @@ class ResolutionChooserDialog extends Dialog {
} }
}); });
l = new Label(composite, SWT.NONE); l = new Label(parent, SWT.NONE);
l.setText("Resolution:"); l.setText("Resolution:");
mMonitorCombo = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY); mMonitorCombo = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
mMonitors = parent.getDisplay().getMonitors(); mMonitors = parent.getDisplay().getMonitors();
for (Monitor m : mMonitors) { for (Monitor m : mMonitors) {
Rectangle r = m.getBounds(); Rectangle r = m.getBounds();
@@ -131,8 +119,5 @@ class ResolutionChooserDialog extends Dialog {
mMonitorIndex = mMonitorCombo.getSelectionIndex(); mMonitorIndex = mMonitorCombo.getSelectionIndex();
} }
}); });
applyDialogFont(composite);
return composite;
} }
} }

View File

@@ -0,0 +1,78 @@
/*
* Copyright (C) 2009 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.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
/**
* jface-based dialog that properly sets up a {@link GridLayout} top composite with the proper
* margin.
*
* Implementing dialog must create the content of the dialog in
* {@link #createDialogContent(Composite)}.
*
*/
public abstract class GridDialog extends Dialog {
private final int mNumColumns;
private final boolean mMakeColumnsEqualWidth;
/**
* Creates the dialog
* @param parentShell the parent {@link Shell}.
* @param numColumns the number of columns in the grid
* @param makeColumnsEqualWidth whether or not the columns will have equal width
*/
public GridDialog(Shell parentShell, int numColumns, boolean makeColumnsEqualWidth) {
super(parentShell);
mNumColumns = numColumns;
mMakeColumnsEqualWidth = makeColumnsEqualWidth;
}
/**
* Creates the content of the dialog. The <var>parent</var> composite is a {@link GridLayout}
* created with the <var>numColumn</var> and <var>makeColumnsEqualWidth</var> parameters
* passed to {@link #GridDialog(Shell, int, boolean)}.
* @param parent the parent composite.
*/
public abstract void createDialogContent(Composite parent);
@Override
protected Control createDialogArea(Composite parent) {
Composite top = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(mNumColumns, mMakeColumnsEqualWidth);
layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
layout.horizontalSpacing = convertHorizontalDLUsToPixels(
IDialogConstants.HORIZONTAL_SPACING);
top.setLayout(layout);
top.setLayoutData(new GridData(GridData.FILL_BOTH));
createDialogContent(top);
applyDialogFont(top);
return top;
}
}