Add 'src/jexer/' from commit 'cf01c92f5809a0732409e280fb0f32f27393618d'
[nikiroo-utils.git] / src / jexer / backend / SwingSessionInfo.java
index b19c60f6a38e183b95781e46dbe8e12d116ddb89..2f74d7012130e0eeda1f44c4721396d645493b35 100644 (file)
@@ -3,7 +3,7 @@
  *
  * The MIT License (MIT)
  *
- * Copyright (C) 2017 Kevin Lamonte
+ * Copyright (C) 2019 Kevin Lamonte
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -179,6 +179,14 @@ public class SwingSessionInfo implements SessionInfo {
         Insets insets = swing.getInsets();
         int width = swing.getWidth() - insets.left - insets.right;
         int height = swing.getHeight() - insets.top - insets.bottom;
+        // In theory, if Java reported pixel-perfect dimensions, the
+        // expressions above would precisely line up with the requested
+        // window size from SwingComponent.setDimensions().  In practice,
+        // there appears to be a small difference.  Add half a text cell in
+        // both directions before the division to hopefully reach the same
+        // result as setDimensions() was supposed to give us.
+        width += (textWidth / 2);
+        height += (textHeight / 2);
         windowWidth = width / textWidth;
         windowHeight = height / textHeight;
 
@@ -187,7 +195,6 @@ public class SwingSessionInfo implements SessionInfo {
             swing.getWidth(), swing.getHeight(),
             windowWidth, windowHeight);
         */
-
     }
 
     // ------------------------------------------------------------------------
@@ -207,4 +214,13 @@ public class SwingSessionInfo implements SessionInfo {
         this.textHeight = textHeight;
     }
 
+    /**
+     * Getter for the underlying Swing component.
+     *
+     * @return the SwingComponent
+     */
+    public SwingComponent getSwingComponent() {
+        return swing;
+    }
+
 }