Package net.xoetrope.swt

Source Code of net.xoetrope.swt.XToolBar

package net.xoetrope.swt;

import net.xoetrope.xui.XAppender;
import net.xoetrope.xui.XAttributedComponent;
import net.xoetrope.xui.XProjectManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.CoolItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;

/**
* <p>
* Draws a toolbar
* </p>
* <p>
* Copyright (c) Xoetrope Ltd., 1998-2003
* </p>
* License: see license.txt $Revision: 2.18 $
*/
public class XToolBar extends ToolBar implements XAppender, XAttributedComponent
{

  private CoolItem ci;

  /**
   * Constructs a new toolbar for the shell
   */
  public XToolBar()
  {
    super( (Shell)XProjectManager.getCurrentProject().getObject( "ClientShell" ), SWT.FLAT );
  }

  /**
   * Constructs a new toolbar for a coolbar
   *
   * @param parent
   *          parent coolbar
   */
  public XToolBar( XCoolBar parent )
  {
    super( parent, SWT.FLAT );
    ci = new CoolItem( parent, SWT.NONE );
  }

  /**
   * Suppress the subclassing exception
   */
  protected void checkSubclass()
  {
  }

  /**
   * Set one or more attributes of the component.
   *
   * @param attribName
   *          the name of the attribute
   * @param attribValue
   *          the value of the attribute
   * @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( "tooltip" ) )
      setToolTipText( attribValueStr );
    else if ( attribNameLwr.equals( "bg" ) )
      setBackground( new Color( getDisplay(), Integer.parseInt( attribValueLwr.substring( 0, 2 ), 16 ), Integer.parseInt( attribValueLwr.substring(
          2, 4 ), 16 ), Integer.parseInt( attribValueLwr.substring( 4, 6 ), 16 ) ) );
    else if ( attribNameLwr.equals( "visible" ) )
      setVisible( attribValueLwr.equals( "true" ) || attribValueLwr.equals( "1" ) );
    else
      return -1;

    return 0;
  }

  /**
   * Set an Action for the toolbar - does nothing
   *
   * @param action
   *          the action object
   */
  public void setAction( Object action )
  {
  }

  /**
   * Do any final setup needed
   */
  public void setup()
  {
  }

  /**
   * Appends the object o to this item
   *
   * @param o
   *          the appended item
   * @param name
   *          the name of the toolbar
   */
  public void append( Object o, String name )
  {
  }

  /**
   * Adds a separator to this item.
   */
  public void addSeparator()
  {
    new ToolItem( this, SWT.SEPARATOR );
  }

  /**
   * Get a child object by name
   *
   * @param name
   *          the item name
   * @return the child item
   */
  public Object getObject( String name )
  {
    return null;
  }

  /**
   * Set the name of this object
   *
   * @param name
   *          the item name
   */
  public void setName( String name )
  {
  }

  /**
   * Set the display attributes
   */
  public void setDisplayAttributes()
  {
    if ( ci != null ) {
      ci.setControl( this );
      Point size = computeSize( SWT.DEFAULT, SWT.DEFAULT );
      setSize( size );
      size = ci.computeSize( size.x, size.y );
      ci.setSize( size );
    }
    else {
      int nb = getItemCount();
      int max = 35;
      for ( int i = 0; i < nb; i++ ) {
        int height = getItem( i ).getBounds().height;
        if ( height > max )
          max = height;
      }
      setBounds( 0, 0, ( (Shell)XProjectManager.getCurrentProject().getObject( "ClientShell" ) ).getSize().x, max );
    }
  }
}
TOP

Related Classes of net.xoetrope.swt.XToolBar

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.