Java Code Examples for org.eclipse.nebula.widgets.grid.GridItem#getImage()

The following examples show how to use org.eclipse.nebula.widgets.grid.GridItem#getImage() . 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: TypeColunmCellRenderer.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Rectangle getTextBounds(GridItem item, boolean preferred) {
	int x = leftMargin;

	Image image = item.getImage(getColumn());
	if (image != null) {
		x += image.getBounds().width + 3;
	}

	Rectangle bounds = new Rectangle(x, topMargin + textTopMargin, 0, 0);

	GC gc = new GC(item.getParent());
	gc.setFont(item.getFont(getColumn()));
	Point size = gc.stringExtent(item.getText(getColumn()));

	bounds.height = size.y;

	if (preferred) {
		bounds.width = size.x - 1;
	} else {
		bounds.width = getBounds().width - x - rightMargin;
	}

	gc.dispose();

	return bounds;
}
 
Example 2
Source File: TBSearchCellRenderer.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Rectangle getTextBounds(GridItem item, boolean preferred) {
	int x = leftMargin;

	if (isTree()) {
		x += getToggleIndent(item);

		x += toggleRenderer.getBounds().width + insideMargin;

	}

	if (isCheck()) {
		x += checkRenderer.getBounds().width + insideMargin;
	}

	Image image = item.getImage(getColumn());
	if (image != null) {
		x += image.getBounds().width + insideMargin;
	}

	Rectangle bounds = new Rectangle(x, topMargin + textTopMargin, 0, 0);

	GC gc = new GC(item.getParent());
	gc.setFont(item.getFont(getColumn()));
	Point size = gc.stringExtent(item.getText(getColumn()));

	bounds.height = size.y;

	if (preferred) {
		bounds.width = size.x - 1;
	} else {
		bounds.width = getBounds().width - x - rightMargin;
	}

	gc.dispose();

	return bounds;
}
 
Example 3
Source File: CellRenderer.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Rectangle getTextBounds(GridItem item, boolean preferred) {
	int x = leftMargin;

	if (isTree()) {
		x += getToggleIndent(item);

		x += toggleRenderer.getBounds().width + insideMargin;

	}

	if (isCheck()) {
		x += checkRenderer.getBounds().width + insideMargin;
	}

	Image image = item.getImage(getColumn());
	if (image != null) {
		x += image.getBounds().width + insideMargin;
	}

	Rectangle bounds = new Rectangle(x, topMargin + textTopMargin, 0, 0);

	GC gc = new GC(item.getParent());
	gc.setFont(item.getFont(getColumn()));
	Point size = gc.stringExtent(item.getText(getColumn()));

	bounds.height = size.y;

	if (preferred) {
		bounds.width = size.x - 1;
	} else {
		bounds.width = getBounds().width - x - rightMargin;
	}

	gc.dispose();

	return bounds;
}
 
Example 4
Source File: DefaultCellRenderer.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
     * {@inheritDoc}
     */
    public Point computeSize(GC gc, int wHint, int hHint, Object value)
    {
        GridItem item = (GridItem)value;

        gc.setFont(item.getFont(getColumn()));

        int x = 0;

        x += leftMargin;

        if (isTree())
        {
            x += getToggleIndent(item);

            x += toggleRenderer.getBounds().width + insideMargin;

        }

        if (isCheck())
        {
            x += checkRenderer.getBounds().width + insideMargin;
        }

        int y = 0;

        Image image = item.getImage(getColumn());
        if (image != null)
        {
            y = topMargin + image.getBounds().height + bottomMargin;

            x += image.getBounds().width + insideMargin;
        }

// MOPR-DND
// MOPR: replaced this code (to get correct preferred height for cells in word-wrap columns)
//
//       x += gc.stringExtent(item.getText(column)).x + rightMargin;
//
//        y = Math.max(y,topMargin + gc.getFontMetrics().getHeight() + bottomMargin);
//
// with this code:

        int textHeight = 0;
        if(!isWordWrap())
        {
            x += gc.textExtent(item.getText(getColumn())).x + rightMargin;

            textHeight = topMargin + textTopMargin + gc.getFontMetrics().getHeight() + textBottomMargin + bottomMargin;
        }
        else
        {
        	int plainTextWidth;
        	if (wHint == SWT.DEFAULT)
        	  plainTextWidth = getBounds().width - x - rightMargin;
        	else
        		plainTextWidth = wHint - x - rightMargin;

            TextLayout currTextLayout = new TextLayout(gc.getDevice());
            currTextLayout.setFont(gc.getFont());
            currTextLayout.setText(item.getText(getColumn()));
            currTextLayout.setAlignment(getAlignment());
            currTextLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth);

            x += plainTextWidth + rightMargin;

            textHeight += topMargin + textTopMargin;
            for(int cnt=0;cnt<currTextLayout.getLineCount();cnt++)
                textHeight += currTextLayout.getLineBounds(cnt).height;
            textHeight += textBottomMargin + bottomMargin;

            currTextLayout.dispose();
        }

        y = Math.max(y, textHeight);

        return new Point(x, y);
    }
 
