/* * Copyright (c) 2004,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 com.foundation.view.builder.*; import com.foundation.view.definition.*; public class GridLayoutDataBuilder extends AbstractLayoutBuilder { protected static final String ALIGNMENT_BEGINNING = "beginning"; protected static final String ALIGNMENT_CENTER = "center"; protected static final String ALIGNMENT_END = "end"; protected static final String ALIGNMENT_FILL = "fill"; //These are the same as beginning and end, but allow people hand writing the vml to make mistakes.// protected static final String ALIGNMENT_RIGHT = "right"; protected static final String ALIGNMENT_LEFT = "left"; protected static final String ALIGNMENT_TOP = "top"; protected static final String ALIGNMENT_BOTTOM = "bottom"; protected static final String PROPERTY_HORIZONTAL_ALIGNMENT = "horizontal-alignment"; protected static final String PROPERTY_VERTICAL_ALIGNMENT = "vertical-alignment"; protected static final String PROPERTY_DEFAULT_WIDTH = "default-width"; protected static final String PROPERTY_DEFAULT_HEIGHT = "default-height"; protected static final String PROPERTY_MINIMUM_WIDTH = "minimum-width"; protected static final String PROPERTY_MINIMUM_HEIGHT = "minimum-height"; protected static final String PROPERTY_HORIZONTAL_INDENT = "horizontal-indent"; protected static final String PROPERTY_HORIZONTAL_SPAN = "horizontal-span"; protected static final String PROPERTY_HORIZONTAL_FILL = "horizontal-fill"; protected static final String PROPERTY_VERTICAL_INDENT = "vertical-indent"; protected static final String PROPERTY_VERTICAL_SPAN = "vertical-span"; protected static final String PROPERTY_VERTICAL_FILL = "vertical-fill"; protected static final String PROPERTY_EXCLUDE = "exclude"; /** * GridLayoutDataBuilder constructor. */ public GridLayoutDataBuilder() { super(); }//GridLayoutDataBuilder()// /** * Converts the alignment identifier string into the necessary source code. * @param alignment The string identifying which alignment to use. * @return The source code specifying which alignment. */ protected String getAlignmentSource(String alignment) { String source = null; if(ALIGNMENT_BEGINNING.equals(alignment) || ALIGNMENT_LEFT.equals(alignment) || ALIGNMENT_TOP.equals(alignment)) { source = "BEGINNING"; }//if// else if(ALIGNMENT_CENTER.equals(alignment)) { source = "CENTER"; }//else if// else if(ALIGNMENT_END.equals(alignment) || ALIGNMENT_RIGHT.equals(alignment) || ALIGNMENT_BOTTOM.equals(alignment)) { source = "END"; }//else if// else if(ALIGNMENT_FILL.equals(alignment)) { source = "FILL"; }//else if// return source; }//getAlignmentSource()// /* (non-Javadoc) * @see com.foundation.view.builder.IBuilder#appendInitializationHead(com.foundation.view.builder.IViewSourceBuilder, java.lang.StringBuffer, com.foundation.view.definition.ComponentData) */ public void appendInitializationHead(IViewSourceBuilder viewBuilder, StringBuffer buffer, IComponentData data) { String horizontalAlignment = (String) data.getPropertyValue(PROPERTY_HORIZONTAL_ALIGNMENT); String verticalAlignment = (String) data.getPropertyValue(PROPERTY_VERTICAL_ALIGNMENT); Integer defaultWidth = (Integer) data.getPropertyValue(PROPERTY_DEFAULT_WIDTH); Integer defaultHeight = (Integer) data.getPropertyValue(PROPERTY_DEFAULT_HEIGHT); Integer minimumWidth = (Integer) data.getPropertyValue(PROPERTY_MINIMUM_WIDTH); Integer minimumHeight = (Integer) data.getPropertyValue(PROPERTY_MINIMUM_HEIGHT); Integer horizontalIndent = (Integer) data.getPropertyValue(PROPERTY_HORIZONTAL_INDENT); Integer horizontalSpan = (Integer) data.getPropertyValue(PROPERTY_HORIZONTAL_SPAN); Boolean horizontalFill = (Boolean) data.getPropertyValue(PROPERTY_HORIZONTAL_FILL); Integer verticalIndent = (Integer) data.getPropertyValue(PROPERTY_VERTICAL_INDENT); Integer verticalSpan = (Integer) data.getPropertyValue(PROPERTY_VERTICAL_SPAN); Boolean verticalFill = (Boolean) data.getPropertyValue(PROPERTY_VERTICAL_FILL); Boolean exclude = (Boolean) data.getPropertyValue(PROPERTY_EXCLUDE); buffer.append("\t\t" + getComponentClassName() + " layoutData = new " + getComponentClassName() + "();\r\n"); buffer.append("\t\t\r\n"); if(verticalAlignment != null) { String alignment = getAlignmentSource(verticalAlignment); if(alignment != null) { buffer.append("\t\tlayoutData.verticalAlignment = " + getComponentClassName() + "." + alignment + ";\r\n"); }//if// }//if// if(horizontalAlignment != null) { String alignment = getAlignmentSource(horizontalAlignment); if(alignment != null) { buffer.append("\t\tlayoutData.horizontalAlignment = " + getComponentClassName() + "." + alignment + ";\r\n"); }//if// }//if// if(defaultWidth != null) { buffer.append("\t\tlayoutData.widthHint = " + (defaultWidth.intValue() < 0 ? -1 : defaultWidth.intValue()) + ";\r\n"); }//if// if(defaultHeight != null) { buffer.append("\t\tlayoutData.heightHint = " + (defaultHeight.intValue() < 0 ? -1 : defaultHeight.intValue()) + ";\r\n"); }//if// if(minimumWidth != null) { buffer.append("\t\tlayoutData.minimumWidth = " + (minimumWidth.intValue() < 0 ? 0 : minimumWidth.intValue()) + ";\r\n"); if(defaultWidth == null) { buffer.append("\t\tlayoutData.widthHint = " + (minimumWidth.intValue() < 0 ? 0 : minimumWidth.intValue()) + ";\r\n"); }//if// }//if// if(minimumHeight != null) { buffer.append("\t\tlayoutData.minimumHeight = " + (minimumHeight.intValue() < 0 ? -1 : minimumHeight.intValue()) + ";\r\n"); if(defaultHeight == null) { buffer.append("\t\tlayoutData.heightHint = " + (minimumHeight.intValue() < 0 ? -1 : minimumHeight.intValue()) + ";\r\n"); }//if// }//if// if(horizontalIndent != null) { buffer.append("\t\tlayoutData.horizontalIndent = " + horizontalIndent + ";\r\n"); }//if// if(horizontalSpan != null) { buffer.append("\t\tlayoutData.horizontalSpan = " + horizontalSpan + ";\r\n"); }//if// if(verticalIndent != null) { buffer.append("\t\tlayoutData.verticalIndent = " + verticalIndent + ";\r\n"); }//if// if(verticalSpan != null) { buffer.append("\t\tlayoutData.verticalSpan = " + verticalSpan + ";\r\n"); }//if// if(horizontalFill != null) { buffer.append("\t\tlayoutData.grabExcessHorizontalSpace = " + horizontalFill + ";\r\n"); }//if// if(verticalFill != null) { buffer.append("\t\tlayoutData.grabExcessVerticalSpace = " + verticalFill + ";\r\n"); }//if// if(exclude != null) { buffer.append("\t\tlayoutData.exclude = " + exclude + ";\r\n"); }//if// buffer.append("\t\t" + viewBuilder.getComponentAttributeName(data.getParent()) + ".setLayoutData(layoutData);\r\n"); }//appendInitializationHead()// /* (non-Javadoc) * @see com.foundation.view.builder.IBuilder#getComponentClassName() */ public String getComponentClassName() { return "com.foundation.view.swt.layout.GridData"; }//getComponentClassName()// }//GridLayoutDataBuilder//