Untitled
unknown
java
3 years ago
9.3 kB
3
Indexable
package com.hcm.smartsheet.gui; import com.jfoenix.controls.JFXButton; import com.jfoenix.controls.JFXDrawer; import com.jfoenix.controls.JFXHamburger; import com.jfoenix.controls.JFXTabPane; import com.jfoenix.transitions.hamburger.HamburgerNextArrowBasicTransition; import javafx.animation.TranslateTransition; import javafx.event.Event; import javafx.event.EventHandler; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.geometry.Insets; import javafx.scene.Node; import javafx.scene.Parent; import javafx.scene.control.Label; import javafx.scene.control.Tab; import javafx.scene.effect.DropShadow; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.MouseEvent; import javafx.scene.layout.*; import javafx.scene.paint.Color; import javafx.scene.text.TextAlignment; import javafx.stage.Stage; import javafx.util.Duration; import java.io.IOException; import java.net.URL; import java.util.HashMap; import java.util.Objects; import static javafx.scene.layout.BorderPane.setMargin; public class MainController { @FXML private AnchorPane applicationPane; @FXML private JFXHamburger rightHamburger; @FXML private JFXDrawer rightDrawer; @FXML private AnchorPane rightAnchor; @FXML private AnchorPane topPane; @FXML private JFXTabPane tabContainer; @FXML private Tab homeTab; @FXML private GridPane homeContainer; @FXML private Tab dashboardTab; @FXML private GridPane dashboardContainer; @FXML private Tab projectTab; @FXML private GridPane projectContainer; @FXML private Tab peopleTab; @FXML private GridPane peopleContainer; @FXML private Tab timesheetTab; @FXML private GridPane timesheetContainer; @FXML private Tab calendarTab; @FXML private GridPane calendarContainer; @FXML private ImageView maximizeIcon; @FXML private GridPane topGridPane; public void initialize() { configureView(); maximizeIcon.setImage(new Image("/graphics/icons8-maximize-button-96-white.png")); try { VBox box = FXMLLoader.load(Objects.requireNonNull(getClass().getClassLoader().getResource("fxml/Drawer.fxml"))); rightDrawer.setSidePane(box); } catch (IOException ex) { ex.printStackTrace(); } rightAnchor.setPrefWidth(250); rightAnchor.setTranslateX(-150); setMargin(rightAnchor, new Insets(0, rightAnchor.translateXProperty().doubleValue(), 0, 0)); final TranslateTransition translateRightAnchor = new TranslateTransition(Duration.millis(500), rightAnchor); HamburgerNextArrowBasicTransition burgerTask1 = new HamburgerNextArrowBasicTransition(rightHamburger); burgerTask1.setRate(-1); rightHamburger.addEventHandler(MouseEvent.MOUSE_CLICKED, (e) -> { burgerTask1.setRate(burgerTask1.getRate() * -1); burgerTask1.setOnFinished(ex -> enableHamburger()); burgerTask1.play(); rightHamburger.setDisable(true); rightHamburger.setStyle("-fx-opacity: 1"); if (rightDrawer.isOpened()) { rightDrawer.close(); rightDrawer.setMinWidth(0); translateRightAnchor.setFromX(0); translateRightAnchor.setToX(-200 + 75); translateRightAnchor.play(); } else { rightDrawer.open(); rightDrawer.setMinWidth(250); translateRightAnchor.setFromX(-200 + 75); translateRightAnchor.setToX(0); translateRightAnchor.play(); } }); rightAnchor.translateXProperty().addListener(e -> setMargin(rightAnchor, new Insets(0, rightAnchor.translateXProperty().doubleValue(), 0, 0))); } private void enableHamburger() { rightHamburger.setDisable(false); } private final double tabWidth = 85.0; public static int lastSelectedTabIndex = 0; private boolean isRestoreWindowIcon; private void configureView() { tabContainer.setTabMinWidth(tabWidth); tabContainer.setTabMaxWidth(tabWidth); tabContainer.setTabMinHeight(tabWidth); tabContainer.setTabMaxHeight(tabWidth); tabContainer.setRotateGraphic(true); EventHandler<Event> replaceBackgroundColorHandler = event -> { lastSelectedTabIndex = tabContainer.getSelectionModel().getSelectedIndex(); Tab currentTab = (Tab) event.getTarget(); if (currentTab.isSelected()) { currentTab.setStyle("-fx-background-color: -fx-focus-color;"); } else { currentTab.setStyle("-fx-background-color: -fx-accent;"); } }; configureTab(homeTab, " Home", "graphics/baseline_home_white_36dp.png", homeContainer, getClass().getResource("HomeContainer.fxml"), replaceBackgroundColorHandler); configureTab(dashboardTab, "Dashboard", "graphics/baseline_dashboard_white_36dp.png", dashboardContainer, getClass().getResource("DashboardContainer.fxml"), replaceBackgroundColorHandler); configureTab(projectTab, "Projects", "graphics/baseline_assignment_white_36dp.png", projectContainer, getClass().getResource("ProjectContainer.fxml"), replaceBackgroundColorHandler); configureTab(peopleTab, "People", "graphics/baseline_people_white_36dp.png", peopleContainer, getClass().getResource("PeopleContainer.fxml"), replaceBackgroundColorHandler); configureTab(timesheetTab, "Timesheets", "graphics/baseline_clock_white_36dp.png", timesheetContainer, getClass().getResource("TimesheetContainer.fxml"), replaceBackgroundColorHandler); configureTab(calendarTab, "Calendar", "graphics/baseline_calendar_white_36dp.png", calendarContainer, getClass().getResource("CalendarContainer.fxml"), replaceBackgroundColorHandler); } private void configureTab(Tab tab, String title, String iconPath, GridPane containerPane, URL resourceURL, EventHandler<Event> onSelectionChangedEvent) { double imageWidth = 40.0; ImageView imageView = new ImageView(new Image(iconPath)); imageView.setFitHeight(imageWidth); imageView.setFitWidth(imageWidth); Label label = new Label(title); label.setMaxWidth(tabWidth - 20); label.setPadding(new Insets(6, 0, 0, 0)); label.setStyle("-fx-text-fill: white; -fx-font-size: 9pt; -fx-font-weight: normal;"); label.setTextAlignment(TextAlignment.CENTER); BorderPane tabPane = new BorderPane(); tabPane.setRotate(90.0); tabPane.setMaxWidth(tabWidth); tabPane.setCenter(imageView); tabPane.setBottom(label); tab.setText(""); tab.setGraphic(tabPane); tab.setOnSelectionChanged(onSelectionChangedEvent); if (containerPane != null && resourceURL != null) { try { Parent contentView = FXMLLoader.load(resourceURL); containerPane.getChildren().add(contentView); AnchorPane.setTopAnchor(contentView, 0.0); AnchorPane.setBottomAnchor(contentView, 0.0); AnchorPane.setRightAnchor(contentView, 0.0); AnchorPane.setLeftAnchor(contentView, 0.0); } catch (IOException e) { e.printStackTrace(); } } } @FXML private void minimizeProgram(MouseEvent event) { Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); stage.setIconified(true); } @FXML public void fullscreenProgram(MouseEvent event) { Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); if (stage.isFullScreen()) { stage.setFullScreen(false); maximizeIcon.setImage(new Image("/graphics/icons8-maximize-button-96-white.png")); } else { stage.setFullScreenExitHint(""); stage.setFullScreen(true); maximizeIcon.setImage(new Image("/graphics/icons8-restore-down-96-white.png")); } } @FXML public void doubleClickFullscreen() { //System.out.println(getRestoreIcon()); if (!getRestoreIcon()) { System.out.println("Maximize Icon"); //maximizeIcon.setImage(maxImage); } else { System.out.println("Restore Icon"); //maximizeIcon.setImage(restoreImage); } } @FXML private void closeProgram(MouseEvent event) { Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); stage.close(); } @FXML public void isRestoreIcon(boolean isIcon) { //System.out.println(isIcon); this.isRestoreWindowIcon = isIcon; doubleClickFullscreen(); } @FXML public boolean getRestoreIcon() { return isRestoreWindowIcon; } }
Editor is loading...