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

org.wings.plaf.css.InternalFrameCG 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.event.SInternalFrameEvent;
import org.wings.io.Device;
import org.wings.plaf.Update;
import org.wings.resource.ResourceManager;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class InternalFrameCG extends AbstractComponentCG implements
        org.wings.plaf.InternalFrameCG {
    private static final long serialVersionUID = 1L;
    private final static Logger log = LoggerFactory.getLogger(InternalFrameCG.class);
    protected static final String WINDOWICON_CLASSNAME = "WindowIcon";
    protected static final String BUTTONICON_CLASSNAME = "WindowButton";
    private SIcon closeIcon;
    private SIcon deiconifyIcon;
    private SIcon iconifyIcon;
    private SIcon maximizeIcon;
    private SIcon unmaximizeIcon;

    /**
     * Initialize properties from config
     */
    public InternalFrameCG() {
        this.closeIcon = (SIcon) ResourceManager.getObject("InternalFrameCG.closeIcon", SIcon.class);
        this.deiconifyIcon = (SIcon) ResourceManager.getObject("InternalFrameCG.deiconifyIcon", SIcon.class);
        this.iconifyIcon = (SIcon) ResourceManager.getObject("InternalFrameCG.iconifyIcon", SIcon.class);
        this.maximizeIcon = (SIcon) ResourceManager.getObject("InternalFrameCG.maximizeIcon", SIcon.class);
        this.unmaximizeIcon = (SIcon) ResourceManager.getObject("InternalFrameCG.unmaximizeIcon", SIcon.class);
    }

    protected static void writeIcon(Device device, SIcon icon, String cssClass) throws IOException {
        device.print("");
    }

    protected static void writeWindowIcon(Device device, SInternalFrame frame,
                                          int event, SIcon icon, String cssClass) throws IOException {
        Utils.printButtonStart(device, frame, Integer.toString(event), true, frame.getShowAsFormComponent(), cssClass);
        device.print(">");
        writeIcon(device, icon, null);
        Utils.printButtonEnd(device, true);
    }

    protected static void writeWindowIcon(Device device, SInternalFrame frame,
                                          int event, SIcon icon) throws IOException {
        writeWindowIcon(device, frame, event, icon, null);
    }


    @Override
    public void writeInternal(final Device device, final SComponent _c)
            throws IOException {

        SInternalFrame frame = (SInternalFrame)_c;

        // Optional attribute to identify the internal frame for
        // SDialog and SOptionPane usage.
        Map optionalAttributes = new HashMap();
        optionalAttributes.put("SComponentClass", "org.wings.SInternalFrame");

        writeDivPrefix(device, frame, optionalAttributes);
        writeWindowBar(device, frame);
        // write the actual content
        if (!frame.isIconified()) {
            String style = frame.getStyle(SInternalFrame.SELECTOR_CONTENT);
            if (style != null)
                device.print("
"); Utils.renderContainer(device, frame); device.print("
"); } writeDivSuffix(device, frame); } /** * Convenience method to keep differences between default and msie * implementations small * @param device * @param frame * @throws IOException */ protected void writeWindowBar(final Device device, SInternalFrame frame) throws IOException { String text = frame.getTitle(); if (text == null) text = "wingS"; String style = frame.getStyle(SInternalFrame.SELECTOR_TITLE); if (style != null) device.print("
"); if (frame.isClosable() && closeIcon != null) { writeWindowIcon(device, frame, SInternalFrameEvent.INTERNAL_FRAME_CLOSED, closeIcon, BUTTONICON_CLASSNAME); } if (frame.isMaximized() && unmaximizeIcon != null) { writeWindowIcon(device, frame, SInternalFrameEvent.INTERNAL_FRAME_UNMAXIMIZED, unmaximizeIcon, BUTTONICON_CLASSNAME); } if (frame.isMaximizable() && !frame.isMaximized() && maximizeIcon != null) { writeWindowIcon(device, frame, SInternalFrameEvent.INTERNAL_FRAME_MAXIMIZED, maximizeIcon, BUTTONICON_CLASSNAME); } if (frame.isIconified() && deiconifyIcon != null) { writeWindowIcon(device, frame, SInternalFrameEvent.INTERNAL_FRAME_DEICONIFIED, deiconifyIcon, BUTTONICON_CLASSNAME); } if (frame.isIconifyable() && !frame.isIconified() && iconifyIcon != null) { writeWindowIcon(device, frame, SInternalFrameEvent.INTERNAL_FRAME_ICONIFIED, iconifyIcon, BUTTONICON_CLASSNAME); } device.print("
"); // float right end if (frame.getIcon() != null) { writeIcon(device, frame.getIcon(), WINDOWICON_CLASSNAME); } device.print(text); device.print("
"); device.print("
"); } @Override protected String getDragHandle(SComponent component) { return component.getName() + "_titlebar"; } public SIcon getCloseIcon() { return closeIcon; } public void setCloseIcon(SIcon closeIcon) { this.closeIcon = closeIcon; } public SIcon getDeiconifyIcon() { return deiconifyIcon; } public void setDeiconifyIcon(SIcon deiconifyIcon) { this.deiconifyIcon = deiconifyIcon; } public SIcon getIconifyIcon() { return iconifyIcon; } public void setIconifyIcon(SIcon iconifyIcon) { this.iconifyIcon = iconifyIcon; } public SIcon getMaximizeIcon() { return maximizeIcon; } public void setMaximizeIcon(SIcon maximizeIcon) { this.maximizeIcon = maximizeIcon; } public SIcon getUnmaximizeIcon() { return unmaximizeIcon; } public void setUnmaximizeIcon(SIcon unmaximizeIcon) { this.unmaximizeIcon = unmaximizeIcon; } /** * {@inheritDoc} */ @Override public Update getAddWindowUpdate(SContainer container, SWindow window) { return new AddWindowUpdate(container, window); } 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 Update getRemoveWindowUpdate(final SContainer container, final SWindow window) { return new RemoveWindowUpdate(container, window); } 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; } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy