Java 类javafx.scene.canvas.Canvas 实例源码
项目:hygene
文件:Snapshot.java
/**
* Takes a snapshot of a canvas and saves it to the destination.
* <p>
* After the screenshot is taken it shows a dialogue to the user indicating the location of the snapshot.
*
* @param canvas a JavaFX {@link Canvas} object
* @return the destination of the screenshot
*/
public String take(final Canvas canvas) {
final WritableImage writableImage = new WritableImage((int) canvas.getWidth(), (int) canvas.getHeight());
final WritableImage snapshot = canvas.snapshot(new SnapshotParameters(), writableImage);
try {
ImageIO.write(SwingFXUtils.fromFXImage(snapshot, null), FILE_FORMAT, destination);
new InformationDialogue(
"Snapshot taken",
"You can find your snapshot here: " + destination.getAbsolutePath()
).show();
} catch (final IOException e) {
LOGGER.error("Snapshot could not be taken.", e);
new ErrorDialogue(e).show();
}
return destination.getAbsolutePath();
}
项目:KDTree
文件:KDTreeDemo.java
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("2DTree Demo");
Group root = new Group();
Canvas canvas = new Canvas(XSIZE, YSIZE);
gc = canvas.getGraphicsContext2D();
canvas.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent e) {
gc.fillOval(e.getX(), e.getY(), 3, 3);
double[] coords = { e.getX() / XSIZE, e.getY() / YSIZE };
instance.insert(new HyperPoint(coords));
instance.draw();
}
});
root.getChildren().add(canvas);
Scene sc = new Scene(root);
primaryStage.setScene(sc);
primaryStage.show();
}
项目:Aidos
文件:Sandbox.java
private static void init() {
root = new Group();
s = new Scene(root, SCENE_WIDTH, SCENE_HEIGHT);
c = new Canvas(CANVAS_WIDTH, CANVAS_HEIGHT);
root.getChildren().add(c);
gc = c.getGraphicsContext2D();
gc.setStroke(Color.BLUE);
gc.setLineWidth(2);
gc.setFill(Color.BLUE);
Renderer.init();
GameLoop.start(gc);
//Initialize Objects
Player p = new Player();
setPlayer(p);
//load map
loadMap();
//should be called at last it based on player
EventHandler.attachEventHandlers(s);
}
项目:circularplot
文件:CircularPlot.java
private void initGraphics() {
if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
Double.compare(getHeight(), 0.0) <= 0) {
if (getPrefWidth() > 0 && getPrefHeight() > 0) {
setPrefSize(getPrefWidth(), getPrefHeight());
} else {
setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
}
}
getStyleClass().add("circular-plot");
canvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
ctx = canvas.getGraphicsContext2D();
ctx.setLineCap(StrokeLineCap.BUTT);
getChildren().setAll(canvas);
}
项目:netTanks
文件:Framework.java
public Framework(int width, int height) {
this.setWidth(width);
this.setHeight(height);
random = new Random();
bullets = new ArrayList<>();
tanks = new ArrayList<>();
mines = new ArrayList<>();
pickUps = new ArrayList<>();
hud = new HUD(this);
canvas = new Canvas(width, height);
gc = canvas.getGraphicsContext2D();
canvas.setWidth(width);
canvas.setHeight(height);
this.getChildren().add(canvas);
//Create Game Loop
gameloop = new Timeline(new KeyFrame(
Duration.millis(16.666666666667),
ae -> update()));
gameloop.setCycleCount(Timeline.INDEFINITE);
//Set SCALE to current scale of Canvas
SCALE = this.getScaleX();
//Make the Canvas register keystrokes
this.addEventFilter(MouseEvent.ANY, (e) -> this.requestFocus());
//Set Inputs
setKeyInput();
setMouseInput();
}
项目:dotmatrix
文件:DotMatrix.java
private void initGraphics() {
// prefill matrix with dotOffColor
for (int y = 0 ; y < rows ; y++) {
for (int x = 0 ; x < cols ; x++) {
matrix[x][y] = dotOffColor;
}
}
if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 ||
Double.compare(getWidth(), 0.0) <= 0 || Double.compare(getHeight(), 0.0) <= 0) {
if (getPrefWidth() > 0 && getPrefHeight() > 0) {
setPrefSize(getPrefWidth(), getPrefHeight());
} else {
setPrefSize(preferredWidth, preferredHeight);
}
}
canvas = new Canvas(preferredWidth, preferredHeight);
ctx = canvas.getGraphicsContext2D();
pane = new StackPane(canvas);
getChildren().setAll(pane);
}
项目:candlelight
文件:ResizeableLayeredCanvasPane.java
@Override
protected void layoutChildren()
{
super.layoutChildren();
final double x = this.snappedLeftInset();
final double y = this.snappedTopInset();
final double w = this.snapSize(this.getWidth()) - x - this.snappedRightInset();
final double h = this.snapSize(this.getHeight()) - y - this.snappedBottomInset();
for(Canvas canvas : this.layers)
{
canvas.setLayoutX(x);
canvas.setLayoutY(y);
canvas.setWidth(w);
canvas.setHeight(h);
}
}
项目:sankeyplot
文件:SankeyPlot.java
private void initGraphics() {
if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
Double.compare(getHeight(), 0.0) <= 0) {
if (getPrefWidth() > 0 && getPrefHeight() > 0) {
setPrefSize(getPrefWidth(), getPrefHeight());
} else {
setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
}
}
getStyleClass().add("sankey-plot");
canvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
ctx = canvas.getGraphicsContext2D();
getChildren().setAll(canvas);
}
项目:PhotoScript
文件:DragBox.java
/**
* 初始化背景绘画节点
*/
protected void initCanvas() {
canvas = new Canvas();
//在Canvas高宽改变的时候,重新绘制
canvas.heightProperty().addListener(observable -> {
clearConner();
drawConner();
});
canvas.widthProperty().addListener(observable -> {
clearConner();
drawConner();
});
//canvas的高宽于box的高宽绑定在一起
canvas.widthProperty().bind(Width);
canvas.heightProperty().bind(Height);
getChildren().add(canvas);
//无论Canvas接收到什么鼠标事件都传递给Box处理
canvas.setMouseTransparent(true);
}
项目:worldheatmap
文件:HeatMap.java
public HeatMap(final double WIDTH, final double HEIGHT, ColorMapping COLOR_MAPPING, final double EVENT_RADIUS, final boolean FADE_COLORS, final double HEAT_MAP_OPACITY, final OpacityDistribution OPACITY_DISTRIBUTION) {
super();
SNAPSHOT_PARAMETERS.setFill(Color.TRANSPARENT);
eventList = new ArrayList();
eventImages = new HashMap<>();
colorMapping = COLOR_MAPPING;
mappingGradient = colorMapping.mapping;
fadeColors = FADE_COLORS;
radius = EVENT_RADIUS;
opacityDistribution = OPACITY_DISTRIBUTION;
eventImage = createEventImage(radius, opacityDistribution);
monochrome = new Canvas(WIDTH, HEIGHT);
ctx = monochrome.getGraphicsContext2D();
monochromeImage = new WritableImage((int) WIDTH, (int) HEIGHT);
setImage(heatMap);
setMouseTransparent(true);
setOpacity(HEAT_MAP_OPACITY);
registerListeners();
}
项目:charts
文件:HeatMap.java
public HeatMap(final double WIDTH, final double HEIGHT, ColorMapping COLOR_MAPPING, final double SPOT_RADIUS, final boolean FADE_COLORS, final double HEAT_MAP_OPACITY, final OpacityDistribution OPACITY_DISTRIBUTION) {
super();
SNAPSHOT_PARAMETERS.setFill(Color.TRANSPARENT);
spotList = new ArrayList<>();
spotImages = new HashMap<>();
colorMapping = COLOR_MAPPING;
mappingGradient = colorMapping.getGradient();
fadeColors = FADE_COLORS;
radius = SPOT_RADIUS;
opacityDistribution = OPACITY_DISTRIBUTION;
spotImage = createSpotImage(radius, opacityDistribution);
monochrome = new Canvas(WIDTH, HEIGHT);
ctx = monochrome.getGraphicsContext2D();
monochromeImage = new WritableImage((int) WIDTH, (int) HEIGHT);
setImage(heatMap);
setMouseTransparent(true);
setOpacity(HEAT_MAP_OPACITY);
registerListeners();
}
项目:charts
文件:CoxcombChart.java
private void initGraphics() {
if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
Double.compare(getHeight(), 0.0) <= 0) {
if (getPrefWidth() > 0 && getPrefHeight() > 0) {
setPrefSize(getPrefWidth(), getPrefHeight());
} else {
setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
}
}
getStyleClass().add("coxcomb-chart");
popup = new InfoPopup();
canvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
ctx = canvas.getGraphicsContext2D();
ctx.setLineCap(StrokeLineCap.BUTT);
ctx.setTextBaseline(VPos.CENTER);
ctx.setTextAlign(TextAlignment.CENTER);
pane = new Pane(canvas);
getChildren().setAll(pane);
}
项目:charts
文件:Axis.java
private void initGraphics() {
if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
Double.compare(getHeight(), 0.0) <= 0) {
if (getPrefWidth() != 0 && getPrefHeight() != 0) {
if (VERTICAL == getOrientation()) {
setPrefSize(20, 250);
} else {
setPrefSize(250, 20);
}
}
}
getStyleClass().add("axis");
axisCanvas = new Canvas(width, height);
axisCtx = axisCanvas.getGraphicsContext2D();
pane = new Pane(axisCanvas);
getChildren().setAll(pane);
}
项目:charts
文件:PixelMatrix.java
private void initGraphics() {
// prefill matrix with pixelOffColor
for (int y = 0 ; y < rows ; y++) {
for (int x = 0 ; x < cols ; x++) {
matrix[x][y] = pixelOffColor;
}
}
if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 ||
Double.compare(getWidth(), 0.0) <= 0 || Double.compare(getHeight(), 0.0) <= 0) {
if (getPrefWidth() > 0 && getPrefHeight() > 0) {
setPrefSize(getPrefWidth(), getPrefHeight());
} else {
setPrefSize(preferredWidth, preferredHeight);
}
}
canvas = new Canvas(preferredWidth, preferredHeight);
ctx = canvas.getGraphicsContext2D();
getChildren().setAll(canvas);
}
项目:charts
文件:XYZPane.java
private void initGraphics() {
if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
Double.compare(getHeight(), 0.0) <= 0) {
if (getPrefWidth() > 0 && getPrefHeight() > 0) {
setPrefSize(getPrefWidth(), getPrefHeight());
} else {
setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
}
}
getStyleClass().setAll("chart", "xyz-chart");
canvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
ctx = canvas.getGraphicsContext2D();
pane = new Pane(canvas);
getChildren().setAll(pane);
}
项目:charts
文件:YPane.java
private void initGraphics() {
if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
Double.compare(getHeight(), 0.0) <= 0) {
if (getPrefWidth() > 0 && getPrefHeight() > 0) {
setPrefSize(getPrefWidth(), getPrefHeight());
} else {
setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
}
}
getStyleClass().setAll("chart", "xy-chart");
canvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
ctx = canvas.getGraphicsContext2D();
getChildren().setAll(canvas);
}
项目:charts
文件:NestedBarChart.java
private void initGraphics() {
if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
Double.compare(getHeight(), 0.0) <= 0) {
if (getPrefWidth() > 0 && getPrefHeight() > 0) {
setPrefSize(getPrefWidth(), getPrefHeight());
} else {
setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
}
}
getStyleClass().add("nested-bar-chart");
popup = new InfoPopup();
canvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
ctx = canvas.getGraphicsContext2D();
pane = new Pane(canvas);
getChildren().setAll(pane);
}
项目:charts
文件:CircularPlot.java
private void initGraphics() {
if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
Double.compare(getHeight(), 0.0) <= 0) {
if (getPrefWidth() > 0 && getPrefHeight() > 0) {
setPrefSize(getPrefWidth(), getPrefHeight());
} else {
setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
}
}
canvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
ctx = canvas.getGraphicsContext2D();
ctx.setLineCap(StrokeLineCap.BUTT);
tooltip = new Tooltip();
tooltip.setAutoHide(true);
getChildren().setAll(canvas);
}
项目:charts
文件:LegendItem.java
private void initGraphics() {
if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
Double.compare(getHeight(), 0.0) <= 0) {
if (getPrefWidth() > 0 && getPrefHeight() > 0) {
setPrefSize(getPrefWidth(), getPrefHeight());
} else {
setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
}
}
canvas = new Canvas(PREFERRED_HEIGHT, PREFERRED_HEIGHT);
ctx = canvas.getGraphicsContext2D();
ctx.setTextAlign(TextAlignment.LEFT);
ctx.setTextBaseline(VPos.CENTER);
pane = new Pane(canvas);
getChildren().setAll(pane);
}
项目:charts
文件:SankeyPlot.java
private void initGraphics() {
if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
Double.compare(getHeight(), 0.0) <= 0) {
if (getPrefWidth() > 0 && getPrefHeight() > 0) {
setPrefSize(getPrefWidth(), getPrefHeight());
} else {
setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
}
}
canvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
ctx = canvas.getGraphicsContext2D();
tooltip = new Tooltip();
tooltip.setAutoHide(true);
getChildren().setAll(canvas);
}
项目:charts
文件:Grid.java
private void initGraphics() {
if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
Double.compare(getHeight(), 0.0) <= 0) {
if (getPrefWidth() > 0 && getPrefHeight() > 0) {
setPrefSize(getPrefWidth(), getPrefHeight());
} else {
setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
}
}
canvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
ctx = canvas.getGraphicsContext2D();
pane = new Pane(canvas);
getChildren().setAll(pane);
}
项目:charts
文件:XYPane.java
private void initGraphics() {
if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
Double.compare(getHeight(), 0.0) <= 0) {
if (getPrefWidth() > 0 && getPrefHeight() > 0) {
setPrefSize(getPrefWidth(), getPrefHeight());
} else {
setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
}
}
getStyleClass().setAll("chart", "xy-chart");
canvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
ctx = canvas.getGraphicsContext2D();
getChildren().setAll(canvas);
}
项目:charts
文件:SunburstChart.java
private void initGraphics() {
if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
Double.compare(getHeight(), 0.0) <= 0) {
if (getPrefWidth() > 0 && getPrefHeight() > 0) {
setPrefSize(getPrefWidth(), getPrefHeight());
} else {
setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
}
}
segmentPane = new Pane();
chartCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
chartCanvas.setMouseTransparent(true);
chartCtx = chartCanvas.getGraphicsContext2D();
pane = new Pane(segmentPane, chartCanvas);
pane.setBackground(new Background(new BackgroundFill(backgroundPaint, CornerRadii.EMPTY, Insets.EMPTY)));
pane.setBorder(new Border(new BorderStroke(borderPaint, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(borderWidth))));
getChildren().setAll(pane);
prepareData();
}
项目:charts
文件:StreamChart.java
private void initGraphics() {
if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
Double.compare(getHeight(), 0.0) <= 0) {
if (getPrefWidth() > 0 && getPrefHeight() > 0) {
setPrefSize(getPrefWidth(), getPrefHeight());
} else {
setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
}
}
canvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
ctx = canvas.getGraphicsContext2D();
tooltip = new Tooltip();
tooltip.setAutoHide(true);
getChildren().setAll(canvas);
}
项目:Suji
文件:GameDrawer.java
public GameDrawer(Canvas canvas) {
this.canvas = canvas;
lastState = new Board();
setStoneDrawer(new SimpleStoneDrawer(canvas));
setBoardDrawer(new SimpleBoardDrawer(canvas));
canvas.widthProperty().addListener(this::onCanvasResize);
canvas.heightProperty().addListener(this::onCanvasResize);
hoverStone = null;
}
项目:Suji
文件:TexturedBoardDrawer.java
private TexturedBoardDrawer(Canvas canvas, Image backgroundTexture, Image lineTexture, boolean useSimpleLines) {
super(canvas);
background = backgroundTexture;
lines = lineTexture;
simpleLines = useSimpleLines;
}
项目:Suji
文件:SimpleBoardDrawer.java
@Override
public void drawLines() {
CoordProjector projector = getProjector();
GraphicsContext context = getGraphicsContext();
for (int i = 1; i < 20; i++) {
//Horizontal Lines
DrawCoords start = projector.fromBoardCoords(getCoords(1, i));
DrawCoords end = projector.fromBoardCoords(getCoords(19, i));
context.strokeLine(start.getX(), start.getY(), end.getX(), end.getY());
//Vertical Lines
start = projector.fromBoardCoords(getCoords(i, 1));
end = projector.fromBoardCoords(getCoords(i, 19));
context.strokeLine(start.getX(), start.getY(), end.getX(), end.getY());
}
Canvas canvas = context.getCanvas();
StoneDrawer drawer = new SimpleStoneDrawer(canvas);
double scale = DimensionHelper.getStoneRadius(canvas);
scale = (context.getLineWidth() * 4) / scale;
drawer.drawStones(getHandicapStones(9), BLACK, scale);
}
项目:Suji
文件:BoardController.java
private void constructCanvas() {
boardCanvas = new Canvas();
if ( interactive ) {
boardCanvas.setOnMouseMoved(this::canvasHover);
boardCanvas.setOnMouseClicked(this::canvasClicked);
boardCanvas.setOnMouseExited(this::canvasExit);
}
boardPane.getChildren().add(boardCanvas);
gameDrawer = buildGameDrawer();
gameDrawer.draw(getGameHandler().getBoard());
}
项目:Suji
文件:DimensionHelper.java
public static DrawCoords getTopLeftCorner(Canvas canvas) {
double length = getBoardLength(canvas);
double canvasWidth = canvas.getWidth();
double canvasHeight = canvas.getHeight();
double x = 0;
double y = 0;
if ( canvasWidth > length )
x = (canvasWidth - length) / 2;
else
y = (canvasHeight - length) / 2;
return new DrawCoords(x, y);
}
项目:horizon
文件:HorizonChart.java
private void initGraphics() {
if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
Double.compare(getHeight(), 0.0) <= 0) {
if (getPrefWidth() > 0 && getPrefHeight() > 0) {
setPrefSize(getPrefWidth(), getPrefHeight());
} else {
setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
}
}
canvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
ctx = canvas.getGraphicsContext2D();
getChildren().setAll(canvas);
}
项目:hygene
文件:HeatMapDrawing.java
/**
* Sets the {@link Canvas} for use during drawing.
* <p>
* Prompts a draw.
*
* @param canvas the {@link Canvas} on which drawing will take place
*/
public void setCanvas(final Canvas canvas) {
this.graphicsContext = canvas.getGraphicsContext2D();
this.canvasWidth = canvas.widthProperty();
this.canvasHeight = canvas.heightProperty();
canvasWidth.addListener((observable, oldValue, newValue) -> draw());
canvasHeight.addListener((observable, oldValue, newValue) -> draw());
draw();
}
项目:hygene
文件:SequenceVisualizer.java
/**
* Sets the {@link Canvas} for use by the visualizer.
* <p>
* When the user clicks on the canvas, if the x and y coordinates intersect with a base then the offset is updated
* to the given base. If the mouse is hovered over a base the hovered base id is updated.
*
* @param canvas {@link Canvas} for use by the visualizer
*/
public void setCanvas(final Canvas canvas) {
this.canvas = canvas;
this.graphicsContext = canvas.getGraphicsContext2D();
canvas.widthProperty().addListener((observable, oldValue, newValue) -> draw());
canvas.setOnMouseClicked(event -> {
Optional.of(rTree).ifPresent(tree -> tree.find(event.getX(), event.getY(), offsetProperty::set));
// Do a second search as base nodes have been shifted.
Optional.of(rTree).ifPresent(tree -> tree.find(event.getX(), event.getY(), hoveredBaseIdProperty::set));
});
canvas.setOnMouseMoved(event -> Optional.of(rTree)
.ifPresent(tree -> tree.find(event.getX(), event.getY(), hoveredBaseIdProperty::set)));
canvas.setOnMouseExited(event -> hoveredBaseIdProperty.set(-1));
}
项目:hygene
文件:SequenceVisualizerTest.java
@BeforeEach
void beforeEach() {
final Canvas canvas = mock(Canvas.class);
graphicsContext = mock(GraphicsContext.class);
canvasWidthProperty = mock(DoubleProperty.class);
when(canvas.getGraphicsContext2D()).thenReturn(graphicsContext);
when(canvas.widthProperty()).thenReturn(canvasWidthProperty);
sequenceVisualizer = new SequenceVisualizer();
sequenceVisualizer.setCanvas(canvas);
}
项目:hygene
文件:GraphDimensionsCalculatorTest.java
private Canvas mockCanvas() {
final Canvas canvas = mock(Canvas.class);
when(canvas.getWidth()).thenReturn(CANVAS_WIDTH);
when(canvas.getHeight()).thenReturn(CANVAS_HEIGHT);
return canvas;
}
项目:hygene
文件:SnapshotTest.java
@Test
void testSnapshot() {
final String expectedDestinationDirectory = new File(GFA_FILE_NAME).getParent();
interact(() -> {
final Canvas canvas = spy(Canvas.class);
when(canvas.getHeight()).thenReturn(10.0);
when(canvas.getWidth()).thenReturn(10.0);
final String destination = Snapshot.forGfaFile(new GfaFile(GFA_FILE_NAME)).take(canvas);
assertThat(destination).contains(expectedDestinationDirectory);
assertThat(new File(destination)).exists();
});
}
项目:SunburstChart
文件:SunburstChart.java
private void initGraphics() {
if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
Double.compare(getHeight(), 0.0) <= 0) {
if (getPrefWidth() > 0 && getPrefHeight() > 0) {
setPrefSize(getPrefWidth(), getPrefHeight());
} else {
setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
}
}
segmentPane = new Pane();
chartCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
chartCanvas.setMouseTransparent(true);
chartCtx = chartCanvas.getGraphicsContext2D();
pane = new Pane(segmentPane, chartCanvas);
pane.setBackground(new Background(new BackgroundFill(backgroundPaint, CornerRadii.EMPTY, Insets.EMPTY)));
pane.setBorder(new Border(new BorderStroke(borderPaint, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(borderWidth))));
getChildren().setAll(pane);
prepareData();
}
项目:radialchart
文件:RadialChart.java
private void initGraphics() {
if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 ||
Double.compare(getWidth(), 0.0) <= 0 || Double.compare(getHeight(), 0.0) <= 0) {
if (getPrefWidth() > 0 && getPrefHeight() > 0) {
setPrefSize(getPrefWidth(), getPrefHeight());
} else {
setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
}
}
canvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
ctx = canvas.getGraphicsContext2D();
pane = new Pane(canvas);
pane.setBackground(new Background(new BackgroundFill(backgroundPaint, CornerRadii.EMPTY, Insets.EMPTY)));
pane.setBorder(new Border(new BorderStroke(borderPaint, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(borderWidth))));
getChildren().setAll(pane);
}
项目:marathonv5
文件:ImagePanel.java
private void createLeftPane() {
canvas = new Canvas(image.getWidth(), image.getHeight());
canvas.addEventFilter(MouseEvent.ANY, new ImagePanelMouseListener());
graphics = canvas.getGraphicsContext2D();
anchorPane.setMaxWidth(image.getWidth());
anchorPane.setMaxHeight(image.getHeight());
anchorPane.getChildren().add(canvas);
initializeAnnotations();
drawGraphics();
}
项目:Hive_Game
文件:BoardDrawer.java
public BoardDrawer(Canvas c, TraducteurBoard t) {
this.can = c;
this.gc = can.getGraphicsContext2D();
hex = new Hexagon();
traducteur = t;
traducteur.setMoveOrigin(new CoordGene<Double>(can.getWidth() / 2, (can.getHeight() / 2) - Consts.SIDE_SIZE));
}
项目:Hive_Game
文件:RefreshJavaFX.java
public RefreshJavaFX(Core core, Canvas c, Highlighter h,TraducteurBoard t,GameScreenController g) {
this.core = core;
drawer = new BoardDrawer(c,t);
this.h =h;
this.g = g;
time = 0;
}