Example 5
Source File: TypeColunmCellRenderer.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Point computeSize(GC gc, int wHint, int hHint, Object value) {
	GridItem item = (GridItem) value;

	gc.setFont(item.getFont(getColumn()));

	int x = 0;

	x += leftMargin;

	int y = 0;

	Image image = item.getImage(getColumn());
	if (image != null) {
		y = topMargin + image.getBounds().height + bottomMargin;

		x += image.getBounds().width + 3;
	}

	// MOPR-DND
	// MOPR: replaced this code (to get correct preferred height for cells in word-wrap columns)
	//
	// x += gc.stringExtent(item.getText(column)).x + rightMargin;
	//
	// y = Math.max(y,topMargin + gc.getFontMetrics().getHeight() + bottomMargin);
	//
	// with this code:

	int textHeight = 0;
	if (!isWordWrap()) {
		x += gc.textExtent(item.getText(getColumn())).x + rightMargin;

		textHeight = topMargin + textTopMargin + gc.getFontMetrics().getHeight() + textBottomMargin + bottomMargin;
	} else {
		int plainTextWidth;
		if (wHint == SWT.DEFAULT)
			plainTextWidth = getBounds().width - x - rightMargin;
		else
			plainTextWidth = wHint - x - rightMargin;

		TextLayout currTextLayout = new TextLayout(gc.getDevice());
		currTextLayout.setFont(gc.getFont());
		currTextLayout.setText(item.getText(getColumn()));
		currTextLayout.setAlignment(getAlignment());
		currTextLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth);

		x += plainTextWidth + rightMargin;

		textHeight += topMargin + textTopMargin;
		for (int cnt = 0; cnt < currTextLayout.getLineCount(); cnt++)
			textHeight += currTextLayout.getLineBounds(cnt).height;
		textHeight += textBottomMargin + bottomMargin;

		currTextLayout.dispose();
	}

	y = Math.max(y, textHeight);

	return new Point(x, y);
}
 
Example 6
Source File: SourceColunmCellRenderer.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Point computeSize(GC gc, int wHint, int hHint, Object value) {
	GridItem item = (GridItem) value;

	gc.setFont(item.getFont(getColumn()));

	int x = 0;

	x += leftMargin;

	int y = 0;

	Image image = item.getImage(getColumn());
	if (image != null) {
		y = topMargin + image.getBounds().height + bottomMargin;
	}

	// MOPR-DND
	// MOPR: replaced this code (to get correct preferred height for cells in word-wrap columns)
	//
	// x += gc.stringExtent(item.getText(column)).x + rightMargin;
	//
	// y = Math.max(y,topMargin + gc.getFontMetrics().getHeight() + bottomMargin);
	//
	// with this code:

	int textHeight = 0;
	if (!isWordWrap()) {
		x += gc.textExtent(item.getText(getColumn())).x + rightMargin;

		textHeight = topMargin + textTopMargin + gc.getFontMetrics().getHeight() + textBottomMargin + bottomMargin;
	} else {
		int plainTextWidth;
		if (wHint == SWT.DEFAULT)
			plainTextWidth = getBounds().width - x - rightMargin;
		else
			plainTextWidth = wHint - x - rightMargin;

		TextLayout currTextLayout = new TextLayout(gc.getDevice());
		currTextLayout.setFont(gc.getFont());
		currTextLayout.setText(item.getText(getColumn()));
		currTextLayout.setAlignment(getAlignment());
		currTextLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth);

		x += plainTextWidth + rightMargin;

		textHeight += topMargin + textTopMargin;
		for (int cnt = 0; cnt < currTextLayout.getLineCount(); cnt++)
			textHeight += currTextLayout.getLineBounds(cnt).height;
		textHeight += textBottomMargin + bottomMargin;

		currTextLayout.dispose();
	}

	y = Math.max(y, textHeight);

	return new Point(x, y);
}
 
