use of java.awt.datatransfer.UnsupportedFlavorException in project jdk8u_jdk by JetBrains.
the class SunDropTargetContextPeer method getTransferData.
/**
* @return the data
*/
public Object getTransferData(DataFlavor df) throws UnsupportedFlavorException, IOException, InvalidDnDOperationException {
SecurityManager sm = System.getSecurityManager();
try {
if (!dropInProcess && sm != null) {
sm.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION);
}
} catch (Exception e) {
Thread currentThread = Thread.currentThread();
currentThread.getUncaughtExceptionHandler().uncaughtException(currentThread, e);
return null;
}
Long lFormat = null;
Transferable localTransferable = local;
if (localTransferable != null) {
return localTransferable.getTransferData(df);
}
if (dropStatus != STATUS_ACCEPT || dropComplete) {
throw new InvalidDnDOperationException("No drop current");
}
Map flavorMap = DataTransferer.getInstance().getFlavorsForFormats(currentT, DataTransferer.adaptFlavorMap(currentDT.getFlavorMap()));
lFormat = (Long) flavorMap.get(df);
if (lFormat == null) {
throw new UnsupportedFlavorException(df);
}
if (df.isRepresentationClassRemote() && currentDA != DnDConstants.ACTION_LINK) {
throw new InvalidDnDOperationException("only ACTION_LINK is permissable for transfer of java.rmi.Remote objects");
}
final long format = lFormat.longValue();
Object ret = getNativeData(format);
if (ret instanceof byte[]) {
try {
return DataTransferer.getInstance().translateBytes((byte[]) ret, df, format, this);
} catch (IOException e) {
throw new InvalidDnDOperationException(e.getMessage());
}
} else if (ret instanceof InputStream) {
try {
return DataTransferer.getInstance().translateStream((InputStream) ret, df, format, this);
} catch (IOException e) {
throw new InvalidDnDOperationException(e.getMessage());
}
} else {
throw new IOException("no native data was transfered");
}
}
use of java.awt.datatransfer.UnsupportedFlavorException in project jdk8u_jdk by JetBrains.
the class SunClipboard method getData.
/**
* @see java.awt.Clipboard#getData
* @since 1.5
*/
public Object getData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
if (flavor == null) {
throw new NullPointerException("flavor");
}
Transferable cntnts = getContextContents();
if (cntnts != null) {
return cntnts.getTransferData(flavor);
}
long format = 0;
byte[] data = null;
Transferable localeTransferable = null;
try {
openClipboard(null);
long[] formats = getClipboardFormats();
Long lFormat = (Long) DataTransferer.getInstance().getFlavorsForFormats(formats, getDefaultFlavorTable()).get(flavor);
if (lFormat == null) {
throw new UnsupportedFlavorException(flavor);
}
format = lFormat.longValue();
data = getClipboardData(format);
if (DataTransferer.getInstance().isLocaleDependentTextFormat(format)) {
localeTransferable = createLocaleTransferable(formats);
}
} finally {
closeClipboard();
}
return DataTransferer.getInstance().translateBytes(data, flavor, format, localeTransferable);
}
use of java.awt.datatransfer.UnsupportedFlavorException in project megameklab by MegaMek.
the class CriticalTransferHandler method exportDone.
@Override
public void exportDone(JComponent source, Transferable data, int action) {
if (data == null) {
return;
}
Mounted mounted = null;
try {
mounted = getUnit().getEquipment(Integer.parseInt((String) data.getTransferData(DataFlavor.stringFlavor)));
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (UnsupportedFlavorException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if ((source instanceof DropTargetCriticalList) && (mounted.getLocation() != Entity.LOC_NONE)) {
DropTargetCriticalList<?> list = (DropTargetCriticalList<?>) source;
int loc;
if (getUnit() instanceof BattleArmor) {
String[] split = list.getName().split(":");
loc = Integer.parseInt(split[0]);
} else {
loc = Integer.parseInt(list.getName());
if (loc == mounted.getLocation()) {
return;
}
}
int slot = list.getSelectedIndex();
int startSlot = slot;
mounted = list.getMounted();
if (mounted == null) {
return;
}
if (UnitUtil.isFixedLocationSpreadEquipment(mounted.getType())) {
return;
}
while (slot > 0) {
slot--;
CriticalSlot cs = getUnit().getCritical(loc, slot);
if ((cs != null) && (cs.getType() == CriticalSlot.TYPE_EQUIPMENT) && cs.getMount().equals(mounted)) {
startSlot = slot;
}
}
if (!(getUnit() instanceof BattleArmor)) {
for (int i = startSlot; i < (startSlot + UnitUtil.getCritsUsed(getUnit(), mounted.getType())); i++) {
getUnit().setCritical(loc, i, null);
}
}
Mounted linkedBy = mounted.getLinkedBy();
if (linkedBy != null && !(getUnit() instanceof BattleArmor)) {
UnitUtil.removeCriticals(getUnit(), linkedBy);
try {
UnitUtil.addMounted(getUnit(), linkedBy, mounted.getLocation(), linkedBy.isRearMounted());
} catch (LocationFullException e) {
UnitUtil.changeMountStatus(getUnit(), linkedBy, Entity.LOC_NONE, Entity.LOC_NONE, false);
linkedBy.setLinked(null);
mounted.setLinkedBy(null);
}
}
// UnitUtil.compactCriticals(unit);
refresh.refreshBuild();
}
}
use of java.awt.datatransfer.UnsupportedFlavorException in project suite by stupidsing.
the class ClipboardUtil method getClipboardText.
public String getClipboardText() {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable contents = clipboard.getContents(null);
String text;
if (contents != null && contents.isDataFlavorSupported(DataFlavor.stringFlavor))
try {
text = contents.getTransferData(DataFlavor.stringFlavor).toString();
} catch (UnsupportedFlavorException ex) {
LogUtil.error(ex);
text = "";
} catch (IOException ex) {
LogUtil.error(ex);
text = "";
}
else
text = "";
return text;
}
use of java.awt.datatransfer.UnsupportedFlavorException in project sldeditor by robward-scisys.
the class TreeTransferHandler method exportDone.
/*
* (non-Javadoc)
*
* @see javax.swing.TransferHandler#exportDone(javax.swing.JComponent, java.awt.datatransfer.Transferable, int)
*/
@Override
protected void exportDone(JComponent source, Transferable data, int action) {
if (!(source instanceof JTree) || (data == null)) {
return;
}
JTree tree = (JTree) source;
NodeInterface destinationTreeNode = (NodeInterface) tree.getLastSelectedPathComponent();
DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
DataFlavor destDataFlavour = destinationTreeNode.getDataFlavour();
TransferredData transferredData = null;
try {
transferredData = (TransferredData) data.getTransferData(destDataFlavour);
} catch (UnsupportedFlavorException e) {
ConsoleManager.getInstance().exception(this, e);
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
}
if (action == MOVE) {
DataFlavourManager.deleteNodes(model, transferredData);
}
if (action != NONE) {
DataFlavourManager.displayMessages(destinationTreeNode, transferredData, action);
}
setDragging(false);
}
Aggregations