kopia lustrzana https://github.com/jameshball/osci-render
Create first version of project selection with previously opened projects saved
rodzic
b0fa2e67fd
commit
8a6ebcdde3
|
@ -0,0 +1,6 @@
|
|||
package sh.ball.gui;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ExceptionRunnable {
|
||||
void run() throws Exception;
|
||||
}
|
|
@ -17,6 +17,7 @@ import sh.ball.audio.engine.ConglomerateAudioEngine;
|
|||
import sh.ball.audio.midi.MidiCommunicator;
|
||||
import sh.ball.gui.components.CodeEditor;
|
||||
import sh.ball.gui.controller.MainController;
|
||||
import sh.ball.gui.controller.ProjectSelectController;
|
||||
import sh.ball.parser.lua.LuaParser;
|
||||
import sh.ball.parser.obj.ObjParser;
|
||||
import sh.ball.parser.svg.SvgParser;
|
||||
|
@ -24,6 +25,7 @@ import sh.ball.parser.txt.TextParser;
|
|||
import sh.ball.shapes.Vector2;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
@ -36,6 +38,7 @@ public class Gui extends Application {
|
|||
public static String LOG_DIR = "./logs/";
|
||||
public static final Logger logger = Logger.getLogger(Gui.class.getName());
|
||||
|
||||
public static ProjectSelectController projectSelectController;
|
||||
public static ShapeAudioPlayer audioPlayer;
|
||||
public static AudioDevice defaultDevice;
|
||||
public static CodeEditor editor;
|
||||
|
@ -74,8 +77,13 @@ public class Gui extends Application {
|
|||
new Thread(midiCommunicator).start();
|
||||
}
|
||||
|
||||
private Stage stage;
|
||||
private Scene scene;
|
||||
private Parent root;
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) throws Exception {
|
||||
this.stage = stage;
|
||||
System.setProperty("prism.lcdtext", "false");
|
||||
System.setProperty("org.luaj.luajc", "true");
|
||||
|
||||
|
@ -92,15 +100,32 @@ public class Gui extends Application {
|
|||
editor.prefHeightProperty().bind(editorStage.heightProperty());
|
||||
editor.prefWidthProperty().bind(editorStage.widthProperty());
|
||||
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/main.fxml"));
|
||||
Parent root = loader.load();
|
||||
MainController controller = loader.getController();
|
||||
FXMLLoader projectSelectLoader = new FXMLLoader(getClass().getResource("/fxml/projectSelect.fxml"));
|
||||
Parent projectSelectRoot = projectSelectLoader.load();
|
||||
projectSelectController = projectSelectLoader.getController();
|
||||
projectSelectController.setApplicationLauncher(this::launchMainApplication);
|
||||
|
||||
stage.getIcons().add(new Image(Objects.requireNonNull(getClass().getResourceAsStream("/icons/icon.png"))));
|
||||
stage.setTitle("osci-render");
|
||||
Scene scene = new Scene(root);
|
||||
scene = new Scene(projectSelectRoot);
|
||||
scene.getStylesheets().add(getClass().getResource("/css/main.css").toExternalForm());
|
||||
|
||||
stage.setScene(scene);
|
||||
stage.setResizable(false);
|
||||
|
||||
stage.setOnCloseRequest(t -> {
|
||||
Platform.exit();
|
||||
System.exit(0);
|
||||
});
|
||||
|
||||
stage.show();
|
||||
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/main.fxml"));
|
||||
root = loader.load();
|
||||
MainController controller = loader.getController();
|
||||
|
||||
controller.setAddRecentFile(projectSelectController::addRecentFile);
|
||||
|
||||
controller.setSoftwareOscilloscopeAction(() -> {
|
||||
getHostServices().showDocument("https://james.ball.sh/oscilloscope");
|
||||
});
|
||||
|
@ -136,13 +161,8 @@ public class Gui extends Application {
|
|||
}
|
||||
});
|
||||
|
||||
stage.setScene(scene);
|
||||
stage.setResizable(false);
|
||||
|
||||
controller.setStage(stage);
|
||||
|
||||
stage.show();
|
||||
|
||||
stage.setOnCloseRequest(t -> {
|
||||
controller.shutdown();
|
||||
Platform.exit();
|
||||
|
@ -150,6 +170,10 @@ public class Gui extends Application {
|
|||
});
|
||||
}
|
||||
|
||||
public void launchMainApplication() {
|
||||
scene.setRoot(root);
|
||||
}
|
||||
|
||||
public static void launchCodeEditor(String code, String fileName) {
|
||||
editor.setCode(code, fileName);
|
||||
editorStage.show();
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.nio.charset.StandardCharsets;
|
|||
import java.text.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.UnaryOperator;
|
||||
import java.util.logging.Level;
|
||||
|
||||
|
@ -70,6 +71,7 @@ public class MainController implements Initializable, FrequencyListener, MidiLis
|
|||
private static final double BLOCK_INCREMENT = 0.005;
|
||||
private static final double MAJOR_TICK_UNIT = 0.1;
|
||||
|
||||
private Consumer<String> addRecentFile;
|
||||
private String openProjectPath;
|
||||
private final FileChooser wavFileChooser = new FileChooser();
|
||||
|
||||
|
@ -1200,6 +1202,7 @@ public class MainController implements Initializable, FrequencyListener, MidiLis
|
|||
transformer.transform(domSource, streamResult);
|
||||
openProjectPath = projectFileName;
|
||||
updateTitle(null, projectFileName);
|
||||
addRecentFile.accept(openProjectPath);
|
||||
} catch (ParserConfigurationException | TransformerException e) {
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
|
@ -1413,6 +1416,10 @@ public class MainController implements Initializable, FrequencyListener, MidiLis
|
|||
});
|
||||
}
|
||||
|
||||
public void setAddRecentFile(Consumer<String> addRecentFile) {
|
||||
this.addRecentFile = addRecentFile;
|
||||
}
|
||||
|
||||
private record PrintableSlider(Slider slider) {
|
||||
@Override
|
||||
public String toString() {
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
package sh.ball.gui.controller;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.CheckBox;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.control.ProgressIndicator;
|
||||
import sh.ball.gui.ExceptionRunnable;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
public class ProjectSelectController implements Initializable {
|
||||
|
||||
private static final int MAX_ITEMS = 20;
|
||||
private static final String RECENT_FILE = "RECENT_FILE_";
|
||||
|
||||
private final Preferences userPreferences = Preferences.userNodeForPackage(getClass());
|
||||
private final ObservableList<String> recentFiles = FXCollections.observableArrayList();
|
||||
private ExceptionRunnable launchMainApplication;
|
||||
|
||||
@FXML
|
||||
private ListView<String> recentFilesListView;
|
||||
@FXML
|
||||
private Button newProjectButton;
|
||||
@FXML
|
||||
private CheckBox startMutedCheckBox;
|
||||
|
||||
@Override
|
||||
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||
for (int i = 0; i < MAX_ITEMS; i++) {
|
||||
String path = userPreferences.get(RECENT_FILE + i, null);
|
||||
if (path != null) {
|
||||
recentFiles.add(path);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
recentFilesListView.setItems(recentFiles);
|
||||
|
||||
newProjectButton.setOnAction(e -> {
|
||||
try {
|
||||
launchMainApplication.run();
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void addRecentFile(String path) {
|
||||
int index = recentFiles.indexOf(path);
|
||||
if (index == -1) {
|
||||
userPreferences.get(RECENT_FILE + recentFiles.size(), path);
|
||||
recentFiles.add(0, path);
|
||||
if (recentFiles.size() > MAX_ITEMS) {
|
||||
recentFiles.remove(recentFiles.size() - 1);
|
||||
}
|
||||
} else {
|
||||
recentFiles.remove(index);
|
||||
recentFiles.add(0, path);
|
||||
}
|
||||
resetRecentFiles();
|
||||
}
|
||||
|
||||
private void resetRecentFiles() {
|
||||
for (int i = 0; i < MAX_ITEMS; i++) {
|
||||
userPreferences.remove(RECENT_FILE + i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < recentFiles.size(); i++) {
|
||||
userPreferences.put(RECENT_FILE + i, recentFiles.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
public void setApplicationLauncher(ExceptionRunnable launchMainApplication) {
|
||||
this.launchMainApplication = launchMainApplication;
|
||||
}
|
||||
}
|
|
@ -72,7 +72,7 @@
|
|||
}
|
||||
|
||||
.titled-pane, .text {
|
||||
-fx-font-size: 13;
|
||||
-fx-font-size: 1em;
|
||||
-fx-font-smoothing-type: gray;
|
||||
-fx-text-fill: white;
|
||||
}
|
||||
|
@ -146,14 +146,45 @@
|
|||
}
|
||||
|
||||
#frequency .text {
|
||||
-fx-font-size: 20;
|
||||
-fx-font-size: 1.5em;
|
||||
}
|
||||
|
||||
#control-pane, .titled-pane, .pane, #frequencyPane {
|
||||
#control-pane, .titled-pane, .pane, .darkPane {
|
||||
-fx-background-color: darker_color;
|
||||
-fx-effect: dropshadow(three-pass-box, rgba(0,0,0,0.8), 10, 0, 0, 0);
|
||||
}
|
||||
|
||||
.list-cell {
|
||||
-fx-background-color: transparent;
|
||||
}
|
||||
.list-view {
|
||||
-fx-background-color: very_dark;
|
||||
-fx-border-width: 1px;
|
||||
-fx-border-color: white;
|
||||
}
|
||||
|
||||
.progress-indicator:indeterminate .segment {
|
||||
-fx-background-color: white;
|
||||
}
|
||||
|
||||
.progress-indicator:indeterminate {
|
||||
-fx-border-width: 0;
|
||||
-fx-background-color: transparent;
|
||||
}
|
||||
|
||||
.progress-indicator:indeterminate > .spinner {
|
||||
-fx-background-color: transparent;
|
||||
-fx-background-insets: 0;
|
||||
-fx-background-radius: 0;
|
||||
-fx-border-width: 0;
|
||||
}
|
||||
|
||||
.list-cell:filled:selected:focused, .list-cell:filled:hover {
|
||||
-fx-background-color: grey_color;
|
||||
-fx-text-fill: white;
|
||||
-fx-cursor: hand;
|
||||
}
|
||||
|
||||
.combo-box .list-cell
|
||||
{
|
||||
-fx-background: very_dark;
|
||||
|
@ -339,4 +370,8 @@
|
|||
.spinner .increment-arrow-button .increment-arrow,
|
||||
.spinner .decrement-arrow-button .decrement-arrow {
|
||||
-fx-background-color: white;
|
||||
}
|
||||
|
||||
.label.title .text {
|
||||
-fx-font-size: 1.5em;
|
||||
}
|
|
@ -212,7 +212,7 @@
|
|||
<TitledPane animated="false" collapsible="false" layoutX="7.0" layoutY="33.0" minHeight="371.0" minWidth="378.0" prefHeight="364.0" prefWidth="378.0" text="Main settings">
|
||||
<fx:include fx:id="general" source="general.fxml" />
|
||||
</TitledPane>
|
||||
<AnchorPane fx:id="frequencyPane" layoutX="392.0" layoutY="692.0" prefHeight="53.0" prefWidth="610.0">
|
||||
<AnchorPane fx:id="frequencyPane" layoutX="392.0" layoutY="692.0" prefHeight="53.0" prefWidth="610.0" styleClass="darkPane">
|
||||
<children>
|
||||
<fx:include fx:id="image" layoutX="34.0" source="image.fxml" />
|
||||
</children>
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.CheckBox?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.ListView?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
|
||||
<AnchorPane prefHeight="752.0" prefWidth="1008.0" stylesheets="@../css/main.css" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sh.ball.gui.controller.ProjectSelectController">
|
||||
<AnchorPane layoutX="11.0" layoutY="12.0" prefHeight="727.0" prefWidth="984.0" styleClass="darkPane">
|
||||
<children>
|
||||
<ImageView fitHeight="247.0" fitWidth="252.0" layoutX="372.0" layoutY="15.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../images/osci.png" />
|
||||
</image>
|
||||
</ImageView>
|
||||
<ListView fx:id="recentFilesListView" layoutX="238.0" layoutY="333.0" prefHeight="257.0" prefWidth="527.0" />
|
||||
<Button fx:id="newProjectButton" layoutX="432.0" layoutY="609.0" mnemonicParsing="false" prefHeight="40.0" prefWidth="131.0" text="Start new project" />
|
||||
<CheckBox fx:id="startMutedCheckBox" layoutX="450.0" layoutY="670.0" mnemonicParsing="false" text="Start muted" />
|
||||
<Label layoutX="398.0" layoutY="294.0" styleClass="title" text="Recently opened projects" />
|
||||
<Label layoutX="14.0" layoutY="700.0" text="v1.26.4" />
|
||||
</children></AnchorPane>
|
||||
</AnchorPane>
|
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 28 KiB |
Ładowanie…
Reference in New Issue