Change build scripts
[jvcard.git] / src / com / googlecode / lanterna / gui2 / AbstractBorder.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
22 import com.googlecode.lanterna.TerminalPosition;
23 import com.googlecode.lanterna.TerminalSize;
24
25 /**
26 * Abstract implementation of {@code Border} interface that has some of the methods filled out. If you want to create
27 * your own {@code Border} implementation, should should probably extend from this.
28 * @author Martin
29 */
30 public abstract class AbstractBorder extends AbstractComposite<Border> implements Border {
31 @Override
32 public void setComponent(Component component) {
33 super.setComponent(component);
34 if(component != null) {
35 component.setPosition(TerminalPosition.TOP_LEFT_CORNER);
36 }
37 }
38
39 @Override
40 public BorderRenderer getRenderer() {
41 return (BorderRenderer)super.getRenderer();
42 }
43
44 @Override
45 public Border setSize(TerminalSize size) {
46 super.setSize(size);
47 getComponent().setSize(getWrappedComponentSize(size));
48 return self();
49 }
50
51 @Override
52 public LayoutData getLayoutData() {
53 return getComponent().getLayoutData();
54 }
55
56 @Override
57 public Border setLayoutData(LayoutData ld) {
58 getComponent().setLayoutData(ld);
59 return this;
60 }
61
62 @Override
63 public TerminalPosition toBasePane(TerminalPosition position) {
64 return super.toBasePane(position).withRelative(getWrappedComponentTopLeftOffset());
65 }
66
67 @Override
68 public TerminalPosition toGlobal(TerminalPosition position) {
69 return super.toGlobal(position).withRelative(getWrappedComponentTopLeftOffset());
70 }
71
72 private TerminalPosition getWrappedComponentTopLeftOffset() {
73 return getRenderer().getWrappedComponentTopLeftOffset();
74 }
75
76 private TerminalSize getWrappedComponentSize(TerminalSize borderSize) {
77 return getRenderer().getWrappedComponentSize(borderSize);
78 }
79 }