Skip to content

Instantly share code, notes, and snippets.

@arjabbar
Created June 23, 2016 20:32
Show Gist options
  • Save arjabbar/2d98a121e928e93bde44b1625074dd01 to your computer and use it in GitHub Desktop.
Save arjabbar/2d98a121e928e93bde44b1625074dd01 to your computer and use it in GitHub Desktop.
CSS Injector
cssStage = new Stage();
TextArea cssBox = new TextArea();
cssBox.minHeight(150);
cssBox.minWidth(300);
cssBox.setFont(new Font("monospace", 16));
Parent root = new Pane(cssBox);
Scene scene = new Scene(root);
cssStage.setScene(scene);
cssStage.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
if (event.getCode().equals(KeyCode.ENTER) && event.isControlDown() && !cssBox.getText().isEmpty()) {
String text = cssBox.getText().replaceAll("\n|\t", "");
int endIndex = cssBox.getText().indexOf("{");
String selector = text.substring(0, endIndex).trim();
String styling = text.substring(endIndex, text.length()).replaceAll("\\{|\\}", "");
getRootView().lookupAll(selector).forEach(node -> node.setStyle(styling));
}
});
cssStage.show();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment