color chooser widget
[fanfix.git] / src / jexer / session / SwingSessionInfo.java
1 /*
2 * Jexer - Java Text User Interface
3 *
4 * License: LGPLv3 or later
5 *
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.
9 *
10 * Copyright (C) 2015 Kevin Lamonte
11 *
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.
16 *
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.
21 *
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
26 * 02110-1301 USA
27 *
28 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
29 * @version 1
30 */
31 package jexer.session;
32
33 import java.awt.Frame;
34 import java.awt.Insets;
35
36 /**
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.
40 */
41 public final class SwingSessionInfo implements SessionInfo {
42
43 /**
44 * The Swing Frame.
45 */
46 private Frame frame;
47
48 /**
49 * The width of a text cell in pixels.
50 */
51 private int textWidth;
52
53 /**
54 * The height of a text cell in pixels.
55 */
56 private int textHeight;
57
58 /**
59 * User name.
60 */
61 private String username = "";
62
63 /**
64 * Language.
65 */
66 private String language = "en_US";
67
68 /**
69 * Text window width.
70 */
71 private int windowWidth = 132;
72
73 /**
74 * Text window height.
75 */
76 private int windowHeight = 40;
77
78 /**
79 * Username getter.
80 *
81 * @return the username
82 */
83 public String getUsername() {
84 return this.username;
85 }
86
87 /**
88 * Username setter.
89 *
90 * @param username the value
91 */
92 public void setUsername(final String username) {
93 this.username = username;
94 }
95
96 /**
97 * Language getter.
98 *
99 * @return the language
100 */
101 public String getLanguage() {
102 return this.language;
103 }
104
105 /**
106 * Language setter.
107 *
108 * @param language the value
109 */
110 public void setLanguage(final String language) {
111 this.language = language;
112 }
113
114 /**
115 * Text window width getter.
116 *
117 * @return the window width
118 */
119 public int getWindowWidth() {
120 return windowWidth;
121 }
122
123 /**
124 * Text window height getter.
125 *
126 * @return the window height
127 */
128 public int getWindowHeight() {
129 return windowHeight;
130 }
131
132 /**
133 * Public constructor.
134 *
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
138 */
139 public SwingSessionInfo(final Frame frame, final int textWidth,
140 final int textHeight) {
141
142 this.frame = frame;
143 this.textWidth = textWidth;
144 this.textHeight = textHeight;
145 }
146
147 /**
148 * Re-query the text window size.
149 */
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;
156
157 /*
158 System.err.printf("queryWindowSize(): frame %d %d window %d %d\n",
159 frame.getWidth(), frame.getHeight(),
160 windowWidth, windowHeight);
161 */
162
163 }
164
165 }