Java Code Examples for java.awt.Graphics2D.getStroke()

The following are Jave code examples for showing how to use getStroke() of the java.awt.Graphics2D class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Tarski   File: mxEdgeHandler.java   View Source Code Vote up 7 votes
/**
 * 
 */
public void paint(Graphics g) {
  Graphics2D g2 = (Graphics2D) g;

  Stroke stroke = g2.getStroke();
  g2.setStroke(getSelectionStroke());
  g.setColor(getSelectionColor());

  Point last = state.getAbsolutePoint(0).getPoint();

  for (int i = 1; i < state.getAbsolutePointCount(); i++) {
    Point current = state.getAbsolutePoint(i).getPoint();
    Line2D line = new Line2D.Float(last.x, last.y, current.x, current.y);

    Rectangle bounds = g2.getStroke().createStrokedShape(line).getBounds();

    if (g.hitClip(bounds.x, bounds.y, bounds.width, bounds.height)) {
      g2.draw(line);
    }

    last = current;
  }

  g2.setStroke(stroke);
  super.paint(g);
}
 
Example 2
Project: MapAnalyst   File: MapRectangleImpl.java   View Source Code Vote up 6 votes
@Override
public void paint(Graphics g, Point topLeft, Point bottomRight) {
    // Prepare graphics
    Color oldColor = g.getColor();
    g.setColor(getColor());
    Stroke oldStroke = null;
    if (g instanceof Graphics2D) {
        Graphics2D g2 = (Graphics2D) g;
        oldStroke = g2.getStroke();
        g2.setStroke(getStroke());
    }
    // Draw
    g.drawRect(topLeft.x, topLeft.y, bottomRight.x - topLeft.x, bottomRight.y - topLeft.y);
    // Restore graphics
    g.setColor(oldColor);
    if (g instanceof Graphics2D) {
        ((Graphics2D) g).setStroke(oldStroke);
    }
    int width = bottomRight.x-topLeft.x;
    int height = bottomRight.y-topLeft.y;
    Point p = new Point(topLeft.x+(width/2), topLeft.y+(height/2));
    if (getLayer() == null || getLayer().isVisibleTexts()) paintText(g, p);
}
 
Example 3
Project: TrabalhoFinalEDA2   File: mxGraphOutline.java   View Source Code Vote up 6 votes
/**
 * Paints the foreground. Foreground is dynamic and should never be made
 * part of the triple buffer. It is painted on top of the buffer.
 */
protected void paintForeground(Graphics g)
{
	if (graphComponent != null)
	{
		Graphics2D g2 = (Graphics2D) g;

		Stroke stroke = g2.getStroke();
		g.setColor(Color.BLUE);
		g2.setStroke(new BasicStroke(3));
		g.drawRect(finderBounds.x, finderBounds.y, finderBounds.width,
				finderBounds.height);

		if (zoomHandleVisible)
		{
			g2.setStroke(stroke);
			g.setColor(DEFAULT_ZOOMHANDLE_FILL);
			g.fillRect(finderBounds.x + finderBounds.width - 6, finderBounds.y
					+ finderBounds.height - 6, 8, 8);
			g.setColor(Color.BLACK);
			g.drawRect(finderBounds.x + finderBounds.width - 6, finderBounds.y
					+ finderBounds.height - 6, 8, 8);
		}
	}
}
 
Example 4
Project: VASSAL-src   File: SelectionHighlighter.java   View Source Code Vote up 6 votes
public void draw(GamePiece p, Graphics g, int x, int y, Component obs, double zoom) {
  final Graphics2D g2d = (Graphics2D) g;
  if (accept(p)) {
    if (useImage) {
      final int x1 = x - (int) (imagePainter.getImageSize().width * zoom / 2);
      final int y1 = y - (int) (imagePainter.getImageSize().height * zoom / 2);
      imagePainter.draw(g, x1, y1, zoom, obs);
    }
    else {
      if (color == null || thickness <= 0) {
        return;
      }
      final Shape s = p.getShape();
      final Stroke str = g2d.getStroke();
      g2d.setStroke(new BasicStroke(Math.max(1, Math.round(zoom * thickness))));
      g2d.setColor(color);
      final AffineTransform t = AffineTransform.getScaleInstance(zoom, zoom);
      t.translate(x / zoom, y / zoom);
      g2d.draw(t.createTransformedShape(s));
      g2d.setStroke(str);
    }
  }
}
 
