Change build scripts
[jvcard.git] / src / com / googlecode / lanterna / terminal / swing / TerminalEmulatorDeviceConfiguration.java
CommitLineData
a3b510ab
NR
1/*
2 * This file is part of lanterna (http://code.google.com/p/lanterna/).
3 *
4 * lanterna is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Copyright (C) 2010-2015 Martin
18 */
19package com.googlecode.lanterna.terminal.swing;
20
21import com.googlecode.lanterna.TextColor;
22
23/**
24 * Object that encapsulates the configuration parameters for the terminal 'device' that a SwingTerminal is emulating.
25 * This includes properties such as the shape of the cursor, the color of the cursor, how large scrollback is available
26 * and if the cursor should blink or not.
27 * @author martin
28 */
29public class TerminalEmulatorDeviceConfiguration {
30
31 /**
32 * This is a static reference to the default terminal device configuration. Use this one if you are unsure.
33 */
34 public static TerminalEmulatorDeviceConfiguration getDefault() {
35 return new TerminalEmulatorDeviceConfiguration();
36 }
37
38 private final int lineBufferScrollbackSize;
39 private final int blinkLengthInMilliSeconds;
40 private final CursorStyle cursorStyle;
41 private final TextColor cursorColor;
42 private final boolean cursorBlinking;
43
44 /**
45 * Creates a new terminal device configuration object with all the defaults set
46 */
47 @SuppressWarnings("WeakerAccess")
48 public TerminalEmulatorDeviceConfiguration() {
49 this(2000, 500, CursorStyle.REVERSED, new TextColor.RGB(255, 255, 255), false);
50 }
51
52 /**
53 * Creates a new terminal device configuration object with all configurable values specified.
54 * @param lineBufferScrollbackSize How many lines of scrollback buffer should the terminal save?
55 * @param blinkLengthInMilliSeconds How many milliseconds does a 'blink' last
56 * @param cursorStyle Style of the terminal text cursor
57 * @param cursorColor Color of the terminal text cursor
58 * @param cursorBlinking Should the terminal text cursor blink?
59 */
60 @SuppressWarnings("WeakerAccess")
61 public TerminalEmulatorDeviceConfiguration(int lineBufferScrollbackSize, int blinkLengthInMilliSeconds, CursorStyle cursorStyle, TextColor cursorColor, boolean cursorBlinking) {
62 this.lineBufferScrollbackSize = lineBufferScrollbackSize;
63 this.blinkLengthInMilliSeconds = blinkLengthInMilliSeconds;
64 this.cursorStyle = cursorStyle;
65 this.cursorColor = cursorColor;
66 this.cursorBlinking = cursorBlinking;
67 }
68
69 /**
70 * Returns the length of a 'blink', which is the interval time a character with the blink SGR enabled with be drawn
71 * with foreground color and background color set to the same.
72 * @return Milliseconds of a blink interval
73 */
74 public int getBlinkLengthInMilliSeconds() {
75 return blinkLengthInMilliSeconds;
76 }
77
78 /**
79 * How many lines of history should be saved so the user can scroll back to them?
80 * @return Number of lines in the scrollback buffer
81 */
82 public int getLineBufferScrollbackSize() {
83 return lineBufferScrollbackSize;
84 }
85
86 /**
87 * Style the text cursor should take
88 * @return Text cursor style
89 * @see TerminalEmulatorDeviceConfiguration.CursorStyle
90 */
91 public CursorStyle getCursorStyle() {
92 return cursorStyle;
93 }
94
95 /**
96 * What color to draw the text cursor color in
97 * @return Color of the text cursor
98 */
99 public TextColor getCursorColor() {
100 return cursorColor;
101 }
102
103 /**
104 * Should the text cursor be blinking
105 * @return {@code true} if the text cursor should be blinking
106 */
107 @SuppressWarnings("BooleanMethodIsAlwaysInverted")
108 public boolean isCursorBlinking() {
109 return cursorBlinking;
110 }
111
112 /**
113 * Returns a copy of this device configuration but with a different size of the scrollback buffer
114 * @param lineBufferScrollbackSize Size of the scrollback buffer (in number of lines) the copy should have
115 * @return Copy of this device configuration with a specified size for the scrollback buffer
116 */
117 public TerminalEmulatorDeviceConfiguration withLineBufferScrollbackSize(int lineBufferScrollbackSize) {
118 if(this.lineBufferScrollbackSize == lineBufferScrollbackSize) {
119 return this;
120 }
121 else {
122 return new TerminalEmulatorDeviceConfiguration(
123 lineBufferScrollbackSize,
124 blinkLengthInMilliSeconds,
125 cursorStyle,
126 cursorColor,
127 cursorBlinking);
128 }
129 }
130
131 /**
132 * Different cursor styles supported by SwingTerminal
133 */
134 public enum CursorStyle {
135 /**
136 * The cursor is drawn by inverting the front- and background colors of the cursor position
137 */
138 REVERSED,
139 /**
140 * The cursor is drawn by using the cursor color as the background color for the character at the cursor position
141 */
142 FIXED_BACKGROUND,
143 /**
144 * The cursor is rendered as a thick horizontal line at the bottom of the character
145 */
146 UNDER_BAR,
147 /**
148 * The cursor is rendered as a left-side aligned vertical line
149 */
150 VERTICAL_BAR,
151 ;
152 }
153}