public abstract class JBScalableIcon extends UserScaleContextSupport implements ScalableIcon
UserScaleContext
aware, assuming vector-based painting (system scale independent).Modifier | Constructor and Description |
---|---|
|
JBScalableIcon() |
protected |
JBScalableIcon(JBScalableIcon icon) |
Modifier and Type | Method and Description |
---|---|
float |
getScale() |
double |
getScale(DerivedScaleType type) |
double |
getScale(ScaleType type) |
T |
getScaleContext() |
protected boolean |
isIconPreScaled() |
javax.swing.Icon |
scale(float scale)
Creates and returns a scaled instance of the icon.
|
protected double |
scaleVal(double value)
An equivalent of scaleVal(value, PIX_SCALE)
|
protected double |
scaleVal(double value,
DerivedScaleType type)
Returns the value scaled according to the provided scale type
|
protected double |
scaleVal(double value,
ScaleType type)
Returns the value scaled according to the provided scale type
|
protected void |
setAutoUpdateScaleContext(boolean autoUpdate)
Sets whether the scale context should be auto-updated by the
Scaler . |
protected void |
setIconPreScaled(boolean preScaled) |
boolean |
setScale(Scale scale)
Sets the new scale in the context
|
java.lang.String |
toString() |
boolean |
updateScaleContext(UserScaleContext ctx)
Updates the current context with the state of the provided context.
|
JBScalableIcon |
withIconPreScaled(boolean preScaled)
The pre-scaled state of the icon indicates whether the initial size of the icon
is pre-scaled (by the global user scale) or not.
|
public JBScalableIcon()
protected JBScalableIcon(JBScalableIcon icon)
protected boolean isIconPreScaled()
protected void setIconPreScaled(boolean preScaled)
public JBScalableIcon withIconPreScaled(boolean preScaled)
For example, say we have an icon of 15x15 initial size, USR_SCALE is 1.5f, OBJ_SCALE is 1,5f. Math.round(Math.round(15 * USR_SCALE) * OBJ_SCALE) = 35 Math.round(15 * USR_SCALE * OBJ_SCALE) = 34
Thus, JBUI.scale(MyIcon.create(w, h)) is preferable to MyIcon.create(JBUI.scale(w), JBUI.scale(h)). Here [w, h] is "raw" unscaled size.
preScaled
- whether the icon is pre-scaled(JBScalableIcon)
protected void setAutoUpdateScaleContext(boolean autoUpdate)
Scaler
.
This ensures that scaleVal(double)
always uses up-to-date scale.
This is useful when the icon doesn't need to recalculate its internal sizes
on the scale context update and so it doesn't need the result of the update
and/or it doesn't listen for updates. Otherwise, the value should be set to
false and the scale context should be updated manually.
By default the value is true.
public float getScale()
getScale
in interface ScalableIcon
public javax.swing.Icon scale(float scale)
ScalableIcon
scale(1f)
will
return the icon in its original scale.
To scale this instance by n
times: scale(n * getScale())
.
Note that the methods Icon.getIconWidth()
and Icon.getIconHeight()
should return the scaled size of the icon.scale
in interface ScalableIcon
scale
- scaleprotected double scaleVal(double value)
protected double scaleVal(double value, ScaleType type)
protected double scaleVal(double value, DerivedScaleType type)
public java.lang.String toString()
toString
in class java.lang.Object
public T getScaleContext()
getScaleContext
in interface ScaleContextAware
public boolean updateScaleContext(UserScaleContext ctx)
ScaleContextAware
ctx
is null, then updates the current context via ScaleContext.update()
and returns the result.updateScaleContext
in interface ScaleContextAware
ctx
- the new scale contextpublic double getScale(ScaleType type)
getScale
in interface ScaleContextAware
public double getScale(DerivedScaleType type)
getScale
in interface ScaleContextAware
public boolean setScale(Scale scale)
ScaleContextAware
setScale
in interface ScaleContextAware