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.internal.widgets; 18 19 import com.android.sdklib.AndroidVersion; 20 import com.android.sdklib.IAndroidTarget; 21 import com.android.sdklib.internal.avd.AvdInfo; 22 import com.android.sdklib.internal.avd.AvdManager; 23 import com.android.sdklib.internal.avd.AvdInfo.AvdStatus; 24 import com.android.sdkuilib.ui.GridDataBuilder; 25 import com.android.sdkuilib.ui.GridLayoutBuilder; 26 import com.android.sdkuilib.ui.SwtBaseDialog; 27 28 import org.eclipse.swt.SWT; 29 import org.eclipse.swt.layout.GridData; 30 import org.eclipse.swt.layout.GridLayout; 31 import org.eclipse.swt.widgets.Composite; 32 import org.eclipse.swt.widgets.Label; 33 import org.eclipse.swt.widgets.Shell; 34 35 import java.util.HashMap; 36 import java.util.Map; 37 38 /** 39 * Dialog displaying the details of an AVD. 40 */ 41 final class AvdDetailsDialog extends SwtBaseDialog { 42 43 private final AvdInfo mAvdInfo; 44 45 public AvdDetailsDialog(Shell shell, AvdInfo avdInfo) { 46 super(shell, SWT.APPLICATION_MODAL, "AVD details"); 47 mAvdInfo = avdInfo; 48 } 49 50 /** 51 * Create contents of the dialog. 52 */ 53 @Override 54 protected void createContents() { 55 Shell shell = getShell(); 56 GridLayoutBuilder.create(shell).columns(2); 57 GridDataBuilder.create(shell).fill(); 58 59 GridLayout gl; 60 61 Composite c = new Composite(shell, SWT.NONE); 62 c.setLayout(gl = new GridLayout(2, false)); 63 gl.marginHeight = gl.marginWidth = 0; 64 c.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 65 66 if (mAvdInfo != null) { 67 displayValue(c, "Name:", mAvdInfo.getName()); 68 displayValue(c, "CPU/ABI:", AvdInfo.getPrettyAbiType(mAvdInfo.getAbiType())); 69 70 displayValue(c, "Path:", mAvdInfo.getDataFolderPath()); 71 72 if (mAvdInfo.getStatus() != AvdStatus.OK) { 73 displayValue(c, "Error:", mAvdInfo.getErrorMessage()); 74 } else { 75 IAndroidTarget target = mAvdInfo.getTarget(); 76 AndroidVersion version = target.getVersion(); 77 displayValue(c, "Target:", String.format("%s (API level %s)", 78 target.getName(), version.getApiString())); 79 80 // display some extra values. 81 Map<String, String> properties = mAvdInfo.getProperties(); 82 if (properties != null) { 83 String skin = properties.get(AvdManager.AVD_INI_SKIN_NAME); 84 if (skin != null) { 85 displayValue(c, "Skin:", skin); 86 } 87 88 String sdcard = properties.get(AvdManager.AVD_INI_SDCARD_SIZE); 89 if (sdcard == null) { 90 sdcard = properties.get(AvdManager.AVD_INI_SDCARD_PATH); 91 } 92 if (sdcard != null) { 93 displayValue(c, "SD Card:", sdcard); 94 } 95 96 String snapshot = properties.get(AvdManager.AVD_INI_SNAPSHOT_PRESENT); 97 if (snapshot != null) { 98 displayValue(c, "Snapshot:", snapshot); 99 } 100 101 // display other hardware 102 HashMap<String, String> copy = new HashMap<String, String>(properties); 103 // remove stuff we already displayed (or that we don't want to display) 104 copy.remove(AvdManager.AVD_INI_ABI_TYPE); 105 copy.remove(AvdManager.AVD_INI_CPU_ARCH); 106 copy.remove(AvdManager.AVD_INI_SKIN_NAME); 107 copy.remove(AvdManager.AVD_INI_SKIN_PATH); 108 copy.remove(AvdManager.AVD_INI_SDCARD_SIZE); 109 copy.remove(AvdManager.AVD_INI_SDCARD_PATH); 110 copy.remove(AvdManager.AVD_INI_IMAGES_1); 111 copy.remove(AvdManager.AVD_INI_IMAGES_2); 112 113 if (copy.size() > 0) { 114 Label l = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL); 115 l.setLayoutData(new GridData( 116 GridData.FILL, GridData.CENTER, false, false, 2, 1)); 117 118 c = new Composite(shell, SWT.NONE); 119 c.setLayout(gl = new GridLayout(2, false)); 120 gl.marginHeight = gl.marginWidth = 0; 121 c.setLayoutData(new GridData(GridData.FILL_BOTH)); 122 123 for (Map.Entry<String, String> entry : copy.entrySet()) { 124 displayValue(c, entry.getKey() + ":", entry.getValue()); 125 } 126 } 127 } 128 } 129 } 130 } 131 132 // -- Start of internal part ---------- 133 // Hide everything down-below from SWT designer 134 //$hide>>$ 135 136 137 @Override 138 protected void postCreate() { 139 // pass 140 } 141 142 /** 143 * Displays a value with a label. 144 * 145 * @param parent the parent Composite in which to display the value. This Composite must use a 146 * {@link GridLayout} with 2 columns. 147 * @param label the label of the value to display. 148 * @param value the string value to display. 149 */ 150 private void displayValue(Composite parent, String label, String value) { 151 Label l = new Label(parent, SWT.NONE); 152 l.setText(label); 153 l.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false)); 154 155 l = new Label(parent, SWT.NONE); 156 l.setText(value); 157 l.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); 158 } 159 160 // End of hiding from SWT Designer 161 //$hide<<$ 162 } 163