1 7 8 package com.sun.java.swing.plaf.windows; 9 10 import javax.swing.plaf.basic.*; 11 import javax.swing.plaf.*; 12 import javax.swing.*; 13 import java.awt.*; 14 15 import com.sun.java.swing.plaf.windows.TMSchema.*; 16 import com.sun.java.swing.plaf.windows.XPStyle.Skin; 17 18 31 public class WindowsProgressBarUI extends BasicProgressBarUI 32 { 33 34 private Rectangle boxRect; 35 36 public static ComponentUI createUI(JComponent x) { 37 return new WindowsProgressBarUI(); 38 } 39 40 41 protected void installDefaults() { 42 super.installDefaults(); 43 44 if (XPStyle.getXP() != null) { 45 LookAndFeel.installProperty(progressBar, "opaque", Boolean.FALSE); 46 progressBar.setBorder(null); 47 } 48 } 49 50 protected Dimension getPreferredInnerHorizontal() { 51 XPStyle xp = XPStyle.getXP(); 52 if (xp != null) { 53 Dimension dim = xp.getDimension(progressBar, Part.PP_BAR, null, 54 Prop.NORMALSIZE); 55 if (dim == null) { 56 XPStyle.Skin skin = xp.getSkin(progressBar, Part.PP_BAR); 60 dim = new Dimension(super.getPreferredInnerHorizontal().width, 61 skin.getHeight()); 62 } 63 return dim; 64 } else { 65 return super.getPreferredInnerHorizontal(); 66 } 67 } 68 69 protected Dimension getPreferredInnerVertical() { 70 XPStyle xp = XPStyle.getXP(); 71 if (xp != null) { 72 Dimension dim = xp.getDimension(progressBar, Part.PP_BARVERT, null, 73 Prop.NORMALSIZE); 74 if (dim == null) { 75 XPStyle.Skin skin = xp.getSkin(progressBar, Part.PP_BARVERT); 79 dim = new Dimension(skin.getWidth(), 80 super.getPreferredInnerVertical().height); 81 } 82 return dim; 83 } else { 84 return super.getPreferredInnerVertical(); 85 } 86 } 87 88 protected void paintDeterminate(Graphics g, JComponent c) { 89 XPStyle xp = XPStyle.getXP(); 90 if (xp != null) { 91 boolean vertical = (progressBar.getOrientation() == JProgressBar.VERTICAL); 92 boolean isLeftToRight = WindowsGraphicsUtils.isLeftToRight(c); 93 int barRectWidth = progressBar.getWidth(); 94 int barRectHeight = progressBar.getHeight()-1; 95 int amountFull = getAmountFull(null, barRectWidth, barRectHeight); 97 98 paintXPBackground(g, vertical, barRectWidth, barRectHeight); 99 if (progressBar.isStringPainted()) { 101 g.setColor(progressBar.getForeground()); 104 barRectHeight -= 2; 105 barRectWidth -= 2; 106 Graphics2D g2 = (Graphics2D)g; 107 g2.setStroke(new BasicStroke((float)(vertical ? barRectWidth : barRectHeight), 108 BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); 109 if (!vertical) { 110 if (isLeftToRight) { 111 g2.drawLine(2, barRectHeight / 2 + 1, 112 amountFull - 2, barRectHeight / 2 + 1); 113 } else { 114 g2.drawLine(2 + barRectWidth, 115 barRectHeight / 2 + 1, 116 2 + barRectWidth - (amountFull - 2), 117 barRectHeight / 2 + 1); 118 } 119 paintString(g, 0, 0, barRectWidth, barRectHeight, amountFull, null); 120 } else { 121 g2.drawLine(barRectWidth/2 + 1, barRectHeight + 1, 122 barRectWidth/2 + 1, barRectHeight + 1 - amountFull + 2); 123 paintString(g, 2, 2, barRectWidth, barRectHeight, amountFull, null); 124 } 125 126 } else { 127 Skin skin = 128 xp.getSkin(progressBar, vertical ? Part.PP_CHUNKVERT : Part.PP_CHUNK); 129 int thickness; 130 if (vertical) { 131 thickness = barRectWidth - 5; 132 } else { 133 thickness = barRectHeight - 5; 134 } 135 136 int chunkSize = xp.getInt(progressBar, Part.PP_PROGRESS, null, 137 Prop.PROGRESSCHUNKSIZE, 2); 138 int spaceSize = xp.getInt(progressBar, Part.PP_PROGRESS, null, 139 Prop.PROGRESSSPACESIZE, 0); 140 int nChunks = (amountFull-4) / (chunkSize + spaceSize); 141 142 if (spaceSize > 0 && (nChunks * (chunkSize + spaceSize) + chunkSize) < (amountFull-4)) { 144 nChunks++; 145 } 146 147 for (int i = 0; i < nChunks; i++) { 148 if (vertical) { 149 skin.paintSkin(g, 150 3, barRectHeight - i * (chunkSize + spaceSize) - chunkSize - 2, 151 thickness, chunkSize, null); 152 } else { 153 if (isLeftToRight) { 154 skin.paintSkin(g, 155 4 + i * (chunkSize + spaceSize), 2, 156 chunkSize, thickness, null); 157 } else { 158 skin.paintSkin(g, 159 barRectWidth - (2 + (i+1) * (chunkSize + spaceSize)), 2, 160 chunkSize, thickness, null); 161 } 162 } 163 } 164 } 165 } else { 166 super.paintDeterminate(g, c); 167 } 168 } 169 170 171 protected void paintIndeterminate(Graphics g, JComponent c) { 172 XPStyle xp = XPStyle.getXP(); 173 if (xp != null) { 174 boolean vertical = (progressBar.getOrientation() == JProgressBar.VERTICAL); 175 int barRectWidth = progressBar.getWidth(); 176 int barRectHeight = progressBar.getHeight()-1; 177 paintXPBackground(g, vertical, barRectWidth, barRectHeight); 178 179 boxRect = getBox(boxRect); 181 if (boxRect != null) { 182 g.setColor(progressBar.getForeground()); 183 if (!vertical) { 184 g.fillRect(boxRect.x, boxRect.y + 2, boxRect.width, boxRect.height - 4); 185 } else { 186 g.fillRect(boxRect.x + 2, boxRect.y, boxRect.width - 3, boxRect.height); 187 } 188 if (progressBar.isStringPainted()) { 189 if (!vertical) { 190 paintString(g, -1, -1, barRectWidth, barRectHeight, 0, null); 191 } else { 192 paintString(g, 1, 1, barRectWidth, barRectHeight, 0, null); 193 } 194 } 195 } 196 } else { 197 super.paintIndeterminate(g, c); 198 } 199 } 200 201 private void paintXPBackground(Graphics g, boolean vertical, 202 int barRectWidth, int barRectHeight) { 203 XPStyle xp = XPStyle.getXP(); 204 Part part = vertical ? Part.PP_BARVERT : Part.PP_BAR; 205 Skin skin = xp.getSkin(progressBar, part); 206 207 skin.paintSkin(g, 0, 0, barRectWidth, barRectHeight, null); 209 } 210 } 211 212 | Popular Tags |