* @author Kevin Lamonte [kevin.lamonte@gmail.com]
* @version 1
*/
-package jexer.session;
+package jexer.backend;
-import java.awt.Frame;
import java.awt.Insets;
/**
- * SwingSessionInfo provides a session implementation with a callback into an
- * Swing Frame to support queryWindowSize(). The username is blank, language
- * is "en_US", with a 132x40 text window.
+ * SwingSessionInfo provides a session implementation with a callback into
+ * Swing to support queryWindowSize(). The username is blank, language is
+ * "en_US", with a 80x25 text window.
*/
public final class SwingSessionInfo implements SessionInfo {
/**
- * The Swing Frame.
+ * The Swing JFrame or JComponent.
*/
- private Frame frame;
+ private SwingComponent swing;
/**
* The width of a text cell in pixels.
*/
- private int textWidth;
+ private int textWidth = 10;
/**
* The height of a text cell in pixels.
*/
- private int textHeight;
+ private int textHeight = 10;
/**
* User name.
return windowHeight;
}
+ /**
+ * Set the dimensions of a single text cell.
+ *
+ * @param textWidth the width of a cell in pixels
+ * @param textHeight the height of a cell in pixels
+ */
+ public void setTextCellDimensions(final int textWidth,
+ final int textHeight) {
+
+ this.textWidth = textWidth;
+ this.textHeight = textHeight;
+ }
+
/**
* Public constructor.
*
- * @param frame the Swing Frame
+ * @param swing the Swing JFrame or JComponent
* @param textWidth the width of a cell in pixels
* @param textHeight the height of a cell in pixels
- * @param windowWidth the number of text columns to start with
- * @param windowHeight the number of text rows to start with
*/
- public SwingSessionInfo(final Frame frame, final int textWidth,
- final int textHeight, final int windowWidth, final int windowHeight) {
+ public SwingSessionInfo(final SwingComponent swing, final int textWidth,
+ final int textHeight) {
- this.frame = frame;
- this.textWidth = textWidth;
- this.textHeight = textHeight;
- this.windowWidth = windowWidth;
- this.windowHeight = windowHeight;
+ this.swing = swing;
+ this.textWidth = textWidth;
+ this.textHeight = textHeight;
}
/**
* Re-query the text window size.
*/
public void queryWindowSize() {
- Insets insets = frame.getInsets();
- int height = frame.getHeight() - insets.top - insets.bottom;
- int width = frame.getWidth() - insets.left - insets.right;
+ Insets insets = swing.getInsets();
+ int width = swing.getWidth() - insets.left - insets.right;
+ int height = swing.getHeight() - insets.top - insets.bottom;
windowWidth = width / textWidth;
windowHeight = height / textHeight;
/*
System.err.printf("queryWindowSize(): frame %d %d window %d %d\n",
- frame.getWidth(), frame.getHeight(),
+ swing.getWidth(), swing.getHeight(),
windowWidth, windowHeight);
- */
+ */
}