vm-modify: add H/W support item.
authorminkee.lee <minkee.lee@samsung.com>
Tue, 20 Oct 2015 09:25:31 +0000 (18:25 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Wed, 21 Oct 2015 09:36:39 +0000 (18:36 +0900)
Change-Id: I1a8203fe7245c00a172d6aee5250217a08cd6ebd
Signed-off-by: minkee.lee <minkee.lee@samsung.com>
12 files changed:
resource/renewal/res/btn_off_hover.png [new file with mode: 0644]
resource/renewal/res/btn_off_nml.png [new file with mode: 0644]
resource/renewal/res/btn_on_hover.png [new file with mode: 0644]
resource/renewal/res/btn_on_nml.png [new file with mode: 0644]
src/org/tizen/emulator/manager/renewal/resources/ImageResources.java
src/org/tizen/emulator/manager/ui/renewal/dialoghandler/VMModifyHandler.java
src/org/tizen/emulator/manager/ui/renewal/item/modify/common/DisplayItem.java
src/org/tizen/emulator/manager/ui/renewal/item/modify/comp/ModifyItem.java
src/org/tizen/emulator/manager/ui/renewal/item/modify/comp/PropertyValue.java
src/org/tizen/emulator/manager/ui/renewal/item/modify/vm/HWSupportItem.java [new file with mode: 0644]
src/org/tizen/emulator/manager/ui/renewal/item/modify/vm/OnOffSubItemComp.java [new file with mode: 0644]
src/org/tizen/emulator/manager/ui/renewal/widgets/ImageButton.java

diff --git a/resource/renewal/res/btn_off_hover.png b/resource/renewal/res/btn_off_hover.png
new file mode 100644 (file)
index 0000000..6440286
Binary files /dev/null and b/resource/renewal/res/btn_off_hover.png differ
diff --git a/resource/renewal/res/btn_off_nml.png b/resource/renewal/res/btn_off_nml.png
new file mode 100644 (file)
index 0000000..6aa19a7
Binary files /dev/null and b/resource/renewal/res/btn_off_nml.png differ
diff --git a/resource/renewal/res/btn_on_hover.png b/resource/renewal/res/btn_on_hover.png
new file mode 100644 (file)
index 0000000..b1fe264
Binary files /dev/null and b/resource/renewal/res/btn_on_hover.png differ
diff --git a/resource/renewal/res/btn_on_nml.png b/resource/renewal/res/btn_on_nml.png
new file mode 100644 (file)
index 0000000..9dfaab8
Binary files /dev/null and b/resource/renewal/res/btn_on_nml.png differ
index d20da4c..e09a39d 100644 (file)
@@ -257,12 +257,21 @@ public enum ImageResources {
        BTN_PROFILE_TV_UNSELECTED_HOVER("btn_profile_tv_unselected_hover"),
        BTN_PROFILE_TV_UNSELECTED_NML("btn_profile_tv_unselected_nml"),
 
+
+       // on off button
+       BTN_ON_NML("btn_on_nml"),
+       BTN_ON_HOVER("btn_on_hover"),
+       BTN_OFF_NML("btn_off_nml"),
+       BTN_OFF_HOVER("btn_off_hover"),
+
+
        // checkbox
        CHECKBOX_UNCHECKED_NML("btn_checkbox_unchecked_nml"),
        CHECKBOX_UNCHECKED_HOVER("btn_checkbox_unchecked_hover"),
        CHECKBOX_CHECKED_NML("btn_checkbox_checked_nml"),
        CHECKBOX_CHECKED_HOVER("btn_checkbox_checked_hover");
 
+
        String name;
        Image image;
        ImageData imageData;
index da74131..5418aaf 100644 (file)
@@ -49,6 +49,7 @@ import org.tizen.emulator.manager.ui.renewal.item.modify.common.RamSizeItem;
 import org.tizen.emulator.manager.ui.renewal.item.modify.common.SensorItem;
 import org.tizen.emulator.manager.ui.renewal.item.modify.vm.DeviceTemplateItem;
 import org.tizen.emulator.manager.ui.renewal.item.modify.vm.FileSharingItem;
+import org.tizen.emulator.manager.ui.renewal.item.modify.vm.HWSupportItem;
 import org.tizen.emulator.manager.vms.VMProperty;
 import org.tizen.emulator.manager.vms.VMPropertyValue;
 
@@ -95,6 +96,7 @@ public class VMModifyHandler {
                itemList.add(new SensorItem(deviceItem.getTreeRoot(), null));
                itemList.add(new ConnectivityItem(deviceItem.getTreeRoot(), null));
                itemList.add(new FileSharingItem());
+               itemList.add(new HWSupportItem());
 
 
 
index fa3122f..8c64b7d 100644 (file)
@@ -64,7 +64,7 @@ public class DisplayItem extends ModifyDialogItem {
        private static final String NAME = "display";
        private final ImageResources TITLE_ICON_RESOURCE = ImageResources.ICON_TITLE_DISPLAY;
 
-       private final int ROW_HEIGHT = ModifyItem.ITEM_HEIGHT + ModifyItem.LINE_WIDTH;
+       private final int ROW_HEIGHT = ModifyItem.ITEM_HEIGHT;
        private final int ROW_NUM = 4;  // TODO
 
 
@@ -72,7 +72,7 @@ public class DisplayItem extends ModifyDialogItem {
        public DisplayItem(TreeModifyItem treeRoot, List<RESOLUTION> resList) {
                super(NAME, TITLE);
                item = new SubTreeModifyItem();
-               item.setItemHeight(ROW_HEIGHT * ROW_NUM);
+               item.setItemHeight(ROW_HEIGHT * ROW_NUM + ModifyItem.LINE_WIDTH);
                treeRoot.addSubItem((SubTreeModifyItem)item);
                this.resList = resList;
        }
index 779b892..6a3b704 100644 (file)
@@ -66,6 +66,10 @@ public class ModifyItem {
                return itemHeight;
        }
 
+       public static int calcItemHeight(int rowNum) {
+               return ITEM_HEIGHT * rowNum + LINE_WIDTH;
+       }
+
 
        public void setItemHeight(int itemHeight) {
                this.itemHeight = itemHeight;
index e0e6fe5..d83bb3b 100644 (file)
@@ -342,6 +342,38 @@ public class PropertyValue {
        }
 
 
+       public void setCPUVirtualization(boolean isOn) {
+               if (isVMValue()) {
+                       vmValue.isHWVirtualization = isOn;
+               }
+       }
+
+
+       public void setGPUAcceleration(boolean isOn) {
+               if (isVMValue()) {
+                       vmValue.isGLAcceleration = isOn;
+               }
+       }
+
+
+       public boolean getCPUVirtualization() {
+               if (isVMValue()) {
+                       return vmValue.isHWVirtualization;
+               }
+               return false;
+       }
+
+
+       public boolean getGPUAcceleration() {
+               if (isVMValue()) {
+                       return vmValue.isGLAcceleration;
+               }
+               return false;
+       }
+
+
+
+
 //     public
 /*
        public RESOLUTION getResolution() {
diff --git a/src/org/tizen/emulator/manager/ui/renewal/item/modify/vm/HWSupportItem.java b/src/org/tizen/emulator/manager/ui/renewal/item/modify/vm/HWSupportItem.java
new file mode 100644 (file)
index 0000000..152afe4
--- /dev/null
@@ -0,0 +1,155 @@
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Minkee Lee <minkee.lee@samsung.com>
+ * JiHye Kim <jihye424.kim@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * Sangho Park <sangho1206.park@samsung.com>
+ *
+ * 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.item.modify.vm;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.tizen.emulator.manager.job.CheckGPU;
+import org.tizen.emulator.manager.job.CheckVT;
+import org.tizen.emulator.manager.renewal.resources.ImageResources;
+import org.tizen.emulator.manager.resources.StringResources;
+import org.tizen.emulator.manager.ui.Messages;
+import org.tizen.emulator.manager.ui.renewal.item.modify.common.ModifyDialogItem;
+import org.tizen.emulator.manager.ui.renewal.item.modify.comp.ModifyItem;
+import org.tizen.emulator.manager.ui.renewal.item.modify.comp.PropertyValue;
+
+public class HWSupportItem extends ModifyDialogItem {
+
+       private static final String TITLE = "HW Support";
+       private static final String NAME = "hwSupport";
+
+       private final int rowNum = 2; // TODO
+
+       private static final String TITLE_CPU = "CPU VT";
+       private static final String TITLE_GPU = "GPU";
+
+       private OnOffSubItemComp cpuItem;
+       private OnOffSubItemComp gpuItem;
+
+       private boolean isCpuOn = false;
+       private boolean isGpuOn = false;
+
+
+       private static String CPUDisableToolTipText = Messages.getString("CPUSupportSubViewItem.CPUToolTip.0") //$NON-NLS-1$
+                       + StringResources.NEW_LINE + Messages.getString("CPUSupportSubViewItem.CPUToolTip.1"); //$NON-NLS-1$
+
+       private static String GPUToolTipText = Messages.getString("GPUSupportSubViewItem.GPUToolTip.0") //$NON-NLS-1$
+                       + StringResources.NEW_LINE
+                       + Messages.getString("GPUSupportSubViewItem.GPUToolTip.1"); //$NON-NLS-1$
+       private static String GPUDisableToolTipText = Messages.getString("GPUSupportSubViewItem.GPUToolTip.2") //$NON-NLS-1$
+                         + StringResources.NEW_LINE + Messages.getString("GPUSupportSubViewItem.GPUToolTip.3"); //$NON-NLS-1$
+
+       public final String GALLIUM_WARNING_MSG =
+                       Messages.getString("GPUSupportSubViewItem.GraphicCardError.0") //$NON-NLS-1$
+                       +Messages.getString("GPUSupportSubViewItem.GraphicCardError.1") //$NON-NLS-1$
+                       + Messages.getString("GPUSupportSubViewItem.GraphicCardError.2") //$NON-NLS-1$
+                       + Messages.getString("GPUSupportSubViewItem.GraphicCardError.3") //$NON-NLS-1$
+                       + Messages.getString("GPUSupportSubViewItem.GraphicCardError.4"); //$NON-NLS-1$
+
+
+
+       public HWSupportItem() {
+               super(NAME, TITLE);
+       }
+
+
+       @Override
+       public void create(Composite parent) {
+               item = new ModifyItem();
+               item.setItemHeight(ModifyItem.ITEM_HEIGHT * rowNum);
+               item.init(parent);
+               item.setItemTitle(createIconTitle(item, ImageResources.ICON_TITLE_HWSUPPORT));
+               item.create();
+
+               makeBody();
+       }
+
+
+       private void makeBody() {
+               item.setBodyLayoutDefault();
+
+               // create CPU item
+               cpuItem = new OnOffSubItemComp(TITLE_CPU, item.getBody());
+               cpuItem.setLayoutData(getSubItemLayoutData());
+               cpuItem.create();
+               cpuItem.setOnOff(isCpuOn);
+               if (!CheckVT.isVTSupported()) {
+                       cpuItem.setDisable(CPUDisableToolTipText);
+               }
+
+               // create GPU item
+               gpuItem = new OnOffSubItemComp(TITLE_GPU, item.getBody());
+               gpuItem.setLayoutData(getSubItemLayoutData());
+               gpuItem.create();
+               gpuItem.setOnOff(isGpuOn);
+               if (!CheckGPU.isGPUSupported()) {
+                       gpuItem.setDisable(GPUDisableToolTipText);
+               } else {
+                       gpuItem.setToolTipText(GPUToolTipText);
+               }
+       }
+
+
+       private GridData getSubItemLayoutData() {
+               GridData data = new GridData();
+               data.grabExcessHorizontalSpace = true;
+               data.horizontalAlignment = SWT.FILL;
+               data.heightHint = ModifyItem.ITEM_HEIGHT;
+               return data;
+       }
+
+
+       @Override
+       public void setInitialValue(PropertyValue value) {
+               isCpuOn = value.getCPUVirtualization();
+               isGpuOn = value.getGPUAcceleration();
+
+
+       }
+
+       @Override
+       public void setValue(PropertyValue value) {
+               value.setCPUVirtualization(cpuItem.getOnOff());
+               value.setGPUAcceleration(gpuItem.getOnOff());
+
+       }
+
+       @Override
+       public ModifyDialogItem cloneItem() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+
+
+}
diff --git a/src/org/tizen/emulator/manager/ui/renewal/item/modify/vm/OnOffSubItemComp.java b/src/org/tizen/emulator/manager/ui/renewal/item/modify/vm/OnOffSubItemComp.java
new file mode 100644 (file)
index 0000000..0264332
--- /dev/null
@@ -0,0 +1,206 @@
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Minkee Lee <minkee.lee@samsung.com>
+ * JiHye Kim <jihye424.kim@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * Sangho Park <sangho1206.park@samsung.com>
+ *
+ * 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.item.modify.vm;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Canvas;
+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.renewal.resources.FontResources;
+import org.tizen.emulator.manager.renewal.resources.ImageResources;
+import org.tizen.emulator.manager.ui.renewal.item.modify.comp.ModifyItem;
+import org.tizen.emulator.manager.ui.renewal.widgets.ImageButton;
+import org.tizen.emulator.manager.ui.renewal.widgets.WSTATE;
+
+
+public class OnOffSubItemComp extends Composite {
+
+       private static final int VAR_INDENT = 88;
+       private static final int LABEL_SPACING = 6;
+       private static final int BUTTON_WIDTH = 54;
+       private static final int BUTTON_HEIGHT = 21;
+
+       private boolean isOn = true;
+       private String labelText = TEXT_ON;
+
+       private static String TEXT_ON = "On";
+       private static String TEXT_OFF = "Off";
+       private static String TEXT_DISABLE = "Disabled";
+
+       private ImageButton button;
+
+       private Canvas textCanvas;
+
+       @Override
+       public void setToolTipText(String toolTipText) {
+               button.setToolTipText(toolTipText);
+               textCanvas.setToolTipText(toolTipText);
+       }
+
+       private final String title;
+
+       public OnOffSubItemComp(String title, Composite parent) {
+               super(parent, SWT.NONE);
+               this.title = title;
+       }
+
+       public void setOnOff(boolean isOn) {
+               this.isOn = isOn;
+               button.setSelection(isOn);
+               labelText = getLabelText(isOn);
+               textCanvas.redraw();
+       }
+
+
+       public void setDisable(String toolTipText) {
+               isOn = false;
+
+               button.setSelection(false);
+               button.setEnabled(false);
+
+               labelText = TEXT_DISABLE;
+               textCanvas.setToolTipText(toolTipText);
+               textCanvas.redraw();
+       }
+
+       public boolean getOnOff() {
+               return isOn;
+       }
+
+       public void create() {
+               // create comp
+               this.setLayout(new FormLayout());
+
+               // draw title & virtical var
+               drawTitle(title);
+
+               // create button
+               button = new ImageButton(this,  SWT.PUSH);
+               button.setImage(WSTATE.NORMAL, ImageResources.BTN_OFF_NML);
+               button.setImage(WSTATE.HOVER, ImageResources.BTN_OFF_HOVER);
+               button.setImage(WSTATE.PUSH, ImageResources.BTN_OFF_HOVER);
+               button.setImage(WSTATE.DISABLE_OFF, ImageResources.BTN_OFF_NML);
+               button.setImage(WSTATE.SELECTED, ImageResources.BTN_ON_NML);
+               button.setImage(WSTATE.SELECTED_HOVER, ImageResources.BTN_ON_HOVER);
+               button.setImage(WSTATE.SELECTED_PUSH, ImageResources.BTN_ON_HOVER);
+               button.setImage(WSTATE.DISABLE_ON, ImageResources.BTN_OFF_NML);
+               FormData formData = new FormData();
+               formData.left = new FormAttachment(0, ModifyItem.BODY_MARGIN_LEFT + VAR_INDENT);
+               formData.top = new FormAttachment(0, (ModifyItem.ITEM_HEIGHT - BUTTON_HEIGHT) / 2);
+               formData.width = BUTTON_WIDTH;
+               formData.height = BUTTON_HEIGHT;
+               button.setLayoutData(formData);
+               button.addListener(SWT.Selection, new Listener() {
+                       @Override
+                       public void handleEvent(Event event) {
+                               if (event.type == SWT.Selection) {
+                                       // change button
+                                       ImageButton button = (ImageButton)event.widget;
+                                       button.setSelection(!button.isSelection());
+
+                                       // set on off value
+                                       isOn = button.isSelection();
+                                       labelText = getLabelText(isOn);
+                                       textCanvas.redraw();
+                               }
+                       }
+               });
+
+               // create canvas
+               textCanvas = new Canvas(this, SWT.NONE);
+               formData = new FormData();
+               formData.left = new FormAttachment(button, LABEL_SPACING);
+               formData.top = new FormAttachment(0, (ModifyItem.ITEM_HEIGHT - BUTTON_HEIGHT) / 2);
+               formData.width = 50; // I guess it is enough for string
+               formData.height = BUTTON_HEIGHT;
+               textCanvas.setLayoutData(formData);
+               textCanvas.addPaintListener(new PaintListener() {
+                       @Override
+                       public void paintControl(PaintEvent e) {
+                               // draw text
+                               GC gc = e.gc;
+                               gc.setForeground(ColorResources.CONTENT_FONT.getColor());
+                               gc.setFont(FontResources.CONTENT.getFont());
+
+                               int itemHeight = ((Composite)e.widget).getBounds().height;
+                               Point textExt = gc.textExtent(labelText);
+                               int posY = (itemHeight - textExt.y) / 2;
+
+                               gc.drawText(labelText, 0, posY);
+
+                       }
+               });
+
+       }
+
+       private void drawTitle(final String title) {
+               this.addPaintListener(new PaintListener() {
+                       @Override
+                       public void paintControl(PaintEvent e) {
+
+                               // draw title
+                               GC gc = e.gc;
+                               gc.setForeground(ColorResources.CONTENT_FONT.getColor());
+                               gc.setFont(FontResources.CONTENT.getFont());
+
+                               int itemHeight = ((Composite)e.widget).getBounds().height;
+                               Point textExt = gc.textExtent(title);
+                               int posY = (itemHeight - textExt.y) / 2;
+
+                               gc.drawText(title, 0, posY);
+
+                               // draw vertical var
+                               gc.setForeground(ColorResources.MODIFY_ITEM_LINE.getColor());
+                               gc.setLineWidth(ModifyItem.LINE_WIDTH);
+                               gc.drawLine(VAR_INDENT, -1,
+                                               VAR_INDENT, itemHeight);
+
+                       }
+
+               });
+       }
+
+
+       private String getLabelText(boolean isOn) {
+               return isOn ? TEXT_ON : TEXT_OFF;
+       }
+
+}
index 0eb6c04..c56da35 100644 (file)
@@ -51,6 +51,7 @@ import org.eclipse.swt.widgets.Listener;
 import org.eclipse.swt.widgets.TypedListener;
 import org.tizen.emulator.manager.renewal.resources.ColorResources;
 import org.tizen.emulator.manager.renewal.resources.FontResources;
+import org.tizen.emulator.manager.renewal.resources.ImageResources;
 
 public class ImageButton extends Canvas {
        private final Composite parent;
@@ -63,6 +64,8 @@ public class ImageButton extends Canvas {
        protected ArrayList<Color> fontColors = null;
        protected ArrayList<Font> fonts = null;
 
+       WStateImageMap imageMap = new WStateImageMap();
+
        private String text = ""; //$NON-NLS-1$
        protected boolean selected = false;
        private boolean defaultPush = true;
@@ -154,6 +157,10 @@ public class ImageButton extends Canvas {
                images.set(state.getId(), image);
        }
 
+       public void setImage(WSTATE state, ImageResources imageResource) {
+               imageMap.put(state, imageResource);
+       }
+
        @Override
        public void setBackground(Color color) {
                for (WSTATE s : WSTATE.values()) {
@@ -217,6 +224,9 @@ public class ImageButton extends Canvas {
                        break;
                }
 
+               if (image == null) {
+                       return;
+               }
                Rectangle rect = image.getBounds();
                gc.drawImage(image, rect.x, rect.y);
        }
@@ -344,6 +354,9 @@ public class ImageButton extends Canvas {
                public void paintControl(PaintEvent e) {
                        Rectangle rect = ((Canvas) e.widget).getClientArea();
                        Image img = images.get(state.getId());
+                       if (img == null) {
+                               img = imageMap.get(state);
+                       }
 
                        if (colors.get(state.getId()) != null) {
                                e.gc.setBackground(colors.get(state.getId()));