Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
InfiniteWaitUI |
|
| 1.25;1.25 |
1 | package org.jtheque.core.managers.view.impl.components; | |
2 | ||
3 | import org.jdesktop.jxlayer.JXLayer; | |
4 | import org.jdesktop.jxlayer.plaf.BufferedLayerUI; | |
5 | import org.jtheque.utils.ui.SizeTracker; | |
6 | ||
7 | import javax.swing.JComponent; | |
8 | import java.awt.Graphics2D; | |
9 | ||
10 | /* | |
11 | * This file is part of JTheque. | |
12 | * | |
13 | * JTheque is free software: you can redistribute it and/or modify | |
14 | * it under the terms of the GNU General Public License as published by | |
15 | * the Free Software Foundation, either version 3 of the License. | |
16 | * | |
17 | * JTheque is distributed in the hope that it will be useful, | |
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | * GNU General Public License for more details. | |
21 | * | |
22 | * You should have received a copy of the GNU General Public License | |
23 | * along with JTheque. If not, see <http://www.gnu.org/licenses/>. | |
24 | */ | |
25 | ||
26 | /** | |
27 | * An UI to make a JXLayer waiting. | |
28 | * | |
29 | * @author Baptiste Wicht | |
30 | */ | |
31 | public final class InfiniteWaitUI extends BufferedLayerUI<JComponent> { | |
32 | private final WaitFigure waitFigure; | |
33 | ||
34 | private final SizeTracker tracker; | |
35 | ||
36 | /** | |
37 | * Construct a new <code>InfiniteWaitUI</code>. | |
38 | * | |
39 | * @param content The content pane of the view. | |
40 | */ | |
41 | public InfiniteWaitUI(JXLayer<JComponent> content) { | |
42 | 0 | super(); |
43 | ||
44 | 0 | waitFigure = new InfiniteWaitFigure(); |
45 | 0 | waitFigure.setGlassPane(content); |
46 | 0 | waitFigure.init(); |
47 | ||
48 | 0 | tracker = new SizeTracker(content); |
49 | 0 | } |
50 | ||
51 | @Override | |
52 | public void paintLayer(Graphics2D g2, JXLayer<? extends JComponent> layer) { | |
53 | 0 | if(tracker.hasSizeChanged()){ |
54 | 0 | tracker.updateSize(); |
55 | 0 | waitFigure.setBounds(layer.getWidth(), layer.getHeight()); |
56 | } | |
57 | ||
58 | 0 | waitFigure.paint(g2); |
59 | 0 | } |
60 | ||
61 | /** | |
62 | * Start the animation. | |
63 | */ | |
64 | public void start() { | |
65 | 0 | setAlpha(1.0f); |
66 | 0 | waitFigure.start(); |
67 | 0 | } |
68 | ||
69 | /** | |
70 | * Stop the animation. | |
71 | */ | |
72 | public void stop() { | |
73 | 0 | setAlpha(0.0f); |
74 | 0 | waitFigure.stop(); |
75 | 0 | } |
76 | } |