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

org.wings.plaf.css.FlowLayoutCG 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.wings.SComponent;
import org.wings.SConstants;
import org.wings.SFlowLayout;
import org.wings.SLayoutManager;
import org.wings.io.Device;

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

public class FlowLayoutCG extends AbstractLayoutCG {
    private static final long serialVersionUID = 1L;

    /**
     * @param d the device to write the code to
     * @param l the layout manager
     * @throws IOException
     */
    @Override
    public void write(Device d, SLayoutManager l) throws IOException {
        final SFlowLayout layout = (SFlowLayout) l;
        final Insets insets = convertGapsToInset(layout.getHgap(), layout.getVgap());
        final List components = layout.getComponents();
        final int alignment = layout.getAlignment();

        openLayouterBody(d, layout);
        d.print("");

        final String alignmentStyle;
        if (alignment == SConstants.LEFT) {
            alignmentStyle = "float:left;";
        } else if (alignment == SConstants.RIGHT) {
            alignmentStyle = "float:right;";
        } else if (alignment == SConstants.CENTER) {
            alignmentStyle = "float:left; "; // Floating does not work with center :-(
        } else {
            alignmentStyle = "";
        }
        
        if ( alignment == SConstants.CENTER ) {
            d.print("
"); } if (components.size() > 1) { /* We need two spacer divs (end/beginning) so that the sourrounding flow layout takes up the whole space instead of 0px heigth. See http://www.alistapart.com/articles/practicalcss/. The nbsp's are only needed for firefox... */ d.print("
"); for (Object component : components) { printComponent(d, (SComponent) component, alignmentStyle, insets); } /* Second spacer. See upper. */ d.print("
"); } else if (components.size() == 1) { // Special handling of trivial case // // Why: FlowLayout may be default for many containers. // BUT: The effect is that in MSIE oversized, floating componentns DO NOT lead to a scrollbar // // Try this: //
//
//
//
// //
1000px widht
//
//
//
//
printComponent( d, (SComponent)components.get(0), "", insets ); } if ( alignment == SConstants.CENTER ) { d.print( "
" ); } d.print(""); closeLayouterBody(d, layout); } private static void printComponent(Device d, SComponent component, String alignmentStlye, Insets insets) throws IOException { if (component.isVisible()) { Utils.printNewline(d, component); d.print(""); component.write(d); // Render contained component Utils.printNewline(d, component); d.print("
"); } } @Override protected int getLayoutHGap(SLayoutManager layout) { SFlowLayout flowLayout = (SFlowLayout) layout; return flowLayout.getHgap(); } @Override protected int getLayoutVGap(SLayoutManager layout) { SFlowLayout flowLayout = (SFlowLayout) layout; return flowLayout.getVgap(); } @Override protected int getLayoutBorder(SLayoutManager layout) { SFlowLayout flowLayout = (SFlowLayout) layout; return flowLayout.getBorder(); } @Override protected int layoutOversize(SLayoutManager layout) { return 0; } @Override public int getDefaultLayoutCellHAlignment() { return SConstants.NO_ALIGN; // Don't knoff. } @Override public int getDefaultLayoutCellVAlignment() { return SConstants.NO_ALIGN; // Don't knoff. } }



© 2015 - 2024 Weber Informatics LLC | Privacy Policy