org.wings.plaf.css.AbstractComponentCG Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2000,2005 wingS development team.
*
* This file is part of wingS (http://wingsframework.org).
*
* wingS is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* Please see COPYING for the complete licence.
*/
package org.wings.plaf.css;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wings.*;
import org.wings.border.SDefaultBorder;
import org.wings.border.SEmptyBorder;
import org.wings.dnd.DragSource;
import org.wings.dnd.DropTarget;
import org.wings.io.Device;
import org.wings.io.StringBuilderDevice;
import org.wings.plaf.*;
import org.wings.plaf.css.script.OnPageRenderedScript;
import org.wings.session.ScriptManager;
import org.wings.util.SessionLocal;
import java.io.IOException;
import java.io.Serializable;
import java.util.Map;
/**
* Partial CG implementation that is common to all ComponentCGs.
*
* @author Holger Engels
*/
public abstract class AbstractComponentCG
implements ComponentCG, SConstants, Serializable
{
private static final Logger log = LoggerFactory.getLogger(AbstractComponentCG.class);
/**
* An invisible icon / graphic (spacer graphic)
*/
private static final SIcon BLIND_ICON = new SResourceIcon("org/wings/icons/blind.gif");
/**
* Be careful with this shared StringBuilder. Don't use it in situations where unknown code is called, that might
* use the StringBuilder, too.
*/
public static final SessionLocal STRING_BUILDER = new SessionLocal() {
@Override
protected StringBuilder initialValue() {
return new StringBuilder();
}
};
protected AbstractComponentCG() {
}
/**
* Renders the default HTML TABLE prefix code for a component. This prefix will handle
*
* - All CSS Attrbiutes declared on the SComponent
* - Components CSS class
* - Components id
* - Borders and insets (only if TABLE is used)
* - Components ToolTip hooks
* - Components Popup menu hooks
* - components event id
eid
*
*
* @param device The output device to use
* @param component The component to render
* @throws IOException on error on the output device
*/
protected final void writeTablePrefix(Device device, COMPONENT_TYPE component) throws IOException {
writePrefix(device, component, true, null);
}
/**
* Renders the default HTML TABLE prefix code for a component. This prefix will handle
*
* - All CSS Attrbiutes declared on the SComponent
* - Components CSS class
* - Components id
* - Borders and insets (only if TABLE is used)
* - Components ToolTip hooks
* - Components Popup menu hooks
* - components event id
eid
*
*
* @param device The output device to use
* @param component The component to render
* @throws IOException on error on the output device
*/
protected final void writeTablePrefix(Device device, COMPONENT_TYPE component, Map optionalAttributes) throws IOException {
writePrefix(device, component, true, optionalAttributes);
}
/**
* Renders the closing suffix for a TABLE based component prefix.
* @param device The output device to use
* @param component The component to render
* @throws IOException on error on the output device
*/
protected final void writeTableSuffix(Device device, COMPONENT_TYPE component) throws IOException {
writeSuffix(device, component, true);
}
/**
* Renders a DIV prefix code for a component. Discouraged
* This prefix will handle
*
* - All CSS Attrbiutes declared on the SComponent
* - Components CSS class
* - Components id
* - Borders and insets (only if TABLE is used)
* - Components ToolTip hooks
* - Components Popup menu hooks
* - components event id
eid
*
*
* @param device The output device to use
* @param component The component to render
* @param optionalAttributes A map of additional CSS attributes
* @throws IOException on error on the output device
*/
protected final void writeDivPrefix(Device device, COMPONENT_TYPE component, Map optionalAttributes) throws IOException {
writePrefix(device, component, false, optionalAttributes);
}
/**
* Renders the closing suffix for a DIV prefix.
* @param device The output device to use
* @param component The component to render
* @throws IOException on error on the output device
*/
protected final void writeDivSuffix(Device device, COMPONENT_TYPE component) throws IOException {
writeSuffix(device, component, false);
}
/**
* Renders the HTML prefix code for a component. This prefix will handle
*
* - All CSS Attrbiutes declared on the SComponent
* - Components CSS class
* - Components id
* - Borders and insets (only if TABLE is used)
* - Components ToolTip hooks
* - Components Popup menu hooks
* - components event id
eid
*
*
* @param device The output device to use
* @param component The component to render
* @param useTable true
if it should be wrapped into a TABLE
element (recommended!) or a DIV
* @param optionalAttributes A map of additional CSS attributes
* @throws IOException on error on the output device
*/
protected final void writePrefix(final Device device, final COMPONENT_TYPE component,
final boolean useTable, Map optionalAttributes)
throws IOException {
// This is the containing element of a component
// it is responsible for styles, sizing...
if (useTable) {
device.print("'); // table
}
else {
device.print('>'); // div
}
}
protected final void writeSuffix(Device device, COMPONENT_TYPE component, boolean useTable) throws IOException {
if (useTable) {
device.print("
");
}
else {
device.print("