[Xswt-developer] stylesheets
Brought to you by:
dvorme
|
From: <ha...@id...> - 2006-07-05 21:48:40
|
Hi, After implementing the tree builder, I've been working on the stylesheet mechanism, based on the design suggestions at http://www.coconut-palm-software.com/the_visual_editor/?page_id=3D61. = The current design is as follows: When the import/stylesheet tag is encountered, another instance of XSWT = is used to load that stylesheet. Parsing a stylesheet differs somewhat from parsing an ordinary file, as it expects to find all the styles at the = top level, and each must have an id. No objects are created, but the id map = is used to "remember" the styles. What is important is that that XSWT = instance keeps track of its own imports (and other state). When a style is referenced, the corresponding style tag/element/node is retrieved and parsed by the XSWT object that loaded it, but in the = context of the referencing object. I think the basic design works, but haven't gone through all the = details. However, I've written the first test that works(!): public class StyleTest extends XSWTTestCase { public void testStyle() { Label label =3D (Label)getChild(0, Label.class); Color col =3D label.getBackground(); assertEquals(255, col.getRed()); assertEquals(0, col.getGreen()); assertEquals(0, col.getBlue()); assertTrue((label.getStyle() & SWT.BORDER) > 0); } =09 public static void main(String[] args) { doRun(StyleTest.class); } } StyleTest.xswt <xswt xmlns:x=3D"http://sweet_swt.sf.net/xswt"> <import xmlns=3D"http://sweet_swt.sf.net/xswt"> <package name=3D"java.lang"/> <package name=3D"org.eclipse.swt.widgets"/> <package name=3D"com.swtworkbench.community.xswt.test"/> <stylesheet x:id=3D"styles" relativeTo=3D"StyleTest" path=3D"StyleTestStyles.xswt"/> </import> <x:children> <label x:style=3D"styles.redLabel"/> </x:children> </xswt> StyleTestStyles.xswt: <xswt xmlns:x=3D"http://sweet_swt.sf.net/xswt"> <import xmlns=3D"http://sweet_swt.sf.net/xswt"> <package name=3D"java.lang"/> <package name=3D"org.eclipse.swt.widgets"/> </import> <label x:id=3D"redLabel" x:style=3D"BORDER" background=3D"Red"/> </xswt> Note how the stylesheet has its own id and how the style in that = stylesheet is referenced using <stylesheet-id>.<style-id>. Hallvard Tr=E6tteberg (ha...@id..., http://www.idi.ntnu.no/~hal) Associate Professor, IS group, Dept. of Computer and Information = Sciences at the Norwegian Univ. of Science and Technology |