Commit | Line | Data |
---|---|---|
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 | */ | |
19 | package com.googlecode.lanterna.terminal.swing; | |
20 | ||
21 | import com.googlecode.lanterna.graphics.AbstractTextGraphics; | |
22 | import com.googlecode.lanterna.TextCharacter; | |
23 | import com.googlecode.lanterna.TerminalPosition; | |
24 | import com.googlecode.lanterna.TerminalSize; | |
25 | import com.googlecode.lanterna.graphics.TextGraphics; | |
26 | ||
27 | /** | |
28 | * Implementation of TextGraphics for the SwingTerminal, which is able to access directly into the TextBuffer and set | |
29 | * values in there directly. | |
30 | * @author Martin | |
31 | */ | |
32 | class VirtualTerminalTextGraphics extends AbstractTextGraphics { | |
33 | private final VirtualTerminal virtualTerminal; | |
34 | ||
35 | VirtualTerminalTextGraphics(VirtualTerminal virtualTerminal) { | |
36 | this.virtualTerminal = virtualTerminal; | |
37 | } | |
38 | ||
39 | @Override | |
40 | public TextGraphics setCharacter(int columnIndex, int rowIndex, TextCharacter textCharacter) { | |
41 | TerminalSize size = getSize(); | |
42 | if(columnIndex < 0 || columnIndex >= size.getColumns() || | |
43 | rowIndex < 0 || rowIndex >= size.getRows()) { | |
44 | return this; | |
45 | } | |
46 | virtualTerminal.setCursorAndPutCharacter(new TerminalPosition(columnIndex, rowIndex), textCharacter); | |
47 | return this; | |
48 | } | |
49 | ||
50 | @Override | |
51 | public TextCharacter getCharacter(TerminalPosition position) { | |
52 | return virtualTerminal.getCharacter(position); | |
53 | } | |
54 | ||
55 | @Override | |
56 | public TextCharacter getCharacter(int column, int row) { | |
57 | return getCharacter(new TerminalPosition(column, row)); | |
58 | } | |
59 | ||
60 | @Override | |
61 | public TerminalSize getSize() { | |
62 | return virtualTerminal.getSize(); | |
63 | } | |
64 | } |