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 --------------------------------------------------------------
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 ----------------------------------------------------------------
// ------------------------------------------------------------------------
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;
+ }
+
}
*/
private java.awt.datatransfer.Clipboard systemClipboard = null;
+ /**
+ * The image selection class.
+ */
+ private ImageSelection imageSelection;
+
+ /**
+ * ImageSelection is used to hold an image while on the clipboard.
+ */
+ private class ImageSelection implements Transferable {
+
+ /**
+ * Returns an array of DataFlavor objects indicating the flavors the
+ * data can be provided in. The array should be ordered according to
+ * preference for providing the data (from most richly descriptive to
+ * least descriptive).
+ *
+ * @return an array of data flavors in which this data can be
+ * transferred
+ */
+ public DataFlavor[] getTransferDataFlavors() {
+ return new DataFlavor[] { DataFlavor.imageFlavor };
+ }
+
+ /**
+ * Returns whether or not the specified data flavor is supported for
+ * this object.
+ *
+ * @param flavor the requested flavor for the data
+ * @return boolean indicating whether or not the data flavor is
+ * supported
+ */
+ public boolean isDataFlavorSupported(DataFlavor flavor) {
+ return DataFlavor.imageFlavor.equals(flavor);
+ }
+
+ /**
+ * Returns an object which represents the data to be transferred. The
+ * class of the object returned is defined by the representation
+ * class of the flavor.
+ *
+ * @param flavor the requested flavor for the data
+ * @throws IOException if the data is no longer available in the
+ * requested flavor.
+ * @throws UnsupportedFlavorException if the requested data flavor is
+ * not supported.
+ */
+ public Object getTransferData(DataFlavor flavor)
+ throws UnsupportedFlavorException, IOException {
+
+ if (!DataFlavor.imageFlavor.equals(flavor)) {
+ throw new UnsupportedFlavorException(flavor);
+ }
+ return image;
+ }
+ }
+
// ------------------------------------------------------------------------
// Constructors -----------------------------------------------------------
// ------------------------------------------------------------------------
public void copyImage(final BufferedImage image) {
this.image = image;
if (systemClipboard != null) {
- // TODO
+ ImageSelection imageSelection = new ImageSelection();
+ systemClipboard.setContents(imageSelection, null);
}
}