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()) {
}
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 || !UiColors.getInstance().isUnicode())
return false;
Mode[] modes = Mode.values();
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);
}
}