Java Code Examples for java.awt.BasicStroke#CAP_BUTT

The following examples show how to use java.awt.BasicStroke#CAP_BUTT . These examples are extracted from open source projects. 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
private BasicStroke createStroke( final BorderEdge edge, final long internalWidth ) {
  final float effectiveWidth = (float) StrictGeomUtility.toExternalValue( internalWidth );
  if ( BorderStyle.HIDDEN.equals( edge.getBorderStyle() ) ) {
    return null;
  }

  if ( BorderStyle.DASHED.equals( edge.getBorderStyle() ) ) {
    return new BasicStroke( effectiveWidth, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f, new float[] {
      6 * effectiveWidth, 6 * effectiveWidth }, 0.0f );
  }
  if ( BorderStyle.DOTTED.equals( edge.getBorderStyle() ) ) {
    return new BasicStroke( effectiveWidth, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 5.0f, new float[] { 0.0f,
      2 * effectiveWidth }, 0.0f );
  }
  if ( BorderStyle.DOT_DASH.equals( edge.getBorderStyle() ) ) {
    return new BasicStroke( effectiveWidth, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f, new float[] { 0,
      2 * effectiveWidth, 6 * effectiveWidth, 2 * effectiveWidth }, 0.0f );
  }
  if ( BorderStyle.DOT_DOT_DASH.equals( edge.getBorderStyle() ) ) {
    return new BasicStroke( effectiveWidth, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f, new float[] { 0,
      2 * effectiveWidth, 0, 2 * effectiveWidth, 6 * effectiveWidth, 2 * effectiveWidth }, 0.0f );
  }
  return new BasicStroke( effectiveWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER );
}
 
Example 2
/**
 * Returns the AWT line cap corresponding to the specified SWT line cap.
 *
 * @param swtLineCap  the SWT line cap.
 *
 * @return The AWT line cap.
 */
private int toAwtLineCap(int swtLineCap) {
    if (swtLineCap == SWT.CAP_FLAT) {
        return BasicStroke.CAP_BUTT;
    }
    else if (swtLineCap == SWT.CAP_ROUND) {
        return BasicStroke.CAP_ROUND;
    }
    else if (swtLineCap == SWT.CAP_SQUARE) {
        return BasicStroke.CAP_SQUARE;
    }
    else {
        throw new IllegalArgumentException("SWT LineCap " + swtLineCap
            + " not recognised");
    }
}
 
Example 3
/**
 * Returns the SWT line cap corresponding to the specified AWT line cap.
 *
 * @param awtLineCap  the AWT line cap.
 *
 * @return The SWT line cap.
 */
private int toSwtLineCap(int awtLineCap) {
    if (awtLineCap == BasicStroke.CAP_BUTT) {
        return SWT.CAP_FLAT;
    }
    else if (awtLineCap == BasicStroke.CAP_ROUND) {
        return SWT.CAP_ROUND;
    }
    else if (awtLineCap == BasicStroke.CAP_SQUARE) {
        return SWT.CAP_SQUARE;
    }
    else {
        throw new IllegalArgumentException("AWT LineCap " + awtLineCap
            + " not recognised");
    }
}
 
Example 4
/**
 * Returns the SWT line cap corresponding to the specified AWT line cap.
 *
 * @param awtLineCap  the AWT line cap.
 *
 * @return The SWT line cap.
 */
private int toSwtLineCap(int awtLineCap) {
    if (awtLineCap == BasicStroke.CAP_BUTT) {
        return SWT.CAP_FLAT;
    }
    else if (awtLineCap == BasicStroke.CAP_ROUND) {
        return SWT.CAP_ROUND;
    }
    else if (awtLineCap == BasicStroke.CAP_SQUARE) {
        return SWT.CAP_SQUARE;
    }
    else {
        throw new IllegalArgumentException("AWT LineCap " + awtLineCap
            + " not recognised");
    }
}
 
Example 5
@Override
public void paint(Graphics g) {
    if (g == null || !(g instanceof Graphics2D)) {
        return;
    }
    g.setColor(Color.white);
    g.setXORMode(Color.black);
    Graphics2D dg = (Graphics2D) g;
    Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT,
            BasicStroke.JOIN_MITER,
            10.0f,
            new float[]{1.0f, 1.0f},
            0.0f);
    dg.setStroke(stroke);
    try {
        dg.draw(new Line2D.Float(10, 10, 20, 20));
    } catch (Throwable e) {
        synchronized (this) {
            theError = e;
        }
    } finally {
        didDraw.countDown();
    }
}
 
