1 package be
.nikiroo
.jvcard
.tui
;
5 import be
.nikiroo
.jvcard
.tui
.ImageText
.Mode
;
7 import com
.googlecode
.lanterna
.TerminalSize
;
8 import com
.googlecode
.lanterna
.gui2
.BorderLayout
;
9 import com
.googlecode
.lanterna
.gui2
.Panel
;
10 import com
.googlecode
.lanterna
.gui2
.TextBox
;
13 * A {@link Panel} containing an {@link ImageText} rendering.
18 public class ImageTextControl
extends Panel
{
19 private ImageText image
;
24 * Create a new {@link ImageTextControl} for the given {@link Image} and
25 * {@link TerminalSize}.
28 * the {@link Image} to render
30 * the target size of this control
32 public ImageTextControl(Image image
, TerminalSize size
) {
33 Mode mode
= Mode
.DOUBLE_DITHERING
;
34 if (!UiColors
.getInstance().isUnicode()) {
38 Mode
[] modes
= Mode
.values();
39 for (int i
= 0; i
< modes
.length
; i
++) {
44 this.setLayoutManager(new BorderLayout());
46 setImage(new ImageText(image
, size
, mode
, false));
50 * Cycle through the available rendering modes if possible.
52 * @return TRUE if it was possible to switch modes
54 public boolean switchMode() {
55 if (image
== null || !UiColors
.getInstance().isUnicode())
58 Mode
[] modes
= Mode
.values();
60 if (mode
>= modes
.length
)
63 image
.setMode(modes
[mode
]);
72 public void invertColor() {
74 image
.setColorInvert(!image
.isColorInvert());
80 public synchronized Panel
setSize(TerminalSize size
) {
92 * Set/reset the {@link ImageText} to render.
95 * the new {@link ImageText}
97 private void setImage(ImageText image
) {
99 removeAllComponents();
102 txt
= new TextBox(image
.getText());
103 this.addComponent(txt
, BorderLayout
.Location
.CENTER
);