Example usage for java.awt BasicStroke CAP_BUTT

List of usage examples for java.awt BasicStroke CAP_BUTT

Introduction

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

Prototype

int CAP_BUTT

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

Click Source Link

Document

Ends unclosed subpaths and dash segments with no added decoration.

Usage

From source file:TransformTranslatedRotation.java

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

    // Use antialiasing.
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    // Move the origin to 75, 75.
    AffineTransform at = AffineTransform.getTranslateInstance(75, 75);
    g2.transform(at);// w w  w . ja  v  a  2s. com

    // Draw the shapes in their original locations.
    g2.setPaint(Color.black);
    g2.draw(axes);
    g2.draw(shape);

    // Transform the Graphics2D.
    float cm = 72 / 2.54f;
    g2.transform(AffineTransform.getRotateInstance(-Math.PI / 6, 3 * cm, 2 * cm));

    // Draw the "new" shapes in dashed.
    Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 3, 1 },
            0);
    g2.setStroke(stroke);
    g2.draw(axes);
    g2.draw(shape);
}

From source file:TransformTransRotation.java

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

    // Use antialiasing.
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    // Move the origin to 75, 75.
    AffineTransform at = AffineTransform.getTranslateInstance(75, 75);
    g2.transform(at);/*from  ww  w.j  a  va 2s .co  m*/

    // Draw the shapes in their original locations.
    g2.setPaint(Color.black);
    g2.draw(axes);
    g2.draw(shape);

    // Transform the Graphics2D.
    AffineTransform rat = new AffineTransform();
    rat.setToTranslation(100, 0);
    rat.rotate(Math.PI / 6);
    g2.transform(rat);

    // Draw the "new" shapes in dashed.
    Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 3, 1 },
            0);
    g2.setStroke(stroke);
    g2.draw(axes);
    g2.draw(shape);
}

From source file:TransformersRotationTranslation.java

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

    // Use antialiasing.
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    // Move the origin to 75, 75.
    AffineTransform at = AffineTransform.getTranslateInstance(75, 75);
    g2.transform(at);//from   w  ww.j  a  va2 s  .co m

    // Draw the shapes in their original locations.
    g2.setPaint(Color.black);
    g2.draw(axes);
    g2.draw(shape);

    // Transform the Graphics2D.
    AffineTransform rat = new AffineTransform();
    rat.setToRotation(Math.PI / 6);
    rat.translate(100, 100);

    g2.transform(rat);

    // Draw the "new" shapes in dashed.
    Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 3, 1 },
            0);
    g2.setStroke(stroke);
    g2.draw(axes);
    g2.draw(shape);
}

From source file:TransformShear.java

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

    // Use antialiasing.
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    // Move the origin to 75, 75.
    AffineTransform at = AffineTransform.getTranslateInstance(75, 75);
    g2.transform(at);/*from w  w  w. j  a v a  2 s .  c o m*/

    // Draw the shapes in their original locations.
    g2.setPaint(Color.black);
    g2.draw(axes);
    g2.draw(shape);

    // Transform the Graphics2D.
    AffineTransform sat = AffineTransform.getTranslateInstance(150, 0);
    sat.shear(-.5, 0);
    g2.transform(sat);

    // Draw the "new" shapes in dashed.
    g2.transform(AffineTransform.getTranslateInstance(75, 75));

    Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 3, 1 },
            0);
    g2.setStroke(stroke);
    g2.draw(axes);
    g2.draw(shape);
}

From source file:TextLayoutWithCarets.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);

    if (mInitialized == false)
        initialize(g2);//from   w w  w.ja v a2 s  . c om

    float x = 20, y = 80;
    mLayout.draw(g2, x, y);

    // Create a plain stroke and a dashed stroke.
    Stroke[] caretStrokes = new Stroke[2];
    caretStrokes[0] = new BasicStroke();
    caretStrokes[1] = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 0, new float[] { 4, 4 },
            0);

    // Now draw the carets
    Shape[] carets = mLayout.getCaretShapes(mHit.getInsertionIndex());
    for (int i = 0; i < carets.length; i++) {
        if (carets[i] != null) {
            AffineTransform at = AffineTransform.getTranslateInstance(x, y);
            Shape shape = at.createTransformedShape(carets[i]);
            g2.setStroke(caretStrokes[i]);
            g2.draw(shape);
        }
    }
}

From source file:mediamatrix.gui.JVMMemoryProfilerPanel.java

