V
- The type of image formatpublic abstract class ImageSizeConstraint<V> extends AbstractValidation<V> implements Constraint<V>
Constraint
that
checks whether the size of an image is within maximum bounds. Also image
size can be adjusted according to ImageAdjust
mode.ImageSize
,
ImageAdjust
Modifier and Type | Class and Description |
---|---|
static class |
ImageSizeConstraint.AwtCodec
This class provides
ImageSizeConstraint implementation for
java.awt.Image type. |
protected static class |
ImageSizeConstraint.Context
Context to be used by image codecs.
|
protected static class |
ImageSizeConstraint.IOContext
Context used by
ImageSizeConstraint.RawCodec . |
static class |
ImageSizeConstraint.RawCodec
This class provides
ImageSizeConstraint implementation for
byte[] type. |
Modifier | Constructor and Description |
---|---|
protected |
ImageSizeConstraint(ImageSize annotation)
Constructs a new
ImageSizeConstraint from the specified
annotation. |
protected |
ImageSizeConstraint(int maxWidth,
int maxHeight,
ImageAdjust adjust)
Constructs a new
ImageSizeConstraint with the specified
maximum bounds and adjust mode. |
Modifier and Type | Method and Description |
---|---|
boolean |
appendMessageArguments(ValidationContext<?> context,
Map<String,Object> arguments)
Appends
maxWidth and maxHeight arguments that
contain maximum allowed image width and height respectively. |
protected abstract ImageSizeConstraint.Context |
decodeImage(V value)
Decodes the specified raw image representation into
java.awt.Image and returns context that contains image and
its attributes. |
protected abstract V |
encodeImage(ImageSizeConstraint.Context context)
Encodes
java.awt.Image from the specified context and
returns raw image representation. |
ImageAdjust |
getAdjustMode()
Returns image size adjust mode.
|
int |
getMaxHeight()
Returns maximum image height.
|
int |
getMaxWidth()
Returns maximum image width.
|
String |
getMessageTemplate(ValidationContext<?> context)
Returns localized error message template.
|
static BufferedImage |
toBufferedImage(Image source)
Converts
java.awt.Image into
java.awt.image.BufferedImage . |
<T> V |
validate(V value,
ValidationContext<T> context)
Checks whether the size of the specified image is within maximum bounds.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getType
protected ImageSizeConstraint(int maxWidth, int maxHeight, ImageAdjust adjust)
ImageSizeConstraint
with the specified
maximum bounds and adjust mode.maxWidth
- Maximum image width.maxHeight
- Maximum image height.adjust
- Image size adjust mode.IllegalArgumentException
- if the specified maximum width or height
is negative or zero or the specified adjust mode is
null
.protected ImageSizeConstraint(ImageSize annotation)
ImageSizeConstraint
from the specified
annotation.annotation
- Constraint annotation.IllegalArgumentException
- if the specified annotation defines
negative or zero maximum width or height.public final int getMaxWidth()
public final int getMaxHeight()
public final ImageAdjust getAdjustMode()
public String getMessageTemplate(ValidationContext<?> context)
getMessageTemplate
in interface Constraint<V>
getMessageTemplate
in interface Validation<V>
getMessageTemplate
in class AbstractValidation<V>
context
- Validation context.public boolean appendMessageArguments(ValidationContext<?> context, Map<String,Object> arguments)
maxWidth
and maxHeight
arguments that
contain maximum allowed image width and height respectively.appendMessageArguments
in interface Constraint<V>
appendMessageArguments
in interface Validation<V>
appendMessageArguments
in class AbstractValidation<V>
context
- Validation context.arguments
- Arguments to be substituted into the error message
template.true
.public <T> V validate(V value, ValidationContext<T> context)
validate
in interface Constraint<V>
T
- The type of validated entity.value
- Image to be checked.context
- Validation context.ImageAdjust.NONE
.ConstraintViolationException
- if image size exceeds maximum bounds
and adjust mode is ImageAdjust.NONE
.protected abstract ImageSizeConstraint.Context decodeImage(V value) throws IOException
java.awt.Image
and returns context that contains image and
its attributes.value
- Raw image representation.IOException
- if decoding of an image fails.protected abstract V encodeImage(ImageSizeConstraint.Context context) throws IOException
java.awt.Image
from the specified context and
returns raw image representation.context
- Image context.IOException
- if encoding of an image fails.public static BufferedImage toBufferedImage(Image source)
java.awt.Image
into
java.awt.image.BufferedImage
.source
- java.awt.Image
object.java.awt.image.BufferedImage
object.Copyright © 2011–2020 FoxLabs. All rights reserved.