Example usage for java.awt BasicStroke BasicStroke

List of usage examples for java.awt BasicStroke BasicStroke

Introduction

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

Prototype

public BasicStroke(float width, int cap, int join) 

Source Link

Document

Constructs a solid BasicStroke with the specified attributes.

Usage

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:org.jfree.chart.demo.MemoryUsageDemo.java

public MemoryUsageDemo(int i) {
    super(new BorderLayout());
    total = new TimeSeries("Total Memory");
    total.setMaximumItemAge(i);//from   ww w .  j ava  2s  . c  o m
    free = new TimeSeries("Free Memory");
    free.setMaximumItemAge(i);
    TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
    timeseriescollection.addSeries(total);
    timeseriescollection.addSeries(free);
    DateAxis dateaxis = new DateAxis("Time");
    NumberAxis numberaxis = new NumberAxis("Memory");
    dateaxis.setTickLabelFont(new Font("SansSerif", 0, 12));
    numberaxis.setTickLabelFont(new Font("SansSerif", 0, 12));
    dateaxis.setLabelFont(new Font("SansSerif", 0, 14));
    numberaxis.setLabelFont(new Font("SansSerif", 0, 14));
    XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(true, false);
    xylineandshaperenderer.setSeriesPaint(0, Color.red);
    xylineandshaperenderer.setSeriesPaint(1, Color.green);
    xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(3F, 0, 2));
    xylineandshaperenderer.setSeriesStroke(1, new BasicStroke(3F, 0, 2));
    XYPlot xyplot = new XYPlot(timeseriescollection, dateaxis, numberaxis, xylineandshaperenderer);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    dateaxis.setAutoRange(true);
    dateaxis.setLowerMargin(0.0D);
    dateaxis.setUpperMargin(0.0D);
    dateaxis.setTickLabelsVisible(true);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    JFreeChart jfreechart = new JFreeChart("JVM Memory Usage", new Font("SansSerif", 1, 24), xyplot, true);
    jfreechart.setBackgroundPaint(Color.white);
    ChartPanel chartpanel = new ChartPanel(jfreechart, true);
    chartpanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4),
            BorderFactory.createLineBorder(Color.black)));
    add(chartpanel);
}

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;//w w w  .  j  av  a2 s. co 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:org.openfaces.component.chart.impl.configuration.PlotSelectionConfigurator.java

private void setupGridChartSelection(Plot plot, GridChartView chartView) {
    if (chartView.getPoint() != null) {
        GridPointInfo point = chartView.getPoint();
        final ChartSelection selection = chartView.getChart().getChartSelection();

        final LineStyle lineStyle = selection.getLineStyle();
        Paint outlinePaint = lineStyle.getColor() != null ? lineStyle.getColor() : Color.BLUE;
        final Stroke outlineStroke = lineStyle.getStroke() != null ? lineStyle.getStroke()
                : new BasicStroke(5.0F, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);
        final Paint selectionPaint = selection.getFillPaint();

        Object itemRenderer = null;
        if (plot instanceof XYPlot) {
            itemRenderer = ((XYPlot) plot).getRenderer();
        } else if (plot instanceof CategoryPlot) {
            itemRenderer = ((CategoryPlot) plot).getRenderer();
        }/*ww  w.j  a v a  2  s  .co  m*/

        if (itemRenderer != null && itemRenderer instanceof CustomizedRenderer) {
            if (itemRenderer instanceof BarRenderer) {
                ((BarRenderer) itemRenderer).setDrawBarOutline(true);
            } else if (itemRenderer instanceof XYBarRenderer) {
                ((XYBarRenderer) itemRenderer).setDrawBarOutline(true);
            } else if (itemRenderer instanceof XYRendererAdapter) {
                ((XYRendererAdapter) itemRenderer).setDrawOutlines(true);
            } else if (itemRenderer instanceof XYLineAndShapeRenderer) {
                ((XYLineAndShapeRenderer) itemRenderer).setDrawOutlines(true);
            }

            final SeriesInfo series = point.getSeries();
            ((CustomizedRenderer) itemRenderer).setItemOutlinePaint(series.getIndex(), point.getIndex(),
                    outlinePaint);
            ((CustomizedRenderer) itemRenderer).setItemOutlineStroke(series.getIndex(), point.getIndex(),
                    outlineStroke);

            ((CustomizedRenderer) itemRenderer).setItemPaint(series.getIndex(), point.getIndex(),
                    selectionPaint);
        }
    }
}

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 w  w . j a v  a  2 s.  c  o m
    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:com.rapidminer.gui.new_plotter.engine.jfreechart.renderer.FormattedXYErrorRenderer.java

@Override
public void renderFormatDelegateChanged(RenderFormatDelegate source) {
    SeriesFormat seriesFormat = source.getSeriesFormat();
    if (seriesFormat != null) {
        setErrorStroke(new BasicStroke(Math.round(seriesFormat.getLineWidth() / 2.0), BasicStroke.CAP_SQUARE,
                BasicStroke.JOIN_MITER));
    }//  ww  w  .  jav a 2  s .  c  o  m
}

From source file:ChartUsingJava.CombinedXYPlotDemo1.java