Example 7
Source File: CellRenderer.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
private boolean isCenteredCheckBoxOnly(GridItem item) {
	return !isTree() && item.getImage(getColumn()) == null && item.getText(getColumn()).equals("")
			&& getAlignment() == SWT.CENTER;
}
 
Example 8
Source File: CellRenderer.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Point computeSize(GC gc, int wHint, int hHint, Object value) {
	GridItem item = (GridItem) value;

	gc.setFont(item.getFont(getColumn()));

	int x = 0;

	x += leftMargin;

	if (isTree()) {
		x += getToggleIndent(item);

		x += toggleRenderer.getBounds().width + insideMargin;

	}

	if (isCheck()) {
		x += checkRenderer.getBounds().width + insideMargin;
	}

	int y = 0;

	Image image = item.getImage(getColumn());
	if (image != null) {
		y = topMargin + image.getBounds().height + bottomMargin;

		x += image.getBounds().width + insideMargin;
	}

	// MOPR-DND
	// MOPR: replaced this code (to get correct preferred height for cells
	// in word-wrap columns)
	//
	// x += gc.stringExtent(item.getText(column)).x + rightMargin;
	//
	// y = Math.max(y,topMargin + gc.getFontMetrics().getHeight() +
	// bottomMargin);
	//
	// with this code:

	int textHeight = 0;
	if (!isWordWrap()) {
		x += gc.textExtent(item.getText(getColumn())).x + rightMargin;

		textHeight = topMargin + textTopMargin + gc.getFontMetrics().getHeight() + textBottomMargin + bottomMargin;
	} else {
		int plainTextWidth;
		if (wHint == SWT.DEFAULT)
			plainTextWidth = getBounds().width - x - rightMargin;
		else
			plainTextWidth = wHint - x - rightMargin;

		TextLayout currTextLayout = new TextLayout(gc.getDevice());
		currTextLayout.setFont(gc.getFont());
		currTextLayout.setText(item.getText(getColumn()));
		currTextLayout.setAlignment(getAlignment());
		currTextLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth);

		x += plainTextWidth + rightMargin;

		textHeight += topMargin + textTopMargin;
		for (int cnt = 0; cnt < currTextLayout.getLineCount(); cnt++)
			textHeight += currTextLayout.getLineBounds(cnt).height;
		textHeight += textBottomMargin + bottomMargin;

		currTextLayout.dispose();
	}

	y = Math.max(y, textHeight);

	return new Point(x, y);
}
 
Example 9
Source File: DefaultCellRenderer.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
private boolean isCenteredCheckBoxOnly(GridItem item)
  {
  	return !isTree() && item.getImage(getColumn()) == null && item.getText(getColumn()).equals("")
&& getAlignment() == SWT.CENTER;
  }
 
Example 10
Source File: TBSearchCellRenderer.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Point computeSize(GC gc, int wHint, int hHint, Object value) {
	GridItem item = (GridItem) value;

	gc.setFont(item.getFont(getColumn()));

	int x = 0;

	x += leftMargin;

	if (isTree()) {
		x += getToggleIndent(item);

		x += toggleRenderer.getBounds().width + insideMargin;

	}

	if (isCheck()) {
		x += checkRenderer.getBounds().width + insideMargin;
	}

	int y = 0;

	Image image = item.getImage(getColumn());
	if (image != null) {
		y = topMargin + image.getBounds().height + bottomMargin;

		x += image.getBounds().width + insideMargin;
	}

	// MOPR-DND
	// MOPR: replaced this code (to get correct preferred height for cells in word-wrap columns)
	//
	// x += gc.stringExtent(item.getText(column)).x + rightMargin;
	//
	// y = Math.max(y,topMargin + gc.getFontMetrics().getHeight() + bottomMargin);
	//
	// with this code:

	int textHeight = 0;
	if (!isWordWrap()) {
		x += gc.textExtent(item.getText(getColumn())).x + rightMargin;

		textHeight = topMargin + textTopMargin + gc.getFontMetrics().getHeight() + textBottomMargin + bottomMargin;
	} else {
		int plainTextWidth;
		if (wHint == SWT.DEFAULT)
			plainTextWidth = getBounds().width - x - rightMargin;
		else
			plainTextWidth = wHint - x - rightMargin;

		TextLayout currTextLayout = new TextLayout(gc.getDevice());
		currTextLayout.setFont(gc.getFont());
		currTextLayout.setText(item.getText(getColumn()));
		currTextLayout.setAlignment(getAlignment());
		currTextLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth);

		x += plainTextWidth + rightMargin;

		textHeight += topMargin + textTopMargin;
		for (int cnt = 0; cnt < currTextLayout.getLineCount(); cnt++)
			textHeight += currTextLayout.getLineBounds(cnt).height;
		textHeight += textBottomMargin + bottomMargin;

		currTextLayout.dispose();
	}

	y = Math.max(y, textHeight);

	return new Point(x, y);
}
 
