Java Code Examples for org.eclipse.draw2d.IFigure#getClientArea()

The following examples show how to use org.eclipse.draw2d.IFigure#getClientArea() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WrappableToolbarLayout.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
public void layout(IFigure container) {
	Rectangle clientArea = container.getClientArea();
	int w = 0;
	int h = 0;
	int maxH = 0;
	for (Object child : container.getChildren()) {
		IFigure figure = (IFigure) child;
		Dimension preferSize = figure.getPreferredSize();
		if (w + preferSize.width < clientArea.width) {
			figure.setBounds(
					new Rectangle(clientArea.x + w, clientArea.y + h, preferSize.width, preferSize.height));
			w += preferSize.width;
			if (maxH < preferSize.height) {
				maxH = preferSize.height;
			}
		} else {
			h += maxH;
			w = 0;
			figure.setBounds(
					new Rectangle(clientArea.x + w, clientArea.y + h, preferSize.width, preferSize.height));
			w = preferSize.width;
			maxH = preferSize.height;
		}
	}

}
 
Example 2
Source File: FirstCellLayout.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public void layout( IFigure container )
{
	List list = container.getChildren( );
	Rectangle rect = container.getClientArea( );
	Rectangle contraint = getChildContraint( container );
	
	
	for (int i=0; i<list.size( ); i++)
	{
		Figure child = (Figure)list.get( i );
		if (constraints.get( child ) == null)
		{
			child.setBounds( new Rectangle(rect.x, rect.y, rect.width-contraint.width, rect.height ));
		}
		else
		{
			child.setBounds( new Rectangle(rect.x+rect.width-contraint.width, rect.y, contraint.width, rect.height ));
		}
	}
}
 
Example 3
Source File: EditorRulerLayout.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see org.eclipse.draw2d.LayoutManager#layout(org.eclipse.draw2d.IFigure)
 */
public void layout( IFigure container )
{
	List children = container.getChildren( );
	Rectangle rulerSize = container.getClientArea( );
	for ( int i = 0; i < children.size( ); i++ )
	{
		IFigure child = (IFigure) children.get( i );
		Dimension childSize = child.getPreferredSize( );
		int position = ( (Integer) getConstraint( child ) ).intValue( );
		if ( ( (EditorRulerFigure) container ).isHorizontal( ) )
		{
			childSize.height = rulerSize.height - 1;
			Rectangle.SINGLETON.setLocation( position
					- ( childSize.width / 2 ), rulerSize.y );
		}
		else
		{
			childSize.width = rulerSize.width - 1;
			Rectangle.SINGLETON.setLocation( rulerSize.x, position
					- ( childSize.height / 2 ) );
		}
		Rectangle.SINGLETON.setSize( childSize );
		child.setBounds( Rectangle.SINGLETON );
	}
}
 
Example 4
Source File: MultipleLayout.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public void layout( IFigure container )
{
	List list = container.getChildren( );
	for ( int i = 0; i < list.size( ); i++ )
	{
		Figure child = (Figure)list.get( i );
		Dimension dim = child.getPreferredSize();
		Rectangle bounds = new Rectangle(container.getClientArea( ).x ,container.getClientArea( ).y,dim.width, dim.height);
		if (!child.getBounds( ).equals( bounds ))
		{
			child.setBounds( bounds );
			//container.getBounds( ).width = bounds.width;
		}
	}
	
}
 
Example 5
Source File: TankFigure.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public void layout(IFigure container) {
	Rectangle area = container.getClientArea();		
	area.height-=1;
	Dimension scaleSize = new Dimension(0, 0);
	Dimension markerSize = new Dimension(0, 0);
	
	if(scale != null) {
		if(scale.isVisible()){
			scaleSize = scale.getPreferredSize(-1, area.height);
			scale.setBounds(new Rectangle(area.x, area.y, 
				scaleSize.width, scaleSize.height));	
		}else{
			scaleSize = scale.getPreferredSize(-1, area.height+2*scale.getMargin());
			scale.setBounds(new Rectangle(area.x, area.y-scale.getMargin(), 
					scaleSize.width, scaleSize.height));
			scaleSize.height=0;
			scaleSize.width=0;
		}
						
	}
	
	if(marker != null && marker.isVisible()) {
		markerSize = marker.getPreferredSize();
		marker.setBounds(new Rectangle(area.x + area.width - markerSize.width,
				marker.getScale().getBounds().y, markerSize.width, markerSize.height));			
	}
	
	if(tank != null) {
		tank.setBounds(new Rectangle(
				area.x + scaleSize.width,
				scale.getValuePosition(scale.getRange().getUpper(), false),
				area.width - scaleSize.width - markerSize.width,
				scale.getTickLength()+ tank.getLineWidth()));
	}	
}
 
