Empyreus / lanterna

Automatically exported from code.google.com/p/lanterna
GNU Lesser General Public License v3.0
0 stars 0 forks source link

GUIScreen.runInEventThread(.... guiScreen.showWindow() ... ) blocks #82

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
If you call GUIScreen.showWindow() inside a Action in 
GUIScreen.runInEventThread(...), the UI thread gets stuck.

This Example reproduces the issue in isolation:

import java.util.concurrent.TimeUnit;

import com.googlecode.lanterna.TerminalFacade;
import com.googlecode.lanterna.gui.GUIScreen.Position;
import com.googlecode.lanterna.gui.dialog.WaitingDialog;

public class SimpleController
{

    public static void main(String[] args) throws InterruptedException
    {
        // Construct the screen
        final GUIScreen guiScreen = TerminalFacade.createGUIScreen();
        guiScreen.getScreen().startScreen();

        final Window main = new Window("Main");
        final WaitingDialog waitingDialog = new WaitingDialog("Loading...", "Standby");

        // Spawn the main window in a own thread. Otherwise our Controller blocks.
        new Thread(new Runnable() {
            @Override
            public void run()
            {
                guiScreen.showWindow(main, Position.FULL_SCREEN);
            }
        }).start();

        // Show the waiting popup. For this we can use the event thread (i thought)
        guiScreen.runInEventThread(new Action() {

            @Override
            public void doAction()
            {
                guiScreen.showWindow(waitingDialog);
            }
        });

        // Here we simulate heave business logic :)
        TimeUnit.SECONDS.sleep(2);

        // loading is done. close the popup now.
        System.out.println("Close loading popup");

        waitingDialog.close();
        guiScreen.invalidate();

        // this code will never reached.
    }
}

It does the following:

1. Controller initilizes the GUIScreen
2. Then it shows the main window
3. After the main window is created, the Waiting window should become visible
Now It takes some time (in this example 2 seconds)
4. Finally, after the "heavy calculation", the Controller should hide the 
Waiting window somehow.

Best Regards,
Christian.

Original issue reported on code.google.com by cschneid...@gmail.com on 12 Aug 2013 at 5:35

GoogleCodeExporter commented 9 years ago
Yep, that's a bug. Fixed now on 2.1.x branch, I'll make a proper release 
tomorrow.

Original comment by mab...@gmail.com on 21 Aug 2013 at 1:50

GoogleCodeExporter commented 9 years ago
2.1.6 has been released.

Original comment by mab...@gmail.com on 22 Aug 2013 at 2:35