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) 

Source Link

Document

Constructs a solid BasicStroke with the specified line width and with default values for the cap and join styles.

Usage

From source file:com.joliciel.jochre.graphics.VectorizerImpl.java

public BufferedImage drawArrayLists(JochreImage jochreImage) {
    long startTime = (new Date()).getTime();
    BufferedImage vectorizedImage = new BufferedImage(jochreImage.getWidth(), jochreImage.getHeight(),
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics2D = vectorizedImage.createGraphics();
    graphics2D.setStroke(new BasicStroke(1));
    graphics2D.setPaint(Color.BLACK);

    for (Paragraph paragraph : jochreImage.getParagraphs()) {
        for (RowOfShapes row : paragraph.getRows()) {
            for (GroupOfShapes group : row.getGroups()) {
                for (Shape shape : group.getShapes()) {
                    List<LineSegment> lines = this.vectorize(shape);

                    for (LineSegment line : lines)
                        graphics2D.drawLine(shape.getLeft() + line.getStartX(),
                                shape.getTop() + line.getStartY(), shape.getLeft() + line.getEndX(),
                                shape.getTop() + line.getEndY());
                }// w  w  w . j a va  2  s.  c  o m
            }
        }
    }

    if (LOG.isDebugEnabled()) {
        long endTime = (new Date()).getTime();
        long diff = endTime - startTime;
        LOG.debug("Time elapsed: " + ((double) diff / 1000));
    }
    return vectorizedImage;
}

From source file:edu.cuny.jfree.chart.annotations.CategoryIntervalAnnotation.java

public CategoryIntervalAnnotation(final Comparable category, final double value1, final double value2,
        final Paint paint, final Stroke stroke) {
    this.paint = Color.black;
    this.stroke = new BasicStroke(1.0F);
    if (category == null) {
        throw new IllegalArgumentException("Null 'category' argument.");
    }/* w  w  w  . j  a  va 2 s .  c o  m*/
    if (paint == null) {
        throw new IllegalArgumentException("Null 'paint' argument.");
    }
    if (stroke == null) {
        throw new IllegalArgumentException("Null 'stroke' argument.");
    } else {
        this.category = category;
        this.value1 = value1;
        this.value2 = value2;
        this.paint = paint;
        this.stroke = stroke;
        return;
    }
}

From source file:edu.umass.cs.iesl.pdf2meta.cli.extract.pdfbox.pagedrawer.StrokePath.java

/**
 * S stroke the path./*from   w  ww  .j av  a 2s.c  o m*/
 * @param operator The operator that is being executed.
 * @param arguments List
 *
 * @throws java.io.IOException If an error occurs while processing the font.
 */
public void process(PDFOperator operator, List<COSBase> arguments) throws IOException {
    ///dwilson 3/19/07 refactor
    try {
        GraphicsAwarePDFStreamEngine drawer = (GraphicsAwarePDFStreamEngine) context;

        float lineWidth = (float) context.getGraphicsState().getLineWidth();
        Matrix ctm = context.getGraphicsState().getCurrentTransformationMatrix();
        if (ctm != null && ctm.getXScale() > 0) {
            lineWidth = lineWidth * ctm.getXScale();
        }

        BasicStroke stroke = (BasicStroke) drawer.getStroke();
        if (stroke == null) {
            drawer.setStroke(new BasicStroke(lineWidth));
        } else {
            drawer.setStroke(new BasicStroke(lineWidth, stroke.getEndCap(), stroke.getLineJoin(),
                    stroke.getMiterLimit(), stroke.getDashArray(), stroke.getDashPhase()));
        }
        drawer.strokePath();
    } catch (Exception exception) {
        log.warn(exception, exception);
    }
}

From source file:FindHullWindowLogic.java

static void drawPointsOnChart(JPanel panelWhenInside, ArrayList<Point2D> convexHull) {
    panelWhenInside.removeAll();//from   w  w w  . ja  v  a2 s  .  co  m
    panelWhenInside.setLayout(new java.awt.BorderLayout());
    XYSeries seriersAllPoints = new XYSeries("All points");
    addPointsToSeries(seriersAllPoints);

    int pairsNumber = 0;
    if (convexHull != null)
        pairsNumber = convexHull.size() - 1;
    XYSeries covnexHullDivideOnPiars[] = new XYSeries[pairsNumber];

    for (int i = 0; i < covnexHullDivideOnPiars.length; i++) {
        covnexHullDivideOnPiars[i] = new XYSeries("Convex hull pair " + i);
    }

    if (convexHull != null) {
        divideOnPairsAndConvertConvexHullIntoSeries(covnexHullDivideOnPiars, convexHull);
    }

    // Add the seriersAllPoints to your data set
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(seriersAllPoints);

    for (int i = 0; i < covnexHullDivideOnPiars.length; i++) {
        dataset.addSeries(covnexHullDivideOnPiars[i]);
    }

    // Generate the graph
    JFreeChart chart = ChartFactory.createXYLineChart(null, // Title
            null, // x-axis Label
            null, // y-axis Label
            dataset, // Dataset
            PlotOrientation.VERTICAL, // Plot Orientation
            false, // Show Legend
            false, // Use tooltips
            false // Configure chart to generate URLs?
    );

    final XYPlot plot = chart.getXYPlot();
    ChartPanel chartPanel = new ChartPanel(chart);
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.BLACK);
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShape(0, ShapeUtilities.createDiamond(3));

    for (int i = 1; i <= covnexHullDivideOnPiars.length; i++) {
        renderer.setSeriesPaint(i, Color.red);
        renderer.setSeriesLinesVisible(i, true);
        renderer.setSeriesStroke(i, new BasicStroke(1.0f));
    }

    plot.setRenderer(renderer);

    panelWhenInside.add(chartPanel, BorderLayout.CENTER);
    panelWhenInside.validate();
}

