Java Code Examples for org.eclipse.swt.graphics.TextLayout#setText()

The following examples show how to use org.eclipse.swt.graphics.TextLayout#setText() . 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: XbaseInformationControl.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Creates and initializes the text layout used to compute the size hint.
 * 
 * @since 3.2
 */
private void createTextLayout() {
	fTextLayout = new TextLayout(fSashForm.getDisplay());

	// Initialize fonts
	String symbolicFontName = fSymbolicFontName == null ? JFaceResources.DIALOG_FONT : fSymbolicFontName;
	Font font = JFaceResources.getFont(symbolicFontName);
	fTextLayout.setFont(font);
	fTextLayout.setWidth(-1);
	font = JFaceResources.getFontRegistry().getBold(symbolicFontName);
	fBoldStyle = new TextStyle(font, null, null);

	// Compute and set tab width
	fTextLayout.setText("    "); //$NON-NLS-1$
	int tabWidth = fTextLayout.getBounds().width;
	fTextLayout.setTabs(new int[] { tabWidth });
	fTextLayout.setText(""); //$NON-NLS-1$
}
 
Example 2
Source File: CellFigure.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
protected void drawBlankString( Graphics g, String s )
{
	TextLayout tl = new TextLayout( Display.getCurrent( ) );

	// bidi_hcg: Apply text direction
	tl.setOrientation( this.rtl ? SWT.RIGHT_TO_LEFT : SWT.LEFT_TO_RIGHT );
	
	tl.setText( s );
	Rectangle rc = tl.getBounds( );

	int left = ( getClientArea( ).width - rc.width ) / 2;
	int top = ( getClientArea( ).height - rc.height ) / 2;

	g.drawText( s, getClientArea( ).x + left, getClientArea( ).y + top );
	tl.dispose();
}
 
Example 3
Source File: XGridCellRenderer.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public TextLayout getTextLayout(GC gc, GridItem item, int columnIndex, boolean innerTagStyled, boolean drawInnerTag) {
	TextLayout layout = new TextLayout(gc.getDevice());
	layout.setFont(font);
	layout.setTabs(new int[]{tabWidth});
	innerTagFactory.reset();
	
	String displayStr = "";
	try{
		displayStr = InnerTagUtil.resolveTag(innerTagFactory.parseInnerTag(item.getText(columnIndex)));
	}catch (NullPointerException e) {
		return null;
	}
	layout.setText(displayStr);
	int width = getBounds().width - leftMargin - rightMargin;
	layout.setWidth(width < 1 ? 1 : width);
	layout.setSpacing(Constants.SEGMENT_LINE_SPACING);
	layout.setAlignment(SWT.LEFT);
	layout.setOrientation(item.getParent().getOrientation());
	if (displayStr.length() != 0 && innerTagStyled) {
		attachInnertTagStyle(gc, layout, drawInnerTag);
	}
	return layout;
}
 
Example 4
Source File: ComponentStatusLabel.java    From arx with Apache License 2.0 5 votes vote down vote up
/**
 * Shorten text
 *
 * @param gc
 * @param t
 * @param width
 * @return
 */
protected String shortenText(GC gc, String t, int width) {
    if (t == null) return null;
    int w = gc.textExtent(ELLIPSIS, DRAW_FLAGS).x;
    if (width <= w) return t;
    int l = t.length();
    int max = l / 2;
    int min = 0;
    int mid = (max + min) / 2 - 1;
    if (mid <= 0) return t;
    TextLayout layout = new TextLayout(getDisplay());
    layout.setText(t);
    mid = validateOffset(layout, mid);
    while (min < mid && mid < max) {
        String s1 = t.substring(0, mid);
        String s2 = t.substring(validateOffset(layout, l - mid), l);
        int l1 = gc.textExtent(s1, DRAW_FLAGS).x;
        int l2 = gc.textExtent(s2, DRAW_FLAGS).x;
        if (l1 + w + l2 > width) {
            max = mid;
            mid = validateOffset(layout, (max + min) / 2);
        } else if (l1 + w + l2 < width) {
            min = mid;
            mid = validateOffset(layout, (max + min) / 2);
        } else {
            min = max;
        }
    }
    String result = mid == 0 ? t : t.substring(0, mid) + ELLIPSIS + t.substring(validateOffset(layout, l - mid), l);
    layout.dispose();
    return result;
}
 
Example 5
Source File: TextPainterWithPadding.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
private TextLayout getCellTextLayout(LayerCell cell) {
	int orientation = editor.getTable().getStyle() & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
	TextLayout layout = new TextLayout(editor.getTable().getDisplay());
	layout.setOrientation(orientation);
	layout.setSpacing(Constants.SEGMENT_LINE_SPACING);
	layout.setFont(font);
	layout.setAscent(ascent);
	layout.setDescent(descent); // 和 StyledTextEditor 同步
	layout.setTabs(new int[] { tabWidth });

	Rectangle rectangle = cell.getBounds();
	int width = rectangle.width - leftPadding - rightPadding;
	width -= 1;
	if (wrapText && width > 0) {
		layout.setWidth(width);
	}

	String displayText = InnerTagUtil.resolveTag(innerTagFactory.parseInnerTag((String) cell.getDataValue()));
	if (XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
		displayText = displayText.replaceAll("\\n", Constants.LINE_SEPARATOR_CHARACTER + "\n");
		displayText = displayText.replaceAll("\\t", Constants.TAB_CHARACTER + "");
		displayText = displayText.replaceAll(" ", Constants.SPACE_CHARACTER + "");
	}
	layout.setText(displayText);
	List<InnerTagBean> innerTagBeans = innerTagFactory.getInnerTagBeans();
	for (InnerTagBean innerTagBean : innerTagBeans) {
		String placeHolder = placeHolderBuilder.getPlaceHolder(innerTagBeans, innerTagBeans.indexOf(innerTagBean));
		int start = displayText.indexOf(placeHolder);
		if (start == -1) {
			continue;
		}
		TextStyle style = new TextStyle();
		Point rect = tagRender.calculateTagSize(innerTagBean);
		style.metrics = new GlyphMetrics(rect.y, 0, rect.x + SEGMENT_LINE_SPACING * 2);
		layout.setStyle(style, start, start + placeHolder.length() - 1);
	}

	return layout;
}
 
