[WIP] CFV Refactor
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / internal / provisional / tmf / ui / views / timegraph2 / swtjfx / examples / Example.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.Node;
9 import javafx.scene.Scene;
10 import javafx.scene.control.ScrollPane;
11 import javafx.scene.paint.Color;
12 import javafx.scene.shape.Rectangle;
13 import javafx.stage.Stage;
14
15 @NonNullByDefault({})
16 public class Example extends Application {
17 @Override
18 public void start(Stage stage) {
19 Node content = new Rectangle(1000, 700, Color.GREEN);
20 ScrollPane scrollPane = new ScrollPane(content);
21 scrollPane.setPrefSize(500, 300);
22
23 ChangeListener<Object> changeListener = new ChangeListener<Object>() {
24 @Override
25 public void changed(ObservableValue<? extends Object> observable, Object oldValue, Object newValue) {
26 double hmin = scrollPane.getHmin();
27 double hmax = scrollPane.getHmax();
28 double hvalue = scrollPane.getHvalue();
29 double contentWidth = content.getLayoutBounds().getWidth();
30 double viewportWidth = scrollPane.getViewportBounds().getWidth();
31
32 double hoffset =
33 Math.max(0, contentWidth - viewportWidth) * (hvalue - hmin) / (hmax - hmin);
34
35 double vmin = scrollPane.getVmin();
36 double vmax = scrollPane.getVmax();
37 double vvalue = scrollPane.getVvalue();
38 double contentHeight = content.getLayoutBounds().getHeight();
39 double viewportHeight = scrollPane.getViewportBounds().getHeight();
40
41 double voffset =
42 Math.max(0, contentHeight - viewportHeight) * (vvalue - vmin) / (vmax - vmin);
43
44 System.out.printf("Offset: [%.1f, %.1f] width: %.1f height: %.1f %n",
45 hoffset, voffset, viewportWidth, viewportHeight);
46 }
47 };
48 scrollPane.viewportBoundsProperty().addListener(changeListener);
49 scrollPane.hvalueProperty().addListener(changeListener);
50 scrollPane.vvalueProperty().addListener(changeListener);
51
52 Scene scene = new Scene(scrollPane, 640, 480);
53 stage.setScene(scene);
54
55 stage.show();
56 }
57
58 public static void main(String[] args) {
59 launch(args);
60 }
61 }
This page took 0.033423 seconds and 5 git commands to generate.