use of java.awt.dnd.InvalidDnDOperationException 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.dnd.InvalidDnDOperationException in project blue by kunstmusik.
the class AudioLayersDropTargetListener method drop.
/*
* (non-Javadoc)
*
* @see java.awt.dnd.DropTargetListener#drop(java.awt.dnd.DropTargetDropEvent)
*/
@Override
public void drop(DropTargetDropEvent dtde) {
Node node = NodeTransfer.node(dtde.getTransferable(), NodeTransfer.DND_COPY);
if (node != null) {
File f = node.getLookup().lookup(File.class);
if (f == null || !f.isFile()) {
dtde.dropComplete(false);
return;
}
dtde.acceptDrop(DnDConstants.ACTION_COPY);
Point p = dtde.getLocation();
AudioLayerGroup audioLayerGroup = audioLayersPanel.getAudioLayerGroup();
int index = audioLayerGroup.getLayerNumForY(p.y);
AudioClip af = new AudioClip();
af.setName(f.getName());
af.setAudioFile(f);
float startTime = (float) p.x / audioLayersPanel.getTimeState().getPixelSecond();
af.setStartTime(startTime);
af.setSubjectiveDuration(af.getAudioDuration());
AudioLayer layer = audioLayerGroup.get(index);
layer.add(af);
dtde.dropComplete(true);
}
try {
Transferable tr = dtde.getTransferable();
if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
dtde.acceptDrop(DnDConstants.ACTION_LINK);
List<?> list = (List<?>) tr.getTransferData(DataFlavor.javaFileListFlavor);
if (list.size() != 1) {
dtde.dropComplete(false);
return;
}
String s = list.get(0).toString().trim();
System.out.println("file flavor found: " + s);
if (!s.toLowerCase().endsWith("wav") && !s.toLowerCase().endsWith("aif") && !s.toLowerCase().endsWith("aiff")) {
dtde.dropComplete(false);
return;
}
String sObjName = s.substring(s.lastIndexOf(File.separator) + 1);
Point p = dtde.getLocation();
AudioLayerGroup audioLayerGroup = audioLayersPanel.getAudioLayerGroup();
int index = audioLayerGroup.getLayerNumForY(p.y);
AudioClip af = new AudioClip();
af.setName(sObjName);
af.setAudioFile(new File(s));
float startTime = (float) p.x / audioLayersPanel.getTimeState().getPixelSecond();
af.setStartTime(startTime);
af.setSubjectiveDuration(af.getAudioDuration());
AudioLayer layer = audioLayerGroup.get(index);
layer.add(af);
dtde.dropComplete(true);
return;
} else if (dtde.isDataFlavorSupported(DataFlavor.stringFlavor)) {
dtde.acceptDrop(DnDConstants.ACTION_LINK);
String str = (String) tr.getTransferData(DataFlavor.stringFlavor);
System.out.println("String flavor found: " + str);
if (!str.startsWith("file://")) {
dtde.dropComplete(false);
return;
}
str = str.substring(7).trim();
if (!str.toLowerCase().endsWith("wav") && !str.toLowerCase().endsWith("aif") && !str.toLowerCase().endsWith("aiff")) {
System.err.println("Could not open file: " + str);
dtde.dropComplete(false);
return;
}
str = URLDecoder.decode(str);
str = str.replaceAll(" ", "\\ ");
File f = new File(str);
if (!f.exists()) {
dtde.dropComplete(false);
return;
}
String sObjName = str.substring(str.lastIndexOf(File.separator) + 1);
Point p = dtde.getLocation();
AudioLayerGroup audioLayerGroup = audioLayersPanel.getAudioLayerGroup();
int index = audioLayerGroup.getLayerNumForY(p.y);
AudioClip af = new AudioClip();
af.setName(sObjName);
af.setAudioFile(f);
float startTime = (float) p.x / audioLayersPanel.getTimeState().getPixelSecond();
af.setStartTime(startTime);
af.setSubjectiveDuration(af.getAudioDuration());
AudioLayer layer = audioLayerGroup.get(index);
layer.add(af);
dtde.dropComplete(true);
return;
}
dtde.rejectDrop();
} catch (UnsupportedFlavorException | IOException | InvalidDnDOperationException e) {
e.printStackTrace();
dtde.rejectDrop();
}
}
Aggregations