| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| SizeTracker |
|
| 1.3333333333333333;1.333 |
| 1 | package org.jtheque.utils.ui; | |
| 2 | ||
| 3 | import javax.swing.JComponent; | |
| 4 | ||
| 5 | /* | |
| 6 | * This file is part of JTheque. | |
| 7 | * | |
| 8 | * JTheque is free software: you can redistribute it and/or modify | |
| 9 | * it under the terms of the GNU General Public License as published by | |
| 10 | * the Free Software Foundation, either version 3 of the License. | |
| 11 | * | |
| 12 | * JTheque is distributed in the hope that it will be useful, | |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 | * GNU General Public License for more details. | |
| 16 | * | |
| 17 | * You should have received a copy of the GNU General Public License | |
| 18 | * along with JTheque. If not, see <http://www.gnu.org/licenses/>. | |
| 19 | */ | |
| 20 | ||
| 21 | /** | |
| 22 | * A tracker for the size of a <code>JComponent</code> | |
| 23 | * | |
| 24 | * @author Baptiste Wicht | |
| 25 | */ | |
| 26 | public final class SizeTracker { | |
| 27 | 0 | private int width = -1; |
| 28 | 0 | private int height = -1; |
| 29 | ||
| 30 | private final JComponent component; | |
| 31 | ||
| 32 | /** | |
| 33 | * Construct a new SizeTracker. | |
| 34 | * | |
| 35 | * @param c The component to track the sizes. | |
| 36 | */ | |
| 37 | public SizeTracker(JComponent c) { | |
| 38 | 0 | super(); |
| 39 | ||
| 40 | 0 | component = c; |
| 41 | 0 | } |
| 42 | ||
| 43 | /** | |
| 44 | * Update the cached size. | |
| 45 | */ | |
| 46 | public void updateSize() { | |
| 47 | 0 | width = component.getWidth(); |
| 48 | 0 | height = component.getHeight(); |
| 49 | 0 | } |
| 50 | ||
| 51 | /** | |
| 52 | * Indicate if the size has changed from the last update. | |
| 53 | * | |
| 54 | * @return <code>true</code> if the size has changed else <code>false</code>. | |
| 55 | */ | |
| 56 | public boolean hasSizeChanged() { | |
| 57 | 0 | return width != component.getWidth() || height != component.getHeight(); |
| 58 | } | |
| 59 | } |