Created
November 28, 2019 12:31
-
-
Save Col-E/f9b27e8525cb680791c2eb316c9f23af to your computer and use it in GitHub Desktop.
Live CSS tampering
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package me.coley.recaf.ui.controls.theme; | |
import javafx.application.Application; | |
import javafx.fxml.FXMLLoader; | |
import javafx.scene.Parent; | |
import javafx.scene.Scene; | |
import javafx.scene.control.SplitPane; | |
import javafx.scene.image.Image; | |
import javafx.scene.input.KeyCode; | |
import javafx.stage.Stage; | |
import me.coley.recaf.ui.controls.text.TextPane; | |
import me.coley.recaf.ui.controls.text.model.Languages; | |
import java.io.*; | |
import java.lang.management.ManagementFactory; | |
import java.lang.management.PlatformLoggingMXBean; | |
import static me.coley.recaf.util.ClasspathUtil.resource; | |
public class CSSPlayground extends Application { | |
public static void main(String[] args) { | |
launch(args); | |
} | |
@Override | |
public void start(Stage stage) throws Exception { | |
FXMLLoader loader = new FXMLLoader(CSSPlayground.class.getResource("/sampler.fxml")); | |
Parent root = loader.load(); | |
SplitPane sp = new SplitPane(); | |
Scene scene = new Scene(sp); | |
scene.getStylesheets().add("style/text-theme-default.css"); | |
TextPane cssContent = new TextPane(null, Languages.find("css")); | |
cssContent.setText(".text-area {}"); | |
cssContent.setEditable(true); | |
cssContent.setOnKeyReleased(e -> { | |
if(e.isControlDown() && e.getCode() == KeyCode.S) { | |
String css = cssContent.getText(); | |
try { | |
File temp = File.createTempFile("recaf", "tmpcss"); | |
temp.deleteOnExit(); | |
BufferedWriter bw = new BufferedWriter(new FileWriter(temp)); | |
bw.write(css); | |
bw.close(); | |
scene.getStylesheets().clear(); | |
scene.getStylesheets().add("style/text-theme-default.css"); | |
scene.getStylesheets().add(temp.toURI().toString()); | |
} catch(Exception ex) {} | |
} | |
}); | |
sp.getItems().add(cssContent); | |
sp.getItems().add(root); | |
// Disable CSS logger, it complains a lot about non-issues | |
ManagementFactory.getPlatformMXBean(PlatformLoggingMXBean.class).setLoggerLevel("javafx" + | |
".css", "OFF"); | |
stage.setScene(scene); | |
stage.getIcons().add(new Image(resource("icons/logo.png"))); | |
stage.setTitle("CSS Playground"); | |
stage.show(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<?import javafx.scene.control.Button?> | |
<?import javafx.scene.control.CheckBox?> | |
<?import javafx.scene.control.ComboBox?> | |
<?import javafx.scene.control.Label?> | |
<?import javafx.scene.control.ListView?> | |
<?import javafx.scene.control.Menu?> | |
<?import javafx.scene.control.MenuBar?> | |
<?import javafx.scene.control.MenuItem?> | |
<?import javafx.scene.control.SplitPane?> | |
<?import javafx.scene.control.Tab?> | |
<?import javafx.scene.control.TabPane?> | |
<?import javafx.scene.control.TableColumn?> | |
<?import javafx.scene.control.TableView?> | |
<?import javafx.scene.control.TextArea?> | |
<?import javafx.scene.control.TextField?> | |
<?import javafx.scene.control.TreeView?> | |
<?import javafx.scene.layout.AnchorPane?> | |
<?import javafx.scene.layout.BorderPane?> | |
<BorderPane xmlns="http://javafx.com/javafx/8.0.1" xmlns:fx="http://javafx.com/fxml/1"> | |
<top> | |
<MenuBar BorderPane.alignment="CENTER"> | |
<menus> | |
<Menu mnemonicParsing="false" text="File"> | |
<items> | |
<MenuItem mnemonicParsing="false" text="Close" /> | |
</items> | |
</Menu> | |
<Menu mnemonicParsing="false" text="Edit"> | |
<items> | |
<MenuItem mnemonicParsing="false" text="Copy" /> | |
<MenuItem mnemonicParsing="false" text="Cut" /> | |
<MenuItem mnemonicParsing="false" text="Delete" /> | |
</items> | |
</Menu> | |
<Menu mnemonicParsing="false" text="Help"> | |
<items> | |
<MenuItem mnemonicParsing="false" text="About" /> | |
</items> | |
</Menu> | |
</menus> | |
</MenuBar> | |
</top> | |
<center> | |
<SplitPane dividerPositions="0.29797979797979796" prefHeight="366.0" prefWidth="657.0" BorderPane.alignment="CENTER"> | |
<items> | |
<BorderPane> | |
<center> | |
<TreeView editable="true" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER" /> | |
</center> | |
</BorderPane> | |
<TabPane SplitPane.resizableWithParent="false"> | |
<tabs> | |
<Tab text="Tab 1"> | |
<content> | |
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0"> | |
<children> | |
<Button layoutX="106.0" layoutY="14.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="122.0" text="Button" /> | |
<Label layoutX="14.0" layoutY="18.0" text="Example Text" /> | |
<Label layoutX="14.0" layoutY="61.0" text="Example Text" /> | |
<CheckBox layoutX="106.0" layoutY="61.0" mnemonicParsing="false" prefHeight="17.0" prefWidth="94.0" text="CheckBox" /> | |
<Label layoutX="14.0" layoutY="101.0" text="Example Text" /> | |
<ComboBox layoutX="106.0" layoutY="97.0" prefHeight="25.0" prefWidth="124.0" promptText="Prompt Text" /> | |
<Button disable="true" layoutX="260.0" layoutY="16.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="122.0" text="Button" /> | |
<CheckBox disable="true" layoutX="260.0" layoutY="63.0" mnemonicParsing="false" prefHeight="17.0" prefWidth="94.0" text="CheckBox" /> | |
<ComboBox disable="true" layoutX="260.0" layoutY="99.0" prefHeight="25.0" prefWidth="124.0" promptText="Prompt Text" /> | |
<Label layoutX="14.0" layoutY="139.0" text="Example Text" /> | |
<ListView layoutX="106.0" layoutY="139.0" prefHeight="200.0" prefWidth="126.0" /> | |
<ListView layoutX="258.0" layoutY="139.0" prefHeight="200.0" prefWidth="126.0" /> | |
</children> | |
</AnchorPane> | |
</content> | |
</Tab> | |
<Tab text="Tab 2"> | |
<content> | |
<BorderPane> | |
<center> | |
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0"> | |
<children> | |
<TextField layoutX="14.0" layoutY="14.0" prefHeight="25.0" prefWidth="200.0" text="Textfield" /> | |
<TextField disable="true" layoutX="229.0" layoutY="14.0" prefHeight="25.0" prefWidth="200.0" text="Textfield" /> | |
<TextArea layoutX="14.0" layoutY="50.0" prefHeight="97.0" prefWidth="199.0" text="# Sample Text Text: Area Example: Text" /> | |
<TextArea disable="true" layoutX="230.0" layoutY="50.0" prefHeight="97.0" prefWidth="199.0" text="# Sample Text Text: Area Example: Text" /> | |
<TableView layoutX="14.0" layoutY="159.0" prefHeight="163.0" prefWidth="410.0" tableMenuButtonVisible="true"> | |
<columns> | |
<TableColumn prefWidth="75.0" text="C1" /> | |
<TableColumn prefWidth="75.0" text="C2" /> | |
</columns> | |
</TableView> | |
</children> | |
</AnchorPane> | |
</center> | |
</BorderPane> | |
</content> | |
</Tab> | |
</tabs> | |
</TabPane> | |
</items> | |
</SplitPane> | |
</center> | |
</BorderPane> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment