187 */ 188 protected abstract PaintContext getPaintContext(); 189 190 /** 191 * <p>Configures the given Graphics2D. Often, rendering hints or compositing rules are 192 * applied to a Graphics2D object prior to painting, which should affect all of the 193 * subsequent painting operations. This method provides a convenient hook for configuring 194 * the Graphics object prior to rendering, regardless of whether the render operation is 195 * performed to an intermediate buffer or directly to the display.</p> 196 * 197 * @param g The Graphics2D object to configure. Will not be null. 198 */ 199 protected void configureGraphics(Graphics2D g) { 200 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 201 } 202 203 /** 204 * Actually performs the painting operation. Subclasses must implement this method. 205 * The graphics object passed may represent the actual surface being rendered to, 206 * or it may be an intermediate buffer. It has also been pre-translated. Simply render 207 * the component as if it were located at 0, 0 and had a width of <code>width</code> 208 * and a height of <code>height</code>. For performance reasons, you may want to read 209 * the clip from the Graphics2D object and only render within that space. 210 * 211 * @param g The Graphics2D surface to paint to 212 * @param c The JComponent related to the drawing event. For example, if the 213 * region being rendered is Button, then <code>c</code> will be a 214 * JButton. If the region being drawn is ScrollBarSlider, then the 215 * component will be JScrollBar. This value may be null. 216 * @param width The width of the region to paint. Note that in the case of 217 * painting the foreground, this value may differ from c.getWidth(). 218 * @param height The height of the region to paint. Note that in the case of 219 * painting the foreground, this value may differ from c.getHeight(). 220 * @param extendedCacheKeys The result of the call to getExtendedCacheKeys() 221 */ 222 protected abstract void doPaint(Graphics2D g, JComponent c, int width, 223 int height, Object[] extendedCacheKeys); 224 225 /** 226 * Decodes and returns a float value representing the actual pixel location for 227 * the given encoded X value. 228 * 229 * @param x an encoded x value (0...1, or 1...2, or 2...3) 230 * @return the decoded x value 231 * @throws IllegalArgumentException 232 * if {@code x < 0} or {@code x > 3} 233 */ 396 * @return a valid RadialGradientPaint. This method never returns null. 397 * @throws NullPointerException 398 * if {@code midpoints} array is null, 399 * or {@code colors} array is null 400 * @throws IllegalArgumentException 401 * if {@code r} is non-positive, 402 * or {@code midpoints.length != colors.length}, 403 * or {@code colors} is less than 2 in size, 404 * or a {@code midpoints} value is less than 0.0 or greater than 1.0, 405 * or the {@code midpoints} are not provided in strictly increasing order 406 */ 407 protected final RadialGradientPaint decodeRadialGradient(float x, float y, float r, float[] midpoints, Color[] colors) { 408 if (r == 0f) { 409 r = .00001f; 410 } 411 return new RadialGradientPaint(x, y, r, midpoints, colors); 412 } 413 414 /** 415 * Get a color property from the given JComponent. First checks for a 416 * <code>getXXX()</code> method and if that fails checks for a client 417 * property with key <code>property</code>. If that still fails to return 418 * a Color then <code>defaultColor</code> is returned. 419 * 420 * @param c The component to get the color property from 421 * @param property The name of a bean style property or client property 422 * @param defaultColor The color to return if no color was obtained from 423 * the component. 424 * @param saturationOffset additively modifies the HSB saturation component 425 * of the color returned (ignored if default color is returned). 426 * @param brightnessOffset additively modifies the HSB brightness component 427 * of the color returned (ignored if default color is returned). 428 * @param alphaOffset additively modifies the ARGB alpha component of the 429 * color returned (ignored if default color is returned). 430 * 431 * @return The color that was obtained from the component or defaultColor 432 */ 433 protected final Color getComponentColor(JComponent c, String property, 434 Color defaultColor, 435 float saturationOffset, 436 float brightnessOffset, 437 int alphaOffset) { 438 Color color = null; | 187 */ 188 protected abstract PaintContext getPaintContext(); 189 190 /** 191 * <p>Configures the given Graphics2D. Often, rendering hints or compositing rules are 192 * applied to a Graphics2D object prior to painting, which should affect all of the 193 * subsequent painting operations. This method provides a convenient hook for configuring 194 * the Graphics object prior to rendering, regardless of whether the render operation is 195 * performed to an intermediate buffer or directly to the display.</p> 196 * 197 * @param g The Graphics2D object to configure. Will not be null. 198 */ 199 protected void configureGraphics(Graphics2D g) { 200 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 201 } 202 203 /** 204 * Actually performs the painting operation. Subclasses must implement this method. 205 * The graphics object passed may represent the actual surface being rendered to, 206 * or it may be an intermediate buffer. It has also been pre-translated. Simply render 207 * the component as if it were located at 0, 0 and had a width of {@code width} 208 * and a height of {@code height}. For performance reasons, you may want to read 209 * the clip from the Graphics2D object and only render within that space. 210 * 211 * @param g The Graphics2D surface to paint to 212 * @param c The JComponent related to the drawing event. For example, if the 213 * region being rendered is Button, then {@code c} will be a 214 * JButton. If the region being drawn is ScrollBarSlider, then the 215 * component will be JScrollBar. This value may be null. 216 * @param width The width of the region to paint. Note that in the case of 217 * painting the foreground, this value may differ from c.getWidth(). 218 * @param height The height of the region to paint. Note that in the case of 219 * painting the foreground, this value may differ from c.getHeight(). 220 * @param extendedCacheKeys The result of the call to getExtendedCacheKeys() 221 */ 222 protected abstract void doPaint(Graphics2D g, JComponent c, int width, 223 int height, Object[] extendedCacheKeys); 224 225 /** 226 * Decodes and returns a float value representing the actual pixel location for 227 * the given encoded X value. 228 * 229 * @param x an encoded x value (0...1, or 1...2, or 2...3) 230 * @return the decoded x value 231 * @throws IllegalArgumentException 232 * if {@code x < 0} or {@code x > 3} 233 */ 396 * @return a valid RadialGradientPaint. This method never returns null. 397 * @throws NullPointerException 398 * if {@code midpoints} array is null, 399 * or {@code colors} array is null 400 * @throws IllegalArgumentException 401 * if {@code r} is non-positive, 402 * or {@code midpoints.length != colors.length}, 403 * or {@code colors} is less than 2 in size, 404 * or a {@code midpoints} value is less than 0.0 or greater than 1.0, 405 * or the {@code midpoints} are not provided in strictly increasing order 406 */ 407 protected final RadialGradientPaint decodeRadialGradient(float x, float y, float r, float[] midpoints, Color[] colors) { 408 if (r == 0f) { 409 r = .00001f; 410 } 411 return new RadialGradientPaint(x, y, r, midpoints, colors); 412 } 413 414 /** 415 * Get a color property from the given JComponent. First checks for a 416 * {@code getXXX()} method and if that fails checks for a client 417 * property with key {@code property}. If that still fails to return 418 * a Color then {@code defaultColor} is returned. 419 * 420 * @param c The component to get the color property from 421 * @param property The name of a bean style property or client property 422 * @param defaultColor The color to return if no color was obtained from 423 * the component. 424 * @param saturationOffset additively modifies the HSB saturation component 425 * of the color returned (ignored if default color is returned). 426 * @param brightnessOffset additively modifies the HSB brightness component 427 * of the color returned (ignored if default color is returned). 428 * @param alphaOffset additively modifies the ARGB alpha component of the 429 * color returned (ignored if default color is returned). 430 * 431 * @return The color that was obtained from the component or defaultColor 432 */ 433 protected final Color getComponentColor(JComponent c, String property, 434 Color defaultColor, 435 float saturationOffset, 436 float brightnessOffset, 437 int alphaOffset) { 438 Color color = null; |