package eg.utils;

import java.awt.Dimension;
import java.awt.Toolkit;

/**
 * Static constants and methods to obtain quantities that depend on the screen size and
 * resolution
 */
public class ScreenParams {

   private final static boolean IS_WINDOWS
         = System.getProperty("os.name").toLowerCase().contains("win");
   private final static String VERSION = System.getProperty("java.version");
   private final static boolean IS_JAVA_9_OR_HIGHER = !VERSION.startsWith("1.8");
   private final static int SCREEN_RES
         = Toolkit.getDefaultToolkit().getScreenResolution();
   private final static double SCREEN_RES_RATIO = SCREEN_RES / 72.0;

  /**
   * The screen size */
   public final static Dimension SCREEN_SIZE
        = Toolkit.getDefaultToolkit().getScreenSize();

   /**
    * Returns a new <code>Dimension</code> that is scaled to the
    * screen resolution ratio
    * @see #scaledSize(double)
    *
    * @param width  the width in pt
    * @param height  the height in pt
    * @return   the Dimension
    */
   public static Dimension scaledDimension(int width, int height) {
      width = scaledSize(width);
      height = scaledSize(height);
      return new Dimension(width, height);
   }

   /**
    * Returns a size that scales the specified size depending on the
    * screen resolution, the Java version and the OS.
    * <p>
    * If the program is run using Java 8 the scaled size is the product
    * of the specified size and the resolution ratio. This ratio is the
    * screen resolution divided by the graphics resolution assumed by
    * Java (72 dpi).
    * <p>
    * If the program is run using a higher Java version the specified size
    * is returned unchanged or, if the OS is Windows, multiplied with the
    * ratio (96/72).
    *
    * @param size  the size
    * @return  the rounded rescaled size
    */
   public static int scaledSize(double size) {
      if (IS_JAVA_9_OR_HIGHER) {
         if (IS_WINDOWS) {
            return (int) (Math.round(size * 96/72));
         }
         else {
            return (int) size;
         }
      }
      else {
         return (int) (Math.round(size * SCREEN_RES_RATIO));
      }
   }
}

@@ -140,16 +140,19 @@
 d on the
+%0A *
  screen 
@@ -159,19 +159,16 @@
 size and
-%0A *
  resolut
@@ -315,24 +315,34 @@
 ins(%22win%22);%0A
+         %0A
    private f
@@ -589,16 +589,26 @@
 tion();%0A
+         %0A
    priva
@@ -1263,43 +1263,19 @@
  a s
-ize that scales the specifi
+cal
 ed size 
 depe
@@ -1274,30 +1274,61 @@
 ize 
+that 
 depend
-ing 
+s on the Java versi
 on
+,
  the
+ OS or
 %0A    *
+ the
  scr
@@ -1345,37 +1345,8 @@
 tion
-, the Java version and the OS
 .%0A  
@@ -1763,15 +1763,13 @@
 tio 
-(
 96/72
-)
 .%0A  
@@ -1795,24 +1795,33 @@
 ze  the size
+ to scale
 %0A    * @retu
@@ -1836,18 +1836,16 @@
 rounded 
-re
 scaled s
@@ -2008,17 +2008,19 @@
 ize * 96
-/
+ / 
 72));%0A  
@@ -2181,10 +2181,523 @@
  %7D%0A   %7D%0A
+   %0A   /**%0A    * Returns a size that reverts the scaling calculated by %7B@link #scaledSize%7D%0A    *%0A    * @param size  the size to scale%0A    * @return  the rounded scaled size%0A    */%0A   public static int invertedScaledSize(int size) %7B%0A      if (IS_JAVA_9_OR_HIGHER) %7B%0A         if (IS_WINDOWS) %7B%0A            return (int) (Math.round(size / (96 / 72)));%0A         %7D%0A         else %7B%0A            return (int) size;%0A         %7D%0A      %7D%0A      else %7B%0A         return (int) (Math.round(size / SCREEN_RES_RATIO));%0A      %7D%0A   %7D%0A
 %7D%0A

add method to obtain the size that is the reverted scaled size