Example 6
private static void draw(final Image img) {
    float[] dashes = {200.0f, 200.0f};
    BasicStroke bs = new BasicStroke(20.0f,
                                     BasicStroke.CAP_BUTT,
                                     BasicStroke.JOIN_MITER,
                                     1.0f,
                                     dashes,
                                     0.0f);
    Graphics2D g = (Graphics2D) img.getGraphics();
    g.setColor(Color.WHITE);
    g.fillRect(0, 0, 200, 40);
    Line2D line = new Line2D.Double(400, 400, 3600, 400);
    g.setColor(Color.BLACK);
    g.scale(0.05, 0.05);
    g.setStroke(bs);
    g.draw(line);
    g.dispose();
}
 
Example 7
private void initDefaultValues() {
    setRenderingOptimized(true);

    Color systemSelection = Utils.getSystemSelection();

    setLineStroke(new BasicStroke(1));
    setLinePaint(systemSelection);

    setFillPaint(new Color(systemSelection.getRed(),
                           systemSelection.getGreen(),
                           systemSelection.getBlue(), 80));

    oddPerfStroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 6, 6 }, 6);
    evenPerfStroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 6, 6 }, 0);

    setLineMode(true, true, true, true);
}
 
Example 8
@Override
public void paint(Graphics g) {
    if (g == null || !(g instanceof Graphics2D)) {
        return;
    }
    g.setColor(Color.white);
    g.setXORMode(Color.black);
    Graphics2D dg = (Graphics2D) g;
    Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT,
            BasicStroke.JOIN_MITER,
            10.0f,
            new float[]{1.0f, 1.0f},
            0.0f);
    dg.setStroke(stroke);
    try {
        dg.draw(new Line2D.Float(10, 10, 20, 20));
    } catch (Throwable e) {
        synchronized (this) {
            theError = e;
        }
    } finally {
        didDraw.countDown();
    }
}
 