Example 6
Source File: ListLayout.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected void setBoundsOfChild( IFigure parent, IFigure child,
		Rectangle bounds )
{
	parent.getClientArea( Rectangle.SINGLETON );
	bounds.translate( Rectangle.SINGLETON.x, Rectangle.SINGLETON.y );

	if ( !bounds.equals( child.getBounds( ) ) )
	{
		child.setBounds( bounds );
	}
}
 
Example 7
Source File: ListBandLayout.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected void setBoundsOfChild( IFigure parent, IFigure child,
		Rectangle bounds )
{
	parent.getClientArea( Rectangle.SINGLETON );
	bounds.translate( Rectangle.SINGLETON.x, Rectangle.SINGLETON.y );

	if ( !bounds.equals( child.getBounds( ) ) )
	{
		child.setBounds( bounds );
	}
}
 
Example 8
Source File: TableLayout.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected void setBoundsOfChild( IFigure parent, IFigure child,
		Rectangle bounds )
{
	parent.getClientArea( Rectangle.SINGLETON );
	bounds.translate( Rectangle.SINGLETON.x, Rectangle.SINGLETON.y );

	// comment out to force invalidation.
	// if ( !bounds.equals( child.getBounds( ) ) )
	{
		child.setBounds( bounds );
		if ( child.getLayoutManager( ) != null )
			child.getLayoutManager( ).invalidate( );
		child.revalidate( );
	}
}
 
Example 9
Source File: ComponentMeterFigure.java    From arx with Apache License 2.0 5 votes vote down vote up
@Override
protected Dimension calculatePreferredSize(IFigure container, int w,
        int h) {
    Insets insets = container.getInsets();
    Dimension d = new Dimension(container.getClientArea().width, container.getClientArea().height);
    d.expand(insets.getWidth(), insets.getHeight());
    return d;
}
 
Example 10
Source File: GaugeFigure.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public void layout(IFigure container) {
	Rectangle area = container.getClientArea();
	
	area.width = Math.min(area.width, area.height);
	area.height = area.width;
	area.shrink(BORDER_WIDTH, BORDER_WIDTH);
	
	Point center = area.getCenter();			
	
	if(scale != null) {				
		scale.setBounds(area);
	}
	
	if(ramp != null && ramp.isVisible()) {
		Rectangle rampBounds = area.getCopy();
		ramp.setBounds(rampBounds.shrink(area.width/4, area.height/4));
	}
	

	
	if(valueLabel != null) {
		Dimension labelSize = valueLabel.getPreferredSize();
		valueLabel.setBounds(new Rectangle(area.x + area.width/2 - labelSize.width/2,
				(int)(area.y + area.height * 6.3f/8 - labelSize.height/2),
				labelSize.width, labelSize.height));
	}
	
	if(title != null) {
		Dimension titleSize = titleLabel.getPreferredSize();
		titleLabel.setBounds(new Rectangle(area.x + area.width/2 - titleSize.width/2,
				(int)(area.y + area.height * 7.1f/8 - titleSize.height/2),
				titleSize.width, titleSize.height));
	}
	
	if(unit != null) {
		Dimension unitSize = unitLabel.getPreferredSize();
		unitLabel.setBounds(new Rectangle(area.x + area.width/2 - unitSize.width/2,
				(int)(area.y + area.height * 5.5f/8 - unitSize.height/2),
				unitSize.width, unitSize.height));
	}
	
	if(needle != null && scale != null) {
		needlePoints.setPoint (
				new Point(center.x, center.y - NeedleCenter.DIAMETER/2 + 3), 0);
		scale.getScaleTickMarks();
		needlePoints.setPoint(
				new Point(center.x + area.width/2 - RoundScaleTickMarks.MAJOR_TICK_LENGTH
				- GAP_BTW_NEEDLE_SCALE, center.y), 1);
		needlePoints.setPoint(
				new Point(center.x, center.y + NeedleCenter.DIAMETER/2 - 3), 2);
	
		double valuePosition = 360 - scale.getValuePosition(getCoercedValue(), false);
		if(maximum > minimum){
			if(value > maximum)
				valuePosition += 10;
			else if(value < minimum)
				valuePosition -=10;
		}else{
			if(value > minimum)
				valuePosition -= 10;
			else if(value < maximum)
				valuePosition +=10;
		}
		needlePoints.setPoint(
				PointsUtil.rotate(needlePoints.getPoint(0),	valuePosition, center), 0);
		needlePoints.setPoint(
				PointsUtil.rotate(needlePoints.getPoint(1), valuePosition, center), 1);
		needlePoints.setPoint(
				PointsUtil.rotate(needlePoints.getPoint(2), valuePosition, center),2);				
		needle.setPoints(needlePoints);			
		
	}
	
	if(needleCenter != null){
		needleCenter.setBounds(new Rectangle(center.x - NeedleCenter.DIAMETER/2,
				center.y - NeedleCenter.DIAMETER/2,
				NeedleCenter.DIAMETER, NeedleCenter.DIAMETER));
	}		
				
}
 
