The CAP decoration is applied at the end of each dash as documented
(though admittedly this phrase isn't repeated in the docs of the
constructors, just the class comments and the constants).  Thus, the
round caps will eat into the null space of the dashes by half of the
line width on both ends of each dash.  Square caps will also eat into
the null voids of the dash pattern.

The net effect is that if you have a line width of 4 and a dash pattern
of 4,4 and a CAP of:

       BUTT    - lines look 4,4 dashed
       SQUARE  - lines look continuous with no dashing
       ROUND   - lines connect, but "narrow" between the dashes

You are using a line width of 2 with the pattern of 4,4 and so the
effect isn't as pronounced as those examples, but it still makes it look
like the pattern has reduced null areas.  The parts where it closes
completely could be the rendering code trying to do something sensible
with a circular shape that is only 2 pixels tall - which release and
platform is that on?

In any case, try the different values for CAP and you should see the
dash open up or close more.  If you then go back and modify your dash
pattern to account for the fact that the CAPs are eating into the null
space of the pattern you should be able to achieve the effect you are
looking for.

Also, ROUND caps with a line width of 2 doesn't leave much room for
"roundness".  That is probably responsible for most of the inconsistency
you see on the various angles.  Try a line width of at least 3 for ROUND
or use BUTT instead...

                       ...jim

Russell East wrote:
Hi,
the attached sample app uses Java2D dash pattern to try to create a
railway pattern, but the result isn't very good.

The code is specifying the dash array as { 4.0f, 4.0f } but I'm seeing
variable results:
  o  on the top line it seems more like {5, 3}
  o  on the left line seems more like { 6, 2, 5, 3 } and
  o  on the bottom line does not look dashed at all

Is it something I'm doing wrong in my code, or known problem?

-- Russell

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".


------------------------------------------------------------------------

/*
 * Copyright (C) 1999 - 2006 by Environmental Systems Research Institute Inc.
 * All Rights Reserved.
 *
 *  N O T I C E
 *
 *  THIS MATERIAL IS CONSIDERED A TRADE SECRET BY ESRI.
 *  UNAUTHORIZED ACCESS IS PROHIBITED.
 *
 * $Workfile:$  $Revision:$
 */

package com.esri.mc.app;

import javax.swing.*;
import java.awt.*;
import java.awt.geom.GeneralPath;

/**
 * dash lines look wrong
 */
public class RailwayLines extends JFrame {

    public static void main(String[] args) {
        new RailwayLines().setVisible(true);
    }

    public RailwayLines() {
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setBounds(200, 200, 500, 300);
        String text = System.getProperty("java.vm.version");
        this.setTitle(text);
        MyCanvas canvas = new MyCanvas();
        this.getContentPane().add(canvas);
    }
}

final class MyCanvas extends JComponent {
    private Stroke topStroke, backStroke;
    private Color topColor, backColor;
    private GeneralPath path;

    MyCanvas() {
        topStroke = constructTopStroke();
        backStroke = constructBackStroke();
        topColor = Color.WHITE;
        backColor = new Color(102, 102, 102);
        path = constructPath();
    }

    private GeneralPath constructPath() {
        GeneralPath path = new GeneralPath();
        path.moveTo(100.0f, 100.0f);
        path.lineTo(200.0f, 200.0f);
        path.lineTo(400.0f, 200.0f);
        path.lineTo(400.0f, 100.0f);
        path.closePath();
        return path;
    }

    private Stroke constructBackStroke() {
        float width = 4.0f;
        int cap = BasicStroke.CAP_ROUND;
        int join = BasicStroke.JOIN_ROUND;
        return new BasicStroke(width, cap, join);
    }

    private Stroke constructTopStroke() {
        float width = 2.0f;
        int cap = BasicStroke.CAP_ROUND;
        int join = BasicStroke.JOIN_ROUND;
        float miterLimit = 10.f;
        float[] dash = { 4.0f, 4.0f };
        float dashPhase = 0.0f;
        return new BasicStroke(width, cap, join, miterLimit, dash, dashPhase);
    }

    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g;
        g2.setColor(backColor);
        g2.setStroke(backStroke);
        g2.draw(path);
        g2.setColor(topColor);
        g2.setStroke(topStroke);
        g2.draw(path);
    }
}

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to