Package net.xoetrope.swing

Source Code of net.xoetrope.swing.XScrollPane

package net.xoetrope.swing;

import java.awt.Component;
import javax.swing.JScrollPane;
import javax.swing.border.EmptyBorder;
import net.xoetrope.xui.XAttributedComponent;
import net.xoetrope.xui.XProjectManager;
import net.xoetrope.xui.style.XStyle;

/**
* <p>Wraps ScrollPane</p>
* <p>Copyright (c) Xoetrope Ltd., 1998-2004<br>
* License:      see license.txt
* $Revision: 2.7 $
*/
public class XScrollPane extends JScrollPane implements XAttributedComponent
{
  private static int nextHorzScrollPanePolicy = JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED;
  private static int nextVertScrollPanePolicy = JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED;
 
  /**
   * Set the scrollbar policy for the next horizontal scroll pane that is created.
   * Once used this value reverts to the default value of JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED
   * @param scrollBarPolicy the policy for the next scrollbar
   */
  public static void setNextHorzScrollPanePolicy( int scrollBarPolicy )
  {
    nextHorzScrollPanePolicy = scrollBarPolicy;
  }

  /**
   * Set the scrollbar policy for the next vertical scroll pane that is created.
   * Once used this value reverts to the default value of JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED
   * @param scrollBarPolicy the policy for the next scrollbar
   */
  public static void setNextVertScrollPanePolicy( int scrollBarPolicy )
  {
    nextVertScrollPanePolicy = scrollBarPolicy;
  }

  /**
   * Set the scrollbar policy for the next scroll pane that is created. Both the
   * vertical and horizonatl values are set.
   * Once used this value reverts to the default value of SCROLLBARS_AS_NEEDED
   * @param scrollBarPolicy the policy for the next scrollbar
   */
  public static void setNextScrollPanePolicy( int scrollBarPolicy )
  {
    nextVertScrollPanePolicy = nextHorzScrollPanePolicy = scrollBarPolicy;
  }

  /**
   * Creates a new scroll pane
   */
  public XScrollPane()
  {
    super( nextVertScrollPanePolicy, nextHorzScrollPanePolicy );
    nextVertScrollPanePolicy = JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED;
    nextHorzScrollPanePolicy = JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED;
  }

  /**
   * Adds a new componnet and then lays out the container
   * @param c a component to add to this pane
   * @return the newly added component
   */
  public Component add( Component c )
  {
    setViewportView( c );
    layout();

    return c;
  }

  /**
   * Set one or more attributes of the component.
   * <LI>horizontal_scrollbar, values=as needed|always|never</LI>
   * <LI>vertical_scrollbar, values=as needed|always|never</LI>
   * @param attribName the attribute name
   * @param attribValue the attribute value
   * @return 0 for success, non zero for failure or to require some further action
   */
  public int setAttribute( String attribName, Object attribValue )
  {
    String attribNameLwr = attribName.toLowerCase();
    String attribValueStr = (String)attribValue;
    String attribValueLwr = null;
    if ( attribValue != null )
      attribValueLwr = attribValueStr.toLowerCase();
   
    if ( attribNameLwr.equals( "vertical_scrollbar" )|| attribNameLwr.equals( "verticalscrollbarpolicy" )) {
      setVerticalScrollBarPolicy( attribValueLwr.equals( "as needed" ) ? JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED :
                                  attribValueLwr.equals( "always" ) ?
                                  JScrollPane.VERTICAL_SCROLLBAR_ALWAYS : JScrollPane.VERTICAL_SCROLLBAR_NEVER );
    }
    else if ( attribNameLwr.equals( "horizontal_scrollbar" ) || attribNameLwr.equals( "horizontalscrollbarpolicy" )) {
      setHorizontalScrollBarPolicy( attribValueLwr.equals( "as needed" ) ?
                                    JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED :
                                    attribValueLwr.equals( "always" ) ?
                                    JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS : JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
    }
    else if ( attribNameLwr.equals( "style" )) {
      XStyle style = XProjectManager.getStyleManager().getStyle( (String)attribValue );
      getViewport().setBackground( style.getStyleAsColor( XStyle.COLOR_BACK ) );     
    }
    else if ( attribNameLwr.equals( "opaque" )) {
      setOpaque( attribValue.equals("true"));
      getViewport().setOpaque( attribValue.equals( "true" ));
      this.setBorder( new EmptyBorder( 0, 0, 0, 0 ));
    }
    else if ( attribNameLwr.equals( "border" )) {
      if ( "0".equals( attribValueLwr ))
        setBorder( new EmptyBorder( 0, 0, 0, 0 ));
    }
    else
      return -1;

    return 0;
  }
}
TOP

Related Classes of net.xoetrope.swing.XScrollPane

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.