Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ledmington committed Sep 12, 2024
1 parent 502b083 commit c7b8b8c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
10 changes: 10 additions & 0 deletions emu-gui/src/main/java/com/ledmington/emu/AppConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,14 @@ public static void setDefaultMonospaceFont(final String monospaceFontFamily) {
}
MONOSPACE_FONT_FAMILY = monospaceFontFamily;
}

/** Shorthand default font size. */
public static int DEFAULT_FONT_SIZE = 12;

public static void setDefaultFontSize(final int newFontSize) {
if (newFontSize <= 1) {
throw new IllegalArgumentException(String.format("Invalid font size: %,d", newFontSize));
}
DEFAULT_FONT_SIZE = newFontSize;
}
}
8 changes: 6 additions & 2 deletions emu-gui/src/main/java/com/ledmington/emu/ELFViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ public ELFViewer(final double width, final double height) {
}
});

final Button settings = new Button();
settings.setText("Settings");
settings.setOnAction(e -> new SettingsWindow());

textArea.setEditable(false);
textArea.setFont(new Font(AppConstants.MONOSPACE_FONT_FAMILY, 12));
vbox.getChildren().addAll(load, textArea);
vbox.getChildren().addAll(load, settings, textArea);
final Scene scene = new Scene(vbox);

this.setScene(scene);
Expand Down Expand Up @@ -89,6 +92,7 @@ private void loadFile(final File elfFile) {
sb.append('\n');
}
}
textArea.setFont(new Font(AppConstants.MONOSPACE_FONT_FAMILY, AppConstants.DEFAULT_FONT_SIZE));
this.textArea.setText(sb.toString());
}
}
20 changes: 16 additions & 4 deletions emu-gui/src/main/java/com/ledmington/emu/SettingsWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.Spinner;
import javafx.scene.layout.Background;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.FlowPane;
Expand All @@ -34,6 +35,7 @@
public final class SettingsWindow extends Stage {

private final ComboBox<Label> fonts;
private final Spinner<Integer> fontSize;

public SettingsWindow() {
final BorderPane bPane = new BorderPane();
Expand All @@ -43,14 +45,23 @@ public SettingsWindow() {
{
mainPane.getChildren().add(new Label("Font"));
fonts = new ComboBox<>();
for (final String fontName : Font.getFontNames()) {
final Label lbl = new Label(fontName);
lbl.setFont(Font.font(fontName, FontWeight.NORMAL, FontPosture.REGULAR, 11));
for (final String fontFamily : Font.getFamilies()) {
final Label lbl = new Label(fontFamily);
lbl.setFont(
Font.font(fontFamily, FontWeight.NORMAL, FontPosture.REGULAR, AppConstants.DEFAULT_FONT_SIZE));
lbl.setTextFill(Color.BLACK);
fonts.getItems().add(lbl);
if (fonts.getValue() == null) {
fonts.setValue(lbl);
}
}
fonts.setOnMouseClicked(e -> System.out.printf("Clicked '%s'\n", e));
mainPane.getChildren().add(fonts);
}
{
mainPane.getChildren().add(new Label("Font Size"));
fontSize = new Spinner<>(1, 20, AppConstants.DEFAULT_FONT_SIZE);
mainPane.getChildren().add(fontSize);
}
bPane.setCenter(mainPane);

final FlowPane bottomPane = new FlowPane();
Expand All @@ -59,6 +70,7 @@ public SettingsWindow() {
ok.setBackground(Background.fill(Color.LIGHTBLUE));
ok.setOnMouseClicked(e -> {
AppConstants.setDefaultMonospaceFont(fonts.getValue().getText());
AppConstants.setDefaultFontSize(fontSize.getValue());
this.close();
});
bottomPane.getChildren().add(ok);
Expand Down

0 comments on commit c7b8b8c

Please sign in to comment.