Example 11
Source File: ThermometerFigure.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public void layout(IFigure container) {
	Rectangle area = container.getClientArea();		
	if(bulb != null && bulb.isVisible()) {
		int diameter = area.width/2;
		if(diameter > Bulb.MAX_DIAMETER)
			diameter = Bulb.MAX_DIAMETER;
		int x = area.x + area.width/2 - diameter /2;
		int spareHeight = (area.height < diameter)? 0: (area.height - diameter);
		int y = area.y + spareHeight;			
		bulb.setBounds(new Rectangle(x, y, diameter, diameter));
		area.height = spareHeight + scale.getMargin();			
	}
	Dimension unitSize = new Dimension(0, 0);
	Dimension scaleSize;
	Dimension markerSize;
	Dimension pipeSize;
	if(unit != null && unit.isVisible()) {
		unitSize = unit.getPreferredSize();			
		unit.setBounds(new Rectangle(
				area.x + area.width/2 - Pipe.PIPE_WIDTH/2 - unitSize.width,
				area.y, unitSize.width, unitSize.height));
	}
	
	if(scale != null) {
		scaleSize = scale.getPreferredSize(-1, area.height-unitSize.height);
		scale.setBounds(new Rectangle(area.x + area.width/2 - Pipe.PIPE_WIDTH/2 - scaleSize.width,
				area.y+unitSize.height, 
				scaleSize.width, scaleSize.height));					
	}
	
	if(marker != null && marker.isVisible()) {
		markerSize = marker.getPreferredSize();
		marker.setBounds(new Rectangle(area.x + area.width/2 + Pipe.PIPE_WIDTH/2,
				marker.getScale().getBounds().y, markerSize.width, markerSize.height));			
	}
	
	
	
	if(pipe != null) {
		pipeSize = pipe.getPreferredSize(-1, scale.getTickLength());
		pipe.setBounds(new Rectangle(
				area.x + area.width/2 -  Pipe.PIPE_WIDTH/2,
				scale.getValuePosition(scale.getRange().getUpper(), false) - pipe.getCorner().height,
				pipeSize.width,
				pipeSize.height));
	}	
}
 
