1 /*
2 * *************************************************************************************************************************************************************
3 *
4 * SteelBlue: DCI User Interfaces
5 * http://tidalwave.it/projects/steelblue
6 *
7 * Copyright (C) 2015 - 2024 by Tidalwave s.a.s. (http://tidalwave.it)
8 *
9 * *************************************************************************************************************************************************************
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
17 * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
18 *
19 * *************************************************************************************************************************************************************
20 *
21 * git clone https://bitbucket.org/tidalwave/steelblue-src
22 * git clone https://github.com/tidalwave-it/steelblue-src
23 *
24 * *************************************************************************************************************************************************************
25 */
26 package it.tidalwave.role.ui.javafx.impl;
27
28 import javax.annotation.Nonnull;
29 import java.util.Collection;
30 import java.util.function.Supplier;
31 import javafx.scene.control.Menu;
32 import javafx.scene.control.MenuBar;
33 import javafx.scene.control.MenuItem;
34 import it.tidalwave.util.annotation.VisibleForTesting;
35 import it.tidalwave.role.ui.UserAction;
36 import it.tidalwave.role.ui.javafx.JavaFXBinder;
37 import it.tidalwave.role.ui.spi.MenuBarModelSupport;
38 import lombok.NoArgsConstructor;
39 import lombok.extern.slf4j.Slf4j;
40
41 /***************************************************************************************************************************************************************
42 *
43 * The JavaFX implementation for {@link it.tidalwave.role.ui.ToolBarModel}.
44 *
45 * @since 1.1-ALPHA-6
46 * @author Fabrizio Giudici
47 *
48 **************************************************************************************************************************************************************/
49 @NoArgsConstructor @Slf4j
50 public class JavaFXMenuBarModel extends MenuBarModelSupport<JavaFXBinder, MenuBar, Menu, MenuItem>
51 {
52 /***********************************************************************************************************************************************************
53 * @param userActionsSupplier the supplier of actions
54 **********************************************************************************************************************************************************/
55 @VisibleForTesting JavaFXMenuBarModel (@Nonnull final Supplier<Collection<? extends UserAction>> userActionsSupplier)
56 {
57 super(userActionsSupplier);
58 }
59
60 /***********************************************************************************************************************************************************
61 * {@inheritDoc}
62 **********************************************************************************************************************************************************/
63 protected void populateImpl (@Nonnull final JavaFXBinder binder, @Nonnull final MenuBar menuBar)
64 {
65 menuBar.useSystemMenuBarProperty().set(true); // FIXME: only if macOS?
66 super.populateImpl(binder, menuBar);
67 }
68
69 /***********************************************************************************************************************************************************
70 * {@inheritDoc}
71 **********************************************************************************************************************************************************/
72 @Nonnull
73 protected Menu createMenu (@Nonnull final String label)
74 {
75 return new Menu(label);
76 }
77
78 /***********************************************************************************************************************************************************
79 * {@inheritDoc}
80 **********************************************************************************************************************************************************/
81 protected void addMenuToMenuBar (@Nonnull final MenuBar menuBar, @Nonnull final Menu menu)
82 {
83 menuBar.getMenus().add(menu);
84 }
85
86 /***********************************************************************************************************************************************************
87 * {@inheritDoc}
88 **********************************************************************************************************************************************************/
89 @Override
90 protected void addMenuItemToMenu (@Nonnull final Menu menu, @Nonnull final JavaFXBinder binder, @Nonnull final UserAction action)
91 {
92 final var menuItem = new MenuItem();
93 binder.bind(menuItem, action);
94 menu.getItems().add(menuItem);
95 }
96 }