How to Convert CSS into Bss

How to convert css into bss

Let's imagine your jdk 8 home bin directory is on your shell path.

Create Love.java:

import javafx.stage.*;
import javafx.application.*;
import javafx.scene.control.*;
import javafx.scene.*;

public class Love extends Application {
public void start(Stage stage) throws Exception {
Scene scene = new Scene(new Label("hello, world"));
scene.getStylesheets().add("love.css");
stage.setScene(scene);
stage.show();
}
}

Compile it:

javac Love.java

Create love.css:

.label { -fx-text-fill: firebrick; }

Compile it:

javafxpackager -createbss -srcfiles love.css -outdir . -outfile love

This will create love.bss

Now you can delete love.css as you don't need it anymore as you have made binary love.

Now run your app:

java Love

Even though you requested love.css, the JavaFX runtime was smart enough to recognize that you have a binary love.bss and use that to apply css styles to your app.

love

OpenJFX 11 - javafxpackager Binary CSS

While there is a jpackage tool that is possibly being added to Java 14, I'm not aware that it is going to use Css2Bin.

In OpenJFX (11+), Css2Bin is still a tool used internally to convert the Modena CSS files into BSS. You can find it here.

If you search the uses of this tool within OpenJFX, you will find it in the build.gradle file that is used to build JavaFX itself.

I'll paste the task, as it is relevant to see what it does:

def modulePath = "${project.sourceSets.main.java.outputDir}"
modulePath += File.pathSeparator + "${rootProject.projectDir}/modules/javafx.graphics/build/classes/java/main"
modulePath += File.pathSeparator + "${rootProject.projectDir}/modules/javafx.base/build/classes/java/main"
processResources {
doLast {
def cssFiles = fileTree(dir: "$moduleDir/com/sun/javafx/scene/control/skin")
cssFiles.include "**/*.css"
cssFiles.each { css ->
logger.info("converting CSS to BSS ${css}");

javaexec {
executable = JAVA
workingDir = project.projectDir
jvmArgs += patchModuleArgs
jvmArgs += "--module-path=$modulePath"
jvmArgs += "--add-modules=javafx.graphics"
main = "com.sun.javafx.css.parser.Css2Bin"
args css
}
}
}
}

As you can notice, basically a java command is called, with the JavaFX jars in the module path, to run the Css2Bin::main public method, which is just part of the javafx.graphics included module.

So nothing prevents you from doing exactly the same in your build process.

Assuming you are using Gradle, you can add a task that is executed before the jar task, something like this:

def java_home = hasProperty('org.gradle.java.home') ? 
getProperty('org.gradle.java.home') : System.getenv('JAVA_HOME')

task css {
if (java_home == null) {
throw new RuntimeException("java_home is not defined.")
}
def cssFiles = fileTree(dir: "$project.rootDir/src/main/resources/")
cssFiles.include "**/*.css"
cssFiles.each { css ->
logger.info("converting CSS to BSS ${css}")
doLast {
exec {
commandLine "${java_home}/bin/java",
"--module-path", sourceSets.main.runtimeClasspath.asPath,
"--add-modules", "javafx.graphics",
"com.sun.javafx.css.parser.Css2Bin", css
}
}
}
}

Simply run:

./gradlew css

and it will convert all the css files in your resources to bss. Then you will probably need to filter out the css ones when doing the jar.

Same task can be run in a similar way from Maven or command line, of course.

java.io.IOException: rsrc:application/application.bss wrong binary CSS version: 5. Expected version less than or equal to3

As José Pereda stated, bss is version 5 on Java 8. Based on the JavaFX 8 CSS Reference Guide for label, the syntax is correct. However, this is for Java 8, while you are currently using Java 7. If you have Java 8, configure eclipse and set the build path to use it and set your PATH variable accordingly to Java 8.

If the problem persists:

If it's not working even after the update, we'll try to compile it slightly differently to see what happens. According to this post, you don't need the .css file once you have compiled the .bss file.

Create a Test folder somewhere easily accessible. We'll be using this to see how the files being compiled separately will effect the exception since updating Java has done nothing at this point.

First, try to run the program with the essential files. If your Main.java file doesn't rely on the other java files in your project, then copy that file in to the test folder we recently created. If not, copy only the necessary parts that use the css (such as the scene and label that calls the css file), and paste that into a new Main.java in the new test folder.

Continuing forward you're going to have to open a command window in your test folder. You can do this by pressing SHIFT + RIGHT CLICK in the test folder on Windows Explorer and click Open command window here

