update roadmap
[fanfix.git] / src / jexer / session / SwingSessionInfo.java
CommitLineData
daa4106c 1/*
30bd4abd
KL
2 * Jexer - Java Text User Interface
3 *
e16dda65 4 * The MIT License (MIT)
30bd4abd 5 *
a2018e99 6 * Copyright (C) 2017 Kevin Lamonte
30bd4abd 7 *
e16dda65
KL
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:
30bd4abd 14 *
e16dda65
KL
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
30bd4abd 17 *
e16dda65
KL
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.
30bd4abd
KL
25 *
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
27 * @version 1
28 */
29package jexer.session;
30
31import java.awt.Frame;
32import java.awt.Insets;
33
34/**
a4406f4e
KL
35 * SwingSessionInfo provides a session implementation with a callback into an
36 * Swing Frame to support queryWindowSize(). The username is blank, language
bd8d51fa 37 * is "en_US", with a 132x40 text window.
30bd4abd 38 */
a4406f4e 39public final class SwingSessionInfo implements SessionInfo {
30bd4abd
KL
40
41 /**
a4406f4e 42 * The Swing Frame.
30bd4abd
KL
43 */
44 private Frame frame;
45
46 /**
47 * The width of a text cell in pixels.
48 */
49 private int textWidth;
50
51 /**
52 * The height of a text cell in pixels.
53 */
54 private int textHeight;
55
56 /**
57 * User name.
58 */
59 private String username = "";
60
61 /**
62 * Language.
63 */
64 private String language = "en_US";
65
66 /**
67 * Text window width.
68 */
55d2b2c2 69 private int windowWidth = 80;
30bd4abd
KL
70
71 /**
72 * Text window height.
73 */
55d2b2c2 74 private int windowHeight = 25;
30bd4abd
KL
75
76 /**
77 * Username getter.
78 *
79 * @return the username
80 */
81 public String getUsername() {
82 return this.username;
83 }
84
85 /**
86 * Username setter.
87 *
88 * @param username the value
89 */
90 public void setUsername(final String username) {
91 this.username = username;
92 }
93
94 /**
95 * Language getter.
96 *
97 * @return the language
98 */
99 public String getLanguage() {
100 return this.language;
101 }
102
103 /**
104 * Language setter.
105 *
106 * @param language the value
107 */
108 public void setLanguage(final String language) {
109 this.language = language;
110 }
111
112 /**
113 * Text window width getter.
114 *
115 * @return the window width
116 */
117 public int getWindowWidth() {
118 return windowWidth;
119 }
120
121 /**
122 * Text window height getter.
123 *
124 * @return the window height
125 */
126 public int getWindowHeight() {
127 return windowHeight;
128 }
129
130 /**
131 * Public constructor.
132 *
a4406f4e 133 * @param frame the Swing Frame
30bd4abd
KL
134 * @param textWidth the width of a cell in pixels
135 * @param textHeight the height of a cell in pixels
136 */
a4406f4e 137 public SwingSessionInfo(final Frame frame, final int textWidth,
30bd4abd
KL
138 final int textHeight) {
139
140 this.frame = frame;
141 this.textWidth = textWidth;
142 this.textHeight = textHeight;
143 }
144
145 /**
146 * Re-query the text window size.
147 */
148 public void queryWindowSize() {
149 Insets insets = frame.getInsets();
150 int height = frame.getHeight() - insets.top - insets.bottom;
151 int width = frame.getWidth() - insets.left - insets.right;
152 windowWidth = width / textWidth;
153 windowHeight = height / textHeight;
154
155 /*
156 System.err.printf("queryWindowSize(): frame %d %d window %d %d\n",
157 frame.getWidth(), frame.getHeight(),
158 windowWidth, windowHeight);
159 */
160
161 }
162
30bd4abd 163}