Example 12
Source File: KnobFigure.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public void layout(IFigure container) {
	Rectangle area = container.getClientArea();			
	area.width = Math.min(area.width, area.height);
	area.height = area.width;
	area.shrink(BORDER_WIDTH, BORDER_WIDTH);
	
	Point center = area.getCenter();			
	Rectangle bulbBounds = null;
	
	if(scale != null) {				
		scale.setBounds(area);
		bulbBounds = area.getCopy();
		bulbBounds.shrink(area.width/2 - scale.getInnerRadius() + GAP_BTW_BULB_SCALE, 
				area.height/2 - scale.getInnerRadius() + GAP_BTW_BULB_SCALE);
	}
	
	if(scale != null && ramp != null && ramp.isVisible()) {
		Rectangle rampBounds = area.getCopy();
		ramp.setBounds(rampBounds.shrink(area.width/2 - scale.getInnerRadius() - ramp.getRampWidth()+2,
				area.height/2 - scale.getInnerRadius() - ramp.getRampWidth()+2));
	}
	
	if(valueLabel != null && valueLabel.isVisible()) {
		Dimension labelSize = valueLabel.getPreferredSize();				
		valueLabel.setBounds(new Rectangle(bulbBounds.x + bulbBounds.width/2 - labelSize.width/2,
				bulbBounds.y + bulbBounds.height * 3/4 - labelSize.height/2,
				labelSize.width, labelSize.height));
	}
	
	if(bulb != null && scale != null && bulb.isVisible()) {				
		bulb.setBounds(bulbBounds);				
	}
	
	if(scale != null && thumb != null && thumb.isVisible()){
		Point thumbCenter = new Point(bulbBounds.x + bulbBounds.width*7.0/8.0, 
				bulbBounds.y + bulbBounds.height/2);
		double valuePosition = 360 - scale.getValuePosition(getCoercedValue(), false);				
		thumbCenter = PointsUtil.rotate(thumbCenter,	valuePosition, center);
		int thumbDiameter = bulbBounds.width/6;
		
		thumb.setBounds(new Rectangle(thumbCenter.x - thumbDiameter/2,
				thumbCenter.y - thumbDiameter/2,
				thumbDiameter, thumbDiameter));
	}						
}
 
Example 13
Source File: ReportFlowLayout.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void layout( IFigure parent, WorkingData data )
{
	Iterator iterator = parent.getChildren( ).iterator( );
	int dx;
	int i = 0;
	int display = ReportItemConstraint.BLOCK;
	int lastDisplay = ReportItemConstraint.BLOCK;

	int wHint = parent.getClientArea( ).width;
	int hHint = -1;
	
	while ( iterator.hasNext( ) )
	{
		IFigure f = (IFigure) iterator.next( );

		Insets fmargin = getFigureMargin( f );

		// fix bugzilla 156157
		// always pass hint here, let child process inline/block cases. this
		// is to resovle percentage custom size
		wHint = parent.getClientArea( ).width;

		if ( wHint != -1 )
		{
			wHint = Math.max( 0, wHint - fmargin.getWidth( ) );
		}

		Dimension pref = getChildSize( f, wHint, hHint );

		// Hack to allow in-line label wrap.
		if ( f instanceof LabelFigure
				&& ( pref.width + fmargin.getWidth( ) ) > parent.getClientArea( ).width )
		{
			pref = getChildSize( f,
					Math.max( 0, parent.getClientArea( ).width
							- fmargin.getWidth( ) ),
					hHint );
		}

		Rectangle r = new Rectangle( 0,
				0,
				pref.width + fmargin.getWidth( ),
				pref.height + fmargin.getHeight( ) );

		display = getDisplay( f );

		if ( data.rowCount > data.rowPos )
		{
			if ( ( data.rowWidth + r.width > data.maxWidth )
					|| display == ReportItemConstraint.BLOCK
					|| lastDisplay == ReportItemConstraint.BLOCK )
				layoutRow( parent );
		}
		lastDisplay = display;

		r.x = data.rowX;
		r.y = data.rowY;
		dx = r.width + getMinorSpacing( );
		data.rowX += dx;
		data.rowWidth += dx;
		data.rowHeight = Math.max( data.rowHeight, r.height );
		data.row[data.rowCount] = f;
		data.margin[data.rowCount] = fmargin;
		data.bounds[data.rowCount] = r;
		data.rowCount++;
		i++;
	}
	if ( data.rowCount > data.rowPos )
	{
		layoutRow( parent );
	}
	layoutVertical( parent );
}
 