public JVMMemoryProfilerPanel() {
    initComponents();/*from ww  w. j av  a2 s . co  m*/
    profiler = new JVMMemoryProfiler(frequency);
    profiler.addListener(new JVMMemoryProfilerListener() {

        @Override
        public void addScore(long t, long f) {
            total.add(new Millisecond(), t);
            free.add(new Millisecond(), f);
        }
    });

    total = new TimeSeries("Total Memory");
    total.setMaximumItemCount(historyCount);
    free = new TimeSeries("Free Memory");
    free.setMaximumItemCount(historyCount);

    final TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(total);
    dataset.addSeries(free);

    final DateAxis domain = new DateAxis("Time");
    final NumberAxis range = new NumberAxis("Memory");
    domain.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    domain.setLabelFont(new Font("SansSerif", Font.PLAIN, 14));
    range.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    range.setLabelFont(new Font("SansSerif", Font.PLAIN, 14));
    range.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    final XYItemRenderer renderer = new DefaultXYItemRenderer();
    renderer.setSeriesPaint(0, Color.red);
    renderer.setSeriesPaint(1, Color.green);
    renderer.setBaseStroke(new BasicStroke(3f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));

    final XYPlot plot = new XYPlot(dataset, domain, range, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    domain.setAutoRange(true);
    domain.setLowerMargin(0.0);
    domain.setUpperMargin(0.0);
    domain.setTickLabelsVisible(true);

    final JFreeChart chart = new JFreeChart("JVM Memory Usage", new Font("SansSerif", Font.BOLD, 24), plot,
            true);
    chart.setBackgroundPaint(Color.white);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4),
            BorderFactory.createLineBorder(Color.black)));
    chart.getLegend().setItemFont(new Font("SansSerif", Font.PLAIN, 12));

    add(chartPanel, BorderLayout.CENTER);
}

From source file:net.sf.jasperreports.chartthemes.spring.ScaledDialRange.java

