Package org.vanted.scaling
Class Toolbox
java.lang.Object
org.vanted.scaling.Toolbox
public class Toolbox extends Object
An utility class holding some handy methods for tweaking the scaling of some
components, where necessary.
- Author:
- D. Garkov
-
Field Summary
Fields Modifier and Type Field Description static String
STATE_IDLE
static String
STATE_ON_SLIDER
static String
STATE_ON_START
static String
STATE_RESCALED
static String
STATE_UNSCALED
static int
UL_TYPE_CIRCLE
static int
UL_TYPE_DISC
static int
UL_TYPE_EXTRA
static int
UL_TYPE_SQUARE
-
Constructor Summary
Constructors Constructor Description Toolbox()
-
Method Summary
Modifier and Type Method Description static void
addScalingListener(PropertyChangeListener listener)
Add a PropertyChangeListener to be informed about the workflow of the scaling procedures.static String
getCurrentState()
Get the current state of the scaling workflow.static float
getDPIScalingRatio()
This is the scaling factor that could be passed onto a ComponentScaler to directly scale an exception component, for example, without going through the whole component tree, when using the ScalingCoordinator.static int
getSliderValue()
static org.vanted.scaling.AutomatonBean.State
getState(String value)
Access other than the current states by value.static boolean
isComponentScaled(JComponent component)
A shortcut method for ComponentRegulator.isScaled(JComponent) that checks at runtime whether a component has been scaled with the most recent scaling procedure.static void
overrideExecutionOrder()
By overriding the order for all, you can allow proxy scalers to run before the application DPI scaling init.static void
registerScaler(Class<?> jComponentSuperclass, ComponentScaler scaler)
Adds a new component scaler to the automatic scaling routine.static void
registerSliderChangeListeners(ChangeListener[] changeListeners)
This method could be used to add any number of ChangeListeners, so that you could synchronize any actions with the movement of the slider, i.e.static void
removeScalingListener(PropertyChangeListener listener)
Remove a previously add PropertyChangeListener.static void
resetScalingOf(JComponent component, float previousDPIratio)
Reset the scaling ofcomponent
and its children.static void
scaleComponent(JComponent component, boolean check)
Version of scaleComponent(JComponent, float, boolean) using the default DPI scaling ratio.static void
scaleComponent(JComponent component, float DPIratio, boolean check)
This automatically marks the component and its children as scaled, while doing so.static void
scaleJEditorPaneUnorderedLists(JEditorPane ep, int type, String extra)
Prepares an <ul> by removing any style-type elements, such as bullets, squares, circles or discs with none.static boolean
wasScalingPerformed()
Another shortcut utility method, which determines whether a new scaling procedure has been performed at runtime.
-
Field Details
-
STATE_UNSCALED
- See Also:
- Constant Field Values
-
STATE_ON_START
- See Also:
- Constant Field Values
-
STATE_ON_SLIDER
- See Also:
- Constant Field Values
-
STATE_RESCALED
- See Also:
- Constant Field Values
-
STATE_IDLE
- See Also:
- Constant Field Values
-
UL_TYPE_DISC
public static final int UL_TYPE_DISC- See Also:
- Constant Field Values
-
UL_TYPE_CIRCLE
public static final int UL_TYPE_CIRCLE- See Also:
- Constant Field Values
-
UL_TYPE_SQUARE
public static final int UL_TYPE_SQUARE- See Also:
- Constant Field Values
-
UL_TYPE_EXTRA
public static final int UL_TYPE_EXTRA- See Also:
- Constant Field Values
-
-
Constructor Details
-
Toolbox
public Toolbox()
-
-
Method Details
-
registerScaler
Adds a new component scaler to the automatic scaling routine.- Parameters:
jComponentSuperclass
- the super JComponent for which the scaler isscaler
- newly implemented ComponentScaler sub-type- See Also:
ComponentRegulator.registerNewScaler(Class, ComponentScaler)
-
addScalingListener
Add a PropertyChangeListener to be informed about the workflow of the scaling procedures. If the listener has already been added, it does nothing. This could be useful when coordinating the scaling of any extra components that haven't been scaled globally. For instance, components that are initialized after the scaling is done or any that change their layout continuously. Then their respective scaler could be dispatched. One should listen for property change on the one of the three active states: onStart, onSlider and rescaled.For more information see AutomatonBean documentation.
- Parameters:
listener
-
-
removeScalingListener
Remove a previously add PropertyChangeListener. Nothing happens, if the removal fails.- Parameters:
listener
-
-
registerSliderChangeListeners
This method could be used to add any number of ChangeListeners, so that you could synchronize any actions with the movement of the slider, i.e. the live scaling itself.- Parameters:
changeListeners
-
-
getCurrentState
Get the current state of the scaling workflow. -
getState
Access other than the current states by value. The case doesn't matter. Alternatively, one could use the String State fields.- Parameters:
value
- Possible values are:unscaled, rescaled,
onStart, onSlider,
idle.- Returns:
- the state or an exception
- Throws:
IllegalArgumentException
- if the value is different from the allowed names.NullPointerException
- ifvalue
is null.
-
isComponentScaled
A shortcut method for ComponentRegulator.isScaled(JComponent) that checks at runtime whether a component has been scaled with the most recent scaling procedure.- Parameters:
component
- to be tested- Returns:
- true if the component has been scaled
-
wasScalingPerformed
public static boolean wasScalingPerformed()Another shortcut utility method, which determines whether a new scaling procedure has been performed at runtime. It is regarded as new only on the first call, after the DPI was changed. Any subsequent calls will be regarded as not new. This conform to the underlying method.- Returns:
- true if scaled anew at runtime.
- See Also:
ComponentRegulator.isModifiedPoolRefilled()
-
getDPIScalingRatio
public static float getDPIScalingRatio()This is the scaling factor that could be passed onto a ComponentScaler to directly scale an exception component, for example, without going through the whole component tree, when using the ScalingCoordinator. If the user hasn't performed any scaling operations so far, nothing will happen.- Returns:
- a ready to use scaling factor to use directly with scalers
-
scaleJEditorPaneUnorderedLists
Prepares an <ul> by removing any style-type elements, such as bullets, squares, circles or discs with none. Then the removed character ought be added as part of the contents to simulate styling. E.g.:<li>● Fist item </li>
<li>● Second item </li>Additionally, the padding is adjusted as well.
Warning: The JEditorPane should have as mime type "html".
- Parameters:
ep
-type
- one of the constant typesextra
- if some other specific type is necessary (UL_TYPE_EXTRA)
-
resetScalingOf
Reset the scaling ofcomponent
and its children. This does count as actual scaling and also does not check whether components have been scaled.- Parameters:
component
- whose scaling shall be reset (and of its children)previousDPIRatio
- the previous ratio
-
scaleComponent
Version of scaleComponent(JComponent, float, boolean) using the default DPI scaling ratio.- Parameters:
component
- container to start scaling fromcheck
- if true it will make sure to avoid doubly scaling
-
scaleComponent
This automatically marks the component and its children as scaled, while doing so.- Parameters:
component
- container to start scaling fromDPIratio
- see getDPIScalingRatio()check
- , if true it will make sure to avoid doubly scaling
-
getSliderValue
public static int getSliderValue() -
overrideExecutionOrder
public static void overrideExecutionOrder()By overriding the order for all, you can allow proxy scalers to run before the application DPI scaling init. This may lead to Exceptions. To scale a specific single component, you can just use one of the component scalers directly.
-