Page 1 of 1

Why Forge Swing GUI is currently hold with duct tape

PostPosted: 12 Jul 2011, 08:45
by Snacko
Swing is single threaded, this means every creation / manipulation of Swing objects has to be done on the even dispatch thread.
This has a heavy implication that you dont bog down the even dispatch thread with heavy computation or the GUI wont update. The exact example of this done wrong is the progress bar which doesn't update if you move it around, but just smears.

Currently as a duct tape fix the whole Forge code runs on the even dispatch queue!
To disable the tape fix you have to comment the code in Gui_NewGame.java
Code: Select all
SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    AllZone.setComputer(new ComputerAI_Input(new ComputerAI_General()));
                    new Gui_NewGame();
                }
            });
And only leave the two lines inside or run. For a better effect you can enable one of Substance skins which will enable the checking of proper Swing usage. If you're brave enough, you now should see couple hundred exceptions and Forge GUI might not work at all at some points ;)

The good course of action would be to fix this at some point. I'm just leaving it here for anyone wanting to do any GUI work on Forge.

You can read more here :
basically you need to use invokeLater or SwingWorker
http://www.javaworld.com/javaworld/jw-0 ... tml?page=1

Re: Why Forge Swing GUI is currently hold with duct tape

PostPosted: 12 Jul 2011, 12:02
by friarsol
Snacko wrote:The good course of action would be to fix this at some point. I'm just leaving it here for anyone wanting to do any GUI work on Forge.
Thanks for the Notes Snacko, but I slightly disagree. The good course of action is to nuke it all and start from scratch. Our UI needs a major makeover.

Re: Why Forge Swing GUI is currently hold with duct tape

PostPosted: 15 Jul 2011, 18:07
by Braids
if we could implement more of the UI in terms of (a list of?) decisions you or the AI can make at this moment and the effects of each of these decisions, this would greatly help minimax.

do we need a separate View layer? (as in Model View Controller)

Re: Why Forge Swing GUI is currently hold with duct tape

PostPosted: 17 Aug 2011, 19:03
by Braids
i'm rewriting some of the UI startup code. thanks for the pointer, Snacko. i should be able to avoid the pitfall you describe during the execution of my new code. well, it's a start. better than nothing.

@Snacko, could you review my code once i've committed it? if i don't hear from you, i'll try to PM you after the commit.

Re: Why Forge Swing GUI is currently hold with duct tape

PostPosted: 17 Aug 2011, 21:52
by Snacko
Pm me after commit as I don't follow commits very closely.