当前位置: 首页>>代码示例>>Java>>正文


Java Graphics2D.translate方法代码示例

本文整理汇总了Java中java.awt.Graphics2D.translate方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics2D.translate方法的具体用法?Java Graphics2D.translate怎么用?Java Graphics2D.translate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.Graphics2D的用法示例。


在下文中一共展示了Graphics2D.translate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: paintComponent

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D) g.create();
    g2d.translate(-getX(), -getY());
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setColor(Color.BLUE);
    int[] xs = new int[points.length];
    int[] ys = new int[points.length];
    for (int i = 0; i < points.length; i++) {
        xs[i] = points[i].x;
        ys[i] = points[i].y;
    }
    g2d.setColor(UIHelper.getColor("NodeConnection.border"));
    g2d.setStroke(new BasicStroke(3));
    g2d.drawPolyline(xs, ys, points.length);
    g2d.setPaint(new GradientPaint(points[0], UIHelper.getColor("NodeConnection.color1"), points[points.length - 1], UIHelper.getColor("NodeConnection.color2")));
    g2d.setStroke(new BasicStroke(1.5f));
    g2d.drawPolyline(xs, ys, points.length);
    g2d.dispose();
}
 
开发者ID:VISNode,项目名称:VISNode,代码行数:22,代码来源:JNodeConnection.java

示例2: runTest