Example 5
Project: jdk8u-jdk   File: Underline.java   View Source Code Vote up 6 votes
void drawUnderline(Graphics2D g2d,
                   float thickness,
                   float x1,
                   float x2,
                   float y) {

    Stroke saveStroke = g2d.getStroke();
    g2d.setStroke(stroke);

    Line2D.Float drawLine = new Line2D.Float(x1, y, x2, y);
    g2d.draw(drawLine);

    drawLine.y1 += DEFAULT_THICKNESS;
    drawLine.y2 += DEFAULT_THICKNESS;
    drawLine.x1 += DEFAULT_THICKNESS;

    g2d.draw(drawLine);

    g2d.setStroke(saveStroke);
}
 
Example 6
Project: openjdk-jdk10   File: BlockWidget.java   View Source Code Vote up 6 votes
@Override
protected void paintWidget() {
    super.paintWidget();
    Graphics2D g = this.getGraphics();
    Stroke old = g.getStroke();
    g.setColor(Color.BLUE);
    Rectangle r = new Rectangle(this.getPreferredBounds());
    r.width--;
    r.height--;
    if (this.getBounds().width > 0 && this.getBounds().height > 0) {
        g.setStroke(new BasicStroke(2));
        g.drawRect(r.x, r.y, r.width, r.height);
    }

    Color titleColor = Color.BLACK;
    g.setColor(titleColor);
    g.setFont(titleFont);

    String s = "B" + blockNode.getName();
    Rectangle2D r1 = g.getFontMetrics().getStringBounds(s, g);
    g.drawString(s, r.x + 5, r.y + (int) r1.getHeight());
    g.setStroke(old);
}
 
Example 7
Project: QN-ACTR-Release   File: PainterConvex2D.java   View Source Code Vote up 6 votes
/**
 * Draw a semi-trasparet area
 * @param g The graphic object
 * @param dragPoint The first point
 * @param beginPoint The second point
 * @param c The color of the area
 */
public void drawDragArea(Graphics2D g, Point dragPoint, Point beginPoint, Color c) {
	g.setColor(c);

	Polygon poly = new Polygon();

	poly.addPoint((int) beginPoint.getX(), (int) beginPoint.getY());
	poly.addPoint((int) beginPoint.getX(), (int) dragPoint.getY());
	poly.addPoint((int) dragPoint.getX(), (int) dragPoint.getY());
	poly.addPoint((int) dragPoint.getX(), (int) beginPoint.getY());

	//Set the widths of the shape's outline
	Stroke oldStro = g.getStroke();
	Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
	g.setStroke(stroke);
	g.drawPolygon(poly);
	g.setStroke(oldStro);

	//Set the trasparency of the iside of the rectangle
	Composite oldComp = g.getComposite();
	Composite alphaComp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f);
	g.setComposite(alphaComp);
	g.fillPolygon(poly);
	g.setComposite(oldComp);

}
 
Example 8
Project: jmt   File: PainterConvex2D.java   View Source Code Vote up 6 votes
/**
 * Draw a semi-trasparent area that is the filtered area
 * @param g The graphic object
 * @param filteredArea The filtered area
 */
public void drawFiltArea(Graphics2D g, Area filtArea) {
	AffineTransform t = new AffineTransform();
	t.scale(scale / 100, scale / 100);
	AffineTransform t2 = new AffineTransform();
	t2.translate(tran_x, tran_y);

	filtArea.transform(t);
	filtArea.transform(t2);

	Stroke oldStro = g.getStroke();
	Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
	g.setStroke(stroke);

	g.setColor(Color.GRAY);
	Composite oldComp = g.getComposite();
	Composite alphaComp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
	g.setComposite(alphaComp);

	g.fill(filtArea);
	g.setComposite(oldComp);
	g.setStroke(oldStro);
}
 
