~ubuntu-branches/ubuntu/precise/triplea/precise

« back to all changes in this revision

Viewing changes to src/games/strategy/engine/framework/ui/background/WaitWindow.java

  • Committer: Package Import Robot
  • Author(s): Scott Howard
  • Date: 2011-11-11 21:40:11 UTC
  • Revision ID: package-import@ubuntu.com-20111111214011-sehf2rwat36o2xqf
Tags: upstream-1.3.2.2
ImportĀ upstreamĀ versionĀ 1.3.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package games.strategy.engine.framework.ui.background;
 
2
 
 
3
import java.awt.*;
 
4
import java.util.*;
 
5
import java.util.Timer;
 
6
 
 
7
import javax.swing.*;
 
8
import javax.swing.border.*;
 
9
 
 
10
public class WaitWindow extends JWindow
 
11
{
 
12
 
 
13
    private final Object m_mutex = new Object();
 
14
    private Timer m_timer = new Timer();
 
15
 
 
16
 
 
17
    public WaitWindow(String waitMessage)
 
18
    {
 
19
        // super("Game Loading, Please wait");
 
20
        // setIconImage(GameRunner.getGameIcon(this));
 
21
        setSize(200, 80);
 
22
 
 
23
        WaitPanel mainPanel = new WaitPanel(waitMessage);
 
24
 
 
25
        setLocationRelativeTo(null);
 
26
        // setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
 
27
 
 
28
        mainPanel.setBorder(new LineBorder(Color.BLACK));
 
29
 
 
30
        setLayout(new BorderLayout());
 
31
        add(mainPanel, BorderLayout.CENTER);
 
32
    }
 
33
 
 
34
    public void showWait()
 
35
    {
 
36
        TimerTask task = new TimerTask()
 
37
        {
 
38
 
 
39
            @Override
 
40
            public void run()
 
41
            {
 
42
                SwingUtilities.invokeLater(new Runnable()
 
43
                {
 
44
                    public void run()
 
45
                    {
 
46
                        toFront();
 
47
                    }
 
48
                }
 
49
 
 
50
                );
 
51
 
 
52
            }
 
53
 
 
54
        };
 
55
 
 
56
        synchronized(m_mutex)
 
57
        {
 
58
            if(m_timer != null)
 
59
                m_timer.schedule(task, 15, 15);
 
60
        }
 
61
 
 
62
    }
 
63
 
 
64
    public void doneWait()
 
65
    {
 
66
        synchronized(m_mutex)
 
67
        {
 
68
            if(m_timer != null)
 
69
            {
 
70
                m_timer.cancel();
 
71
                m_timer = null;
 
72
            }
 
73
        }
 
74
 
 
75
        SwingUtilities.invokeLater(new Runnable()
 
76
        {
 
77
 
 
78
            public void run()
 
79
            {
 
80
 
 
81
                setVisible(false);
 
82
                removeAll();
 
83
                dispose();
 
84
 
 
85
            }
 
86
        });
 
87
 
 
88
    }
 
89
 
 
90
    public static void main(String[] args)
 
91
    {
 
92
 
 
93
        SwingUtilities.invokeLater(new Runnable()
 
94
        {
 
95
 
 
96
            public void run()
 
97
            {
 
98
                final WaitWindow window = new WaitWindow("Loading game, please wait.");
 
99
                window.setVisible(true);
 
100
 
 
101
                window.showWait();
 
102
 
 
103
            }
 
104
 
 
105
        });
 
106
 
 
107
    }
 
108
 
 
109
}