After this, compile Main.java by typing this in the newly opened commnd prompt window:

javac Main.java

Next, copy appication.css but rename it to Main.css, for testing purposes. Then, run this in the command prompt window (You didn't have the -outfile arguement; this shouldn't matter, but it's a slight safety measure):

javafxpackager -createbss -srcfiles Main.css -outdir . -outfile Main

Now you should see that you have Main.css. Now, with the same command window you can easily run the file and see what happens.

java Main

Please leave a comment if this help you and which part of this answer you actually used to fix the problem if this answer did help you, thanks!

BeautifulSoup use unique CSS Selector

As far as I know nth-of-child is still not implemented in BeautifulSoup4. Also if you investigate the website's CSS (namely _system.scss file), you'll find out that there are 3 statuses:

  1. system-item-green
  2. system-item-yellow
  3. system-item-red

So you may want to slightly change your code to be like this:

import requests
from bs4 import BeautifulSoup as BS

url = 'https://www.placetel.de/status'
headers = {
'User-Agent': 'Mozilla/5.0 (X11; Linux i586; rv:31.0) Gecko/20100101 Firefox/31.0'
}
source = requests.get(url, headers=headers)
soup = BS(source.text, 'html.parser')

status = soup.select("div.system-item")[1].attrs['class']

if 'system-item-green' in status:
print("It works!")
elif 'system-item-yellow' in status:
print("Something's slightly wrong")
elif 'system-item-red' in status:
print("Does not work")
else:
print("Has someone changed page's markup?")

How to change the bootstrap primary color?

Bootstrap 5 (update 2021)

The method is still the same for Bootstrap 5.

https://codeply.com/p/iauLPArGqE

Bootstrap 4

To change the primary, or any of the theme colors in Bootstrap 4 SASS, set the appropriate variables before importing bootstrap.scss. This allows your custom scss to override the !default values...

$primary: purple;
$danger: red;

@import "bootstrap";

Demo: https://codeply.com/go/f5OmhIdre3


In some cases, you may want to set a new color from another existing Bootstrap variable. For this @import the functions and variables first so they can be referenced in the customizations...

/* import the necessary Bootstrap files */
@import "bootstrap/functions";
@import "bootstrap/variables";

$theme-colors: (
primary: $purple
);

/* finally, import Bootstrap */
@import "bootstrap";

Demo: https://codeply.com/go/lobGxGgfZE


Also see: this answer, this answer or changing the button color in (CSS or SASS)


It's also possible to change the primary color with CSS only but it requires a lot of additional CSS since there are many -primary variations (btn-primary, alert-primary, bg-primary, text-primary, table-primary, border-primary, etc...) and some of these classes have slight colors variations on borders, hover, and active states. Therefore, if you must use CSS it's better to use target one component such as changing the primary button color.

JavaFX: Cannot load binary stylesheets

It was indeed a difference in the environment: the .bss files were being filtered by maven when the resources plugin was copying them from the source directory into the jar or classes folder while building. This was essentially corrupting the files.

So the solution was to add an exclude clause to the project's pom.xml:

<project>
...
<build>
...
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
...
<exclude>**/*.bss</exclude>
...

How to load css file in javafx8

You need an URL and call toExternalForm in order to load a css file into your project.

Use the ClassLoader for that:

scene.getStylesheets().add(getClass().getResource("/style.css").toExternalForm());

What is better 1 Huge Css file or several smaller files

One large CSS file leads to fewer HTTP requests, which can improve performance.

Several smaller files leads to easier organization which will make development and maintenance cheaper and easier.
This is a hard one to answer. Both options have their pros and cons in my opinion.

I personally don't love reading through a single HUGE CSS file, and maintaining it is very difficult. On the other hand, splitting it out causes extra http requests which could potentially slow things down.

My opinion would be one of two things.

1) If you know that your CSS will NEVER change once you've built it, I'd build multiple CSS files in the development stage (for readability), and then manually combine them before going live (to reduce http requests)

2) If you know that you're going to change your CSS once in a while, and need to keep it readable, I would build separate files and use code (providing you're using some sort of programming language) to combine them at runtime build time (runtime minification/combination is a resource pig).

With either option I would highly recommend caching on the client side in order to further reduce http requests.

I've settled on using separate files in my design time, and a build process to minify and combine. This way I can have separate (manageable) css while I develop and a proper monolithic minified file at runtime. And I still have my static files and less system overhead because I'm not doing compression/minification at runtime.



Related Topics



Leave a reply



Submit