X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Fio%2FAWTScreen.java;h=208bea356496334386bf2ee0cd02b2172cdcdbe7;hb=091d8a06c7f9f91c2a15c9350b6502cf4c10f5a3;hp=f56f4238c765353ec325c5cbf080ed4558a3cb89;hpb=87a17f3ca4b2602c396afdbb13cccb4c1e7cbd38;p=nikiroo-utils.git diff --git a/src/jexer/io/AWTScreen.java b/src/jexer/io/AWTScreen.java index f56f423..208bea3 100644 --- a/src/jexer/io/AWTScreen.java +++ b/src/jexer/io/AWTScreen.java @@ -38,7 +38,6 @@ import java.awt.Color; import java.awt.Cursor; import java.awt.Font; import java.awt.FontMetrics; -import java.awt.Frame; import java.awt.Graphics; import java.awt.Insets; import java.awt.Point; @@ -47,6 +46,8 @@ import java.awt.Toolkit; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.io.InputStream; +import javax.swing.JFrame; +import javax.swing.SwingUtilities; /** * This Screen implementation draws to a Java AWT Frame. @@ -103,7 +104,12 @@ public final class AWTScreen extends Screen { /** * AWTFrame is our top-level hook into the AWT system. */ - class AWTFrame extends Frame { + class AWTFrame extends JFrame { + + /** + * Serializable version. + */ + private static final long serialVersionUID = 1; /** * The terminus font resource filename. @@ -236,7 +242,7 @@ public final class AWTScreen extends Screen { setDOSColors(); setTitle("Jexer Application"); - setBackground(java.awt.Color.black); + setBackground(Color.black); // setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR)); // setFont(new Font("Liberation Mono", Font.BOLD, 16)); // setFont(new Font(Font.MONOSPACED, Font.PLAIN, 16)); @@ -253,24 +259,28 @@ public final class AWTScreen extends Screen { // setFont(new Font("Liberation Mono", Font.PLAIN, 24)); setFont(new Font(Font.MONOSPACED, Font.PLAIN, 24)); } - setVisible(true); - resizeToScreen(); + pack(); // Kill the X11 cursor // Transparent 16 x 16 pixel cursor image. BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB); - // Create a new blank cursor. Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor( cursorImg, new Point(0, 0), "blank cursor"); setCursor(blankCursor); + + // Be capable of seeing Tab / Shift-Tab + setFocusTraversalKeysEnabled(false); + + // Save the text cell width/height + getFontDimensions(); } /** - * Resize to font dimensions. + * Figure out my font dimensions. */ - public void resizeToScreen() { + private void getFontDimensions() { Graphics gr = getGraphics(); FontMetrics fm = gr.getFontMetrics(); maxDescent = fm.getMaxDescent(); @@ -281,7 +291,12 @@ public final class AWTScreen extends Screen { // This also produces the same number, but works better for ugly // monospace. textHeight = fm.getMaxAscent() + maxDescent - leading; + } + /** + * Resize to font dimensions. + */ + public void resizeToScreen() { // Figure out the thickness of borders and use that to set the // final size. Insets insets = getInsets(); @@ -290,11 +305,6 @@ public final class AWTScreen extends Screen { setSize(textWidth * screen.width + insets.left + insets.right, textHeight * screen.height + insets.top + insets.bottom); - - /* - System.err.printf("W: %d H: %d MD: %d L: %d\n", textWidth, - textHeight, maxDescent, leading); - */ } /** @@ -333,7 +343,7 @@ public final class AWTScreen extends Screen { if (bounds != null) { // Only update what is in the bounds xCellMin = screen.textColumn(bounds.x); - xCellMax = screen.textColumn(bounds.x + bounds.width) + 1; + xCellMax = screen.textColumn(bounds.x + bounds.width); if (xCellMax > screen.width) { xCellMax = screen.width; } @@ -344,7 +354,7 @@ public final class AWTScreen extends Screen { xCellMin = 0; } yCellMin = screen.textRow(bounds.y); - yCellMax = screen.textRow(bounds.y + bounds.height) + 1; + yCellMax = screen.textRow(bounds.y + bounds.height); if (yCellMax > screen.height) { yCellMax = screen.height; } @@ -354,6 +364,9 @@ public final class AWTScreen extends Screen { if (yCellMin < 0) { yCellMin = 0; } + } else { + // We need a total repaint + reallyCleared = true; } // Prevent updates to the screen's data from the TApplication @@ -406,7 +419,8 @@ public final class AWTScreen extends Screen { reallyCleared = false; } // synchronized (screen) } - } + + } // class AWTFrame /** * The raw AWT Frame. Note package private access. @@ -417,17 +431,38 @@ public final class AWTScreen extends Screen { * Public constructor. */ public AWTScreen() { - frame = new AWTFrame(this); + try { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + AWTScreen.this.frame = new AWTFrame(AWTScreen.this); + AWTScreen.this.sessionInfo = + new AWTSessionInfo(AWTScreen.this.frame, + frame.textWidth, + frame.textHeight); + + AWTScreen.this.setDimensions(sessionInfo.getWindowWidth(), + sessionInfo.getWindowHeight()); + + AWTScreen.this.frame.resizeToScreen(); + AWTScreen.this.frame.setVisible(true); + } + } ); + } catch (Exception e) { + e.printStackTrace(); + } } + /** + * The sessionInfo. + */ + private AWTSessionInfo sessionInfo; + /** * Create the AWTSessionInfo. Note package private access. * * @return the sessionInfo */ AWTSessionInfo getSessionInfo() { - AWTSessionInfo sessionInfo = new AWTSessionInfo(frame, frame.textWidth, - frame.textHeight); return sessionInfo; }