2013-08-20 72 views
0

我在javafx中繪製時間軸動畫。下面是創建線的代碼:如何使annotation僅在一個窗格中可見? JavaFX

public Line getLine() { 

Point startPoint = FigureUtil.translateGeographicalToViewCoords(center.longitude, center.latitude, mapViewState); 
line = new Line(); 
line.setStartX(startPoint.x); 
line.setStartY(startPoint.y); 
line.setStrokeWidth(4); 

line.setStyle("-fx-stroke: rgba(37, 176, 79, 0.5);"); 
return line; 
} 

public void stop(){ 
timer.stop(); 
timeline.stop(); 
} 
private KeyFrame getFrame() { 
Duration duration = Duration.millis(60/speedOfRotating); 

EventHandler<ActionEvent> onFinished = new EventHandler<ActionEvent>() { 
    public void handle(ActionEvent t) { 
    LatLong latLong = LongitudeLatitudeUtil.getLatLongByDistanceAndAngle(center, time, size); 
    Point endPoint = FigureUtil.translateGeographicalToViewCoords(latLong.longitude, latLong.latitude, mapViewState); 
    line.setEndX(endPoint.x); 
    line.setEndY(endPoint.y); 
    time++; 
    } 
}; 
KeyFrame keyFrame = new KeyFrame(duration, onFinished); 
return keyFrame; 
} 

private void startTimer() { 
timer = new AnimationTimer() { 
    @Override 
    public void handle(long l) { 
    time++; 
    if (time > 360) { 
     time = 0; 
    } 
    } 
}; 
timer.start(); 
} 

public void start() { 
startTimer(); 
timeline = new Timeline(); 
timeline.setCycleCount(Timeline.INDEFINITE); 
timeline.setAutoReverse(true); 
// You can add a specific action when each frame is started. 

// timeline.getKeyFrames().remove(1); 
timeline.getKeyFrames().add(getFrame()); 
timeline.play(); 

} 

當我添加它添加到窗格我有這樣一個問題:[1]:http://img.image-storage.com/69224197/be380fee3e074.jpg。 線條不應該顯示在我添加到的窗格之外(它用虛線分隔)。

回答

0

你可以簡單地爲您添加行到容器節點指定剪輯。

linesContainer.setClip(RectangleBuilder.create().width(linesContainer.getWidth()).height(linesContainer.getHeight()).build());

0

,您可以使用裁剪來掩蓋節點的特定區域:

Line line = LineBuilder.create().endX(250).endY(250).build(); 
// pane to clip 
FlowPane pane = FlowPaneBuilder.create().minHeight(200).minWidth(200).children(line).build(); 
// clipping shape 
Rectangle rect = RectangleBuilder.create().x(pane.getLayoutX()).y(pane.getLayoutY()).width(pane.getMinWidth()).height(pane.getMinHeight()).build(); 

pane.setClip(rect); 
相關問題