From: giwoong.kim Date: Fri, 4 Jan 2013 06:58:12 +0000 (+0900) Subject: skin: trim a button text on Key Window X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.1~1227 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0afb9c01abc1d4c2cd539cfcf76c97fe147ae46e;p=sdk%2Femulator%2Fqemu.git skin: trim a button text on Key Window Cut off the excess length of custom button text on Key Window if user sets long text. Signed-off-by: GiWoong Kim --- diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/window/ImageButton.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/window/ImageButton.java index 7864bcbe61..351f62c6d9 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/window/ImageButton.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/window/ImageButton.java @@ -54,6 +54,8 @@ public class ImageButton extends Canvas { /* image - 0 : normal, 1 : hover, 2 : pushed */ private Image imageButton[]; + private int width; + private int height; private String text; private int textPositionX; private int textPositionY; @@ -69,9 +71,12 @@ public class ImageButton extends Canvas { imageButton[1] = imageHover; imageButton[2] = imagePushed; + this.width = imageNormal.getImageData().width; + this.height = imageNormal.getImageData().height; + this.text = null; - textPositionX = imageNormal.getImageData().width / 2; - textPositionY = imageNormal.getImageData().height / 2; + textPositionX = width / 2; + textPositionY = height / 2; white = Display.getCurrent().getSystemColor(SWT.COLOR_WHITE); gray = Display.getCurrent().getSystemColor(SWT.COLOR_GRAY); @@ -193,15 +198,31 @@ public class ImageButton extends Canvas { }); } - public void setText(String text) { - if (text == null || text.isEmpty()) { + public void setText(String textValue) { + /* checking whether the text value is appropriate */ + if (textValue == null || textValue.isEmpty()) { return; } - this.text = text; - GC gc = new GC(this); - Point textSize = gc.textExtent(text); + Point textSize = gc.textExtent(textValue); + Point originalSize = textSize; + + while (textSize.x >= (width - 10)) { + textValue = textValue.substring(0, textValue.length() - 1); + textSize = gc.textExtent(textValue); + } + + if (originalSize.x != textSize.x) { + textValue = textValue.substring(0, textValue.length() - 1); + textValue += ".."; + textSize = gc.textExtent(textValue); + } + + gc.dispose(); + + /* set text */ + text = textValue; textPositionX -= textSize.x / 2; if (textPositionX < 0) { @@ -212,8 +233,6 @@ public class ImageButton extends Canvas { if (textPositionY < 0) { textPositionY = 0; } - - gc.dispose(); } public String getText() {