| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| ExtendedGlassPane |
|
| 1.1428571428571428;1.143 |
| 1 | package org.jtheque.core.managers.view.impl.components; | |
| 2 | ||
| 3 | /* | |
| 4 | * This file is part of JTheque. | |
| 5 | * | |
| 6 | * JTheque is free software: you can redistribute it and/or modify | |
| 7 | * it under the terms of the GNU General Public License as published by | |
| 8 | * the Free Software Foundation, either version 3 of the License. | |
| 9 | * | |
| 10 | * JTheque is distributed in the hope that it will be useful, | |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 13 | * GNU General Public License for more details. | |
| 14 | * | |
| 15 | * You should have received a copy of the GNU General Public License | |
| 16 | * along with JTheque. If not, see <http://www.gnu.org/licenses/>. | |
| 17 | */ | |
| 18 | ||
| 19 | import org.jtheque.core.managers.view.able.IWindowView; | |
| 20 | ||
| 21 | import javax.swing.JPanel; | |
| 22 | import java.awt.Cursor; | |
| 23 | import java.awt.Graphics; | |
| 24 | ||
| 25 | /** | |
| 26 | * An Extended Glass Pane. It's a glass pane on which we can display an wait animation. | |
| 27 | * | |
| 28 | * @author Baptiste Wicht | |
| 29 | */ | |
| 30 | public final class ExtendedGlassPane extends JPanel { | |
| 31 | private WaitFigure waitFigure; | |
| 32 | ||
| 33 | private boolean wait; | |
| 34 | ||
| 35 | private final IWindowView frame; | |
| 36 | ||
| 37 | /** | |
| 38 | * Construct a new glass pane associated to a frame. | |
| 39 | * | |
| 40 | * @param frame The parent frame | |
| 41 | */ | |
| 42 | public ExtendedGlassPane(IWindowView frame) { | |
| 43 | 0 | super(); |
| 44 | ||
| 45 | 0 | this.frame = frame; |
| 46 | ||
| 47 | 0 | setOpaque(false); |
| 48 | 0 | } |
| 49 | ||
| 50 | /** | |
| 51 | * Start the wait. | |
| 52 | */ | |
| 53 | public void startWait() { | |
| 54 | 0 | wait = true; |
| 55 | 0 | setVisible(true); |
| 56 | 0 | setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); |
| 57 | 0 | waitFigure.start(); |
| 58 | 0 | } |
| 59 | ||
| 60 | /** | |
| 61 | * Stop the wait. | |
| 62 | */ | |
| 63 | public void stopWait() { | |
| 64 | 0 | wait = false; |
| 65 | 0 | setVisible(false); |
| 66 | 0 | setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
| 67 | 0 | waitFigure.stop(); |
| 68 | 0 | } |
| 69 | ||
| 70 | @Override | |
| 71 | public void setBounds(int x, int y, int width, int height) { | |
| 72 | 0 | super.setBounds(x, y, width, height); |
| 73 | ||
| 74 | 0 | waitFigure.setBounds(width, height); |
| 75 | 0 | } |
| 76 | ||
| 77 | @Override | |
| 78 | protected void paintComponent(Graphics graphics) { | |
| 79 | 0 | if (wait) { |
| 80 | 0 | waitFigure.paint(graphics); |
| 81 | } | |
| 82 | 0 | } |
| 83 | ||
| 84 | /** | |
| 85 | * Set the wait figure. | |
| 86 | * | |
| 87 | * @param waitFigure The new wait figure | |
| 88 | */ | |
| 89 | public void setWaitFigure(WaitFigure waitFigure) { | |
| 90 | 0 | this.waitFigure = waitFigure; |
| 91 | 0 | waitFigure.setGlassPane(this); |
| 92 | 0 | waitFigure.init(); |
| 93 | 0 | } |
| 94 | ||
| 95 | /** | |
| 96 | * Get the window of the glass pane. | |
| 97 | * | |
| 98 | * @return The window. | |
| 99 | */ | |
| 100 | public IWindowView getWindow() { | |
| 101 | 0 | return frame; |
| 102 | } | |
| 103 | } |