From source file:com.sciaps.common.RegionMarkerItem.java

private void createMarker() {
    final Color c = new Color(8, 255, 8, 63);
    marker_ = new IntervalMarker(min_, max_, c, new BasicStroke(2.0f), null, null, 1.0f);
    String[] tmp = name_.split("-");
    marker_.setLabel(tmp[0]);/*from  ww w. java 2s . co m*/
    marker_.setLabelPaint(Color.blue);
    marker_.setLabelFont(new java.awt.Font("Tahoma", 1, 14));
    marker_.setLabelOffset(new RectangleInsets(50, 10, 10, 20));
}

From source file:org.jls.toolbox.math.chart.Thermometer.java

/**
 * Permet de crer et de paramtrer le thermomtre.
 *///ww w .  j av  a  2s. c  om
private void createChart() {
    this.plot = new ThermometerPlot(this.dataset);
    this.chart = new JFreeChart(this.plot);

    this.plot.setInsets(new RectangleInsets(0, 0, 0, 0));
    this.plot.setPadding(new RectangleInsets(0, 0, 0, 0));
    this.plot.setThermometerStroke(new BasicStroke(1.0f));
    this.plot.setThermometerPaint(Color.black);
    this.plot.setFollowDataInSubranges(true);
    this.plot.setRange(0, 100);
    this.plot.setForegroundAlpha(100);

    // this.chart.setBackgroundPaint(new JPanel().getBackground());
    this.chart.setAntiAlias(true);
    this.chart.setPadding(new RectangleInsets(0, 0, 0, 0));
    this.chart.setTitle(this.title);

    this.panel = new ChartPanel(this.chart);
    double coeff = 0.3;
    int width = (int) (this.panel.getPreferredSize().getWidth() * coeff);
    int height = (int) (this.panel.getPreferredSize().getHeight() * coeff);
    this.panel.setPreferredSize(new Dimension(width, height));
}

From source file:org.openaltimeter.desktopapp.annotations.XYDotAnnotation.java

@Override
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis,
        int rendererIndex, PlotRenderingInfo info) {
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation);

    float anchorX = (float) domainAxis.valueToJava2D(x, dataArea, domainEdge);
    float anchorY = (float) rangeAxis.valueToJava2D(y, dataArea, rangeEdge);

    if (orientation == PlotOrientation.HORIZONTAL) {
        float tempAnchor = anchorX;
        anchorX = anchorY;//from w w  w .j  ava2s.  c o  m
        anchorY = tempAnchor;
    }

    // dot drawing
    g2.setPaint(color);
    g2.setStroke(new BasicStroke(1.0f));
    Ellipse2D e = new Ellipse2D.Double(anchorX - size / 2, anchorY - size / 2, size, size);
    g2.fill(e);
}

