[WIP] CFV Refactor
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / internal / provisional / tmf / ui / views / timegraph2 / swtjfx / examples / Example2.java
1 package org.eclipse.tracecompass.internal.provisional.tmf.ui.views.timegraph2.swtjfx.examples;
2
3 import org.eclipse.jdt.annotation.NonNullByDefault;
4
5 import javafx.application.Application;
6 import javafx.beans.value.ChangeListener;
7 import javafx.beans.value.ObservableValue;
8 import javafx.scene.Scene;
9 import javafx.scene.canvas.Canvas;
10 import javafx.scene.control.ScrollPane;
11 import javafx.scene.layout.Pane;
12 import javafx.stage.Stage;
13
14 @NonNullByDefault({})
15 public class Example2 extends Application {
16
17 private static final double TEN_BILLIONS = 10000000000.0;
18
19 @Override
20 public void start(Stage stage) {
21 // Node content = new Rectangle(1000, 700, Color.GREEN);
22 Pane pane = new Pane();
23 pane.setPrefSize(TEN_BILLIONS, TEN_BILLIONS);
24 ScrollPane scrollPane = new ScrollPane(pane);
25 scrollPane.setPrefSize(500, 300);
26
27 ChangeListener<Object> changeListener = new ChangeListener<Object>() {
28 @Override
29 public void changed(ObservableValue<? extends Object> observable, Object oldValue, Object newValue) {
30 System.out.println("source=" + observable.toString());
31
32 double hmin = scrollPane.getHmin();
33 double hmax = scrollPane.getHmax();
34 double hvalue = scrollPane.getHvalue();
35 double contentWidth = pane.getLayoutBounds().getWidth();
36 double viewportWidth = scrollPane.getViewportBounds().getWidth();
37
38 double hoffset =
39 Math.max(0, contentWidth - viewportWidth) * (hvalue - hmin) / (hmax - hmin);
40
41 double vmin = scrollPane.getVmin();
42 double vmax = scrollPane.getVmax();
43 double vvalue = scrollPane.getVvalue();
44 double contentHeight = pane.getLayoutBounds().getHeight();
45 double viewportHeight = scrollPane.getViewportBounds().getHeight();
46
47 double voffset =
48 Math.max(0, contentHeight - viewportHeight) * (vvalue - vmin) / (vmax - vmin);
49
50 System.out.printf("Offset: [%.1f, %.1f] width: %.1f height: %.1f %n",
51 hoffset, voffset, viewportWidth, viewportHeight);
52 }
53 };
54 scrollPane.viewportBoundsProperty().addListener(changeListener);
55 scrollPane.hvalueProperty().addListener(changeListener);
56 scrollPane.vvalueProperty().addListener(changeListener);
57
58 /* Drawing on the region */
59 Canvas canvas1 = new Canvas(100, 100);
60 canvas1.relocate(TEN_BILLIONS - 100, 0);
61 canvas1.getGraphicsContext2D().strokeOval(60, 60, 30, 30);
62
63 Canvas canvas2 = new Canvas(100, 100);
64 canvas2.relocate(TEN_BILLIONS - 100, TEN_BILLIONS - 100);
65 canvas2.getGraphicsContext2D().fillOval(60, 60, 30, 30);
66
67 pane.getChildren().addAll(canvas1, canvas2);
68
69 /* Showing the scene */
70 Scene scene = new Scene(scrollPane, 640, 480);
71 stage.setScene(scene);
72
73 stage.show();
74 }
75
76 public static void main(String[] args) {
77 launch(args);
78 }
79 }
This page took 0.035409 seconds and 5 git commands to generate.