Example 11
Source File: CellRenderer.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Point computeSize(GC gc, int wHint, int hHint, Object value) {
	GridItem item = (GridItem) value;

	gc.setFont(item.getFont(getColumn()));

	int x = 0;

	x += leftMargin;

	if (isTree()) {
		x += getToggleIndent(item);

		x += toggleRenderer.getBounds().width + insideMargin;

	}

	if (isCheck()) {
		x += checkRenderer.getBounds().width + insideMargin;
	}

	int y = 0;

	Image image = item.getImage(getColumn());
	if (image != null) {
		y = topMargin + image.getBounds().height + bottomMargin;

		x += image.getBounds().width + insideMargin;
	}

	// MOPR-DND
	// MOPR: replaced this code (to get correct preferred height for cells
	// in word-wrap columns)
	//
	// x += gc.stringExtent(item.getText(column)).x + rightMargin;
	//
	// y = Math.max(y,topMargin + gc.getFontMetrics().getHeight() +
	// bottomMargin);
	//
	// with this code:

	int textHeight = 0;
	if (!isWordWrap()) {
		x += gc.textExtent(item.getText(getColumn())).x + rightMargin;

		textHeight = topMargin + textTopMargin + gc.getFontMetrics().getHeight() + textBottomMargin + bottomMargin;
	} else {
		int plainTextWidth;
		if (wHint == SWT.DEFAULT)
			plainTextWidth = getBounds().width - x - rightMargin;
		else
			plainTextWidth = wHint - x - rightMargin;

		TextLayout currTextLayout = new TextLayout(gc.getDevice());
		currTextLayout.setFont(gc.getFont());
		currTextLayout.setText(item.getText(getColumn()));
		currTextLayout.setAlignment(getAlignment());
		currTextLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth);

		x += plainTextWidth + rightMargin;

		textHeight += topMargin + textTopMargin;
		for (int cnt = 0; cnt < currTextLayout.getLineCount(); cnt++)
			textHeight += currTextLayout.getLineBounds(cnt).height;
		textHeight += textBottomMargin + bottomMargin;

		currTextLayout.dispose();
	}

	y = Math.max(y, textHeight);

	return new Point(x, y);
}
 
Example 12
Source File: TBSearchCellRenderer.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
private boolean isCenteredCheckBoxOnly(GridItem item) {
	return !isTree() && item.getImage(getColumn()) == null && item.getText(getColumn()).equals("")
			&& getAlignment() == SWT.CENTER;
}
 
Example 13
Source File: DefaultCellRenderer.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
     * {@inheritDoc}
     */
    public Point computeSize(GC gc, int wHint, int hHint, Object value)
    {
        GridItem item = (GridItem)value;

        gc.setFont(item.getFont(getColumn()));

        int x = 0;

        x += leftMargin;

        if (isTree())
        {
            x += getToggleIndent(item);

            x += toggleRenderer.getBounds().width + insideMargin;

        }

        if (isCheck())
        {
            x += checkRenderer.getBounds().width + insideMargin;
        }

        int y = 0;

        Image image = item.getImage(getColumn());
        if (image != null)
        {
            y = topMargin + image.getBounds().height + bottomMargin;

            x += image.getBounds().width + insideMargin;
        }

// MOPR-DND
// MOPR: replaced this code (to get correct preferred height for cells in word-wrap columns)
//
//       x += gc.stringExtent(item.getText(column)).x + rightMargin;
//
//        y = Math.max(y,topMargin + gc.getFontMetrics().getHeight() + bottomMargin);
//
// with this code:

        int textHeight = 0;
        if(!isWordWrap())
        {
            x += gc.textExtent(item.getText(getColumn())).x + rightMargin;

            textHeight = topMargin + textTopMargin + gc.getFontMetrics().getHeight() + textBottomMargin + bottomMargin;
        }
        else
        {
        	int plainTextWidth;
        	if (wHint == SWT.DEFAULT)
        	  plainTextWidth = getBounds().width - x - rightMargin;
        	else
        		plainTextWidth = wHint - x - rightMargin;

            TextLayout currTextLayout = new TextLayout(gc.getDevice());
            currTextLayout.setFont(gc.getFont());
            currTextLayout.setText(item.getText(getColumn()));
            currTextLayout.setAlignment(getAlignment());
            currTextLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth);

            x += plainTextWidth + rightMargin;

            textHeight += topMargin + textTopMargin;
            for(int cnt=0;cnt<currTextLayout.getLineCount();cnt++)
                textHeight += currTextLayout.getLineBounds(cnt).height;
            textHeight += textBottomMargin + bottomMargin;

            currTextLayout.dispose();
        }

        y = Math.max(y, textHeight);

        return new Point(x, y);
    }
 
