2 * Jexer - Java Text User Interface
4 * License: LGPLv3 or later
6 * This module is licensed under the GNU Lesser General Public License
7 * Version 3. Please see the file "COPYING" in this directory for more
8 * information about the GNU Lesser General Public License Version 3.
10 * Copyright (C) 2015 Kevin Lamonte
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 3 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this program; if not, see
24 * http://www.gnu.org/licenses/, or write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
28 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
31 package jexer
.session
;
33 import java
.awt
.Frame
;
34 import java
.awt
.Insets
;
37 * SwingSessionInfo provides a session implementation with a callback into an
38 * Swing Frame to support queryWindowSize(). The username is blank, language
39 * is "en_US", with a 132x40 text window.
41 public final class SwingSessionInfo
implements SessionInfo
{
49 * The width of a text cell in pixels.
51 private int textWidth
;
54 * The height of a text cell in pixels.
56 private int textHeight
;
61 private String username
= "";
66 private String language
= "en_US";
71 private int windowWidth
= 132;
76 private int windowHeight
= 40;
81 * @return the username
83 public String
getUsername() {
90 * @param username the value
92 public void setUsername(final String username
) {
93 this.username
= username
;
99 * @return the language
101 public String
getLanguage() {
102 return this.language
;
108 * @param language the value
110 public void setLanguage(final String language
) {
111 this.language
= language
;
115 * Text window width getter.
117 * @return the window width
119 public int getWindowWidth() {
124 * Text window height getter.
126 * @return the window height
128 public int getWindowHeight() {
133 * Public constructor.
135 * @param frame the Swing Frame
136 * @param textWidth the width of a cell in pixels
137 * @param textHeight the height of a cell in pixels
139 public SwingSessionInfo(final Frame frame
, final int textWidth
,
140 final int textHeight
) {
143 this.textWidth
= textWidth
;
144 this.textHeight
= textHeight
;
148 * Re-query the text window size.
150 public void queryWindowSize() {
151 Insets insets
= frame
.getInsets();
152 int height
= frame
.getHeight() - insets
.top
- insets
.bottom
;
153 int width
= frame
.getWidth() - insets
.left
- insets
.right
;
154 windowWidth
= width
/ textWidth
;
155 windowHeight
= height
/ textHeight
;
158 System.err.printf("queryWindowSize(): frame %d %d window %d %d\n",
159 frame.getWidth(), frame.getHeight(),
160 windowWidth, windowHeight);