package net.xoetrope.swt;
import java.io.IOException;
import java.io.InputStream;
import net.xoetrope.xui.XAttributedComponent;
import net.xoetrope.xui.XProjectManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.ExpandBar;
import org.eclipse.swt.widgets.ExpandItem;
/**
* <p>
* Draws an expanditem
* </p>
* <p>
* Copyright (c) Xoetrope Ltd., 1998-2003
* </p>
* License: see license.txt $Revision: 2.18 $ Notice : You must put a layout in
* parameter
*/
public class XExpandItem extends Composite implements XAttributedComponent
{
private ExpandItem item;
/**
* Create a new expanditem
*
* @param parent
* parent object
*/
public XExpandItem( Object parent )
{
super( (ExpandBar)parent, SWT.NONE );
item = new ExpandItem( (ExpandBar)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( "content" ) )
item.setText( attribValueStr );
else if ( attribNameLwr.equals( "tooltip" ) )
setToolTipText( attribValueStr );
else if ( attribNameLwr.equals( "image" ) ) {
try {
InputStream url = XProjectManager.getCurrentProject().getUrl( attribValueStr ).openStream();
Image im = new Image( getDisplay(), url );
if ( im != null )
item.setImage( im );
}
catch ( IOException e ) {
e.printStackTrace();
}
}
else if ( attribNameLwr.equals( "visible" ) )
setVisible( attribValueLwr.equals( "true" ) || attribValueLwr.equals( "1" ) );
else
return -1;
return 0;
}
/**
* Set the display attributes
*/
public void setDisplayAttributes()
{
item.setHeight( computeSize( SWT.DEFAULT, SWT.DEFAULT ).y );
item.setControl( this );
}
}