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

org.wings.plaf.css.FrameCG 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.plaf.Update;
import org.wings.*;
import org.wings.style.CSSProperty;
import org.wings.sdnd.SDragAndDropManager;
import org.wings.event.SRequestEvent;
import org.wings.dnd.DragAndDropManager;
import org.wings.header.*;
import org.wings.io.Device;
import org.wings.plaf.CGManager;
import org.wings.plaf.css.script.*;
import org.wings.resource.ClassPathResource;
import org.wings.resource.ReloadResource;
import org.wings.resource.ResourceManager;
import org.wings.resource.UpdateResource;
import org.wings.resource.ResourceNotFoundException;
import org.wings.script.*;
import org.wings.session.*;

import javax.swing.*;

import java.io.IOException;
import java.util.*;
import java.awt.event.KeyEvent;
import java.awt.event.InputEvent;

/**
 * PLAF renderer for SFrames.
 * Does quite many abritriray things i.e. registering diverse service scripts, etc.
 */
public class FrameCG implements org.wings.plaf.FrameCG {

    private static final long serialVersionUID = 1L;

    private final static Logger log = LoggerFactory.getLogger(FrameCG.class);

    /**
     * The default DOCTYPE enforcing standard (non-quirks mode) in all current browsers. Please be aware, that
     * changing the DOCTYPE may change the way how browser renders the generate document i.e. esp. the CSS
     * attribute inheritance does not work correctly on table elements.
     * See i.e. http://www.ericmeyeroncss.com/bonus/render-mode.html
     */
    public final static String STRICT_DOCTYPE = "";
    
    /**
     * The HTML DOCTYPE setting all browsers to Quirks mode. We need this to force IE to use the correct box
     * rendering model. It's the only browser you cannot reconfigure via a CSS tag.
     */
    public final static String QUIRKS_DOCTYPE = "";

    // EmulateIE7 means 5 in quirks mode and 7 in standard mode .. this is what 7 actually did
    public final static String IE_COMPATIBILITY_MODE = "";

    /**
     * Lookup for a property Stylesheet.BROWSERNAME to know fitting stylesheets
     */
    private static final String PROPERTY_STYLESHEET = "Stylesheet.";
    private static final String BROWSER_DEFAULT = "default";

    private String documentType = STRICT_DOCTYPE;

    /**
     * Should the returned HTML page start with the <?xml version="1.0" encoding="...">.
     * This has effects which rendering mode the browsers will choose (quirks/strict)
     */
    private Boolean renderXmlDeclaration = Boolean.FALSE;
    