Example 14
Source File: TBSearchCellRenderer.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Point computeSize(GC gc, int wHint, int hHint, Object value) {
	GridItem item = (GridItem) value;

	gc.setFont(item.getFont(getColumn()));

	int x = 0;

	x += leftMargin;

	if (isTree()) {
		x += getToggleIndent(item);

		x += toggleRenderer.getBounds().width + insideMargin;

	}

	if (isCheck()) {
		x += checkRenderer.getBounds().width + insideMargin;
	}

	int y = 0;

	Image image = item.getImage(getColumn());
	if (image != null) {
		y = topMargin + image.getBounds().height + bottomMargin;

		x += image.getBounds().width + insideMargin;
	}

	// MOPR-DND
	// MOPR: replaced this code (to get correct preferred height for cells in word-wrap columns)
	//
	// x += gc.stringExtent(item.getText(column)).x + rightMargin;
	//
	// y = Math.max(y,topMargin + gc.getFontMetrics().getHeight() + bottomMargin);
	//
	// with this code:

	int textHeight = 0;
	if (!isWordWrap()) {
		x += gc.textExtent(item.getText(getColumn())).x + rightMargin;

		textHeight = topMargin + textTopMargin + gc.getFontMetrics().getHeight() + textBottomMargin + bottomMargin;
	} else {
		int plainTextWidth;
		if (wHint == SWT.DEFAULT)
			plainTextWidth = getBounds().width - x - rightMargin;
		else
			plainTextWidth = wHint - x - rightMargin;

		TextLayout currTextLayout = new TextLayout(gc.getDevice());
		currTextLayout.setFont(gc.getFont());
		currTextLayout.setText(item.getText(getColumn()));
		currTextLayout.setAlignment(getAlignment());
		currTextLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth);

		x += plainTextWidth + rightMargin;

		textHeight += topMargin + textTopMargin;
		for (int cnt = 0; cnt < currTextLayout.getLineCount(); cnt++)
			textHeight += currTextLayout.getLineBounds(cnt).height;
		textHeight += textBottomMargin + bottomMargin;

		currTextLayout.dispose();
	}

	y = Math.max(y, textHeight);

	return new Point(x, y);
}
 
Example 15
Source File: DefaultCellRenderer.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Rectangle getTextBounds(GridItem item, boolean preferred)
{
    int x = leftMargin;

    if (isTree())
    {
        x += getToggleIndent(item);

        x += toggleRenderer.getBounds().width + insideMargin;

    }

    if (isCheck())
    {
        x += checkRenderer.getBounds().width + insideMargin;
    }

    Image image = item.getImage(getColumn());
    if (image != null)
    {
        x += image.getBounds().width + insideMargin;
    }

    Rectangle bounds = new Rectangle(x,topMargin + textTopMargin,0,0);

    GC gc = new GC(item.getParent());
    gc.setFont(item.getFont(getColumn()));
    Point size = gc.stringExtent(item.getText(getColumn()));

    bounds.height = size.y;

    if (preferred)
    {
        bounds.width = size.x - 1;
    }
    else
    {
        bounds.width = getBounds().width - x - rightMargin;
    }

    gc.dispose();

    return bounds;
}
 
Example 16
Source File: DefaultCellRenderer.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
private boolean isCenteredCheckBoxOnly(GridItem item)
  {
  	return !isTree() && item.getImage(getColumn()) == null && item.getText(getColumn()).equals("")
&& getAlignment() == SWT.CENTER;
  }
 
