SWTSkinObjectText1public class SWTSkinObjectText1 extends SWTSkinObjectBasic implements SWTSkinObjectTextText Skin Object. This one uses a label widget. |
Fields Summary |
---|
String | sText | String | sKey | boolean | bIsTextDefault | org.eclipse.swt.widgets.Label | label |
Constructors Summary |
---|
public SWTSkinObjectText1(SWTSkin skin, SWTSkinProperties skinProperties, String sID, String sConfigID, String[] typeParams, SWTSkinObject parent)
super(skin, skinProperties, sID, sConfigID, "text", parent);
int style = SWT.WRAP;
String sAlign = skinProperties.getStringValue(sConfigID + ".align");
if (sAlign != null) {
int align = SWTSkinUtils.getAlignment(sAlign, SWT.NONE);
if (align != SWT.NONE) {
style |= align;
}
}
if (skinProperties.getIntValue(sConfigID + ".border", 0) == 1) {
style |= SWT.BORDER;
}
Composite createOn;
if (parent == null) {
createOn = skin.getShell();
} else {
createOn = (Composite) parent.getControl();
}
boolean bKeepMaxSize = properties.getStringValue(
sConfigID + ".keepMaxSize", "").equals("1");
label = bKeepMaxSize ? new LabelNoShrink(createOn, style) : new Label(
createOn, style);
setControl(label);
if (typeParams.length > 1) {
bIsTextDefault = true;
sText = typeParams[1];
label.setText(sText);
}
|
Methods Summary |
---|
public void | setText(java.lang.String text)
if (text == null) {
text = "";
}
if (text.equals(sText)) {
return;
}
this.sText = text;
this.sKey = null;
bIsTextDefault = false;
Utils.execSWTThread(new AERunnable() {
public void runSupport() {
if (label != null && !label.isDisposed()) {
label.setText(sText);
Utils.relayout(label);
}
}
});
| public void | setTextID(java.lang.String key)
if (key == null) {
setText("");
}
if (key.equals(sKey)) {
return;
}
this.sText = MessageText.getString(key);
this.sKey = key;
bIsTextDefault = false;
Utils.execSWTThread(new AERunnable() {
public void runSupport() {
if (label != null && !label.isDisposed()) {
Messages.setLanguageText(label, key);
Utils.relayout(label);
}
}
});
| public java.lang.String | switchSuffix(java.lang.String suffix, int level, boolean walkUp)
suffix = super.switchSuffix(suffix, level, walkUp);
if (suffix == null) {
return null;
}
String sPrefix = sConfigID + ".text";
if (sText == null || bIsTextDefault) {
String text = properties.getStringValue(sPrefix + suffix);
if (text != null) {
label.setText(text);
}
}
Color color = properties.getColor(sPrefix + ".color" + suffix);
//System.out.println(this + "; " + sPrefix + ";" + suffix + "; " + color + "; " + text);
if (color != null) {
label.setForeground(color);
}
Font existingFont = (Font) label.getData("Font" + suffix);
if (existingFont != null && !existingFont.isDisposed()) {
label.setFont(existingFont);
} else {
boolean bNewFont = false;
int iFontSize = -1;
int iFontWeight = -1;
String sFontFace = null;
String sSize = properties.getStringValue(sPrefix + ".size" + suffix);
if (sSize != null) {
FontData[] fd = label.getFont().getFontData();
try {
char firstChar = sSize.charAt(0);
if (firstChar == '+" || firstChar == '-") {
sSize = sSize.substring(1);
}
int iSize = NumberFormat.getInstance(Locale.US).parse(sSize).intValue();
if (firstChar == '+") {
iFontSize = (int) (fd[0].height + iSize);
} else if (firstChar == '-") {
iFontSize = (int) (fd[0].height - iSize);
} else {
iFontSize = iSize;
}
if (sSize.endsWith("px")) {
iFontSize = Utils.getFontHeightFromPX(label.getFont(), null, iSize);
}
bNewFont = true;
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
String sStyle = properties.getStringValue(sPrefix + ".style" + suffix);
if (sStyle != null) {
String[] sStyles = sStyle.toLowerCase().split(",");
for (int i = 0; i < sStyles.length; i++) {
String s = sStyles[i];
if (s.equals("bold")) {
if (iFontWeight == -1) {
iFontWeight = SWT.BOLD;
} else {
iFontWeight |= SWT.BOLD;
}
bNewFont = true;
}
if (s.equals("italic")) {
if (iFontWeight == -1) {
iFontWeight = SWT.ITALIC;
} else {
iFontWeight |= SWT.ITALIC;
}
bNewFont = true;
}
if (s.equals("underline")) {
label.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
Point size = ((Control) e.widget).getSize();
e.gc.drawLine(0, size.y - 1, size.x - 1, size.y - 1);
}
});
}
if (s.equals("strike")) {
label.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
Point size = ((Control) e.widget).getSize();
int y = size.y / 2;
e.gc.drawLine(0, y, size.x - 1, y);
}
});
}
}
}
sFontFace = properties.getStringValue(sPrefix + ".font" + suffix);
if (sFontFace != null) {
bNewFont = true;
}
if (bNewFont) {
FontData[] fd = label.getFont().getFontData();
if (iFontSize > 0) {
fd[0].setHeight(iFontSize);
}
if (iFontWeight >= 0) {
fd[0].setStyle(iFontWeight);
}
if (sFontFace != null) {
fd[0].setName(sFontFace);
}
final Font labelFont = new Font(label.getDisplay(), fd);
label.setFont(labelFont);
label.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
labelFont.dispose();
}
});
label.setData("Font" + suffix, labelFont);
}
}
label.update();
return suffix;
|
|