jstrachan 2003/01/31 09:16:16
Modified: jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt
SwtTagLibrary.java MenuTag.java WidgetTag.java
jelly/jelly-tags/swt/src/test/org/apache/commons/jelly/tags/swt
example.jelly
Added: jelly/jelly-tags/swt/src/test/org/apache/commons/jelly/tags/swt
styleDefaultDemo.jelly
Log:
Added a default style code to most of the widgets so that specifying styles on
widgets is not required (though is still there if you need to change the defaults)
Revision Changes Path
1.3 +41 -13
jakarta-commons-sandbox/jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt/SwtTagLibrary.java
Index: SwtTagLibrary.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt/SwtTagLibrary.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SwtTagLibrary.java 24 Jan 2003 05:26:13 -0000 1.2
+++ SwtTagLibrary.java 31 Jan 2003 17:16:16 -0000 1.3
@@ -61,12 +61,13 @@
*/
package org.apache.commons.jelly.tags.swt;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.*;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
-import org.eclipse.swt.custom.*;
import org.eclipse.swt.widgets.*;
import org.apache.commons.jelly.JellyException;
@@ -96,35 +97,37 @@
public SwtTagLibrary() {
// widgets
- registerWidgetTag( "button", Button.class );
+ registerWidgetTag( "button", Button.class, SWT.BORDER | SWT.PUSH |
SWT.CENTER );
registerWidgetTag( "canvas", Canvas.class );
registerWidgetTag( "caret", Caret.class );
- registerWidgetTag( "combo", Combo.class );
+ registerWidgetTag( "combo", Combo.class, SWT.DROP_DOWN );
registerWidgetTag( "composite", Composite.class );
- registerWidgetTag( "coolBar", CoolBar.class );
+ registerWidgetTag( "coolBar", CoolBar.class, SWT.VERTICAL );
registerWidgetTag( "coolItem", CoolItem.class );
registerWidgetTag( "decorations", Decorations.class );
registerWidgetTag( "group", Group.class );
- registerWidgetTag( "label", Label.class );
+ registerWidgetTag( "label", Label.class, SWT.HORIZONTAL | SWT.SHADOW_IN );
registerWidgetTag( "list", List.class );
- registerTag( "menu", MenuTag.class );
+ registerMenuTag( "menu", SWT.DEFAULT );
+ registerMenuTag( "menuBar", SWT.BAR );
+ registerWidgetTag( "menuSeparator", MenuItem.class, SWT.SEPARATOR );
registerWidgetTag( "menuItem", MenuItem.class );
registerWidgetTag( "messageBox", MessageBox.class );
- registerWidgetTag( "progressBar", ProgressBar.class );
+ registerWidgetTag( "progressBar", ProgressBar.class, SWT.HORIZONTAL );
registerWidgetTag( "sash", Sash.class );
registerWidgetTag( "scale", Scale.class );
- registerWidgetTag( "shell", Shell.class );
+ registerWidgetTag( "shell", Shell.class, SWT.BORDER | SWT.CLOSE | SWT.MIN |
SWT.MAX | SWT.RESIZE | SWT.TITLE );
registerWidgetTag( "slider", Slider.class );
registerWidgetTag( "tabFolder", TabFolder.class );
registerWidgetTag( "tabItem", TabItem.class );
- registerWidgetTag( "table", Table.class );
+ registerWidgetTag( "table", Table.class, SWT.MULTI | SWT.BORDER |
SWT.FULL_SELECTION );
registerWidgetTag( "tableColumn", TableColumn.class );
registerWidgetTag( "tableItem", TableItem.class );
registerWidgetTag( "text", Text.class );
- registerWidgetTag( "toolBar", ToolBar.class );
+ registerWidgetTag( "toolBar", ToolBar.class, SWT.VERTICAL );
registerWidgetTag( "toolItem", ToolItem.class );
registerWidgetTag( "tracker", Tracker.class );
- registerWidgetTag( "tree", Tree.class );
+ registerWidgetTag( "tree", Tree.class, SWT.MULTI );
registerWidgetTag( "treeItem", TreeItem.class );
// custom widgets
@@ -189,7 +192,32 @@
/**
* Register a widget tag for the given name
*/
- protected void registerWidgetTag(String name, final Class widgetClass) {
+ protected void registerWidgetTag(String name, Class widgetClass) {
+ registerWidgetTag(name, widgetClass, SWT.DEFAULT);
+ }
+
+ /**
+ * Register a widget tag for the given name
+ */
+ protected void registerWidgetTag(String name, final Class widgetClass, final
int style) {
+ registerTagFactory(
+ name,
+ new TagFactory() {
+ /**
+ * @see
org.apache.commons.jelly.impl.TagFactory#createTag(java.lang.String,
org.xml.sax.Attributes)
+ */
+ public Tag createTag(String name, Attributes attributes)
+ throws JellyException {
+ return new WidgetTag(widgetClass, style);
+ }
+ }
+ );
+ }
+
+ /**
+ * Register a menu tag for the given name and style
+ */
+ protected void registerMenuTag(String name, final int style) {
registerTagFactory(
name,
new TagFactory() {
@@ -198,7 +226,7 @@
*/
public Tag createTag(String name, Attributes attributes)
throws JellyException {
- return new WidgetTag(widgetClass);
+ return new MenuTag(style);
}
}
);
1.4 +3 -13
jakarta-commons-sandbox/jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt/MenuTag.java
Index: MenuTag.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt/MenuTag.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MenuTag.java 24 Jan 2003 22:53:33 -0000 1.3
+++ MenuTag.java 31 Jan 2003 17:16:16 -0000 1.4
@@ -86,20 +86,10 @@
super(Menu.class);
}
- /**
- * @return the parent Shell or returns null
- */
-/*
- public Widget getParentWidget() {
- Widget parent = super.getParentWidget();
- if (parent instanceof Menu) {
- Menu menu = (Menu) parent;
- return menu.getShell();
- }
- return null;
+ public MenuTag(int style) {
+ super(Menu.class, style);
}
-*/
-
+
// Implementation methods
//-------------------------------------------------------------------------
1.5 +8 -2
jakarta-commons-sandbox/jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt/WidgetTag.java
Index: WidgetTag.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt/WidgetTag.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- WidgetTag.java 31 Jan 2003 12:54:02 -0000 1.4
+++ WidgetTag.java 31 Jan 2003 17:16:16 -0000 1.5
@@ -85,12 +85,18 @@
/** The Log to which logging calls will be made. */
private static final Log log = LogFactory.getLog(WidgetTag.class);
- private Widget parent;
+ private Widget parent;
+ private int style = SWT.DEFAULT;
public WidgetTag(Class widgetClass) {
super(widgetClass);
}
+ public WidgetTag(Class widgetClass, int style) {
+ super(widgetClass);
+ this.style = style;
+ }
+
public String toString() {
return "WidgetTag[widget=" + getWidget() + "]";
}
@@ -230,6 +236,6 @@
if (text != null) {
return SwtHelper.parseStyle(SWT.class, text);
}
- return SWT.DEFAULT;
+ return style;
}
}
1.3 +5 -0
jakarta-commons-sandbox/jelly/jelly-tags/swt/src/test/org/apache/commons/jelly/tags/swt/example.jelly
Index: example.jelly
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/swt/src/test/org/apache/commons/jelly/tags/swt/example.jelly,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- example.jelly 31 Jan 2003 12:54:02 -0000 1.2
+++ example.jelly 31 Jan 2003 17:16:16 -0000 1.3
@@ -76,6 +76,11 @@
<j:include uri="parentDemo.jelly"/>
</onEvent>
</toolItem>
+ <toolItem text="Style Defaulting Demo" toolTipText="Shows how default
styles can be used, rather than always specifying the styles">
+ <onEvent type="Selection">
+ <j:include uri="styleDefaultDemo.jelly"/>
+ </onEvent>
+ </toolItem>
</toolBar>
</shell>
1.1
jakarta-commons-sandbox/jelly/jelly-tags/swt/src/test/org/apache/commons/jelly/tags/swt/styleDefaultDemo.jelly
Index: styleDefaultDemo.jelly
===================================================================
<?xml version="1.0"?>
<j:jelly xmlns:j="jelly:core" xmlns="jelly:swt" xmlns:log="jelly:log">
<!--
|| A demo which shows some default styles being used rather than
explicitly
|| specifying them for each widget
-->
<shell text="This is a shell" var="subShell">
<menuBar>
<menuItem text="File" style="cascade">
<menu>
<menuItem text="New">
<onEvent type="Selection">
<log:info>Selected New option
with event ${event}</log:info>
</onEvent>
</menuItem>
<menuItem text="Open"/>
<menuSeparator/>
<menuItem text="Save"/>
</menu>
</menuItem>
<menuItem text="Help" style="cascade">
<menu>
<menuItem text="About"/>
</menu>
</menuItem>
</menuBar>
<gridLayout/>
<group text="Some form">
<gridData style="fill_horizontal"/>
<gridLayout numColumns="2"/>
<label text="Hello"/>
<text var="textField" text="1234" editable="true">
<gridData style="fill_horizontal"/>
</text>
</group>
<table
headerVisible="true"
linesVisible="true"
toolTipText="This is a table!">
<gridData style="fill_both"/>
<tableColumn text="Name" width="100" toolTipText="This is the
name column"/>
<tableColumn text="Age" width="40" toolTipText="This is the
age column"/>
<!-- we'd normally use some Java bean model to implement the
next bit -->
<tableItem var="row"/>
${row.setText(0, 'James')}
${row.setText(1, '33')}
<tableItem var="row"/>
${row.setText(0, 'Bob')}
${row.setText(1, '30')}
</table>
<toolBar>
<toolItem text="Click Me" toolTipText="I am a ToolBar Item that you
can click">
<onEvent type="Selection">
<log:info>Clicked button with event ${event} and text
field contains ${textField.text}</log:info>
</onEvent>
</toolItem>
</toolBar>
</shell>
<!-- we could abstract the following away as a tag -->
${subShell.pack()}
${subShell.open()}
</j:jelly>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]