From: minkee.lee Date: Wed, 21 Oct 2015 09:02:51 +0000 (+0900) Subject: vm-modify: add skin-list. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7ce1c25129f7be11f1401c021642764d6c5e0a19;p=sdk%2Femulator%2Femulator-manager.git vm-modify: add skin-list. - User can select skin. - Skin-list is depend on resolution. - Only general skin is available if user use custom resolution. Change-Id: Icf7660ecf7941ee29835a2f5ebcc4b78aea47d47 Signed-off-by: minkee.lee --- diff --git a/src/org/tizen/emulator/manager/console/ConsoleCreateVM.java b/src/org/tizen/emulator/manager/console/ConsoleCreateVM.java index 29ddeae..58156f2 100644 --- a/src/org/tizen/emulator/manager/console/ConsoleCreateVM.java +++ b/src/org/tizen/emulator/manager/console/ConsoleCreateVM.java @@ -379,7 +379,7 @@ public class ConsoleCreateVM { RESOLUTION r = checkResolution(resolutionCommand.getCurrentValue()); prop.resolution = r; prop.dpi = r.getDPI(); - ArrayList list = null; + List list = null; if (prop.baseImage != null) { list = prop.baseImage.getPlatform().findSkinList(prop.resolution); } @@ -399,7 +399,7 @@ public class ConsoleCreateVM { } } else { if (skinCommand != null) { - ArrayList list = null; + List list = null; int i = 0; i = Integer.parseInt(skinCommand.getCurrentValue()); if (prop.baseImage != null) { @@ -424,7 +424,7 @@ public class ConsoleCreateVM { prop.skinPath = null; } } else { // resolutionCommon == null and skinComman == null - ArrayList list = null; + List list = null; list = prop.baseImage.getPlatform().findGeneralSkinList(); if (list != null && !list.isEmpty()) { prop.skin = list.get(0); diff --git a/src/org/tizen/emulator/manager/platform/Platform.java b/src/org/tizen/emulator/manager/platform/Platform.java index 0522085..b0d507f 100644 --- a/src/org/tizen/emulator/manager/platform/Platform.java +++ b/src/org/tizen/emulator/manager/platform/Platform.java @@ -76,7 +76,7 @@ public class Platform { private String version = null; private Platform parentPlatform = null; - private ArrayListskinList = new ArrayList(); + private ListskinList = new ArrayList(); private EMPlugin plugin; // for standard base images @@ -228,7 +228,7 @@ public class Platform { skinList = SkinList.sortForPriority(skinList); } - public ArrayList getSkins() { + public List getSkins() { return skinList; } @@ -240,15 +240,15 @@ public class Platform { return SkinList.findSkinUseName(name, skinList); } - public ArrayList findSkinList(RESOLUTION resolution) { + public List findSkinList(RESOLUTION resolution) { return SkinList.findSkinList(resolution, skinList); } - public ArrayList findSkinList(RESOLUTION resolution, SKIN_SHAPE skinShape) { + public List findSkinList(RESOLUTION resolution, SKIN_SHAPE skinShape) { return SkinList.findSkinList(resolution, skinShape, skinList); } - public ArrayList findGeneralSkinList() { + public List findGeneralSkinList() { return SkinList.findGeneralSkinList(skinList); } diff --git a/src/org/tizen/emulator/manager/platform/SkinList.java b/src/org/tizen/emulator/manager/platform/SkinList.java index 2df01fe..5a27104 100644 --- a/src/org/tizen/emulator/manager/platform/SkinList.java +++ b/src/org/tizen/emulator/manager/platform/SkinList.java @@ -30,13 +30,14 @@ package org.tizen.emulator.manager.platform; import java.util.ArrayList; +import java.util.List; import org.tizen.emulator.manager.vms.RESOLUTION; import org.tizen.emulator.manager.vms.SKIN_SHAPE; import org.tizen.emulator.manager.vms.SKIN_TYPE; public class SkinList { - public static Skin findSkinUsePath(String path, ArrayList list) { + public static Skin findSkinUsePath(String path, List list) { if (list != null) { for (Skin skin : list) { if (skin.getPath().equals(path)) { @@ -47,7 +48,7 @@ public class SkinList { return null; } - public static Skin findSkinUseName(String name, ArrayList list) { + public static Skin findSkinUseName(String name, List list) { if (list != null) { for (Skin skin : list) { if (skin.getName().equals(name)) { @@ -58,8 +59,8 @@ public class SkinList { return null; } - private static ArrayList returnSkins = new ArrayList(); - public static ArrayList findSkinList(RESOLUTION resolution, ArrayList list) { + private static List returnSkins = new ArrayList(); + public static List findSkinList(RESOLUTION resolution, List list) { returnSkins.clear(); if (list != null) { for (Skin skin : list) { @@ -73,8 +74,8 @@ public class SkinList { return sortForPriority(returnSkins); } - public static ArrayList findSkinList(RESOLUTION resolution, SKIN_SHAPE skinShape, - ArrayList list) { + public static List findSkinList(RESOLUTION resolution, SKIN_SHAPE skinShape, + List list) { returnSkins.clear(); if (list != null) { for (Skin skin : list) { @@ -88,7 +89,8 @@ public class SkinList { return sortForPriority(returnSkins); } - public static ArrayList findGeneralSkinList( ArrayList list) { + + public static List findGeneralSkinList( List list) { returnSkins.clear(); if (list != null) { for (Skin skin : list) { @@ -100,9 +102,9 @@ public class SkinList { return sortForPriority(returnSkins); } - public static ArrayList sortForPriority(ArrayList list) { + public static List sortForPriority(List list) { // sort using priority - ArrayList tempList = new ArrayList(); + List tempList = new ArrayList(); for (Skin s : list) { tempList.add(s); for (int j = tempList.size() - 1; j > 0; j--) { diff --git a/src/org/tizen/emulator/manager/ui/detail/item/property/SkinSubViewItem.java b/src/org/tizen/emulator/manager/ui/detail/item/property/SkinSubViewItem.java index ac56186..7c9fa40 100644 --- a/src/org/tizen/emulator/manager/ui/detail/item/property/SkinSubViewItem.java +++ b/src/org/tizen/emulator/manager/ui/detail/item/property/SkinSubViewItem.java @@ -31,7 +31,6 @@ package org.tizen.emulator.manager.ui.detail.item.property; -import java.util.ArrayList; import java.util.List; import org.eclipse.swt.events.SelectionEvent; @@ -55,8 +54,8 @@ public class SkinSubViewItem extends ComboSubViewItem { private Skin oldSkin; private Skin newSkin; - private ArrayList skinList; - private DisplayViewItem displayItem; + private List skinList; + private final DisplayViewItem displayItem; private SKIN_SHAPE imageSkinShape; public SkinSubViewItem(LabelViewItem parentItem, Composite comp, @@ -139,7 +138,7 @@ public class SkinSubViewItem extends ComboSubViewItem { combo.removeAll(); int find = -1; - ArrayList skins = null; + List skins = null; if (!parentItem.isCreateMode() && !displayItem.isResolutionExist(re) diff --git a/src/org/tizen/emulator/manager/ui/renewal/item/modify/common/DisplayItem.java b/src/org/tizen/emulator/manager/ui/renewal/item/modify/common/DisplayItem.java index 0f3411a..016ed4e 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/item/modify/common/DisplayItem.java +++ b/src/org/tizen/emulator/manager/ui/renewal/item/modify/common/DisplayItem.java @@ -43,8 +43,6 @@ import org.eclipse.swt.layout.FormLayout; import org.eclipse.swt.layout.GridData; 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.logging.EMLogger; import org.tizen.emulator.manager.platform.Skin; import org.tizen.emulator.manager.renewal.resources.ImageResources; @@ -54,7 +52,6 @@ import org.tizen.emulator.manager.ui.renewal.item.modify.comp.PropertyValue; import org.tizen.emulator.manager.ui.renewal.item.modify.comp.SubTreeModifyItem; import org.tizen.emulator.manager.ui.renewal.item.modify.comp.TreeModifyItem; import org.tizen.emulator.manager.ui.renewal.item.modify.vm.DeviceTemplateItem; -import org.tizen.emulator.manager.ui.renewal.widgets.ComboBox; import org.tizen.emulator.manager.ui.renewal.widgets.TextInputBox; import org.tizen.emulator.manager.ui.renewal.widgets.WidgetHelper; import org.tizen.emulator.manager.vms.RESOLUTION; @@ -65,8 +62,20 @@ 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; + private static final int ROW_HEIGHT = ModifyItem.ITEM_HEIGHT; + public static final int BODY_MARGIN_LEFT = 66; + public static final int WIDGET_TOP = (ROW_HEIGHT - ModifyItem.WIDGET_HEIGHT) / 2; + public static final int TEXT_BOX_WIDTH = 58; + public static final int COMBO_WIDTH = 134; private final int ROW_NUM = 4; // TODO + private final String TITLE_SIZE = "Size"; + + private final ResolutionSubItem resolutionItem; + private TextInputBox sizeTextBox = null; + private String displayDPI = ""; + private String displaySize = ""; + private final SkinSubItem skinItem; + /** constructor for tree sub item */ @@ -75,7 +84,10 @@ public class DisplayItem extends ModifyDialogItem { item = new SubTreeModifyItem(this, treeRoot); item.setItemHeight(ROW_HEIGHT * ROW_NUM + ModifyItem.LINE_WIDTH); treeRoot.addSubItem((SubTreeModifyItem)item); - this.resList = resList; + + resolutionItem = new ResolutionSubItem(this, resList); + skinItem = new SkinSubItem(this); + } @@ -83,14 +95,16 @@ public class DisplayItem extends ModifyDialogItem { super(NAME, TITLE); item = new ModifyItem(); item.setItemHeight(ROW_HEIGHT * ROW_NUM); - this.resList = resList; + + resolutionItem = new ResolutionSubItem(this, resList); + skinItem = new SkinSubItem(this); } @Override public ModifyDialogItem cloneItem() { List resList = new ArrayList(); - if (this.resList != null) { - resList.addAll(this.resList); + if (resolutionItem.getResolutionList() != null) { + resList.addAll(resolutionItem.getResolutionList()); } return new DisplayItem(resList); } @@ -106,12 +120,13 @@ public class DisplayItem extends ModifyDialogItem { if (getDialog().getDialogMode() == DIALOG_MODE.DETAIL) { createDisplayInfomation(); } else { - createResolutionComboItem(); - createResolutionTextItem(); + + resolutionItem.create(); + createSizeItem(); - createSkinItem(); + skinItem.create(); + - initResolutionCombo(); } // set widget disable if template is selected. @@ -126,7 +141,6 @@ public class DisplayItem extends ModifyDialogItem { if (deviceTemplateItem.getDeviceTemplate() != null) { setWidgetEnabled(false); } - } @@ -138,49 +152,25 @@ public class DisplayItem extends ModifyDialogItem { @Override public void setInitialValue(PropertyValue value) { - resolution = value.getResolution(); + resolutionItem.setResolution(value.getResolution()); + resolutionItem.setDisplayHeight(String.valueOf(value.getDisplayHeight())); + resolutionItem.setDisplayWidth(String.valueOf(value.getDisplayWidth())); + displaySize = String.valueOf(value.getDisplaySize()); - displayWidth = String.valueOf(value.getDisplayWidth()); - displayHeight = String.valueOf(value.getDisplayHeight()); - // for detail information - displayDPI = String.valueOf(value.getDisplayDPI()); if (value.getSkin() != null) { - skin = value.getSkin(); + skinItem.setSkin(value.getSkin()); } - } - - - private final String TITLE_RESOLUTION = "Resolution"; - private final String TITLE_SIZE = "Size"; - private final String TITLE_SKIN = "Skin"; - - private final int BODY_MARGIN_LEFT = 66; - - private final int COMBO_WIDTH = 134; - private final int TEXT_BOX_WIDTH = 58; - private final int RESOLUTION_TEXT_BOX_SPACING = 18; - private final int WIDGET_TOP = (ROW_HEIGHT - ModifyItem.WIDGET_HEIGHT) / 2; + // for detail information + displayDPI = String.valueOf(value.getDisplayDPI()); + } - private ComboBox resolutionCombo = null; - private TextInputBox widthTextBox = null; - private TextInputBox heightTextBox = null; - private TextInputBox sizeTextBox = null; - private ComboBox skinCombo = null; - List resList; - private RESOLUTION resolution; - private String displayWidth = ""; - private String displayHeight = ""; - private String displaySize = ""; - private String displayDPI = ""; - private Skin skin = null; - boolean isCustomResolution = false; private void createDisplayInfomation() { - Composite comp = createSubComp(1, TITLE_RESOLUTION); + Composite comp = createSubComp(1, ResolutionSubItem.TITLE_RESOLUTION); // resolution label FormData data = new FormData(); data.left = new FormAttachment(0, BODY_MARGIN_LEFT); @@ -189,7 +179,7 @@ public class DisplayItem extends ModifyDialogItem { data.height = ModifyItem.WIDGET_HEIGHT; Canvas canvas = new Canvas(comp, SWT.NONE); canvas.setLayoutData(data); - WidgetHelper.drawText(canvas, resolution.getStrTypeValue(), SWT.NONE); + WidgetHelper.drawText(canvas, resolutionItem.getResolution().getStrTypeValue(), SWT.NONE); comp = createSubComp(1, TITLE_SIZE); // "inch" label @@ -202,7 +192,7 @@ public class DisplayItem extends ModifyDialogItem { canvas.setLayoutData(data); WidgetHelper.drawText(canvas, displaySize + " inch" + " (DPI: " + displayDPI + ")" , SWT.NONE); - comp = createSubComp(1, TITLE_SKIN); + comp = createSubComp(1, SkinSubItem.TITLE_SKIN); // "inch" label data = new FormData(); data.left = new FormAttachment(0, BODY_MARGIN_LEFT); @@ -211,6 +201,7 @@ public class DisplayItem extends ModifyDialogItem { data.height = ModifyItem.WIDGET_HEIGHT; canvas = new Canvas(comp, SWT.NONE); canvas.setLayoutData(data); + Skin skin = skinItem.getSkin(); WidgetHelper.drawText(canvas, skin == null ? "" : skin.getName(), SWT.NONE); comp = createSubComp(1, "Skin Path"); @@ -225,191 +216,7 @@ public class DisplayItem extends ModifyDialogItem { WidgetHelper.drawText(canvas, skin == null ? "" : skin.getPath(), SWT.NONE); } - private void createResolutionComboItem() { - Composite comp = createSubComp(1, TITLE_RESOLUTION); - - FormData data = new FormData(); - data.left = new FormAttachment(0, BODY_MARGIN_LEFT); - data.top = new FormAttachment(0, WIDGET_TOP); - data.width = COMBO_WIDTH; - data.height = ModifyItem.WIDGET_HEIGHT; - resolutionCombo = new ComboBox(getDialog().getShell(), comp, SWT.NONE); - resolutionCombo.setLayoutData(data); - addResolutionComboListener(); - - } - - private void initResolutionCombo() { - if (resolutionCombo == null || resolutionCombo.isDisposed() ) { - return; - } - - resolutionCombo.clear(); - - // default. - if (resList == null) { - resList = new ArrayList(); - resList.add(RESOLUTION.MINI); - resList.add(RESOLUTION.R_360_480); - resList.add(RESOLUTION.WQXGA); - resList.add(RESOLUTION.WVGA); - resList.add(RESOLUTION.WXGA); - resList.add(RESOLUTION.HD); - resList.add(RESOLUTION.HD1080); - resList.add(RESOLUTION.HVGA); - resList.add(RESOLUTION.QHD); - } - - if (resList.size() == 0) { - return; - } - - // add combo list - for (RESOLUTION res : resList) { - resolutionCombo.addItem(res.toString()); - } - - selectResolutionCombo(); - setResolutionTextBox(); - - - // close popup if it is opened. - resolutionCombo.closeComboBox(); - } - - private void selectResolutionCombo() { - - - String re = null; - if (resolution != null) { - re = resolution.toString(); - } else { - re = resList.get(0).toString(); - } - - // select combobox - int index = -1; - for (int i=0 ; i < resolutionCombo.getItemList().size() ; i++) { - String str = resolutionCombo.getItemList().get(i); - if (str.equals(re)) { - index = i; - break; - } - } - if (index == -1) { - // add resolution - resList.add(0, resolution); - resolutionCombo.addItem(0, resolution.toString()); - resolutionCombo.select(0); - - } else { - resolutionCombo.select(index); - resolutionCombo.redraw(); - } - } - - - private void addResolutionComboListener() { - Listener listener = new Listener() { - @Override - public void handleEvent(Event event) { - switch(event.type) { - case SWT.Selection: - resolutionComboSelected(resolutionCombo.getSelectedItem()); - isCustomResolution = false; - - default: - break; - } - - } - }; - resolutionCombo.addListener(SWT.Selection, listener); - } - - - - private void resolutionComboSelected(String re) { - resolutionCombo.setToolTipText(re); - - // find resolution - RESOLUTION d = null; - for (RESOLUTION r : resList) { - if (re.equals(r.toString())) { - d = r; - } - } - - if (d != null) { - resolution = d; - setResolutionTextBox(); - } - - - // TODO checkValid is needed? - getDialog().checkValid(); - -// if (d == null) { -// if (re.equals(oldResolution.toString())) { -// d = oldResolution; -// } -// } - -// if (d != null) { -// EMLogger.getLogger().fine("Change Resolution -> " + d.getStrTypeValue()); //$NON-NLS-1$ -// resolution = d; -// // TODO -// displayItem.changeResolution(d); -// } - - - } - - private void setResolutionTextBox() { - if (resolution != null) { - displayWidth = String.valueOf(resolution.getResolution().getWidth()); - displayHeight = String.valueOf(resolution.getResolution().getHeight()); - widthTextBox.setText(displayWidth); - heightTextBox.setText(displayHeight); - } - } - - - private void createResolutionTextItem() { - Composite comp = createSubComp(1, ""); - - // text box for width - FormData data = new FormData(); - data.left = new FormAttachment(0, BODY_MARGIN_LEFT); - data.top = new FormAttachment(0, WIDGET_TOP); - data.width = TEXT_BOX_WIDTH; - data.height = ModifyItem.WIDGET_HEIGHT; - widthTextBox = new TextInputBox(comp, SWT.NONE); - widthTextBox.setLayoutData(data); - - // "x" label - data = new FormData(); - data.left = new FormAttachment(widthTextBox, 0); - data.top = new FormAttachment(0, WIDGET_TOP); - data.width = RESOLUTION_TEXT_BOX_SPACING; - data.height = ModifyItem.WIDGET_HEIGHT; - Canvas canvas = new Canvas(comp, SWT.NONE); - canvas.setLayoutData(data); - WidgetHelper.drawText(canvas, "x", SWT.CENTER); - - - // text box for height - data = new FormData(); - data.left = new FormAttachment(widthTextBox, RESOLUTION_TEXT_BOX_SPACING); - data.top = new FormAttachment(0, WIDGET_TOP); - data.width = TEXT_BOX_WIDTH; - data.height = ModifyItem.WIDGET_HEIGHT; - heightTextBox = new TextInputBox(comp, SWT.NONE); - heightTextBox.setLayoutData(data); - - addWidthHeightListener(); - } private void createSizeItem() { @@ -459,81 +266,10 @@ public class DisplayItem extends ModifyDialogItem { }); } - private void addWidthHeightListener() { - // TODO what should we do width custom widdth/height - widthTextBox.getTextWidget().addModifyListener(new ModifyListener() { - @Override - public void modifyText(ModifyEvent e) { - displayWidth = widthTextBox.getValue(); - setCustomResolution(); - getDialog().checkValid(); - } - }); - - heightTextBox.getTextWidget().addModifyListener(new ModifyListener() { - - @Override - public void modifyText(ModifyEvent e) { - displayHeight = heightTextBox.getValue(); - setCustomResolution(); - getDialog().checkValid(); - } - }); - } - - private void setCustomResolution() { - if (!checkDisplayWidthHeight()) { - return; - } - int width = Integer.parseInt(displayWidth); - int height = Integer.parseInt(displayHeight); - if (width == resolution.getResolution().getWidth() - && height == resolution.getResolution().getHeight()) { - if (isCustomResolution) { - isCustomResolution = false; - selectResolutionCombo(); - } - return; - } - - // is in res list ? - for (RESOLUTION res : resList) { - if (width == res.getResolution().getWidth() - && height == res.getResolution().getHeight()) { - if (!isCustomResolution) { - return; - } - resolution = res; - selectResolutionCombo(); - isCustomResolution = false; - return; - } - } - // set "custom" in combobox - resolutionCombo.setText("(custom)"); - resolutionCombo.setToolTipText("(custom)"); - isCustomResolution = true; - } - - - - private void createSkinItem() { - Composite comp = createSubComp(1, TITLE_SKIN); - - FormData data = new FormData(); - data.left = new FormAttachment(0, BODY_MARGIN_LEFT); - data.top = new FormAttachment(0, WIDGET_TOP); - data.width = COMBO_WIDTH; - data.height = ModifyItem.WIDGET_HEIGHT; - skinCombo = new ComboBox(getDialog().getShell(), comp, SWT.NONE); - skinCombo.setLayoutData(data); - } - - - private Composite createSubComp(int rowNum, String title) { + public Composite createSubComp(int rowNum, String title) { GridData data = new GridData(); data.grabExcessHorizontalSpace = true; data.horizontalAlignment = SWT.FILL; @@ -551,28 +287,19 @@ public class DisplayItem extends ModifyDialogItem { @Override public void setValue(PropertyValue value) { // set resolution - if (isCustomResolution) { - resolution = new RESOLUTION( - Integer.parseInt(displayWidth), - Integer.parseInt(displayHeight), - "custom", 0); - } - - value.setResolution(resolution); + resolutionItem.setValue(value); try { // set display size (inch) value.setDisplaySize(Double.parseDouble(displaySize)); - // TODO set displayWidth, displayHeight - value.setDisplayWidth(Integer.parseInt(displayWidth)); - value.setDisplayHeight(Integer.parseInt(displayHeight)); - - } catch (NumberFormatException e) { EMLogger.getLogger().warning(e.getMessage()); } + + // TODO skin + skinItem.setValue(value); } @@ -589,7 +316,7 @@ public class DisplayItem extends ModifyDialogItem { return false; } - if (!checkDisplayWidthHeight()) { + if (!resolutionItem.isValid()) { return false; } @@ -597,24 +324,12 @@ public class DisplayItem extends ModifyDialogItem { } - private boolean checkDisplayWidthHeight() { - // TODO check display width/height - if (displayWidth.isEmpty() || displayHeight.isEmpty()) { - return false; - } - try { - Integer.parseInt(displayWidth); - Integer.parseInt(displayHeight); - } catch (NumberFormatException e) { - return false; - } - return true; - } public List getResolutionList() { - return resList; + return resolutionItem.getResolutionList(); } + @Override public void changeItem(ModifyDialogItem srcDialogItem) { @@ -622,13 +337,12 @@ public class DisplayItem extends ModifyDialogItem { return; } - // change size + DisplayItem srcItem = (DisplayItem)srcDialogItem; - resList.clear(); - for (RESOLUTION res : srcItem.getResolutionList()) { - resList.add(res); - } - initResolutionCombo(); + + // change resolution + resolutionItem.changeItem(srcItem.getResolutionList()); + // change size selectSize(); @@ -639,8 +353,7 @@ public class DisplayItem extends ModifyDialogItem { @Override public void changeItemValue(PropertyValue value) { // display resolution - resolution = value.getResolution(); - selectResolutionCombo(); + resolutionItem.changeValue(value.getResolution()); // size displaySize = String.valueOf(value.getDisplaySize()); @@ -653,12 +366,30 @@ public class DisplayItem extends ModifyDialogItem { } private void setWidgetEnabled(boolean enabled) { - resolutionCombo.setEnabled(enabled); - widthTextBox.setEnabled(enabled); - heightTextBox.setEnabled(enabled); + resolutionItem.setWidgetEnabled(enabled); + sizeTextBox.setEnabled(enabled); // skinCombo.setEnabled(enabled); } + public ResolutionSubItem getResolutionItem() { + return resolutionItem; + } + + + public boolean isResolutionExist(RESOLUTION re) { + if (resolutionItem == null) { + return false; + } + return resolutionItem.isResolutionExist(re); + } + + + public void changeSkinList(RESOLUTION re) { + // change skin list + if (skinItem != null) { + skinItem.settingSkinList(re); + } + } } diff --git a/src/org/tizen/emulator/manager/ui/renewal/item/modify/common/ResolutionSubItem.java b/src/org/tizen/emulator/manager/ui/renewal/item/modify/common/ResolutionSubItem.java new file mode 100644 index 0000000..a979667 --- /dev/null +++ b/src/org/tizen/emulator/manager/ui/renewal/item/modify/common/ResolutionSubItem.java @@ -0,0 +1,444 @@ +/* + * 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.item.modify.common; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +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.logging.EMLogger; +import org.tizen.emulator.manager.ui.renewal.item.modify.comp.ModifyItem; +import org.tizen.emulator.manager.ui.renewal.item.modify.comp.PropertyValue; +import org.tizen.emulator.manager.ui.renewal.widgets.ComboBox; +import org.tizen.emulator.manager.ui.renewal.widgets.TextInputBox; +import org.tizen.emulator.manager.ui.renewal.widgets.WidgetHelper; +import org.tizen.emulator.manager.vms.RESOLUTION; + +public class ResolutionSubItem { + + + private ComboBox resolutionCombo = null; + private TextInputBox widthTextBox = null; + private TextInputBox heightTextBox = null; + + public static final String TITLE_RESOLUTION = "Resolution"; + private final int RESOLUTION_TEXT_BOX_SPACING = 18; + + private RESOLUTION resolution; + private final DisplayItem displayItem; + + boolean isCustomResolution = false; + + + List resList; + private String displayWidth = ""; + private String displayHeight = ""; + + + public ResolutionSubItem(DisplayItem displayItem, List resList) { + this.displayItem = displayItem; + this.resList = resList; + } + + + + public void create() { + createResolutionComboItem(); + createResolutionTextItem(); + + initResolutionCombo(false); + setResolutionTextBox(); + } + + + + private void createResolutionComboItem() { + Composite comp = displayItem.createSubComp(1, TITLE_RESOLUTION); + + FormData data = new FormData(); + data.left = new FormAttachment(0, DisplayItem.BODY_MARGIN_LEFT); + data.top = new FormAttachment(0, DisplayItem.WIDGET_TOP); + data.width = DisplayItem.COMBO_WIDTH; + data.height = ModifyItem.WIDGET_HEIGHT; + resolutionCombo = new ComboBox(displayItem.getDialog().getShell(), comp, SWT.NONE); + resolutionCombo.setLayoutData(data); + addResolutionComboListener(); + + } + + private void initResolutionCombo(boolean notifySelect) { + if (resolutionCombo == null || resolutionCombo.isDisposed() ) { + return; + } + + resolutionCombo.clear(); + + // default. + if (resList == null) { + resList = new ArrayList(); + resList.add(RESOLUTION.MINI); + resList.add(RESOLUTION.R_360_480); + resList.add(RESOLUTION.WQXGA); + resList.add(RESOLUTION.WVGA); + resList.add(RESOLUTION.WXGA); + resList.add(RESOLUTION.HD); + resList.add(RESOLUTION.HD1080); + resList.add(RESOLUTION.HVGA); + resList.add(RESOLUTION.QHD); + } + + if (resList.size() == 0) { + return; + } + + // add combo list + for (RESOLUTION res : resList) { + resolutionCombo.addItem(res.toString()); + } + + selectResolutionCombo(notifySelect); +// setResolutionTextBox(); + + + // close popup if it is opened. + resolutionCombo.closeComboBox(); + } + private void initResolutionCombo() { + initResolutionCombo(true); + } + + private void selectResolutionCombo(boolean notifySelect) { + + + String re = null; + if (resolution != null) { + re = resolution.toString(); + } else { + re = resList.get(0).toString(); + } + + // select combobox + int index = -1; + for (int i=0 ; i < resolutionCombo.getItemList().size() ; i++) { + String str = resolutionCombo.getItemList().get(i); + if (str.equals(re)) { + index = i; + break; + } + } + if (index == -1) { + // add resolution + resList.add(0, resolution); + resolutionCombo.addItem(0, resolution.toString()); + resolutionCombo.select(0, notifySelect); + + } else { + resolutionCombo.select(index, notifySelect); + resolutionCombo.redraw(); + } + } + + + private void addResolutionComboListener() { + Listener listener = new Listener() { + @Override + public void handleEvent(Event event) { + switch(event.type) { + case SWT.Selection: + resolutionComboSelected(resolutionCombo.getSelectedItem()); + isCustomResolution = false; + + displayItem.getDialog().checkValid(); + default: + break; + } + + } + }; + resolutionCombo.addListener(SWT.Selection, listener); + } + + + + private void resolutionComboSelected(String re) { + resolutionCombo.setToolTipText(re); + + // find resolution + RESOLUTION d = null; + for (RESOLUTION r : resList) { + if (re.equals(r.toString())) { + d = r; + } + } + + if (d != null) { + resolution = d; + setResolutionTextBox(); + } + + + // TODO checkValid is needed? + displayItem.getDialog().checkValid(); + +// if (d == null) { +// if (re.equals(oldResolution.toString())) { +// d = oldResolution; +// } +// } + + if (d != null) { + EMLogger.getLogger().fine("Change Resolution -> " + d.getStrTypeValue()); //$NON-NLS-1$ + resolution = d; + // TODO + displayItem.changeSkinList(d); + } + + + } + + + private void setResolutionTextBox() { + if (resolution != null) { + displayWidth = String.valueOf(resolution.getResolution().getWidth()); + displayHeight = String.valueOf(resolution.getResolution().getHeight()); + widthTextBox.setText(displayWidth); + heightTextBox.setText(displayHeight); + } + } + + + private void createResolutionTextItem() { + Composite comp = displayItem.createSubComp(1, ""); + + // text box for width + FormData data = new FormData(); + data.left = new FormAttachment(0, DisplayItem.BODY_MARGIN_LEFT); + data.top = new FormAttachment(0, DisplayItem.WIDGET_TOP); + data.width = DisplayItem.TEXT_BOX_WIDTH; + data.height = ModifyItem.WIDGET_HEIGHT; + widthTextBox = new TextInputBox(comp, SWT.NONE); + widthTextBox.setLayoutData(data); + + // "x" label + data = new FormData(); + data.left = new FormAttachment(widthTextBox, 0); + data.top = new FormAttachment(0, DisplayItem.WIDGET_TOP); + data.width = RESOLUTION_TEXT_BOX_SPACING; + data.height = ModifyItem.WIDGET_HEIGHT; + Canvas canvas = new Canvas(comp, SWT.NONE); + canvas.setLayoutData(data); + WidgetHelper.drawText(canvas, "x", SWT.CENTER); + + + // text box for height + data = new FormData(); + data.left = new FormAttachment(widthTextBox, RESOLUTION_TEXT_BOX_SPACING); + data.top = new FormAttachment(0, DisplayItem.WIDGET_TOP); + data.width = DisplayItem.TEXT_BOX_WIDTH; + data.height = ModifyItem.WIDGET_HEIGHT; + heightTextBox = new TextInputBox(comp, SWT.NONE); + heightTextBox.setLayoutData(data); + + addWidthHeightListener(); + } + + + private void addWidthHeightListener() { + // TODO what should we do width custom widdth/height + + widthTextBox.getTextWidget().addModifyListener(new ModifyListener() { + + @Override + public void modifyText(ModifyEvent e) { + displayWidth = widthTextBox.getValue(); + setCustomResolution(); + displayItem.getDialog().checkValid(); + } + }); + + heightTextBox.getTextWidget().addModifyListener(new ModifyListener() { + + @Override + public void modifyText(ModifyEvent e) { + displayHeight = heightTextBox.getValue(); + setCustomResolution(); + displayItem.getDialog().checkValid(); + } + }); + } + + private void setCustomResolution() { + if (!checkDisplayWidthHeight()) { + return; + } + int width = Integer.parseInt(displayWidth); + int height = Integer.parseInt(displayHeight); + if (width == resolution.getResolution().getWidth() + && height == resolution.getResolution().getHeight()) { + if (isCustomResolution) { + isCustomResolution = false; + selectResolutionCombo(true); + } + return; + } + + // is in res list ? + for (RESOLUTION res : resList) { + if (width == res.getResolution().getWidth() + && height == res.getResolution().getHeight()) { + if (!isCustomResolution) { + return; + } + resolution = res; + selectResolutionCombo(true); + isCustomResolution = false; + return; + } + } + + // set "custom" in combobox + resolutionCombo.setText("(custom)"); + resolutionCombo.setToolTipText("(custom)"); + isCustomResolution = true; + // change skin list (Only general skin is available) + displayItem.changeSkinList(null); + + } + + + private boolean checkDisplayWidthHeight() { + // TODO check display width/height + if (displayWidth.isEmpty() || displayHeight.isEmpty()) { + return false; + } + try { + Integer.parseInt(displayWidth); + Integer.parseInt(displayHeight); + } catch (NumberFormatException e) { + return false; + } + + return true; + } + + + public void setValue(PropertyValue value) { + if (isCustomResolution) { + resolution = new RESOLUTION( + Integer.parseInt(displayWidth), + Integer.parseInt(displayHeight), + "custom", 0); + } + value.setResolution(resolution); + + try { + // displayWidth, displayHeight + value.setDisplayWidth(Integer.parseInt(displayWidth)); + value.setDisplayHeight(Integer.parseInt(displayHeight)); + + + } catch (NumberFormatException e) { + EMLogger.getLogger().warning(e.getMessage()); + } + + } + + + public void setWidgetEnabled(boolean enabled) { + resolutionCombo.setEnabled(enabled); + widthTextBox.setEnabled(enabled); + heightTextBox.setEnabled(enabled); + } + + + public void changeItem(List resList) { + this.resList.clear(); + for (RESOLUTION res : resList) { + this.resList.add(res); + } + initResolutionCombo(); + } + + + public boolean isResolutionExist(RESOLUTION re) { + for (RESOLUTION r : resList) { + if (r.getStrValue().equals(re.getStrValue())) { + return true; + } + } + if (resolution != null) { + if (resolution.getStrValue().equals(re.getStrValue())) { + return true; + } + } + return false; + } + + + public void changeValue(RESOLUTION res) { + resolution = res; + selectResolutionCombo(true); + } + + + public boolean isValid() { + return checkDisplayWidthHeight(); + } + + public List getResolutionList() { + return resList; + } + + public void setResolution(RESOLUTION r) { + this.resolution = r; + } + + public void setDisplayWidth(String width) { + displayWidth = width; + } + + public void setDisplayHeight(String height) { + displayHeight = height; + } + + public RESOLUTION getResolution() { + return resolution; + } +} diff --git a/src/org/tizen/emulator/manager/ui/renewal/item/modify/common/SkinSubItem.java b/src/org/tizen/emulator/manager/ui/renewal/item/modify/common/SkinSubItem.java new file mode 100644 index 0000000..93cc3d8 --- /dev/null +++ b/src/org/tizen/emulator/manager/ui/renewal/item/modify/common/SkinSubItem.java @@ -0,0 +1,219 @@ +/* + * 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.item.modify.common; + +import java.util.List; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.tizen.emulator.manager.logging.EMLogger; +import org.tizen.emulator.manager.platform.Skin; +import org.tizen.emulator.manager.platform.SkinList; +import org.tizen.emulator.manager.ui.renewal.item.modify.comp.ModifyItem; +import org.tizen.emulator.manager.ui.renewal.item.modify.comp.PropertyValue; +import org.tizen.emulator.manager.ui.renewal.widgets.ComboBox; +import org.tizen.emulator.manager.vms.RESOLUTION; +import org.tizen.emulator.manager.vms.SKIN_SHAPE; +import org.tizen.emulator.manager.vms.SKIN_TYPE; + +public class SkinSubItem { + + private final DisplayItem displayItem; + + private ComboBox skinCombo = null; + private Skin skin = null; + private List skinList; + private SKIN_SHAPE imageSkinShape; + + public static final String TITLE_SKIN = "Skin"; + + public SkinSubItem(DisplayItem displayItem) { + this.displayItem = displayItem; + } + + public void setSkin(Skin skin) { + this.skin = skin; + } + + public Skin getSkin() { + return skin; + } + + public void create() { + createSkinItem(); + initSkinCombo(); + } + + + public void setValue(PropertyValue value) { + // set skin + value.setSkin(skin); + + // set skin path + String skinPath = null; + if (skin != null) { + skinPath = skin.getPath(); + } + value.setSkinPath(skinPath); + + } + + + private void settingGeneralSkinList() { + skinCombo.clear(); + List skins = null; + skins = SkinList.findGeneralSkinList(skinList); + if (skins.size() == 0) { + skin = null; + skinCombo.setToolTipText("No skins are available"); + return; + } + + for (Skin s : skins) { + skinCombo.addItem(s.toString()); + } + skinCombo.select(0); + skinCombo.setToolTipText(skinCombo.getSelectedItem()); + skin = skins.get(0); + + } + + // init skin combo list, select combo. + public void settingSkinList(RESOLUTION re) { + if (re == null) { + // setting general skin only. + settingGeneralSkinList(); + return; + } + + skinCombo.clear(); + List skins = null; + + + int find = -1; + + if (!displayItem.getDialog().isCreateMode() + && !displayItem.isResolutionExist(re) ) { + if (skin != null) { + EMLogger.getLogger().fine("Add old skin: " + skin.toString()); //$NON-NLS-1$ + skinCombo.addItem(skin.toString()); + find = 0; + } + + } else { + skins = SkinList.findSkinList(re, imageSkinShape, skinList); + Skin s = null; + for (int i = 0; i < skins.size(); i++) { + s = skins.get(i); + if (skin != null && skin.equals(s)) { + find = i; + } + skinCombo.addItem(s.toString()); + } + + if (find == -1) { + if (skin != null + && skin.getType() == SKIN_TYPE.GENERAL) { + skins.add(0, skin); + skinCombo.addItem(skin.toString(), 0); + } + if (skins.size() > 0) { + find = 0; + } + } + } + + if (find >= 0) { + skinCombo.select(find); + skinCombo.setToolTipText(skinCombo.getSelectedItem()); +// newSkin = skins == null ? oldSkin : skins.get(find); + skin = skins == null ? skin : skins.get(find); + } else { + EMLogger.getLogger().warning("To initial Skin Combo has been failed."); //$NON-NLS-1$ + } + } + + private void createSkinItem() { + Composite comp = displayItem.createSubComp(1, TITLE_SKIN); + + FormData data = new FormData(); + data.left = new FormAttachment(0, DisplayItem.BODY_MARGIN_LEFT); + data.top = new FormAttachment(0, DisplayItem.WIDGET_TOP); + data.width = DisplayItem.COMBO_WIDTH; + data.height = ModifyItem.WIDGET_HEIGHT; + skinCombo = new ComboBox(displayItem.getDialog().getShell(), comp, SWT.NONE); + skinCombo.setLayoutData(data); + + if (displayItem.getDialog().getPropertyValue().isTemplateValue()) { + return; + } + initSkinCombo(); + + } + + + private void initSkinCombo() { + imageSkinShape = displayItem.getDialog().getPropertyValue().getImageSkinShape(); + skinList = displayItem.getDialog().getPropertyValue().getImageSkinList(); + + settingSkinList(displayItem.getResolutionItem().getResolution()); + addSkinComboListener(); + } + + + + private void addSkinComboListener() { + Listener listener = new Listener() { + @Override + public void handleEvent(Event event) { + switch(event.type) { + case SWT.Selection: + String name = skinCombo.getSelectedItem(); + skinCombo.setToolTipText(name); + + skin = SkinList.findSkinUseName(name, skinList); + + displayItem.getDialog().checkValid(); + + default: + break; + } + + } + }; + skinCombo.addListener(SWT.Selection, listener); + } +} + diff --git a/src/org/tizen/emulator/manager/ui/renewal/item/modify/comp/PropertyValue.java b/src/org/tizen/emulator/manager/ui/renewal/item/modify/comp/PropertyValue.java index 4e97544..3f76bcb 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/item/modify/comp/PropertyValue.java +++ b/src/org/tizen/emulator/manager/ui/renewal/item/modify/comp/PropertyValue.java @@ -34,6 +34,7 @@ package org.tizen.emulator.manager.ui.renewal.item.modify.comp; import java.io.File; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.tizen.emulator.manager.devices.DeviceTemplate; @@ -74,12 +75,12 @@ public class PropertyValue { } - private boolean isVMValue() { + public boolean isVMValue() { return vmValue != null; } - private boolean isTemplateValue() { + public boolean isTemplateValue() { return templateValue != null; } @@ -252,6 +253,18 @@ public class PropertyValue { return 0; } + public void setSkin(Skin skin) { + if (isVMValue()) { + vmValue.skin = skin; + } + } + + public void setSkinPath(String path) { + if (isVMValue()) { + vmValue.skinPath = path; + } + } + public String getSkinShape() { if (isVMValue()) { @@ -264,7 +277,7 @@ public class PropertyValue { public Skin getSkin() { if (isVMValue()) { - + return vmValue.skin; } else if (isTemplateValue()) { return templateValue.getSkin(); } @@ -272,6 +285,23 @@ public class PropertyValue { return null; } + + public List getImageSkinList() { + if (isVMValue()) { + return vmValue.baseImage.getPlatform().getSkins(); + } + + return null; + } + + + public SKIN_SHAPE getImageSkinShape() { + if (isVMValue()) { + return vmValue.baseImage.getSkinShape(); + } + return null; + } + public int getRamSize() { if (isVMValue()) { return vmValue.ramSize; diff --git a/src/org/tizen/emulator/manager/ui/renewal/widgets/ComboBox.java b/src/org/tizen/emulator/manager/ui/renewal/widgets/ComboBox.java index e3b1401..db6b81d 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/widgets/ComboBox.java +++ b/src/org/tizen/emulator/manager/ui/renewal/widgets/ComboBox.java @@ -175,6 +175,7 @@ public class ComboBox extends NinePatchBox { public void select(int index) { select(index, true); + redraw(); } private void initBox() { diff --git a/src/org/tizen/emulator/manager/vms/Creator.java b/src/org/tizen/emulator/manager/vms/Creator.java index 1e44c2b..beaac16 100644 --- a/src/org/tizen/emulator/manager/vms/Creator.java +++ b/src/org/tizen/emulator/manager/vms/Creator.java @@ -259,7 +259,7 @@ public class Creator { if (newVM.skin == null && newVM.skinPath == null) { if (newVM.baseImage != null) { - ArrayList list = newVM.baseImage.getPlatform().findSkinList(newVM.resolution); + List list = newVM.baseImage.getPlatform().findSkinList(newVM.resolution); if (!list.isEmpty()) { newVM.skin = list.get(0); }