Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/jext/gui/JextProgressBarUI.java


1   /*
2    * 17:36:02 09/09/00
3    *
4    * JextProgressBarUI.java - A new UI for progress bar
5    * Copyright (C) 2000 Romain Guy
6    * romain.guy@jext.org
7    * www.jext.org
8    *
9    * This program is free software; you can redistribute it and/or
10   * modify it under the terms of the GNU General Public License
11   * as published by the Free Software Foundation; either version 2
12   * of the License, or any later version.
13   *
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   *
19   * You should have received a copy of the GNU General Public License
20   * along with this program; if not, write to the Free Software
21   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22   */
23  
24  package org.jext.gui;
25  
26  import java.awt.Color;
27  import java.awt.Insets;
28  import java.awt.Graphics;
29  import java.awt.Graphics2D;
30  import java.awt.GradientPaint;
31  import java.awt.Rectangle;
32  
33  import javax.swing.JComponent;
34  import javax.swing.UIManager;
35  import javax.swing.plaf.ComponentUI;
36  
37  public class JextProgressBarUI extends javax.swing.plaf.basic.BasicProgressBarUI
38  {
39    private static final Color START = new Color(38, 92, 147);
40    private static final Color END = new Color(146, 173, 201);
41  
42    public static ComponentUI createUI(JComponent c)
43    {
44      return new JextProgressBarUI();
45    }
46  
47    public void paint(Graphics g, JComponent c)
48    {
49      Insets b = progressBar.getInsets();
50      int barRectX = b.left;
51      int barRectY = b.top;
52      int barRectWidth = progressBar.getWidth() - (b.right + barRectX);
53      int barRectHeight = progressBar.getHeight() - (b.bottom + barRectY);
54      int amountFull = getAmountFull(b, barRectWidth, barRectHeight);
55  
56      if (amountFull > 0)
57      {
58        GradientPaint painter = new GradientPaint(barRectX, barRectY,
59                                                  START,
60                                                  barRectX + barRectWidth, barRectY + barRectHeight,
61                                                  END);
62        Graphics2D g2 = (Graphics2D) g;
63        g2.setPaint(painter);
64        g2.fill(new Rectangle(barRectX, barRectY, amountFull, barRectHeight));
65      }
66  
67      if (progressBar.isStringPainted())
68        paintString(g, barRectX, barRectY, barRectWidth, barRectHeight, amountFull, b);
69    }
70  }
71  
72  // End of JextProgressBarUI.java