From 47df36554cb429a9924b0539373bbed9a30c62ce Mon Sep 17 00:00:00 2001 From: Munkyu Im Date: Tue, 10 Mar 2015 16:22:41 +0900 Subject: [PATCH] dialog: Add tap device dialog for macosx It shows current network status for bridged network. It was not added on patch e6426a0f5779df7dd6f449bffe3420b4fa232718 Change-Id: I0cfc44e76f236fd7339a1dd0db4134c3589d41d7 Signed-off-by: Munkyu Im --- .../manager/ui/dialog/TapDeviceDialogForMac.java | 285 +++++++++++++++++++++ 1 file changed, 285 insertions(+) create mode 100644 common-project/src/org/tizen/emulator/manager/ui/dialog/TapDeviceDialogForMac.java diff --git a/common-project/src/org/tizen/emulator/manager/ui/dialog/TapDeviceDialogForMac.java b/common-project/src/org/tizen/emulator/manager/ui/dialog/TapDeviceDialogForMac.java new file mode 100644 index 0000000..7db5667 --- /dev/null +++ b/common-project/src/org/tizen/emulator/manager/ui/dialog/TapDeviceDialogForMac.java @@ -0,0 +1,285 @@ +/* Emulator Manager + * + * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Munkyu Im + * Minkee Lee + * SeokYeon Hwang + * Sangho Park + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +package org.tizen.emulator.manager.ui.dialog; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.layout.RowData; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.tizen.emulator.manager.logging.EMLogger; +import org.tizen.emulator.manager.resources.ColorResources; +import org.tizen.emulator.manager.resources.FontResources; +import org.tizen.emulator.manager.resources.ImageResources; +import org.tizen.emulator.manager.resources.PatchImageResources; +import org.tizen.emulator.manager.ui.MainDialog; +import org.tizen.emulator.manager.ui.widgets.ImageCombo; +import org.tizen.emulator.manager.ui.widgets.ImageLabel; +import org.tizen.emulator.manager.ui.widgets.WSTATE; +import org.tizen.emulator.manager.vms.helper.VMWorkerException; + +public class TapDeviceDialogForMac { + private static Shell dialog = null; + private static int width = 300; + private static int height = 155; + private static Image image; + private static int COMP_WIDTH = 270; + private static int UPPER_HEIGHT = 54; + private static int ITEM_COUNT = 2; + + private static Text nameText; + private static ImageCombo combo; + + private static Button okButton; + private static Button cancelButton; + + private static String tapName; + private static String ifName; + + static { + image = PatchImageResources.getDetailListView2(ITEM_COUNT); + } + + public static void open() { + makeDialog(); + dialog.open(); + while (!dialog.isDisposed()) { + if (!Display.getCurrent().readAndDispatch()) { + Display.getCurrent().sleep(); + } + } + } + + private static void makeDialog() { + dialog = new Shell(MainDialog.getShell(), SWT.DIALOG_TRIM + | SWT.APPLICATION_MODAL); + dialog.setText("Setting tap device."); + dialog.setSize(width, height); + dialog.setBackground(ColorResources.TAB_CONTENTS_BG_COLOR.getColor()); + RowLayout rowLayout = new RowLayout(); + rowLayout.type = SWT.VERTICAL; + rowLayout.marginTop = 15; + rowLayout.marginLeft = 10; + rowLayout.spacing = 15; + + dialog.setLayout(rowLayout); + + makeUpperComposite(); + makeLowerComposite(); + addListener(); + + } + + private static void makeUpperComposite() { + Composite upperComp = new Composite(dialog, SWT.BORDER); + upperComp.setLayoutData(new RowData(COMP_WIDTH, UPPER_HEIGHT)); + upperComp.addPaintListener(new PaintListener() { + public void paintControl(PaintEvent e) { + Rectangle rect = ((Composite) e.widget).getClientArea(); + e.gc.drawImage(image, rect.x - 2, rect.y); + + } + }); + upperComp.setLayout(new FormLayout()); + + // tap name (text input) + Label nameLabel = new Label(upperComp, SWT.NONE); + nameLabel.setFont(FontResources.DETAIL_TITLE_FONT.getFont()); + nameLabel.setText("Tap name"); + nameLabel.setBackground(ColorResources.DETAIL_MIDDLE_COLOR.getColor()); + FormData data = new FormData(); + data.left = new FormAttachment(0, 15); + data.top = new FormAttachment(0, 4); + data.width = 85; + data.height = 20; + nameLabel.setLayoutData(data); + + Image INPUTBOX_ON_IMAGE = PatchImageResources.getInputBoxON(150); + ImageLabel valueLabel = new ImageLabel(upperComp, SWT.NONE); + valueLabel.setEnableImage(INPUTBOX_ON_IMAGE); + valueLabel.setLayout(new FormLayout()); + data = new FormData(); + data.left = new FormAttachment(0, 100); + data.top = new FormAttachment(0, 4); + data.width = 150; + data.height = 19; + valueLabel.setLayoutData(data); + + nameText = new Text(valueLabel, SWT.NONE); + nameText.setBackground(ColorResources.DETAIL_INPUT_BOX_COLOR.getColor()); + nameText.setFont(FontResources.DETAIL_LABEL_FONT.getFont()); + nameText.setForeground(ColorResources.DETAIL_ENABLE_FONT_COLOR + .getColor()); + nameText.setTextLimit(20); + + data = new FormData(); + data.left = new FormAttachment(0, 5); + data.top = new FormAttachment(0, 2); + data.right = new FormAttachment(100, -5); + data.bottom = new FormAttachment(100, -2); + nameText.setLayoutData(data); + nameText.setText("auto"); + nameText.setEnabled(false); + valueLabel.setEnabled(false); + + // interface (combo select) + Label ifLabel = new Label(upperComp, SWT.NONE); + ifLabel.setFont(FontResources.DETAIL_TITLE_FONT.getFont()); + ifLabel.setText("Interface"); + ifLabel.setBackground(ColorResources.DETAIL_MIDDLE_COLOR.getColor()); + data = new FormData(); + data.left = new FormAttachment(0, 15); + data.top = new FormAttachment(0, 31); + data.width = 85; + data.height = 20; + ifLabel.setLayoutData(data); + + combo = new ImageCombo(upperComp, SWT.NONE); + combo.setImage(WSTATE.NORMAL, INPUTBOX_ON_IMAGE); + combo.setImage(WSTATE.PUSH, INPUTBOX_ON_IMAGE); + combo.setImage(WSTATE.HOVER, INPUTBOX_ON_IMAGE); + combo.setImage(WSTATE.DISABLE_ON, INPUTBOX_ON_IMAGE); + + combo.setArrowButtonImage(ImageResources.ARROW_DROPDOWN.getImage()); + combo.setEnabled(true); + combo.setItemHeight(INPUTBOX_ON_IMAGE.getImageData().height); + combo.setLayout(new FormLayout()); + + data = new FormData(); + data.left = new FormAttachment(0, 100); + data.top = new FormAttachment(0, 31); + data.width = INPUTBOX_ON_IMAGE.getImageData().width; + data.height = INPUTBOX_ON_IMAGE.getImageData().height; + combo.setLayoutData(data); + + try { + for (String str : getInterfaceList()) { + if (str.equals("en0")) { + combo.add(str, 0); + continue; + } + combo.add(str); + } + combo.select(0); + } catch (VMWorkerException e) { + EMLogger.getLogger().warning("Failed to get interface list."); + EMLogger.getLogger().warning(e.getMessage()); + new MessageDialog() + .openWarningDialog("Failed to get interface list.\n" + + e.getMessage()); + } + + } + + private static void makeLowerComposite() { + Composite lowerComp = new Composite(dialog, 0); + lowerComp.setLayoutData(new RowData(COMP_WIDTH + 1, 30)); + lowerComp + .setBackground(ColorResources.TAB_CONTENTS_BG_COLOR.getColor()); + lowerComp.setLayout(new FormLayout()); + + int BUTTON_WIDTH = 128; + int BUTTON_HEIGHT = 26; + + okButton = new Button(lowerComp, SWT.PUSH); + okButton.setText("OK"); + okButton.setEnabled(true); + okButton.setFont(FontResources.COMBO_BUTTON_FONT.getFont()); + FormData data = new FormData(); + data.left = new FormAttachment(0, 0); + data.top = new FormAttachment(0, 0); + data.width = BUTTON_WIDTH; + data.height = BUTTON_HEIGHT; + okButton.setLayoutData(data); + + cancelButton = new Button(lowerComp, SWT.PUSH); + cancelButton.setText("CANCEL"); + cancelButton.setEnabled(true); + cancelButton.setFont(FontResources.COMBO_BUTTON_FONT.getFont()); + data = new FormData(); + data.left = new FormAttachment(okButton, 16); + data.top = new FormAttachment(0, 0); + data.width = BUTTON_WIDTH; + data.height = BUTTON_HEIGHT; + cancelButton.setLayoutData(data); + + } + + private static void addListener() { + cancelButton.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent arg0) { + dialog.close(); + } + + public void widgetDefaultSelected(SelectionEvent arg0) { + + } + }); + + okButton.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent arg0) { + + tapName = nameText.getText(); + ifName = combo.getText(); + dialog.close(); + + } + + public void widgetDefaultSelected(SelectionEvent arg0) { + // TODO Auto-generated method stub + } + }); + + } + + private static List getInterfaceList() throws VMWorkerException { + List result = new ArrayList(); + //TODO: currently support only en0 + result.add("en0"); + return result; + } +} -- 2.7.4