7457f57a0d73b185f1f618e4a035faade6e7c88b
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
.backend
;
31 import java
.awt
.Insets
;
34 * SwingSessionInfo provides a session implementation with a callback into
35 * Swing to support queryWindowSize(). The username is blank, language is
36 * "en_US", with a 80x25 text window.
38 public final class SwingSessionInfo
implements SessionInfo
{
41 * The Swing JFrame or JComponent.
43 private SwingComponent swing
;
46 * The width of a text cell in pixels.
48 private int textWidth
= 10;
51 * The height of a text cell in pixels.
53 private int textHeight
= 10;
58 private String username
= "";
63 private String language
= "en_US";
68 private int windowWidth
= 80;
73 private int windowHeight
= 25;
78 * @return the username
80 public String
getUsername() {
87 * @param username the value
89 public void setUsername(final String username
) {
90 this.username
= username
;
96 * @return the language
98 public String
getLanguage() {
105 * @param language the value
107 public void setLanguage(final String language
) {
108 this.language
= language
;
112 * Text window width getter.
114 * @return the window width
116 public int getWindowWidth() {
121 * Text window height getter.
123 * @return the window height
125 public int getWindowHeight() {
130 * Set the dimensions of a single text cell.
132 * @param textWidth the width of a cell in pixels
133 * @param textHeight the height of a cell in pixels
135 public void setTextCellDimensions(final int textWidth
,
136 final int textHeight
) {
138 this.textWidth
= textWidth
;
139 this.textHeight
= textHeight
;
143 * Public constructor.
145 * @param swing the Swing JFrame or JComponent
146 * @param textWidth the width of a cell in pixels
147 * @param textHeight the height of a cell in pixels
149 public SwingSessionInfo(final SwingComponent swing
, final int textWidth
,
150 final int textHeight
) {
153 this.textWidth
= textWidth
;
154 this.textHeight
= textHeight
;
158 * Public constructor.
160 * @param swing the Swing JFrame or JComponent
161 * @param textWidth the width of a cell in pixels
162 * @param textHeight the height of a cell in pixels
163 * @param width the number of columns
164 * @param height the number of rows
166 public SwingSessionInfo(final SwingComponent swing
, final int textWidth
,
167 final int textHeight
, final int width
, final int height
) {
170 this.textWidth
= textWidth
;
171 this.textHeight
= textHeight
;
172 this.windowWidth
= width
;
173 this.windowHeight
= height
;
177 * Re-query the text window size.
179 public void queryWindowSize() {
180 Insets insets
= swing
.getInsets();
181 int width
= swing
.getWidth() - insets
.left
- insets
.right
;
182 int height
= swing
.getHeight() - insets
.top
- insets
.bottom
;
183 windowWidth
= width
/ textWidth
;
184 windowHeight
= height
/ textHeight
;
187 System.err.printf("queryWindowSize(): frame %d %d window %d %d\n",
188 swing.getWidth(), swing.getHeight(),
189 windowWidth, windowHeight);