From 94de0300f9f7b3bca7b835dd996a49aaef964795 Mon Sep 17 00:00:00 2001 From: Rafael Ibasco Date: Tue, 8 Jan 2019 15:57:22 +0800 Subject: [PATCH] (Issue #5) Font Browser Enhancement --- .../controllers/GlcdEmulatorController.java | 32 +-- .../GlcdFontBrowserController.java | 211 +++++++++++++---- .../controllers/GlcdFontDrawerController.java | 21 +- .../glcdemulator/emulator/BufferLayout.java | 5 + .../emulator/BufferLayoutFactory.java | 4 + .../emulator/VerticalBufferLayout.java | 3 +- .../glcdemulator/model/FontCacheEntry.java | 24 +- .../services/FontCacheService.java | 9 +- .../json/adapters/FontCacheEntryAdapter.java | 6 +- src/main/resources/css/app-dark.css | 4 + .../resources/views/font-browser-dialog.fxml | 224 ++++++++++-------- 11 files changed, 367 insertions(+), 176 deletions(-) diff --git a/src/main/java/com/ibasco/glcdemulator/controllers/GlcdEmulatorController.java b/src/main/java/com/ibasco/glcdemulator/controllers/GlcdEmulatorController.java index c1f26b6..ba43248 100644 --- a/src/main/java/com/ibasco/glcdemulator/controllers/GlcdEmulatorController.java +++ b/src/main/java/com/ibasco/glcdemulator/controllers/GlcdEmulatorController.java @@ -679,14 +679,6 @@ private void setupStatusBar() { leftItems.add(connectionDetails); } - private void disableConnectionTypeOptions(boolean disable) { - pConnType.setDisable(disable); - for (Toggle toggle : connType.getToggles()) { - ToggleButton button = (ToggleButton) toggle; - button.setDisable(disable); - } - } - private void activateProfile(GlcdEmulatorProfile profile) { glcdScreen.stop(); try { @@ -851,6 +843,7 @@ protected void updateItem(Double size, boolean empty) { /** * Check if we have a default profile stored in the File System. */ + private void setupDefaultProfile() { //Load default profile int defaultProfileId = appConfig.getDefaultProfileId(); @@ -1056,7 +1049,7 @@ private void saveAppSettings() { private JFXDialog getDisplayBrowseDialog() { try { GlcdEmulatorProfile profile = getContext().getProfileManager().getActiveProfile(); - Parent node = ResourceUtil.loadFxmlResource(Views.DISPLAY_BROWSE, GlcdEmulatorController.this); + Parent node = ResourceUtil.loadFxmlResource(Views.DISPLAY_BROWSE); MenuItem miCopyConstructor = new MenuItem("Copy constructor"); miCopyConstructor.setOnAction(event -> { @@ -1303,11 +1296,11 @@ private void setupConnectionTypeBindings() { ConnectionType type = (ConnectionType) newValue.getUserData(); switch (type) { case TCP: - view = ResourceUtil.loadFxmlResource("emulator-settings-tcp", GlcdEmulatorController.this); + view = ResourceUtil.loadFxmlResource("emulator-settings-tcp"); setupConnTypeTcpBindings(); break; case SERIAL: - view = ResourceUtil.loadFxmlResource("emulator-settings-serial", GlcdEmulatorController.this); + view = ResourceUtil.loadFxmlResource("emulator-settings-serial"); setupConnTypeSerialBindings(); break; } @@ -1343,7 +1336,7 @@ private void setupConnTypeTcpBindings() { private Parent createFlowControlView() { try { - return ResourceUtil.loadFxmlResource("emulator-settings-serial-fc", this); + return ResourceUtil.loadFxmlResource(Views.SERIAL_SETTINGS_FC); } catch (IOException e) { throw new EmulatorControllerException("Problem loading Flow Control view", e); } @@ -1620,7 +1613,7 @@ public GlcdBusInterface fromString(String string) { if (busInterface == null) { busInterface = GlcdUtil.findPreferredBusInterface(profile.getDisplay()); if (busInterface != null) - log.info("Bus interface is null, returning default: {}", busInterface.name()); + log.info("Bus interface is null, using preferred: {}", busInterface.name()); else log.warn("Bus interface not found for display: {}", profile.getDisplay().getName()); } @@ -1639,15 +1632,14 @@ public GlcdBusInterface fromString(String string) { profileBindGroup.registerUnidirectional(drawTestService.displayProperty(), profile.displayProperty()); profileBindGroup.registerUnidirectional(btnDrawAnimTest.textProperty(), textBinding); - //drawTestService.bufferProperty().bind(displayBuffer); - //drawTestService.busInterfaceProperty().bind(busInterfaceBinding); - //drawTestService.displayProperty().bind(profile.displayProperty()); - //btnDrawAnimTest.textProperty().bind(textBinding); - - //Bidirectional Bindings profileBindGroup.registerBidirectional(glcdScreen.activePixelColorProperty(), profile.lcdActivePixelColorProperty()); profileBindGroup.registerBidirectional(glcdScreen.inactivePixelColorProperty(), profile.lcdInactivePixelColorProperty()); + profile.lcdActivePixelColorProperty().addListener((observable, oldValue, newValue) -> { + if (newValue != null) { + profile.setLcdInactivePixelColor(newValue); + } + }); profileBindGroup.registerBidirectional(glcdScreen.backlightColorProperty(), profile.lcdBacklightColorProperty()); profileBindGroup.registerBidirectional(glcdScreen.contrastProperty(), profile.lcdContrastProperty()); profileBindGroup.registerBidirectional(glcdScreen.pixelSizeProperty(), profile.lcdPixelSizeProperty()); @@ -1825,7 +1817,7 @@ private void openFontBrowserAction(ActionEvent event) { //TODO: Fix edit bug private void profileEditAction(ActionEvent event) { GlcdEmulatorProfile selectedProfile = tvProfiles.getSelectionModel().getSelectedItem(); - GlcdEditProfileController controller = Controllers.getEditProfileController(); + GlcdEditProfileController controller = Controllers.getController(GlcdEditProfileController.class); Stage stage = Stages.getEditProfileStage(); controller.setProfile(selectedProfile); controller.setOwner(stage); diff --git a/src/main/java/com/ibasco/glcdemulator/controllers/GlcdFontBrowserController.java b/src/main/java/com/ibasco/glcdemulator/controllers/GlcdFontBrowserController.java index df5b89b..b16073e 100644 --- a/src/main/java/com/ibasco/glcdemulator/controllers/GlcdFontBrowserController.java +++ b/src/main/java/com/ibasco/glcdemulator/controllers/GlcdFontBrowserController.java @@ -3,7 +3,7 @@ * Organization: Rafael Luis Ibasco * Project: GLCD Simulator * Filename: GlcdFontBrowserController.java - * + * * --------------------------------------------------------- * %% * Copyright (C) 2018 Rafael Luis Ibasco @@ -12,12 +12,12 @@ * it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public * License along with this program. If not, see * . @@ -26,6 +26,7 @@ package com.ibasco.glcdemulator.controllers; import com.ibasco.glcdemulator.Controller; +import com.ibasco.glcdemulator.Controllers; import com.ibasco.glcdemulator.constants.Views; import com.ibasco.glcdemulator.controls.GlcdScreen; import com.ibasco.glcdemulator.enums.PixelShape; @@ -41,7 +42,10 @@ import javafx.application.Platform; import javafx.beans.binding.Bindings; import javafx.beans.binding.BooleanBinding; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.concurrent.Worker; +import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.geometry.VPos; @@ -49,7 +53,7 @@ import javafx.scene.control.Label; import javafx.scene.effect.Effect; import javafx.scene.effect.GaussianBlur; -import javafx.scene.input.MouseEvent; +import javafx.scene.input.*; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; @@ -64,13 +68,22 @@ import java.io.IOException; import java.net.URL; +import java.util.Comparator; +import java.util.List; import java.util.ResourceBundle; +import java.util.Set; import java.util.concurrent.Callable; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Collectors; public class GlcdFontBrowserController extends Controller implements Initializable { private static final Logger log = LoggerFactory.getLogger(GlcdFontBrowserController.class); + // @FXML private GlcdScreen fontDisplay; @@ -98,32 +111,70 @@ public class GlcdFontBrowserController extends Controller implements Initializab @FXML private JFXButton btnReloadCache; + @FXML + private JFXTextField tfFontNameCpp; + + @FXML + private JFXTextField tfFontNameJava; + + @FXML + private JFXTextField tfFontMaxWidth; + + @FXML + private JFXTextField tfFontMaxHeight; + + @FXML + private JFXTextField tfFontAscent; + + @FXML + private JFXTextField tfFontDescent; + + @FXML + private JFXComboBox cbFontSize; + + @FXML + private JFXTextField tfFontName; + + @FXML + private JFXRadioButton rbFilterSize; + + @FXML + private JFXRadioButton rbFilterName; + + @FXML + private JFXButton btnCopyU8g2; + + @FXML + private JFXButton btnCopyJava; + + @FXML + private JFXCheckBox cbFilterSize; + + @FXML + private JFXCheckBox cbFilterName; + + @FXML + private JFXComboBox cbDisplaySize; + + @FXML + private Label lblTotalFonts; + // + private static final String DEFAULT_TEXT = "ABC def 123"; private FontRenderer fontRenderer = FontRenderer.getInstance(); - private FontCacheService fontCacheService; + private FontCacheService fontCacheService = new FontCacheService(); - private FontCacheDetails details; + private FontCacheDetails details = new FontCacheDetails(); private JFXDrawersStack drawersStack; - private JFXDrawer leftDrawer; + private JFXDrawer drawer; private HamburgerSlideCloseTransition transition; - public GlcdFontBrowserController(FontCacheService service, FontCacheDetails details) { - this.fontCacheService = service; - this.details = details; - } - - public FontCacheService getFontCacheService() { - return fontCacheService; - } - - public void setFontCacheService(FontCacheService fontCacheService) { - this.fontCacheService = fontCacheService; - } + private final AtomicBoolean modifierCtrlPressed = new AtomicBoolean(false); public FontCacheDetails getDetails() { return details; @@ -133,17 +184,87 @@ public void setDetails(FontCacheDetails details) { this.details = details; } + private class FontSizeInfo { + private FontCacheEntry entry; + + private FontSizeInfo(FontCacheEntry entry) { + this.entry = entry; + } + + private int getArea() { + return entry.getMaxCharWidth() * entry.getMaxCharHeight(); + } + + private int getWidth() { + return entry.getMaxCharWidth(); + } + + private int getHeight() { + return entry.getMaxCharHeight(); + } + + private String getName() { + return entry.getMaxCharWidth() + " x " + entry.getMaxCharHeight(); + } + + @Override + public String toString() { + return getName(); + } + } + @Override public void initialize(URL location, ResourceBundle resources) { + log.debug("INITIALIZE: {}", fontDisplay); initFontDisplay(); initDrawer(); initPreloaderBindings(); initPreviewTextBindings(); + btnReloadCache.setOnAction(this::rebuildCache); + btnCopyU8g2.setOnAction(this::copyU8g2Name); + btnCopyJava.setOnAction(this::copyJavaName); + cbFontSize.disableProperty().bind(cbFilterSize.selectedProperty().not()); + tfFontName.disableProperty().bind(cbFilterName.selectedProperty().not()); + cbDisplaySize.setConverter(new StringConverter() { + @Override + public String toString(GlcdSize object) { + return object.getDisplayWidth() + " x " + object.getDisplayHeight(); + } - btnReloadCache.setOnAction(event -> { - if (DialogUtil.promptConfirmation("Are you sure you want to rebuild the font cache?", "Rebuilding the whole cache may take a while")) { - showTopDrawer(false); - Platform.runLater(() -> fontCacheService.rebuild()); + @Override + public GlcdSize fromString(String string) { + return null; + } + }); + ObservableList sizeList = FXCollections.observableArrayList(GlcdSize.values()); + sizeList.sort(Comparator.comparing(GlcdSize::getDisplayWidth, Integer::compareTo)); + cbDisplaySize.setItems(sizeList); + cbDisplaySize.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { + if (newValue != null) { + List res = GlcdUtil.findDisplay(GlcdUtil.bySize(newValue)); + if (!res.isEmpty()) { + GlcdDisplay display = res.get(0); + log.debug("Choosing display size: {}, Selected display = {}", newValue, display); + fontRenderer.setDisplay(display); + //re-initialize the font display screen + initFontDisplay(); + } + } + }); + + //Lazy-initialization + root.sceneProperty().addListener((observable, oldValue, newValue) -> { + if (newValue != null) //noinspection Duplicates + { + drawersStack = (JFXDrawersStack) newValue.getRoot(); + drawersStack.addEventHandler(KeyEvent.KEY_PRESSED, event -> { + if (event.getCode() == KeyCode.CONTROL) + modifierCtrlPressed.set(true); + }); + drawersStack.addEventHandler(KeyEvent.KEY_RELEASED, event -> { + if (event.getCode() == KeyCode.CONTROL) + modifierCtrlPressed.set(false); + }); } }); @@ -241,8 +362,16 @@ private void initPreviewTextBindings() { details.previewTextProperty().bindBidirectional(tfPreviewText.textProperty()); //Render text on new font selection details.activeEntryProperty().addListener((observable, oldValue, newValue) -> { - if (newValue != null) + if (newValue != null) { + //log.debug("ACTIVE ENTRY CHANGED: {}", fontDisplay.getBuffer()); renderText(newValue.getFont(), tfPreviewText.getText()); + tfFontNameCpp.setText(newValue.getFont().getKey()); + tfFontNameJava.setText(newValue.getFont().name()); + tfFontAscent.setText(String.valueOf(newValue.getAscent())); + tfFontDescent.setText(String.valueOf(newValue.getDescent())); + tfFontMaxWidth.setText(String.valueOf(newValue.getMaxCharWidth())); + tfFontMaxHeight.setText(String.valueOf(newValue.getMaxCharHeight())); + } }); //Render text if preview text changes tfPreviewText.textProperty().addListener((observable, oldValue, newValue) -> { @@ -257,26 +386,27 @@ private void initPreviewTextBindings() { private void initDrawer() { try { - GlcdFontTopDrawerController leftDrawerController = new GlcdFontTopDrawerController(fontCacheService, details); - VBox leftDrawerPane = ResourceUtil.loadFxmlResource(Views.FONT_BROWSER_TOPDRAWER, leftDrawerController); - leftDrawer = new JFXDrawer(); - leftDrawer.setSidePane(leftDrawerPane); - leftDrawer.setDirection(JFXDrawer.DrawerDirection.TOP); - leftDrawer.setDefaultDrawerSize(150); - leftDrawer.setResizeContent(true); - leftDrawer.setOverLayVisible(false); - leftDrawer.setResizableOnDrag(false); - leftDrawer.setId("TOP"); + Controllers.initialize(GlcdFontDrawerController.class, details); + + VBox drawerPane = ResourceUtil.loadFxmlResource(Views.FONT_BROWSER_TOPDRAWER); + + drawer = new JFXDrawer(); + drawer.setSidePane(drawerPane); + drawer.setDirection(JFXDrawer.DrawerDirection.TOP); + drawer.setDefaultDrawerSize(150); + drawer.setResizeContent(true); + drawer.setOverLayVisible(false); + drawer.setResizableOnDrag(false); + drawer.setId("TOP"); transition = new HamburgerSlideCloseTransition(hamLeftDrawer); - hamLeftDrawer.addEventHandler(MouseEvent.MOUSE_PRESSED, event -> toggleTopDrawer()); + hamLeftDrawer.addEventHandler(MouseEvent.MOUSE_PRESSED, event -> toggleDrawer()); } catch (IOException e) { log.error("There was a problem loading the view for '" + Views.FONT_BROWSER_TOPDRAWER + "'", e); } } private void initFontDisplay() { - fontRenderer = FontRenderer.getInstance(); fontDisplay.setBuffer(new PixelBuffer(fontRenderer.getDriver().getWidth(), fontRenderer.getDriver().getHeight())); fontDisplay.setBacklightColor(Color.BLACK); //79ff4d fontDisplay.setActivePixelColor(Color.WHITE); @@ -310,14 +440,14 @@ private void initPreloaderBindings() { } // - private void toggleTopDrawer() { - showTopDrawer(!leftDrawer.isOpened()); + private void toggleDrawer() { + showDrawer(!drawer.isOpened()); } - private void showTopDrawer(boolean show) { + private void showDrawer(boolean show) { transition.setRate(show ? 1 : -1); transition.play(); - drawersStack.toggle(leftDrawer, show); + drawersStack.toggle(drawer, show); } private void renderText(GlcdFont font, String text) { @@ -326,7 +456,6 @@ private void renderText(GlcdFont font, String text) { return; }*/ fontRenderer.renderFont(fontDisplay, font, text); - fontDisplay.refresh(); drawFontHeader(font, fontDisplay); } diff --git a/src/main/java/com/ibasco/glcdemulator/controllers/GlcdFontDrawerController.java b/src/main/java/com/ibasco/glcdemulator/controllers/GlcdFontDrawerController.java index 90bb87b..eea958f 100644 --- a/src/main/java/com/ibasco/glcdemulator/controllers/GlcdFontDrawerController.java +++ b/src/main/java/com/ibasco/glcdemulator/controllers/GlcdFontDrawerController.java @@ -43,24 +43,33 @@ import java.net.URL; import java.util.ResourceBundle; -public class GlcdFontTopDrawerController extends Controller implements Initializable { +public class GlcdFontDrawerController extends Controller implements Initializable { - private static final Logger log = LoggerFactory.getLogger(GlcdFontTopDrawerController.class); + private static final Logger log = LoggerFactory.getLogger(GlcdFontDrawerController.class); @FXML private JFXListView lvFonts; - private final FontCacheService fontCacheService; + private FontCacheDetails details; - private final FontCacheDetails details; + public GlcdFontDrawerController() { + } + + public GlcdFontDrawerController(FontCacheDetails details) { + this.details = details; + } - public GlcdFontTopDrawerController(FontCacheService service, FontCacheDetails details) { - this.fontCacheService = service; + public void setDetails(FontCacheDetails details) { this.details = details; } + public FontCacheDetails getDetails() { + return details; + } + @Override public void initialize(URL location, ResourceBundle resources) { + log.debug("Initializing Font Drawer controller"); lvFonts.setOrientation(Orientation.HORIZONTAL); lvFonts.setCellFactory(this::listCellFactory); details.activeEntryProperty().bind(lvFonts.getSelectionModel().selectedItemProperty()); diff --git a/src/main/java/com/ibasco/glcdemulator/emulator/BufferLayout.java b/src/main/java/com/ibasco/glcdemulator/emulator/BufferLayout.java index a9446ce..6e6080a 100644 --- a/src/main/java/com/ibasco/glcdemulator/emulator/BufferLayout.java +++ b/src/main/java/com/ibasco/glcdemulator/emulator/BufferLayout.java @@ -33,6 +33,11 @@ abstract public class BufferLayout { abstract public void processByte(byte data); + public void processBuffer(byte[] data) { + for (byte d : data) + processByte(d); + } + abstract public void reset(); abstract public void initialize(); diff --git a/src/main/java/com/ibasco/glcdemulator/emulator/BufferLayoutFactory.java b/src/main/java/com/ibasco/glcdemulator/emulator/BufferLayoutFactory.java index cdc00ba..4a8eea3 100644 --- a/src/main/java/com/ibasco/glcdemulator/emulator/BufferLayoutFactory.java +++ b/src/main/java/com/ibasco/glcdemulator/emulator/BufferLayoutFactory.java @@ -58,6 +58,10 @@ public static BufferLayout createBufferLayout(GlcdBufferType type) { return bufferStrategyInstance; } + public static BufferLayout createBufferLayout(GlcdDisplay display) { + return createBufferLayout(display, null); + } + public static BufferLayout createBufferLayout(GlcdDisplay display, PixelBuffer buffer) { log.debug("Buffer type/layout = {}", display.getBufferType()); Class layoutClass = retrieveLayoutClass(display.getBufferType()); diff --git a/src/main/java/com/ibasco/glcdemulator/emulator/VerticalBufferLayout.java b/src/main/java/com/ibasco/glcdemulator/emulator/VerticalBufferLayout.java index 9fd3433..9724ada 100644 --- a/src/main/java/com/ibasco/glcdemulator/emulator/VerticalBufferLayout.java +++ b/src/main/java/com/ibasco/glcdemulator/emulator/VerticalBufferLayout.java @@ -52,7 +52,7 @@ public class VerticalBufferLayout extends BufferLayout { @Override public void processByte(byte data) { if (pageBufferList.isEmpty()) - throw new IllegalStateException("Page buffer is currently empty"); + throw new IllegalStateException("Page buffer is currently empty."); if (pageIndex > (pageSize - 1)) throw new IllegalStateException(String.format("Page index is greater than the maximum page limit (page index = %d, max page index = %d)", pageIndex, pageSize - 1)); @@ -73,6 +73,7 @@ public void processByte(byte data) { @Override public void initialize() { log.debug("Initializing page buffer strategy"); + reset(); } @Override diff --git a/src/main/java/com/ibasco/glcdemulator/model/FontCacheEntry.java b/src/main/java/com/ibasco/glcdemulator/model/FontCacheEntry.java index fe57d98..57e9fde 100644 --- a/src/main/java/com/ibasco/glcdemulator/model/FontCacheEntry.java +++ b/src/main/java/com/ibasco/glcdemulator/model/FontCacheEntry.java @@ -38,17 +38,39 @@ public class FontCacheEntry { private ReadOnlyIntegerWrapper descent = new ReadOnlyIntegerWrapper(); + private ReadOnlyIntegerWrapper maxCharWidth = new ReadOnlyIntegerWrapper(); + + private ReadOnlyIntegerWrapper maxCharHeight = new ReadOnlyIntegerWrapper(); + private ReadOnlyObjectWrapper font = new ReadOnlyObjectWrapper<>(); private ReadOnlyObjectWrapper image = new ReadOnlyObjectWrapper<>(); - public FontCacheEntry(int ascent, int descent, GlcdFont font, File cachedImage) { + public FontCacheEntry(int ascent, int descent, int maxCharWidth, int maxCharHeight, GlcdFont font, File cachedImage) { this.ascent.set(ascent); this.descent.set(descent); + this.maxCharWidth.set(maxCharWidth); + this.maxCharHeight.set(maxCharHeight); this.font.set(font); this.image.set(cachedImage); } + public int getMaxCharWidth() { + return maxCharWidth.get(); + } + + public ReadOnlyIntegerWrapper maxCharWidthProperty() { + return maxCharWidth; + } + + public int getMaxCharHeight() { + return maxCharHeight.get(); + } + + public ReadOnlyIntegerWrapper maxCharHeightProperty() { + return maxCharHeight; + } + public File getImage() { return image.get(); } diff --git a/src/main/java/com/ibasco/glcdemulator/services/FontCacheService.java b/src/main/java/com/ibasco/glcdemulator/services/FontCacheService.java index c021a6b..105e428 100644 --- a/src/main/java/com/ibasco/glcdemulator/services/FontCacheService.java +++ b/src/main/java/com/ibasco/glcdemulator/services/FontCacheService.java @@ -133,8 +133,8 @@ protected ObservableList call() throws Exception { else fontScreen.refresh(); - NodeUtil.saveNodeImageToFile(screenBuffer, cachedImagePath, width, height); - FontCacheEntry entry = new FontCacheEntry(info.getAscent(), info.getDescent(), font, cachedImagePath); + NodeUtil.saveNodeImageToFile(fontScreen, cachedImagePath, width, height); + FontCacheEntry entry = new FontCacheEntry(info.getAscent(), info.getDescent(), info.getMaxCharWidth(), info.getMaxCharHeight(), font, cachedImagePath); entries.add(entry); } catch (Exception e) { log.warn("Font Cache Service: Unable to cache font '" + font.name() + "' (Reason: {})", e.toString()); @@ -224,7 +224,10 @@ private int loadCacheEntries() { String json = org.apache.commons.io.FileUtils.readFileToString(cacheFile, StandardCharsets.UTF_8); Type fooType = new TypeToken>() { }.getType(); - return JsonUtils.fromJson(json, fooType); + ArrayList cachedEntries = JsonUtils.fromJson(json, fooType); + entries.clear(); + entries.addAll(cachedEntries); + return entries.size(); } } catch (IOException e) { log.error("Error during cache-read operation", e); diff --git a/src/main/java/com/ibasco/glcdemulator/utils/json/adapters/FontCacheEntryAdapter.java b/src/main/java/com/ibasco/glcdemulator/utils/json/adapters/FontCacheEntryAdapter.java index 2f286b1..11b9d59 100644 --- a/src/main/java/com/ibasco/glcdemulator/utils/json/adapters/FontCacheEntryAdapter.java +++ b/src/main/java/com/ibasco/glcdemulator/utils/json/adapters/FontCacheEntryAdapter.java @@ -38,9 +38,11 @@ public FontCacheEntry deserialize(JsonElement json, Type typeOfT, JsonDeserializ JsonObject obj = json.getAsJsonObject(); int ascent = obj.get("ascent").getAsInt(); int descent = obj.get("descent").getAsInt(); + int maxcharwidth = obj.get("maxwidth").getAsInt(); + int maxcharheight = obj.get("maxheight").getAsInt(); String fontKey = obj.get("font").getAsString(); String imagePath = obj.get("image").getAsString(); - return new FontCacheEntry(ascent, descent, GlcdFont.valueOf(fontKey), new File(imagePath)); + return new FontCacheEntry(ascent, descent, maxcharwidth, maxcharheight, GlcdFont.valueOf(fontKey), new File(imagePath)); } @Override @@ -48,6 +50,8 @@ public JsonElement serialize(FontCacheEntry src, Type typeOfSrc, JsonSerializati JsonObject obj = new JsonObject(); obj.addProperty("ascent", src.getAscent()); obj.addProperty("descent", src.getDescent()); + obj.addProperty("maxwidth", src.getMaxCharWidth()); + obj.addProperty("maxheight", src.getMaxCharHeight()); obj.addProperty("font", src.getFont().name()); obj.addProperty("image", src.getImage().getAbsolutePath()); return obj; diff --git a/src/main/resources/css/app-dark.css b/src/main/resources/css/app-dark.css index 3013b60..cbe1870 100644 --- a/src/main/resources/css/app-dark.css +++ b/src/main/resources/css/app-dark.css @@ -448,3 +448,7 @@ -fx-alignment: center-left; -fx-spacing: 8; } + +#apFontDetails { + -fx-background-color: #2C2C2C; +} \ No newline at end of file diff --git a/src/main/resources/views/font-browser-dialog.fxml b/src/main/resources/views/font-browser-dialog.fxml index 02b7dea..497a9f5 100644 --- a/src/main/resources/views/font-browser-dialog.fxml +++ b/src/main/resources/views/font-browser-dialog.fxml @@ -5,113 +5,121 @@ - - + + - +
- + - + - + - - - + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -124,9 +132,22 @@ - - + + + + + + + + + + + + @@ -152,17 +173,14 @@ - + -