Fix UTF8 bug, create first executable JAR file
[jvcard.git] / src / com / googlecode / lanterna / gui2 / EmptySpace.java
... / ...
CommitLineData
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.gui2;
20
21import com.googlecode.lanterna.TerminalSize;
22import com.googlecode.lanterna.TextColor;
23
24/**
25 * Simple component which draws a solid color over its area. The size this component will request is specified through
26 * it's constructor.
27 *
28 * @author Martin
29 */
30public class EmptySpace extends AbstractComponent<EmptySpace> {
31 private final TerminalSize size;
32 private TextColor color;
33
34 /**
35 * Creates an EmptySpace with size 1x1 and a default color chosen from the theme
36 */
37 public EmptySpace() {
38 this(null, TerminalSize.ONE);
39 }
40
41 /**
42 * Creates an EmptySpace with a specified color and preferred size of 1x1
43 * @param color Color to use (null will make it use the theme)
44 */
45 public EmptySpace(TextColor color) {
46 this(color, TerminalSize.ONE);
47 }
48
49 /**
50 * Creates an EmptySpace with a specified preferred size (color will be chosen from the theme)
51 * @param size Preferred size
52 */
53 public EmptySpace(TerminalSize size) {
54 this(null, size);
55 }
56
57 /**
58 * Creates an EmptySpace with a specified color (null will make it use a color from the theme) and preferred size
59 * @param color Color to use (null will make it use the theme)
60 * @param size Preferred size
61 */
62 public EmptySpace(TextColor color, TerminalSize size) {
63 this.color = color;
64 this.size = size;
65 }
66
67 /**
68 * Changes the color this component will use when drawn
69 * @param color New color to draw the component with, if {@code null} then the component will use the theme's
70 * default color
71 */
72 public void setColor(TextColor color) {
73 this.color = color;
74 }
75
76 /**
77 * Returns the color this component is drawn with, or {@code null} if this component uses whatever the default color
78 * the theme is set to use
79 * @return Color used when drawing or {@code null} if it's using the theme
80 */
81 public TextColor getColor() {
82 return color;
83 }
84
85 @Override
86 protected ComponentRenderer<EmptySpace> createDefaultRenderer() {
87 return new ComponentRenderer<EmptySpace>() {
88
89 @Override
90 public TerminalSize getPreferredSize(EmptySpace component) {
91 return size;
92 }
93
94 @Override
95 public void drawComponent(TextGUIGraphics graphics, EmptySpace component) {
96 graphics.applyThemeStyle(graphics.getThemeDefinition(EmptySpace.class).getNormal());
97 if(color != null) {
98 graphics.setBackgroundColor(color);
99 }
100 graphics.fill(' ');
101 }
102 };
103 }
104}