-
- All Known Implementing Classes:
- AbstractRegionPainter
public interface Painter<T>
A painting delegate. The Painter interface defines exactly one method,
paint
. It is used in situations where the developer can change the painting routine of a component without having to resort to subclassing the component. It is also generically useful when doing any form of painting delegation.Painter
s are simply encapsulations of Java2D code and make it fairly trivial to reuse existingPainter
s or to combine them together. Implementations of this interface are also trivial to write, such that if you can't find aPainter
that does what you need, you can write one with minimal effort. Writing aPainter
requires knowledge of Java2D.A
Painter
may be created with a type parameter. This type will be expected in thepaint
method. For example, you may wish to write aPainter
that only works with subclasses ofComponent
. In that case, when thePainter
is declared, you may declare that it requires aComponent
, allowing the paint method to be type safe. Ex:Painter<Component> p = new Painter<Component>() { public void paint(Graphics2D g, Component c, int width, int height) { g.setColor(c.getBackground()); //and so forth } }
This interface makes no guarantees of threadsafety.
-
-
Method Summary
Methods Modifier and Type Method and Description void
paint(Graphics2D g, T object, int width, int height)
Renders to the givenGraphics2D
object.
-
-
-
Method Detail
-
paint
void paint(Graphics2D g, T object, int width, int height)
Renders to the given
Graphics2D
object. Implementations of this method may modify state on theGraphics2D
, and are not required to restore that state upon completion. In most cases, it is recommended that the caller pass in a scratch graphics object. TheGraphics2D
must never be null.State on the graphics object may be honored by the
paint
method, but may not be. For instance, setting the antialiasing rendering hint on the graphics may or may not be respected by thePainter
implementation.The supplied object parameter acts as an optional configuration argument. For example, it could be of type
Component
. APainter
that expected it could then read state from thatComponent
and use the state for painting. For example, an implementation may read the backgroundColor and use that.Generally, to enhance reusability, most standard
Painter
s ignore this parameter. They can thus be reused in any context. Theobject
may be null. Implementations must not throw a NullPointerException if the object parameter is null.Finally, the
width
andheight
arguments specify the width and height that thePainter
should paint into. More specifically, the specified width and height instruct the painter that it should paint fully within this width and height. Any specified clip on theg
param will further constrain the region.For example, suppose I have a
Painter
implementation that draws a gradient. The gradient goes from white to black. It "stretches" to fill the painted region. Thus, if I use thisPainter
to paint a 500 x 500 region, the far left would be black, the far right would be white, and a smooth gradient would be painted between. I could then, without modification, reuse thePainter
to paint a region that is 20x20 in size. This region would also be black on the left, white on the right, and a smooth gradient painted between.- Parameters:
g
- The Graphics2D to render to. This must not be null.object
- an optional configuration parameter. This may be null.width
- width of the area to paint.height
- height of the area to paint.
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
22/11/2024 01:04:52 Cette version de la page est en cache (à la date du 22/11/2024 01:04:52) afin d'accélérer le traitement. Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la dernère version de la page.Document créé le 11/06/2005, dernière modification le 04/03/2020
Source du document imprimé : https://www.gaudry.be/java-api-rf-javax/swing/Painter.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.