Java 类org.eclipse.draw2d.ScaledGraphics 实例源码

项目:gef-gwt    文件:Thumbnail.java   
/**
 * Starts this updater. This method initializes all the necessary
 * resources and puts this {@link Runnable} on the asynch queue. If this
 * updater is not active or is already running, this method just
 * returns.
 */
public void start() {
    if (!isActive() || isRunning())
        return;

    isRunning = true;
    setDirty(false);
    resetTileValues();

    if (!targetSize.equals(thumbnailImageSize)) {
        resetThumbnailImage();
    }

    if (targetSize.isEmpty())
        return;

    thumbnailGC = new GC(thumbnailImage,
            sourceFigure.isMirrored() ? SWT.RIGHT_TO_LEFT : SWT.NONE);
    thumbnailGraphics = new ScaledGraphics(new SWTGraphics(thumbnailGC));
    thumbnailGraphics.scale(getScaleX());
    thumbnailGraphics.translate(getSourceRectangle().getLocation()
            .negate());

    Color color = sourceFigure.getForegroundColor();
    if (color != null)
        thumbnailGraphics.setForegroundColor(color);
    color = sourceFigure.getBackgroundColor();
    if (color != null)
        thumbnailGraphics.setBackgroundColor(color);
    thumbnailGraphics.setFont(sourceFigure.getFont());

    setScales(targetSize.width / (float) getSourceRectangle().width,
            targetSize.height / (float) getSourceRectangle().height);

    Display.getCurrent().asyncExec(this);
}
项目:cogtool    文件:ScalableFrameFigure.java   
/**
 * Draw the figure to the screen. If the scale is not 1.0, then resize it
 * using a scaled graphics object.
 *
 * Checks with the AView to determine if it should actually draw.
 */
@Override
protected void paintClientArea(Graphics graphics)
{
    if (View.isDrawingOK()) {
        double myScale = getScale();

        // Scale factor is actual size, so no need to scale
        if (myScale == 1.0) {
            super.paintClientArea(graphics);
            paintTempFigure(graphics);
        }

        // Scaling of the canvas needs to be performed
        else if (OSUtils.MACOSX) {
            ScaledGraphics g = new ScaledGraphics(graphics);

            if ((getBorder() != null) &&  ! getBorder().isOpaque()) {
                g.clipRect(getBounds().getCropped(getInsets()));
            }

            // This path causes a couple of bugs -- if the view is zoomed
            // and the contents are scaled (as in the Design Editor),
            // it applies the latter scale first while drawing, then
            // it applies the zoom scale.  This causes thin things to
            // disappear and widget locations to be off in the design view.
            // TODO: eliminate this clause in favor of below when
            //       SWT is fixed on MACOS
            g.scale(myScale);
            g.pushState();
            try {
                paintChildren(g);
                paintTempFigure(g);
            }
            finally {
                g.dispose();
            }
        }
        else {
            // This is simpler and works on the PC
            graphics.scale(myScale);
            graphics.pushState();
            super.paintClientArea(graphics);
            graphics.popState();
            paintTempFigure(graphics);
            graphics.scale(1.0 / myScale);
        }
    }
}