-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from otymko/feature/issue61_2
Исправление #61 подход 2
- Loading branch information
Showing
2 changed files
with
46 additions
and
22 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/main/java/org/github/otymko/phoenixbsl/core/CustomTextTransfer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.github.otymko.phoenixbsl.core; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.awt.*; | ||
import java.awt.datatransfer.*; | ||
import java.io.IOException; | ||
|
||
@Slf4j | ||
public class CustomTextTransfer implements ClipboardOwner { | ||
|
||
private StringSelection stringSelection; | ||
|
||
@Override | ||
public void lostOwnership(Clipboard clipboard, Transferable contents) { | ||
// TODO Auto-generated method stub | ||
} | ||
|
||
public void setClipboardContents(String content) { | ||
stringSelection = new StringSelection(content); | ||
var clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); | ||
clipboard.setContents(stringSelection, this); | ||
} | ||
|
||
public String getClipboardContents() { | ||
String content = ""; | ||
var clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); | ||
var contents = clipboard.getContents(null); | ||
var hasTransferableText = (contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor); | ||
if (hasTransferableText) { | ||
try { | ||
content = (String) contents.getTransferData(DataFlavor.stringFlavor); | ||
} catch (UnsupportedFlavorException ex) { | ||
LOGGER.error(ex.getMessage()); | ||
} catch (IOException ex) { | ||
LOGGER.error(ex.getMessage()); | ||
} | ||
} | ||
return content; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters