JDK-5095630 : new method in AlphaComposite to derive new instances by rule or extra alpha
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.2.1
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2004-09-01
  • Updated: 2017-05-16
  • Resolved: 2004-11-22
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 betaFixed
Description
The following new methods on AlphaComposite would simplify a fair amount
of code:

	public AlphaComposite derive(float alpha);

	public AlphaComposite derive(int rule);

The first one in particular would simplify the creation of new objects from:

	AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f);

to:

	AlphaComposite ac = AlphaComposite.SrcOver.derive(0.5);

this would also simplify a fade operation where a new AlphaComposite needs
to be created with a different alpha parameter for each iteration of the
fade:

	ac = ac.derive(newfadeamount);

The latter method that derives a new instance with a new rule is probably
less useful, but is included for completeness.

Comments
EVALUATION New methods were implemented as described in the description. The full javadocs are as follows: /** * Returns a similar <code>AlphaComposite</code> object that uses * the specified compositing rule. * If this object already uses the specified compositing rule, * this object is returned. * @return an <code>AlphaComposite</code> object derived from * this object that uses the specified compositing rule. * @param rule the compositing rule * @throws IllegalArgumentException if * <code>rule</code> is not one of * the following: {@link #CLEAR}, {@link #SRC}, {@link #DST}, * {@link #SRC_OVER}, {@link #DST_OVER}, {@link #SRC_IN}, * {@link #DST_IN}, {@link #SRC_OUT}, {@link #DST_OUT}, * {@link #SRC_ATOP}, {@link #DST_ATOP}, or {@link #XOR} */ public AlphaComposite derive(int rule); /** * Returns a similar <code>AlphaComposite</code> object that uses * the specified alpha value. * If this object already has the specified alpha value, * this object is returned. * @return an <code>AlphaComposite</code> object derived from * this object that uses the specified alpha value. * @param alpha the constant alpha to be multiplied with the alpha of * the source. <code>alpha</code> must be a floating point number in the * inclusive range [0.0,&nbsp;1.0]. * @throws IllegalArgumentException if * <code>alpha</code> is less than 0.0 or greater than 1.0 */ public AlphaComposite derive(float alpha); ###@###.### 10/23/04 08:31 GMT
23-10-2004