1 /* //device/tools/ddms/src/com/android/ddms/AboutDialog.java 2 ** 3 ** Copyright 2007, The Android Open Source Project 4 ** 5 ** Licensed under the Apache License, Version 2.0 (the "License"); 6 ** you may not use this file except in compliance with the License. 7 ** You may obtain a copy of the License at 8 ** 9 ** http://www.apache.org/licenses/LICENSE-2.0 10 ** 11 ** Unless required by applicable law or agreed to in writing, software 12 ** distributed under the License is distributed on an "AS IS" BASIS, 13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 ** See the License for the specific language governing permissions and 15 ** limitations under the License. 16 */ 17 18 package com.android.ddms; 19 20 import com.android.ddmlib.Log; 21 import com.android.ddmuilib.ImageLoader; 22 23 import org.eclipse.swt.SWT; 24 import org.eclipse.swt.events.SelectionAdapter; 25 import org.eclipse.swt.events.SelectionEvent; 26 import org.eclipse.swt.graphics.Image; 27 import org.eclipse.swt.layout.GridData; 28 import org.eclipse.swt.layout.GridLayout; 29 import org.eclipse.swt.widgets.Button; 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; 35 36 import java.io.InputStream; 37 38 /** 39 * Our "about" box. 40 */ 41 public class AboutDialog extends Dialog { 42 43 private Image logoImage; 44 45 /** 46 * Create with default style. 47 */ 48 public AboutDialog(Shell parent) { 49 this(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); 50 } 51 52 /** 53 * Create with app-defined style. 54 */ 55 public AboutDialog(Shell parent, int style) { 56 super(parent, style); 57 } 58 59 /** 60 * Prepare and display the dialog. 61 */ 62 public void open() { 63 Shell parent = getParent(); 64 Shell shell = new Shell(parent, getStyle()); 65 shell.setText("About..."); 66 67 logoImage = loadImage(shell, "ddms-logo.png"); // $NON-NLS-1$ 68 createContents(shell); 69 shell.pack(); 70 71 shell.open(); 72 Display display = parent.getDisplay(); 73 while (!shell.isDisposed()) { 74 if (!display.readAndDispatch()) 75 display.sleep(); 76 } 77 78 logoImage.dispose(); 79 } 80 81 /* 82 * Load an image file from a resource. 83 * 84 * This depends on Display, so I'm not sure what the rules are for 85 * loading once and caching in a static class field. 86 */ 87 private Image loadImage(Shell shell, String fileName) { 88 InputStream imageStream; 89 String pathName = "/images/" + fileName; // $NON-NLS-1$ 90 91 imageStream = this.getClass().getResourceAsStream(pathName); 92 if (imageStream == null) { 93 //throw new NullPointerException("couldn't find " + pathName); 94 Log.w("ddms", "Couldn't load " + pathName); 95 Display display = shell.getDisplay(); 96 return ImageLoader.createPlaceHolderArt(display, 100, 50, 97 display.getSystemColor(SWT.COLOR_BLUE)); 98 } 99 100 Image img = new Image(shell.getDisplay(), imageStream); 101 if (img == null) 102 throw new NullPointerException("couldn't load " + pathName); 103 return img; 104 } 105 106 /* 107 * Create the about box contents. 108 */ 109 private void createContents(final Shell shell) { 110 GridLayout layout; 111 GridData data; 112 Label label; 113 114 shell.setLayout(new GridLayout(2, false)); 115 116 // Fancy logo 117 Label logo = new Label(shell, SWT.BORDER); 118 logo.setImage(logoImage); 119 120 // Text Area 121 Composite textArea = new Composite(shell, SWT.NONE); 122 layout = new GridLayout(1, true); 123 textArea.setLayout(layout); 124 125 // Text lines 126 label = new Label(textArea, SWT.NONE); 127 if (Main.sRevision != null && Main.sRevision.length() > 0) { 128 label.setText("Dalvik Debug Monitor Revision " + Main.sRevision); 129 } else { 130 label.setText("Dalvik Debug Monitor"); 131 } 132 label = new Label(textArea, SWT.NONE); 133 label.setText("Copyright 2007, The Android Open Source Project"); 134 label = new Label(textArea, SWT.NONE); 135 label.setText("All Rights Reserved."); 136 137 // blank spot in grid 138 label = new Label(shell, SWT.NONE); 139 140 // "OK" button 141 Button ok = new Button(shell, SWT.PUSH); 142 ok.setText("OK"); 143 data = new GridData(GridData.HORIZONTAL_ALIGN_END); 144 data.widthHint = 80; 145 ok.setLayoutData(data); 146 ok.addSelectionListener(new SelectionAdapter() { 147 @Override 148 public void widgetSelected(SelectionEvent e) { 149 shell.close(); 150 } 151 }); 152 153 shell.pack(); 154 155 shell.setDefaultButton(ok); 156 } 157 } 158