You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by di...@apache.org on 2004/09/05 17:25:02 UTC
cvs commit: jakarta-commons/jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt ColorTag.java FontTag.java
dion 2004/09/05 08:25:02
Added: jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt
ColorTag.java FontTag.java
Log:
Add new tags
Revision Changes Path
1.1 jakarta-commons/jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt/ColorTag.java
Index: ColorTag.java
===================================================================
/*
* Copyright 2002,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jelly.tags.swt;
import org.apache.commons.jelly.JellyTagException;
import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.XMLOutput;
import org.apache.commons.jelly.tags.swt.converters.ColorConverter;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Widget;
/**
* Class to create a {@link Color} instance within Jelly SWT.
*
* @author <a href="mailto:crafterm@apache.org">Marcus Crafter</a>
* @author Written with much help thanks to the ImageTag class
* @version CVS $Id: ColorTag.java,v 1.1 2004/09/05 15:25:02 dion Exp $
*/
public class ColorTag extends TagSupport {
/** RGB value */
private String rgb;
/** Variable name */
private String var;
/**
* Sets the RGB value for this {@link Color} instance
*
* @param rgb value (eg. #666666);
*/
public void setRgb(final String rgb) {
this.rgb = rgb;
}
/**
* Obtain the RGB value for this {@link Color} instance
*
* @return the RGB value (eg. #666666)
*/
public String getRgb() {
return this.rgb;
}
/**
* Sets the variable name
*
* @param var the variable name of this {@link Color} instance
*/
public void setVar(final String var) {
this.var = var;
}
/**
* Obtain the variable name.
*
* @return the variable name of this {@link Color} instance
*/
public String getVar() {
return this.var;
}
/**
* @return the parent widget which this widget will be added to.
*/
public Widget getParentWidget() {
final WidgetTag tag = (WidgetTag) findAncestorWithClass(WidgetTag.class);
if (tag != null) {
return tag.getWidget();
}
return null;
}
// Tag interface
//-------------------------------------------------------------------------
/**
* Creates a {@link Color} instance as defined by the RGB attribute.
* Stores this {@link Color} instance in the Context so that it can be
* referenced in the Jelly script.
*
* @param output {@link XMLOutput} reference
* @throws JellyTagException if an error occurs
* @see org.apache.commons.jelly.Tag#doTag(org.apache.commons.jelly.XMLOutput)
*/
public void doTag(final XMLOutput output) throws JellyTagException {
// invoke by body just in case some nested tag configures me
invokeBody(output);
final Widget parent = getParentWidget();
if (parent == null) {
throw new JellyTagException(
"This tag must be nested within a Widget or a Window"
);
}
if (var == null) {
throw new JellyTagException("This tag requires a context variable name");
}
final Color color =
new Color(
parent.getDisplay(),
ColorConverter.getInstance().parse(getRgb())
);
// store the Color in the context
context.setVariable(var, color);
}
}
1.1 jakarta-commons/jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt/FontTag.java
Index: FontTag.java
===================================================================
/*
* Copyright 2002,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jelly.tags.swt;
import org.apache.commons.jelly.JellyTagException;
import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.XMLOutput;
import org.apache.commons.jelly.tags.swt.converters.ColorConverter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Widget;
/**
* Class to create a {@link Font} instance within Jelly SWT.
*
* @author <a href="mailto:crafterm@apache.org">Marcus Crafter</a>
* @author Written with much help thanks to the ImageTag class
* @version CVS $Id: FontTag.java,v 1.1 2004/09/05 15:25:02 dion Exp $
*/
public class FontTag extends TagSupport {
/** The Log to which logging calls will be made. */
private static final Log log = LogFactory.getLog(FontTag.class);
/** Font type */
private String type;
/** Font size */
private int size;
/** Font style */
private String style;
/** Font variable name */
private String var;
/**
* Set the type of this {@link Font}
*
* @param type {@link Font} type name
*/
public void setType(final String type) {
this.type = type;
}
/**
* Obtain the {@link Font} type name
*
* @return the {@link Font} type name
*/
public String getType() {
return this.type;
}
/**
* Set the size of this {@link Font}
*
* @param size {@link Font} size
*/
public void setSize(final int size) {
this.size = size;
}
/**
* Obtain the {@link Font} size
*
* @return the {@link Font} size
*/
public int getSize() {
return this.size;
}
/**
* Set the style of this {@link Font} (eg. bold, normal, italics)
*
* @param style the style of this {@link Font}
*/
public void setStyle(final String style) {
this.style = style;
}
/**
* Obtain the style of this {@link Font}
*
* @return the style of this {@link Font}
*/
public String getStyle() {
return this.style;
}
/**
* Sets the variable name
*
* @param var the variable name of this {@link Font} instance
*/
public void setVar(final String var) {
this.var = var;
}
/**
* Obtain the variable name.
*
* @return the variable name of this {@link Font} instance
*/
public String getVar() {
return this.var;
}
/**
* @return the parent widget which will deliver us a {@link Device} reference
*/
public Widget getParentWidget() {
final WidgetTag tag = (WidgetTag) findAncestorWithClass(WidgetTag.class);
if (tag != null) {
return tag.getWidget();
}
return null;
}
// Tag interface
//-------------------------------------------------------------------------
/**
* Creates a {@link Font} instance as defined by the type, size and style
* attributes, and stores this {@link Font} instance in the Context so that
* it can be referenced in the Jelly script.
*
* @param output {@link XMLOutput} reference
* @throws JellyTagException if an error occurs
* @see org.apache.commons.jelly.Tag#doTag(org.apache.commons.jelly.XMLOutput)
*/
public void doTag(final XMLOutput output) throws JellyTagException {
// invoke by body just in case some nested tag configures me
invokeBody(output);
final Widget parent = getParentWidget();
if (parent == null) {
throw new JellyTagException(
"This tag must be nested within a Widget or a Window"
);
}
if (var == null) {
throw new JellyTagException("This tag requires a context variable name");
}
if (type == null) {
throw new JellyTagException("This tag requires a font type name");
}
if (size <= 0) {
throw new JellyTagException("This tag requires a font size greater than 0");
}
if (style == null) {
if (log.isDebugEnabled()) {
log.debug("No style set on font " + type + ", defaulting to normal");
}
}
final Font font =
new Font(
parent.getDisplay(),
type,
size,
style == null ? SWT.NORMAL : SwtHelper.parseStyle(SWT.class, style)
);
// store the Color in the context
context.setVariable(var, font);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org