From: minkee.lee Date: Fri, 16 Oct 2015 10:07:59 +0000 (+0900) Subject: dialog: support custom resolution. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9d5882682957589bcb1cb3adb09961144cabb9d8;p=sdk%2Femulator%2Femulator-manager.git dialog: support custom resolution. - If user edit display width & height, custom resolution is selected. - If input size(width,height) is in the list, it's not custom. Conflicts: src/org/tizen/emulator/manager/ui/renewal/widgets/ComboBox.java Change-Id: Ieacec52a7acace3a64e417a13e5577f6f00e182b Signed-off-by: minkee.lee --- 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 fefecf1..6f36d7b 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 @@ -160,6 +160,8 @@ public class DisplayItem extends ModifyDialogItem { private String displayDPI = ""; private Skin skin = null; + boolean isCustomResolution = false; + private void createDisplayInfomation() { Composite comp = createSubComp(1, TITLE_RESOLUTION); // resolution label @@ -250,8 +252,17 @@ public class DisplayItem extends ModifyDialogItem { resolutionCombo.addItem(res.toString()); } - // select resolution - // TODO default resolution + selectResolutionCombo(); + setResolutionTextBox(); + + + // close popup if it is opened. + resolutionCombo.closeComboBox(); + } + + private void selectResolutionCombo() { + + String re = null; if (resolution != null) { re = resolution.toString(); @@ -269,16 +280,15 @@ public class DisplayItem extends ModifyDialogItem { } } if (index == -1) { + // add resolution + resList.add(0, resolution); + resolutionCombo.addItem(0, resolution.toString()); resolutionCombo.select(0); - resolution = resList.get(0); + } else { resolutionCombo.select(index); + resolutionCombo.redraw(); } - - resolutionComboSelected(re); - - // close popup if it is opened. - resolutionCombo.closeComboBox(); } @@ -289,6 +299,7 @@ public class DisplayItem extends ModifyDialogItem { switch(event.type) { case SWT.Selection: resolutionComboSelected(resolutionCombo.getSelectedItem()); + isCustomResolution = false; default: break; @@ -439,6 +450,7 @@ public class DisplayItem extends ModifyDialogItem { @Override public void modifyText(ModifyEvent e) { displayWidth = widthTextBox.getValue(); + setCustomResolution(); getDialog().checkValid(); } }); @@ -448,11 +460,47 @@ public class DisplayItem extends ModifyDialogItem { @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() { @@ -486,8 +534,16 @@ 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); + try { // set display size (inch) value.setDisplaySize(Double.parseDouble(displaySize)); @@ -516,6 +572,15 @@ public class DisplayItem extends ModifyDialogItem { return false; } + if (!checkDisplayWidthHeight()) { + return false; + } + + return true; + } + + + private boolean checkDisplayWidthHeight() { // TODO check display width/height if (displayWidth.isEmpty() || displayHeight.isEmpty()) { return false; @@ -542,7 +607,10 @@ public class DisplayItem extends ModifyDialogItem { // change size DisplayItem srcItem = (DisplayItem)srcDialogItem; - resList = srcItem.getResolutionList(); + resList.clear(); + for (RESOLUTION res : srcItem.getResolutionList()) { + resList.add(res); + } initResolutionCombo(); // change size 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 f139228..8651b64 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/widgets/ComboBox.java +++ b/src/org/tizen/emulator/manager/ui/renewal/widgets/ComboBox.java @@ -103,15 +103,35 @@ public class ComboBox extends NinePatchBox { } public void addItem(String item) { - items.add(item); - datas.add(null); + addItem(items.size(), item); } + + public void addItem(int index, String item) { + addItem(index, item, null); + } + + public void addItem(String item, Object data) { - items.add(item); - datas.add(data); + addItem(items.size(), item, data); } + + public void addItem(int index, String item, Object data) { + try { + items.add(index, item); + } catch (IndexOutOfBoundsException e) { + items.add(item); + } + + try { + datas.add(index, data); + } catch (IndexOutOfBoundsException e) { + datas.add(data); + } + } + + @Override public void redraw() { textCanvas.redraw(); @@ -199,6 +219,11 @@ public class ComboBox extends NinePatchBox { }); } + public void setText(String text) { + selectedItem = text; + redraw(); + } + @Override protected void draw(PaintEvent e) {