Can components created by JavaSwingBuilder reference other Yaml files?

141 Views Asked by At

Typically when using JavaBuilder1 you can define a new component thusly:

Yaml myFrame.yaml:

JFrame(name=frame, title=frame.title, size=packed, defaultCloseOperation=exitOnClose):
    - JPanel(name=panel1, tabTitle=tab.panel1Name):
        -JTextArea(name=textArea1)
    - JPanel(name=panel2, tabTitle=tab.panel2Name):
        -JTextArea(name=textArea2)
    - JPanel(name=panel3, tabTitle=tab.panel3Name):
        -JTextArea(name=textArea3)

Java myFrame.java:

public class MyFrame extends JFrame {
    private BuildResult result = SwingJavaBuilder.build(this);
}

JavaBuilders knows what to load by the file name. Is there a way to get JavaBuilders to load another set of files called panel1...panel3 depending on the component name? This would be so one part of my application can write the yaml files out and then I can 'Hot Deploy' them when my JFrame is built (with private BuildResult result = SwingJavaBuilder.build(this);)


My intention is to read a directory looking for a file/set of files that might read like so:

my.dir.panel1=available
my.dir.panel1.textArea1=available
my.dir.panel1.textArea1.default=Declarative GUIs!
my.dir.panel1.textArea2=unavailable
my.dir.panel2=available
my.dir.panel2.textArea1=available
my.dir.panel3=available
my.dir.panel3.textArea1=available
my.dir.panel4=unavailable
my.dir.panel4.textArea1=unavailable

And then use that to populate components in Swing. I can write out the Yaml files programmatically with snakeYaml dependant on what is 'available' in the above properties file but if I can avoid rewriting the JFrame section (which may contain a variety of other components that won't change) in the Yaml file that would be ideal.

The only other way I can think of this is to have multiple results created in Java like so

public class MyFrame extends JFrame {
    private BuildResult frankenResult = SwingJavaBuilder.build(this);
    private BuildResult subReult1 = SwingJavaBuilder.build(new MyPanel());

    JFrame myFrame = (JFrame)result.get("myFrame");
    JPanel myPanel = (JPanel)result.get("panel1");
    myFrame.add(myPanel);
}

But thinking about it I'm not certain I can make this call SwingJavaBuilder.build(new MyPanel());

So how can I create subsets of Components in a separate yaml file and then reference them in a main Yaml file?

1: GitHub Repo

0

There are 0 best solutions below