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
.*;
22 import com
.googlecode
.lanterna
.graphics
.ThemeDefinition
;
25 * Default window decoration renderer that is used unless overridden with another decoration renderer. The windows are
26 * drawn using a bevel colored line and the window title in the top-left corner, very similar to ordinary titled
31 public class DefaultWindowDecorationRenderer
implements WindowDecorationRenderer
{
33 public TextGUIGraphics
draw(TextGUI textGUI
, TextGUIGraphics graphics
, Window window
) {
34 String title
= window
.getTitle();
39 ThemeDefinition themeDefinition
= graphics
.getThemeDefinition(DefaultWindowDecorationRenderer
.class);
40 char horizontalLine
= themeDefinition
.getCharacter("HORIZONTAL_LINE", Symbols
.SINGLE_LINE_HORIZONTAL
);
41 char verticalLine
= themeDefinition
.getCharacter("VERTICAL_LINE", Symbols
.SINGLE_LINE_VERTICAL
);
42 char bottomLeftCorner
= themeDefinition
.getCharacter("BOTTOM_LEFT_CORNER", Symbols
.SINGLE_LINE_BOTTOM_LEFT_CORNER
);
43 char topLeftCorner
= themeDefinition
.getCharacter("TOP_LEFT_CORNER", Symbols
.SINGLE_LINE_TOP_LEFT_CORNER
);
44 char bottomRightCorner
= themeDefinition
.getCharacter("BOTTOM_RIGHT_CORNER", Symbols
.SINGLE_LINE_BOTTOM_RIGHT_CORNER
);
45 char topRightCorner
= themeDefinition
.getCharacter("TOP_RIGHT_CORNER", Symbols
.SINGLE_LINE_TOP_RIGHT_CORNER
);
47 TerminalSize drawableArea
= graphics
.getSize();
48 graphics
.applyThemeStyle(themeDefinition
.getPreLight());
49 graphics
.drawLine(new TerminalPosition(0, drawableArea
.getRows() - 2), new TerminalPosition(0, 1), verticalLine
);
50 graphics
.drawLine(new TerminalPosition(1, 0), new TerminalPosition(drawableArea
.getColumns() - 2, 0), horizontalLine
);
51 graphics
.setCharacter(0, 0, topLeftCorner
);
52 graphics
.setCharacter(0, drawableArea
.getRows() - 1, bottomLeftCorner
);
54 graphics
.applyThemeStyle(themeDefinition
.getNormal());
57 new TerminalPosition(drawableArea
.getColumns() - 1, 1),
58 new TerminalPosition(drawableArea
.getColumns() - 1, drawableArea
.getRows() - 2),
61 new TerminalPosition(1, drawableArea
.getRows() - 1),
62 new TerminalPosition(drawableArea
.getColumns() - 2, drawableArea
.getRows() - 1),
65 graphics
.setCharacter(drawableArea
.getColumns() - 1, 0, topRightCorner
);
66 graphics
.setCharacter(drawableArea
.getColumns() - 1, drawableArea
.getRows() - 1, bottomRightCorner
);
68 if(!title
.isEmpty()) {
69 graphics
.putString(2, 0, TerminalTextUtils
.fitString(title
, drawableArea
.getColumns() - 3));
72 return graphics
.newTextGraphics(new TerminalPosition(1, 1), graphics
.getSize().withRelativeColumns(-2).withRelativeRows(-2));
76 public TerminalSize
getDecoratedSize(Window window
, TerminalSize contentAreaSize
) {
77 return contentAreaSize
78 .withRelativeColumns(2)
80 .max(new TerminalSize(TerminalTextUtils
.getColumnWidth(window
.getTitle()) + 4, 1)); //Make sure the title fits!
83 private static final TerminalPosition OFFSET
= new TerminalPosition(1, 1);
86 public TerminalPosition
getOffset(Window window
) {