/**
 * Creates an overlaid chart./*from  w ww  . j ava2 s .c om*/
 *
 * @return The chart.
 */
private static JFreeChart createCombinedChart() {

    // create plot ...
    IntervalXYDataset data1 = createDataset1();
    XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false);
    renderer1.setBaseToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
    renderer1.setSeriesStroke(0, new BasicStroke(4.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    renderer1.setSeriesPaint(0, Color.blue);

    DateAxis domainAxis = new DateAxis("Year");
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.02);
    ValueAxis rangeAxis = new NumberAxis("$billion");
    XYPlot plot1 = new XYPlot(data1, null, rangeAxis, renderer1);
    plot1.setBackgroundPaint(Color.lightGray);
    plot1.setDomainGridlinePaint(Color.white);
    plot1.setRangeGridlinePaint(Color.white);

    // add a second dataset and renderer...
    IntervalXYDataset data2 = createDataset2();
    XYBarRenderer renderer2 = new XYBarRenderer() {
        public Paint getItemPaint(int series, int item) {
            XYDataset dataset = getPlot().getDataset();
            if (dataset.getYValue(series, item) >= 0.0) {
                return Color.red;
            } else {
                return Color.green;
            }
        }
    };
    renderer2.setSeriesPaint(0, Color.red);
    renderer2.setDrawBarOutline(false);
    renderer2.setBaseToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));

    XYPlot plot2 = new XYPlot(data2, null, new NumberAxis("$billion"), renderer2);
    plot2.setBackgroundPaint(Color.lightGray);
    plot2.setDomainGridlinePaint(Color.white);
    plot2.setRangeGridlinePaint(Color.white);

    CombinedXYPlot cplot = new CombinedXYPlot(domainAxis, rangeAxis);
    cplot.add(plot1, 3);
    cplot.add(plot2, 2);
    cplot.setGap(8.0);
    cplot.setDomainGridlinePaint(Color.white);
    cplot.setDomainGridlinesVisible(true);

    // return a new chart containing the overlaid plot...
    JFreeChart chart = new JFreeChart("CombinedXYPlotDemo1", JFreeChart.DEFAULT_TITLE_FONT, cplot, false);
    chart.setBackgroundPaint(Color.white);
    LegendTitle legend = new LegendTitle(cplot);
    chart.addSubtitle(legend);
    return chart;
}

From source file:net.sf.profiler4j.console.AllocDiffPanel.java

public AllocDiffPanel(int maxAgeMillis) {
    super(new BorderLayout());

    totalSeries = new TimeSeries("Allocs/Sec", Millisecond.class);
    totalSeries.setMaximumItemAge(maxAgeMillis);

    TimeSeriesCollection seriesCollection = new TimeSeriesCollection();
    seriesCollection.addSeries(totalSeries);

    NumberAxis numberAxis = new NumberAxis("Allocs/Sec");
    numberAxis.setLabelFont(new Font("SansSerif", 0, 14));
    numberAxis.setTickLabelFont(new Font("SansSerif", 0, 12));
    numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    DateAxis dateAxis = new DateAxis("Time");
    dateAxis.setTickLabelFont(new Font("SansSerif", 0, 12));
    dateAxis.setLabelFont(new Font("SansSerif", 0, 14));
    dateAxis.setAutoRange(true);// w  w  w . j  a v  a2s.  c  o  m
    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, Color.RED);
    lineRenderer.setSeriesPaint(1, Color.GREEN.darker());
    lineRenderer.setStroke(new BasicStroke(2F, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));

    XYPlot xyplot = new XYPlot(seriesCollection, dateAxis, numberAxis, lineRenderer);
    xyplot.setBackgroundPaint(Color.WHITE);
    xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));

    JFreeChart chart = new JFreeChart("Object Allocactions in Remote JVM",
            new Font("SansSerif", Font.PLAIN, 18), xyplot, true);
    chart.setBackgroundPaint(Color.white);

    ChartPanel panel = new ChartPanel(chart);
    panel.setBorder(createCompoundBorder(createEmptyBorder(8, 8, 8, 8), createLineBorder(Color.LIGHT_GRAY)));
    add(panel);
    setBorder(createEmptyBorder(8, 8, 8, 8));
}

From source file:net.sf.maltcms.chromaui.charts.ChartCustomizer.java

/**
 *
 * @param plot//from www .  j a  v a  2  s .co  m
 * @param width
 */
public static void setSeriesStrokes(XYPlot plot, float width) {
    XYItemRenderer renderer = plot.getRenderer();
    int series = plot.getSeriesCount();
    for (int i = 0; i < series; i++) {
        renderer.setSeriesStroke(i, new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    }
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.renderer.FormattedStatisticalLineAndShapeRenderer.java

@Override
public void renderFormatDelegateChanged(RenderFormatDelegate source) {
    SeriesFormat seriesFormat = source.getSeriesFormat();
    if (seriesFormat != null) {
        setErrorIndicatorStroke(new BasicStroke(Math.round(seriesFormat.getLineWidth() / 2.0),
                BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER));
    }/*from w  w  w  .  j a  v a 2 s  . co  m*/
}