From 0afb9c01abc1d4c2cd539cfcf76c97fe147ae46e Mon Sep 17 00:00:00 2001 From: "giwoong.kim" Date: Fri, 4 Jan 2013 15:58:12 +0900 Subject: [PATCH] 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 --- .../tizen/emulator/skin/window/ImageButton.java | 37 ++++++++++++++++------ 1 file changed, 28 insertions(+), 9 deletions(-) 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 7864bcb..351f62c 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() { -- 2.7.4