2 * This file is part of lanterna (http://code.google.com/p/lanterna/).
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.
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.
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/>.
17 * Copyright (C) 2010-2015 Martin
19 package com
.googlecode
.lanterna
.gui2
;
21 import com
.googlecode
.lanterna
.Symbols
;
22 import com
.googlecode
.lanterna
.TerminalSize
;
23 import com
.googlecode
.lanterna
.graphics
.ThemeDefinition
;
26 * Static non-interactive component that is typically rendered as a single line. Normally this component is used to
27 * separate component from each other in situations where a bordered panel isn't ideal. By default the separator will
28 * ask for a size of 1x1 so you'll need to make it bigger, either through the layout manager or by overriding the
32 public class Separator
extends AbstractComponent
<Separator
> {
34 private final Direction direction
;
37 * Creates a new {@code Separator} for a specific direction, which will decide whether to draw a horizontal line or
40 * @param direction Direction of the line to draw within the separator
42 public Separator(Direction direction
) {
43 if(direction
== null) {
44 throw new IllegalArgumentException("Cannot create a separator with a null direction");
46 this.direction
= direction
;
50 * Returns the direction of the line drawn for this separator
51 * @return Direction of the line drawn for this separator
53 public Direction
getDirection() {
58 protected DefaultSeparatorRenderer
createDefaultRenderer() {
59 return new DefaultSeparatorRenderer();
63 * Helper interface that doesn't add any new methods but makes coding new button renderers a little bit more clear
65 public static abstract class SeparatorRenderer
implements ComponentRenderer
<Separator
> {
69 * This is the default separator renderer that is used if you don't override anything. With this renderer, the
70 * separator has a preferred size of one but will take up the whole area it is given and fill that space with either
71 * horizontal or vertical lines, depending on the direction of the {@code Separator}
73 public static class DefaultSeparatorRenderer
extends SeparatorRenderer
{
75 public TerminalSize
getPreferredSize(Separator component
) {
76 return TerminalSize
.ONE
;
80 public void drawComponent(TextGUIGraphics graphics
, Separator component
) {
81 ThemeDefinition themeDefinition
= graphics
.getThemeDefinition(Separator
.class);
82 graphics
.applyThemeStyle(themeDefinition
.getNormal());
83 char character
= themeDefinition
.getCharacter(component
.getDirection().name().toUpperCase(),
84 component
.getDirection() == Direction
.HORIZONTAL ? Symbols
.SINGLE_LINE_HORIZONTAL
: Symbols
.SINGLE_LINE_VERTICAL
);
85 graphics
.fill(character
);