ImageText: jDoc
[jvcard.git] / src / be / nikiroo / jvcard / tui / ImageTextControl.java
CommitLineData
25232463
NR
1package be.nikiroo.jvcard.tui;
2
3import java.awt.Image;
4
5import be.nikiroo.jvcard.tui.ImageText.Mode;
6
7import com.googlecode.lanterna.TerminalSize;
8import com.googlecode.lanterna.gui2.BorderLayout;
9import com.googlecode.lanterna.gui2.Panel;
10import com.googlecode.lanterna.gui2.TextBox;
11
12public class ImageTextControl extends Panel {
13 private ImageText img;
14 private TextBox txt;
15 private int mode;
16
17 public ImageTextControl(Image image, TerminalSize size) {
18 Mode mode = Mode.DOUBLE_DITHERING;
19 if (!UiColors.getInstance().isUnicode()) {
20 mode = Mode.ASCII;
21 }
22
23 Mode[] modes = Mode.values();
24 for (int i = 0; i < modes.length; i++) {
25 if (mode == modes[i])
26 this.mode = i;
27 }
28
29 this.setLayoutManager(new BorderLayout());
30 setImg(new ImageText(image, size, mode));
31 }
32
33 public boolean switchMode() {
34 if (img == null || !UiColors.getInstance().isUnicode())
35 return false;
36
37 Mode[] modes = Mode.values();
38 mode++;
39 if (mode >= modes.length)
40 mode = 0;
41
42 img.setMode(modes[mode]);
43 setImg(img);
44
45 return true;
46 }
47
48 public void invertColor() {
49 if (img != null) {
20ce79bb 50 img.setColorInvert(!img.isColorInvert());
25232463
NR
51 setImg(img);
52 }
53 }
54
55 private void setImg(ImageText img) {
56 this.img = img;
57 removeAllComponents();
58 txt = null;
59 if (img != null) {
60 txt = new TextBox(img.getText());
61 this.addComponent(txt, BorderLayout.Location.CENTER);
62 }
63 }
64}