Example usage for java.awt BasicStroke CAP_ROUND

List of usage examples for java.awt BasicStroke CAP_ROUND

Introduction

In this page you can find the example usage for java.awt BasicStroke CAP_ROUND.

Prototype

int CAP_ROUND

To view the source code for java.awt BasicStroke CAP_ROUND.

Click Source Link

Document

Ends unclosed subpaths and dash segments with a round decoration that has a radius equal to half of the width of the pen.

Usage

From source file:Main.java

static public void main(String args[]) throws Exception {
    int width = 200, height = 200;
    BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

    Graphics2D ig2 = bi.createGraphics();
    ig2.fillRect(0, 0, width - 1, height - 1);

    BasicStroke stroke = new BasicStroke(10, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    ig2.setPaint(Color.lightGray);
    ig2.setStroke(stroke);//w  w w .  j a  v  a  2 s  . com
    ig2.draw(new Ellipse2D.Double(0, 0, 100, 100));

    ImageIO.write(bi, "GIF", new File("a.gif"));
}

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    BasicStroke bs = new BasicStroke(16.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL);
    g2.setStroke(bs);/*from w  w w .j  a  v  a  2 s .  c om*/
    g.drawLine(30, 20, 270, 20);
}

From source file:Charts2D.java

public Charts2D() {
    super("2D Charts");
    setSize(720, 280);/*from  w  w  w .  j ava2s.  c o m*/
    getContentPane().setLayout(new GridLayout(1, 3, 10, 0));
    getContentPane().setBackground(Color.white);

    int[] xData = new int[8];
    int[] yData = new int[8];
    for (int i = 0; i < xData.length; i++) {
        xData[i] = i;
        yData[i] = (int) (Math.random() * 100);
        if (i > 0)
            yData[i] = (yData[i - 1] + yData[i]) / 2;
    }

    JChart2D chart = new JChart2D(JChart2D.LineChart, xData.length, xData, yData, "Line Chart");
    chart.setStroke(new BasicStroke(5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
    chart.setLineColor(new Color(0, 28, 28));
    getContentPane().add(chart);

    chart = new JChart2D(JChart2D.ColumnChart, xData.length, xData, yData, "Column Chart");
    GradientPaint gp = new GradientPaint(0, 100, Color.white, 0, 300, Color.blue, true);
    chart.setGradient(gp);
    chart.setEffectIndex(JChart2D.Gradientffect);
    chart.setDrawShadow(true);
    getContentPane().add(chart);

    chart = new JChart2D(JChart2D.PieChart, xData.length, xData, yData, "Pie Chart");
    ImageIcon icon = new ImageIcon("largeJava2slogo.GIF");
    chart.setForegroundImage(icon.getImage());
    chart.setEffectIndex(JChart2D.ImageEffect);
    chart.setDrawShadow(true);
    getContentPane().add(chart);

    WindowListener wndCloser = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    addWindowListener(wndCloser);

    setVisible(true);
}

From source file:grafix.graficos.indices.IndiceADX.java

@Override
public void plotar(final XYPlot plot, final JanelaGraficos janela, final int contador) {
    XYLineAndShapeRenderer r = new XYLineAndShapeRenderer();
    r.setSeriesLinesVisible(0, true);/*from   w w  w  .j ava2s  . c o  m*/
    r.setSeriesShapesVisible(0, false);
    r.setSeriesPaint(0, Color.BLUE);
    r.setSeriesStroke(0, new BasicStroke(.75f));

    r.setSeriesPaint(1, Color.RED);
    r.setSeriesStroke(1, new BasicStroke(.6f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 3.0f, 4.0f }, 0.0f));
    r.setSeriesLinesVisible(1, true);
    r.setSeriesShapesVisible(1, false);

    r.setSeriesPaint(2, new Color(0f, .6f, 0f));
    r.setSeriesStroke(2, new BasicStroke(.6f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 2.0f,
            new float[] { 3.0f, 4.0f }, 0.0f));
    r.setSeriesLinesVisible(2, true);
    r.setSeriesShapesVisible(2, false);

    r.setToolTipGenerator(new IndiceToolTipGenerator(this));
    plot.setRenderer(contador, r);
    plot.setDataset(contador, getDataSet(janela));
}

From source file:de.d3web.empiricaltesting.casevisualization.jung.EdgeStrokeTransformer.java

/**
 * Transforms a Finding to color depending on the state of the next
 * RatedTestCase//from  w  ww  .j  a  va2  s. c  o m
 */
@Override
public Stroke transform(EdgeFinding f) {

    RatedTestCase rtc = graph.getDest(f);
    String strength = ConfigLoader.getInstance().getProperty("edgeWidthNewCase");

    if (rtc.wasTestedBefore()) {
        strength = ConfigLoader.getInstance().getProperty("edgeWidthOldCase");
    }

    return new BasicStroke(Float.parseFloat(strength) / 2, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER);

}

From source file:SimpleAttributes.java

public void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D) g.create();
    g2d.setBackground(Color.GRAY);
    g2d.clearRect(0, 0, getWidth(), getHeight());

    // String and line with default attributes
    g2d.drawString("Default Font", 10, 20);
    g2d.drawLine(10, 22, 80, 22);/* ww w . j  a v a 2  s  .  co m*/

    // Change the font, foreground color, and Stroke
    g2d.setFont(g.getFont().deriveFont(Font.BOLD | Font.ITALIC, 24f));
    g2d.setColor(Color.WHITE);
    g2d.setStroke(new BasicStroke(10f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));

    // String and line with new attributes
    g2d.drawString("New Font", 10, 50);
    g2d.drawLine(10, 57, 120, 57);
    g2d.dispose();
}

