X-Git-Url: http://git.nikiroo.be/?p=jvcard.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2Ftui%2FImageTextControl.java;h=dc0548260a860e019eef25c5d8e3153545690b78;hp=4ee35e97ba34bb95e8c1b1b7b9dafcde56edca43;hb=7da41ecd30228908bf2afcd07ff7943ab59d4c01;hpb=20ce79bb39f98eacdf796f600dd175868ee31347 diff --git a/src/be/nikiroo/jvcard/tui/ImageTextControl.java b/src/be/nikiroo/jvcard/tui/ImageTextControl.java index 4ee35e9..dc05482 100644 --- a/src/be/nikiroo/jvcard/tui/ImageTextControl.java +++ b/src/be/nikiroo/jvcard/tui/ImageTextControl.java @@ -2,6 +2,7 @@ package be.nikiroo.jvcard.tui; import java.awt.Image; +import be.nikiroo.jvcard.launcher.Main; import be.nikiroo.jvcard.tui.ImageText.Mode; import com.googlecode.lanterna.TerminalSize; @@ -9,14 +10,29 @@ import com.googlecode.lanterna.gui2.BorderLayout; import com.googlecode.lanterna.gui2.Panel; import com.googlecode.lanterna.gui2.TextBox; +/** + * A {@link Panel} containing an {@link ImageText} rendering. + * + * @author niki + * + */ public class ImageTextControl extends Panel { - private ImageText img; + private ImageText image; private TextBox txt; private int mode; + /** + * Create a new {@link ImageTextControl} for the given {@link Image} and + * {@link TerminalSize}. + * + * @param image + * the {@link Image} to render + * @param size + * the target size of this control + */ public ImageTextControl(Image image, TerminalSize size) { Mode mode = Mode.DOUBLE_DITHERING; - if (!UiColors.getInstance().isUnicode()) { + if (!Main.isUnicode()) { mode = Mode.ASCII; } @@ -27,11 +43,17 @@ public class ImageTextControl extends Panel { } this.setLayoutManager(new BorderLayout()); - setImg(new ImageText(image, size, mode)); + setSize(size); + setImage(new ImageText(image, size, mode, false)); } + /** + * Cycle through the available rendering modes if possible. + * + * @return TRUE if it was possible to switch modes + */ public boolean switchMode() { - if (img == null || !UiColors.getInstance().isUnicode()) + if (image == null || !Main.isUnicode()) return false; Mode[] modes = Mode.values(); @@ -39,25 +61,46 @@ public class ImageTextControl extends Panel { if (mode >= modes.length) mode = 0; - img.setMode(modes[mode]); - setImg(img); + image.setMode(modes[mode]); + setImage(image); return true; } + /** + * Invert the colours. + */ public void invertColor() { - if (img != null) { - img.setColorInvert(!img.isColorInvert()); - setImg(img); + if (image != null) { + image.setColorInvert(!image.isColorInvert()); + setImage(image); } } - private void setImg(ImageText img) { - this.img = img; + @Override + public synchronized Panel setSize(TerminalSize size) { + if (image != null) + image.setSize(size); + + super.setSize(size); + + setImage(image); + + return this; + }; + + /** + * Set/reset the {@link ImageText} to render. + * + * @param image + * the new {@link ImageText} + */ + private void setImage(ImageText image) { + this.image = image; removeAllComponents(); txt = null; - if (img != null) { - txt = new TextBox(img.getText()); + if (image != null) { + txt = new TextBox(image.getText()); this.addComponent(txt, BorderLayout.Location.CENTER); } }