API Overview API Index Package Overview Direct link to this page
JDK 1.6
  javax.swing.plaf.metal. MetalProgressBarUI View Javadoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173

/*
 * @(#)MetalProgressBarUI.java	1.28 06/04/07
 *
 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

package javax.swing.plaf.metal;

import javax.swing.*;
import javax.swing.plaf.*;
import javax.swing.plaf.basic.*;
import java.awt.*;

/**
 * The Metal implementation of ProgressBarUI.
 * <p>
 * <strong>Warning:</strong>
 * Serialized objects of this class will not be compatible with
 * future Swing releases. The current serialization support is
 * appropriate for short term storage or RMI between applications running
 * the same version of Swing.  As of 1.4, support for long term storage
 * of all JavaBeans<sup><font size="-2">TM</font></sup>
 * has been added to the <code>java.beans</code> package.
 * Please see {@link java.beans.XMLEncoder}.
 *
 * @version 1.28 04/07/06
 * @author Michael C. Albers
 */
public class MetalProgressBarUI extends BasicProgressBarUI {

    private Rectangle innards;
    private Rectangle box;

    public static ComponentUI createUI(JComponent c) {
	return new MetalProgressBarUI();
    }

    /**
     * Draws a bit of special highlighting on the progress bar.
     * The core painting is deferred to the BasicProgressBar's
     * <code>paintDeterminate</code> method.
     * @since 1.4
     */ 
    public void paintDeterminate(Graphics g, JComponent c) {
	super.paintDeterminate(g,c);

        if (!(g instanceof Graphics2D)) {
            return;
        }

	if (progressBar.isBorderPainted()) {
	    Insets b = progressBar.getInsets(); // area for border
	    int barRectWidth = progressBar.getWidth() - (b.left + b.right);
	    int barRectHeight = progressBar.getHeight() - (b.top + b.bottom);
	    int amountFull = getAmountFull(b, barRectWidth, barRectHeight);
            boolean isLeftToRight = MetalUtils.isLeftToRight(c);
            int startX, startY, endX, endY;
	    
            // The progress bar border is painted according to a light source.
            // This light source is stationary and does not change when the
            // component orientation changes.
            startX = b.left;
            startY = b.top;
            endX = b.left + barRectWidth - 1;
            endY = b.top + barRectHeight - 1;

            Graphics2D g2 = (Graphics2D)g;
            g2.setStroke(new BasicStroke(1.f));

	    if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
                // Draw light line lengthwise across the progress bar.
		g2.setColor(MetalLookAndFeel.getControlShadow());
                g2.drawLine(startX, startY, endX, startY);

                if (amountFull > 0) {
                    // Draw darker lengthwise line over filled area.
		    g2.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
                    
                    if (isLeftToRight) {
                        g2.drawLine(startX, startY,
                                startX + amountFull - 1, startY);
                    } else {
                        g2.drawLine(endX, startY,
                                endX - amountFull + 1, startY);
                        if (progressBar.getPercentComplete() != 1.f) {
		            g2.setColor(MetalLookAndFeel.getControlShadow());
                        }
                    }
                }
                // Draw a line across the width.  The color is determined by
                // the code above.
                g2.drawLine(startX, startY, startX, endY);

	    } else { // VERTICAL
		// Draw light line lengthwise across the progress bar.
		g2.setColor(MetalLookAndFeel.getControlShadow());
		g2.drawLine(startX, startY, startX, endY);
		
		if (amountFull > 0) { 
                    // Draw darker lengthwise line over filled area.
		    g2.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
		    g2.drawLine(startX, endY,
                            startX, endY - amountFull + 1);
		}
                // Draw a line across the width.  The color is determined by
                // the code above.
		g2.setColor(MetalLookAndFeel.getControlShadow());

                if (progressBar.getPercentComplete() == 1.f) {
		    g2.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
                }
		g2.drawLine(startX, startY, endX, startY);
	    }
	}
    }

    /**
     * Draws a bit of special highlighting on the progress bar
     * and bouncing box.
     * The core painting is deferred to the BasicProgressBar's
     * <code>paintIndeterminate</code> method.
     * @since 1.4
     */ 
    public void paintIndeterminate(Graphics g, JComponent c) {
        super.paintIndeterminate(g, c);

        if (!progressBar.isBorderPainted() || (!(g instanceof Graphics2D))) {
            return;
        }

        Insets b = progressBar.getInsets(); // area for border
        int barRectWidth = progressBar.getWidth() - (b.left + b.right);
        int barRectHeight = progressBar.getHeight() - (b.top + b.bottom);
        int amountFull = getAmountFull(b, barRectWidth, barRectHeight);
        boolean isLeftToRight = MetalUtils.isLeftToRight(c);
        int startX, startY, endX, endY;
        Rectangle box = null;
        box = getBox(box);
    
        // The progress bar border is painted according to a light source.
        // This light source is stationary and does not change when the
        // component orientation changes.
        startX = b.left;
        startY = b.top;
        endX = b.left + barRectWidth - 1;
        endY = b.top + barRectHeight - 1;

        Graphics2D g2 = (Graphics2D)g;
        g2.setStroke(new BasicStroke(1.f));

        if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
            // Draw light line lengthwise across the progress bar.
            g2.setColor(MetalLookAndFeel.getControlShadow());
            g2.drawLine(startX, startY, endX, startY);
            g2.drawLine(startX, startY, startX, endY);

            // Draw darker lengthwise line over filled area.
            g2.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
            g2.drawLine(box.x, startY, box.x + box.width - 1, startY);

        } else { // VERTICAL
            // Draw light line lengthwise across the progress bar.
            g2.setColor(MetalLookAndFeel.getControlShadow());
            g2.drawLine(startX, startY, startX, endY);
            g2.drawLine(startX, startY, endX, startY);

            // Draw darker lengthwise line over filled area.
            g2.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
            g2.drawLine(startX, box.y, startX, box.y + box.height - 1);
        }
    }
}

Generated By: JavaOnTracks Doclet 0.1.4     ©Thibaut Colar