Example 14
Source File: ReportFlowLayout.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void layout( IFigure parent, WorkingData data )
{
	Iterator iterator = parent.getChildren( ).iterator( );
	int dx;
	int i = 0;

	int display = ReportItemConstraint.BLOCK;
	int lastDisplay = ReportItemConstraint.BLOCK;
	int hHint = -1;
	
	while ( iterator.hasNext( ) )
	{
		int wHint = parent.getClientArea( ).width;
		IFigure f = (IFigure) iterator.next( );

		Insets fmargin = getFigureMargin( f );

		if ( wHint != -1 )
		{
			wHint = Math.max( 0, wHint - fmargin.getWidth( ) );
		}

		Dimension pref = getChildSize( f, wHint, hHint );
		display = getDisplay( f );
		if (display == ReportItemConstraint.INLINE && f instanceof LabelFigure && lastDisplay == ReportItemConstraint.INLINE)
		{
			pref = getChildSize( f,  wHint - data.rowWidth  <=0 ? -1:wHint - data.rowWidth , hHint );
			if (pref.width ==  wHint - data.rowWidth)
			{
				pref = getChildSize( f,  -1, hHint );
			}
		}
		else if (display == ReportItemConstraint.INLINE)
			
		{
			pref = getChildSize( f,  -1, hHint );
		}
		
		Rectangle r = new Rectangle( 0,
				0,
				pref.width + fmargin.getWidth( ),
				pref.height + fmargin.getHeight( ) );

		if ( data.rowCount > data.rowPos )
		{
			if ( ( data.rowWidth + r.width > data.maxWidth ) 
					|| display == ReportItemConstraint.BLOCK 
						|| lastDisplay == ReportItemConstraint.BLOCK)
				layoutRow( parent );
		}
		lastDisplay = display;
		r.x = data.rowX;
		r.y = data.rowY;
		dx = r.width + getMinorSpacing( );
		data.rowX += dx;
		data.rowWidth += dx;
		data.rowHeight = Math.max( data.rowHeight, r.height );
		data.row[data.rowCount] = f;
		data.margin[data.rowCount] = fmargin;
		data.bounds[data.rowCount] = r;
		data.rowCount++;
		i++;
	}
	if ( data.rowCount > data.rowPos )
	{
		layoutRow( parent );
	}
	layoutVertical( parent );
}
 
Example 15
Source File: GridLayout.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Applies a rectangle-based layout to the container.
 */
@Override
public void layout(IFigure container) {

	// Get the maximum bounding box we can use for layout out sub-figures.
	Rectangle limit = container.getClientArea();

	// Compute the maximum width/height of each cell. We'll make everything
	// square.
	int maxWidth = (limit.width - (columns - 1) * horizontalSpacing)
			/ columns;
	int maxHeight = (limit.height - (rows - 1) * verticalSpacing) / rows;

	// Get the size and any vertical/horizontal padding necessary.
	int size, paddingX = 0, paddingY = 0;
	if (maxWidth > maxHeight) { // Height-restricted.
		size = maxHeight;
		paddingX = (limit.width - size * columns
				- horizontalSpacing * (columns - 1)) / 2;
	} else { // Width-restricted.
		size = maxWidth;
		paddingY = (limit.height - size * rows
				- verticalSpacing * (rows - 1)) / 2;
	}

	int i, row, column, x, y, w, h;

	// Loop over the IFigures in the container with this layout.
	for (Object childObject : container.getChildren()) {
		IFigure child = (IFigure) childObject;

		// Get the constraints (and the x, y, w, h offsets from it).
		GridData constraint = getConstraint(child);
		Rectangle offsets = constraint.getOffsets();

		// Get the index and compute the row and column for the index.
		i = constraint.getIndex();
		row = i / columns;
		column = i % columns;

		// Compute the bounds of the cell in the row, column position.
		x = paddingX + column * (size + horizontalSpacing) + offsets.x;
		y = paddingY + row * (size + verticalSpacing) + offsets.y;
		w = size + offsets.width;
		h = size + offsets.height;

		// Set the bounds for the child IFigure.
		child.setBounds(new Rectangle(x, y, w, h));
	}

	return;
}
 
Example 16
Source File: ReportFlowLayout.java    From birt with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Sets the given bounds for the child figure input.
 * 
 * @param parent
 *            the parent figure
 * @param child
 *            the child figure
 * @param bounds
 *            the size of the child to be set
 * @since 2.0
 */
protected void setBoundsOfChild( IFigure parent, IFigure child,
		Rectangle bounds )
{
	parent.getClientArea( Rectangle.SINGLETON );
	bounds.translate( Rectangle.SINGLETON.x, Rectangle.SINGLETON.y );
	child.setBounds( bounds );
}