    protected final List
headers = new ArrayList<>(); protected final List\n"); } protected void writeHeadExtension(Device out, SFrame frame) throws IOException { // Hook for subclasses } protected void wirteBodyExtension(Device out, SFrame frame) throws IOException { // Hook for subclasses } private static void writeGlobalInitScript(Device out, SFrame frame) throws IOException { Map initConfig = new HashMap<>(); initConfig.put("eventEpoch", frame.getEventEpoch()); initConfig.put("reloadResource", frame.getDynamicResource(ReloadResource.class).getURL().toString()); initConfig.put("updateResource", frame.getDynamicResource(UpdateResource.class).getURL().toString()); initConfig.put("updateEnabled", frame.isUpdateEnabled()); initConfig.put("updateCursor", Utils.mapToJsObject(frame.getUpdateCursor())); initConfig.put("autoAdjustLayout", Utils.mapToJsObject(frame.getAutoAdjustLayout())); initConfig.put("cometEnabled", frame.getSession().getComet() != null && frame.getSession().getComet().isCometEnabled()); final String logLevel = SFrame.getLogLevel(); if (logLevel != null && !logLevel.isEmpty()) { initConfig.put("loglevel", logLevel); } out.print("wingS.global.init("); Utils.mapToJsObject(initConfig).write(out); out.print(");"); } private static void writeTooltipInitScript(Device out, SToolTipManager tooltipManager) throws IOException { out.print("wingS.tooltip.init("); out.print(tooltipManager.getInitialDelay()).print(","); out.print(tooltipManager.getDismissDelay()).print(","); out.print(tooltipManager.isFollowMouse()).print(");"); } public String getDocumentType() { return documentType; } public void setDocumentType(String documentType) { this.documentType = documentType; } /** * @return The current rendered DOCTYPE of this document. {@link #STRICT_DOCTYPE} */ public Boolean getRenderXmlDeclaration() { return renderXmlDeclaration; } /** * Sets should the returned HTML page start with the <?xml version="1.0" encoding="...">. * This has effects which rendering mode the browsers will choose (quirks/strict) * * @param renderXmlDeclaration should the returned HTML page start with the <?xml version="1.0" encoding="...">. */ public void setRenderXmlDeclaration(Boolean renderXmlDeclaration) { this.renderXmlDeclaration = renderXmlDeclaration; } @Override public Update getComponentUpdate(SComponent component) { return null; } @Override public Update getAddHeaderUpdate(SFrame frame, int index, Object header) { if (header instanceof Script) return new HeaderScriptUpdate(frame, true, (Script) header, index); else if (header instanceof Link) return new HeaderLinkUpdate(frame, true, (Link) header, index); else return null; } @Override public Update getAddHeaderUpdate(SFrame frame, Object header) { if (header instanceof Script) return new HeaderScriptUpdate(frame, true, (Script) header); else if (header instanceof Link) return new HeaderLinkUpdate(frame, true, (Link) header); else return null; } @Override public Update getRemoveHeaderUpdate(SFrame frame, Object header) { if (header instanceof Script) // Removing script headers asynchronously would indeed // detach the according header, however, the functions // contained in the according files are not unloaded. // If unloading functions is desired, it might be a good // idea to RETURN 'NULL' here. This would create a // component update of the frame which in turn would // force a complete page reload and function unloading. return new HeaderScriptUpdate(frame, false, (Script) header); else if (header instanceof Link) return new HeaderLinkUpdate(frame, false, (Link) header); else return null; } @Override public Update getEpochUpdate(SFrame frame, String epoch) { return new EpochUpdate(frame, epoch); } @Override public Update getFocusUpdate(SFrame frame, SComponent focus) { return new FocusUpdate(frame, focus); } @Override public Update getUpdateEnabledUpdate(SFrame frame, boolean enabled) { return new UpdateEnabledUpdate(frame, enabled); } @Override public Update getAddWindowUpdate(SContainer container, SWindow window) { return new AddWindowUpdate(container, window); } @Override public Update getRemoveWindowUpdate(SContainer container, SWindow window) { return new RemoveWindowUpdate(container, window); } protected static class HeaderScriptUpdate extends AbstractUpdate { private Boolean add; private Script script; private Integer index; public HeaderScriptUpdate(SFrame frame, boolean add, Script script) { super(frame); this.add = add; this.script = script; } public HeaderScriptUpdate(SFrame frame, boolean add, Script script, int index) { this(frame, add, script); this.index = index; } @Override public int getPriority() { return 5; } @Override public Handler getHandler() { UpdateHandler handler = new UpdateHandler("headerScript"); handler.addParameter(add); handler.addParameter(script.getURL().toString()); handler.addParameter(script.getType()); if (index != null) handler.addParameter(index); return handler; } public boolean equals(Object object) { if (this == object) return true; if (!super.equals(object)) return false; return script.equals(((HeaderScriptUpdate) object).script); } } protected static class HeaderLinkUpdate extends AbstractUpdate { private Boolean add; private Link link; private Integer index; public HeaderLinkUpdate(SFrame frame, boolean add, Link link) { super(frame); this.add = add; this.link = link; } public HeaderLinkUpdate(SFrame frame, boolean add, Link link, int index) { this(frame, add, link); this.index = index; } @Override public int getPriority() { return 5; } @Override public Handler getHandler() { UpdateHandler handler = new UpdateHandler("headerLink"); handler.addParameter(add); handler.addParameter(link.getURL().toString()); handler.addParameter(link.getType()); if (link.getRel() != null || link.getRev() != null || link.getTarget() != null || index != null) handler.addParameter(link.getRel()); if (link.getRev() != null || link.getTarget() != null || index != null) handler.addParameter(link.getRev()); if (link.getTarget() != null || index != null) handler.addParameter(link.getTarget()); if (index != null) handler.addParameter(index); return handler; } public boolean equals(Object object) { if (this == object) return true; if (!super.equals(object)) return false; return link.equals(((HeaderLinkUpdate) object).link); } } protected static class EpochUpdate extends AbstractUpdate { private String epoch; public EpochUpdate(SFrame frame, String epoch) { super(frame); this.epoch = epoch; } @Override public int getPriority() { return 0; } @Override public Handler getHandler() { UpdateHandler handler = new UpdateHandler("epoch"); handler.addParameter(epoch); return handler; } } protected static class FocusUpdate extends AbstractUpdate { private SComponent focus; public FocusUpdate(SFrame frame, SComponent focus) { super(frame); this.focus = focus; } @Override public int getPriority() { return 0; } @Override public Handler getHandler() { UpdateHandler handler = new UpdateHandler("focus"); handler.addParameter(focus.getName()); return handler; } } protected static class UpdateEnabledUpdate extends AbstractUpdate { private Boolean enabled; public UpdateEnabledUpdate(SFrame frame, boolean enabled) { super(frame); this.enabled = enabled; } @Override public Handler getHandler() { UpdateHandler handler = new UpdateHandler("updateEnabled"); handler.addParameter(enabled); return handler; } } protected static class AddWindowUpdate extends AbstractUpdate { private SWindow window; public AddWindowUpdate(SContainer container, SWindow window) { super(container); this.window = window; } @Override public int getPriority() { return Integer.MAX_VALUE; } @Override public Handler getHandler() { UpdateHandler handler = new UpdateHandler("addWindow"); handler.addParameter(component.getName()); handler.addParameter("
"); return handler; } @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final AddWindowUpdate other = (AddWindowUpdate) obj; return Objects.equals(window, window); } @Override public int hashCode() { int hash = 7; hash = 19 * hash + (this.window != null ? this.window.hashCode() : 0); return hash; } } protected static class RemoveWindowUpdate extends AbstractUpdate { private SWindow window; public RemoveWindowUpdate(final SContainer container, final SWindow window) { super(container); this.window = window; } @Override public Handler getHandler() { UpdateHandler handler = new UpdateHandler("removeWindow"); handler.addParameter(window.getName()); return handler; } @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final RemoveWindowUpdate other = (RemoveWindowUpdate) obj; return Objects.equals(window, window); } @Override public int hashCode() { int hash = 7; hash = 19 * hash + (this.window != null ? this.window.hashCode() : 0); return hash; } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy