+
+ @Override
+ public synchronized Panel setSize(TerminalSize size) {
+ super.setSize(size);
+ setImage(image);
+ return this;
+ }
+
+ /**
+ * Set the {@link Image} to render and refresh it to the current size
+ * constraints.
+ *
+ * @param image
+ * the new {@link Image}
+ */
+ private void setImage(Image image) {
+ this.image = image;
+
+ if (txtImage != null && top.containsComponent(txtImage))
+ top.removeComponent(txtImage);
+
+ TerminalSize size = getTxtSize();
+ if (size != null) {
+ if (txtImage != null)
+ txtImage.setSize(size);
+ else
+ txtImage = new ImageTextControl(image, size);
+ }
+
+ if (size != null) {
+ top.addComponent(txtImage, BorderLayout.Location.LEFT);
+ }
+
+ invalidate();
+ }
+
+ /**
+ * Compute the size to use for the {@link Image} text rendering. Return NULL
+ * in case of error.
+ *
+ * @return the {@link TerminalSize} to use or NULL if it is not possible
+ */
+ private TerminalSize getTxtSize() {
+ if (image != null && getSize() != null && getSize().getColumns() > 0
+ && getSize().getRows() > 0) {
+ if (fullscreenImage) {
+ return getSize();
+ } else {
+ // TODO: configure size?
+ int w = getSize().getColumns() - 40;
+ int h = getSize().getRows() - 5;
+ if (w <= 0 || h <= 0)
+ return null;
+
+ return new TerminalSize(w, h);
+ }
+ }
+
+ return null;
+ }