Change build scripts
[jvcard.git] / src / com / googlecode / lanterna / gui2 / DefaultWindowDecorationRenderer.java
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 */
19 package com.googlecode.lanterna.gui2;
20
21 import com.googlecode.lanterna.*;
22 import com.googlecode.lanterna.graphics.ThemeDefinition;
23
24 /**
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
27 * borders.
28 *
29 * @author Martin
30 */
31 public class DefaultWindowDecorationRenderer implements WindowDecorationRenderer {
32 @Override
33 public TextGUIGraphics draw(TextGUI textGUI, TextGUIGraphics graphics, Window window) {
34 String title = window.getTitle();
35 if(title == null) {
36 title = "";
37 }
38
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);
46
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);
53
54 graphics.applyThemeStyle(themeDefinition.getNormal());
55
56 graphics.drawLine(
57 new TerminalPosition(drawableArea.getColumns() - 1, 1),
58 new TerminalPosition(drawableArea.getColumns() - 1, drawableArea.getRows() - 2),
59 verticalLine);
60 graphics.drawLine(
61 new TerminalPosition(1, drawableArea.getRows() - 1),
62 new TerminalPosition(drawableArea.getColumns() - 2, drawableArea.getRows() - 1),
63 horizontalLine);
64
65 graphics.setCharacter(drawableArea.getColumns() - 1, 0, topRightCorner);
66 graphics.setCharacter(drawableArea.getColumns() - 1, drawableArea.getRows() - 1, bottomRightCorner);
67
68 if(!title.isEmpty()) {
69 graphics.putString(2, 0, TerminalTextUtils.fitString(title, drawableArea.getColumns() - 3));
70 }
71
72 return graphics.newTextGraphics(new TerminalPosition(1, 1), graphics.getSize().withRelativeColumns(-2).withRelativeRows(-2));
73 }
74
75 @Override
76 public TerminalSize getDecoratedSize(Window window, TerminalSize contentAreaSize) {
77 return contentAreaSize
78 .withRelativeColumns(2)
79 .withRelativeRows(2)
80 .max(new TerminalSize(TerminalTextUtils.getColumnWidth(window.getTitle()) + 4, 1)); //Make sure the title fits!
81 }
82
83 private static final TerminalPosition OFFSET = new TerminalPosition(1, 1);
84
85 @Override
86 public TerminalPosition getOffset(Window window) {
87 return OFFSET;
88 }
89 }