Example 17
Source File: SourceColunmCellRenderer.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Point computeSize(GC gc, int wHint, int hHint, Object value) {
	GridItem item = (GridItem) value;

	gc.setFont(item.getFont(getColumn()));

	int x = 0;

	x += leftMargin;

	int y = 0;

	Image image = item.getImage(getColumn());
	if (image != null) {
		y = topMargin + image.getBounds().height + bottomMargin;
	}

	// MOPR-DND
	// MOPR: replaced this code (to get correct preferred height for cells in word-wrap columns)
	//
	// x += gc.stringExtent(item.getText(column)).x + rightMargin;
	//
	// y = Math.max(y,topMargin + gc.getFontMetrics().getHeight() + bottomMargin);
	//
	// with this code:

	int textHeight = 0;
	if (!isWordWrap()) {
		x += gc.textExtent(item.getText(getColumn())).x + rightMargin;

		textHeight = topMargin + textTopMargin + gc.getFontMetrics().getHeight() + textBottomMargin + bottomMargin;
	} else {
		int plainTextWidth;
		if (wHint == SWT.DEFAULT)
			plainTextWidth = getBounds().width - x - rightMargin;
		else
			plainTextWidth = wHint - x - rightMargin;

		TextLayout currTextLayout = new TextLayout(gc.getDevice());
		currTextLayout.setFont(gc.getFont());
		currTextLayout.setText(item.getText(getColumn()));
		currTextLayout.setAlignment(getAlignment());
		currTextLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth);

		x += plainTextWidth + rightMargin;

		textHeight += topMargin + textTopMargin;
		for (int cnt = 0; cnt < currTextLayout.getLineCount(); cnt++)
			textHeight += currTextLayout.getLineBounds(cnt).height;
		textHeight += textBottomMargin + bottomMargin;

		currTextLayout.dispose();
	}

	y = Math.max(y, textHeight);

	return new Point(x, y);
}
 
Example 18
Source File: TargetColunmCellRenderer.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Point computeSize(GC gc, int wHint, int hHint, Object value) {
	GridItem item = (GridItem) value;

	gc.setFont(item.getFont(getColumn()));

	int x = 0;

	x += leftMargin;

	int y = 0;

	Image image = item.getImage(getColumn());
	if (image != null) {
		y = topMargin + image.getBounds().height + bottomMargin;

		x += image.getBounds().width + 3;
	}

	// MOPR-DND
	// MOPR: replaced this code (to get correct preferred height for cells in word-wrap columns)
	//
	// x += gc.stringExtent(item.getText(column)).x + rightMargin;
	//
	// y = Math.max(y,topMargin + gc.getFontMetrics().getHeight() + bottomMargin);
	//
	// with this code:

	int textHeight = 0;
	if (!isWordWrap()) {
		x += gc.textExtent(item.getText(getColumn())).x + rightMargin;

		textHeight = topMargin + textTopMargin + gc.getFontMetrics().getHeight() + textBottomMargin + bottomMargin;
	} else {
		int plainTextWidth;
		if (wHint == SWT.DEFAULT)
			plainTextWidth = getBounds().width - x - rightMargin;
		else
			plainTextWidth = wHint - x - rightMargin;

		TextLayout currTextLayout = new TextLayout(gc.getDevice());
		currTextLayout.setFont(gc.getFont());
		currTextLayout.setText(item.getText(getColumn()));
		currTextLayout.setAlignment(getAlignment());
		currTextLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth);

		x += plainTextWidth + rightMargin;

		textHeight += topMargin + textTopMargin;
		for (int cnt = 0; cnt < currTextLayout.getLineCount(); cnt++)
			textHeight += currTextLayout.getLineBounds(cnt).height;
		textHeight += textBottomMargin + bottomMargin;

		currTextLayout.dispose();
	}

	y = Math.max(y, textHeight);

	return new Point(x, y);
}
 
Example 19
Source File: CellRenderer.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
private boolean isCenteredCheckBoxOnly(GridItem item) {
	return !isTree() && item.getImage(getColumn()) == null && item.getText(getColumn()).equals("")
			&& getAlignment() == SWT.CENTER;
}
 
Example 20
Source File: TBSearchCellRenderer.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
private boolean isCenteredCheckBoxOnly(GridItem item) {
	return !isTree() && item.getImage(getColumn()) == null && item.getText(getColumn()).equals("")
			&& getAlignment() == SWT.CENTER;
}