1 30 31 package com.jgoodies.looks.plastic; 32 33 import java.awt.Color ; 34 import java.awt.Component ; 35 import java.awt.Graphics ; 36 37 import javax.swing.JComponent ; 38 import javax.swing.SwingConstants ; 39 import javax.swing.UIManager ; 40 import javax.swing.plaf.ComponentUI ; 41 42 import com.jgoodies.looks.common.ExtBasicArrowButtonHandler; 43 44 45 53 public final class PlasticXPSpinnerUI extends PlasticSpinnerUI { 54 55 public static ComponentUI createUI(JComponent b) { 56 return new PlasticXPSpinnerUI(); 57 } 58 59 60 68 private static final ExtBasicArrowButtonHandler nextButtonHandler 69 = new ExtBasicArrowButtonHandler("increment", true); 70 private static final ExtBasicArrowButtonHandler previousButtonHandler 71 = new ExtBasicArrowButtonHandler("decrement", false); 72 73 74 87 protected Component createPreviousButton() { 88 return new SpinnerXPArrowButton(SwingConstants.SOUTH, previousButtonHandler); 89 } 90 91 92 105 protected Component createNextButton() { 106 return new SpinnerXPArrowButton(SwingConstants.NORTH, nextButtonHandler); 107 } 108 109 110 114 private static class SpinnerXPArrowButton extends PlasticArrowButton { 115 116 private SpinnerXPArrowButton(int direction, 117 ExtBasicArrowButtonHandler handler) { 118 super(direction, UIManager.getInt("ScrollBar.width") - 2, false); 119 addActionListener(handler); 120 addMouseListener(handler); 121 } 122 123 protected int calculateArrowHeight(int height, int width) { 124 int arrowHeight = Math.min((height - 4) / 3, (width - 4) / 3); 125 return Math.max(arrowHeight, 3); 126 } 127 128 protected boolean isPaintingNorthBottom() { 129 return true; 130 } 131 132 protected void paintNorth(Graphics g, boolean leftToRight, boolean isEnabled, 133 Color arrowColor, boolean isPressed, 134 int width, int height, int w, int h, int arrowHeight, int arrowOffset, 135 boolean paintBottom) { 136 if (!isFreeStanding) { 137 height += 1; 138 g.translate(0, -1); 139 if (!leftToRight) { 140 width += 1; 141 g.translate(-1, 0); 142 } else { 143 width += 2; 144 } 145 } 146 147 g.setColor(arrowColor); 149 int startY = ((h + 1) - arrowHeight) / 2; int startX = w / 2; 151 for (int line = 0; line < arrowHeight; line++) { 153 g.fillRect(startX - line - arrowOffset, startY + line, 2*(line + 1), 1); 154 } 155 156 if (isEnabled) { 157 Color shadowColor = UIManager.getColor("ScrollBar.darkShadow"); 158 159 g.setColor(shadowColor); 160 g.drawLine(0, 0, width - 2, 0); 161 g.drawLine(0, 0, 0, height - 1); 162 g.drawLine(width - 2, 1, width - 2, height - 1); 163 if (paintBottom) { 164 g.fillRect(0, height - 1, width - 1, 1); 165 } 166 } else { 167 PlasticUtils.drawDisabledBorder(g, 0, 0, width, height + 1); 168 if (paintBottom) { 169 g.setColor(PlasticLookAndFeel.getControlShadow()); 170 g.fillRect(0, height - 1, width - 1, 1); 171 } 172 } 173 if (!isFreeStanding) { 174 height -= 1; 175 g.translate(0, 1); 176 if (!leftToRight) { 177 width -= 1; 178 g.translate(1, 0); 179 } else { 180 width -= 2; 181 } 182 } 183 } 184 185 protected void paintSouth(Graphics g, boolean leftToRight, boolean isEnabled, 186 Color arrowColor, boolean isPressed, 187 int width, int height, int w, int h, int arrowHeight, int arrowOffset) { 188 189 if (!isFreeStanding) { 190 height += 1; 191 if (!leftToRight) { 192 width += 1; 193 g.translate(-1, 0); 194 } else { 195 width += 2; 196 } 197 } 198 199 g.setColor(arrowColor); 201 202 int startY = (((h + 0) - arrowHeight) / 2) + arrowHeight - 1; int startX = w / 2; 204 205 207 for (int line = 0; line < arrowHeight; line++) { 208 g.fillRect(startX - line - arrowOffset, startY - line, 2*(line + 1), 1); 209 } 210 211 if (isEnabled) { 212 Color shadowColor = UIManager.getColor("ScrollBar.darkShadow"); 213 g.setColor(shadowColor); 214 g.drawLine(0, 0, 0, height - 2); 215 g.drawLine(width - 2, 0, width - 2, height - 2); 216 } else { 218 PlasticUtils.drawDisabledBorder(g, 0, -1, width, height + 1); 219 } 220 221 if (!isFreeStanding) { 222 height -= 1; 223 if (!leftToRight) { 224 width -= 1; 225 g.translate(1, 0); 226 } else { 227 width -= 2; 228 } 229 } 230 } 231 232 } 233 234 } | Popular Tags |