Class ImageConf
The following properties with their respective purpose are available:
- Layer: The layer onto which the image will be drawn. Layers exist to determine the order in which something is drawn onto the component. Here a list of available layers:
- Primer: The primer color of the image style which will be used as a filler color for the image background. The background is the inner component area of the component.
- Image:
The image which will be drawn onto the component,
which may be specified as an instance of
Image
,ImageIcon
or path to an image file (seeUIFactoryMethods.findIcon(String)
). - Placement: The placement type determines where the image will be drawn onto the component. The following placement options are available:
- Repeat:
If this flag is set to
true
, then the image may be painted multiple times so that it fills up the entire inner component area. There will not be a noticeable effect of this flag if the image already fills out the inner component area (seeautoFit(boolean)
,size(int, int)
). - Fit-Mode:
If this enum determines how the image will be stretched or shrunk
to fill the inner component area dependent on the specified width and height,
meaning that if the width was not specified explicitly through
width(Integer)
then the image will be scaled to fit the inner component width, and if a height was not specified throughheight(Integer)
then the image will be scaled to fit the inner component height.
Note that the inner component area is the area enclosed by the border, which is itself not part of said area! - Width and Height:
These properties allow you to specify the width and height of the image.
If the width or height is not specified, then the image will be drawn
with its original width or height or it will be scaled to fit the inner component area
if
autoFit(boolean)
is set totrue
. - Opacity: This property allows you to specify the opacity of the image. The opacity must be between 0.0f and 1.0f, where 0.0f means that the image is completely transparent and 1.0f means that the image is completely opaque.
- Padding: This property allows you to specify the padding of the image. The padding is the space between the image and the inner component area. The padding can be specified for each side of the image individually or for all sides at once.
- Offset:
The offset consists of two integers, one for the horizontal offset
and one for the vertical offset.
It allows you to specify the offset of the image from the placement position. This means that after the image has been placed onto the component, it will be moved by the specified offset in the horizontal and vertical direction. - Clip Area:
The clip area determines onto which part of the component the image will be drawn.
The following clip areas are available:
UI.ComponentArea.ALL
- The entire component, which is the union of all other clip areas (INTERIOR + EXTERIOR + BORDER + CONTENT
).UI.ComponentArea.INTERIOR
- The inner component area, which is defined asALL - EXTERIOR - BORDER
.UI.ComponentArea.EXTERIOR
- The outer component area, which can be expressed asALL - INTERIOR - BORDER
, orALL - CONTENT
.UI.ComponentArea.BORDER
- The border of the component, which is the area between the inner and outer component area and which can be expressed asALL - INTERIOR - EXTERIOR
.UI.ComponentArea.BODY
- The body of the component is the inner component area including the border area. It can be expressed asALL - EXTERIOR
, orINTERIOR + BORDER
.
The default clip area is
UI.ComponentArea.BODY
as this is the area which is most commonly used.
Take a look at the following example:
of(component).withStyle( it -> it
.image( image -> image
.layer(Layer.BACKGROUND)
.image(image)
.placement(Placement.CENTER)
.autoFit(false)
.repeat(true)
.primer(Color.CYAN)
.padding(12)
)
);
This will draw the specified image onto the background layer of the component.
The image will be drawn at the center of the inner component area with a padding of 12,
without being scaled to fit the inner component area, instead the size of the image
will be used.
If it does not fill the entire inner component area based on its size, then
it will be repeated across said area, and the primer color
will be used as a filler color for the parts of the image which
are transparent.
-
Method Summary
Modifier and TypeMethodDescriptionautoFit
(boolean autoFit) If this flag is set totrue
, then the image will be stretched or shrunk to fill the inner component area dependent on the specified width and height, meaning that if the width was not specified explicitly throughwidth(Integer)
then the image will be scaled to fit the inner component width, and if a height was not specified throughheight(Integer)
then the image will be scaled to fit the inner component height.clipTo
(UI.ComponentArea clipArea) Use this to specify the clip area of the image, which determines on which part of the component the image will be drawn.boolean
fitMode
(UI.FitComponent fit) There are different kinds of strategies to fit the image onto the component.int
hashCode()
Ensures that the image has the specified height.horizontalOffset
(int x) Use this to specify the horizontal offset by which the image will be moved and drawn onto the component.Here you can specify the image which will be drawn onto the component.Here you can specify the path to the image for which the icon will be loaded, cached and drawn onto the component.Here you can specify the image icon which will be drawn onto the component.image
(IconDeclaration image) Here you can specify the path to the image in the form of anIconDeclaration
for which the icon will be loaded and drawn onto the component.offset
(int x, int y) Use this to specify the vertical and horizontal offset by which the image will be moved and drawn onto the component.opacity
(float opacity) This method allows you to specify the opacity of the image.padding
(int padding) This method allows you to specify the padding for all sides of the image.padding
(int topBottom, int leftRight) This method allows you to specify the padding of the image.padding
(int top, int right, int bottom, int left) This method allows you to specify the padding of the image.placement
(UI.Placement placement) Here you can specify the placement of the image onto the component.Here you can specify the primer color of the image style which will be used as a filler color for the image background.repeat
(boolean repeat) If this flag is set totrue
, then the image may be painted multiple times so that it fills up the entire inner component area.size
(int width, int height) Ensures that the image has the specified width and height.Ensures that the image has the specified width and height.toString()
verticalOffset
(int y) Use this to specify the vertical offset by which the image will be moved and drawn onto the component.Ensures that the image has the specified width.
-
Method Details
-
primer
Here you can specify the primer color of the image style which will be used as a filler color for the image background.
Note that the primer color will not be visible if the image is opaque and it fills the entire component.- Parameters:
color
- The primer color of the image style.- Returns:
- A new
ImageConf
instance with the specified primer color.
-
image
Here you can specify the image which will be drawn onto the component. The supplied object must be an instance ofImage
implementation.- Parameters:
image
- The image which will be drawn onto the component.- Returns:
- A new
ImageConf
instance with the specified image.
-
image
Here you can specify the image icon which will be drawn onto the component. The supplied object must be an instance ofImageIcon
implementation.- Parameters:
image
- The image icon which will be drawn onto the component.- Returns:
- A new
ImageConf
instance with the specified image.
-
image
Here you can specify the path to the image in the form of anIconDeclaration
for which the icon will be loaded and drawn onto the component. If the icon could not be found, then the image will not be drawn. The path is relative to the classpath or may be an absolute path.- Parameters:
image
- The path to the (icon) image in the form of anIconDeclaration
.- Returns:
- A new
ImageConf
instance with the specified image. - Throws:
NullPointerException
- If the specifiedimage
is null.
-
image
Here you can specify the path to the image for which the icon will be loaded, cached and drawn onto the component. If the icon could not be found, then the image will not be drawn. The path is relative to the classpath or may be an absolute path. (seeUIFactoryMethods.findIcon(String)
).- Parameters:
path
- The path to the (icon) image.- Returns:
- A new
ImageConf
instance with the specified image. - Throws:
NullPointerException
- If the specifiedpath
is null.
-
placement
Here you can specify the placement of the image onto the component. The default placement isUI.Placement.CENTER
.
Here a list of available options and their effect:UI.Placement.CENTER
- The image will be drawn at the center of the component. So the center of the image will be at the center of the inner component area.UI.Placement.TOP_LEFT
- The image will be drawn beginning at the top left corner of the inner component area. So the top left corner of the image will be in the top left corner of the inner component area.UI.Placement.TOP_RIGHT
- The image will be placed in the top right corner of the inner component area. So the top right corner of the image will be in the top right corner of the inner component area.UI.Placement.BOTTOM_LEFT
- The image will be drawn in the bottom left corner of the inner component area. So the bottom left corner of the image will be in the bottom left corner of the inner component area.UI.Placement.BOTTOM_RIGHT
- The image will be drawn in the bottom right corner of the inner component area. So the bottom right corner of the image will be in the bottom right corner of the inner component area.UI.Placement.TOP
- The image will be drawn in the top center of the inner component area. So the top center of the image will be in the top center of the inner component area.UI.Placement.BOTTOM
- The image will be drawn in the bottom center of the inner component area. So the bottom center of the image will be in the bottom center of the inner component area.UI.Placement.LEFT
- The image will be drawn in the left center of the inner component area. So the left center of the image will be in the left center of the inner component area.UI.Placement.RIGHT
- The image will be drawn in the right center of the inner component area. So the right center of the image will be in the right center of the inner component area.UI.Placement.UNDEFINED
- The image will be drawn at a position which is determined by other factors such as the image size and the component size.
- Parameters:
placement
- The placement of the image onto the component.- Returns:
- A new
ImageConf
instance with the specified placement.
-
repeat
If this flag is set totrue
, then the image may be painted multiple times so that it fills up the entire inner component area. There will not be a noticeable effect of this flag if the image already fills out the inner component area (seeautoFit(boolean)
,size(int, int)
).- Parameters:
repeat
- Weather the image should be painted repeatedly across the inner component area.- Returns:
- A new
ImageConf
instance with the specifiedrepeat
flag value.
-
autoFit
If this flag is set totrue
, then the image will be stretched or shrunk to fill the inner component area dependent on the specified width and height, meaning that if the width was not specified explicitly throughwidth(Integer)
then the image will be scaled to fit the inner component width, and if a height was not specified throughheight(Integer)
then the image will be scaled to fit the inner component height.
Note that the inner component area is the area enclosed by the border, which is itself not part of said area!- Parameters:
autoFit
- If true the image will be scaled to fit the inner component area for every dimension which was not specified, otherwise the image will not be scaled to fit the inner component area.- Returns:
- A new
ImageConf
instance with the specifiedautoFit
flag value.
-
fitMode
There are different kinds of strategies to fit the image onto the component. These strategies are identified using theUI.FitComponent
enum which defines the following fit modes:UI.FitComponent.NO
- The image will not be scaled to fit the inner component area.UILayoutConstants.WIDTH(int, int, int)
- The image will be scaled to fit the inner component width.UILayoutConstants.HEIGHT(int, int, int)
- The image will be scaled to fit the inner component height.UI.FitComponent.WIDTH_AND_HEIGHT
- The image will be scaled to fit both the component width and height.UI.FitComponent.MAX_DIM
- The image will be scaled to fit the smaller of the two dimension of the inner component area.UI.FitComponent.MIN_DIM
- The image will be scaled to fit the larger of the two dimension of the inner component area.
- Parameters:
fit
- The fit mode of the image.- Returns:
- A new
ImageConf
instance with the specifiedfit
mode.
-
width
Ensures that the image has the specified width.- Parameters:
width
- The width of the image.- Returns:
- A new
ImageConf
instance with the specifiedwidth
.
-
height
Ensures that the image has the specified height.- Parameters:
height
- The height of the image.- Returns:
- A new
ImageConf
instance with the specifiedheight
.
-
size
Ensures that the image has the specified width and height.- Parameters:
width
- The width of the image.height
- The height of the image.- Returns:
- A new
ImageConf
instance with the specifiedwidth
andheight
.
-
size
Ensures that the image has the specified width and height.- Parameters:
size
- The size of the image.- Returns:
- A new
ImageConf
instance with the specifiedsize
.
-
opacity
This method allows you to specify the opacity of the image. The opacity must be between 0.0f and 1.0f, where 0.0f means that the image is completely transparent and 1.0f means that the image is completely opaque.- Parameters:
opacity
- The opacity of the image.- Returns:
- A new
ImageConf
instance with the specified opacity.
-
padding
This method allows you to specify the padding of the image. The padding is the space between the image and the inner component area.- Parameters:
top
- The top padding of the image.right
- The right padding of the image.bottom
- The bottom padding of the image.left
- The left padding of the image.- Returns:
- A new
ImageConf
instance with the specified padding.
-
padding
This method allows you to specify the padding of the image. The padding is the space between the image and the inner component area.- Parameters:
topBottom
- The top and bottom padding of the image.leftRight
- The left and right padding of the image.- Returns:
- A new
ImageConf
instance with the specified padding.
-
padding
This method allows you to specify the padding for all sides of the image. The padding is the space between the image and the inner component area.- Parameters:
padding
- The padding of the image.- Returns:
- A new
ImageConf
instance with the specified padding.
-
offset
Use this to specify the vertical and horizontal offset by which the image will be moved and drawn onto the component.- Parameters:
x
- The horizontal offset.y
- The vertical offset.- Returns:
- A new
ImageConf
instance with the specified offset.
-
horizontalOffset
Use this to specify the horizontal offset by which the image will be moved and drawn onto the component.- Parameters:
x
- The horizontal offset.- Returns:
- A new
ImageConf
instance with the specified offset.
-
verticalOffset
Use this to specify the vertical offset by which the image will be moved and drawn onto the component.- Parameters:
y
- The vertical offset.- Returns:
- A new
ImageConf
instance with the specified offset.
-
clipTo
Use this to specify the clip area of the image, which determines on which part of the component the image will be drawn. TheUI.ComponentArea
enum defines the following clip areas:UI.ComponentArea.ALL
- The image will be drawn onto the entire component, which is the union of all other clip areas (INTERIOR + EXTERIOR + BORDER + CONTENT
).UI.ComponentArea.INTERIOR
- The image will be drawn onto the inner component area, which is defined asALL - EXTERIOR - BORDER
.UI.ComponentArea.EXTERIOR
- The image will be drawn onto the outer component area, which can be expressed asALL - INTERIOR - BORDER
, orALL - CONTENT
.UI.ComponentArea.BORDER
- The image will be drawn onto the border of the component, which is the area between the inner and outer component area and which can be expressed asALL - INTERIOR - EXTERIOR
.UI.ComponentArea.BODY
- The image will be drawn onto the component body, which is the inner component area including the border area. It can be expressed asALL - EXTERIOR
, orINTERIOR + BORDER
.
UI.ComponentArea.INTERIOR
, which means that the image will be drawn onto the inner component area.Use
UI.ComponentArea.ALL
to draw the image without any additional clipping onto the entire component, which may also cover the border and margin area of the component.- Parameters:
clipArea
- The clip area of the image.- Returns:
- A new
ImageConf
instance with the specified clip area.
-
simplified
-
hashCode
public int hashCode() -
equals
-
toString
-