Example 9
Project: brModelo   File: Linha.java   View Source Code Vote up 6 votes
@Override
public void DoPaint(Graphics2D g) {
    super.DoPaint(g);
    Stroke bkp = g.getStroke();

    g.setPaint(getForeColor());
    if (getPontosParaDesenho() != null) {
        if (isDashed()) {
            g.setStroke(new BasicStroke(getLargura(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{1, 2}, 0));
        } else {
            g.setStroke(new BasicStroke(
                    getLargura(),
                    BasicStroke.CAP_ROUND,
                    BasicStroke.JOIN_ROUND));
        }

        g.drawPolyline(pontosParaDesenhoX, pontosParaDesenhoY, pontosParaDesenhoX.length);
    }
    g.setStroke(bkp);
}
 
Example 10
Project: routerapp   File: LineHighlightEffect.java   View Source Code Vote up 6 votes
/**
 * 
 */
public LineHighlightEffect(Shape shape, Graphics2D graphics,
		int length, ViselPane viselPane, boolean continuous) {
	this.shape = shape;
	this.length = length;
	this.graphics = graphics;
	this.viselPane = viselPane;
	this.continuous = continuous;
	
	timer = new Timer(length/10, this);
	duration = 0;
	stroke = (BasicStroke) graphics.getStroke();
	currentLineWidth =
		initialLineWidth = stroke.getLineWidth();
	
}
 
Example 11
Project: VASSAL-src   File: RegionGrid.java   View Source Code Vote up 6 votes
public void paint(Graphics g) {
  Rectangle b = getVisibleRect();
  g.clearRect(b.x, b.y, b.width, b.height);
  myBoard.draw(g, 0, 0, 1.0, this);
  final Rectangle bounds =
    new Rectangle(new Point(),myBoard.bounds().getSize());
  grid.forceDraw(g,bounds,bounds,1.0,false);
  final Rectangle selection = config.getSelectionRect();
  if (selection != null) {
    final Graphics2D g2d = (Graphics2D) g;
    final Stroke str = g2d.getStroke();
    g2d.setStroke(new BasicStroke(2.0f));
    g2d.setColor(Color.RED);
    g2d.drawRect(selection.x, selection.y, selection.width, selection.height);
    g2d.setStroke(str);
  }
}
 
Example 12
Project: litiengine   File: RectangleOutlineParticle.java   View Source Code Vote up 5 votes
@Override
public void render(final Graphics2D g, final Point2D emitterOrigin) {
  final Point2D renderLocation = this.getLocation(emitterOrigin);
  final Stroke oldStroke = g.getStroke();
  g.setColor(this.getColor());
  g.setStroke(new BasicStroke(this.stroke));
  g.draw(new Rectangle2D.Double(renderLocation.getX(), renderLocation.getY(), this.getWidth(), this.getHeight()));
  g.setStroke(oldStroke);
}
 
Example 13
Project: jdk8u-jdk   File: Underline.java   View Source Code Vote up 5 votes
void drawUnderline(Graphics2D g2d,
                   float thickness,
                   float x1,
                   float x2,
                   float y) {


    Stroke saveStroke = g2d.getStroke();
    g2d.setStroke(getStroke(thickness));
    g2d.draw(new Line2D.Float(x1, y + shift, x2, y + shift));
    g2d.setStroke(saveStroke);
}
 
Example 14
Project: brModelo   File: LivreJuncao.java   View Source Code Vote up 5 votes
@Override
protected void DoPaintDoks(Graphics2D g) {
    super.DoPaintDoks(g);
    Stroke bkp = g.getStroke();
    g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{1, 2}, 0));
    Shape t = new Ellipse2D.Float(getLeft(), getTop(), getWidth(), getHeight());
    g.draw(t);
    g.setStroke(bkp);
}
 
Example 15
Project: ramus   File: IDEF0Object.java   View Source Code Vote up 5 votes
@Override
 public void paint(final Graphics2D g) {
     g.setColor(function.getBackground());
     final Rectangle2D rect = movingArea.getBounds(getBounds());
     g.fill(rect);
     g.setFont(function.getFont());
     // g.setColor(function.getForeground());
     super.paint(g);

     final Stroke tmp = g.getStroke();
     g.draw(rect);
     if (!function.isHaveChilds()) {
         g.draw(new Line2D.Double(rect.getX()
                 + Math.round(movingArea.getIDoubleOrdinate(4)),
                 rect.getY(), rect.getX(), rect.getY()
                 + Math.round(movingArea.getIDoubleOrdinate(4))));
     }
     g.setStroke(new BasicStroke(2));
     /*
      * g.draw(new Line2D.Double(rect.getX() + rect.getWidth() - 1,
* rect.getY() + 1, rect.getX() + rect.getWidth() - 1, rect.getY() +
* rect.getHeight() - 1)); g.draw(new Line2D.Double(rect.getX() + 1,
* rect.getY() + rect.getHeight() - 1, rect.getX() + rect.getWidth() -
* 1, rect .getY() + rect.getHeight() - 1));
*/
     final String string = getIDEF0Kod();
     g.setFont(function.getFont());
     double h = MovingArea.getWidth(0)
             + MovingArea.getWidth((int) function.getFont()
             .getStringBounds(string, g.getFontRenderContext())
             .getHeight());
     h = h * 0.7;
     movingArea.paintText(g, string,
             new FRectangle(getBounds().getX(), getBounds().getBottom() - h
                     - 3, getBounds().getWidth() - 3, h),
             com.ramussoft.pb.print.old.Line.RIGHT_ALIGN, 1, true);

     g.setStroke(tmp);
     paintTringle(g);
 }
 
