private int style = 0;
private int width;
- private String text;
+ private int maxWidth = 200;
+ private String text = "";
private Image image;
private boolean resizable = false;
public void pack () {
checkWidget();
int w = getPreferredWidth();
+ //
+ if (w > maxWidth) {
+ w = maxWidth;
+ }
+
if (w != width) {
setWidth(w);
}
this.selectedFont = font;
}
+ public int getMaxWidth() {
+ return maxWidth;
+ }
+
+ public void setMaxWidth(int width) {
+ this.maxWidth = width;
+ }
+
void relesaeParent() {
parent.destroyColumn(this);
}
}
if (needRedrawingText) {
- int textWidth = TextSizeUtil.textExtent(getFont(), text);
+ int textWidth = TextSizeUtil.stringExtend(getFont(), text).x;
drawingText = text;
if (textWidth > (width - imageEX.x - 10)) {
while (textWidth > (width - 10) - TextSizeUtil.OMITLEN && drawingText.length() > 1) {
drawingText = drawingText.substring(0, drawingText.length() - 1);
- textWidth = TextSizeUtil.textExtent(getFont(), drawingText);
+ textWidth = TextSizeUtil.stringExtend(getFont(), drawingText).x;
}
drawingText = drawingText + TextSizeUtil.OMIT;
}
needRedrawingText = false;
}
- int textWidth = TextSizeUtil.textExtent(getFont(), drawingText);
+ Point textSize = TextSizeUtil.stringExtend(getFont(), drawingText);
switch (getAlignment()) {
case SWT.LEFT:
imageX += (image != null ? SPACING : 0);
break;
case SWT.RIGHT:
imageX += (image != null
- ? width - imageEX.x - SPACING - textWidth - 10
- : width - textWidth - 10);
+ ? width - imageEX.x - SPACING - textSize.x - 10
+ : width - textSize.x - 10);
textX += imageX + imageEX.x + SPACING;
break;
case SWT.CENTER:
imageX += (image != null
- ? rect.x + ((width - image.getImageData().width - textWidth) / 2)
- : rect.x + ((width - textWidth) / 2));
+ ? rect.x + ((width - image.getImageData().width - textSize.x) / 2)
+ : rect.x + ((width - textSize.x) / 2));
textX += imageX + imageEX.x;
break;
}
gc.drawImage(image, imageX, imageY);
}
- int fontHeight = gc.getFontMetrics().getHeight();
- textY = rect.y + (rect.height - fontHeight) / 2 - 1;
+ textY = rect.y + (rect.height - textSize.y) / 2 - 1;
if (!text.isEmpty()) {
gc.setFont(isHoverState? selectedFont : font);
@Override
public void mouseDoubleClick(MouseEvent e) {
if (isResizeableState) {
- setWidth(getPreferredWidth());
+ //setWidth(getPreferredWidth());
+ pack();
}
}
int result = 0;
Font font = getFont();
if (text != null && text.length() >= 0) {
- if (text.indexOf('\n') != -1) {
- result = TextSizeUtil.stringExtend(font, text);
- } else {
- result = TextSizeUtil.textExtent(font, text);
- }
+ result = TextSizeUtil.stringExtend(font, text).x;
Image image = getImage();
if (image != null) {
ensureData(index, count);
if (!text.equals(dataList[index].text)) {
dataList[index].text = text;
- dataList[index].textWidth = TextSizeUtil.textExtent(font, text);
+ dataList[index].textWidth = TextSizeUtil.stringExtend(font, text).x;
dataList[index].needRedrawingText = true;
if (parent.getColumnCount() == 0) {
parent.updateScrollBars(true);
private int getTextWidth(int index, Font font) {
if (hasData(index)) {
TableItemData data = dataList[index];
- if (data.textWidth == -1) {
+ //if (data.textWidth == -1) {
data.textWidth
- = TextSizeUtil.stringExtend(font, data.text);
- }
+ = TextSizeUtil.stringExtend(font, data.text).x;
+ //}
return data.textWidth;
}
return 0;
String drawingText = data.drawingText;
if (data.needRedrawingText) {
drawingText = item.getText(index);
- int textWidth = TextSizeUtil.textExtent(getFont(), drawingText);
+ int textWidth = TextSizeUtil.stringExtend(getFont(), drawingText).x;
if (textWidth > (rect.width - imageSize.x - 10)) {
while((textWidth > (rect.width - 10) - TextSizeUtil.OMITLEN)
&& drawingText.length() > 1) {
drawingText = drawingText.substring(0, drawingText.length() - 1);
- textWidth = TextSizeUtil.textExtent(getFont(), drawingText);
+ textWidth = TextSizeUtil.stringExtend(getFont(), drawingText).x;
}
drawingText = drawingText + TextSizeUtil.OMIT;
}
data.needRedrawingText = false;
data.drawingText = drawingText;
- data.drawingTextWidth = TextSizeUtil.textExtent(getFont(), drawingText);
+ data.drawingTextWidth = TextSizeUtil.stringExtend(getFont(), drawingText).x;
}
+ int spacing = image != null ? 5 : 0;
switch(item.getParentTable().getColumn(index).getAlignment()) {
case SWT.LEFT:
imageX += (image != null ? 5 : 0);
- textX += imageX + imageSize.x + 5;
+ textX += imageX + imageSize.x + spacing;
break;
case SWT.RIGHT:
imageX += (image != null
? rect.width - imageSize.x - data.drawingTextWidth - 10
: rect.width - data.drawingTextWidth - 10);
- textX += imageX + imageSize.x + 5;
+ textX += imageX + imageSize.x + spacing;
break;
case SWT.CENTER:
imageX += (image != null
- ? (rect.width - imageSize.x - data.drawingTextWidth) / 2 + 5
- : (rect.width - data.drawingTextWidth) / 2) - 5;
- textX += imageX + imageSize.x + 5;
+ ? (rect.width - imageSize.x - data.drawingTextWidth) / 2
+ : (rect.width - data.drawingTextWidth) / 2);
+ textX += imageX + imageSize.x + spacing;
break;
default:
}
if (data.text != null && !data.text.isEmpty()) {
gc.setFont(item.getFont(index));
- textY = rect.y + (rect.height - gc.getFontMetrics().getHeight())/2 - 1;
+ textY = rect.y + (rect.height - gc.textExtent(drawingText).y)/2;
gc.setForeground(isSelected ? item.getSelectedForground(): item.getForeground());
gc.drawText(drawingText, textX, textY);
}
package org.tizen.emulator.manager.ui.table;
-import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.FontData;
-import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Display;
public static final int OMITLEN = 12;
public static final String OMIT = "...";
- public static float getCharHeight(Font font) {
- float result;
- FontData fontData = font.getFontData()[0];
- result = fontData.getHeight() * 0.48f;
-
- if ((fontData.getStyle() & SWT.BOLD)!= 0) {
- result *= 1.45;
- }
- return result;
- }
-
- public static int textExtent(Font font, String text) {
-
- GC gc = new GC(Display.getCurrent());
- gc.setFont(font);
- FontMetrics metrics = gc.getFontMetrics();
- int width = metrics.getAverageCharWidth();
- gc.dispose();
- return width * text.length();
- }
-
- public static int stringExtend(Font font, String text) {
+ public static Point stringExtend(Font font, String text) {
GC gc = new GC(Display.getCurrent());
gc.setFont(font);
- Point p = gc.stringExtent(text);
+ Point p = gc.textExtent(text);
gc.dispose();
- return p.x;
+ return p;
}
}