Example 6
Source File: XGridCellRenderer.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 设置字体
 * @param font
 *            ;
 */
public void setFont(Font font) {
	TextLayout layout = new TextLayout(Display.getDefault());
	layout.setFont(font);
	StringBuffer tabBuffer = new StringBuffer(tabSize);
	for (int i = 0; i < tabSize; i++) {
		tabBuffer.append(' ');
	}
	layout.setText(tabBuffer.toString());
	tabWidth = layout.getBounds().width;
	layout.dispose();
	this.font = font;
}
 
Example 7
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 8
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 9
Source File: TypeColunmCellRenderer.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 10
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 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 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 13
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 14
Source File: AccordionLabel.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Shorten the given text <code>t</code> so that its length doesn't exceed
 * the given width. The default implementation replaces characters in the
 * center of the original string with an ellipsis ("..."). Override if you
 * need a different strategy.
 * 
 * @param gc
 *            the gc to use for text measurement
 * @param t
 *            the text to shorten
 * @param width
 *            the width to shorten the text to, in pixels
 * @return the shortened text
 */
protected String shortenText( GC gc, String t, int width )
{
	if ( t == null )
		return null;
	int w = gc.textExtent( ELLIPSIS, DRAW_FLAGS ).x;
	if ( width <= w )
		return t;
	int l = t.length( );
	int max = l / 2;
	int min = 0;
	int mid = ( max + min ) / 2 - 1;
	if ( mid <= 0 )
		return t;
	TextLayout layout = new TextLayout( getDisplay( ) );
	layout.setText( t );
	mid = validateOffset( layout, mid );
	while ( min < mid && mid < max )
	{
		String s1 = t.substring( 0, mid );
		String s2 = t.substring( validateOffset( layout, l - mid ), l );
		int l1 = gc.textExtent( s1, DRAW_FLAGS ).x;
		int l2 = gc.textExtent( s2, DRAW_FLAGS ).x;
		if ( l1 + w + l2 > width )
		{
			max = mid;
			mid = validateOffset( layout, ( max + min ) / 2 );
		}
		else if ( l1 + w + l2 < width )
		{
			min = mid;
			mid = validateOffset( layout, ( max + min ) / 2 );
		}
		else
		{
			min = max;
		}
	}
	String result = mid == 0 ? t : t.substring( 0, mid )
			+ ELLIPSIS
			+ t.substring( validateOffset( layout, l - mid ), l );
	layout.dispose( );
	return result;
}
 
Example 15
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 16
Source File: CleanUpPostSaveListener.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected Control createMessageArea(Composite parent) {
	initializeDialogUnits(parent);

	Composite messageComposite= new Composite(parent, SWT.NONE);
	messageComposite.setFont(parent.getFont());
	GridLayout layout= new GridLayout();
	layout.numColumns= 1;
	layout.marginHeight= 0;
	layout.marginWidth= 0;
	layout.verticalSpacing= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
	layout.horizontalSpacing= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
	messageComposite.setLayout(layout);
	messageComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

	Label explain= new Label(messageComposite, SWT.WRAP);
	explain.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
	explain.setText(FixMessages.CleanUpPostSaveListener_SlowCleanUpWarningDialog_explain);

	final BulletListBlock cleanUpListBlock= new BulletListBlock(messageComposite, SWT.NONE);
	GridData gridData= new GridData(SWT.FILL, SWT.FILL, true, true);
	cleanUpListBlock.setLayoutData(gridData);
	cleanUpListBlock.setText(fCleanUpNames);

	TextLayout textLayout= new TextLayout(messageComposite.getDisplay());
	textLayout.setText(fCleanUpNames);
	int lineCount= textLayout.getLineCount();
	if (lineCount < 5)
		gridData.heightHint= textLayout.getLineBounds(0).height * 6;
	textLayout.dispose();

	Link link= new Link(messageComposite, SWT.NONE);
	link.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
	link.setText(FixMessages.CleanUpPostSaveListener_SlowCleanUpDialog_link);

	link.addSelectionListener(new SelectionAdapter() {
		/*
		 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
		 */
		@Override
		public void widgetSelected(SelectionEvent e) {
			PreferencesUtil.createPreferenceDialogOn(getShell(), SaveParticipantPreferencePage.PREFERENCE_PAGE_ID, null, null).open();
		}
	});

	return messageComposite;
}
 
Example 17
Source File: TargetColunmCellRenderer.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 18
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 19
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 20
Source File: DefaultCellRenderer.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
     * {@inheritDoc}
     */
    @Override
	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 = gc.textExtent(item.getText(getColumn())).x;
        	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);
    }