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 Details

  • Constructor Details

    • Toolbox

      public Toolbox()
  • Method Details

    • registerScaler

      public static void registerScaler​(Class<?> jComponentSuperclass, ComponentScaler scaler)
      Adds a new component scaler to the automatic scaling routine.
      Parameters:
      jComponentSuperclass - the super JComponent for which the scaler is
      scaler - newly implemented ComponentScaler sub-type
      See Also:
      ComponentRegulator.registerNewScaler(Class, ComponentScaler)
    • addScalingListener

      public static void addScalingListener​(PropertyChangeListener listener)
      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

      public static void removeScalingListener​(PropertyChangeListener listener)
      Remove a previously add PropertyChangeListener. Nothing happens, if the removal fails.
      Parameters:
      listener -
    • registerSliderChangeListeners

      public 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. the live scaling itself.
      Parameters:
      changeListeners -
    • getCurrentState

      public static String getCurrentState()
      Get the current state of the scaling workflow.
    • getState

      public static org.vanted.scaling.AutomatonBean.State getState​(String value)
      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 - if value is null.
    • isComponentScaled

      public 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.
      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

      public 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. 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 types
      extra - if some other specific type is necessary (UL_TYPE_EXTRA)
    • resetScalingOf

      public static void resetScalingOf​(JComponent component, float previousDPIratio)
      Reset the scaling of component 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

      public static void scaleComponent​(JComponent component, boolean check)
      Version of scaleComponent(JComponent, float, boolean) using the default DPI scaling ratio.
      Parameters:
      component - container to start scaling from
      check - if true it will make sure to avoid doubly scaling
    • scaleComponent

      public static void scaleComponent​(JComponent component, float DPIratio, boolean check)
      This automatically marks the component and its children as scaled, while doing so.
      Parameters:
      component - container to start scaling from
      DPIratio - 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.