org.eclipse.swt.graphics.GC Java Examples
The following examples show how to use
org.eclipse.swt.graphics.GC.
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: VerticalIndentGuidesPainter.java From Pydev with Eclipse Public License 1.0 | 6 votes |
private AutoCloseable configGC(final GC gc) { final int lineStyle = gc.getLineStyle(); final int alpha = gc.getAlpha(); final int[] lineDash = gc.getLineDash(); final Color foreground = gc.getForeground(); final Color background = gc.getBackground(); gc.setForeground(this.indentGuide.getColor(styledText)); gc.setBackground(styledText.getBackground()); gc.setAlpha(this.indentGuide.getTransparency()); gc.setLineStyle(SWT.LINE_CUSTOM); gc.setLineDash(new int[] { 1, 2 }); return new AutoCloseable() { @Override public void close() throws Exception { gc.setForeground(foreground); gc.setBackground(background); gc.setAlpha(alpha); gc.setLineStyle(lineStyle); gc.setLineDash(lineDash); } }; }
Example #2
Source File: SwitchButton.java From gama with GNU General Public License v3.0 | 6 votes |
/** * @see org.eclipse.swt.widgets.Composite#computeSize(int, int, boolean) */ @Override public Point computeSize(final int wHint, final int hHint, final boolean changed) { this.checkWidget(); boolean disposeGC = false; if (this.gc == null || this.gc.isDisposed()) { this.gc = new GC(this); disposeGC = true; } final Point buttonSize = this.computeButtonSize(); int width = buttonSize.x; int height = buttonSize.y; if (this.text != null && this.text.trim().length() > 0) { final Point textSize = this.gc.textExtent(this.text); width += textSize.x + this.gap + 1; } width += 6; height += 6; if (disposeGC) { this.gc.dispose(); } return new Point(width, height); }
Example #3
Source File: TextUtils.java From nebula with Eclipse Public License 2.0 | 6 votes |
private static String getShortStringTruncatedInTheEnd(GC gc, String text, int width) { char[] chars = text.toCharArray(); int calcWidth = gc.stringExtent("...").x; int index = 0; int length = chars.length; while (calcWidth < width && index < length) { int step = gc.getCharWidth(chars[index]); calcWidth += step; if (calcWidth >= width) { break; } index++; } if (index == length - 1) { return text; } StringBuilder sb = new StringBuilder(index + 4); if (index > 4) { sb.append(text.substring(0, index - 4)); } else { sb.append(text.substring(0, 1)); } sb.append("..."); return sb.toString(); }
Example #4
Source File: GridItem.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
/** * Sets the receiver's row header image. If the image is <code>null</code> * none is shown in the header * * @param image * the new image * @throws org.eclipse.swt.SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed * </li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the * thread that created the receiver</li> * </ul> */ public void setHeaderImage(Image image) { checkWidget(); // if (text == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (image != headerImage) { GC gc = new GC(parent); int oldWidth = parent.getRowHeaderRenderer().computeSize(gc, SWT.DEFAULT, SWT.DEFAULT, this).x; int oldHeight = parent.getRowHeaderRenderer().computeSize(gc, SWT.DEFAULT, SWT.DEFAULT, this).y; this.headerImage = image; int newWidth = parent.getRowHeaderRenderer().computeSize(gc, SWT.DEFAULT, SWT.DEFAULT, this).x; int newHeight = parent.getRowHeaderRenderer().computeSize(gc, SWT.DEFAULT, SWT.DEFAULT, this).y; gc.dispose(); parent.recalculateRowHeaderWidth(this, oldWidth, newWidth); parent.recalculateRowHeaderHeight(this, oldHeight, newHeight); } parent.redraw(); }
Example #5
Source File: TextPainter.java From swt-bling with MIT License | 6 votes |
int drawLeftJustified(GC gc, boolean paint, List<DrawData> line, int y) { int maxY = 0; if (line.size() > 0) { int startIndex = getStartIndex(line); int x = bounds.x + paddingLeft; for (int i = startIndex; i < line.size(); i++) { DrawData drawData = line.get(i); x = drawTextToken(gc, paint, y, x, drawData); if (drawData.extent.y > maxY) { maxY = drawData.extent.y; } } } return maxY; }
Example #6
Source File: SaveImageAction.java From olca-app with Mozilla Public License 2.0 | 6 votes |
@Override public void run() { if (file == null) return; log.trace("export product graph as image: {}", file); ScalableRootEditPart editPart = (ScalableRootEditPart) editor.getGraphicalViewer().getRootEditPart(); IFigure rootFigure = editPart.getLayer(LayerConstants.PRINTABLE_LAYERS); Rectangle bounds = rootFigure.getBounds(); Image img = new Image(null, bounds.width, bounds.height); GC imageGC = new GC(img); Graphics graphics = new SWTGraphics(imageGC); rootFigure.paint(graphics); ImageLoader imgLoader = new ImageLoader(); imgLoader.data = new ImageData[] { img.getImageData() }; imgLoader.save(file.getAbsolutePath(), SWT.IMAGE_PNG); }
Example #7
Source File: Edge.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * draw temporary labels for external nodes (and save their bounds for later) */ private List<Rectangle> drawTemporaryLabels(GC gc) { final List<Rectangle> nodesExternalBounds = new ArrayList<>(); final Rectangle clip = GraphUtils.getClip(gc); float px = clip.x + clip.width; float py = clip.y + clip.height; for (String currNE : endNodesExternal) { final org.eclipse.swt.graphics.Point size = gc.stringExtent(currNE); py -= size.y + 4; final float rx = px - (size.x + 4); final Rectangle b = new Rectangle(rx, py, size.x, size.y); nodesExternalBounds.add(b); // TODO string extent will be computed twice :( GraphUtils.drawString(gc, currNE, b.x + b.width / 2, b.y + b.height / 2); } return nodesExternalBounds; }
Example #8
Source File: TextCellRenderer.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
/** * Draw a String in the drawing area, splitting it into multiple lines. * * @param gc gc * @param rect drawing area * @param s String to draw * @param cellStyle cell style determing alignment */ private void drawCellStringMulti(GC gc, Rectangle rect, String s, ICellStyle cellStyle) { int halign = TextRenderer.LEFT; if (cellStyle.getHorizontalAlignment() == ITableViewState.HAlignment.RIGHT) { halign = TextRenderer.RIGHT; } else if (cellStyle.getHorizontalAlignment() == ITableViewState.HAlignment.CENTER) { halign = TextRenderer.CENTER; } int valign = TextRenderer.TOP; if (cellStyle.getVerticalAlignment() == ITableViewState.VAlignment.BOTTOM) { valign = TextRenderer.BOTTOM; } else if (cellStyle.getVerticalAlignment() == ITableViewState.VAlignment.CENTER) { valign = TextRenderer.CENTER; } TextRenderer.renderText(gc, rect, true, false, s, halign, valign); }
Example #9
Source File: CustomCombo.java From nebula with Eclipse Public License 2.0 | 6 votes |
public Point computeSize(int wHint, int hHint, boolean changed) { checkWidget(); int width = 0, height = 0; String[] items = list.getItems(); GC gc = new GC(text); int spacer = gc.stringExtent(" ").x; //$NON-NLS-1$ int textWidth = gc.stringExtent(text.getText()).x; for (int i = 0; i < items.length; i++) { textWidth = Math.max(gc.stringExtent(items[i]).x, textWidth); } gc.dispose(); Point textSize = text.computeSize(SWT.DEFAULT, SWT.DEFAULT, changed); Point arrowSize = arrow.computeSize(SWT.DEFAULT, SWT.DEFAULT, changed); Point listSize = list.computeSize(SWT.DEFAULT, SWT.DEFAULT, changed); int borderWidth = getBorderWidth(); height = Math.max(textSize.y, arrowSize.y); width = Math.max(textWidth + 2 * spacer + arrowSize.x + 2 * borderWidth, listSize.x); if (wHint != SWT.DEFAULT) width = wHint; if (hHint != SWT.DEFAULT) height = hHint; return new Point(width + 2 * borderWidth, height + 2 * borderWidth); }
Example #10
Source File: BreadcrumbItem.java From SWET with MIT License | 6 votes |
private Point computeSizeOfTextAndImages() { int width = 0, height = 0; final boolean textISNotEmpty = getText() != null && !getText().equals(""); if (textISNotEmpty) { final GC gc = new GC(this.parentBreadcrumb); gc.setFont(this.parentBreadcrumb.getFont()); final Point extent = gc.stringExtent(getText()); gc.dispose(); width += extent.x; height = extent.y; } final Point imageSize = computeMaxWidthAndHeightForImages(getImage(), this.selectionImage, this.disabledImage); if (imageSize.x != -1) { width += imageSize.x; height = Math.max(imageSize.y, height); if (textISNotEmpty) { width += MARGIN * 2; } } width += MARGIN; return new Point(width, height); }
Example #11
Source File: PlaceBidOrderWizard.java From offspring with MIT License | 6 votes |
@Override public Control createReadonlyControl(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); GridLayoutFactory.fillDefaults().numColumns(2).spacing(10, 0) .margins(0, 0).applyTo(composite); textPriceReadonly = new Text(composite, SWT.BORDER); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER) .grab(true, false).applyTo(textPriceReadonly); textPriceReadonly.setText(""); labelPriceTotalReadonly = new Label(composite, SWT.NONE); GC gc = new GC(labelPriceTotalReadonly); GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER) .hint(gc.textExtent(THIRD_COLUMN).x, SWT.DEFAULT) .applyTo(labelPriceTotalReadonly); gc.dispose(); labelPriceTotalReadonly.setText("0.0"); return composite; // textPriceReadonly = new Text(parent, SWT.BORDER); // textPriceReadonly.setEditable(false); // return textPriceReadonly; }
Example #12
Source File: IndentGuidePainter.java From IndentGuide with MIT License | 6 votes |
/** * Creates a new painter for the given text viewer. * * @param textViewer * the text viewer the painter should be attached to */ public IndentGuidePainter(ITextViewer textViewer) { super(); fTextViewer = textViewer; fTextWidget = textViewer.getTextWidget(); GC gc = new GC(fTextWidget); gc.setAdvanced(true); fIsAdvancedGraphicsPresent = gc.getAdvanced(); gc.dispose(); IPreferenceStore store = Activator.getDefault().getPreferenceStore(); lineAlpha = store.getInt(PreferenceConstants.LINE_ALPHA); lineStyle = store.getInt(PreferenceConstants.LINE_STYLE); lineWidth = store.getInt(PreferenceConstants.LINE_WIDTH); lineShift = store.getInt(PreferenceConstants.LINE_SHIFT); drawLeftEnd = store.getBoolean(PreferenceConstants.DRAW_LEFT_END); drawBlankLine = store.getBoolean(PreferenceConstants.DRAW_BLANK_LINE); skipCommentBlock = store .getBoolean(PreferenceConstants.SKIP_COMMENT_BLOCK); }
Example #13
Source File: MenuItemProviders.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
public static IMenuItemProvider autoResizeAllSelectedColumnMenuItemProvider() { return new IMenuItemProvider() { public void addMenuItem(final NatTable natTable, final Menu popupMenu) { MenuItem autoResizeColumns = new MenuItem(popupMenu, SWT.PUSH); autoResizeColumns.setText("Auto resize all selected columns"); autoResizeColumns.setEnabled(true); autoResizeColumns.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { int columnPosition = getNatEventData(event).getColumnPosition(); natTable.doCommand(new InitializeAutoResizeColumnsCommand(natTable, columnPosition, natTable.getConfigRegistry(), new GC(natTable))); } }); } }; }
Example #14
Source File: AbstractEllipseContainmentExample.java From gef with Eclipse Public License 2.0 | 6 votes |
@Override protected AbstractControllableShape createControllableShape1( Canvas canvas) { return new AbstractControllableShape(canvas) { @Override public void createControlPoints() { // the ellipse does not have any control points } @Override public Ellipse createGeometry() { double w5 = getCanvas().getClientArea().width / 5; double h5 = getCanvas().getClientArea().height / 5; return new Ellipse(w5, h5, 3 * w5, 3 * h5); } @Override public void drawShape(GC gc) { Ellipse ellipse = createGeometry(); gc.drawOval((int) ellipse.getX(), (int) ellipse.getY(), (int) ellipse.getWidth(), (int) ellipse.getHeight()); } }; }
Example #15
Source File: TargetColunmCellRenderer.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
/** * {@inheritDoc} */ public Rectangle getTextBounds(GridItem item, boolean preferred) { int x = leftMargin; 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: MenuItemProviders.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
public static IMenuItemProvider autoResizeColumnMenuItemProvider() { return new IMenuItemProvider() { public void addMenuItem(final NatTable natTable, final Menu popupMenu) { MenuItem autoResizeColumns = new MenuItem(popupMenu, SWT.PUSH); autoResizeColumns.setText("Auto resize column"); autoResizeColumns.setImage(GUIHelper.getImage("auto_resize")); autoResizeColumns.setEnabled(true); autoResizeColumns.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { int columnPosition = getNatEventData(event).getColumnPosition(); natTable.doCommand(new InitializeAutoResizeColumnsCommand(natTable, columnPosition, natTable.getConfigRegistry(), new GC(natTable))); } }); } }; }
Example #17
Source File: BasicGridLookPainter.java From nebula with Eclipse Public License 2.0 | 6 votes |
private void paintHeaderRow(GC gc, int x, int y, int[] columns, final int h, int rowIndex, int[] colSpans) { GridMargins margins = getMargins(); int col = 0; for (int i = 0; i < colSpans.length; i++) { final int colSpan = colSpans[i]; final int w = sum(columns, col, colSpan) + (colSpan - 1) * margins.getHorizontalSpacing(); paintHeaderCell(gc, new Rectangle(x, y, w, h), rowIndex, col, colSpan); col += colSpan; x += w + margins.getHorizontalSpacing(); } }
Example #18
Source File: BookmarkRulerColumn.java From xds-ide with Eclipse Public License 1.0 | 6 votes |
/** * Draws the ruler column. * * @param gc the GC to draw into * @param visibleLines the visible model lines */ private void doPaint(GC gc, ILineRange visibleLines) { Display display= fCachedTextWidget.getDisplay(); int lastLine = visibleLines.getStartLine() + visibleLines.getNumberOfLines(); int y = -JFaceTextUtil.getHiddenTopLinePixels(fCachedTextWidget); if (mapMarks != null) { for (int line= visibleLines.getStartLine(); line < lastLine; line++) { int widgetLine= JFaceTextUtil.modelLineToWidgetLine(fCachedTextViewer, line); if (widgetLine == -1) continue; int lineHeight= fCachedTextWidget.getLineHeight(fCachedTextWidget.getOffsetAtLine(widgetLine)); if (mapMarks != null && mapMarks.containsKey(line)) { paintLine(line, mapMarks.get(line), y, lineHeight, gc, display); } y += lineHeight; } } }
Example #19
Source File: PWTabContainer.java From nebula with Eclipse Public License 2.0 | 6 votes |
/** * Create the background of the container */ private void createButtonsContainerBackground() { buttonContainer.addListener(SWT.Resize, event -> { final Rectangle rect = buttonContainer.getClientArea(); final Image image = new Image(getDisplay(), Math.max(1, rect.width), Math.max(1, rect.height)); final GC gc = new GC(image); final Color grey = new Color(getDisplay(), 204, 204, 204); gc.setForeground(grey); gc.drawLine(0, rect.height - 1, rect.width, rect.height - 1); grey.dispose(); gc.dispose(); buttonContainer.setBackgroundImage(image); if (oldButtonContainerImage != null) { oldButtonContainerImage.dispose(); } oldButtonContainerImage = image; }); SWTGraphicUtil.addDisposer(buttonContainer, oldButtonContainerImage); }
Example #20
Source File: MenuItemProviders.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
public static IMenuItemProvider autoResizeColumnMenuItemProvider() { return new IMenuItemProvider() { public void addMenuItem(final NatTable natTable, final Menu popupMenu) { MenuItem autoResizeColumns = new MenuItem(popupMenu, SWT.PUSH); autoResizeColumns.setText("Auto resize column"); autoResizeColumns.setImage(GUIHelper.getImage("auto_resize")); autoResizeColumns.setEnabled(true); autoResizeColumns.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { int columnPosition = getNatEventData(event).getColumnPosition(); natTable.doCommand(new InitializeAutoResizeColumnsCommand(natTable, columnPosition, natTable.getConfigRegistry(), new GC(natTable))); } }); } }; }
Example #21
Source File: SWTGraphics2D.java From openstock with GNU General Public License v3.0 | 5 votes |
/** * Creates a new instance. * * @param gc the graphics context. */ public SWTGraphics2D(GC gc) { super(); this.gc = gc; this.hints = new RenderingHints(null); this.composite = AlphaComposite.getInstance(AlphaComposite.SRC, 1.0f); setStroke(new BasicStroke()); }
Example #22
Source File: PieUtils.java From BiglyBT with GNU General Public License v2.0 | 5 votes |
public static void drawPie(GC gc,int x, int y,int width,int height,int percent) { Color background = gc.getBackground(); gc.setForeground(Colors.blue); int angle = (percent * 360) / 100; if(angle<4) angle = 0; // workaround fillArc rendering bug gc.setBackground(Colors.white); gc.fillArc(x,y,width,height,0,360); gc.setBackground(background); gc.fillArc(x,y,width,height,90,angle*-1); gc.drawOval(x , y , width-1, height-1); }
Example #23
Source File: HSDropDownButton.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
public String getSpaceByWidth(int width) { GC gc = new GC(Display.getDefault()); int spaceWidth = gc.getAdvanceWidth(' '); gc.dispose(); int spacecount = width / spaceWidth; StringBuilder b = new StringBuilder(); while (spacecount-- > 0) { b.append(" "); } return b.toString(); }
Example #24
Source File: SvgContainer.java From nebula with Eclipse Public License 2.0 | 5 votes |
public void apply(GC gc) { for(SvgElement element : elements) { if(element instanceof SvgGraphic) { ((SvgGraphic) element).apply(gc); } } }
Example #25
Source File: ImagePainter.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
@Override public void paintCell(LayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) { if (paintBg) { super.paintCell(cell, gc, bounds, configRegistry); } Image image = getImage(cell, configRegistry); if (image != null) { Rectangle imageBounds = image.getBounds(); IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry); gc.drawImage(image, bounds.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, bounds, imageBounds.width), bounds.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, bounds, imageBounds.height)); } }
Example #26
Source File: CFEdge.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** Sets the color of the {@link GC} depending on the edge type. */ void setColor(GC gc) { Display displ = Display.getCurrent(); Color color = GraphUtils.getColor(50, 50, 50); if (isDead || cfTypes.contains(ControlFlowType.DeadCode)) { color = displ.getSystemColor(SWT.COLOR_GRAY); } else { for (ControlFlowType cfType : cfTypes) { switch (cfType) { case LoopEnter: case LoopReenter: case LoopInfinite: case Break: case Continue: case Return: color = displ.getSystemColor(SWT.COLOR_BLUE); break; case Throw: color = displ.getSystemColor(SWT.COLOR_RED); break; default: break; } } } gc.setForeground(color); }
Example #27
Source File: TwisteToggleRenderer.java From nebula with Eclipse Public License 2.0 | 5 votes |
public void paint(GC gc, Object value) { Transform transform = new Transform(gc.getDevice()); transform.translate(getBounds().x, getBounds().y); gc.setTransform(transform); Color back = gc.getBackground(); Color fore = gc.getForeground(); if (!isHover()) { gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW)); } else { gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_LIST_SELECTION)); } gc.setBackground(gc.getForeground()); if (isExpanded()) { gc.drawPolygon(new int[] {1, 3, 4, 6, 5, 6, 8, 3 }); gc.fillPolygon(new int[] {1, 3, 4, 6, 5, 6, 8, 3 }); } else { gc.drawPolygon(new int[] {3, 1, 6, 4, 6, 5, 3, 8 }); gc.fillPolygon(new int[] {3, 1, 6, 4, 6, 5, 3, 8 }); } if (isFocus()) { gc.setBackground(back); gc.setForeground(fore); gc.drawFocus(-1, -1, 12, 12); } gc.setTransform(null); transform.dispose(); }
Example #28
Source File: LineNumberPainter.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
public void paintCell(LayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) { Rectangle cellBounds = cell.getBounds(); // Color backgroundColor = CellStyleUtil.getCellStyle(cell, // configRegistry).getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR); // if (backgroundColor != null) { Color originalBackground = gc.getBackground(); gc.setBackground(GUIHelper.COLOR_WIDGET_BACKGROUND); gc.fillRectangle(bounds); gc.setBackground(originalBackground); // } if (checkSplit(cell, configRegistry)) { // Color originalBackground = gc.getBackground(); // gc.setBackground(GUIHelper.COLOR_RED); // gc.fillRectangle(cellBounds); // gc.setBackground(originalBackground); // gc.setBackgroundPattern(new Pattern(Display.getCurrent(), // XliffEditorGUIHelper.getImage(XliffEditorGUIHelper.ImageName.SPLITPOINT))); Image image = XliffEditorGUIHelper.getImage(XliffEditorGUIHelper.ImageName.SPLITPOINT); gc.drawImage(image, cellBounds.width / 2 - image.getBounds().width / 2, cellBounds.y + cellBounds.height / 2 - image.getBounds().height / 2); // gc.setBackgroundPattern(null); // // } // else { } super.paintCell(cell, gc, bounds, configRegistry); }
Example #29
Source File: SourceViewerInformationControl.java From goclipse with Eclipse Public License 1.0 | 5 votes |
@Override public Point computeSizeConstraints(int widthInChars, int heightInChars) { GC gc= new GC(fText); gc.setFont(fTextFont); int width= gc.getFontMetrics().getAverageCharWidth(); int height= fText.getLineHeight(); //https://bugs.eclipse.org/bugs/show_bug.cgi?id=377109 gc.dispose(); return new Point(widthInChars * width, heightInChars * height); }
Example #30
Source File: DiskMapTab.java From AppleCommander with GNU General Public License v2.0 | 5 votes |
/** * Paint a map with the given dimensions. */ private void paintDiskMap(int xdim, int ydim, PaintEvent event) { Canvas canvas = (Canvas) event.widget; Rectangle area = canvas.getClientArea(); area.width-= 2; area.height-= 2; int[] ypos = new int[ydim + 1]; for (int i=0; i<ydim; i++) { ypos[i] = (i * area.height) / ydim + 1; } ypos[ydim] = area.height; int[] xpos = new int[xdim + 1]; for (int i=0; i<xdim; i++) { xpos[i] = (i * area.width) / xdim + 1; } xpos[xdim] = area.width; Image image = new Image(canvas.getDisplay(), area); GC gc = new GC(image); int x = 0; int y = 0; DiskUsage usage = disk.getDiskUsage(); for (x=0; x<xdim && usage.hasNext(); x++) { for (y=0; y<ydim && usage.hasNext(); y++) { usage.next(); boolean free = usage.isFree(); Rectangle box = new Rectangle(xpos[x], ypos[y], xpos[x+1]-xpos[x], ypos[y+1]-ypos[y]); drawBox(box, gc, free ? freeFill : usedFill, black, gray); } } event.gc.drawImage(image, 0, 0); gc.dispose(); image.dispose(); }