From 73bd9b3db6451a5055d5be5600397ec68b474853 Mon Sep 17 00:00:00 2001 From: Dirk Lemmermann Date: Tue, 22 Feb 2022 17:54:56 +0100 Subject: [PATCH] Added the stylesheet directly to the control as there were still issues properly styling the control. Fixed some CSS rules to more easily pick up inherited colors. More consistent with Modena rules now. Added CSSFX to the demo app. --- pdfviewfx-demo/pom.xml | 7 +++ .../com/dlsc/pdfviewfx/demo/PDFViewApp.java | 9 ++-- pdfviewfx-demo/src/main/java/module-info.java | 1 + .../main/java/com/dlsc/pdfviewfx/PDFView.java | 30 ++++--------- .../resources/com/dlsc/pdfviewfx/pdf-view.css | 45 +++++++++++++------ 5 files changed, 54 insertions(+), 38 deletions(-) diff --git a/pdfviewfx-demo/pom.xml b/pdfviewfx-demo/pom.xml index 11aee3d..dccbd08 100644 --- a/pdfviewfx-demo/pom.xml +++ b/pdfviewfx-demo/pom.xml @@ -54,6 +54,13 @@ pdfviewfx 1.6.0 + + + fr.brouillard.oss + cssfx + 11.5.0 + + diff --git a/pdfviewfx-demo/src/main/java/com/dlsc/pdfviewfx/demo/PDFViewApp.java b/pdfviewfx-demo/src/main/java/com/dlsc/pdfviewfx/demo/PDFViewApp.java index 874468d..9059b7d 100644 --- a/pdfviewfx-demo/src/main/java/com/dlsc/pdfviewfx/demo/PDFViewApp.java +++ b/pdfviewfx-demo/src/main/java/com/dlsc/pdfviewfx/demo/PDFViewApp.java @@ -1,9 +1,7 @@ package com.dlsc.pdfviewfx.demo; import com.dlsc.pdfviewfx.PDFView; - -import java.io.File; - +import fr.brouillard.oss.cssfx.CSSFX; import javafx.application.Application; import javafx.beans.binding.Bindings; import javafx.collections.ObservableList; @@ -18,6 +16,8 @@ import javafx.stage.FileChooser.ExtensionFilter; import javafx.stage.Stage; +import java.io.File; + public class PDFViewApp extends Application { private FileChooser chooser; @@ -67,6 +67,9 @@ public void start(Stage primaryStage) { box.setFillWidth(true); Scene scene = new Scene(box); + + CSSFX.start(primaryStage); + primaryStage.setTitle("PDF View"); primaryStage.setWidth(1000); primaryStage.setHeight(900); diff --git a/pdfviewfx-demo/src/main/java/module-info.java b/pdfviewfx-demo/src/main/java/module-info.java index d400aba..dc3436b 100644 --- a/pdfviewfx-demo/src/main/java/module-info.java +++ b/pdfviewfx-demo/src/main/java/module-info.java @@ -1,4 +1,5 @@ module com.dlsc.pdfviewfx.demo { requires com.dlsc.pdfviewfx; + requires fr.brouillard.oss.cssfx; exports com.dlsc.pdfviewfx.demo; } \ No newline at end of file diff --git a/pdfviewfx/src/main/java/com/dlsc/pdfviewfx/PDFView.java b/pdfviewfx/src/main/java/com/dlsc/pdfviewfx/PDFView.java index 139ddb8..104de5e 100644 --- a/pdfviewfx/src/main/java/com/dlsc/pdfviewfx/PDFView.java +++ b/pdfviewfx/src/main/java/com/dlsc/pdfviewfx/PDFView.java @@ -2,6 +2,13 @@ import com.dlsc.pdfviewfx.PDFView.Document.DocumentProcessingException; import com.dlsc.pdfviewfx.skins.PDFViewSkin; +import javafx.beans.property.*; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.geometry.Rectangle2D; +import javafx.scene.control.Control; +import javafx.scene.control.Skin; +import javafx.scene.paint.Color; import java.awt.image.BufferedImage; import java.io.File; @@ -10,27 +17,6 @@ import java.util.Objects; import java.util.function.Supplier; -import javafx.beans.property.BooleanProperty; -import javafx.beans.property.DoubleProperty; -import javafx.beans.property.FloatProperty; -import javafx.beans.property.IntegerProperty; -import javafx.beans.property.ListProperty; -import javafx.beans.property.ObjectProperty; -import javafx.beans.property.SimpleBooleanProperty; -import javafx.beans.property.SimpleDoubleProperty; -import javafx.beans.property.SimpleFloatProperty; -import javafx.beans.property.SimpleIntegerProperty; -import javafx.beans.property.SimpleListProperty; -import javafx.beans.property.SimpleObjectProperty; -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.property.StringProperty; -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; -import javafx.geometry.Rectangle2D; -import javafx.scene.control.Control; -import javafx.scene.control.Skin; -import javafx.scene.paint.Color; - /** * A PDF viewer based on Apache PDFBox. The view shows thumbnails * on the left and the full page on the right. The user can zoom in, @@ -75,6 +61,8 @@ public PDFView() { setSearchText(null); }); + + getStylesheets().add(getUserAgentStylesheet()); } @Override diff --git a/pdfviewfx/src/main/resources/com/dlsc/pdfviewfx/pdf-view.css b/pdfviewfx/src/main/resources/com/dlsc/pdfviewfx/pdf-view.css index 5f211e9..5036161 100644 --- a/pdfviewfx/src/main/resources/com/dlsc/pdfviewfx/pdf-view.css +++ b/pdfviewfx/src/main/resources/com/dlsc/pdfviewfx/pdf-view.css @@ -18,12 +18,12 @@ .pdf-view .search-result-list-view .list-cell .matches-label { -fx-font-size: .9em; - -fx-text-fill: grey; + -fx-text-fill: -fx-text-background-color; + -fx-opacity: .5 } .pdf-view .search-result-list-view:focused .list-cell:focused .matches-label, .pdf-view .search-result-list-view:focused .list-cell:selected .matches-label { - -fx-text-fill: white; } .pdf-view .search-result-list-view .list-cell .image-view-wrapper { @@ -39,19 +39,31 @@ /* ------------------------------------------------------------------ * Thumbnail List View */ -.pdf-view .thumbnail-list-view .list-cell { +.pdf-view .thumbnail-list-view .list-cell, +.pdf-view .thumbnail-list-view:focused .list-cell { + -fx-background: rgb(245, 245, 245); + -fx-background-color: -fx-background; -fx-padding: 20 20 10 10; - -fx-background-color: rgb(245, 245, 245) !important; +} + +.pdf-view .thumbnail-list-view .list-cell:odd, +.pdf-view .thumbnail-list-view:focused .list-cell:odd { + -fx-background: rgb(245, 245, 245); + -fx-background-color: -fx-background; } .pdf-view .thumbnail-list-view .list-cell .page-number-label, -.pdf-view .thumbnail-list-view .list-cell:selected .page-number-label { - -fx-text-fill: grey; +.pdf-view .thumbnail-list-view:focused .list-cell .page-number-label, +.pdf-view .thumbnail-list-view .list-cell:selected .page-number-label, +.pdf-view .thumbnail-list-view:focused .list-cell:selected .page-number-label { + -fx-text-fill: -fx-text-background-color; -fx-font-size: 10px; } -.pdf-view .thumbnail-list-view .list-cell:selected { - -fx-background-color: rgb(245, 245, 245) !important; +.pdf-view .thumbnail-list-view .list-cell:selected, +.pdf-view .thumbnail-list-view:focused .list-cell:selected { + -fx-background: rgb(245, 245, 245); + -fx-background-color: -fx-background; } .pdf-view .thumbnail-list-view { @@ -70,17 +82,22 @@ -fx-background-radius: 2px; } +.pdf-view .label { + -fx-text-fill: -fx-text-background-color; +} + .pdf-view .tool-bar .search-field .ikonli-font-icon { - -fx-icon-color: gray; + -fx-opacity: .66; + -fx-icon-color: -fx-text-background-color; -fx-icon-size: 16px; } .pdf-view .tool-bar .search-field .ikonli-font-icon:hover { - -fx-icon-color: black; + -fx-opacity: 1; } .pdf-view .tool-bar .search-field .ikonli-font-icon:pressed { - -fx-icon-color: black; + -fx-opacity: 1; } .pdf-view .search-navigator { @@ -92,7 +109,7 @@ } .pdf-view .search-navigator .search-result-label { - -fx-text-fill: black; + -fx-text-fill: -fx-text-background-color; } .pdf-view .search-navigator .search-bar-button { @@ -100,7 +117,7 @@ -fx-background-radius: 2, 2; -fx-background-color: gray, -fx-base; -fx-background-insets: 0, 1 1 1 1; - -fx-text-fill: black; + -fx-text-fill: -fx-text-background-color; } .pdf-view .search-navigator .search-bar-button:hover { @@ -137,7 +154,7 @@ .pdf-view .tool-bar .tool-bar-button .ikonli-font-icon { -fx-icon-size: 18px; - -fx-icon-color: black; + -fx-icon-color: -fx-text-background-color; } .pdf-view .page-control .previous-page-button {