Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 484685

Summary: InfiniteCanvas#fitToSize() should delay its computation when the zoom factor is invalid.
Product: [Tools] GEF Reporter: Matthias Wienand <matthias.wienand>
Component: GEF FXAssignee: gef-inbox <gef-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 0.2.0   
Target Milestone: 4.0.0 / 3.11.0 (Neon) M5   
Hardware: All   
OS: All   
Whiteboard:

Description Matthias Wienand CLA 2015-12-18 08:35:37 EST
In some situations, the InfiniteCanvas#fitToSize() method computes an invalid zoom factor. Scrolling and zooming should then be delayed to a later point at which the computation works.

The following snippet demonstrates the issue (the red rectangle stays at the top left, although it should fill the whole window):

package org.eclipse.gef4.fx.examples.snippets;

import org.eclipse.gef4.fx.nodes.InfiniteCanvas;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class InfiniteCanvasFitToSizeSnippet extends Application {
	public static void main(String[] args) {
		launch();
	}

	@Override
	public void start(Stage primaryStage) throws Exception {
		InfiniteCanvas canvas = new InfiniteCanvas();
		canvas.getContentGroup().getChildren()
				.add(new Rectangle(50, 50, Color.RED));
		canvas.fitToSize();
		Scene scene = new Scene(canvas, 400, 400);
		primaryStage.setScene(scene);
		primaryStage.sizeToScene();
		primaryStage.show();
	}
}
Comment 1 Matthias Wienand CLA 2016-01-25 04:44:18 EST
Delaying the operation seems unintuitive. Therefore, I enhanced the Javadoc, explaining in which situations the operation can be performed, and how this can be verified beforehand. Moreover, if the operation is called while the InfiniteCanvas is in an invalid state, an IllegalStateException is thrown. Additionally, I added two parameters that can be used to restrict the zoom level to a certain range. The code is published on the master branch, therefore, I resolve this ticket as fixed for 3.11.0M5.