Example 9
private void renderRegen(Graphics2D g, WidgetInfo widgetInfo, double percent, Color color)
{
	Widget widget = client.getWidget(widgetInfo);
	if (widget == null || widget.isHidden())
	{
		return;
	}
	Rectangle bounds = widget.getBounds();

	Arc2D.Double arc = new Arc2D.Double(bounds.x + OFFSET, bounds.y + (bounds.height / 2 - DIAMETER / 2), DIAMETER, DIAMETER, 90.d, -360.d * percent, Arc2D.OPEN);
	final Stroke STROKE = new BasicStroke(2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
	g.setStroke(STROKE);
	g.setColor(color);
	g.draw(arc);
}
 
Example 10
/**
 * Maps a line cap code from AWT to the corresponding JavaFX StrokeLineCap
 * enum value.
 * 
 * @param c  the line cap code.
 * 
 * @return A JavaFX line cap value. 
 */
private StrokeLineCap awtToJavaFXLineCap(int c) {
    if (c == BasicStroke.CAP_BUTT) {
        return StrokeLineCap.BUTT;
    } else if (c == BasicStroke.CAP_ROUND) {
        return StrokeLineCap.ROUND;
    } else if (c == BasicStroke.CAP_SQUARE) {
        return StrokeLineCap.SQUARE;
    } else {
        throw new IllegalArgumentException("Unrecognised cap code: " + c);
    }
}
 
Example 11
/**
 * Creates a new {@code SigPainter} object.
 *
 * @param g     Graphic context
 * @param scale the global scale
 */
public SigPainter (Graphics g,
                   Scale scale)
{
    this.g = (Graphics2D) g;
    this.clip = g.getClipBounds();

    // Determine proper music fonts
    if (scale == null) {
        musicFontLarge = musicFontSmall = null;
        musicHeadFontLarge = musicHeadFontSmall = null;
    } else {
        // Standard size
        final int large = scale.getInterline();
        musicFontLarge = MusicFont.getBaseFont(large);
        musicHeadFontLarge = MusicFont.getHeadFont(scale, large);

        // Smaller size
        final Integer small = scale.getSmallInterline();
        musicFontSmall = (small != null) ? MusicFont.getBaseFont(small) : null;
        musicHeadFontSmall = (small != null) ? MusicFont.getHeadFont(scale, small) : null;
    }

    // Determine lines parameters
    lineStroke = new BasicStroke(
            (scale != null) ? scale.getFore() : 2f,
            BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_ROUND);
    stemStroke = new BasicStroke(3f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);
    ledgerStroke = new BasicStroke(2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);
}
 
Example 12
private void renderRegen(Graphics2D g, WidgetInfo widgetInfo, double percent, Color color)
{
	Widget widget = client.getWidget(widgetInfo);
	if (widget == null || widget.isHidden())
	{
		return;
	}
	Rectangle bounds = widget.getBounds();

	Arc2D.Double arc = new Arc2D.Double(bounds.x + OFFSET, bounds.y + (bounds.height / 2 - DIAMETER / 2), DIAMETER, DIAMETER, 90.d, -360.d * percent, Arc2D.OPEN);
	final Stroke STROKE = new BasicStroke(2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
	g.setStroke(STROKE);
	g.setColor(color);
	g.draw(arc);
}
 
Example 13
IMGrayUnderline() {
    stroke = new BasicStroke(DEFAULT_THICKNESS,
                             BasicStroke.CAP_BUTT,
                             BasicStroke.JOIN_MITER,
                             10.0f,
                             new float[] {1, 1},
                             0);
}
 
Example 14
/**
 * Adds annotations to the Gaussian fit parameters
 * 
 * @param plot
 * @param fit Gaussian fit {normalisation factor, mean, sigma}
 */
public static void addGaussianFitAnnotations(XYPlot plot, double[] fit) {
  Paint c = plot.getDomainCrosshairPaint();
  BasicStroke s = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1,
      new float[] {5f, 2.5f}, 0);

  plot.addDomainMarker(new ValueMarker(fit[1], c, s));
  plot.addDomainMarker(new ValueMarker(fit[1] - fit[2], c, s));
  plot.addDomainMarker(new ValueMarker(fit[1] + fit[2], c, s));
}
 
Example 15
@Override
public void setMagnification(double mag) {
	if (mag < 0.00000001) mag = 0.00000001;
	// ensure a stroke of thickness 1.0 regardless of magnification
	this.stroke = new BasicStroke((float)(1.0/mag), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
	// FIXES MAG TO ImageCanvas.zoomLevel LIMITS!!
	//super.setMagnification(mag);
	// So, manually:
	this.magnification = mag;
	imp.setTitle(imp.getTitle());
	display.getMode().magnificationUpdated(srcRect, mag);
}
 
Example 16
protected boolean selectStylePen(int cap, int join, float width,
                                 Color color) {

    long endCap;
    long lineJoin;

    float[] rgb = color.getRGBColorComponents(null);

    switch(cap) {
    case BasicStroke.CAP_BUTT: endCap = PS_ENDCAP_FLAT; break;
    case BasicStroke.CAP_ROUND: endCap = PS_ENDCAP_ROUND; break;
    default:
    case BasicStroke.CAP_SQUARE: endCap = PS_ENDCAP_SQUARE; break;
    }

    switch(join) {
    case BasicStroke.JOIN_BEVEL:lineJoin = PS_JOIN_BEVEL; break;
    default:
    case BasicStroke.JOIN_MITER:lineJoin = PS_JOIN_MITER; break;
    case BasicStroke.JOIN_ROUND:lineJoin = PS_JOIN_ROUND; break;
    }

    return (selectStylePen(getPrintDC(), endCap, lineJoin, width,
                           (int) (rgb[0] * MAX_WCOLOR),
                           (int) (rgb[1] * MAX_WCOLOR),
                           (int) (rgb[2] * MAX_WCOLOR)));
}
 
Example 17
private static void draw(final Image img) {
    float[] dashes = {10.0f, 10.0f};
    BasicStroke bs = new BasicStroke(0.0f, BasicStroke.CAP_BUTT,
                                     BasicStroke.JOIN_BEVEL, 10.0f, dashes,
                                     0.0f);
    Graphics2D g = (Graphics2D) img.getGraphics();
    g.setColor(Color.WHITE);
    g.fillRect(0, 0, 200, 40);
    Line2D line = new Line2D.Double(20, 20, 180, 20);
    g.setColor(Color.BLACK);
    g.setStroke(bs);
    g.draw(line);
    g.dispose();
}
 
Example 18
IMGrayUnderline() {
    stroke = new BasicStroke(DEFAULT_THICKNESS,
                             BasicStroke.CAP_BUTT,
                             BasicStroke.JOIN_MITER,
                             10.0f,
                             new float[] {1, 1},
                             0);
}
 
Example 19
Source Project: DroidUIBuilder   File: ETitledLine.java    License: Apache License 2.0 4 votes vote down vote up
public void paint(Graphics g)
    {
        Graphics2D g2d = (Graphics2D) g;
//        Paint oldPaint = g2.getPaint();
        
        Border b = this.getBorder();
    	Insets its = null;
    	if(b != null)
    	{
    		its = b.getBorderInsets(this);
    	}
    	
        int y = (its!=null?its.top:0);
        int x = (its!=null?its.left:0);
        
        //先计算出阴影线要绘制的开始坐标
        int titleWidth = needDrawTitle()?g2d.getFontMetrics().stringWidth(title):0;
        int startX = titleWidth==0?0:titleWidth+5;
        
        //绘制标题
        if(needDrawTitle())
        {
        	g2d.setFont(titleFont);
        	//先以白底绘制标题(以使之产生立体感)
        	g2d.setColor(new Color(255,255,255));
        	g2d.drawString(title, x, (y + g2d.getFontMetrics().getAscent()) - 1);
        	
        	//再以标题颜色绘制真正的标题内容
        	g2d.setColor(titleColor);
        	g2d.drawString(title, x, (y + g2d.getFontMetrics().getAscent()));
        }
        
        y += (needDrawTitle()?Utils.getStrPixHeight(titleFont):0);
        //------------------------------------- 底线绘制开始
        //** 绘制底线1(短实线区)
        g2d.setColor(bottomLine1Color);
        g2d.fillRoundRect(x, y, bottomLine1Width, bottomLine1Height, 0, 0);//填充的宽度是字段宽度
        
        y += bottomLine1Height - 1;//这里-1是为了使虚线Y开始绘制的坐标与底线1的底刚好在同一水平线
        //** 绘制底线2(长虚线区)
        Stroke oldStroke = g2d.getStroke();
		Stroke sroke = new BasicStroke(1, BasicStroke.CAP_BUTT,
				BasicStroke.JOIN_BEVEL, 0, new float[]
				{bottomLine2EntityOfStroke, bottomLine2SpacingOfStroke}, 0);//实线,空白
		g2d.setStroke(sroke);
		g2d.setColor(bottomLine2Color);
		g2d.drawLine(x+bottomLine1Width+1,y, getWidth(),y);//从底线1长度+1处开始绘度(+1是为了好看一点而已)
		g2d.setStroke(oldStroke);
        
        //------------------------------------- 底线绘制END
    	
    }
 
Example 20
@Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g); //paint background
        RenderingHints renderHints
                = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
                        RenderingHints.VALUE_ANTIALIAS_ON);
        renderHints.put(RenderingHints.KEY_RENDERING,
                RenderingHints.VALUE_RENDER_QUALITY);

        Graphics2D Canvas = (Graphics2D) g;
        Canvas.addRenderingHints(renderHints);

