1 7 8 package javax.swing.plaf.metal; 9 10 import javax.swing.*; 11 import javax.swing.plaf.*; 12 import javax.swing.plaf.basic.*; 13 import java.awt.*; 14 15 30 public class MetalProgressBarUI extends BasicProgressBarUI { 31 32 private Rectangle innards; 33 private Rectangle box; 34 35 public static ComponentUI createUI(JComponent c) { 36 return new MetalProgressBarUI (); 37 } 38 39 44 public void paintDeterminate(Graphics g, JComponent c) { 45 super.paintDeterminate(g,c); 46 47 if (!(g instanceof Graphics2D)) { 48 return; 49 } 50 51 if (progressBar.isBorderPainted()) { 52 Insets b = progressBar.getInsets(); int barRectWidth = progressBar.getWidth() - (b.left + b.right); 54 int barRectHeight = progressBar.getHeight() - (b.top + b.bottom); 55 int amountFull = getAmountFull(b, barRectWidth, barRectHeight); 56 boolean isLeftToRight = MetalUtils.isLeftToRight(c); 57 int startX, startY, endX, endY; 58 59 startX = b.left; 63 startY = b.top; 64 endX = b.left + barRectWidth - 1; 65 endY = b.top + barRectHeight - 1; 66 67 Graphics2D g2 = (Graphics2D)g; 68 g2.setStroke(new BasicStroke(1.f)); 69 70 if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) { 71 g2.setColor(MetalLookAndFeel.getControlShadow()); 73 g2.drawLine(startX, startY, endX, startY); 74 75 if (amountFull > 0) { 76 g2.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); 78 79 if (isLeftToRight) { 80 g2.drawLine(startX, startY, 81 startX + amountFull - 1, startY); 82 } else { 83 g2.drawLine(endX, startY, 84 endX - amountFull + 1, startY); 85 if (progressBar.getPercentComplete() != 1.f) { 86 g2.setColor(MetalLookAndFeel.getControlShadow()); 87 } 88 } 89 } 90 g2.drawLine(startX, startY, startX, endY); 93 94 } else { g2.setColor(MetalLookAndFeel.getControlShadow()); 97 g2.drawLine(startX, startY, startX, endY); 98 99 if (amountFull > 0) { 100 g2.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); 102 g2.drawLine(startX, endY, 103 startX, endY - amountFull + 1); 104 } 105 g2.setColor(MetalLookAndFeel.getControlShadow()); 108 109 if (progressBar.getPercentComplete() == 1.f) { 110 g2.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); 111 } 112 g2.drawLine(startX, startY, endX, startY); 113 } 114 } 115 } 116 117 123 public void paintIndeterminate(Graphics g, JComponent c) { 124 super.paintIndeterminate(g, c); 125 126 if (!progressBar.isBorderPainted() || (!(g instanceof Graphics2D))) { 127 return; 128 } 129 130 Insets b = progressBar.getInsets(); int barRectWidth = progressBar.getWidth() - (b.left + b.right); 132 int barRectHeight = progressBar.getHeight() - (b.top + b.bottom); 133 int amountFull = getAmountFull(b, barRectWidth, barRectHeight); 134 boolean isLeftToRight = MetalUtils.isLeftToRight(c); 135 int startX, startY, endX, endY; 136 Rectangle box = null; 137 box = getBox(box); 138 139 startX = b.left; 143 startY = b.top; 144 endX = b.left + barRectWidth - 1; 145 endY = b.top + barRectHeight - 1; 146 147 Graphics2D g2 = (Graphics2D)g; 148 g2.setStroke(new BasicStroke(1.f)); 149 150 if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) { 151 g2.setColor(MetalLookAndFeel.getControlShadow()); 153 g2.drawLine(startX, startY, endX, startY); 154 g2.drawLine(startX, startY, startX, endY); 155 156 g2.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); 158 g2.drawLine(box.x, startY, box.x + box.width - 1, startY); 159 160 } else { g2.setColor(MetalLookAndFeel.getControlShadow()); 163 g2.drawLine(startX, startY, startX, endY); 164 g2.drawLine(startX, startY, endX, startY); 165 166 g2.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); 168 g2.drawLine(startX, box.y, startX, box.y + box.height - 1); 169 } 170 } 171 } 172 | Popular Tags |