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.
It will fill whatever area was specified using
clipTo(UI.ComponentArea).
The default area used for rendering the image style isUI.ComponentArea.INTERIOR - Image:
The image which will be drawn onto the component,
which may be specified as an instance of
Image,ImageIconor 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(int)then the image will be scaled to fit the inner component width, and if a height was not specified throughheight(int)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.INTERIORas 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. The primer color serves as a consistent
background color which will leak through the transparent parts of the image.
-
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.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.booleanfitMode(UI.FitComponent fit) There are different kinds of strategies to fit the image onto the component.inthashCode()height(int height) Ensures that the image has the specified height, irrespective of other configurations.
So, if aUI.FitComponentpolicy was supplied tofitMode(UI.FitComponent)which, for example, stretches the image to fill out the entire component, then supplying a customheightto this method will force this stretched image to have that specificheightwithout preserving its aspect ratio!
So you may end up rendering a distorted image if not careful.
Also note that the provided height is considered to include any padding supplied to methods likepadding(int),padding(int, int), orpadding(int, int, int, int).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 you want to draw onto the component.Here you can specify the image icon which will be drawn onto the component.image(IconDeclaration image) Here you can specify an image in the form of anIconDeclaration, which typically has aIconDeclaration.source()that holds a path to an image. If the suppliedIconDeclarationis path based, then it will be resolved relative to the classpath or as an absolute path.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 extra padding of the image's bounding rectangle.padding(int top, int right, int bottom, int left) This method allows you to specify extra padding to the rectangle where the image is drawn.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 background color rendered before the image is rendered.repeat(boolean repeat) If this flag is set totrue, then the image may be painted multiple times so that it fills out the entire inner component area.size(int width, int height) Ensures that the image has the specified width and height (including padding).
Note that the image may be rendered smaller than the specified dimensions if a padding was specified through methods likepadding(int),padding(int, int), orpadding(int, int, int, int).Ensures that the image has the specified width and height.Use this to specify an image directly in the form of an SVG string in your style.toString()verticalOffset(int y) Use this to specify the vertical offset by which the image will be moved and drawn onto the component.width(int width) Ensures that the image has the specified width, irrespective of other configurations.
So, if aUI.FitComponentpolicy was supplied tofitMode(UI.FitComponent)which, for example, stretches the image to fill out the entire component, then supplying a customwidthto this method will force this stretched image to have that specificwidthwithout preserving its aspect ratio!
So you may end up rendering a distorted image if not careful.
Also note that the provided width is considered to include any padding supplied to methods likepadding(int),padding(int, int), orpadding(int, int, int, int).
-
Method Details
-
primer
Here you can specify the primer color of the image style which will be used as background color rendered before the image is rendered.
Note that the primer color may not necessarily visible if the specified image is fully opaque, and fills the entire component.- Parameters:
color- The primer color of the image style.- Returns:
- A new
ImageConfinstance with the specified primer color.
-
image
Here you can specify the image which will be drawn onto the component. The supplied object must be aa subtype ofImage, likeBufferedImagefor example.
Please note that using this method will override whatever information was previously passed to
image(ImageIcon),image(IconDeclaration),image(String)orsvg(String)!- Parameters:
image- The image which will be drawn onto the component.- Returns:
- A new
ImageConfinstance 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 ofImageIconimplementation. So this may also be anSvgIconfor example, which is aImageIconsubtype...
Please note that using this method will override whatever information was previously passed to
svg(String),image(IconDeclaration),image(String)andimage(Image)!- Parameters:
image- The image icon which will be drawn onto the component.- Returns:
- A new
ImageConfinstance with the specified image.
-
image
Here you can specify an image in the form of anIconDeclaration, which typically has aIconDeclaration.source()that holds a path to an image. If the suppliedIconDeclarationis path based, then it will be resolved relative to the classpath or as an absolute path. However, the declaration may also be based on an SVG String as source (seeIconDeclaration.ofSvg(String)).
If the icon could not be found or parsed, then the image will not be drawn.
Please note that using this method will override whatever information was previously passed to
image(ImageIcon),svg(String),image(String)andimage(Image)!- Parameters:
image- The path to the (icon) image or SVG String in the form of anIconDeclaration.- Returns:
- A new
ImageConfinstance with the specified icon declaration for resolving an image. - Throws:
NullPointerException- If the specifiedimageis null.
-
svg
Use this to specify an image directly in the form of an SVG string in your style.
The suppliedStringwill be parsed and converted into aSvgIcon, which can render itself onto a component according to your desired configuration...
This is equivalent to calling:
If the supplied SVG is invalid, then this will result in an empty.image(IconDeclaration.ofSvg("..."))SvgIcon, which will simply not render anything.
Please note that using this method will override whatever information was previously passed to
image(ImageIcon),image(IconDeclaration),image(String)andimage(Image)!- Parameters:
svg- AStringholding an XML based SVG document.- Returns:
- A new
ImageConfinstance with the specified SVG String as source to be rendered as image. - Throws:
NullPointerException- If the specifiedsvgis null.
-
image
Here you can specify the path to the image you want to draw onto the component. The underlying icon will be loaded, cached and rendered for you automatically. 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)).
Please note that using this method will override whatever information was previously passed to
image(ImageIcon),image(IconDeclaration),svg(String)andimage(Image)!- Parameters:
path- The path to the (icon) image.- Returns:
- A new
ImageConfinstance with the specified image. - Throws:
NullPointerException- If the specifiedpathis 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
ImageConfinstance with the specified placement. - Throws:
NullPointerException- If the supplied enum constant isnull.
-
repeat
If this flag is set totrue, then the image may be painted multiple times so that it fills out 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- Whether the image should be painted repeatedly across the inner component area.- Returns:
- A new
ImageConfinstance with the specifiedrepeatflag 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. This means that if no custom width was specified throughwidth(int)then the image will be scaled to fit the inner component width. Also, if no custom height was passed toheight(int)then the image will be scaled to fit the inner component height.
Note that what we mean by the "inner component area" is the area enclosed by the border. It is represented by theUI.ComponentArea.INTERIORconstant.- 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
ImageConfinstance with the specifiedautoFitflag value.
-
fitMode
There are different kinds of strategies to fit the image onto the component. These strategies are identified using theUI.FitComponentenum 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. Note that this will only scale the width of the image, but not its height, and so the inherent aspect ratio of the image may not be preserved!UILayoutConstants.HEIGHT(int, int, int)- The image will be scaled to fit the inner component height. Note that this will only scale the height of the image, but not its width, and so the inherent aspect ratio of the image may not be preserved!UI.FitComponent.WIDTH_AND_HEIGHT- The image will be scaled to fit both the component width and height. Note that this may override the inherent aspect ratio of the image in favor of the aspect ratio of the component dimensions!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.UI.FitComponent.UNDEFINED- How the image will be scaled to fit the component is unclear. Another property may override this, but typically the behavior is similar toUI.FitComponent.NO.
So for example, if you pass anSvgIcontoimage(ImageIcon)which whoseSvgIcon.getFitComponent()is notUNDEFINED, then this will override the "fit component" policy of this config object.
- Parameters:
fit- The fit mode of the image.- Returns:
- A new
ImageConfinstance with the specifiedfitmode. - Throws:
NullPointerException- If the supplied enum constant isnull.
-
width
Ensures that the image has the specified width, irrespective of other configurations.
So, if aUI.FitComponentpolicy was supplied tofitMode(UI.FitComponent)which, for example, stretches the image to fill out the entire component, then supplying a customwidthto this method will force this stretched image to have that specificwidthwithout preserving its aspect ratio!
So you may end up rendering a distorted image if not careful.
Also note that the provided width is considered to include any padding supplied to methods likepadding(int),padding(int, int), orpadding(int, int, int, int).- Parameters:
width- The desired width of the rendered image.- Returns:
- A new
ImageConfinstance with the specifiedwidth.
-
height
Ensures that the image has the specified height, irrespective of other configurations.
So, if aUI.FitComponentpolicy was supplied tofitMode(UI.FitComponent)which, for example, stretches the image to fill out the entire component, then supplying a customheightto this method will force this stretched image to have that specificheightwithout preserving its aspect ratio!
So you may end up rendering a distorted image if not careful.
Also note that the provided height is considered to include any padding supplied to methods likepadding(int),padding(int, int), orpadding(int, int, int, int).- Parameters:
height- The desired height of the rendered image, including top and bottom padding.- Returns:
- A new
ImageConfinstance with the specifiedheight.
-
size
Ensures that the image has the specified width and height (including padding).
Note that the image may be rendered smaller than the specified dimensions if a padding was specified through methods likepadding(int),padding(int, int), orpadding(int, int, int, int).- Parameters:
width- The width of the image, including left and right padding if specified.height- The height of the image, including top and bottom padding if specified.- Returns:
- A new
ImageConfinstance with the specifiedwidthandheight.
-
size
Ensures that the image has the specified width and height. Note that if the aspect ratio of these two dimensions does not match the innate aspect ratio of the image, then the final render of the image will end up looking distorted.- Parameters:
size- The desired size of the rendered image.- Returns:
- A new
ImageConfinstance 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
ImageConfinstance with the specified opacity.
-
padding
This method allows you to specify extra padding to the rectangle where the image is drawn. This will eat into the native size of the image, or the custom image dimensions supplied to methods likewidth(int),height(int)andsize(int, int).- 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
ImageConfinstance with the specified padding.
-
padding
This method allows you to specify extra padding of the image's bounding rectangle. This will eat into the native size of the image, or the custom image dimensions supplied to methods likewidth(int),height(int)andsize(int, int).- Parameters:
topBottom- The top and bottom padding of the image.leftRight- The left and right padding of the image.- Returns:
- A new
ImageConfinstance with the specified padding.
-
padding
This method allows you to specify the padding for all sides of the image. This will eat into the native size of the image, or the custom image dimensions supplied to methods likewidth(int),height(int)andsize(int, int).- Parameters:
padding- The padding of the image.- Returns:
- A new
ImageConfinstance 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. Note that this is relative to theUI.Placementpolicy of the image specified throughplacement(UI.Placement).
The default placement of an image isUI.Placement.CENTER, and so the offset will start from there...- Parameters:
x- The horizontal offset relative to theplacement(UI.Placement)of the image.y- The vertical offset relative to theplacement(UI.Placement)of the image.- Returns:
- A new
ImageConfinstance with the specified offset.
-
horizontalOffset
Use this to specify the horizontal offset by which the image will be moved and drawn onto the component. Note that this is relative to theUI.Placementpolicy of the image specified throughplacement(UI.Placement).
The default placement of an image isUI.Placement.CENTER, and so the offset will start from there...- Parameters:
x- The horizontal offset relative to theplacement(UI.Placement)of the image.- Returns:
- A new
ImageConfinstance with the specified offset.
-
verticalOffset
Use this to specify the vertical offset by which the image will be moved and drawn onto the component. Note that this is relative to theUI.Placementpolicy of the image specified throughplacement(UI.Placement).
The default placement of an image isUI.Placement.CENTER, and so the offset will start from there...- Parameters:
y- The vertical offset relative to theplacement(UI.Placement)of the image.- Returns:
- A new
ImageConfinstance 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.ComponentAreaenum 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.ALLto 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
ImageConfinstance with the specified clip area.
-
simplified
-
hashCode
public int hashCode() -
equals
-
toString
-