import javafx.application.Application; 
import javafx.scene.Group; 
import javafx.scene.Scene; 
import javafx.scene.paint.Color; 
import javafx.scene.shape.Line; 
import javafx.scene.shape.StrokeLineCap; 
import javafx.stage.Stage; 

/** 
 * Sample to reproduce the poor rendering performance of dashed strokes. 
 * Change the value of the variable dashed to switch between solid and non-solid strokes. 
 * Drag the mouse to watch the rendering performance. 
 */ 
public class TestDashStyle extends Application { 
	private boolean dashed = false; 
	
	public static void main(String[] args) {
		launch(args);
	}
	
	@Override 
	public void start(Stage primaryStage) throws Exception { 
		primaryStage.setTitle("Performance of Non-Solid Lines"); 

		Group root = new Group(); 

		for (int i = 0; i < 1000; i += 10) { 
			Line line1 = createLine(i, 0, i, 1000); 
			Line line2 = createLine(0, i, 1000, i); 
			root.getChildren().addAll(line1, line2); 
		} 

		Scene scene = new Scene(root, 1200, 800); 
		scene.setOnMouseDragged(event -> { 
			root.setTranslateX(event.getX()); 
			root.setTranslateY(event.getY()); 
		}); 

		primaryStage.setScene(scene); 
		primaryStage.show(); 
	} 

	private Line createLine(double startX, double startY, double endX, double endY) { 
		double thickness = 1; 
		Line line = new Line(startX, startY, endX, endY); 
		line.setStroke(Color.RED); 
		line.setStrokeWidth(thickness); 
		if (dashed) { 
			line.setStrokeLineCap(StrokeLineCap.SQUARE); 
			line.getStrokeDashArray().addAll(0.0, 3.0 * thickness); 
		} 
		return line; 
	} 
} 