Example 16
Project: Pogamut3   File: TimeTicsWidget.java   View Source Code Vote up 5 votes
@Override
protected void
        paintWidget() {
    int secondsPerTick = 10;
    int secTickHeight = 6;

    Graphics2D g = getGraphics();
    g.setColor(getForeground());

    int ticksNum = (int) (totalTime / (1000 * secondsPerTick));

    Stroke formerStroke = g.getStroke();
    g.setStroke(lineStroke);

    // draw main line
    g.drawLine(0, 0, (int) (totalTime / TLWidget.zoomFactor), 0);

    // draw ticks
    for (int tick = 0; tick <= ticksNum; tick++) {
        int x = tick * secondsPerTick * 1000 / TLWidget.zoomFactor;
        g.drawLine(x, 0, x, majorTickHeight);

        // draw label
        String time = ((tick * secondsPerTick) / 60) + ":" + ((tick * secondsPerTick) % 60);
        //g.drawString(time, x, majorTickHeight);

        Rectangle2D r = g.getFontMetrics().getStringBounds(time, g);
        g.drawString(time, x - (float)r.getWidth() * 0.5f, majorTickHeight + (float)(r.getHeight()));

        // draw minor ticks, per seconds
        int lastSecTick = (int) (totalTime / 1000 < (tick + 1) * secondsPerTick - 1 ? totalTime / 1000 : (tick+1) * secondsPerTick - 1);
        for (int secTick = tick * secondsPerTick + 1; secTick <= lastSecTick; secTick++) {
            int secX = secTick * 1000/TLWidget.zoomFactor;
            g.drawLine(secX, 0, secX, secTickHeight);
        }
    }

    g.setStroke(formerStroke);
}
 
Example 17
Project: brModelo   File: LivreTriangulo.java   View Source Code Vote up 5 votes
@Override
protected void PinteRegiao(Graphics2D g) {
    Composite originalComposite = g.getComposite();
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alfa));
    g.setPaint(this.getForeColor());

    if (isGradiente()) {
        int dist = 0;
        int w = getWidth() - dist;
        int h = getHeight() - dist;
        int L = getLeft();
        int T = getTop();
        boolean dv = getGDirecao() == VERTICAL;

        GradientPaint GP = new GradientPaint(L, T, getGradienteStartColor(), dv ? L : L + w, dv ? T + h : T, getGradienteEndColor(), true);
        g.setPaint(GP);
    }

    Stroke bkp = g.getStroke();
    if (isDashed()) {
        g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{1, 2}, 0));
    }
    if (isGradiente()) {
        g.fill(getRegiao());
    }
    g.draw(getRegiao()); //Pinta as eventuais linhas internas do dezenho. Ex. LivreVariosDocumemtos 

    g.setStroke(bkp);
    g.setComposite(originalComposite);
}
 
Example 18
Project: jdk8u-jdk   File: Decoration.java   View Source Code Vote up 5 votes
private void drawTextAndEmbellishments(Label label,
                                       Graphics2D g2d,
                                       float x,
                                       float y) {

    label.handleDraw(g2d, x, y);

    if (!strikethrough && stdUnderline == null && imUnderline == null) {
        return;
    }

    float x1 = x;
    float x2 = x1 + (float)label.getLogicalBounds().getWidth();

    CoreMetrics cm = label.getCoreMetrics();
    if (strikethrough) {
        Stroke savedStroke = g2d.getStroke();
        g2d.setStroke(new BasicStroke(cm.strikethroughThickness,
                                      BasicStroke.CAP_BUTT,
                                      BasicStroke.JOIN_MITER));
        float strikeY = y + cm.strikethroughOffset;
        g2d.draw(new Line2D.Float(x1, strikeY, x2, strikeY));
        g2d.setStroke(savedStroke);
    }

    float ulOffset = cm.underlineOffset;
    float ulThickness = cm.underlineThickness;

    if (stdUnderline != null) {
        stdUnderline.drawUnderline(g2d, ulThickness, x1, x2, y + ulOffset);
    }

    if (imUnderline != null) {
        imUnderline.drawUnderline(g2d, ulThickness, x1, x2, y + ulOffset);
    }
}
 
