camelCase 271 Share Posted August 16 (edited) When making scripts its a common requirement to let users configure certain settings problem is that swing is annoying! it is easy to mess things up and easy to write in a way where adding another setting can mess up the entire ui for smalls scripts, a gui can easily be the majority of the complexity in the codebase instead we will make a framework to take a data class, use reflection and some custom annotations to generate a gui on the fly for us * this was written with functionality in mind, its to make writing scripts faster not to be pretty * this was written 10 minutes before posting this so theres probably edge cases usage: SwingUtilities.invokeLater(() -> new TabbedUI(TestScriptSettings.getData())); see below for examples on how UITab annotation works some examples: No sub tabs, just settings public static class Data { @SerializedName("hoursUntilMuleOff") public int hoursUntilMuleOff = 12; @SerializedName("initalGP") public int initalGP = 16_000_000; @SerializedName("slayerLvl") public int slayerLvl = 30; @SerializedName("slayDragons") public boolean slayDragons = false; @SerializedName("slayWithWhip") public boolean slayWithWhip = true; @SerializedName("prayerTarget") public int prayerTarget = 60; @SerializedName("prayInPOH") public boolean prayInPOH = true; @SerializedName("moneyLeftAfterMuling") public int moneyLeftAfterMuling = 1_000_000; @SerializedName("minLootValue") public int minLootValue = 1000; } results in: 1 tab, some in root: public static class Data { @SerializedName("hoursUntilMuleOff") public int hoursUntilMuleOff = 12; @SerializedName("initalGP") public int initalGP = 16_000_000; @SerializedName("slayerLvl") @UITab("skilling") public int slayerLvl = 30; @SerializedName("slayDragons") @UITab("skilling") public boolean slayDragons = false; @SerializedName("slayWithWhip") @UITab("skilling") public boolean slayWithWhip = true; @SerializedName("prayerTarget") @UITab("skilling") public int prayerTarget = 60; @SerializedName("prayInPOH") @UITab("skilling") public boolean prayInPOH = true; @SerializedName("moneyLeftAfterMuling") public int moneyLeftAfterMuling = 1_000_000; @SerializedName("minLootValue") public int minLootValue = 1000; } results in: some in root, skilling has 2 subtabs public static class Data { @SerializedName("hoursUntilMuleOff") public int hoursUntilMuleOff = 12; @SerializedName("initalGP") public int initalGP = 16_000_000; @SerializedName("slayerLvl") @UITab("skilling") public int slayerLvl = 30; @SerializedName("slayDragons") @UITab({"skilling", "slayer"} ) public boolean slayDragons = false; @SerializedName("slayWithWhip") @UITab({"skilling", "slayer"}) public boolean slayWithWhip = true; @SerializedName("prayerTarget") @UITab({"skilling", "prayer"}) public int prayerTarget = 60; @SerializedName("prayInPOH") @UITab({"skilling", "prayer"}) public boolean prayInPOH = true; @SerializedName("moneyLeftAfterMuling") public int moneyLeftAfterMuling = 1_000_000; @SerializedName("minLootValue") public int minLootValue = 1000; } results in: none in root: @SerializedName("hoursUntilMuleOff") @UITab("script") public int hoursUntilMuleOff = 12; @SerializedName("initalGP") @UITab("script") public int initalGP = 16_000_000; @SerializedName("slayerLvl") @UITab({"skilling", "slayer"}) public int slayerLvl = 30; @SerializedName("slayDragons") @UITab({"skilling", "slayer"} ) public boolean slayDragons = false; @SerializedName("slayWithWhip") @UITab({"skilling", "slayer"}) public boolean slayWithWhip = true; @SerializedName("prayerTarget") @UITab({"skilling", "prayer"}) public int prayerTarget = 60; @SerializedName("prayInPOH") @UITab({"skilling", "prayer"}) public boolean prayInPOH = true; @SerializedName("moneyLeftAfterMuling") @UITab("script") public int moneyLeftAfterMuling = 1_000_000; @SerializedName("minLootValue") @UITab("script") public int minLootValue = 1000; results in: hopefully its evident how this can be used from a quick script with only a couple of settings to a full blown aio with 10-20 settings per skill / activity without ever having to actually write and swing code and read about layouts for 15 hours and give yourself back pain some updates that are nice if you want to - remove requirement for serializedName and just use field name if its not ther - add an annotation that gives tooltips in the GuiOption component - anything to make it prettier contribute and yoink here:https://github.com/camelCaseDB/Reflective-GUI-Generator?tab=readme-ov-filehttps://github.com/Amoz3/Reflective-GUI-Generator Edited August 16 by camelCase yeeter, MaximusPrimo, TheStormer and 2 others 1 4 Link to comment Share on other sites More sharing options...
Hans Zimmer 19 Share Posted August 16 Wonderful camelCase 1 Link to comment Share on other sites More sharing options...
Articron 740 Share Posted August 16 But I love SWING wtf! camelCase 1 Link to comment Share on other sites More sharing options...
camelCase 271 Author Share Posted August 17 9 hours ago, Articron said: But I love SWING wtf! https://www.thetrevorproject.org/resources/article/support-for-self-harm-recovery/ Link to comment Share on other sites More sharing options...
duration 1 Share Posted August 17 Thanks @camelCase Implementation of ENUM using camelCase code. public enum WallSelection { WESTWALL, EASTWALL, AUTOHANDLE } //Prayer Settings @SerializedName("Select Wall") @UITab("Wall") public WallSelection testing = WallSelection.EASTWALL; As well as using @mr beautiful swing Function SwingUtilities.invokeLater(() -> { TabbedUI t = new TabbedUI(new Data()); t.addWindowListener(new WindowListener() { @Override public void windowOpened(WindowEvent e) { } @Override public void windowClosing(WindowEvent e) { // save Logger.info("window closing"); } @Override public void windowClosed(WindowEvent e) { } @Override public void windowIconified(WindowEvent e) { } @Override public void windowDeiconified(WindowEvent e) { } @Override public void windowActivated(WindowEvent e) { } @Override public void windowDeactivated(WindowEvent e) { } }); }); camelCase 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now