/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
public class AquaProgressBarUI extends ProgressBarUI implements ChangeListener, PropertyChangeListener, AncestorListener, Sizeable {
private static final boolean ADJUSTTIMER = true;
protected static final RecyclableSingleton<SizeDescriptor> sizeDescriptor = new RecyclableSingleton<SizeDescriptor>() {
protected SizeDescriptor getInstance() {
public SizeVariant deriveSmall(final SizeVariant v) { v.alterMinSize(0, -6); return super.deriveSmall(v); }
};
}
};
return sizeDescriptor.get();
}
protected boolean isAnimating;
protected boolean isCircular;
protected final AquaPainter<ValueState> painter = AquaPainter.create(JRSUIStateFactory.getProgressBar());
return new AquaProgressBarUI();
}
protected AquaProgressBarUI() { }
progressBar = (JProgressBar)c;
}
progressBar = null;
}
protected void installDefaults() {
progressBar.setOpaque(false);
LookAndFeel.installColorsAndFont(progressBar, "ProgressBar.background", "ProgressBar.foreground", "ProgressBar.font");
}
protected void uninstallDefaults() {
}
protected void installListeners() {
progressBar.addPropertyChangeListener(this); // Listen for changes between determinate and indeterminate state
progressBar.addAncestorListener(this);
}
protected void uninstallListeners() {
progressBar.removeChangeListener(this);
}
}
if (!progressBar.isIndeterminate()) return;
// start the animation thread
}
}
}
// listen for Ancestor events to stop our timer when we are no longer visible
// <rdar://problem/5405035> JProgressBar: UI in Aqua look and feel causes memory leaks
}
if (!progressBar.isIndeterminate()) return;
}
revalidateAnimationTimers(); // revalidate to turn on/off timers when values change
if (progressBar.isIndeterminate()) {
if (isCircular) {
return;
}
paint(g);
return;
}
paint(g);
}
}
// this is questionable. We may want the insets to mean something different.
}
}
}
protected void paintString(final Graphics g, final int x, final int y, final int width, final int height) {
if (!(g instanceof Graphics2D)) return;
if (isHorizontal()) {
} else { // VERTICAL
// We rotate it -90 degrees, then translate it down since we are going to be bottom up.
// 0,0 is now the bottom left of the viewable area, so we just draw our image at
// the render location since that calculation knows about rotation.
}
}
/**
* Designate the place where the progress string will be painted. This implementation places it at the center of the
* progress bar (in both x and y). Override this if you want to right, left, top, or bottom align the progress
* string or if you need to nudge it around for any reason.
*/
protected Point getStringPlacement(final Graphics g, final String progressString, int x, int y, int width, int height) {
if (!isHorizontal()) {
// Calculate the location for the rotated text in real component coordinates.
// swapping x & y and width & height
final int oldX = x;
x = y;
y = oldX;
}
return new Point(x + Math.round(width / 2 - stringWidth / 2), y + ((height + fontSizer.getAscent() - fontSizer.getLeading() - fontSizer.getDescent()) / 2) - 1);
}
}
if (isCircular) {
return getCircularPreferredSize();
}
final Dimension size = isHorizontal() ? getPreferredHorizontalSize(metrics) : getPreferredVerticalSize(metrics);
return size;
}
// Ensure that the progress string will fit
}
// This uses both Height and Descent to be sure that
// there is more than enough room in the progress bar
// for everything.
// This does have a strange dependency on
// getStringPlacememnt() in a funny way.
}
return size;
}
// Ensure that the progress string will fit.
}
// This is also for completeness.
}
return size;
}
if (isCircular) {
return getCircularPreferredSize();
}
// The Minimum size for this component is 10.
// The rationale here is that there should be at least one pixel per 10 percent.
if (isHorizontal()) {
} else {
}
return pref;
}
if (isCircular) {
return getCircularPreferredSize();
}
if (isHorizontal()) {
} else {
}
return pref;
}
painter.state.set(sizeVariant = size == Size.MINI ? Size.SMALL : sizeVariant); // CUI doesn't support mini progress bars right now
}
protected void startAnimationTimer() {
isAnimating = true;
}
protected void stopAnimationTimer() {
isAnimating = false;
}
if (isCircular) {
}
return fUpdateArea;
}
int x = 0;
int y = 0;
final int maxHeight = getMaxProgressBarHeight();
if (isHorizontal()) {
y += excessHeight / 2;
} else {
x += excessHeight / 2;
}
return fUpdateArea;
}
protected int getMaxProgressBarHeight() {
}
protected boolean isHorizontal() {
}
protected void revalidateAnimationTimers() {
if (progressBar.isIndeterminate()) return;
if (!isAnimating) {
startAnimationTimer(); // only starts if supposed to!
return;
}
}
}
protected void repaint() {
if (repaintRect == null) {
return;
}
}
private int repaintInterval;
public Animator() {
// Make sure repaintInterval is reasonable.
}
protected void start() {
lastCall = 0;
} else {
}
if (ADJUSTTIMER) {
timer.setRepeats(false);
timer.setCoalesce(false);
}
}
protected void stop() {
}
if (!ADJUSTTIMER) {
repaint();
return;
}
if (lastCall > 0) {
// adjust nextDelay
if (nextDelay < MINIMUM_DELAY) {
}
}
repaint();
}
}
}