Skip to content

Instantly share code, notes, and snippets.

@DeanWookey DeanWookey/CSSStyleHelperTest.java Secret
Last active Jan 17, 2020

Embed
What would you like to do?
CSSStyleHelperTest
package test.javafx.scene;
import com.sun.javafx.css.StyleManager;
import javafx.stage.Stage;
import com.sun.javafx.tk.Toolkit;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import javafx.css.CssParser;
import javafx.css.Stylesheet;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Text;
import static org.junit.Assert.assertNull;
import org.junit.Before;
import org.junit.Test;
public class CSSStyleHelperTest {
private Scene scene;
private Stage stage;
private StackPane root;
@Before
public void setup() {
root = new StackPane();
scene = new Scene(root);
stage = new Stage();
stage.setScene(scene);
StyleManager sm = StyleManager.getInstance();
sm.userAgentStylesheetContainers.clear();
sm.platformUserAgentStylesheetContainers.clear();
sm.stylesheetContainerMap.clear();
sm.cacheContainerMap.clear();
sm.hasDefaultUserAgentStylesheet = false;
}
@Test
public void removingThenAddingNodeToDifferentBranchGetsNewFontStyleTest() throws IOException {
Stylesheet stylesheet = null;
root.getStyleClass().add("root");
// R
// .-----+-----.
// A B
// .----+----. .
// C D E
//Where C and D are Labels. Then I'd set a font style on A and a different font style on B.
//C and D should pick up the font style of A. Then remove D and readd it to B and see if it still has A's
//font style.
stylesheet = new CssParser().parse(
"removingThenAddingNodeToDifferentBranchGetsNewFontStyleTest",
".root {}\n"
+ ".a { -fx-font-style: italic; }\n"
+ ".b { -fx-font-style: normal; }\n"
);
StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet);
Pane A = new Pane();
A.getStyleClass().add("a");
Pane B = new Pane();
B.getStyleClass().add("b");
Text C = new Text("C");
Text D = new Text("D");
Text E = new Text("E");
root.getChildren().addAll(A, B);
A.getChildren().addAll(C, D);
B.getChildren().add(E);
stage.show();
Toolkit.getToolkit().firePulse();
assertEquals("Italic", C.getFont().getStyle());
assertEquals("Italic", D.getFont().getStyle());
assertNull(E.getFont().getStyle());
A.getChildren().remove(D); //move D
Toolkit.getToolkit().firePulse();
B.getChildren().add(D);
Toolkit.getToolkit().firePulse();
assertEquals("Italic", C.getFont().getStyle());
assertNull(D.getFont().getStyle());
assertNull(E.getFont().getStyle());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.