Merge change I0d2bc2d1 into eclair

* changes:
  New based dialog class.
This commit is contained in:
Android (Google) Code Review
2009-10-07 19:08:05 -04:00
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.AvdInfo;
import com.android.sdkuilib.internal.repository.SettingsController;
import com.android.sdkuilib.ui.GridDialog;
import org.eclipse.jface.dialogs.Dialog;
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.
* 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.
private static boolean sWipeData = false;
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,
SettingsController settingsController) {
super(parentShell);
super(parentShell, 2, false);
mAvd = avd;
mSdkLocation = sdkLocation;
mSettingsController = settingsController;
@@ -112,42 +113,31 @@ final class AvdStartDialog extends Dialog {
}
@Override
protected Control createDialogArea(final Composite parent) {
public void createDialogContent(final Composite parent) {
GridData gd;
// create a composite with standard margins and spacing
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);
Label l = new Label(parent, SWT.NONE);
l.setText("Skin:");
l = new Label(composite, SWT.NONE);
l = new Label(parent, SWT.NONE);
l.setText(mSkinDisplay);
l.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
l = new Label(composite, SWT.NONE);
l = new Label(parent, SWT.NONE);
l.setText("Density:");
l = new Label(composite, SWT.NONE);
l = new Label(parent, SWT.NONE);
l.setText(getDensityText());
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.setEnabled(mEnableScaling);
boolean defaultState = mEnableScaling && sSkinScaling.get(mAvd.getName()) != null;
mScaleButton.setSelection(defaultState);
mScaleButton.setLayoutData(gd = new GridData(GridData.FILL_HORIZONTAL));
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));
gd.horizontalIndent = 30;
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));
gd.horizontalSpan = 2;
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));
gd.horizontalSpan = 2;
applyDialogFont(composite);
// if the scaling is enabled by default, we must initialize the value of mScale
if (defaultState) {
onScaleChange();
}
return composite;
}
@Override

View File

@@ -16,14 +16,13 @@
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.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
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.Combo;
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
* pixel density.
*/
class ResolutionChooserDialog extends Dialog {
class ResolutionChooserDialog extends GridDialog {
public final static float[] MONITOR_SIZES = new float[] {
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;
ResolutionChooserDialog(Shell parentShell) {
super(parentShell);
super(parentShell, 2, false);
}
/**
@@ -84,22 +83,11 @@ class ResolutionChooserDialog extends Dialog {
}
@Override
protected Control createDialogArea(Composite parent) {
// create a composite with standard margins and spacing
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);
public void createDialogContent(Composite parent) {
Label l = new Label(parent, SWT.NONE);
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) {
if (Math.round(size) == 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:");
mMonitorCombo = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
mMonitorCombo = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
mMonitors = parent.getDisplay().getMonitors();
for (Monitor m : mMonitors) {
Rectangle r = m.getBounds();
@@ -131,8 +119,5 @@ class ResolutionChooserDialog extends Dialog {
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;
}
}