Class ComponentRegulator
public class ComponentRegulator extends Object
ScalingCoordinator
, because of factor conversions.
This regulator is responsible for delegating the scaling external to the
LAF-defaults aspects of Swing components. It could be used for any user-set
modifications that have overwritten the LAF defaults. A typical example, are
any specified icons. Those are extracted from the component tree and rescaled
accordingly (see ComponentScaler and its subtypes).- Author:
- D. Garkov
-
Constructor Summary
Constructors Constructor Description ComponentRegulator(float scaleFactor)
Constructs a ComponentRegulator instance for upcoming component scaling. -
Method Summary
Modifier and Type Method Description static void
addScaledComponent(JComponent component)
Add the component to the set of already scaled components.void
clearModifiedPool()
Reset the supporting data structure for reuse.void
clearScalersMap()
Reset the supporting data structure for reuse.float
getFactor()
void
init(Container container)
Global system DPI scaling init! Scan and scale the components specifics.static boolean
isModifiedPoolRefilled()
True, when the modified pool has been recently cleared and re-created.static boolean
isScaled(JComponent component)
A rough measure to determine whethercomponent
had one of his scaling specifics - Font, Icon, Insets; scaled.static void
overrideForAll()
Override default behaviour to run proxy scalers before the application / init DPI scaler.static void
registerNewScaler(Class<?> superclass, ComponentScaler scaler)
Registers new ComponentScaler to use.void
scaleComponentsOf(Component[] components)
void
scaleComponentsOf(Component[] components, boolean check, boolean mark)
void
scaleComponentsOf(Container container)
Recursively iterates the component tree and initiate scaling for any encountered JComponents.void
scaleComponentsOf(Container container, boolean checkScaled, boolean mark)
Override ofscaleComponentsOf(Container)
, allowing for checking whether Containers components are scaled and only when those aren't then scaling, and additionally marking them as such or not.static void
scaleHTMLComponent(JComponent component)
Similar to conduct(JComponent), but for HTML scaling.void
setFactor(float factor)
-
Constructor Details
-
ComponentRegulator
public ComponentRegulator(float scaleFactor)Constructs a ComponentRegulator instance for upcoming component scaling.- Parameters:
scaleFactor
- the working scaling factor, a ratio between current actual DPI and to be emulated DPI.
-
-
Method Details
-
init
Global system DPI scaling init! Scan and scale the components specifics. This are taken from the specified parentContainer
container
.Important: Register any newly implemented component scalers before calling this method! (see: ComponentRegulator#registerNewScaler()}
- Parameters:
container
- , application main frame/window/container- Throws:
OutOfMemoryError
- when the allocated heap memory is not enough to hold all largely scaled components, such as Icons.
-
scaleComponentsOf
Recursively iterates the component tree and initiate scaling for any encountered JComponents.Important: Default behaviour is to first run system scaling and only then any other proxy scalers, to change this, call ComponentRegulator#override().
- Parameters:
container
- the container to crawl
-
scaleComponentsOf
- Parameters:
container
- the container to crawl
-
scaleComponentsOf
Override ofscaleComponentsOf(Container)
, allowing for checking whether Containers components are scaled and only when those aren't then scaling, and additionally marking them as such or not.scaleComponentsOf(Container)
doesn't check and marks all.Important: Default behaviour is to first run system scaling and only then any other proxy scalers, to change this, call ComponentRegulator#override().
- Parameters:
container
-checkScaled
- true to check components for being scaled and avoid double scalingmark
- true to mark any scaled components as such
-
scaleComponentsOf
- Parameters:
components
-check
- true to check components for being scaled and avoid double scalingmark
- true to mark any scaled components as such
-
overrideForAll
public static void overrideForAll()Override default behaviour to run proxy scalers before the application / init DPI scaler. -
scaleHTMLComponent
Similar to conduct(JComponent), but for HTML scaling. It crawls the list of scalers and matches the parameter to its appropriate scaler. It is responsibility of the matched scaler to have implemented such method.Note: No need to explicitly call this method, since it is part of the init(Container) workflow. Useful when implementing HTML support for a new scaler.
- Parameters:
component
-- See Also:
HTMLScaleSupport
-
addScaledComponent
Add the component to the set of already scaled components.- Parameters:
component
- to be stored component
-
registerNewScaler
Registers new ComponentScaler to use. Does not overwrite previous mappings and just returns. Please, use before init(Container).When adding new scalers be aware of the supertype-subtype relationship between the new and the already provided ones. In other words, the more generic the type, further back in the list should be placed.
- Parameters:
superclass
- the super class, or possibly even direct class for overriding purposes.scaler
- the newly implemented ComponentScaler
-
setFactor
public void setFactor(float factor) -
getFactor
public float getFactor() -
isScaled
A rough measure to determine whethercomponent
had one of his scaling specifics - Font, Icon, Insets; scaled.- Parameters:
component
- to be checked at runtime- Returns:
- true if the component has been scaled
-
clearModifiedPool
public void clearModifiedPool()Reset the supporting data structure for reuse. -
clearScalersMap
public void clearScalersMap()Reset the supporting data structure for reuse. -
isModifiedPoolRefilled
public static boolean isModifiedPoolRefilled()True, when the modified pool has been recently cleared and re-created. Also tells us whether a new scaling has been performed at runtime.Useful for reseting a DPI value that is being kept in the caller class.
- Returns:
- true when the pool with scaled components has been refilled. Once a pool has been refilled (i.e true), it changes its state effectively to filled (i.e false). Not filled also returns false.
- See Also:
Toolbox.wasScalingPerformed()
-