2 * Copyright (C) 2009 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.sdkuilib.internal.widgets;
19 import com.android.sdklib.AndroidVersion;
20 import com.android.sdklib.IAndroidTarget;
21 import com.android.sdklib.internal.avd.AvdManager;
22 import com.android.sdklib.internal.avd.AvdManager.AvdInfo;
23 import com.android.sdklib.internal.avd.AvdManager.AvdInfo.AvdStatus;
25 import org.eclipse.swt.SWT;
26 import org.eclipse.swt.graphics.Point;
27 import org.eclipse.swt.graphics.Rectangle;
28 import org.eclipse.swt.layout.GridData;
29 import org.eclipse.swt.layout.GridLayout;
30 import org.eclipse.swt.widgets.Composite;
31 import org.eclipse.swt.widgets.Dialog;
32 import org.eclipse.swt.widgets.Display;
33 import org.eclipse.swt.widgets.Label;
34 import org.eclipse.swt.widgets.Shell;
36 import java.util.HashMap;
41 * Dialog displaying the details of an AVD.
43 final class AvdDetailsDialog extends Dialog {
45 /** Last dialog size for this session. */
46 private static Point sLastSize;
48 private Shell mDialogShell;
49 private final AvdInfo mAvdInfo;
51 private Composite mRootComposite;
53 public AvdDetailsDialog(Shell shell, AvdInfo avdInfo) {
54 super(shell, SWT.APPLICATION_MODAL);
57 setText("AVD details");
61 * Open the dialog and blocks till it gets closed
65 positionShell(); //$hide$ (hide from SWT designer)
67 mDialogShell.layout();
69 Display display = getParent().getDisplay();
70 while (!mDialogShell.isDisposed()) {
71 if (!display.readAndDispatch()) {
76 if (!mDialogShell.isDisposed()) {
77 sLastSize = mDialogShell.getSize();
83 * Create contents of the dialog.
85 private void createContents() {
86 mDialogShell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.RESIZE);
87 mDialogShell.setLayout(new GridLayout(1, false));
88 mDialogShell.setSize(450, 300);
89 mDialogShell.setText(getText());
91 mRootComposite = new Composite(mDialogShell, SWT.NONE);
92 mRootComposite.setLayout(new GridLayout(2, false));
93 mRootComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
97 Composite c = new Composite(mRootComposite, SWT.NONE);
98 c.setLayout(gl = new GridLayout(2, false));
99 gl.marginHeight = gl.marginWidth = 0;
100 c.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
102 if (mAvdInfo != null) {
103 displayValue(c, "Name:", mAvdInfo.getName());
104 displayValue(c, "Path:", mAvdInfo.getPath());
106 if (mAvdInfo.getStatus() != AvdStatus.OK) {
107 displayValue(c, "Error:", mAvdInfo.getErrorMessage());
109 IAndroidTarget target = mAvdInfo.getTarget();
110 AndroidVersion version = target.getVersion();
111 displayValue(c, "Target:", String.format("%s (API level %s)",
112 target.getName(), version.getApiString()));
114 // display some extra values.
115 Map<String, String> properties = mAvdInfo.getProperties();
116 if (properties != null) {
117 String skin = properties.get(AvdManager.AVD_INI_SKIN_NAME);
119 displayValue(c, "Skin:", skin);
122 String sdcard = properties.get(AvdManager.AVD_INI_SDCARD_SIZE);
123 if (sdcard == null) {
124 sdcard = properties.get(AvdManager.AVD_INI_SDCARD_PATH);
126 if (sdcard != null) {
127 displayValue(c, "SD Card:", sdcard);
130 // display other hardware
131 HashMap<String, String> copy = new HashMap<String, String>(properties);
132 // remove stuff we already displayed (or that we don't want to display)
133 copy.remove(AvdManager.AVD_INI_SKIN_NAME);
134 copy.remove(AvdManager.AVD_INI_SKIN_PATH);
135 copy.remove(AvdManager.AVD_INI_SDCARD_SIZE);
136 copy.remove(AvdManager.AVD_INI_SDCARD_PATH);
137 copy.remove(AvdManager.AVD_INI_IMAGES_1);
138 copy.remove(AvdManager.AVD_INI_IMAGES_2);
140 if (copy.size() > 0) {
141 Label l = new Label(mRootComposite, SWT.SEPARATOR | SWT.HORIZONTAL);
142 l.setLayoutData(new GridData(
143 GridData.FILL, GridData.CENTER, false, false, 2, 1));
145 c = new Composite(mRootComposite, SWT.NONE);
146 c.setLayout(gl = new GridLayout(2, false));
147 gl.marginHeight = gl.marginWidth = 0;
148 c.setLayoutData(new GridData(GridData.FILL_BOTH));
150 Set<String> keys = copy.keySet();
151 for (String key : keys) {
152 displayValue(c, key + ":", copy.get(key));
160 // -- Start of internal part ----------
161 // Hide everything down-below from SWT designer
165 * Displays a value with a label.
167 * @param parent the parent Composite in which to display the value. This Composite must use a
168 * {@link GridLayout} with 2 columns.
169 * @param label the label of the value to display.
170 * @param value the string value to display.
172 private void displayValue(Composite parent, String label, String value) {
173 Label l = new Label(parent, SWT.NONE);
175 l.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
177 l = new Label(parent, SWT.NONE);
179 l.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
183 * Centers the dialog in its parent shell.
185 private void positionShell() {
186 // Centers the dialog in its parent shell
187 Shell child = mDialogShell;
188 Shell parent = getParent();
189 if (child != null && parent != null) {
191 // get the parent client area with a location relative to the display
192 Rectangle parentArea = parent.getClientArea();
193 Point parentLoc = parent.getLocation();
194 int px = parentLoc.x;
195 int py = parentLoc.y;
196 int pw = parentArea.width;
197 int ph = parentArea.height;
199 // Reuse the last size if there's one, otherwise use the default
200 Point childSize = sLastSize != null ? sLastSize : child.getSize();
201 int cw = childSize.x;
202 int ch = childSize.y;
204 child.setLocation(px + (pw - cw) / 2, py + (ph - ch) / 2);
205 child.setSize(cw, ch);
209 // End of hiding from SWT Designer