/* * Copyright 2015 Sudipto Chandra. * * 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.sandsoft.cymric.view; import org.sandsoft.cymric.Cymric; import org.sandsoft.cymric.view.components.StatusBar; import org.sandsoft.cymric.model.CymricCore; import org.sandsoft.cymric.model.SideButton; import org.sandsoft.cymric.util.Commons; import org.sandsoft.cymric.util.Logs; import javafx.animation.KeyFrame; import javafx.animation.KeyValue; import javafx.animation.Timeline; import javafx.fxml.FXML; import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; import javafx.scene.layout.Priority; import javafx.scene.layout.VBox; import javafx.util.Duration; /** * FXML Controller class * * @author Sudipto Chandra */ public class RootLayout extends javafx.scene.layout.BorderPane { public static RootLayout createNew(CymricCore core) { try { //get layout RootLayout root = (RootLayout) Commons.loadPaneFromFXML(RootLayout.class); root.setPrefWidth(Cymric.DEFAULT_WIDTH); root.setPrefHeight(Cymric.DEFAULT_HEIGHT); //post load work core.setRootLayout(root); root.setCymricCore(core); root.initalize(); return root; } catch (Exception ex) { Logs.showStackTrace(ex); } return null; } //cymric core private CymricCore mCore; //currently displayed layout private Pane mCurrentLayout; @FXML private HBox contentHolder; @FXML private StatusBar statusBar; //constructor public RootLayout() { } /** * Initializes controls after FXML is loaded. */ public void initalize() { //SidePane SidePane sidePane = SidePane.createNew(mCore); HBox.setHgrow(sidePane, Priority.NEVER); contentHolder.getChildren().add(sidePane); // StatusBar mCore.setStatusBar(statusBar); // EditorLayout EditorLayout.createNew(mCore); // NotesLayout NotesLayout.createNew(mCore); // ProjectLayout ProjectLayout.createNew(mCore); // SettingsLayout SettingsLayout.createNew(mCore); // SnippetLayout SnippetLayout.createNew(mCore); // SoftwareLayout SoftwareLayout.createNew(mCore); // ToolsLayout ToolsLayout.createNew(mCore); //select a side button mCore.getSidePane().setSelectedButton(SideButton.SNIPPET_BUTTON); } /** * Sets the Cymric core to this object. It should be called after all * initialization has been completed. * * @param core Reference to original Cymric core object. */ public void setCymricCore(CymricCore core) { mCore = core; } /** * Adds a new layout on display and removes the previous one. * * @param layout Layout to add. */ public void addLayout(Pane layout) { //remove previous layout if (mCurrentLayout != null) { contentHolder.getChildren().remove(mCurrentLayout); } //add new layout if (layout != null) { mCurrentLayout = layout; HBox.setHgrow(layout, Priority.ALWAYS); contentHolder.getChildren().add(layout); //play some animation Timeline timeline = new Timeline( new KeyFrame(Duration.ZERO, new KeyValue(layout.translateXProperty(), -48), new KeyValue(layout.scaleYProperty(), 0.7) ), new KeyFrame(Duration.millis(100), new KeyValue(layout.translateXProperty(), 0), new KeyValue(layout.scaleYProperty(), 1.0) ) ); timeline.play(); } mCurrentLayout = layout; } }