Example 19
Project: SE2017-Team2   File: CrDrawing.java   View Source Code Vote up 4 votes
/**
 * Draws an arrow representing a relation
 * @param g
 * @param e1
 * @param e2
 * @param c
 * @param id
 * @param isConditional
 */
private void drawArrow(Graphics2D g, Event e1, Event e2, Color c, String id, boolean isConditional) {
	Tuple<Position, Position> tuple = shortest(e1, e2);
	Position p1 = tuple.f;
	Position p2 = tuple.s;
	relationPos.add(p1); 
	relationPos.add(p2); 
	AffineTransform oldXForm = g.getTransform();
	g.setColor(c);
	int ARR_SIZE = 8;
	Stroke oldS = g.getStroke();
	int strokeSize = ARR_SIZE/4;
	Stroke newS = new BasicStroke(strokeSize);
	g.setStroke(newS);
		
	double dx = p2.x() - p1.x(), dy = p2.y() - p1.y();
	double angle = Math.atan2(dy, dx);
	
	int len = (int) Math.sqrt(dx*dx + dy*dy);
	AffineTransform at = AffineTransform.getTranslateInstance(p1.x(), p1.y());
	at.concatenate(AffineTransform.getRotateInstance(angle));
	g.transform(at);
	Font fontUp = new Font("Times New Roman", Font.BOLD, 18);
	Font fontDw = new Font("Times New Roman", Font.BOLD, -18);
	FontMetrics mUp = g.getFontMetrics(fontUp);
	if (isConditional) {
		if (p1.x() > p2.x()) {
			g.setFont(fontDw);
			g.drawString(id, (len/2), -strokeSize+MARGIN);
		}
		else {
			g.setFont(fontUp);
			g.drawString(id, (len/2)-mUp.stringWidth(id), -strokeSize);
		}
		len -= CIRCLE_RADIUS;
		g.drawLine(0, 0, len-ARR_SIZE, 0);
		g.fillRoundRect(len, -(CIRCLE_RADIUS/2), CIRCLE_RADIUS, CIRCLE_RADIUS, CIRCLE_RADIUS, CIRCLE_RADIUS);
	}
	else {
		if (p1.x() > p2.x()) {
			g.setFont(fontDw);
			g.drawString(id, CIRCLE_RADIUS+(len/2), -strokeSize+MARGIN);
		}
		else {
			g.setFont(fontUp);
			g.drawString(id, CIRCLE_RADIUS+(len/2)-mUp.stringWidth(id), -strokeSize);
		}
		g.drawLine(CIRCLE_RADIUS, 0, len-ARR_SIZE, 0);
		g.fillRoundRect(0, -(CIRCLE_RADIUS/2), CIRCLE_RADIUS, CIRCLE_RADIUS, CIRCLE_RADIUS, CIRCLE_RADIUS);
	}
	g.fillPolygon(new int[] {len, len-ARR_SIZE, len-ARR_SIZE, len},
                    new int[] {0, -ARR_SIZE, ARR_SIZE, 0}, 4);
	//reset
	g.setStroke(oldS);
	g.setTransform(oldXForm);
}
 
Example 20
Project: Mafia   File: Pointer.java   View Source Code Vote up 4 votes
public void render(Graphics2D g, Game game) {
	int pointOneX = (int) (startX + (targetX - startX) * pointerStage);
	int pointOneY = (int) (startY + (targetY - startY) * pointerStage);
	
	
	
	Stroke oldStroke = g.getStroke();
	
	
	int colorAlpha = (int) (255 - 255 * pointerStage);
	
	if(isPrimaryPointer)
		g.setColor(new Color(POINTER_PRIMARY_COLOR.getRed(), POINTER_PRIMARY_COLOR.getGreen(), POINTER_PRIMARY_COLOR.getBlue(), colorAlpha));
	else
		g.setColor(new Color(POINTER_SECONDARY_COLOR.getRed(), POINTER_SECONDARY_COLOR.getGreen(), POINTER_SECONDARY_COLOR.getBlue(), colorAlpha));
	
	g.setStroke(new BasicStroke(POINTER_THINKNESS));
	
	g.drawLine(pointOneX, pointOneY, (int) startX, (int) startY);
	
	
	g.setStroke(oldStroke);
}