Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenwrite.git

file editor tabs added

AuthorKarl Tauber <email>
Date2015-07-23 09:16:08 GMT+0200
Commitf6592d2a135409701650af17c4e7ce3499b9e587
Parenta200763
src/main/java/org/markdownwriterfx/FileEditor.java
+/*
+ * Copyright (c) 2015 Karl Tauber <karl at jformdesigner dot com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.markdownwriterfx;
+
+import java.nio.file.Path;
+import javafx.scene.control.SplitPane;
+import javafx.scene.control.Tab;
+import javafx.scene.control.Tooltip;
+import org.markdownwriterfx.editor.MarkdownEditorPane;
+import org.markdownwriterfx.preview.MarkdownPreviewPane;
+
+/**
+ * Editor for a single file.
+ *
+ * @author Karl Tauber
+ */
+class FileEditor
+{
+ private final Tab tab = new Tab();
+ private MarkdownEditorPane markdownEditorPane;
+ private MarkdownPreviewPane markdownPreviewPane;
+
+ FileEditor(Path path) {
+ // avoid that this is GCed
+ tab.setUserData(this);
+
+ tab.setText((path != null) ? path.getFileName().toString() : "New Document");
+ tab.setTooltip((path != null) ? new Tooltip(path.toString()) : null);
+
+ tab.setOnSelectionChanged(e -> {
+ if(tab.isSelected())
+ activated();
+ });
+ }
+
+ Tab getTab() {
+ return tab;
+ }
+
+ private void activated() {
+ if(tab.getContent() != null)
+ return;
+
+ // load file and create UI when the tab becomes visible the first time
+
+ markdownEditorPane = new MarkdownEditorPane();
+ markdownPreviewPane = new MarkdownPreviewPane();
+
+ //TODO
+ markdownEditorPane.setMarkdown("# h1\n\n## h2\n\nsome **bold** text\n\n* ul 1\n* ul 2\n* ul 3");
+
+ // bind preview to editor
+ markdownPreviewPane.markdownASTProperty().bind(markdownEditorPane.markdownASTProperty());
+
+ SplitPane splitPane = new SplitPane(markdownEditorPane.getNode(), markdownPreviewPane.getNode());
+ tab.setContent(splitPane);
+ }
+}
src/main/java/org/markdownwriterfx/MainWindow.java
+/*
+ * Copyright (c) 2015 Karl Tauber <karl at jformdesigner dot com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.markdownwriterfx;
+
+import javafx.scene.Scene;
+import javafx.scene.control.TabPane;
+
+/**
+ * Main window containing a tab pane in the center for file editors.
+ *
+ * @author Karl Tauber
+ */
+class MainWindow
+{
+ private Scene scene;
+ private final TabPane tabPane = new TabPane();
+
+ public MainWindow() {
+ tabPane.setPrefSize(800, 800);
+
+ FileEditor fileEditor = new FileEditor(null);
+ tabPane.getTabs().add(fileEditor.getTab());
+
+ FileEditor fileEditor2 = new FileEditor(null);
+ tabPane.getTabs().add(fileEditor2.getTab());
+ }
+
+ Scene getScene() {
+ if(scene == null)
+ scene = new Scene(tabPane);
+ return scene;
+ }
+}
src/main/java/org/markdownwriterfx/MarkdownWriterFXApp.java
import javafx.application.Application;
-import javafx.scene.Scene;
-import javafx.scene.control.SplitPane;
import javafx.stage.Stage;
-import org.markdownwriterfx.editor.MarkdownEditorPane;
-import org.markdownwriterfx.preview.MarkdownPreviewPane;
/**
* Markdown Writer FX application.
*
* @author Karl Tauber
*/
public class MarkdownWriterFXApp
extends Application
{
- private MarkdownEditorPane markdownEditorPane;
- private MarkdownPreviewPane markdownPreviewPane;
+ private MainWindow mainWindow;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
- markdownEditorPane = new MarkdownEditorPane();
- markdownEditorPane.setMarkdown("# h1\n\n## h2\n\nsome **bold** text\n\n* ul 1\n* ul 2\n* ul 3");
-
- markdownPreviewPane = new MarkdownPreviewPane();
- markdownPreviewPane.markdownASTProperty().bind(markdownEditorPane.markdownASTProperty());
-
- SplitPane content = new SplitPane(markdownEditorPane.getNode(), markdownPreviewPane.getNode());
- content.setPrefSize(800, 800);
+ mainWindow = new MainWindow();
primaryStage.setTitle("Markdown Writer FX");
- primaryStage.setScene(new Scene(content));
+ primaryStage.setScene(mainWindow.getScene());
primaryStage.show();
}
Delta144 lines added, 15 lines removed, 129-line increase