Java Code Examples for org.eclipse.swt.graphics.GC#drawText()
The following examples show how to use
org.eclipse.swt.graphics.GC#drawText() .
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: TextColorDrawingStrategy.java From uima-uimaj with Apache License 2.0 | 6 votes |
@Override public void draw(Annotation annotation, GC gc, StyledText textWidget, int start, int length, Color color) { if (length > 0) { if (annotation instanceof EclipseAnnotationPeer) { if (gc != null) { int end = start + length - 1; Rectangle bounds = textWidget.getTextBounds(start, end); gc.setForeground(color); gc.drawText(textWidget.getText(start, end), bounds.x, bounds.y, true); } else { textWidget.redrawRange(start, length, true); } } } }
Example 2
Source File: GUIResource.java From pentaho-kettle with Apache License 2.0 | 6 votes |
/** * @return an Image containing the given text * with color as foreground (e.g. {@link SWT#COLOR_RED}) */ @SuppressWarnings ( "unused" ) public Image getTextImage( String text, int color ) { //Use a temp image and gc to figure out the size of the text Image tempImage = new Image( display, 400, 400 ); GC tempGC = new GC( tempImage ); Point textSize = tempGC.textExtent( text ); tempGC.dispose(); tempImage.dispose(); //Draw an image with red text for the tab text Image image = new Image( display, textSize.x, textSize.y ); GC gc = new GC( image ); gc.setForeground( display.getSystemColor( color ) ); gc.drawText( text, 0, 0, true ); gc.dispose(); return image; }
Example 3
Source File: HierarchyWizardEditor.java From arx with Apache License 2.0 | 5 votes |
/** * Draws a string. * * @param gc * @param string * @param r */ private void drawString(GC gc, String string, Rectangle r) { gc.setFont(HierarchyWizardEditorRenderer.FONT); Point extent = gc.textExtent(string); int xx = r.x + (r.width - extent.x) / 2; int yy = r.y + (r.height - extent.y) / 2; gc.drawText(string, xx, yy, true); }
Example 4
Source File: DaySelectionCanvas.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
/** * Draws a day on the canvas. * @param gc GC used to draw * @param days item to be drawn * @param days array with days * @param columnWidth width of a column * @param rowHeight height of a row */ private void drawDay(GC gc, int item, int[] days, int columnWidth, int rowHeight) { Color tempBackground = null; Color tempForeground = null; boolean validSelection = isValidSelection(item); if (validSelection && (item == selection)) { tempBackground = gc.getBackground(); tempForeground = gc.getForeground(); gc.setBackground(selectionBackgroundColor); gc.setForeground(SELECTION_FOREGROUND); int height = rowHeight; int width = columnWidth; int x = columnWidth * (item % 7); if (x > 0) { x++; width--; } int y = rowHeight * (item / 7 + 1) + 1; height--; if (y == rowHeight) { y++; height--; } gc.fillRectangle(x, y, width, height); gc.setBackground(tempBackground); } String dayString = String.valueOf(days[item]); Point position = getDayPosition(gc, item, days, columnWidth, rowHeight); gc.drawText(dayString, position.x, position.y, SWT.DRAW_TRANSPARENT); if (validSelection && (item == selection)) { gc.setForeground(tempForeground); } }
Example 5
Source File: ConditionEditor.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private void drawNegated( GC gc, int x, int y, Condition condition ) { Color color = gc.getForeground(); if ( hover_not ) { gc.setBackground( gray ); } gc.fillRectangle( Real2Screen( size_not ) ); gc.drawRectangle( Real2Screen( size_not ) ); if ( condition.isNegated() ) { if ( hover_not ) { gc.setForeground( green ); } gc.drawText( STRING_NOT, size_not.x + 5 + offsetx, size_not.y + 2 + offsety, SWT.DRAW_TRANSPARENT ); gc.drawText( STRING_NOT, size_not.x + 6 + offsetx, size_not.y + 2 + offsety, SWT.DRAW_TRANSPARENT ); if ( hover_not ) { gc.setForeground( color ); } } else { if ( hover_not ) { gc.setForeground( red ); gc.drawText( STRING_NOT, size_not.x + 5 + offsetx, size_not.y + 2 + offsety, SWT.DRAW_TRANSPARENT ); gc.drawText( STRING_NOT, size_not.x + 6 + offsetx, size_not.y + 2 + offsety, SWT.DRAW_TRANSPARENT ); gc.setForeground( color ); } } if ( hover_not ) { gc.setBackground( bg ); } }
Example 6
Source File: TextPainter.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
@Override public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) { if (paintBg) { super.paintCell(cell, gc, rectangle, configRegistry); } Rectangle originalClipping = gc.getClipping(); gc.setClipping(rectangle.intersection(originalClipping)); IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry); setupGCFromConfig(gc, cellStyle); String text = convertDataType(cell, configRegistry); // Draw Text String originalText = text; int originalTextWidth = getWidthFromCache(gc, originalText); text = getAvailableTextToDisplay(gc, rectangle, text); int contentWidth = Math.min(originalTextWidth, rectangle.width); int fontHeight = gc.getFontMetrics().getHeight(); int contentHeight = fontHeight * getNumberOfNewLines(text); gc.drawText( text, rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentWidth), rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentHeight), true ); gc.setClipping(originalClipping); }
Example 7
Source File: ConditionEditor.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public void drawUp( GC gc ) { if ( hover_up ) { gc.setBackground( gray ); gc.fillRectangle( size_up ); } gc.drawRectangle( size_up ); gc.drawText( STRING_UP, size_up.x + 1 + offsetx, size_up.y + 1 + offsety, SWT.DRAW_TRANSPARENT ); }
Example 8
Source File: ViewLattice.java From arx with Apache License 2.0 | 5 votes |
/** * Utility method which centers a text in a rectangle. * * @param gc * @param text * @param x * @param y * @param width * @param height */ private void drawText(final GC gc, final String text, final int x, final int y, final int width, final int height) { Point size = canvas.getSize(); Point extent = gc.textExtent(text); gc.setClipping(x, y, width, height); int xx = x + (width - extent.x) / 2; int yy = y + height / 2 - extent.y / 2; gc.drawText(text, xx, yy, true); gc.setClipping(0, 0, size.x, size.y); }
Example 9
Source File: AbstractGraphicalContentProvider.java From eclipsegraphviz with Eclipse Public License 1.0 | 5 votes |
public Image createErrorImage(Display display, Point size, IStatus status) { Image errorImg = new Image(display, size.x, size.y); GC gc = new GC(errorImg); StringBuffer output = new StringBuffer("Errors generating an image."); if (!status.isOK()) output.append("More details in the log file."); output.append("\n\n"); gc.drawText(renderMessage(status, output), 10, 10); gc.dispose(); return errorImg; }
Example 10
Source File: Chips.java From nebula with Eclipse Public License 2.0 | 5 votes |
private int drawText(final GC gc, final int x) { final Point textSize = gc.stringExtent(text); Color color = null; if (cursorInside) { color = hoverForeground; } else if (isPush && selection) { color = pushedStateForeground; } color = color == null ? getForeground() : color; gc.setForeground(color); gc.drawText(text, x + 2, (getClientArea().height - textSize.y) / 2, true); return x + 2 + textSize.x; }
Example 11
Source File: NebulaSlider.java From nebula with Eclipse Public License 2.0 | 5 votes |
private void drawSelector(GC gc) { final Rectangle rect = getClientArea(); gc.setForeground(selectorColorBorder); gc.setBackground(selectorColor); final int y = (rect.height - SELECTOR_HEIGHT) / 2; // Draw the body gc.fillRoundRectangle(H_MARGIN + xPosition, y, SELECTOR_WIDTH, SELECTOR_HEIGHT, SELECTOR_HEIGHT, SELECTOR_HEIGHT); gc.drawRoundRectangle(H_MARGIN + xPosition, y, SELECTOR_WIDTH, SELECTOR_HEIGHT, SELECTOR_HEIGHT, SELECTOR_HEIGHT); // Draw the arrows gc.setForeground(arrowColor); gc.setLineWidth(3); final int baseY = y + SELECTOR_HEIGHT / 2; gc.drawLine(H_MARGIN + xPosition + 10, baseY, H_MARGIN + xPosition + 17, baseY - 7); gc.drawLine(H_MARGIN + xPosition + 10, baseY, H_MARGIN + xPosition + 17, baseY + 7); gc.drawLine(H_MARGIN + xPosition + SELECTOR_WIDTH - 10, baseY, H_MARGIN + xPosition + SELECTOR_WIDTH - 17, baseY - 7); gc.drawLine(H_MARGIN + xPosition + SELECTOR_WIDTH - 10, baseY, H_MARGIN + xPosition + SELECTOR_WIDTH - 17, baseY + 7); // And the value gc.setForeground(selectorTextColor); gc.setFont(textFont); final String valueAsString = String.valueOf(value); final Point textSize = gc.textExtent(valueAsString); final int xText = H_MARGIN + xPosition + SELECTOR_WIDTH / 2; gc.drawText(valueAsString, xText - textSize.x / 2, y + 2, true); }
Example 12
Source File: EnterPrintDialog.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private void repaint( GC gc, int width, int height ) { ImageData imd = image.getImageData(); double sizeOnPaperX = imd.width * factorx; double sizeOnPaperY = imd.height * factory; double actualSizeX = sizeOnPaperX * scale / 100; double actualSizeY = sizeOnPaperY * scale / 100; // What % of the screen is filled? // The canvas is nrcols * nrrows nr of pages large. double percentScreenX = actualSizeX / ( page.x * nrcols ); double percentScreenY = actualSizeY / ( page.y * nrrows ); gc.drawImage( image, 0, 0, imd.width, imd.height, 0, 0, (int) ( width * percentScreenX ), (int) ( height * percentScreenY ) ); StringBuilder text = new StringBuilder(); text.append( nrcols ).append( "x" ).append( nrrows ).append( " @ " ).append( scale ).append( "%" ); gc.drawText( text.toString(), 0, 0 ); for ( int c = 1; c < nrcols; c++ ) { gc.drawLine( c * ( width / nrcols ), 0, c * ( width / nrcols ), height ); } for ( int r = 1; r < nrrows; r++ ) { gc.drawLine( 0, r * ( height / nrrows ), width, r * ( height / nrrows ) ); } }
Example 13
Source File: CTree.java From nebula with Eclipse Public License 2.0 | 5 votes |
protected void paintItems(GC gc, Rectangle ebounds) { if(isEmpty()) { if (emptyMessage.length() > 0) { Point bSize = getSize(); Point tSize = gc.textExtent(emptyMessage); gc.setForeground(colors.getItemForegroundNormal()); gc.drawText(emptyMessage, (bSize.x - tSize.x) / 2 - ebounds.x, 4 - ebounds.y); } } else { Image image = new Image(gc.getDevice(), ebounds); GC gc2 = new GC(image); for (Iterator iter = paintedItems.iterator(); iter.hasNext();) { CTreeItem item = (CTreeItem) iter.next(); for(int i = 0; i < item.cells.length; i++) { CTreeCell cell = item.cells[i]; cell.paint(gc, ebounds); Rectangle cb = cell.getClientArea(); gc2.setBackground(getDisplay().getSystemColor(SWT.COLOR_CYAN)); gc2.fillRectangle(ebounds); if(!cb.isEmpty() && cell.paintClientArea(gc2, new Rectangle(0,0,cb.width,cb.height))) { gc.drawImage(image, 0,0,Math.min(ebounds.width, cb.width),Math.min(ebounds.height, cb.height), cb.x-ebounds.x,cb.y-ebounds.y,cb.width,cb.height ); } } } gc2.dispose(); image.dispose(); } }
Example 14
Source File: Splash.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private void drawVersionWarning( GC gc, Display display ) { gc.setBackground( versionWarningBackgroundColor ); gc.setForeground( new Color( display, 65, 65, 65 ) ); gc.drawImage( exclamationImage, 304, 243 ); gc.setFont( devWarningFont ); gc.drawText( BaseMessages.getString( PKG, "SplashDialog.DevelopmentWarning" ), 335, 241, true ); }
Example 15
Source File: ConditionEditor.java From hop with Apache License 2.0 | 5 votes |
public void drawUp( GC gc ) { if ( hover_up ) { gc.setBackground( gray ); gc.fillRectangle( size_up ); } gc.drawRectangle( size_up ); gc.drawText( STRING_UP, size_up.x + 1 + offsetx, size_up.y + 1 + offsety, SWT.DRAW_TRANSPARENT ); }
Example 16
Source File: SquareButton.java From swt-bling with MIT License | 5 votes |
protected void drawText(GC gc, int x, int y) { gc.setFont(font); gc.setForeground(currentFontColor); //Advanced font rendering causes errors with some versions of Lato on //Windows, so set advanced to false while drawing test if windows. AdvancedScope scope = AdvancedGC.advancedScope(gc, !ClientOS.isWindows()); gc.drawText(text, x, y, SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER); scope.complete(); }
Example 17
Source File: TextPainter.java From swt-bling with MIT License | 5 votes |
private int drawTextToken(GC gc, boolean paint, int y, int x, DrawData drawData) { configureForStyle(gc, drawData.token); if (paint) { gc.drawText(drawData.token.getText(), x, y, true); addIfHyperlink(drawData, x, y); } x += drawData.extent.x; return x; }
Example 18
Source File: InnerTagRender.java From translationstudio8 with GNU General Public License v2.0 | 4 votes |
public void draw(GC gc, InnerTagBean innerTagBean, int x, int y) { Point tagSize = calculateTagSize(innerTagBean); if (tag != null && tag.isSelected()) { Color b = gc.getBackground(); gc.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_SELECTION)); gc.fillRectangle(0, 0, tagSize.x, tagSize.y); gc.setBackground(b); } int[] tagAreaPoints = calculateTagArea(tagSize, innerTagBean, x, y); String strInx = String.valueOf(innerTagBean.getIndex()); Color gcBgColor = gc.getBackground(); Color gcFgColor = gc.getForeground(); Font gcFont = gc.getFont(); gc.setFont(TAG_FONT); // gc.setBackground(ColorConfigBean.getInstance().getTm90Color()); // Point p = calculateTagSize(innerTagBean); // gc.fillRectangle(x, y, p.x, p.y); if (innerTagBean.isWrongTag()) { gc.setBackground(ColorConfigBean.getInstance().getWrongTagColor()); } else { gc.setBackground(ColorConfigBean.getInstance().getTagBgColor()); } gc.setForeground(ColorConfigBean.getInstance().getTagFgColor()); gc.fillPolygon(tagAreaPoints); // gc.drawPolygon(tagAreaPoints); if (innerTagBean.isWrongTag()) { gc.setBackground(ColorConfigBean.getInstance().getWrongTagColor()); } else { gc.setBackground(ColorConfigBean.getInstance().getTagBgColor()); } gc.setForeground(ColorConfigBean.getInstance().getTagFgColor()); switch (innerTagBean.getType()) { case START: gc.drawText(strInx, tagAreaPoints[0] + MARGIN_H, tagAreaPoints[1] + MARGIN_V); break; default: gc.drawText(strInx, tagAreaPoints[2] + MARGIN_H, tagAreaPoints[3] + MARGIN_V); break; } gc.setBackground(gcBgColor); gc.setForeground(gcFgColor); gc.setFont(gcFont); }
Example 19
Source File: ConditionEditor.java From pentaho-kettle with Apache License 2.0 | 4 votes |
private Point drawCondition( GC gc, int x, int y, int nr, Condition condition ) { int opx, opy, opw, oph; int cx, cy, cw, ch; opx = x; opy = y; opw = size_and_not.width + 6; oph = size_and_not.height + 2; /* * First draw the operator ... */ if ( nr > 0 ) { String operator = condition.getOperatorDesc(); // Remember the size of the rectangle! size_oper[nr] = new Rectangle( opx, opy, opw, oph ); if ( nr == hover_operator ) { gc.setBackground( gray ); gc.fillRectangle( Real2Screen( size_oper[nr] ) ); gc.drawRectangle( Real2Screen( size_oper[nr] ) ); gc.setBackground( bg ); } gc.drawText( operator, size_oper[nr].x + 2 + offsetx, size_oper[nr].y + 2 + offsety, SWT.DRAW_TRANSPARENT ); } /* * Then draw the condition below, possibly negated! */ String str = condition.toString( 0, true, false ); // don't show the operator! Point p = gc.textExtent( str ); cx = opx + 23; cy = opy + oph + 10; cw = p.x + 5; ch = p.y + 5; // Remember the size of the rectangle! size_cond[nr] = new Rectangle( cx, cy, cw, ch ); if ( nr == hover_condition ) { gc.setBackground( gray ); gc.fillRectangle( Real2Screen( size_cond[nr] ) ); gc.drawRectangle( Real2Screen( size_cond[nr] ) ); gc.setBackground( bg ); } gc.drawText( str, size_cond[nr].x + 2 + offsetx, size_cond[nr].y + 5 + offsety, SWT.DRAW_DELIMITER | SWT.DRAW_TRANSPARENT | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC ); p.x += 0; p.y += 5; return p; }
Example 20
Source File: TextCanvas.java From birt with Eclipse Public License 1.0 | 4 votes |
public void paintControl( PaintEvent pe ) { if ( isEnabled( ) && isFocusControl( ) ) { isFocusIn = true; } Color cForeground = null; Color cBackground = null; if ( this.isEnabled( ) ) { cForeground = getDisplay( ).getSystemColor( SWT.COLOR_LIST_FOREGROUND ); cBackground = getDisplay( ).getSystemColor( SWT.COLOR_LIST_BACKGROUND ); } else { cForeground = getDisplay( ).getSystemColor( SWT.COLOR_DARK_GRAY ); cBackground = getDisplay( ).getSystemColor( SWT.COLOR_WIDGET_BACKGROUND ); } GC gc = pe.gc; if ( isFocusIn ) { gc.setBackground( getDisplay( ).getSystemColor( SWT.COLOR_LIST_SELECTION ) ); gc.setForeground( getDisplay( ).getSystemColor( SWT.COLOR_LIST_SELECTION_TEXT ) ); } else { gc.setBackground( cBackground ); gc.setForeground( cForeground ); } gc.fillRectangle( 0, 0, this.getSize( ).x, this.getSize( ).y ); if ( textFont != null ) { gc.setFont( textFont ); } if ( text != null ) { gc.drawText( text, 2, 2 ); } }