From: minkee.lee Date: Wed, 9 Sep 2015 07:28:50 +0000 (+0900) Subject: ui: add dialog which has an empty body. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ac52f5bc0a32410264d72f86c9c20839bbee4244;p=sdk%2Femulator%2Femulator-manager.git ui: add dialog which has an empty body. - A class "Dialog" provides title and buttons. - Add an empty VMModifyDialog with default scroll-bar. Change-Id: Ib75772d52b6591c5d11323e8b8ab50d11d513caf Signed-off-by: minkee.lee --- diff --git a/src/org/tizen/emulator/manager/renewal/resources/ColorResources.java b/src/org/tizen/emulator/manager/renewal/resources/ColorResources.java index 742f8e8..1c31545 100644 --- a/src/org/tizen/emulator/manager/renewal/resources/ColorResources.java +++ b/src/org/tizen/emulator/manager/renewal/resources/ColorResources.java @@ -57,7 +57,8 @@ public enum ColorResources { MESSAGE_BOX_CONTENTS_FONT(102, 102, 102), MESSAGE_BOX_BG(224, 224, 224), MESSAGE_BOX_BUTTON_BG(149, 159, 165), - MESSAGE_BOX_BUTTON_FONT(255, 255, 255); + MESSAGE_BOX_BUTTON_FONT(255, 255, 255), + MESSABE_BOX_BORDER(155,155,155); public static ColorResources GRAY_BTN_FONT = WHITE; diff --git a/src/org/tizen/emulator/manager/ui/renewal/dialog/Dialog.java b/src/org/tizen/emulator/manager/ui/renewal/dialog/Dialog.java new file mode 100644 index 0000000..6acc923 --- /dev/null +++ b/src/org/tizen/emulator/manager/ui/renewal/dialog/Dialog.java @@ -0,0 +1,174 @@ +/* + * Emulator Manager + * + * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Minkee Lee + * JiHye Kim + * 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.renewal.dialog; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.tizen.emulator.manager.renewal.resources.ColorResources; + +public class Dialog { + + private Shell shell; + + private final Shell parent; + private final String title; + private final int width; + private final int height; + private final int buttonStyle; + + private Composite bodyComp; + private int returnValue = SWT.CANCEL; + + protected static final int BORDER_WIDTH = 1; + + public Dialog(Shell parent, String title, int width, int height, int buttonStyle) { + this.parent = parent; + this.title = title; + this.width = width; + this.height = height; + this.buttonStyle = buttonStyle; + } + + public void create() { + initDialog(); + makeDialog(); + } + + public int open() { + shell.open(); + while(!shell.isDisposed()) { + if(!Display.getCurrent().readAndDispatch()) { + Display.getCurrent().sleep(); + } + } + return returnValue; + } + + + public Shell getShell() { + return shell; + } + + + public void setReturnValue(int returnValue) { + this.returnValue = returnValue; + } + + + // Only sub class can get & make body content + protected Composite getBodyComposite() { + return bodyComp; + } + + + + private void makeDialog() { + DialogTitle.create(shell, title); + initBody(); + DialogButtons.create(this, buttonStyle); + } + + + private void initDialog() { + shell = new Shell(parent, SWT.NO_TRIM | SWT.APPLICATION_MODAL); + + // set dialog layout + GridLayout layout = new GridLayout(); + layout.numColumns = 1; + layout.marginWidth = BORDER_WIDTH; + layout.marginHeight = BORDER_WIDTH; + layout.verticalSpacing = 0; + shell.setLayout(layout); + + // set dialog position and size + shell.setBounds(computeDialogBounds(width, height)); + + // set dialog border + addPaintListener(); + } + + + private Rectangle computeDialogBounds(int width, int height) { + Rectangle result = new Rectangle(0, 0, 0, 0); + Rectangle clientRect = parent.getClientArea(); + Rectangle boundRect = parent.getBounds(); + int titleBarHeight = boundRect.height - clientRect.height; + + // calculate x, y except title bar. + result.width = width; + result.height = height; + result.x = (clientRect.width - width) / 2 + boundRect.x; + result.y = (clientRect.height - height) / 2 + boundRect.y + titleBarHeight; + return result; + } + + + // draw border + private void addPaintListener() { + shell.addPaintListener(new PaintListener() { + + @Override + public void paintControl(PaintEvent e) { + e.gc.setForeground(ColorResources.MESSABE_BOX_BORDER.getColor()); + e.gc.setLineWidth(BORDER_WIDTH); + + Rectangle rect = ((Shell)e.widget).getBounds(); + Rectangle drawRect = new Rectangle(0, 0, + rect.width - 1, rect.height - 1); + e.gc.drawRectangle(drawRect); + + } + }); + } + + + private void initBody() { + GridData gridData = new GridData(); + + // set size + gridData.grabExcessHorizontalSpace = true; + gridData.horizontalAlignment = GridData.FILL; + gridData.grabExcessVerticalSpace = true; + gridData.verticalAlignment = GridData.FILL; + + bodyComp = new Composite(shell, SWT.NONE); + bodyComp.setLayoutData(gridData); + } + +} diff --git a/src/org/tizen/emulator/manager/ui/renewal/dialog/DialogButtons.java b/src/org/tizen/emulator/manager/ui/renewal/dialog/DialogButtons.java new file mode 100644 index 0000000..0e30550 --- /dev/null +++ b/src/org/tizen/emulator/manager/ui/renewal/dialog/DialogButtons.java @@ -0,0 +1,142 @@ +/* + * Emulator Manager + * + * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Minkee Lee + * JiHye Kim + * 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.renewal.dialog; + +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.Event; +import org.eclipse.swt.widgets.Listener; +import org.tizen.emulator.manager.renewal.resources.ColorResources; +import org.tizen.emulator.manager.ui.renewal.widgets.GrayButton; + +public class DialogButtons { + + private static final int BUTTON_COMP_HEIGHT = 48; + + private static final int BUTTON_WIDTH = 106; + private static final int BUTTON_HEIGHT = 26; + private static final int BUTTON_SPACING = 6; + private static final int BUTTON_MARGIN_RIGHT = 8; + + private static final String CONFIRM = "Confirm"; + private static final String CANCEL = "Cancel"; + private static final String OK = "OK"; + + public static void create(Dialog dialog, int type) { + Composite buttonComp = new Composite(dialog.getShell(), SWT.NONE); + initButtonComp(buttonComp); + makeButtons(dialog, buttonComp, type); + } + + + private static void initButtonComp(Composite buttonComp) { + GridData gridData = new GridData(); + + // set size + gridData.grabExcessHorizontalSpace = true; + gridData.horizontalAlignment = GridData.FILL; + gridData.heightHint = BUTTON_COMP_HEIGHT; + + buttonComp.setBackground(ColorResources.MESSAGE_BOX_BG.getColor()); + buttonComp.setLayoutData(gridData); + + // for the transparency of corners of buttons. + buttonComp.setBackgroundMode(SWT.INHERIT_FORCE); + } + + + private static void makeButtons(Dialog dialog, Composite buttonComp, int type) { + if (type == (SWT.OK | SWT.CANCEL)) { + buttonComp.setLayout(getButtonLayout(2)); + makeConfirmCancelButton(dialog, buttonComp); + + } else { + buttonComp.setLayout(getButtonLayout(1)); + makeOKButton(dialog, buttonComp); + } + } + + private static GridLayout getButtonLayout(int numColumns) { + GridLayout layout = new GridLayout(); + layout.horizontalSpacing = BUTTON_SPACING; + layout.marginWidth = BUTTON_MARGIN_RIGHT; + layout.numColumns = numColumns; + return layout; + } + + private static void makeOKButton(Dialog dialog, Composite buttonComp) { + // align to center + GridData data = new GridData(BUTTON_WIDTH, BUTTON_HEIGHT); + data.horizontalAlignment = SWT.CENTER; + data.verticalAlignment = SWT.CENTER; + data.grabExcessHorizontalSpace = true; + data.grabExcessVerticalSpace = true; + makeButton(OK, SWT.OK, data, buttonComp, dialog); + } + + private static void makeConfirmCancelButton(Dialog dialog, Composite buttonComp) { + + GridData data; + + // Confirm button + data = new GridData(BUTTON_WIDTH, BUTTON_HEIGHT); + data.horizontalAlignment = SWT.RIGHT; + data.verticalAlignment = SWT.CENTER; + data.grabExcessHorizontalSpace = true; + data.grabExcessVerticalSpace = true; + makeButton(CONFIRM, SWT.OK, data, buttonComp, dialog); + + // Cancel button + data = new GridData(BUTTON_WIDTH, BUTTON_HEIGHT); + data.horizontalAlignment = SWT.RIGHT; + data.verticalAlignment = GridData.CENTER; + makeButton(CANCEL, SWT.CANCEL, data, buttonComp, dialog); + } + + private static void makeButton(final String text, final int type, GridData data, Composite buttonComp, final Dialog dialog) { + GrayButton button = new GrayButton(buttonComp, SWT.PUSH); + button.setText(text); + button.setLayoutData(data); + + button.addListener(SWT.Selection, new Listener(){ + @Override + public void handleEvent(Event event) { + if (event.type == SWT.Selection) { + dialog.setReturnValue(type); + dialog.getShell().close(); + } + } + }); + } + +} diff --git a/src/org/tizen/emulator/manager/ui/renewal/dialog/DialogTitle.java b/src/org/tizen/emulator/manager/ui/renewal/dialog/DialogTitle.java new file mode 100644 index 0000000..1f2c887 --- /dev/null +++ b/src/org/tizen/emulator/manager/ui/renewal/dialog/DialogTitle.java @@ -0,0 +1,89 @@ +/* + * Emulator Manager + * + * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Minkee Lee + * JiHye Kim + * 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.renewal.dialog; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.tizen.emulator.manager.renewal.resources.ColorResources; +import org.tizen.emulator.manager.renewal.resources.FontResources; + +public class DialogTitle { + + private static final int TITLE_COMP_HEIGHT = 31; + private static final int TITLE_MARGIN_TOP = 7; + private static final int TITLE_MARGIN_LEFT = 15; + + public static void create(Shell parentDialog, String title) { + Composite titleComp = new Composite(parentDialog, SWT.NONE); + initTitleComp(parentDialog, titleComp); + makeTitle(parentDialog, titleComp, title); + } + + + private static void initTitleComp(Shell parentDialog, Composite titleComp) { + + // create title composite + GridData gridData = new GridData(); + gridData.grabExcessHorizontalSpace = true; + gridData.horizontalAlignment = GridData.FILL; + gridData.heightHint = TITLE_COMP_HEIGHT; + + titleComp.setBackground(ColorResources.MESSAGE_BOX_TITLE_BG.getColor()); + titleComp.setLayoutData(gridData); + + titleComp.setLayout(new FormLayout()); + } + + + private static void makeTitle(Shell parentDialog, Composite titleComp, String title) { + // add title + FormData data = new FormData(); + data.top = new FormAttachment(0, TITLE_MARGIN_TOP); + data.left = new FormAttachment(0, TITLE_MARGIN_LEFT); + + Label titleLabel = new Label(titleComp, SWT.NONE); + titleLabel.setBackground(ColorResources.MESSAGE_BOX_TITLE_BG.getColor()); + titleLabel.setForeground(ColorResources.MESSAGE_BOX_TITLE_FONT.getColor()); + titleLabel.setFont(FontResources.MESSAGE_BOX_TITLE.getFont()); + titleLabel.setText(title); + titleLabel.setLayoutData(data); + + // make title drag-able + DragHandler.set(parentDialog, titleLabel, titleComp); + } +} diff --git a/src/org/tizen/emulator/manager/ui/renewal/widgets/DragController.java b/src/org/tizen/emulator/manager/ui/renewal/dialog/DragHandler.java similarity index 94% rename from src/org/tizen/emulator/manager/ui/renewal/widgets/DragController.java rename to src/org/tizen/emulator/manager/ui/renewal/dialog/DragHandler.java index 4a81728..6ebd363 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/widgets/DragController.java +++ b/src/org/tizen/emulator/manager/ui/renewal/dialog/DragHandler.java @@ -29,7 +29,7 @@ */ -package org.tizen.emulator.manager.ui.renewal.widgets; +package org.tizen.emulator.manager.ui.renewal.dialog; import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.MouseListener; @@ -37,7 +37,7 @@ import org.eclipse.swt.events.MouseMoveListener; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; -public class DragController { +public class DragHandler { private Shell dialog; private int posX; @@ -50,7 +50,7 @@ public class DragController { * @param controls to receive drag event. */ public static void set(Shell shell, Control... controls) { - DragController controller = new DragController(); + DragHandler controller = new DragHandler(); controller.setTargetShell(shell); controller.setControls(controls); } diff --git a/src/org/tizen/emulator/manager/ui/renewal/dialog/VMModifyDialog.java b/src/org/tizen/emulator/manager/ui/renewal/dialog/VMModifyDialog.java new file mode 100644 index 0000000..814c71a --- /dev/null +++ b/src/org/tizen/emulator/manager/ui/renewal/dialog/VMModifyDialog.java @@ -0,0 +1,92 @@ +/* + * Emulator Manager + * + * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Minkee Lee + * JiHye Kim + * 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.renewal.dialog; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Shell; +import org.tizen.emulator.manager.renewal.resources.ColorResources; + +public class VMModifyDialog extends Dialog { + + private final static String TITLE = "VM Modify"; + private final static int WIDTH = 484; + private final static int HEIGHT = 496; + private final static int BUTTON_STYLE = SWT.OK | SWT.CANCEL; + + private Composite scrolledContent; + + public VMModifyDialog(Shell parent) { + super(parent, TITLE, WIDTH, HEIGHT, BUTTON_STYLE); + } + + + @Override + public void create() { + // - create title, buttons + // - init body + super.create(); + + // make body contents + createScrolledComposite(); + } + + + private void createScrolledComposite() { + initScrolledComposite(); + // TODO make detail item + } + + + private void initScrolledComposite() { + // add scrolled-composite + Composite bodyComp = getBodyComposite(); + bodyComp.setLayout(new FillLayout()); + ScrolledComposite sc = new ScrolledComposite(bodyComp, SWT.V_SCROLL); + scrolledContent = new Composite(sc, SWT.NONE); + + // add content + sc.setContent(scrolledContent); + scrolledContent.setBackground(ColorResources.BLACK.getColor()); + + GridLayout layout = new GridLayout(); + layout.numColumns = 1; + layout.marginWidth = 0; + layout.marginHeight = 0; + layout.verticalSpacing = 0; + scrolledContent.setLayout(layout); + } + +} diff --git a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTable.java b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTable.java index 97d0bc6..87d48f9 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTable.java +++ b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTable.java @@ -46,6 +46,7 @@ import org.tizen.emulator.manager.platform.Profile; import org.tizen.emulator.manager.platform.ProfileList; import org.tizen.emulator.manager.renewal.resources.ImageResources; import org.tizen.emulator.manager.ui.renewal.MainDialog; +import org.tizen.emulator.manager.ui.renewal.dialog.VMModifyDialog; import org.tizen.emulator.manager.ui.renewal.widgets.CreateVMCombo; import org.tizen.emulator.manager.ui.renewal.widgets.ImageButton; import org.tizen.emulator.manager.ui.table.Table; @@ -412,7 +413,10 @@ public class VMListTable { } public void modifyEmulator() { - // TODO: open modify view + VMModifyDialog dialog = new VMModifyDialog(MainDialog.getShell()); + dialog.create(); + dialog.open(); + // TODO do modify } public void launchEmulator() {