All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.java.com.dragome.render.html.renderers.HTMLComponentRenderer Maven / Gradle / Ivy

There is a newer version: 0.96-beta4
Show newest version
/*
 * Copyright (c) 2011-2014 Fernando Petrola
 *
 * 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 com.dragome.render.html.renderers;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.w3c.dom.Element;

import com.dragome.guia.components.VisualButtonImpl;
import com.dragome.guia.components.VisualCheckboxImpl;
import com.dragome.guia.components.VisualLabelImpl;
import com.dragome.guia.components.VisualListBoxImpl;
import com.dragome.guia.components.VisualPanelImpl;
import com.dragome.guia.components.VisualRadioButton;
import com.dragome.guia.components.VisualTextFieldImpl;
import com.dragome.guia.components.interfaces.VisualComboBox;
import com.dragome.guia.components.interfaces.VisualComponent;
import com.dragome.guia.components.interfaces.VisualImage;
import com.dragome.guia.components.interfaces.VisualLink;
import com.dragome.guia.components.interfaces.VisualProgressBar;
import com.dragome.guia.components.interfaces.VisualTextArea;
import com.dragome.render.canvas.interfaces.Canvas;
import com.dragome.render.interfaces.ComponentRenderer;
import com.dragome.services.ServiceLocator;

public class HTMLComponentRenderer implements ComponentRenderer
{
	private static Map, Class>> renderers= new HashMap, Class>>();

	{
		addRenderFor(VisualImage.class, HTMLImageRenderer.class);
		addRenderFor(VisualLink.class, HTMLLinkRenderer.class);
	}

	public Canvas render(final VisualComponent visualComponent)
	{
		ComponentRenderer renderer= null;

		if (visualComponent instanceof VisualComboBox)
			renderer= new HTMLComboBoxRenderer();
		else if (visualComponent instanceof VisualListBoxImpl)
			renderer= new HTMLListRenderer();
		else if (visualComponent instanceof VisualPanelImpl)
			renderer= new HTMLPanelRenderer();
		else if (visualComponent instanceof VisualCheckboxImpl)
			renderer= new HTMLCheckboxRenderer();
		else if (visualComponent instanceof VisualButtonImpl)
			renderer= new HTMLButtonRenderer();
		else if (visualComponent instanceof VisualLabelImpl)
			renderer= new HTMLLabelRenderer();
		else if (visualComponent instanceof VisualTextFieldImpl)
			renderer= new HTMLTextFieldRenderer();
		else if (visualComponent instanceof VisualTextArea)
			renderer= new HTMLTextAreaRenderer();
		else if (visualComponent instanceof VisualRadioButton)
			renderer= new HTMLRadioButtonRenderer();
		else if (visualComponent instanceof VisualProgressBar)
			renderer= new HTMLProgressBarRenderer();

		for (Entry, Class>> entry : renderers.entrySet())
		{
			if (entry.getKey().isAssignableFrom(visualComponent.getClass()))
				renderer= ServiceLocator.getInstance().getReflectionService().createClassInstance(entry.getValue());
		}

		if (renderer != null)
			return renderer.render(visualComponent);
		else
			return new HTMLLabelRenderer().render(new VisualLabelImpl("l1", "no renderer!!"));
	}

	public static  void addRenderFor(Class componentClass, Class> rendererClass)
	{
		renderers.put(componentClass, rendererClass);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy