Initial commit from SVN.
This commit is contained in:
@@ -0,0 +1,337 @@
|
||||
/*
|
||||
* Copyright (c) 2003,2009 Declarative Engineering LLC.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Declarative Engineering LLC
|
||||
* verson 1 which accompanies this distribution, and is available at
|
||||
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
||||
*/
|
||||
package com.foundation.view.swt.builder;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
|
||||
import com.common.debug.Debug;
|
||||
import com.common.util.*;
|
||||
import com.foundation.view.builder.*;
|
||||
import com.foundation.view.definition.*;
|
||||
import com.foundation.view.resource.ResourceReference;
|
||||
import com.foundation.view.JefColor;
|
||||
import com.foundation.view.JefFont;
|
||||
import com.foundation.view.JefGradient;
|
||||
import com.foundation.view.JefImage;
|
||||
|
||||
public abstract class ComponentBuilder extends AbstractBuilder {
|
||||
protected static final String STYLE_BORDER = "border";
|
||||
protected static final String STYLE_LEFT_TO_RIGHT = "left to right";
|
||||
protected static final String STYLE_RIGHT_TO_LEFT = "right to left";
|
||||
|
||||
protected static final String PROPERTY_NAME = "name";
|
||||
protected static final String PROPERTY_X = "x";
|
||||
protected static final String PROPERTY_Y = "y";
|
||||
protected static final String PROPERTY_WIDTH = "width";
|
||||
protected static final String PROPERTY_HEIGHT = "height";
|
||||
protected static final String PROPERTY_IS_VISIBLE = "is-visible";
|
||||
protected static final String PROPERTY_IS_ENABLED = "is-enabled";
|
||||
protected static final String PROPERTY_TAB_ORDER = "tab-order";
|
||||
protected static final String PROPERTY_TOOL_TIP_TEXT = "tool-tip-text";
|
||||
protected static final String PROPERTY_BACKGROUND_COLOR = "background-color";
|
||||
protected static final String PROPERTY_BACKGROUND_IMAGE = "background-image";
|
||||
protected static final String PROPERTY_FOREGROUND_COLOR = "foreground-color";
|
||||
protected static final String PROPERTY_FONT = "font";
|
||||
protected static final String PROPERTY_DECIMAL_SCALE = "decimal-scale";
|
||||
protected static final String PROPERTY_CONTAINER_TITLE = "container-title";
|
||||
protected static final String PROPERTY_CONTAINER_IMAGE = "container-image";
|
||||
protected static final String PROPERTY_CHANGE_TEXT = "change-text";
|
||||
protected static final String PROPERTY_CHANGE_IMAGE = "change-image";
|
||||
protected static final String PROPERTY_UPDATE_TEXT = "update-text";
|
||||
protected static final String PROPERTY_UPDATE_IMAGE = "update-image";
|
||||
protected static final String PROPERTY_UPDATE_TIMEOUT = "update-timeout";
|
||||
protected static final String ASSOCIATION_IS_VISIBLE = "is-visible";
|
||||
protected static final String ASSOCIATION_IS_ENABLED = "is-enabled";
|
||||
protected static final String ASSOCIATION_TOOL_TIP_TEXT = "tool-tip-text";
|
||||
protected static final String ASSOCIATION_BACKGROUND_COLOR = "background-color";
|
||||
protected static final String ASSOCIATION_BACKGROUND_IMAGE = "background-image";
|
||||
protected static final String ASSOCIATION_FOREGROUND_COLOR = "foreground-color";
|
||||
protected static final String ASSOCIATION_FONT = "font";
|
||||
protected static final String ASSOCIATION_CONTAINER_TITLE = "container-title";
|
||||
protected static final String ASSOCIATION_CONTAINER_IMAGE = "container-image";
|
||||
protected static final String EVENT_GAIN_FOCUS = "gain-focus";
|
||||
protected static final String COMPONENT_MENU_FLOATING = "menu-floating";
|
||||
|
||||
private static final String LINK_TARGET_IS_VISIBLE = "is-visible";
|
||||
private static final String LINK_TARGET_IS_ENABLED = "is-enabled";
|
||||
private static final String LINK_TARGET_GAIN_FOCUS = "gain-focus";
|
||||
private static final String LINK_TARGET_TOOL_TIP_TEXT = "tool-tip-text";
|
||||
private static final String LINK_TARGET_BACKGROUND_COLOR = "background-color";
|
||||
private static final String LINK_TARGET_FOREGROUND_COLOR = "foreground-color";
|
||||
private static final String LINK_TARGET_FONT = "font";
|
||||
|
||||
protected static final IHashMap styleMap = new LiteHashMap(AbstractBuilder.styleMap);
|
||||
protected static final IHashMap linkMap = new LiteHashMap(AbstractBuilder.linkMap);
|
||||
|
||||
static {
|
||||
styleMap.put(STYLE_BORDER, "STYLE_BORDER");
|
||||
styleMap.put(STYLE_LEFT_TO_RIGHT, "STYLE_LEFT_TO_RIGHT");
|
||||
styleMap.put(STYLE_RIGHT_TO_LEFT, "STYLE_RIGHT_TO_LEFT");
|
||||
|
||||
linkMap.put(LINK_TARGET_IS_VISIBLE, "LINK_TARGET_IS_VISIBLE");
|
||||
linkMap.put(LINK_TARGET_IS_ENABLED, "LINK_TARGET_IS_ENABLED");
|
||||
linkMap.put(LINK_TARGET_GAIN_FOCUS, "LINK_TARGET_GAIN_FOCUS");
|
||||
linkMap.put(LINK_TARGET_TOOL_TIP_TEXT, "LINK_TARGET_TOOL_TIP_TEXT");
|
||||
linkMap.put(LINK_TARGET_BACKGROUND_COLOR, "LINK_TARGET_BACKGROUND_COLOR");
|
||||
linkMap.put(LINK_TARGET_FOREGROUND_COLOR, "LINK_TARGET_FOREGROUND_COLOR");
|
||||
linkMap.put(LINK_TARGET_FONT, "LINK_TARGET_FONT");
|
||||
}//static//
|
||||
/**
|
||||
* ComponentBuilder constructor.
|
||||
*/
|
||||
public ComponentBuilder() {
|
||||
super();
|
||||
}//ComponentBuilder()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.view.builder.IBuilder#appendInitializationBody(com.foundation.view.builder.IViewSourceBuilder, java.lang.StringBuffer, com.foundation.view.definition.ComponentData, java.lang.String)
|
||||
*/
|
||||
public void appendInitializationBody(IViewSourceBuilder viewBuilder, StringBuffer buffer, IComponentData data, String variableName) {
|
||||
Integer x = (Integer) data.getPropertyValue(PROPERTY_X);
|
||||
Integer y = (Integer) data.getPropertyValue(PROPERTY_Y);
|
||||
Integer width = (Integer) data.getPropertyValue(PROPERTY_WIDTH);
|
||||
Integer height = (Integer) data.getPropertyValue(PROPERTY_HEIGHT);
|
||||
Object isVisible = (Object) data.getPropertyValue(PROPERTY_IS_VISIBLE);
|
||||
Object isEnabled = (Object) data.getPropertyValue(PROPERTY_IS_ENABLED);
|
||||
Object toolTipText = (Object) data.getPropertyValue(PROPERTY_TOOL_TIP_TEXT);
|
||||
Object backgroundColor = (Object) data.getPropertyValue(PROPERTY_BACKGROUND_COLOR);
|
||||
Object backgroundImage = (Object) data.getPropertyValue(PROPERTY_BACKGROUND_IMAGE);
|
||||
Object foregroundColor = (Object) data.getPropertyValue(PROPERTY_FOREGROUND_COLOR);
|
||||
Object font = (Object) data.getPropertyValue(PROPERTY_FONT);
|
||||
Integer decimalScale = (Integer) data.getPropertyValue(PROPERTY_DECIMAL_SCALE);
|
||||
Object title = (Object) data.getPropertyValue(PROPERTY_CONTAINER_TITLE);
|
||||
Object image = (Object) data.getPropertyValue(PROPERTY_CONTAINER_IMAGE);
|
||||
Object changeText = (Object) data.getPropertyValue(PROPERTY_CHANGE_TEXT);
|
||||
Object changeImage = (Object) data.getPropertyValue(PROPERTY_CHANGE_IMAGE);
|
||||
Object updateText = (Object) data.getPropertyValue(PROPERTY_UPDATE_TEXT);
|
||||
Object updateImage = (Object) data.getPropertyValue(PROPERTY_UPDATE_IMAGE);
|
||||
Object updateTimeout = (Object) data.getPropertyValue(PROPERTY_UPDATE_TIMEOUT);
|
||||
IList gainFocusEvents = data.getEvents(EVENT_GAIN_FOCUS);
|
||||
IComponentData floatingMenu = data.getComponent(COMPONENT_MENU_FLOATING, true);
|
||||
IList keys = data.getKeys();
|
||||
|
||||
if((width != null) && (height != null)) {
|
||||
buffer.append("\t" + variableName + ".setSize(" + width + ", " + height + ");\r\n");
|
||||
}//if//
|
||||
|
||||
if((x != null) && (y != null)) {
|
||||
buffer.append("\t" + variableName + ".setLocation(" + x + ", " + y + ");\r\n");
|
||||
}//if//
|
||||
|
||||
if(isVisible != null) {
|
||||
if(isVisible instanceof ResourceReference) {
|
||||
buffer.append("\t" + variableName + ".setDefaultIsVisible(new " + ResourceReference.class.getName() + "(\"" + ((ResourceReference) isVisible).getResourceUrl() + "\"));\r\n");
|
||||
}//if//
|
||||
else {
|
||||
buffer.append("\t" + variableName + ".setDefaultIsVisible(" + ((Boolean) isVisible).booleanValue() + ");\r\n");
|
||||
}//else//
|
||||
}//if//
|
||||
|
||||
if(isEnabled != null) {
|
||||
if(isEnabled instanceof ResourceReference) {
|
||||
buffer.append("\t" + variableName + ".setDefaultIsEnabled(new " + ResourceReference.class.getName() + "(\"" + ((ResourceReference) isEnabled).getResourceUrl() + "\"));\r\n");
|
||||
}//if//
|
||||
else {
|
||||
buffer.append("\t" + variableName + ".setDefaultIsEnabled(" + ((Boolean) isEnabled).booleanValue() + ");\r\n");
|
||||
}//else//
|
||||
}//if//
|
||||
|
||||
if(toolTipText != null) {
|
||||
if(toolTipText instanceof ResourceReference) {
|
||||
buffer.append("\t" + variableName + ".setDefaultToolTipText(new " + ResourceReference.class.getName() + "(\"" + ((ResourceReference) toolTipText).getResourceUrl() + "\"));\r\n");
|
||||
}//if//
|
||||
else {
|
||||
buffer.append("\t" + variableName + ".setDefaultToolTipText(\"" + toolTipText + "\");\r\n");
|
||||
}//else//
|
||||
}//if//
|
||||
|
||||
if(backgroundColor != null) {
|
||||
if(backgroundColor instanceof ResourceReference) {
|
||||
buffer.append("\t" + variableName + ".setDefaultBackgroundColor(new " + ResourceReference.class.getName() + "(\"" + ((ResourceReference) backgroundColor).getResourceUrl() + "\"));\r\n");
|
||||
}//if//
|
||||
else {
|
||||
buffer.append("\t" + variableName + ".setDefaultBackgroundColor(new " + JefGradient.class.getName() + "(\"" + backgroundColor + "\"));\r\n");
|
||||
}//else//
|
||||
}//if//
|
||||
|
||||
if(backgroundImage != null) {
|
||||
if(backgroundImage instanceof ResourceReference) {
|
||||
buffer.append("\t" + variableName + ".setDefaultBackgroundImage(new " + ResourceReference.class.getName() + "(\"" + ((ResourceReference) backgroundImage).getResourceUrl() + "\"));\r\n");
|
||||
}//if//
|
||||
else {
|
||||
buffer.append("\t" + variableName + ".setDefaultBackgroundImage(new " + JefImage.class.getName() + "(\"" + backgroundImage + "\"));\r\n");
|
||||
}//else//
|
||||
}//if//
|
||||
|
||||
if(foregroundColor != null) {
|
||||
if(foregroundColor instanceof ResourceReference) {
|
||||
buffer.append("\t" + variableName + ".setDefaultForegroundColor(new " + ResourceReference.class.getName() + "(\"" + ((ResourceReference) foregroundColor).getResourceUrl() + "\"));\r\n");
|
||||
}//if//
|
||||
else {
|
||||
buffer.append("\t" + variableName + ".setDefaultForegroundColor(new " + JefColor.class.getName() + "(\"" + foregroundColor + "\"));\r\n");
|
||||
}//else//
|
||||
}//if//
|
||||
|
||||
if(font != null) {
|
||||
if(font instanceof ResourceReference) {
|
||||
buffer.append("\t" + variableName + ".setDefaultFont(new " + ResourceReference.class.getName() + "(\"" + ((ResourceReference) font).getResourceUrl() + "\"));\r\n");
|
||||
}//if//
|
||||
else {
|
||||
buffer.append("\t" + variableName + ".setDefaultFont(" + JefFont.class.getName() + ".getJefFonts(\"" + JefFont.getJefFontsString((JefFont[]) font) + "\"));\r\n");
|
||||
}//else//
|
||||
}//if//
|
||||
|
||||
if(changeText != null) {
|
||||
if(changeText instanceof ResourceReference) {
|
||||
buffer.append("\t" + variableName + ".setDefaultChangeText(new " + ResourceReference.class.getName() + "(\"" + ((ResourceReference) changeText).getResourceUrl() + "\"));\r\n");
|
||||
}//if//
|
||||
else {
|
||||
buffer.append("\t" + variableName + ".setDefaultChangeText(\"" + changeText + "\");\r\n");
|
||||
}//else//
|
||||
}//if//
|
||||
|
||||
if(changeImage != null) {
|
||||
if(changeImage instanceof ResourceReference) {
|
||||
buffer.append("\t" + variableName + ".setDefaultChangeImage(new " + ResourceReference.class.getName() + "(\"" + ((ResourceReference) changeImage).getResourceUrl() + "\"));\r\n");
|
||||
}//if//
|
||||
else {
|
||||
buffer.append("\t" + variableName + ".setDefaultChangeImage(new " + JefImage.class.getName() + "(\"" + changeImage + "\"));\r\n");
|
||||
}//else//
|
||||
}//if//
|
||||
|
||||
if(updateText != null) {
|
||||
if(updateText instanceof ResourceReference) {
|
||||
buffer.append("\t" + variableName + ".setDefaultUpdateText(new " + ResourceReference.class.getName() + "(\"" + ((ResourceReference) updateText).getResourceUrl() + "\"));\r\n");
|
||||
}//if//
|
||||
else {
|
||||
buffer.append("\t" + variableName + ".setDefaultUpdateText(\"" + updateText + "\");\r\n");
|
||||
}//else//
|
||||
}//if//
|
||||
|
||||
if(updateImage != null) {
|
||||
if(updateImage instanceof ResourceReference) {
|
||||
buffer.append("\t" + variableName + ".setDefaultUpdateImage(new " + ResourceReference.class.getName() + "(\"" + ((ResourceReference) updateImage).getResourceUrl() + "\"));\r\n");
|
||||
}//if//
|
||||
else {
|
||||
buffer.append("\t" + variableName + ".setDefaultUpdateImage(new " + JefImage.class.getName() + "(\"" + updateImage + "\"));\r\n");
|
||||
}//else//
|
||||
}//if//
|
||||
|
||||
if(updateTimeout != null) {
|
||||
if(updateTimeout instanceof ResourceReference) {
|
||||
//Not supported yet.//
|
||||
// buffer.append("\t" + variableName + ".setDefaultUpdateTimeout(new " + ResourceReference.class.getName() + "(\"" + ((ResourceReference) updateTimeout).getResourceUrl() + "\"));\r\n");
|
||||
}//if//
|
||||
else {
|
||||
int timeout = 10000;
|
||||
|
||||
try {
|
||||
timeout = updateTimeout instanceof Number ? ((Number) updateTimeout).intValue() : NumberFormat.getIntegerInstance().parse(updateTimeout.toString()).intValue();
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
|
||||
buffer.append("\t" + variableName + ".setDefaultUpdateTimeout(new Integer(" + timeout + "));\r\n");
|
||||
}//else//
|
||||
}//if//
|
||||
|
||||
if(decimalScale != null) {
|
||||
buffer.append("\t" + variableName + ".setDecimalScale(new Integer(" + decimalScale + "));\r\n");
|
||||
}//if//
|
||||
|
||||
appendAssociation(viewBuilder, buffer, data, ASSOCIATION_IS_VISIBLE, variableName, "setIsVisibleAssociation", "ASSOCIATION_IS_VISIBLE", IViewSourceBuilder.ACCESS_TYPE_GET_ONLY);
|
||||
appendAssociation(viewBuilder, buffer, data, ASSOCIATION_IS_ENABLED, variableName, "setIsEnabledAssociation", "ASSOCIATION_IS_ENABLED", IViewSourceBuilder.ACCESS_TYPE_GET_ONLY);
|
||||
appendAssociation(viewBuilder, buffer, data, ASSOCIATION_TOOL_TIP_TEXT, variableName, "setToolTipTextAssociation", "ASSOCIATION_TOOL_TIP_TEXT", IViewSourceBuilder.ACCESS_TYPE_GET_ONLY);
|
||||
appendAssociation(viewBuilder, buffer, data, ASSOCIATION_BACKGROUND_COLOR, variableName, "setBackgroundColorAssociation", "ASSOCIATION_BACKGROUND_COLOR", IViewSourceBuilder.ACCESS_TYPE_GET_ONLY);
|
||||
appendAssociation(viewBuilder, buffer, data, ASSOCIATION_BACKGROUND_IMAGE, variableName, "setBackgroundImageAssociation", "ASSOCIATION_BACKGROUND_IMAGE", IViewSourceBuilder.ACCESS_TYPE_GET_ONLY);
|
||||
appendAssociation(viewBuilder, buffer, data, ASSOCIATION_FOREGROUND_COLOR, variableName, "setForegroundColorAssociation", "ASSOCIATION_FOREGROUND_COLOR", IViewSourceBuilder.ACCESS_TYPE_GET_ONLY);
|
||||
appendAssociation(viewBuilder, buffer, data, ASSOCIATION_FONT, variableName, "setFontAssociation", "ASSOCIATION_FONT", IViewSourceBuilder.ACCESS_TYPE_GET_ONLY);
|
||||
appendAssociation(viewBuilder, buffer, data, ASSOCIATION_CONTAINER_TITLE, variableName, "setContainerTitleAssociation", "ASSOCIATION_CONTAINER_TITLE", IViewSourceBuilder.ACCESS_TYPE_GET_ONLY);
|
||||
appendAssociation(viewBuilder, buffer, data, ASSOCIATION_CONTAINER_IMAGE, variableName, "setContainerImageAssociation", "ASSOCIATION_CONTAINER_IMAGE", IViewSourceBuilder.ACCESS_TYPE_GET_ONLY);
|
||||
|
||||
if(title != null) {
|
||||
if(title instanceof ResourceReference) {
|
||||
buffer.append("\t" + variableName + ".setDefaultContainerTitle(new " + ResourceReference.class.getName() + "(\"" + ((ResourceReference) title).getResourceUrl() + "\"));\r\n");
|
||||
}//if//
|
||||
else {
|
||||
buffer.append("\t" + variableName + ".setDefaultContainerTitle(\"" + title + "\");\r\n");
|
||||
}//else//
|
||||
}//if//
|
||||
|
||||
if(image != null) {
|
||||
if(image instanceof ResourceReference) {
|
||||
buffer.append("\t" + variableName + ".setDefaultContainerImage(new " + ResourceReference.class.getName() + "(\"" + ((ResourceReference) image).getResourceUrl() + "\"));\r\n");
|
||||
}//if//
|
||||
else {
|
||||
buffer.append("\t" + variableName + ".setDefaultContainerImage(new " + JefImage.class.getName() + "(\"" + image + "\"));\r\n");
|
||||
}//else//
|
||||
}//if//
|
||||
|
||||
if(gainFocusEvents != null) {
|
||||
for(int index = 0; index < gainFocusEvents.getSize(); index++) {
|
||||
IEventPart eventPart = (IEventPart) gainFocusEvents.get(index);
|
||||
|
||||
buffer.append("\t");
|
||||
buffer.append(variableName);
|
||||
buffer.append(".addGainFocusEventAssociation(");
|
||||
viewBuilder.appendEventAssociation(buffer, variableName, eventPart);
|
||||
buffer.append(");\r\n");
|
||||
}//for//
|
||||
}//if//
|
||||
|
||||
if(keys != null) {
|
||||
for(int index = 0; index < keys.getSize(); index++) {
|
||||
IKeyPart keyPart = (IKeyPart) keys.get(index);
|
||||
String identifier = viewBuilder.addKeyBindingIdentifier(keyPart, variableName, null);
|
||||
|
||||
viewBuilder.addDirectKeyHandler(data, identifier, keyPart);
|
||||
buffer.append('\t');
|
||||
buffer.append(variableName);
|
||||
buffer.append(".addKeyBinding(");
|
||||
viewBuilder.appendKeyBinding(buffer, variableName, keyPart, identifier);
|
||||
buffer.append(");\r\n");
|
||||
}//for//
|
||||
}//if//
|
||||
|
||||
if(floatingMenu != null) {
|
||||
String initializeMethodName = viewBuilder.addInitializeMenuMethod(data, floatingMenu, "PopupMenu");
|
||||
|
||||
buffer.append('\t');
|
||||
buffer.append(initializeMethodName);
|
||||
buffer.append('(');
|
||||
buffer.append(variableName);
|
||||
buffer.append(");\r\n");
|
||||
}//if//
|
||||
}//appendInitializationBody()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.view.builder.IBuilder#appendLinks(com.foundation.view.builder.IViewSourceBuilder, java.lang.StringBuffer, com.foundation.view.definition.ComponentData, java.lang.String)
|
||||
*/
|
||||
public void appendLinks(IViewSourceBuilder viewBuilder, StringBuffer buffer, IComponentData data, String variableName) {
|
||||
}//appendLinks()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.view.swt.builder.AbstractBuilder#getStyleMap()
|
||||
*/
|
||||
public IHashMap getStyleMap() {
|
||||
return styleMap;
|
||||
}//getStyleMap()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.view.swt.builder.AbstractBuilder#getLinkMap()
|
||||
*/
|
||||
public IHashMap getLinkMap() {
|
||||
return linkMap;
|
||||
}//getLinkMap()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.view.builder.IBuilder#shouldPack(com.foundation.view.definition.ComponentData)
|
||||
*/
|
||||
public boolean shouldPack(IComponentData componentData) {
|
||||
Integer width = (Integer) componentData.getPropertyValue(PROPERTY_WIDTH);
|
||||
Integer height = (Integer) componentData.getPropertyValue(PROPERTY_HEIGHT);
|
||||
|
||||
return (width == null) || (height == null);
|
||||
}//shouldPack()//
|
||||
}//ComponentBuilder//
|
||||
Reference in New Issue
Block a user