01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Dennis Ushakov
19: * @version $Revision$
20: */package javax.swing.plaf.metal;
21:
22: import java.awt.Graphics;
23: import java.awt.Rectangle;
24:
25: import javax.swing.JComponent;
26: import javax.swing.JProgressBar;
27: import javax.swing.SwingUtilities;
28: import javax.swing.plaf.ComponentUI;
29: import javax.swing.plaf.basic.BasicProgressBarUI;
30:
31: public class MetalProgressBarUI extends BasicProgressBarUI {
32:
33: public static ComponentUI createUI(final JComponent c) {
34: return new MetalProgressBarUI();
35: }
36:
37: public void paintDeterminate(final Graphics g, final JComponent c) {
38: super .paintDeterminate(g, c);
39:
40: Rectangle inner = SwingUtilities.calculateInnerArea(
41: progressBar, null);
42: paintNonFilledOutline(g, inner);
43:
44: g.setColor(getSelectionBackground());
45: if (progressBar.getOrientation() == JProgressBar.VERTICAL) {
46: if (progressBar.getValue() == progressBar.getMaximum()) {
47: g.drawLine(inner.x, inner.y, inner.x + inner.width,
48: inner.y);
49: }
50: int bottom = inner.y + inner.height;
51: g
52: .drawLine(inner.x, bottom
53: - getAmountFull(progressBar.getInsets(),
54: inner.width, inner.height),
55: inner.x, bottom);
56: } else {
57: g.drawLine(inner.x, inner.y, inner.x, inner.y
58: + inner.height);
59: g.drawLine(inner.x, inner.y, inner.x
60: + getAmountFull(progressBar.getInsets(),
61: inner.width, inner.height), inner.y);
62: }
63: }
64:
65: public void paintIndeterminate(final Graphics g, final JComponent c) {
66: super .paintIndeterminate(g, c);
67:
68: Rectangle inner = SwingUtilities.calculateInnerArea(
69: progressBar, null);
70: Rectangle box = getBox(inner);
71: paintNonFilledOutline(g, inner);
72:
73: g.setColor(getSelectionBackground());
74: if (progressBar.getOrientation() == JProgressBar.VERTICAL) {
75: g.drawLine(inner.x, box.y, inner.x, box.y + box.height);
76: } else {
77: g.drawLine(box.x, inner.y, box.x + box.width, inner.y);
78: }
79: }
80:
81: private void paintNonFilledOutline(final Graphics g,
82: final Rectangle inner) {
83: g.setColor(MetalLookAndFeel.getControlShadow());
84: g.drawLine(inner.x, inner.y, inner.x + inner.width, inner.y);
85: g.drawLine(inner.x, inner.y, inner.x, inner.y + inner.height);
86: }
87: }
|