Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / classpath / javax / swing / plaf / basic / BasicProgressBarUI.java
blobd3674664d4ccc7229eab4da9f0ea08112bea24f3
1 /* BasicProgressBarUI.java --
2 Copyright (C) 2004, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath 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 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax.swing.plaf.basic;
41 import java.awt.Color;
42 import java.awt.Dimension;
43 import java.awt.Font;
44 import java.awt.FontMetrics;
45 import java.awt.Graphics;
46 import java.awt.Insets;
47 import java.awt.Point;
48 import java.awt.Rectangle;
49 import java.awt.Shape;
50 import java.awt.event.ActionEvent;
51 import java.awt.event.ActionListener;
52 import java.awt.event.ComponentAdapter;
53 import java.awt.event.ComponentEvent;
54 import java.awt.event.ComponentListener;
55 import java.beans.PropertyChangeEvent;
56 import java.beans.PropertyChangeListener;
58 import javax.swing.JComponent;
59 import javax.swing.JProgressBar;
60 import javax.swing.LookAndFeel;
61 import javax.swing.SwingConstants;
62 import javax.swing.SwingUtilities;
63 import javax.swing.Timer;
64 import javax.swing.UIManager;
65 import javax.swing.event.AncestorEvent;
66 import javax.swing.event.AncestorListener;
67 import javax.swing.event.ChangeEvent;
68 import javax.swing.event.ChangeListener;
69 import javax.swing.plaf.ComponentUI;
70 import javax.swing.plaf.ProgressBarUI;
72 /**
73 * The Basic Look and Feel UI delegate for the
74 * JProgressBar.
76 public class BasicProgressBarUI extends ProgressBarUI
78 /**
79 * A helper class that listens for ChangeEvents
80 * from the progressBar's model.
82 * @specnote Apparently this class was intended to be protected,
83 * but was made public by a compiler bug and is now
84 * public for compatibility.
86 public class ChangeHandler implements ChangeListener
88 /**
89 * Called every time the state of the model changes.
91 * @param e The ChangeEvent given by the model.
93 public void stateChanged(ChangeEvent e)
95 // Nothing to do but repaint.
96 progressBar.repaint();
101 * This helper class is used to listen for
102 * PropertyChangeEvents from the progressBar.
104 private class PropertyChangeHandler implements PropertyChangeListener
107 * Called every time the properties of the
108 * progressBar change.
110 * @param e The PropertyChangeEvent given by the progressBar.
112 public void propertyChange(PropertyChangeEvent e)
114 // Only need to listen for indeterminate changes.
115 // All other things are done on a repaint.
116 if (e.getPropertyName().equals("indeterminate"))
117 if (((Boolean) e.getNewValue()).booleanValue()
118 && progressBar.isShowing())
119 startAnimationTimer();
120 else
121 stopAnimationTimer();
126 * Receives notification when the progressbar is becoming visible or
127 * invisible and starts/stops the animation timer accordingly.
129 * @author Roman Kennke (kennke@aicas.com)
131 private class AncestorHandler implements AncestorListener
135 * Receives notification when the progressbar is becoming visible. This
136 * starts the animation timer if the progressbar is indeterminate.
138 * @param event the ancestor event
140 public void ancestorAdded(AncestorEvent event)
142 if (progressBar.isIndeterminate())
143 startAnimationTimer();
147 * Receives notification when the progressbar is becoming invisible. This
148 * stops the animation timer if the progressbar is indeterminate.
150 * @param event the ancestor event
152 public void ancestorRemoved(AncestorEvent event)
154 stopAnimationTimer();
158 * Receives notification when an ancestor has been moved. We don't need to
159 * do anything here.
161 public void ancestorMoved(AncestorEvent event)
163 // Nothing to do here.
169 * This helper class is used to listen for
170 * the animationTimer's intervals. On every interval,
171 * the bouncing box should move.
173 private class Animator implements ActionListener
176 * Called every time the animationTimer reaches
177 * its interval.
179 * @param e The ActionEvent given by the timer.
181 public void actionPerformed(ActionEvent e)
183 // Incrementing the animation index will cause
184 // a repaint.
185 incrementAnimationIndex();
190 * Receives notification when the size of the progress bar changes and
191 * invalidates the layout information for the box calculation in
192 * {@link BasicProgressBarUI#getBox(Rectangle)}.
194 * @author Roman Kennke (kennke@aicas.com)
196 private class ComponentHandler extends ComponentAdapter
199 * Receives notification when the size of the progress bar changes and
200 * invalidates the layout information for the box calculation in
201 * {@link BasicProgressBarUI#getBox}.
203 * @param e the component event
205 public void componentResized(ComponentEvent e)
207 boxDependent = -1;
208 boxIndependent = -1;
209 incr = -1;
214 * Holds the value of the bouncing box that is returned by {@link #getBox}.
216 * @since 1.5
218 protected Rectangle boxRect;
220 /** The timer used to move the bouncing box. */
221 private transient Timer animationTimer;
223 // The total number of frames must be an even number.
224 // The total number of frames is calculated from
225 // the cycleTime and repaintInterval given by
226 // the basic Look and Feel defaults.
228 // +-----------------------------------------------+
229 // | frame0 | frame1 | frame2 | frame 3 | frame 4 |
230 // | | frame7 | frame6 | frame 5 | |
231 // +-----------------------------------------------+
233 /** The current animation index. */
234 private transient int animationIndex;
236 /** The total number of frames.*/
237 private transient int numFrames;
239 /** The helper that moves the bouncing box. */
240 private transient Animator animation;
242 /** The helper that listens for property change events. */
243 private transient PropertyChangeHandler propertyListener;
245 /** The Listener for the model. */
246 protected ChangeListener changeListener;
248 /** The progressBar for this UI. */
249 protected JProgressBar progressBar;
253 * The size of the box returned by {@link #getBox} in the orientation
254 * direction of the progress bar. This is package private to avoid accessor
255 * method.
257 transient double boxDependent = - 1;
260 * The size of the box returned by {@link #getBox} against the orientation
261 * direction of the progress bar. This is package private to avoid accessor
262 * method.
264 transient int boxIndependent = - 1;
267 * The increment for box animation. This is package private to avoid accessor
268 * method.
270 transient double incr = -1;
272 /** The length of the cell. The cell is the painted part. */
273 private transient int cellLength;
275 /** The gap between cells. */
276 private transient int cellSpacing;
278 /** The color of the text when the bar is not over it.*/
279 private transient Color selectionBackground;
281 /** The color of the text when the bar is over it. */
282 private transient Color selectionForeground;
285 * Listens for notification when the component becomes showing and
286 * starts/stops the animation timer.
288 private AncestorListener ancestorListener;
291 * Listens for resize events on the progress bar and invalidates some
292 * layout info.
294 private ComponentListener componentListener;
297 * Creates a new BasicProgressBarUI object.
299 public BasicProgressBarUI()
301 super();
305 * Creates a new BasicProgressBarUI for the component.
307 * @param x The JComponent to create the UI for.
309 * @return A new BasicProgressBarUI.
311 public static ComponentUI createUI(JComponent x)
313 return new BasicProgressBarUI();
317 * This method returns the length of the bar (from the minimum)
318 * in pixels (or units that the Graphics object draws in) based
319 * on the progressBar's getPercentComplete() value.
321 * @param b The insets of the progressBar.
322 * @param width The width of the progressBar.
323 * @param height The height of the progressBar.
325 * @return The length of the bar that should be painted in pixels.
327 protected int getAmountFull(Insets b, int width, int height)
329 double percentDone = progressBar.getPercentComplete();
330 if (progressBar.getOrientation() == JProgressBar.HORIZONTAL)
331 return (int) (percentDone * (width - b.left - b.right));
332 else
333 return (int) (percentDone * (height - b.top - b.bottom));
337 * The current animation index.
339 * @return The current animation index.
341 protected int getAnimationIndex()
343 return animationIndex;
347 * This method returns the size and position of the bouncing box
348 * for the current animation index. It stores the values in the
349 * given rectangle and returns it. It returns null if no box should
350 * be drawn.
352 * @param r The bouncing box rectangle.
354 * @return The bouncing box rectangle.
356 protected Rectangle getBox(Rectangle r)
358 if (!progressBar.isIndeterminate())
359 return null;
360 if (r == null)
361 r = new Rectangle();
363 Rectangle vr = new Rectangle();
364 SwingUtilities.calculateInnerArea(progressBar, vr);
366 // Recalculate the metrics only when size of the progressbar has changed.
367 if (incr == -1 || boxDependent == -1 || boxIndependent == -1)
369 //numFrames has to be an even number as defined by spec.
370 int iterations = numFrames / 2;
371 if (progressBar.getOrientation() == JProgressBar.HORIZONTAL)
373 boxDependent = vr.width / 6.;
374 incr = ((double) (vr.width - boxDependent)) / (double) iterations;
375 boxIndependent = vr.height;
377 else
379 boxDependent = vr.height / 6.;
380 incr = ((double) (vr.height - boxDependent)) / (double) iterations;
381 boxIndependent = vr.width;
385 int index = getAnimationIndex();
386 if (animationIndex > (numFrames) / 2)
387 index = numFrames - getAnimationIndex();
389 if (progressBar.getOrientation() == JProgressBar.HORIZONTAL)
391 r.x = vr.x + (int) (incr * index);
392 r.y = vr.y;
393 r.width = (int) boxDependent;
394 r.height = (int) boxIndependent;
396 else
398 r.x = vr.x;
399 r.y = vr.height - (int) (incr * index) + vr.y - (int) boxDependent;
400 r.width = (int) boxIndependent;
401 r.height = (int) boxDependent;
403 return r;
407 * This method returns the length of the cells.
409 * @return The cell length.
411 protected int getCellLength()
413 return cellLength;
417 * This method returns the spacing between cells.
419 * @return The cell gap.
421 protected int getCellSpacing()
423 return cellSpacing;
427 * This method returns the maximum size of the JComponent.
428 * If it returns null, it is up to the LayoutManager
429 * to give it a size.
431 * @param c The component to find a maximum size for.
433 * @return The maximum size.
435 public Dimension getMaximumSize(JComponent c)
437 Insets insets = c.getInsets();
438 Dimension ret;
439 int orientation = progressBar.getOrientation();
440 if (orientation == JProgressBar.VERTICAL)
442 ret = getPreferredInnerVertical();
443 ret.height = Short.MAX_VALUE;
444 ret.width += insets.left + insets.right;
446 else
448 ret = getPreferredInnerHorizontal();
449 ret.width = Short.MAX_VALUE;
450 ret.height += insets.top + insets.bottom;
452 return ret;
456 * This method returns the minimum size of the JComponent.
457 * If it returns null, it is up to the LayoutManager to
458 * give it a size.
460 * @param c The component to find a minimum size for.
462 * @return The minimum size.
464 public Dimension getMinimumSize(JComponent c)
466 Insets insets = c.getInsets();
467 Dimension ret;
468 int orientation = progressBar.getOrientation();
469 if (orientation == JProgressBar.VERTICAL)
471 ret = getPreferredInnerVertical();
472 ret.height = 10;
473 ret.width += insets.left + insets.right;
475 else
477 ret = getPreferredInnerHorizontal();
478 ret.width = 10;
479 ret.height += insets.top + insets.bottom;
481 return ret;
485 * This method returns the preferred size of the inner
486 * rectangle (the bounds without the insets) if the
487 * progressBar is horizontal.
489 * @return The preferred size of the progressBar minus
490 * insets if it's horizontal.
492 protected Dimension getPreferredInnerHorizontal()
494 Font font = progressBar.getFont();
495 FontMetrics fm = progressBar.getFontMetrics(font);
497 int stringWidth = 0;
498 String str = progressBar.getString();
499 if (str != null)
500 stringWidth = fm.stringWidth(progressBar.getString());
501 Insets i = progressBar.getInsets();
502 int prefWidth = Math.max(200 - i.left - i.right, stringWidth);
504 int stringHeight = 0;
505 if (str != null)
506 stringHeight = fm.getHeight();
507 int prefHeight = Math.max(16 - i.top - i.bottom, stringHeight);
509 return new Dimension(prefWidth, prefHeight);
513 * This method returns the preferred size of the inner
514 * rectangle (the bounds without insets) if the
515 * progressBar is vertical.
517 * @return The preferred size of the progressBar minus
518 * insets if it's vertical.
520 protected Dimension getPreferredInnerVertical()
522 Font font = progressBar.getFont();
523 FontMetrics fm = progressBar.getFontMetrics(font);
525 int stringWidth = 0;
526 String str = progressBar.getString();
527 if (str != null)
528 stringWidth = fm.stringWidth(progressBar.getString());
529 Insets i = progressBar.getInsets();
530 int prefHeight = Math.max(200 - i.left - i.right, stringWidth);
532 int stringHeight = 0;
533 if (str != null)
534 stringHeight = fm.getHeight();
535 int prefWidth = Math.max(16 - i.top - i.bottom, stringHeight);
537 return new Dimension(prefWidth, prefHeight);
541 * This method returns the preferred size of the
542 * given JComponent. If it returns null, then it
543 * is up to the LayoutManager to give it a size.
545 * @param c The component to find the preferred size for.
547 * @return The preferred size of the component.
549 public Dimension getPreferredSize(JComponent c)
551 Insets insets = c.getInsets();
552 Dimension ret;
553 int orientation = progressBar.getOrientation();
554 if (orientation == JProgressBar.VERTICAL)
555 ret = getPreferredInnerVertical();
556 else
557 ret = getPreferredInnerHorizontal();
558 ret.width += insets.left + insets.right;
559 ret.height += insets.top + insets.bottom;
560 return ret;
564 * This method returns the Color that the text is shown in when the bar is
565 * not over the text.
567 * @return The color of the text when the bar is not over it.
569 protected Color getSelectionBackground()
571 return selectionBackground;
575 * This method returns the Color that the text is shown in when the bar is
576 * over the text.
578 * @return The color of the text when the bar is over it.
580 protected Color getSelectionForeground()
582 return selectionForeground;
586 * This method returns the point (the top left of the bounding box)
587 * where the text should be painted.
589 * @param g The Graphics object to measure FontMetrics with.
590 * @param progressString The string to paint.
591 * @param x The x coordinate of the overall bounds box.
592 * @param y The y coordinate of the overall bounds box.
593 * @param width The width of the overall bounds box.
594 * @param height The height of the overall bounds box.
596 * @return The top left of the bounding box where text should be painted.
598 protected Point getStringPlacement(Graphics g, String progressString, int x,
599 int y, int width, int height)
601 Rectangle tr = new Rectangle();
602 Rectangle vr = new Rectangle(x, y, width, height);
603 Rectangle ir = new Rectangle();
605 Font f = g.getFont();
606 FontMetrics fm = g.getFontMetrics(f);
608 SwingUtilities.layoutCompoundLabel(progressBar, fm, progressString, null,
609 SwingConstants.CENTER,
610 SwingConstants.CENTER,
611 SwingConstants.CENTER,
612 SwingConstants.CENTER, vr, ir, tr, 0);
613 return new Point(tr.x, tr.y);
617 * This method increments the animation index.
619 protected void incrementAnimationIndex()
621 animationIndex++;
622 //numFrames is like string length, it should be named numFrames or something
623 if (animationIndex >= numFrames)
624 animationIndex = 0;
625 progressBar.repaint();
629 * This method paints the progressBar. It delegates its responsibilities
630 * to paintDeterminate and paintIndeterminate.
632 * @param g The Graphics object to paint with.
633 * @param c The JComponent to paint.
635 public void paint(Graphics g, JComponent c)
637 if (! progressBar.isIndeterminate())
638 paintDeterminate(g, c);
639 else
640 paintIndeterminate(g, c);
644 * This method is called if the painting to be done is
645 * for a determinate progressBar.
647 * @param g The Graphics object to paint with.
648 * @param c The JComponent to paint.
650 protected void paintDeterminate(Graphics g, JComponent c)
652 Color saved = g.getColor();
653 int space = getCellSpacing();
654 int len = getCellLength();
655 int max = progressBar.getMaximum();
656 int min = progressBar.getMinimum();
657 int value = progressBar.getValue();
659 Rectangle vr = SwingUtilities.calculateInnerArea(c, new Rectangle());
660 Rectangle or = progressBar.getBounds();
661 Insets insets = c.getInsets();
663 int amountFull = getAmountFull(insets, or.width, or.height);
665 if (progressBar.getOrientation() == JProgressBar.HORIZONTAL)
667 g.setColor(c.getForeground());
668 g.fillRect(vr.x, vr.y, amountFull, vr.height);
670 else
672 g.setColor(c.getForeground());
673 g.fillRect(vr.x, vr.y + vr.height - amountFull, vr.width, amountFull);
676 if (progressBar.isStringPainted() && !progressBar.getString().equals(""))
677 paintString(g, 0, 0, or.width, or.height, amountFull, insets);
678 g.setColor(saved);
682 * This method is called if the painting to be done is for
683 * an indeterminate progressBar.
685 * @param g The Graphics object to paint with.
686 * @param c The JComponent to paint.
688 protected void paintIndeterminate(Graphics g, JComponent c)
690 //need to paint the box at it's current position. no text is painted since
691 //all we're doing is bouncing back and forth
692 Color saved = g.getColor();
693 Insets insets = c.getInsets();
695 Rectangle or = c.getBounds();
696 Rectangle vr = new Rectangle();
697 SwingUtilities.calculateInnerArea(c, vr);
699 g.setColor(c.getBackground());
700 g.fillRect(vr.x, vr.y, vr.width, vr.height);
702 boxRect = getBox(boxRect);
704 g.setColor(c.getForeground());
705 g.fillRect(boxRect.x, boxRect.y, boxRect.width, boxRect.height);
707 if (progressBar.isStringPainted() && !progressBar.getString().equals(""))
708 paintString(g, 0, 0, or.width, or.height,
709 getAmountFull(insets, or.width, or.height), insets);
711 g.setColor(saved);
715 * This method paints the string for the progressBar.
717 * @param g The Graphics object to paint with.
718 * @param x The x coordinate of the progressBar.
719 * @param y The y coordinate of the progressBar.
720 * @param width The width of the progressBar.
721 * @param height The height of the progressBar.
722 * @param amountFull The amount of the progressBar that has its bar filled.
723 * @param b The insets of the progressBar.
725 protected void paintString(Graphics g, int x, int y, int width, int height,
726 int amountFull, Insets b)
728 // FIXME: We do not support vertical text painting because Java2D is needed
729 // for this.
730 if (progressBar.getOrientation() == JProgressBar.VERTICAL)
731 return;
733 // We want to place in the exact center of the bar.
734 Point placement = getStringPlacement(g, progressBar.getString(),
735 x + b.left, y + b.top,
736 width - b.left - b.right,
737 height - b.top - b.bottom);
739 Color savedColor = g.getColor();
740 Shape savedClip = g.getClip();
741 FontMetrics fm = g.getFontMetrics(progressBar.getFont());
742 int full = getAmountFull(b, width, height);
743 String str = progressBar.getString();
745 // We draw this string two times with different clips so that the text
746 // over the filled area is painted with selectionForeground and over
747 // the clear area with selectionBackground.
748 g.setColor(getSelectionForeground());
749 g.setClip(0, 0, full + b.left, height);
750 g.drawString(str, placement.x, placement.y + fm.getAscent());
751 g.setColor(getSelectionBackground());
752 g.setClip(full + b.left, 0, width - full, height);
753 g.drawString(str, placement.x, placement.y + fm.getAscent());
754 g.setClip(savedClip);
755 g.setColor(savedColor);
759 * This method sets the current animation index. If the index
760 * is greater than the number of frames, it resets to 0.
762 * @param newValue The new animation index.
764 protected void setAnimationIndex(int newValue)
766 animationIndex = (newValue <= numFrames) ? newValue : 0;
767 progressBar.repaint();
771 * This method sets the cell length.
773 * @param cellLen The cell length.
775 protected void setCellLength(int cellLen)
777 cellLength = cellLen;
781 * This method sets the cell spacing.
783 * @param cellSpace The cell spacing.
785 protected void setCellSpacing(int cellSpace)
787 cellSpacing = cellSpace;
791 * This method starts the animation timer. It is called
792 * when the propertyChangeListener detects that the progressBar
793 * has changed to indeterminate mode.
795 * @since 1.4
797 protected void startAnimationTimer()
799 if (animationTimer != null)
800 animationTimer.start();
804 * This method stops the animation timer. It is called when
805 * the propertyChangeListener detects that the progressBar
806 * has changed to determinate mode.
808 * @since 1.4
810 protected void stopAnimationTimer()
812 if (animationTimer != null)
813 animationTimer.stop();
814 setAnimationIndex(0);
818 * This method changes the settings for the progressBar to
819 * the defaults provided by the current Look and Feel.
821 protected void installDefaults()
823 LookAndFeel.installColorsAndFont(progressBar, "ProgressBar.background",
824 "ProgressBar.foreground",
825 "ProgressBar.font");
826 LookAndFeel.installBorder(progressBar, "ProgressBar.border");
827 progressBar.setOpaque(true);
829 selectionForeground = UIManager.getColor("ProgressBar.selectionForeground");
830 selectionBackground = UIManager.getColor("ProgressBar.selectionBackground");
831 cellLength = UIManager.getInt("ProgressBar.cellLength");
832 cellSpacing = UIManager.getInt("ProgressBar.cellSpacing");
834 int repaintInterval = UIManager.getInt("ProgressBar.repaintInterval");
835 int cycleTime = UIManager.getInt("ProgressBar.cycleTime");
837 if (cycleTime % repaintInterval != 0
838 && (cycleTime / repaintInterval) % 2 != 0)
840 int div = (cycleTime / repaintInterval) + 2;
841 div /= 2;
842 div *= 2;
843 cycleTime = div * repaintInterval;
845 setAnimationIndex(0);
846 numFrames = cycleTime / repaintInterval;
847 animationTimer.setDelay(repaintInterval);
851 * The method uninstalls any defaults that were
852 * set by the current Look and Feel.
854 protected void uninstallDefaults()
856 progressBar.setFont(null);
857 progressBar.setForeground(null);
858 progressBar.setBackground(null);
860 selectionForeground = null;
861 selectionBackground = null;
865 * This method registers listeners to all the
866 * components that this UI delegate needs to listen to.
868 protected void installListeners()
870 changeListener = new ChangeHandler();
871 propertyListener = new PropertyChangeHandler();
872 animation = new Animator();
874 progressBar.addChangeListener(changeListener);
875 progressBar.addPropertyChangeListener(propertyListener);
876 animationTimer.addActionListener(animation);
878 ancestorListener = new AncestorHandler();
879 progressBar.addAncestorListener(ancestorListener);
881 componentListener = new ComponentHandler();
882 progressBar.addComponentListener(componentListener);
886 * This method unregisters listeners to all the
887 * components that were listened to.
889 protected void uninstallListeners()
891 progressBar.removeChangeListener(changeListener);
892 progressBar.removePropertyChangeListener(propertyListener);
893 animationTimer.removeActionListener(animation);
895 changeListener = null;
896 propertyListener = null;
897 animation = null;
899 if (ancestorListener != null)
900 progressBar.removeAncestorListener(ancestorListener);
901 ancestorListener = null;
903 if (componentListener != null)
904 progressBar.removeComponentListener(componentListener);
905 componentListener = null;
909 * This method installs the UI for the given JComponent.
910 * This includes setting up defaults and listeners as
911 * well as initializing any values or objects that
912 * the UI may need.
914 * @param c The JComponent that is having this UI installed.
916 public void installUI(JComponent c)
918 super.installUI(c);
919 if (c instanceof JProgressBar)
921 progressBar = (JProgressBar) c;
923 animationTimer = new Timer(200, null);
924 animationTimer.setRepeats(true);
926 installDefaults();
927 installListeners();
929 if (progressBar.isIndeterminate())
930 startAnimationTimer();
934 * This method removes the UI for the given JComponent.
935 * This includes removing any listeners or defaults
936 * that the installUI may have set up.
938 * @param c The JComponent that is having this UI uninstalled.
940 public void uninstallUI(JComponent c)
942 super.uninstallUI(c);
943 uninstallListeners();
944 uninstallDefaults();
946 animationTimer = null;
947 progressBar = null;