From source file:Hypnosis.java

public Hypnosis(double x, double y, double r1, double r2, double a1, double a2, float linewidth, int delay,
        double deltaA, double deltaX, double deltaY) {
    this.x = x;/*from   ww  w. ja  v a  2s.  c o m*/
    this.y = y;
    this.r1 = r1;
    this.r2 = r2;
    this.a1 = a1;
    this.a2 = a2;
    this.linewidth = linewidth;
    this.deltaA = deltaA;
    this.deltaX = deltaX;
    this.deltaY = deltaY;

    // Set up a timer to call actionPerformed() every delay milliseconds
    timer = new Timer(delay, this);

    // Create a buffer for double-buffering
    buffer = new BufferedImage((int) (2 * r2 + linewidth), (int) (2 * r2 + linewidth),
            BufferedImage.TYPE_INT_RGB);

    // Create a Graphics object for the buffer, and set the linewidth
    // and request antialiasing when drawing with it
    osg = buffer.createGraphics();
    osg.setStroke(new BasicStroke(linewidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    osg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
}

From source file:StrokeTest.java

public StrokeTestFrame() {
    setTitle("StrokeTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    canvas = new StrokeComponent();
    add(canvas, BorderLayout.CENTER);

    buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridLayout(3, 3));
    add(buttonPanel, BorderLayout.NORTH);

    ButtonGroup group1 = new ButtonGroup();
    makeCapButton("Butt Cap", BasicStroke.CAP_BUTT, group1);
    makeCapButton("Round Cap", BasicStroke.CAP_ROUND, group1);
    makeCapButton("Square Cap", BasicStroke.CAP_SQUARE, group1);

    ButtonGroup group2 = new ButtonGroup();
    makeJoinButton("Miter Join", BasicStroke.JOIN_MITER, group2);
    makeJoinButton("Bevel Join", BasicStroke.JOIN_BEVEL, group2);
    makeJoinButton("Round Join", BasicStroke.JOIN_ROUND, group2);

    ButtonGroup group3 = new ButtonGroup();
    makeDashButton("Solid Line", false, group3);
    makeDashButton("Dashed Line", true, group3);
}

From source file:org.mustbe.consulo.xprofiler.ui.mainPanel.MemoryPlotPanel.java

public MemoryPlotPanel(int maxAge, String title) {
    super(new BorderLayout());

    totalSeries = new TimeSeries("Committed Memory");
    totalSeries.setMaximumItemAge(maxAge);
    usedSeries = new TimeSeries("Used Memory");
    usedSeries.setMaximumItemAge(maxAge);
    TimeSeriesCollection seriesCollection = new TimeSeriesCollection();
    seriesCollection.addSeries(totalSeries);
    seriesCollection.addSeries(usedSeries);

    NumberAxis numberAxis = new NumberAxis("Memory (KB)");

    numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    DateAxis dateAxis = new DateAxis("Time");

    dateAxis.setAutoRange(true);/*from  w  ww.ja  v  a 2 s. c om*/
    dateAxis.setLowerMargin(0);
    dateAxis.setUpperMargin(0);
    dateAxis.setTickLabelsVisible(true);
    dateAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));

    XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer(true, false);
    lineRenderer.setSeriesPaint(0, JBColor.RED);
    lineRenderer.setSeriesPaint(1, JBColor.GREEN);
    lineRenderer.setDefaultStroke(new BasicStroke(2F, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));

    XYPlot xyplot = new XYPlot(seriesCollection, dateAxis, numberAxis, lineRenderer);
    xyplot.setBackgroundPainter(new ColorPainter(JBColor.white));
    xyplot.setDomainGridlinePaint(JBColor.LIGHT_GRAY);
    xyplot.setRangeGridlinePaint(JBColor.LIGHT_GRAY);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));

    JFreeChart chart = new JFreeChart(title, new Font("SansSerif", Font.PLAIN, 14), xyplot, true);
    chart.setBackgroundPainter(new ColorPainter(JBColor.white));

    add(new ChartPanel(chart, 300, 300, 0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE, true, true, false, false,
            false, false), BorderLayout.CENTER);
}

From source file:org.apache.qpid.disttest.charting.chartbuilder.SeriesPainter.java

private BasicStroke buildStrokeOfWidth(float width, boolean dashed) {
    final BasicStroke stroke;
    if (dashed) {
        stroke = new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
                new float[] { 3.0f, 3.0f }, 0.0f);
    } else {// w w w. j  av a  2 s.com
        stroke = new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    }
    return stroke;
}