org.jacpfx.rcp.components.menuBar.JACPMenuBar Maven / Gradle / Ivy
/************************************************************************
*
* Copyright (C) 2010 - 2014
*
* [JACPMenuBar.java]
* JACPFX Project (https://github.com/JacpFX/JacpFX/)
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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 CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*
*
************************************************************************/
package org.jacpfx.rcp.components.menuBar;
import javafx.application.Platform;
import javafx.collections.ObservableList;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.ToolBar;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.stage.Screen;
import javafx.stage.Stage;
import org.jacpfx.api.util.OS;
import org.jacpfx.rcp.util.CSSUtil;
import org.jacpfx.rcp.util.ShutdownThreadsHandler;
import org.jacpfx.rcp.util.TearDownHandler;
/**
* The Class JACPMenuBar.
*
* @author Patrick Symmangk
*/
public class JACPMenuBar extends HBox {
/**
* The left bar.
*/
private ToolBar leftBar;
/**
* The right bar.
*/
private ToolBar rightBar;
/**
* The main bar.
*/
private MenuBar mainBar;
/**
* The last x.
*/
private double lastW;
private double lastX;
/**
* The last y.
*/
private double lastH;
private double lastY;
private Stage stage;
private Button minimize;
private Button maximize;
private Button close;
private boolean maximized = false;
private boolean unregistered = false;
/**
* The mouse drag offset x.
*/
private double mouseDragOffsetX = 0;
/**
* The mouse drag offset y.
*/
private double mouseDragOffsetY = 0;
/**
* Instantiates a new jACP menu bar.
*/
public JACPMenuBar() {
this.initMenuBar();
}
/**
* Inits the menu bar.
*/
private void initMenuBar() {
this.leftBar = new ToolBar();
this.rightBar = new ToolBar();
this.mainBar = new MenuBar();
if (OS.MAC.equals(OS.getOS())) {
mainBar.setUseSystemMenuBar(true);
this.getChildren().addAll(mainBar);
} else {
this.leftBar.setMinWidth(0);
this.rightBar.setMinWidth(0);
this.mainBar.setPrefHeight(22);
this.setAlignment(Pos.CENTER_LEFT);
HBox.setHgrow(this.mainBar, Priority.ALWAYS);
HBox.setHgrow(this.leftBar, Priority.NEVER);
HBox.setHgrow(this.rightBar, Priority.NEVER);
this.getStyleClass().addAll(this.mainBar.getStyleClass());
this.clearBackground(this.leftBar, this.mainBar, this.rightBar);
this.bind(this.rightBar);
this.getChildren().addAll(this.leftBar, this.mainBar, this.rightBar);
}
}
public void setTitle(final String title) {
}
/**
* Clear background.
*
* @param node the node
*/
private void clearBackground(final Node... node) {
if (node != null) {
for (final Node n : node) {
n.setStyle("-fx-background-color: transparent;");
}
}
}
/**
* Bind.
*
* @param bar the bar
*/
private void bind(final ToolBar bar) {
bar.maxHeightProperty().bind(this.mainBar.heightProperty());
bar.prefHeightProperty().bind(this.mainBar.heightProperty());
}
/**
* Gets the menus.
*
* @return the menus
*/
public ObservableList