//        Canvas.setPaint(Color.BLACK);
//        Canvas.draw3DRect(0, 0, getWidth() - 4, getHeight() - 4, true);
        Canvas.setPaint(Color.BLACK);
        Stroke stroke = new BasicStroke(1.f,
                BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER);
        Canvas.setStroke(stroke);

        Canvas.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
        Canvas.setPaint(Color.GRAY);
        Canvas.drawRect(0, 0, getWidth() - 2, getHeight() - 2);

        if (pgatual == 0) {
            return;
        }
        float[] dash4 = {2f, 2f, 2f};

        BasicStroke bs4 = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1.0f, dash4,
                2f);
        Canvas.setStroke(bs4);

        Canvas.drawLine(l - 1, 1, l - 1, getHeight() - 1);
        Canvas.drawLine(l + w + 1, 1, l + w + 1, getHeight() - 1);
        Canvas.drawLine(1, t - 1, getWidth() - 1, t - 1);
        Canvas.drawLine(1, t + h + 1, getWidth() - 1, t + h + 1);

        Canvas.setStroke(new BasicStroke(
                1f,
                BasicStroke.CAP_ROUND,
                BasicStroke.JOIN_ROUND));
        Canvas.setPaint(Color.BLACK);
        DrawPagina(Canvas);
    }