
<?xml version="1.0" encoding="utf-8"?>
<Shell name="shell" descriptors="xworker.swt.widgets.Shell" text="StyledText"
RESIZE="true" width="640" height="480" label="StyledText"
icon="icons/org/eclipse/swt/custom/SashForm.gif">
<FillLayout name="shellFillLayout"></FillLayout>
<Group name="group" text="StyledText" label="StyledText">
<FillLayout name="groupFillLayout" type="SWT.VERTICAL"></FillLayout>
<Group name="styledText1" text="StyledText">
<FillLayout></FillLayout>
<StyledText name="text1" style="MULTI" H_SCROLL="true" V_SCROLL="true">
<text><![CDATA[The quick brown fox jumps over the lazy dog.
One Two Three]]></text>
</StyledText>
</Group>
<Group name="styledText1" _xmeta_id_="styledText11" text="StyledText with Colorer">
<FillLayout></FillLayout>
<StyledText name="text1" style="MULTI" H_SCROLL="true" V_SCROLL="true">
<text><![CDATA[package xworker.swt.custom;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.xmeta.ActionContext;
import org.xmeta.Bindings;
import org.xmeta.Thing;
import org.xmeta.util.UtilString;
import xworker.swt.design.Designer;
public class CLabelActions {
public static CLabel create(ActionContext actionContext){
Thing self = (Thing) actionContext.get("self");
int style = SWT.NONE;
String selfStyle = self.getString("style");
if("WRAP".equals(selfStyle)){
style |= SWT.WRAP;
}else if("SEPARATOR".equals(selfStyle)){
style |= SWT.SEPARATOR;
}
String selfType = self.getString("type");
if("HORIZONTAL".equals(selfType)){
style |= SWT.HORIZONTAL;
}else if("VERTICAL".equals(selfType)){
style |= SWT.VERTICAL;
}
String shadow = self.getString("shadow");
if("SHADOW_IN".equals(shadow)){
style |= SWT.SHADOW_IN;
}else if("SHADOW_OUT".equals(shadow)){
style |= SWT.SHADOW_OUT;
}else if("SHADOW_NONE".equals(shadow)){
style |= SWT.SHADOW_NONE;
}
if(self.getBoolean("BORDER"))
style |= SWT.BORDER;
String alignment = self.getString("alignment");
if("LEFT".equals(alignment)){
style |= SWT.LEFT;
}else if("CENTER".equals(alignment)){
style |= SWT.CENTER;
}else if("RIGHT".equals(alignment)){
style |= SWT.RIGHT;
}
Composite parent = (Composite) actionContext.get("parent");
CLabel label = new CLabel(parent, style);
//父类的初始化方法
Bindings bindings = actionContext.push(null);
bindings.put("control", label);
try{
self.doAction("super.init", actionContext);
}finally{
actionContext.pop();
}
Object image = actionContext.get(self.getString("image"));
if(image != null && image instanceof Image)
label.setImage((Image) image);
label.setText(UtilString.getString(self.getString("text"), actionContext));
label.setToolTipText(UtilString.getString(self.getString("toolTipText"), actionContext));
//保存变量和创建子事物
actionContext.getScope(0).put(self.getString("name"), label);
actionContext.peek().put("parent", label);
for(Thing child : self.getAllChilds()){
child.doAction("create", actionContext);
}
actionContext.peek().remove("parent");
Designer.attach(label, self.getMetadata().getPath(), actionContext);
return label;
}
}]]></text>
<Colorer codeName="java" codeType="java"></Colorer>
</StyledText>
</Group>
<Group name="styledText1" _xmeta_id_="styledText12" text="StyledText bind TextEditor Keys">
<FillLayout></FillLayout>
<StyledText name="text1" style="MULTI" H_SCROLL="true" V_SCROLL="true">
<text><![CDATA[The quick brown fox jumps over the lazy dog.
One Two Three
Ctrl + A: Select All
Ctrl + F: Search]]></text>
<TextEditor></TextEditor>
</StyledText>
</Group>
</Group>
</Shell>