1
0
Fork 0
mirror of https://gitlab.com/kauron/jstudy synced 2024-12-22 16:33:33 +01:00

Main: adapted menu to macOS style.

This commit is contained in:
Carlos Galindo 2019-10-23 23:33:06 +02:00
parent 8a279ae1cb
commit ca23f61c72
2 changed files with 23 additions and 1 deletions

View file

@ -16,6 +16,8 @@ import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.scene.Parent; import javafx.scene.Parent;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem; import javafx.scene.control.MenuItem;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.image.Image; import javafx.scene.image.Image;
@ -54,6 +56,9 @@ public class Controller implements Initializable {
@FXML @FXML
private MenuItem menuCloseTab, menuSave, menuUndo, menuRedo; private MenuItem menuCloseTab, menuSave, menuUndo, menuRedo;
@FXML
private MenuBar menuBar;
private final BooleanProperty tabIsTable = new SimpleBooleanProperty(false); private final BooleanProperty tabIsTable = new SimpleBooleanProperty(false);
private final Map<Tab, Initializable> tabMap = new HashMap<>(); private final Map<Tab, Initializable> tabMap = new HashMap<>();
private String updateURL, updateFileName; private String updateURL, updateFileName;
@ -96,9 +101,26 @@ public class Controller implements Initializable {
} }
}) })
); );
// Do not show icons in the menu items of the main menu in macOS.
Platform.runLater(() -> {
if (System.getProperty("os.name").toLowerCase().startsWith("mac os x"))
for (Menu m : menuBar.getMenus())
removeIcon(m);
});
new Thread(this::checkUpdate).start(); new Thread(this::checkUpdate).start();
} }
private void removeIcon(Menu menu) {
menu.setGraphic(null);
for (MenuItem item : menu.getItems()) {
if (item instanceof Menu) {
removeIcon((Menu) item);
} else {
item.setGraphic(null);
}
}
}
private boolean isTableTab(Tab tab) { private boolean isTableTab(Tab tab) {
return tabMap.containsKey(tab) && tabMap.get(tab) instanceof TableController; return tabMap.containsKey(tab) && tabMap.get(tab) instanceof TableController;
} }

View file

@ -86,7 +86,7 @@
</TabPane> </TabPane>
</center> </center>
<top> <top>
<MenuBar> <MenuBar fx:id="menuBar" useSystemMenuBar="true">
<menus> <menus>
<Menu text="_File"> <Menu text="_File">
<items> <items>