/**
 * Draws the range.//w w w .  jav  a  2  s.c o m
 * 
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame (in Java2D space).
 * @param view  the dial's view rectangle (in Java2D space).
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    Rectangle2D arcRectInner = DialPlot.rectangleByRadius(frame, this.getInnerRadius(), this.getInnerRadius());
    Rectangle2D arcRectOuter = DialPlot.rectangleByRadius(frame, this.getOuterRadius(), this.getOuterRadius());

    DialScale scale = plot.getScale(this.getScaleIndex());
    if (scale == null) {
        throw new RuntimeException("No scale for scaleIndex = " + this.getScaleIndex());
    }
    double angleMin = scale.valueToAngle(this.getLowerBound());
    double angleMax = scale.valueToAngle(this.getUpperBound());

    Arc2D arcInner = new Arc2D.Double(arcRectInner, angleMin, angleMax - angleMin, Arc2D.OPEN);
    Arc2D arcOuter = new Arc2D.Double(arcRectOuter, angleMax, angleMin - angleMax, Arc2D.OPEN);

    g2.setPaint(this.getPaint());
    g2.setStroke(new BasicStroke(this.lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
    g2.draw(arcInner);
    g2.draw(arcOuter);
}

From source file:net.sf.fspdfs.chartthemes.spring.ScaledDialRange.java

/**
 * Draws the range./*from ww  w. j  av a2 s . c  o m*/
 * 
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame (in Java2D space).
 * @param view  the dial's view rectangle (in Java2D space).
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    Rectangle2D arcRectInner = DialPlot.rectangleByRadius(frame, this.getInnerRadius(), this.getInnerRadius());
    Rectangle2D arcRectOuter = DialPlot.rectangleByRadius(frame, this.getOuterRadius(), this.getOuterRadius());

    DialScale scale = plot.getScale(this.getScaleIndex());
    if (scale == null) {
        throw new RuntimeException("No scale for scaleIndex = " + this.getScaleIndex());
    }
    double angleMin = scale.valueToAngle(this.getLowerBound());
    double angleMax = scale.valueToAngle(this.getUpperBound());

    Arc2D arcInner = new Arc2D.Double(arcRectInner, angleMin, angleMax - angleMin, Arc2D.OPEN);
    Arc2D arcOuter = new Arc2D.Double(arcRectOuter, angleMax, angleMin - angleMax, Arc2D.OPEN);

    g2.setPaint(this.getPaint());
    g2.setStroke(new BasicStroke(this.lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
    g2.draw(arcInner);
    g2.draw(arcOuter);
}

From source file:sturesy.votinganalysis.TimeChart.java

/**
 * Creates an XYSeries-ChartPanel/*from w w  w.  j  a va 2 s . c  o m*/
 * 
 * @param votes
 *            votes to use
 * @return ChartPanel
 */
private ChartPanel getXYSeriesChart(Set<Vote> votes) {

    final XYSeries series = new XYSeries(Localize.getString("label.votes.over.time"));

    if (votes.size() != 0) {
        double[] dubble = createArrayOfVotes(votes);

        for (int i = 0; i < dubble.length; i++) {
            series.add(i, dubble[i]);
        }
    }
    final XYSeriesCollection data = new XYSeriesCollection(series);

    final JFreeChart chart = ChartFactory.createXYLineChart(Localize.getString("label.votes.over.time"),
            Localize.getString("label.time.seconds"), Localize.getString("label.amount.votes"), data,
            PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(_background);
    chart.getPlot().setNoDataMessage("NO DATA");

    chart.getXYPlot().getRenderer().setSeriesStroke(0,
            new BasicStroke(3.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f));
    chart.getXYPlot().getRenderer().setSeriesPaint(0, new Color(255, 140, 0));

    chart.getXYPlot().getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    chart.getXYPlot().getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    ChartPanel chartpanel = new ChartPanel(chart);
    return chartpanel;
}

From source file:edu.jhuapl.graphs.jfreechart.TimeSeriesEffectsTest.java

public static JFreeChartGraphSource getSource() throws GraphException {
    Calendar base = Calendar.getInstance();
    base.set(Calendar.WEEK_OF_YEAR, 6);

    Random r = new Random();

    List<TimePoint> ps1 = new LinkedList<TimePoint>();
    List<TimePoint> ps2 = new LinkedList<TimePoint>();
    List<TimePoint> ps3 = new LinkedList<TimePoint>();

    for (int count = 0; count < 4; count += 1) {
        base.set(Calendar.DAY_OF_WEEK, 2);
        addPoint(base.getTime(), ps2, r);

        // now generate five points for ps1 and p23, the daily sets
        addPoint(base.getTime(), ps1, r);
        addPoint(base.getTime(), ps3, r, "showPoint?week=" + count + "&day=0", null);

        for (int i = 1; i < 5; i += 1) {
            base.add(Calendar.DAY_OF_WEEK, 1);
            addPoint(base.getTime(), ps1, r);
            addPoint(base.getTime(), ps3, r, "showPoint?week=" + count + "&day=" + i, null);
        }/*from  w w  w.  j  a v a  2 s .c  o  m*/

        base.set(Calendar.DAY_OF_WEEK, 1);
        base.add(Calendar.WEEK_OF_YEAR, 1);
    }

    List<DefaultTimeSeries> series = new LinkedList<DefaultTimeSeries>();
    Map<String, Object> s1Md = new HashMap<String, Object>();
    s1Md.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.DAILY);
    s1Md.put(GraphSource.SERIES_SHAPE, new Ellipse2D.Float(-5, -5, 10, 10));
    s1Md.put(GraphSource.SERIES_TITLE, "Frederick County Counts");
    series.add(new DefaultTimeSeries(ps1, s1Md));

    Map<String, Object> s2Md = new HashMap<String, Object>();
    s2Md.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.WEEKLY);
    s2Md.put(GraphSource.SERIES_SHAPE, new Ellipse2D.Float(-7, -7, 14, 14));
    s2Md.put(GraphSource.SERIES_TITLE, "NCR Counts");
    series.add(new DefaultTimeSeries(ps2, s2Md));

    Map<String, Object> s3Md = new HashMap<String, Object>();
    s3Md.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.DAILY);
    s3Md.put(GraphSource.SERIES_SHAPE, new Rectangle2D.Float(-3, -3, 6, 6));
    s3Md.put(GraphSource.SERIES_TITLE, "Carroll County Counts");
    BasicStroke bs = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10,
            new float[] { 3F, 2F, 8F }, 1F);
    s3Md.put(GraphSource.SERIES_STROKE, bs);
    series.add(new DefaultTimeSeries(ps3, s3Md));

    Map<String, Object> params = new HashMap<String, Object>();
    params.put(GraphSource.BACKGROUND_COLOR, Color.BLUE);
    params.put(JFreeChartTimeSeriesGraphSource.PLOT_COLOR, Color.WHITE);
    params.put(GraphSource.GRAPH_TITLE, "Counts");
    params.put(GraphSource.GRAPH_X_LABEL, "Time");
    params.put(GraphSource.GRAPH_Y_LABEL, "Total Counts");
    DateAxis customAxis = new RotatedTickDateAxis(60.);
    params.put(JFreeChartTimeSeriesGraphSource.DATE_AXIS, customAxis);

    JFreeChartGraphSource source = new JFreeChartGraphSource();
    source.setData(series);
    source.setParams(params);
    source.initialize();

    return source;
}