X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTImage.java;h=2dfd6a3032c86af375d8ef855314b1a3ed51cd9a;hb=5ca5f8e5310b189232ed337643f3b7b2ce6cd3b1;hp=3aaca2f832cf41b74a8a9c60600c7cdad4f96a45;hpb=03ae544a1639c127ebec9a46635f2ad465713908;p=fanfix.git diff --git a/src/jexer/TImage.java b/src/jexer/TImage.java index 3aaca2f..2dfd6a3 100644 --- a/src/jexer/TImage.java +++ b/src/jexer/TImage.java @@ -34,15 +34,17 @@ import jexer.backend.ECMA48Terminal; import jexer.backend.MultiScreen; import jexer.backend.SwingTerminal; import jexer.bits.Cell; +import jexer.event.TCommandEvent; import jexer.event.TKeypressEvent; import jexer.event.TMouseEvent; import jexer.event.TResizeEvent; +import static jexer.TCommand.*; import static jexer.TKeypress.*; /** * TImage renders a piece of a bitmap image on screen. */ -public class TImage extends TWidget { +public class TImage extends TWidget implements EditMenuUser { // ------------------------------------------------------------------------ // Constants -------------------------------------------------------------- @@ -216,7 +218,7 @@ public class TImage extends TWidget { @Override public void onMouseDown(final TMouseEvent mouse) { if (clickAction != null) { - clickAction.DO(); + clickAction.DO(this); return; } } @@ -325,6 +327,20 @@ public class TImage extends TWidget { resized = true; } + /** + * Handle posted command events. + * + * @param command command event + */ + @Override + public void onCommand(final TCommandEvent command) { + if (command.equals(cmCopy)) { + // Copy image to clipboard. + getClipboard().copyImage(image); + return; + } + } + // ------------------------------------------------------------------------ // TWidget ---------------------------------------------------------------- // ------------------------------------------------------------------------ @@ -409,8 +425,21 @@ public class TImage extends TWidget { } Cell cell = new Cell(); - cell.setImage(image.getSubimage(x * textWidth, - y * textHeight, width, height)); + if ((width != textWidth) || (height != textHeight)) { + BufferedImage newImage; + newImage = new BufferedImage(textWidth, textHeight, + BufferedImage.TYPE_INT_ARGB); + + java.awt.Graphics gr = newImage.getGraphics(); + gr.drawImage(image.getSubimage(x * textWidth, + y * textHeight, width, height), + 0, 0, null, null); + gr.dispose(); + cell.setImage(newImage); + } else { + cell.setImage(image.getSubimage(x * textWidth, + y * textHeight, width, height)); + } cells[x][y] = cell; } @@ -762,4 +791,44 @@ public class TImage extends TWidget { return newImage; } + // ------------------------------------------------------------------------ + // EditMenuUser ----------------------------------------------------------- + // ------------------------------------------------------------------------ + + /** + * Check if the cut menu item should be enabled. + * + * @return true if the cut menu item should be enabled + */ + public boolean isEditMenuCut() { + return false; + } + + /** + * Check if the copy menu item should be enabled. + * + * @return true if the copy menu item should be enabled + */ + public boolean isEditMenuCopy() { + return true; + } + + /** + * Check if the paste menu item should be enabled. + * + * @return true if the paste menu item should be enabled + */ + public boolean isEditMenuPaste() { + return false; + } + + /** + * Check if the clear menu item should be enabled. + * + * @return true if the clear menu item should be enabled + */ + public boolean isEditMenuClear() { + return false; + } + }