Permalink
Browse files

still trying, a lot of shit in this version

  • Loading branch information...
bdbipbip authored and kistora committed Dec 5, 2017
1 parent b1205bd commit f4fae68162a2b3095811a9c0b259ba0c726d5e7a
@@ -48,7 +48,10 @@ public void drawMap(StreetMap map, Scene scene) {
Double dimension = Double.min(ap.getHeight(), ap.getWidth());
canvas = new Canvas(dimension-30, dimension-30);
Pane overlay = new Pane();
Double canvasWidth = canvas.getWidth();
//ZoomablePane zCanvas = WidgetBuilder.createZoomablePane(canvas);
//ZoomablePane zOverlay = WidgetBuilder.createZoomablePane(overlay);
Double canvasWidth = canvas.getWidth();
GraphicsContext gc = canvas.getGraphicsContext2D();
Set<Long> keys = map.keySet();
Iterator iterator = keys.iterator();
@@ -69,7 +72,7 @@ public void drawMap(StreetMap map, Scene scene) {
gc.strokeLine(canvasWidth, canvasWidth, canvasWidth, 0);
gc.strokeLine(canvasWidth, canvasWidth, 0, canvasWidth);
Group mapGroup = new Group(canvas, overlay);
Group mapGroup = WidgetBuilder.createDrawGroup(canvas,overlay);
ap.getChildren().clear();
ap.getChildren().add(mapGroup);
@@ -3,11 +3,13 @@
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.effect.DropShadow;
import javafx.scene.layout.HBox;
import javafx.scene.input.ScrollEvent;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
@@ -251,4 +253,16 @@ public static void addDelivery(Intersection intersection, String duration, Strin
Controller.cmdAdd2(d);
}
public static void zoom(Group g, ScrollEvent e) {
double zoomIntensity = 0.01;
double scrollDelta = e.getDeltaY();
System.out.println("DELTA Y = "+ scrollDelta);
double newScaleX = g.getScaleX() + zoomIntensity*scrollDelta;
double newScaleY = g.getScaleY() + zoomIntensity*scrollDelta;
g.setScaleX(newScaleX);
g.setScaleY(newScaleY);
}
}
@@ -1,27 +1,40 @@
package lsbdp.agile.view;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import com.sun.deploy.jcp.controller.cacheviewer.DelAppInfo;
import javafx.event.EventHandler;
import javafx.geometry.Point2D;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.Tooltip;
import javafx.scene.input.MouseDragEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.ScrollEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import lsbdp.agile.controller.Controller;
import lsbdp.agile.model.Delivery;
import lsbdp.agile.model.Intersection;
public class WidgetBuilder {
private static double deltaX = 0;
private static double deltaY = 0;
public static Label createDeliveryLabel(Delivery delivery, int count) {
Label label = new Label("Livraison n°"+count + ", duration : " + delivery.getDuration()+"s");
Label label = new Label("Livraison n"+count + ", duration : " + delivery.getDuration()+"s");
label.setId("Delivery-"+String.valueOf(delivery.getLocation().getId()));
@@ -192,4 +205,76 @@ public void handle(MouseEvent event) {
return circle;
}
public static ZoomablePane createZoomablePane(Node node) {
ZoomablePane zp = new ZoomablePane(node);
zp.setOnScroll(new EventHandler<ScrollEvent>() {
@Override
public void handle(ScrollEvent event) {
double wheelDelta = event.getDeltaY();
zp.onScroll(wheelDelta, new Point2D(event.getX(), event.getY()));
}
});
zp.setOnMouseClicked(new EventHandler<MouseEvent>() {
double deltaX = 0;
double deltaY = 0;
@Override
public void handle(MouseEvent e) {
System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
Scene scene = WindowManager.getScene();
//Group g = (Group) scene.lookup("#mapGroup");
System.out.println(e.getX() + "" + e.getY());
zp.setTranslateX(e.getX());
zp.setTranslateY(e.getY());
}
});
return zp;
}
public static Group createDrawGroup(Canvas canvas, Pane overlay) {
Group g = new Group(canvas, overlay);
g.setOnScroll(new EventHandler<ScrollEvent>() {
@Override
public void handle(ScrollEvent e) {
EventHandlers.zoom(g,e);
}
});
g.setOnMousePressed(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent e) {
deltaX = e.getSceneX();
deltaY = e.getSceneY();
}
});
g.setOnMouseDragged(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent e) {
try {
TimeUnit.MICROSECONDS.sleep(10);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
deltaX = e.getX();
deltaY = e.getY();
System.out.println("DELTA X = " + deltaX);
System.out.println("DELTA Y = " + deltaY);
g.setTranslateX(deltaX);
g.setTranslateY(deltaY);
}
});
return g;
}
}
@@ -3,6 +3,8 @@
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.control.Button;
@@ -15,6 +17,7 @@
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.util.Pair;
@@ -49,6 +52,17 @@
public static void initializer (Scene scene) {
WindowManager.scene = scene;
HBox hb = new HBox();
hb.setAlignment(Pos.CENTER);
hb.setId("canvasHBox");
hb.setStyle("-fx-background-color: derive(#ececec,26.4%);");
StackPane sPane = (StackPane) scene.lookup("#mainStackPane");
sPane.getChildren().add(hb);
SplitPane sp = (SplitPane) scene.lookup("#mainSplitPane");
sp.getDividers().get(0).setPosition(0.85);
Controller controller = new Controller();
@@ -0,0 +1,81 @@
package lsbdp.agile.view;
import javafx.geometry.Bounds;
import javafx.geometry.Point2D;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.VBox;
public class ZoomablePane extends ScrollPane {
private double scaleValue = 0.7;
private double zoomIntensity = 0.01;
private Node target;
private Node zoomNode;
public ZoomablePane(Node target) {
super();
this.target = target;
this.zoomNode = new Group(target);
setContent(outerNode(zoomNode));
setPannable(true);
setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
//setFitToHeight(true); //center
// setFitToWidth(true); //center
updateScale();
}
private Node outerNode(Node node) {
Node outerNode = centeredNode(node);
/*outerNode.setOnScroll(e -> {
e.consume();
onScroll(e.getDeltaY(), new Point2D(e.getX(), e.getY()));
});*/
return outerNode;
}
private Node centeredNode(Node node) {
VBox vBox = new VBox(node);
vBox.setAlignment(Pos.CENTER);
return vBox;
}
private void updateScale() {
System.out.println("NEW SCALE :" + scaleValue);
target.setScaleX(scaleValue);
target.setScaleY(scaleValue);
System.out.println(target.scaleXProperty()+""+target.scaleYProperty());
}
public void onScroll(double wheelDelta, Point2D mousePoint) {
double zoomFactor = Math.exp(wheelDelta * zoomIntensity);
Bounds innerBounds = zoomNode.getLayoutBounds();
Bounds viewportBounds = getViewportBounds();
// calculate pixel offsets from [0, 1] range
double valX = this.getHvalue() * (innerBounds.getWidth() - viewportBounds.getWidth());
double valY = this.getVvalue() * (innerBounds.getHeight() - viewportBounds.getHeight());
System.out.println("OLD SCALE : "+ scaleValue);
scaleValue = scaleValue * zoomFactor;
updateScale();
this.layout(); // refresh ScrollPane scroll positions & target bounds
// convert target coordinates to zoomTarget coordinates
Point2D posInZoomTarget = target.parentToLocal(zoomNode.parentToLocal(mousePoint));
// calculate adjustment of scroll position (pixels)
Point2D adjustment = target.getLocalToParentTransform().deltaTransform(posInZoomTarget.multiply(zoomFactor - 1));
// convert back to [0, 1] range
// (too large/small values are automatically corrected by ScrollPane)
Bounds updatedInnerBounds = zoomNode.getBoundsInLocal();
this.setHvalue((valX + adjustment.getX()) / (updatedInnerBounds.getWidth() - viewportBounds.getWidth()));
this.setVvalue((valY + adjustment.getY()) / (updatedInnerBounds.getHeight() - viewportBounds.getHeight()));
}
}
@@ -58,7 +58,6 @@
<StackPane fx:id="mainStackPane" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<HBox fx:id="timeCheeseHBox" alignment="CENTER" prefHeight="100.0" prefWidth="200.0" style="-fx-background-color: derive(#ececec,26.4%);" />
<HBox fx:id="canvasHBox" alignment="CENTER" prefHeight="444.0" prefWidth="517.6" style="-fx-background-color: derive(#ececec,26.4%);" />
</children>
</StackPane>
</children></AnchorPane>

0 comments on commit f4fae68

Please sign in to comment.