import java.awt.Graphics2D; //导入方法依赖的package包/类
public void runTest(Object ctx, int numReps) {
    FillEllipse2Ds.Context cctx = (FillEllipse2Ds.Context) ctx;
    int size = cctx.size;
    int x = cctx.initX;
    int y = cctx.initY;
    Ellipse2D ellipse = cctx.ellipse;
    Graphics2D g2d = (Graphics2D) cctx.graphics;
    g2d.translate(cctx.orgX, cctx.orgY);
    Color rCArray[] = cctx.colorlist;
    int ci = cctx.colorindex;
    do {
        if (rCArray != null) {
            g2d.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
        }
        ellipse.setFrame(x, y, size, size);
        g2d.fill(ellipse);
        if ((x -= 3) < 0) x += cctx.maxX;
        if ((y -= 1) < 0) y += cctx.maxY;
    } while (--numReps > 0);
    cctx.colorindex = ci;
    g2d.translate(-cctx.orgX, -cctx.orgY);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:RenderTests.java

示例3: drawFMSImage

import java.awt.Graphics2D; //导入方法依赖的package包/类
private BufferedImage drawFMSImage() {
	BufferedImage fms = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);

	Graphics2D g = fms.createGraphics();
	Composite c = g.getComposite();

	g.setComposite(AlphaComposite.getInstance(
					AlphaComposite.CLEAR, 0));
	g.fillRect(0, 0, size, size);
	g.setComposite(c);

	g.translate(size / 2, size / 2);
	FMSDraw.drawFMS(g, size / 2,
			eq.strike1,
			eq.dip1, 
			eq.rake1, 
			eq.strike2, 
			eq.dip2, 
			eq.rake2);
	return fms;
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:22,代码来源:FocalMechanismSolutionDB.java

示例4: paint

import java.awt.Graphics2D; //导入方法依赖的package包/类
/** Provides the painting logic.  Note that this does not call any of the
 * painting methods of BasicToggleButtonUI */
@Override
public final void paint(Graphics g, JComponent c) {
    
    BasicSlidingTabDisplayerUI.IndexButton b = 
        (BasicSlidingTabDisplayerUI.IndexButton) c;
    
    Graphics2D g2d = (Graphics2D) g;
    
    paintBackground (g2d, b);
    
    Object orientation = b.getOrientation();
    
    AffineTransform tr = g2d.getTransform();
    if (orientation == TabDisplayer.ORIENTATION_EAST) {
         g2d.rotate( Math.PI / 2 ); 
         g2d.translate( 0, - c.getWidth() );
    } else if (orientation == TabDisplayer.ORIENTATION_WEST) {
         g2d.rotate(-Math.PI / 2); 
         g2d.translate(-c.getHeight(), 0);
    }

    paintIconAndText (g2d, b, orientation);
    g2d.setTransform (tr);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:SlidingTabDisplayerButtonUI.java

示例5: paintBorder

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
	Graphics2D g2 = (Graphics2D) g;
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

	g2.translate(x, y);

	if (c.isEnabled()) {
		if (c.isFocusOwner()) {
			g2.setColor(Colors.TEXTFIELD_BORDER_FOCUS);
		} else {
			g2.setColor(Colors.TEXTFIELD_BORDER);
		}
	} else {
		g2.setColor(Colors.TEXTFIELD_BORDER_DISABLED);
	}

	g2.drawRoundRect(0, 0, w - 1, h - 1, RapidLookAndFeel.CORNER_DEFAULT_RADIUS, RapidLookAndFeel.CORNER_DEFAULT_RADIUS);

	g2.translate(-x, -y);
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:22,代码来源:TextFieldBorder.java

示例6: paintMajorTickForVertSlider

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
protected void paintMajorTickForVertSlider(Graphics g, Rectangle tickBounds, int y) {
	if (Math.abs(trackRect.y - y) < 10 || Math.abs(trackRect.y + trackRect.height - y) < 10) {
		return;
	}

	Graphics2D g2 = (Graphics2D) g;

	int curVal = this.slider.getModel().getValue();
	double percentage = (double) curVal / (slider.getModel().getMaximum() - slider.getModel().getExtent());

	if (trackRect.height * percentage > trackRect.height - y) {
		g2.setColor(Colors.SLIDER_TRACK_BACKGROUND);
	} else {
		g2.setColor(Colors.SLIDER_TRACK_BORDER);
	}

	int trackLeft = (int) this.trackRect.getX() + 3;

	g2.translate(-tickBounds.x, 0);
	g2.fillRect(trackLeft, y, 5, 2);
	g2.translate(tickBounds.x, 0);

}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:25,代码来源:SliderUI.java

示例7: toGraphics

import java.awt.Graphics2D; //导入方法依赖的package包/类
/** Paints a given jGraph in a {@link Graphics} object. */
protected void toGraphics(JGraph<?> graph, Graphics2D graphics) {
    Rectangle2D bounds = graph.getGraphBounds();

    graphics.translate(-bounds.getMinX(), -bounds.getMinY());
    double scale = graph.getScale();
    graphics.scale(1.0 / scale, 1.0 / scale);

    graph.toScreen(bounds);

    Object[] selection = graph.getSelectionCells();
    boolean gridVisible = graph.isGridVisible();
    boolean dBuf = graph.isDoubleBuffered();
    graph.setGridVisible(false);
    graph.clearSelection();
    // Turn off double buffering, otherwise everything gets rasterized
    graph.setDoubleBuffered(false);

    graph.paint(graphics);

    graph.setDoubleBuffered(dBuf);
    graph.setSelectionCells(selection);
    graph.setGridVisible(gridVisible);
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:25,代码来源:GraphToVector.java

示例8: paint

import java.awt.Graphics2D; //导入方法依赖的package包/类
public void paint(Graphics2D graphics, boolean source)
{
    int distance = getAdditionalDistance();
    graphics.translate(distance, 0);
    
    shape.paint(graphics, source);
    
    graphics.translate(-distance, 0);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:AttachableAnchorShape.java

示例9: drawCurrentSeg

import java.awt.Graphics2D; //导入方法依赖的package包/类
protected void drawCurrentSeg(Graphics2D g, boolean on) {
		if( currentSeg==null ) return;
		Color color = g.getColor();
		Stroke stroke = g.getStroke();
		AffineTransform at = g.getTransform();
		g.setColor( on ? onColor : offColor );

//		***** GMA 1.5.2: TESTING
//		g.setStroke( new BasicStroke( 1f/ (float)map.getZoom()) );
		g.setStroke( new BasicStroke( 5f/ (float)map.getZoom()) );
//		***** GMA 1.5.2

		double wrap = map.getWrap();
		if( wrap>0. ) {
			g.translate(-wrap, 0.);
			g.draw( currentSeg );
			g.translate(wrap, 0.);
			g.draw( currentSeg );
			g.translate(wrap, 0.);
			g.draw( currentSeg );
		} else {
			g.draw( currentSeg );
		}
		g.setColor(color);
		g.setStroke(stroke);
		g.setTransform( at);
	}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:28,代码来源:ShipData.java

示例10: drawPoints

import java.awt.Graphics2D; //导入方法依赖的package包/类
private void drawPoints(Graphics2D g, int pixWidth, int pixHeight) {
	double sx = 0.0d;
	double sy = 0.0d;
	sx = ((double) pixWidth - LABEL_MARGIN_X) / (maxX - minX);
	sy = ((double) pixHeight - LABEL_MARGIN_Y) / (maxY - minY);

	Graphics2D coordinateSpace = (Graphics2D) g.create();
	coordinateSpace.translate(LABEL_MARGIN_X, LABEL_MARGIN_Y);
	drawGrid(coordinateSpace, -minX, -minY, sx, sy);
	drawPoints(coordinateSpace, -minX, -minY, sx, sy);
	coordinateSpace.dispose();
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:13,代码来源:SimilarityKDistanceVisualization.java

示例11: print

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public int print(java.awt.Graphics g, PageFormat pf, int page) throws PrinterException {
    if (page > 0) {
        // We have only one page, and 'page' is zero-based
        return NO_SUCH_PAGE;
    }

    Graphics2D g2d = (Graphics2D) g;
    
    // User (0,0) is typically outside the imageable area, so we must
    // translate by the X and Y values in the PageFormat to avoid clipping
    g2d.translate(pf.getImageableX(), pf.getImageableY());

    // Scale plots to paper size.
    double scaleX = pf.getImageableWidth() / contentPane.getWidth();
    double scaleY = pf.getImageableHeight() / contentPane.getHeight();
    g2d.scale(scaleX, scaleY);

    // Disable double buffering
    RepaintManager currentManager = RepaintManager.currentManager(this);
    currentManager.setDoubleBufferingEnabled(false);

    // Now we perform our rendering
    contentPane.printAll(g);

    // Enable double buffering
    currentManager.setDoubleBufferingEnabled(true);

    // tell the caller that this page is part of the printed document
    return PAGE_EXISTS;
}
 
开发者ID:takun2s,项目名称:smile_1.5.0_java7,代码行数:32,代码来源:PlotPanel.java

示例12: testAll

import java.awt.Graphics2D; //导入方法依赖的package包/类
static void testAll(Graphics2D g2d) {
    g2d.setTransform(identity);
    g2d.translate(100, 100);
    testPrimitives(g2d);

    g2d.setTransform(identity);
    g2d.scale(10, 10);
    testPrimitives(g2d);

    g2d.setTransform(identity);
    g2d.rotate(Math.PI/6);
    testPrimitives(g2d);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:PgramUserBoundsTest.java

示例13: drawSimpleNumericalLegend

import java.awt.Graphics2D; //导入方法依赖的package包/类
/** This method can be used to draw a legend on the given graphics context. */
public void drawSimpleNumericalLegend(Graphics graphics, int x, int y, String legendColumnName, String minColorString,
		String maxColorString) {
	Graphics2D g = (Graphics2D) graphics.create();

	// painting label name
	g.setFont(LABEL_FONT_BOLD);
	g.setColor(Color.black);
	g.drawString(legendColumnName, x, y + 1);
	Rectangle2D legendNameBounds = LABEL_FONT.getStringBounds(legendColumnName, g.getFontRenderContext());
	g.translate(legendNameBounds.getWidth() + 5, 0);

	// painting legend
	g.setFont(LABEL_FONT);
	g.setColor(Color.black);
	Rectangle2D minStringBounds = LABEL_FONT.getStringBounds(minColorString, g.getFontRenderContext());

	int keyX = x;
	int keyY = y;

	g.drawString(minColorString, keyX, keyY + 1);
	keyX += minStringBounds.getWidth() + 5;
	for (int i = 0; i < 100; i++) {
		double scaledColor = i / 100.0d;
		Color lineColor = getColorProvider().getPointColor(scaledColor, 255);
		g.setColor(lineColor);
		g.drawLine(keyX, keyY, keyX, keyY - 8);
		keyX++;
	}
	g.setColor(Color.black);
	Rectangle2D frame = new Rectangle2D.Double(keyX - 101, keyY - 8, 101, 8);
	g.draw(frame);
	keyX += 4;
	g.drawString(maxColorString, keyX, keyY + 1);
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:36,代码来源:PlotterAdapter.java

示例14: paintAndrewsPlot

import java.awt.Graphics2D; //导入方法依赖的package包/类
public void paintAndrewsPlot(Graphics g) {
	int pixWidth = getWidth() - 2 * MARGIN;
	int pixHeight = getHeight() - 2 * MARGIN;

	// translate to ignore margins
	Graphics2D translated = (Graphics2D) g.create();
	translated.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	translated.translate(MARGIN, MARGIN);

	// prepare data ...
	prepareData();

	// legend
	if ((colorColumn != -1) && !Double.isInfinite(minColor) && !Double.isInfinite(maxColor)
			&& (dataTable.isNominal(colorColumn) || (minColor != maxColor)) && (lines.size() > 0)) {
		drawLegend(g, dataTable, colorColumn);
	}

	// draw grid, lines, etc.
	if (lines.size() == 0) {
		translated.drawString("No plots selected.", 0, 0);
	} else {
		g.setColor(Color.black);
		draw(translated, pixWidth, pixHeight);
	}
	translated.dispose();
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:28,代码来源:AndrewsCurves.java

示例15: paintBackground

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
 * Paints the background.
 */
protected void paintBackground(Graphics g)
{
	if (graphComponent != null)
	{
		Graphics2D g2 = (Graphics2D) g;
		AffineTransform tx = g2.getTransform();

		try
		{
			// Draws the background of the outline if a graph exists 
			g.setColor(graphComponent.getPageBackgroundColor());
			mxUtils.fillClippedRect(g, 0, 0, getWidth(), getHeight());

			g2.translate(translate.x, translate.y);
			g2.scale(scale, scale);

			// Draws the scaled page background
			if (!graphComponent.isPageVisible())
			{
				Color bg = graphComponent.getBackground();

				if (graphComponent.getViewport().isOpaque())
				{
					bg = graphComponent.getViewport().getBackground();
				}

				g.setColor(bg);
				Dimension size = graphComponent.getGraphControl().getSize();

				// Paints the background of the drawing surface
				mxUtils.fillClippedRect(g, 0, 0, size.width, size.height);
				g.setColor(g.getColor().darker().darker());
				g.drawRect(0, 0, size.width, size.height);
			}
			else
			{
				// Paints the page background using the graphics scaling
				graphComponent.paintBackgroundPage(g);
			}
		}
		finally
		{
			g2.setTransform(tx);
		}
	}
	else
	{
		// Draws the background of the outline if no graph exists 
		g.setColor(getBackground());
		mxUtils.fillClippedRect(g, 0, 0, getWidth(), getHeight());
	}
}
 
开发者ID:GDSRS,项目名称:TrabalhoFinalEDA2,代码行数:56,代码来源:mxGraphOutline.java


注:本文中的java.awt.Graphics2D.translate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。