Example usage for javafx.collections ObservableMap put

List of usage examples for javafx.collections ObservableMap put

Introduction

In this page you can find the example usage for javafx.collections ObservableMap put.

Prototype

V put(K key, V value);

Source Link

Document

Associates the specified value with the specified key in this map (optional operation).

Usage

From source file:Main.java

public static void main(String[] args) {
    Map<String, String> map = new HashMap<String, String>();
    ObservableMap<String, String> observableMap = FXCollections.observableMap(map);
    observableMap.addListener(new MapChangeListener() {
        @Override//  ww w .j  a v  a2s .com
        public void onChanged(MapChangeListener.Change change) {
            System.out.println("change! ");
        }
    });
    observableMap.put("key 1", "value 1");
    map.put("key 2", "value 2");

}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    final Label markerText = new Label();
    StackPane.setAlignment(markerText, Pos.TOP_CENTER);

    String workingDir = System.getProperty("user.dir");
    final File f = new File(workingDir, "../media/omgrobots.flv");

    final Media m = new Media(f.toURI().toString());

    final ObservableMap<String, Duration> markers = m.getMarkers();
    markers.put("Robot Finds Wall", Duration.millis(3100));
    markers.put("Then Finds the Green Line", Duration.millis(5600));
    markers.put("Robot Grabs Sled", Duration.millis(8000));
    markers.put("And Heads for Home", Duration.millis(11500));

    final MediaPlayer mp = new MediaPlayer(m);
    mp.setOnMarker(new EventHandler<MediaMarkerEvent>() {
        @Override/* w w  w .  ja  v a2  s. co m*/
        public void handle(final MediaMarkerEvent event) {
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    markerText.setText(event.getMarker().getKey());
                }
            });
        }
    });

    final MediaView mv = new MediaView(mp);

    final StackPane root = new StackPane();
    root.getChildren().addAll(mv, markerText);
    root.setOnMouseClicked(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent event) {
            mp.seek(Duration.ZERO);
            markerText.setText("");
        }
    });

    final Scene scene = new Scene(root, 960, 540);
    final URL stylesheet = getClass().getResource("media.css");
    scene.getStylesheets().add(stylesheet.toString());

    primaryStage.setScene(scene);
    primaryStage.setTitle("Video Player 2");
    primaryStage.show();

    mp.play();
}

From source file:se.trixon.filebydate.ui.MainApp.java

private void initAccelerators() {
    final ObservableMap<KeyCombination, Runnable> accelerators = mStage.getScene().getAccelerators();

    accelerators.put(new KeyCodeCombination(KeyCode.Q, KeyCombination.SHORTCUT_DOWN), (Runnable) () -> {
        mStage.fireEvent(new WindowEvent(mStage, WindowEvent.WINDOW_CLOSE_REQUEST));
    });//w w  w . j a va2s. co m

    accelerators.put(new KeyCodeCombination(KeyCode.N, KeyCombination.SHORTCUT_DOWN), (Runnable) () -> {
        profileEdit(null);
    });

    if (!IS_MAC) {
        accelerators.put(new KeyCodeCombination(KeyCode.COMMA, KeyCombination.SHORTCUT_DOWN), (Runnable) () -> {
            displayOptions();
        });
    }
}