1 package org
.eclipse
.tracecompass
.internal
.provisional
.tmf
.ui
.views
.timegraph2
.swtjfx
.examples
;
3 import org
.eclipse
.jdt
.annotation
.NonNullByDefault
;
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
;
15 public class Example2
extends Application
{
17 private static final double TEN_BILLIONS
= 10000000000.0;
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);
27 ChangeListener
<Object
> changeListener
= new ChangeListener
<Object
>() {
29 public void changed(ObservableValue
<?
extends Object
> observable
, Object oldValue
, Object newValue
) {
30 System
.out
.println("source=" + observable
.toString());
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();
39 Math
.max(0, contentWidth
- viewportWidth
) * (hvalue
- hmin
) / (hmax
- hmin
);
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();
48 Math
.max(0, contentHeight
- viewportHeight
) * (vvalue
- vmin
) / (vmax
- vmin
);
50 System
.out
.printf("Offset: [%.1f, %.1f] width: %.1f height: %.1f %n",
51 hoffset
, voffset
, viewportWidth
, viewportHeight
);
54 scrollPane
.viewportBoundsProperty().addListener(changeListener
);
55 scrollPane
.hvalueProperty().addListener(changeListener
);
56 scrollPane
.vvalueProperty().addListener(changeListener
);
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);
63 Canvas canvas2
= new Canvas(100, 100);
64 canvas2
.relocate(TEN_BILLIONS
- 100, TEN_BILLIONS
- 100);
65 canvas2
.getGraphicsContext2D().fillOval(60, 60, 30, 30);
67 pane
.getChildren().addAll(canvas1
, canvas2
);
69 /* Showing the scene */
70 Scene scene
= new Scene(scrollPane
, 640, 480);
71 stage
.setScene(scene
);
76 public static void main(String
[] args
) {
This page took 0.035409 seconds and 5 git commands to generate.