1 package be
.nikiroo
.jvcard
.tui
;
5 import be
.nikiroo
.jvcard
.launcher
.Main
;
6 import be
.nikiroo
.jvcard
.tui
.ImageText
.Mode
;
8 import com
.googlecode
.lanterna
.TerminalSize
;
9 import com
.googlecode
.lanterna
.gui2
.BorderLayout
;
10 import com
.googlecode
.lanterna
.gui2
.Panel
;
11 import com
.googlecode
.lanterna
.gui2
.TextBox
;
14 * A {@link Panel} containing an {@link ImageText} rendering.
19 public class ImageTextControl
extends Panel
{
20 private ImageText image
;
25 * Create a new {@link ImageTextControl} for the given {@link Image} and
26 * {@link TerminalSize}.
29 * the {@link Image} to render
31 * the target size of this control
33 public ImageTextControl(Image image
, TerminalSize size
) {
34 Mode mode
= Mode
.DOUBLE_DITHERING
;
35 if (!Main
.isUnicode()) {
39 Mode
[] modes
= Mode
.values();
40 for (int i
= 0; i
< modes
.length
; i
++) {
45 this.setLayoutManager(new BorderLayout());
47 setImage(new ImageText(image
, size
, mode
, false));
51 * Cycle through the available rendering modes if possible.
53 * @return TRUE if it was possible to switch modes
55 public boolean switchMode() {
56 if (image
== null || !Main
.isUnicode())
59 Mode
[] modes
= Mode
.values();
61 if (mode
>= modes
.length
)
64 image
.setMode(modes
[mode
]);
73 public void invertColor() {
75 image
.setColorInvert(!image
.isColorInvert());
81 public synchronized Panel
setSize(TerminalSize size
) {
93 * Set/reset the {@link ImageText} to render.
96 * the new {@link ImageText}
98 private void setImage(ImageText image
) {
100 removeAllComponents();
103 txt
= new TextBox(image
.getText());
104 this.addComponent(txt
, BorderLayout
.Location
.CENTER
);