2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2017 Kevin Lamonte
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
29 package jexer
.session
;
31 import java
.awt
.Frame
;
32 import java
.awt
.Insets
;
35 * SwingSessionInfo provides a session implementation with a callback into an
36 * Swing Frame to support queryWindowSize(). The username is blank, language
37 * is "en_US", with a 132x40 text window.
39 public final class SwingSessionInfo
implements SessionInfo
{
47 * The width of a text cell in pixels.
49 private int textWidth
;
52 * The height of a text cell in pixels.
54 private int textHeight
;
59 private String username
= "";
64 private String language
= "en_US";
69 private int windowWidth
= 80;
74 private int windowHeight
= 25;
79 * @return the username
81 public String
getUsername() {
88 * @param username the value
90 public void setUsername(final String username
) {
91 this.username
= username
;
97 * @return the language
99 public String
getLanguage() {
100 return this.language
;
106 * @param language the value
108 public void setLanguage(final String language
) {
109 this.language
= language
;
113 * Text window width getter.
115 * @return the window width
117 public int getWindowWidth() {
122 * Text window height getter.
124 * @return the window height
126 public int getWindowHeight() {
131 * Public constructor.
133 * @param frame the Swing Frame
134 * @param textWidth the width of a cell in pixels
135 * @param textHeight the height of a cell in pixels
136 * @param windowWidth the number of text columns to start with
137 * @param windowHeight the number of text rows to start with
139 public SwingSessionInfo(final Frame frame
, final int textWidth
,
140 final int textHeight
, final int windowWidth
, final int windowHeight
) {
143 this.textWidth
= textWidth
;
144 this.textHeight
= textHeight
;
145 this.windowWidth
= windowWidth
;
146 this.windowHeight
= windowHeight
;
150 * Re-query the text window size.
152 public void queryWindowSize() {
153 Insets insets
= frame
.getInsets();
154 int height
= frame
.getHeight() - insets
.top
- insets
.bottom
;
155 int width
= frame
.getWidth() - insets
.left
- insets
.right
;
156 windowWidth
= width
/ textWidth
;
157 windowHeight
= height
/ textHeight
;
160 System.err.printf("queryWindowSize(): frame %d %d window %d %d\n",
161 frame.getWidth(), frame.getHeight(),
162 windowWidth, windowHeight);