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

org.wings.plaf.css.CursorCG Maven / Gradle / Ivy

package org.wings.plaf.css;

import org.wings.SComponent;
import org.wings.SLabel;
import org.wings.SIcon;
import org.wings.script.ScriptListener;
import org.wings.session.SCursor;
import org.wings.session.ScriptManager;
import org.wings.plaf.Update;
import org.wings.io.Device;
import org.wings.io.StringBuilderDevice;

import java.io.IOException;
import java.util.List;

public class CursorCG extends AbstractComponentCG implements org.wings.plaf.CursorCG {
    public CursorCG() {
    }

    public static void writeInnerComponent(Device device, SCursor component) throws IOException {
        List icons = component.getIconsByPriority();

        device.print("");

        for(SIcon icon : icons) {
            device.print("\"");");
        }

        SLabel label = component.getLabel();
        if(label != null) {
            LabelCG labelCG = (LabelCG)label.getCG();

            labelCG.write(device, label);
        }

        device.print("");
    }

    public static void writeComponent(Device device, SCursor component) throws IOException {
        //Write outer element (Updates update everything inside)
		device.print("");
		
		//Write inner element
        writeInnerComponent(device, component);

        device.print("
"); } @Override public void writeInternal(Device device, SComponent component) throws IOException { writeComponent(device, (SCursor)component); final SComponent cursor = component; ScriptManager.getInstance().addScriptListener(new MyScriptListener(cursor)); } @Override public Update getContentUpdate(SComponent component) { return new ContentUpdate(component); } protected final static class ContentUpdate extends AbstractUpdate { public ContentUpdate(SComponent component) { super(component); } String htmlCode = ""; String exception = null; @Override public Handler getHandler() { UpdateHandler handler = new UpdateHandler("text"); handler.addParameter(component.getName()); SCursor cursor = (SCursor)component; try { StringBuilderDevice htmlDevice = new StringBuilderDevice(1024); CursorCG cg = (CursorCG)cursor.getCG(); CursorCG.writeInnerComponent(htmlDevice, cursor); htmlCode = htmlDevice.toString(); } catch(Throwable t) { exception = t.getClass().getName(); } handler.addParameter(htmlCode); if(exception != null) handler.addParameter(exception); return handler; } } @Override public Update getVisibilityUpdate(SComponent component, boolean newVisibility) { return new VisibilityUpdate(component, newVisibility); } protected final static class VisibilityUpdate extends AbstractUpdate { private boolean visibility; public VisibilityUpdate(SComponent component, boolean visibility) { super(component); this.visibility = visibility; } @Override public Handler getHandler() { UpdateHandler handler = new UpdateHandler("visibility"); handler.addParameter(component.getName()); if(visibility) { handler.addParameter("block"); handler.addParameter("visible"); } else { handler.addParameter("none"); handler.addParameter("hidden"); } return handler; } } private static class MyScriptListener implements ScriptListener { private final SComponent cursor; public MyScriptListener(SComponent cursor) { this.cursor = cursor; } @Override public String getScript() { StringBuilder builder = AbstractComponentCG.STRING_BUILDER.get(); builder.setLength(0); builder.append("wingS.cursor.setCursorElement('").append(cursor.getName()).append("');\n"); return builder.toString(); } @Override public String getEvent() { return null; } @Override public String getCode() { return null; } @Override public int getPriority() { return LOW_PRIORITY; } } }



© 2015 - 2024 Weber Informatics LLC | Privacy Policy