HTMLBorderLayoutUI.java :  » Swing-Library » Swinglets » com » javelin » swinglets » plaf » html » Java Open Source

Java Open Source » Swing Library » Swinglets 
Swinglets » com » javelin » swinglets » plaf » html » HTMLBorderLayoutUI.java
/*
 * Copyright Javelin Software, All rights reserved.
 */
 
package com.javelin.swinglets.plaf.html;

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

import com.javelin.swinglets.*;
import com.javelin.swinglets.plaf.*;

/**
 * HTMLBorderLayoutUI defines a look and feel for default HTML. 
 * 
 * @author Robin Sharp
 */

public class HTMLBorderLayoutUI extends HTMLLayoutUI
{
   /** 
    * Lays out the container in the specified manner.
    */
    public void layoutContainer( SContainer parent, PrintWriter out )
    {
        if( parent.getComponentCount() == 0 ) return;
        
        SBorderLayout borderLayout = (SBorderLayout)parent.getLayoutManager();
        SComponent component = null;
        
        out.print( "<TABLE BORDER=0 CELLSPACING=" );
        out.print( borderLayout.getGap() );
        out.println( " CELLPADDING=0 >" );
        
        //NORTH
        if( borderLayout.getComponent( SBorderLayout.NORTH ) != null )
        {
            out.print( "<TR>" );
            out.print( "<TD COLSPAN=3 WIDTH=\"100%\"" );

            HTMLUtility.updateHorizontalAlignment( out, component, SConstants.CENTER );
            HTMLUtility.updateVerticalAlignment( out, component, SConstants.BOTTOM );

            paintCell( parent, borderLayout.getComponent( SBorderLayout.NORTH ), out );
            
            out.println( "</TR>" );
        }
        
        out.print( "<TR>" );
        
        //WEST
        if( borderLayout.getComponent( SBorderLayout.WEST ) != null )
        {
            out.print( "<TD" );
            
            HTMLUtility.updateHorizontalAlignment( out, component, SConstants.LEFT );

            paintCell( parent, borderLayout.getComponent( SBorderLayout.WEST ), out );
        }
            
        //CENTER
        if( borderLayout.getComponent( SBorderLayout.CENTER ) != null )
        {
            out.print( "<TD" );
            
            HTMLUtility.updateHorizontalAlignment( out, component, SConstants.CENTER );

            paintCell( parent, borderLayout.getComponent( SBorderLayout.CENTER ), out );
        }

        //EAST
        if( borderLayout.getComponent( SBorderLayout.EAST ) != null )
        {
            out.print( "<TD" );
            
            HTMLUtility.updateHorizontalAlignment( out, component, SConstants.RIGHT );
                
            paintCell( parent, borderLayout.getComponent( SBorderLayout.EAST ), out );
        }

        out.println( "</TR>" );

        //SOUTH
        if( borderLayout.getComponent( SBorderLayout.SOUTH ) != null )
        {
            out.print( "<TR>" );
            out.print( "<TD COLSPAN=3 WIDTH=\"100%\"" );

            HTMLUtility.updateHorizontalAlignment( out, component, SConstants.CENTER );
            HTMLUtility.updateVerticalAlignment( out, component, SConstants.TOP );

            paintCell( parent, borderLayout.getComponent( SBorderLayout.SOUTH ), out );
            out.println( "</TR>" );
        }

      
      out.print( "</TABLE>" );
    }
    
    protected void paintCell( SContainer parent, SComponent component, PrintWriter out )
    {
        
        if( !( component instanceof SIcon ) 
            && !component.isOpaque() )
        {
        }
        else
        if( !( component instanceof SIcon ) 
            && component.getBackground() != null )
        {
            out.print( " BGCOLOR=\"#" + SColor.toHexString( component.getBackground() ) + "\"" );
        }
        else
        if( !( component instanceof SIcon ) 
            && parent.getBackground() != null )
        {
            out.print( " BGCOLOR=\"#" + SColor.toHexString( parent.getBackground() ) + "\"" );
        }
        
        out.print( " >" );
        component.paint( out );
        out.print( "</TD>" );
    }
}

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.