From source file:edu.ucla.stat.SOCR.chart.demo.XYStepRendererDemo1.java

/**
 * Creates a sample chart./* ww  w . j  a va  2  s .  c  om*/
 * 
 * @param dataset  a dataset for the chart.
 * 
 * @return A sample chart.
 */
protected JFreeChart createChart(XYDataset dataset) {
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, domainLabel, rangeLabel, dataset,
            PlotOrientation.VERTICAL, !legendPanelOn, true, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    XYStepRenderer renderer = new XYStepRenderer();
    renderer.setBaseStroke(new BasicStroke(2.0f));
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    renderer.setDefaultEntityRadius(6);
    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

    plot.setRenderer(renderer);
    setXSummary(dataset);
    return chart;
}

From source file:org.openmrs.module.vcttrac.web.view.chart.AbstractChartView.java

/**
 * @see org.springframework.web.servlet.view.AbstractView
 *//*from  w ww. j  ava2s.co m*/
@Override
@SuppressWarnings("unchecked")
protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    // Respond as a PNG image
    response.setContentType("image/png");

    // Disable caching
    response.setHeader("Pragma", "No-cache");
    response.setDateHeader("Expires", 0);
    response.setHeader("Cache-Control", "no-cache");

    int width = (request.getParameter("width") != null && request.getParameter("width").compareTo("") != 0)
            ? (Integer.valueOf(request.getParameter("width")))
            : 450;
    int height = (request.getParameter("height") != null && request.getParameter("height").compareTo("") != 0)
            ? (Integer.valueOf(request.getParameter("height")))
            : 350;

    JFreeChart chart = createChart(model, request);
    chart.setBackgroundPaint(Color.WHITE);
    chart.getPlot().setOutlineStroke(new BasicStroke(0));
    chart.getPlot().setOutlinePaint(getBackgroundColor());
    chart.getPlot().setBackgroundPaint(getBackgroundColor());

    chart.getPlot().setNoDataMessage(VCTTracUtil.getMessage("vcttrac.error.noDataAvailable", null));

    ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, width, height);
}

From source file:org.matsim.analysis.LegHistogramChart.java

static JFreeChart getGraphic(final LegHistogram.DataFrame dataFrame, final String mode, int iteration) {
    final XYSeriesCollection xyData = new XYSeriesCollection();
    final XYSeries departuresSerie = new XYSeries("departures", false, true);
    final XYSeries arrivalsSerie = new XYSeries("arrivals", false, true);
    final XYSeries onRouteSerie = new XYSeries("en route", false, true);
    int onRoute = 0;
    for (int i = 0; i < dataFrame.countsDep.length; i++) {
        onRoute = onRoute + dataFrame.countsDep[i] - dataFrame.countsArr[i] - dataFrame.countsStuck[i];
        double hour = i * dataFrame.binSize / 60.0 / 60.0;
        departuresSerie.add(hour, dataFrame.countsDep[i]);
        arrivalsSerie.add(hour, dataFrame.countsArr[i]);
        onRouteSerie.add(hour, onRoute);
    }// w  w w  .java2 s.c  om

    xyData.addSeries(departuresSerie);
    xyData.addSeries(arrivalsSerie);
    xyData.addSeries(onRouteSerie);

    final JFreeChart chart = ChartFactory.createXYStepChart("Leg Histogram, " + mode + ", it." + iteration,
            "time", "# persons", xyData, PlotOrientation.VERTICAL, true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();

    final CategoryAxis axis1 = new CategoryAxis("hour");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    plot.setDomainAxis(new NumberAxis("time"));

    plot.getRenderer().setSeriesStroke(0, new BasicStroke(2.0f));
    plot.getRenderer().setSeriesStroke(1, new BasicStroke(2.0f));
    plot.getRenderer().setSeriesStroke(2, new BasicStroke(2.0f));
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.gray);
    plot.setDomainGridlinePaint(Color.gray);

    return chart;
}