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

The following examples show how to use org.eclipse.draw2d.IFigure#getPreferredSize() . 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: LaneFigure.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * This is a copy of the parent method. Only change is that we call getContraintAsRectangle() instead of directly accessing the constraints member.
 */
@Override
protected Dimension calculatePreferredSize(IFigure f, int wHint, int hHint) {
	final Rectangle rect = new Rectangle();
	final ListIterator children = f.getChildren().listIterator();
	while (children.hasNext()) {
		final IFigure child = (IFigure) children.next();
		Rectangle r = getConstraintAsRectangle(child);
		if (r == null)
			continue;

		if ((r.width == -1) || (r.height == -1)) {
			final Dimension preferredSize = child.getPreferredSize(r.width, r.height);
			r = r.getCopy();
			if (r.width == -1)
				r.width = preferredSize.width;
			if (r.height == -1)
				r.height = preferredSize.height;
		}
		rect.union(r);
	}
	final Dimension d = rect.getSize();
	final Insets insets = f.getInsets();
	return new Dimension(d.width + insets.getWidth(), d.height + insets.getHeight()).union(getBorderPreferredSize(f));
}
 
Example 3
Source File: ExportToFileAction.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void run() {
	IFigure contents = railroadView.getContents();
	if (contents != null) {
		FileDialog fileDialog = new FileDialog(this.railroadView.getSite().getShell(), SWT.SAVE);
		fileDialog.setFilterExtensions(new String[] { "*.png" });
		fileDialog.setText("Choose diagram file");
		String fileName = fileDialog.open();
		if (fileName == null) {
			return;
		}
		Dimension preferredSize = contents.getPreferredSize();
		Image image = new Image(Display.getDefault(), preferredSize.width + 2 * PADDING, preferredSize.height + 2
				* PADDING);
		GC gc = new GC(image);
		SWTGraphics graphics = new SWTGraphics(gc);
		graphics.translate(PADDING, PADDING);
		graphics.translate(contents.getBounds().getLocation().getNegated());
		contents.paint(graphics);
		ImageData imageData = image.getImageData();
		ImageLoader imageLoader = new ImageLoader();
		imageLoader.data = new ImageData[] { imageData };
		imageLoader.save(fileName, SWT.IMAGE_PNG);
	}
}
 
Example 4
Source File: TableLayout.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
private int[] getColumnWidth(final List<List<IFigure>> table) {
    final int[] columnWidth = new int[colnum];

    for (int i = 0; i < colnum; i++) {
        for (final List<IFigure> tableRow : table) {
            if (tableRow.size() > i) {
                final IFigure figure = tableRow.get(i);

                final int width = figure.getPreferredSize().width;

                if (width > columnWidth[i]) {
                    columnWidth[i] = (int) (width * 1.3);
                }
            }
        }
    }

    return columnWidth;
}
 
Example 5
Source File: TableLayout.java    From erflute with Apache License 2.0 6 votes vote down vote up
private int[] getColumnWidth(List<List<IFigure>> table) {
    final int[] columnWidth = new int[colnum];

    for (int i = 0; i < colnum; i++) {
        for (final List<IFigure> tableRow : table) {
            if (tableRow.size() > i) {
                final IFigure figure = tableRow.get(i);

                final int width = figure.getPreferredSize().width;

                if (width > columnWidth[i]) {
                    columnWidth[i] = (int) (width * 1.3);
                }
            }
        }
    }

    return columnWidth;
}
 
Example 6
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 7
Source File: TableLayout.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
private int[] getColumnWidth(List<List<IFigure>> table) {
	int[] columnWidth = new int[this.colnum];

	for (int i = 0; i < colnum; i++) {
		for (List<IFigure> tableRow : table) {
			if (tableRow.size() > i) {
				IFigure figure = tableRow.get(i);

				int width = figure.getPreferredSize().width;

				if (width > columnWidth[i]) {
					columnWidth[i] = (int) (width * 1.3);
				}
			}
		}
	}

	return columnWidth;
}
 
Example 8
Source File: CursorTimingsLayer.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Point getLocation(PointList points) {
	final IFigure cursorLabel = (IFigure) getConnection().getChildren().get(1);
	final Dimension labelSize = cursorLabel.getPreferredSize();

	final Point firstPoint = points.getFirstPoint();
	final Point lastPoint = points.getLastPoint();
	final int direction = (lastPoint.x() > firstPoint.x()) ? 1 : -1;

	final Point point = super.getLocation(points);
	point.translate(((labelSize.width() / 2) + fDistance) * direction, 0);

	return point;
}
 
Example 9
Source File: TableLayout.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
private int[] getRowHeight(final List<List<IFigure>> table) {
    final int[] rowHeight = new int[table.size()];

    for (int i = 0; i < rowHeight.length; i++) {
        for (final IFigure cell : table.get(i)) {
            final int height = cell.getPreferredSize().height;

            if (height > rowHeight[i]) {
                rowHeight[i] = height;
            }
        }
    }

    return rowHeight;
}
 
Example 10
Source File: TableLayout.java    From erflute with Apache License 2.0 5 votes vote down vote up
private int[] getRowHeight(List<List<IFigure>> table) {
    final int[] rowHeight = new int[table.size()];

    for (int i = 0; i < rowHeight.length; i++) {
        for (final IFigure cell : table.get(i)) {
            final int height = cell.getPreferredSize().height;

            if (height > rowHeight[i]) {
                rowHeight[i] = height;
            }
        }
    }

    return rowHeight;
}
 
Example 11
Source File: ListBandLayout.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void layout( IFigure parent )
{
	Rectangle bounds = parent.getClientArea( ).getCopy( );
	List list = parent.getChildren( );
	int size = list.size( );
	int height = 0;

	ReportShowFigure showFigure = null;
	if ( parent instanceof ReportShowFigure )
	{
		showFigure = (ReportShowFigure) parent;
	}
	for ( int i = 0; i < size; i++ )
	{
		IFigure figure = (IFigure) list.get( i );
		if ( showFigure != null
				&& showFigure.getContent( ) == figure
				&& !showFigure.isControlShowing( ) )
		{
			setBoundsOfChild( parent, figure, new Rectangle( 0,
					height,
					0,
					0 ) );
		}
		else
		{
			Dimension dim = figure.getPreferredSize( bounds.width, -1 );
			setBoundsOfChild( parent, figure, new Rectangle( 0,
					height,
					dim.width,
					dim.height ) );
			height = height + dim.height + verticalSpan;
		}

	}

}
 
Example 12
Source File: TableLayout.java    From ermaster-b with Apache License 2.0 5 votes vote down vote up
private int[] getRowHeight(List<List<IFigure>> table) {
	int[] rowHeight = new int[table.size()];

	for (int i = 0; i < rowHeight.length; i++) {
		for (IFigure cell : table.get(i)) {
			int height = cell.getPreferredSize().height;

			if (height > rowHeight[i]) {
				rowHeight[i] = height;
			}
		}
	}

	return rowHeight;
}