不会加载JavaFX虚拟键盘的自定义CSS

时间:2015-09-08 15:50:04

标签: css javafx keyboard virtual

在使用FXVK虚拟键盘时,我想将默认皮肤改为我自己的想法。我在JavaFX的源代码中找到的css标签。这些已添加到自定义css并加载,如下所示。

keyboard.getScene().getStyleSheets()

当预期显示键盘时,将调用此功能并显示已发出呼叫的输出。然而,CSS不会改变布局。使用keyboard.getStyleSheets()代替use strict; use warnings; use Data::Dumper; my @data; my $domain; my $textFound = 0; my $href = {}; while(<DATA>) { chomp; # found the first domain skipping that one if ( /cn_DomainIntity\s+:\s+\bps_Domain\b/ ){ next; } # start grapping data if (/\bRadioBearerSetup\b/) { $textFound = 1; push @data, $_; } # end grapping data elsif (/\bRadioBearerSetupComplete\b/) { push @data, $_; #push into hash ref push @{$href->{$domain}},@data; # reset the flags $textFound = 0; $domain = ""; # reset data @data = (); } # grab the domain name elsif (/\b([a-z]{2}_Domain)\b/) { $domain = $1; push @data, $domain; } # misc text elsif (1 == $textFound){ push @data, $_; } } print Dumper $href; __DATA__ Random network information. cn_DomainIntity : ps_Domain more text 10.162.55.123 RadioBearerSetup some text some more text cs_Domain random text 10.162.55.136 RadioBearerSetupComplete network stats 10.162.55.122 RadioBearerSetup text ps_Domain text 10.162.66.125 RadioBearerSetupComplete 也不提供替代方案。

1 个答案:

答案 0 :(得分:1)

您的代码对我来说很有效,但是,您的错误是您必须在焦点事件通过应用程序传播并完全呈现FXVK SubWindow之后调用“ setVirtualKeyboardCSS”函数。

enter image description here

public static final int TICK = 5;

public void setTimer() {
        timer = new Timer();
        timer.scheduleAtFixedRate(new TimerTask() {
            public void run() {
                Platform.runLater(() -> {
                    setVirtualKeyboradCss();
                });
            }
        }, TICK, TICK);
    }

    public void setVirtualKeyboradCss() {
        @SuppressWarnings("deprecation")
        final Iterator<Window> windows = Window.impl_getWindows();

        while (windows.hasNext()) {
            final Window window = windows.next();
            if (window instanceof Popup) {
                String vars = getClass().getResource("/css/variables.css").toExternalForm();
                String embed = getClass().getResource("/css/embeded.css").toExternalForm();

                FXVK keyboard = (FXVK) window.getScene().getRoot().lookup(".fxvk");
                if (keyboard != null) {
                    if (!keyboard.getStylesheets().contains(embed)) {
                        keyboard.getStylesheets().addAll(vars, embed);
                    }
                }

                timer.cancel();
                timer = null;
            }
        }
    }

variables.css

@font-face {
    -fx-font-family: "DINPro-Bold";
    src: url('/fonts/DINPro-Bold.otf');
}

* {
    -color-black: #303030;
    -color-white: #FFFFFF;
    -color-brownish-gray: #606060;
    -color-yellow: #FCB400;
}

embeded.css

.fxvk {
    -fx-background-color: -color-brownish-gray;
}

.fxvk .key{
    -fx-font-family: "DINPro-Bold", "sans-serif";
    -fx-border-image-source: null;
    -fx-border-radius: 3;
    -fx-background-radius: 3;
    -fx-background-color: radial-gradient(center 50% 50%, radius 60%, derive(-color-white, -65%), -color-black);
}

.fxvk .key:hover{
    -fx-background-color: -color-yellow;
}

.fxvk-secondary{
}

.shift-icon {
}

.capslock-icon{
}

.shift{
    -fx-fill: -color-white;
}

.special {
    -fx-fill: -color-white;
}

.backspace{
    -fx-fill: -color-white;
}

.enter {
    -fx-fill: -color-white;
}

.hide{
    -fx-fill: -color-white;
}

.multi-char-text{
    -fx-fill: -color-white;
}

.key-text {
    -fx-fill: -color-white;
    -fx-font-family: "DINPro-Bold", "sans-serif";
}

.key-alttext{
    -fx-fill: -color-white;
    -fx-font-family: "DINPro-Bold", "sans-serif";
}

.key-icon {
    -fx-fill: -color-white;
}

.multi-char-text{
    -fx-fill: -color-white;
}