use of java.awt.datatransfer.Clipboard in project JMRI by JMRI.
the class ControlPanelEditor method pasteFromClipboard.
private void pasteFromClipboard() {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
DataFlavor[] flavors = clipboard.getAvailableDataFlavors();
for (DataFlavor flavor : flavors) {
if (_positionableListDataFlavor.equals(flavor)) {
try {
@SuppressWarnings("unchecked") List<Positionable> clipGroup = (List<Positionable>) clipboard.getData(_positionableListDataFlavor);
if (clipGroup != null && clipGroup.size() > 0) {
Positionable pos = clipGroup.get(0);
int minX = pos.getLocation().x;
int minY = pos.getLocation().y;
// locate group at mouse point
for (int i = 1; i < clipGroup.size(); i++) {
pos = clipGroup.get(i);
minX = Math.min(minX, pos.getLocation().x);
minY = Math.min(minY, pos.getLocation().y);
}
if (_pastePending) {
abortPasteItems();
}
_selectionGroup = new ArrayList<Positionable>();
for (int i = 0; i < clipGroup.size(); i++) {
pos = clipGroup.get(i);
// make positionable belong to this editor
pos.setEditor(this);
pos.setLocation(pos.getLocation().x + _anchorX - minX, pos.getLocation().y + _anchorY - minY);
// now set display level in the pane.
pos.setDisplayLevel(pos.getDisplayLevel());
putItem(pos);
pos.updateSize();
pos.setVisible(true);
_selectionGroup.add(pos);
if (pos instanceof PositionableIcon) {
jmri.NamedBean bean = pos.getNamedBean();
if (bean != null) {
((PositionableIcon) pos).displayState(bean.getState());
}
} else if (pos instanceof MemoryIcon) {
((MemoryIcon) pos).displayState();
} else if (pos instanceof PositionableJComponent) {
((PositionableJComponent) pos).displayState();
}
log.debug("Paste Added at ({}, {})", pos.getLocation().x, pos.getLocation().y);
}
}
return;
} catch (IOException ioe) {
log.warn("Editor Paste caught IOException", ioe);
} catch (UnsupportedFlavorException ufe) {
log.warn("Editor Paste caught UnsupportedFlavorException", ufe);
}
}
}
}
use of java.awt.datatransfer.Clipboard in project processdash by dtuma.
the class TabularClipboardDataHelper method getTabularDataFromClipboard.
public static List<List<String>> getTabularDataFromClipboard() {
Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
DataFlavor[] flavors = cb.getAvailableDataFlavors();
if (flavors == null)
return null;
DataFlavor html = searchForFlavor(flavors, "text/html", "java.lang.String");
if (html != null) {
try {
String data = (String) cb.getData(html);
return HtmlTableParser.parseTable(data, true);
} catch (Exception e) {
return null;
}
}
DataFlavor text = searchForFlavor(flavors, "text/plain", "java.lang.String");
if (text != null) {
try {
String data = (String) cb.getData(text);
if (HtmlTableParser.containsHtmlTableData(data))
return HtmlTableParser.parseTable(data, true);
else
return parseTabDelimitedData(data);
} catch (Exception e) {
return null;
}
}
return null;
}
use of java.awt.datatransfer.Clipboard in project processdash by dtuma.
the class WBSClipSelection method putNodeListOnClipboard.
/** Interact with the system clipboard, and place a list of WBSNodes there.
*
* @param wbsNodes the list of WBSNodes to share
* @param o an owner who would like to be notified when the nodes are no
* longer on the system clipboard; can be null.
*/
public static void putNodeListOnClipboard(List wbsNodes, ClipboardOwner o) {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
WBSClipSelection t = new WBSClipSelection(wbsNodes);
clipboard.setContents(t, (o == null ? t : o));
}
use of java.awt.datatransfer.Clipboard in project processdash by dtuma.
the class WBSClipSelection method getNodeListFromClipboard.
/** Interact with the system clipboard to retrieve a list of WBSNodes.
*
* @param prototype if the system clipboard contains plain text, a list
* of nodes modeled after this prototype will be returned.
*/
public static List getNodeListFromClipboard(WBSNode prototype) {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable t = clipboard.getContents(prototype);
// on the clipboard).
try {
Object d = t.getTransferData(WBS_LIST_FLAVOR);
List result = ((WBSClipData) d).getWBSNodes(prototype.getWbsModel());
if (result != null)
return result;
} catch (Exception e) {
}
// clipboard by some other WBS Editor.
try {
Object d = t.getTransferData(WBS_FLAVOR);
List result = ((WBSClipData) d).getWBSNodes(prototype.getWbsModel());
if (result != null)
return result;
} catch (Exception e) {
}
// names, and create some ultra-simple nodes with those names.
try {
String plainText = (String) t.getTransferData(DataFlavor.stringFlavor);
String[] lines = plainText.split("\n");
int baseIndent = Math.max(1, prototype.getIndentLevel());
List result = new ArrayList();
for (int i = 0; i < lines.length; i++) {
Matcher m = PLAINTEXT_PATTERN.matcher(lines[i]);
if (!m.find())
continue;
String nodeName = scrubName(m.group(2)).trim();
int indent = baseIndent;
if (m.group(1) != null && m.group(1).length() > 0) {
Matcher mi = INDENT_PATTERN.matcher(m.group(1));
while (mi.find()) indent++;
}
WBSNode node = new WBSNode(prototype.getWbsModel(), nodeName, WBSNode.UNKNOWN_TYPE, indent, true);
result.add(node);
}
return result;
} catch (Exception e) {
}
// if all else fails, return null to indicate failure.
return null;
}
use of java.awt.datatransfer.Clipboard in project bnd by bndtools.
the class Repository method toClipboard.
void toClipboard(String s) {
if (s == null)
return;
StringSelection stringSelection = new StringSelection(s);
Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
clpbrd.setContents(stringSelection, null);
}
Aggregations