use of java.awt.datatransfer.UnsupportedFlavorException in project keystore-explorer by kaikramer.
the class KeyStoreEntryTransferable method getTransferData.
/**
* Get transfer data.
*
* @param dataFlavor
* Data flavor
* @return Transfer data
* @throws UnsupportedFlavorException
* If the requested data flavor is not supported
* @throws IOException
* If an I/O problem occurred
*/
@Override
public Object getTransferData(DataFlavor dataFlavor) throws UnsupportedFlavorException, IOException {
if (!isDataFlavorSupported(dataFlavor)) {
throw new UnsupportedFlavorException(dataFlavor);
}
if (dataFlavor == DataFlavor.javaFileListFlavor) {
String tempDir = System.getProperty("java.io.tmpdir");
File tmpFile = new File(tempDir, dragEntry.getFileName());
tmpFile.deleteOnExit();
try (FileOutputStream fos = new FileOutputStream(tmpFile)) {
fos.write(dragEntry.getContent());
fos.flush();
}
List<File> list = new ArrayList<File>();
list.add(tmpFile);
return list;
} else {
return dragEntry.getContentString();
}
}
use of java.awt.datatransfer.UnsupportedFlavorException in project openchemlib by Actelion.
the class MoleculeDragAdapter method drawDragImage.
public Image drawDragImage(Transferable transferable, int width, int height) {
if (transferable instanceof MoleculeTransferable) {
try {
MoleculeTransferable t = (MoleculeTransferable) transferable;
Object o = t.getTransferData(MoleculeFlavors.DF_SERIALIZEDOBJECT);
if (o instanceof StereoMolecule) {
StereoMolecule mol = (StereoMolecule) o;
Depictor2D depict = new Depictor2D(mol);
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics g = img.getGraphics();
((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
((Graphics2D) g).setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
depict.validateView(g, new Rectangle2D.Double(0, 0, width, height), AbstractDepictor.cModeInflateToMaxAVBL);
depict.paint(g);
return img;
}
} catch (IOException e1) {
System.err.println(e1);
} catch (UnsupportedFlavorException e1) {
System.err.println(e1);
}
}
return null;
}
use of java.awt.datatransfer.UnsupportedFlavorException in project jsql-injection by ron190.
the class ListTransfertHandler method importData.
@SuppressWarnings("unchecked")
@Override
public boolean importData(TransferSupport support) {
if (!this.canImport(support)) {
return false;
}
DnDList list = (DnDList) support.getComponent();
DefaultListModel<ItemList> listModel = (DefaultListModel<ItemList>) list.getModel();
// This is a drop
if (support.isDrop()) {
if (support.isDataFlavorSupported(DataFlavor.stringFlavor)) {
JList.DropLocation dl = (JList.DropLocation) support.getDropLocation();
int childIndex = dl.getIndex();
List<Integer> selectAfterDrop = new ArrayList<>();
// DnD from list
if (this.dragPaths != null && !this.dragPaths.isEmpty()) {
for (ItemList value : this.dragPaths) {
if (!"".equals(value.toString())) {
// ! FUUuu
ItemList newValue = new ItemList(value.toString().replace("\\", "/"));
selectAfterDrop.add(childIndex);
listModel.add(childIndex++, newValue);
}
}
} else {
// DnD from outside
try {
String importString = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
for (String value : importString.split("\\n")) {
if (!"".equals(value)) {
selectAfterDrop.add(childIndex);
listModel.add(childIndex++, new ItemList(value.replace("\\", "/")));
}
}
} catch (UnsupportedFlavorException | IOException e) {
LOGGER.error(e.getMessage(), e);
}
}
int[] selectedIndices = new int[selectAfterDrop.size()];
int i = 0;
for (Integer integer : selectAfterDrop) {
selectedIndices[i] = integer.intValue();
i++;
}
list.setSelectedIndices(selectedIndices);
} else if (support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
JList.DropLocation dl = (JList.DropLocation) support.getDropLocation();
int childIndex = dl.getIndex();
try {
list.dropPasteFile((List<File>) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor), childIndex);
} catch (UnsupportedFlavorException | IOException e) {
LOGGER.error(e.getMessage(), e);
}
}
} else {
// This is a paste
Transferable transferableFromClipboard = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
if (transferableFromClipboard != null) {
if (transferableFromClipboard.isDataFlavorSupported(DataFlavor.stringFlavor)) {
try {
String clipboardText = (String) transferableFromClipboard.getTransferData(DataFlavor.stringFlavor);
int selectedIndex = 0;
if (list.getSelectedIndex() > 0) {
selectedIndex = list.getSelectedIndex();
}
list.clearSelection();
List<Integer> selectedIndexes = new ArrayList<>();
for (String line : clipboardText.split("\\n")) {
if (!"".equals(line)) {
String newLine = line.replace("\\", "/");
ItemList newItem = new ItemList(newLine);
selectedIndexes.add(selectedIndex);
listModel.add(selectedIndex++, newItem);
}
}
int[] selectedIndexesPasted = new int[selectedIndexes.size()];
int i = 0;
for (Integer integer : selectedIndexes) {
selectedIndexesPasted[i] = integer.intValue();
i++;
}
list.setSelectedIndices(selectedIndexesPasted);
list.scrollRectToVisible(list.getCellBounds(list.getMinSelectionIndex(), list.getMaxSelectionIndex()));
} catch (NullPointerException | UnsupportedFlavorException | IOException e) {
// Fix #8831: Multiple Exception on scrollRectToVisible()
LOGGER.error(e.getMessage(), e);
}
} else if (transferableFromClipboard.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
try {
int selectedIndex = 0;
if (list.getSelectedIndex() > 0) {
selectedIndex = list.getSelectedIndex();
}
list.clearSelection();
list.dropPasteFile((List<File>) transferableFromClipboard.getTransferData(DataFlavor.javaFileListFlavor), selectedIndex);
} catch (UnsupportedFlavorException | IOException e) {
LOGGER.error(e.getMessage(), e);
}
}
}
}
return true;
}
use of java.awt.datatransfer.UnsupportedFlavorException in project jsql-injection by ron190.
the class ListTransfertHandlerScan method importData.
@SuppressWarnings("unchecked")
@Override
public boolean importData(TransferSupport support) {
if (!this.canImport(support)) {
return false;
}
DnDList list = (DnDList) support.getComponent();
DefaultListModel<ItemList> listModel = (DefaultListModel<ItemList>) list.getModel();
// This is a drop
if (support.isDrop()) {
if (support.isDataFlavorSupported(DataFlavor.stringFlavor)) {
JList.DropLocation dropLocation = (JList.DropLocation) support.getDropLocation();
int indexDropLocation = dropLocation.getIndex();
List<Integer> listSelectedIndices = new ArrayList<>();
// DnD from list
if (this.dragPaths != null && !this.dragPaths.isEmpty()) {
for (ItemList itemPath : this.dragPaths) {
if (!"".equals(itemPath.toString())) {
// ! FUUuu
ItemListScan itemDrag = (ItemListScan) itemPath;
ItemListScan itemDrop = new ItemListScan(itemDrag.getBeanInjection());
listSelectedIndices.add(indexDropLocation);
listModel.add(indexDropLocation++, itemDrop);
}
}
} else {
// DnD from outside
try {
String importString = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
for (ItemListScan itemListScan : ListTransfertHandlerScan.parse(importString)) {
listSelectedIndices.add(indexDropLocation);
listModel.add(indexDropLocation++, itemListScan);
}
} catch (UnsupportedFlavorException | IOException e) {
LOGGER.error(e.getMessage(), e);
}
}
int[] selectedIndices = new int[listSelectedIndices.size()];
int i = 0;
for (Integer integer : listSelectedIndices) {
selectedIndices[i] = integer.intValue();
i++;
}
list.setSelectedIndices(selectedIndices);
} else if (support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
JList.DropLocation dl = (JList.DropLocation) support.getDropLocation();
int childIndex = dl.getIndex();
try {
list.dropPasteFile((List<File>) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor), childIndex);
} catch (UnsupportedFlavorException | IOException e) {
LOGGER.error(e.getMessage(), e);
}
}
} else {
// This is a paste
Transferable transferableFromClipboard = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
if (transferableFromClipboard != null) {
if (transferableFromClipboard.isDataFlavorSupported(DataFlavor.stringFlavor)) {
try {
String clipboardText = (String) transferableFromClipboard.getTransferData(DataFlavor.stringFlavor);
int selectedIndex = 0;
if (list.getSelectedIndex() > 0) {
selectedIndex = list.getSelectedIndex();
}
list.clearSelection();
List<Integer> selectedIndexes = new ArrayList<>();
for (ItemListScan itemListScan : ListTransfertHandlerScan.parse(clipboardText)) {
selectedIndexes.add(selectedIndex);
listModel.add(selectedIndex++, itemListScan);
}
int[] selectedIndexesPasted = new int[selectedIndexes.size()];
int i = 0;
for (Integer integer : selectedIndexes) {
selectedIndexesPasted[i] = integer.intValue();
i++;
}
list.setSelectedIndices(selectedIndexesPasted);
list.scrollRectToVisible(list.getCellBounds(list.getMinSelectionIndex(), list.getMaxSelectionIndex()));
} catch (NullPointerException | UnsupportedFlavorException | IOException e) {
// Fix #8831: Multiple Exception on scrollRectToVisible()
LOGGER.error(e.getMessage(), e);
}
} else if (transferableFromClipboard.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
try {
int selectedIndex = 0;
if (list.getSelectedIndex() > 0) {
selectedIndex = list.getSelectedIndex();
}
list.clearSelection();
list.dropPasteFile((List<File>) transferableFromClipboard.getTransferData(DataFlavor.javaFileListFlavor), selectedIndex);
} catch (UnsupportedFlavorException | IOException e) {
LOGGER.error(e.getMessage(), e);
}
}
}
}
return true;
}
use of java.awt.datatransfer.UnsupportedFlavorException in project jsql-injection by ron190.
the class TabTransferHandler method importData.
@Override
public boolean importData(TransferHandler.TransferSupport support) {
System.out.println("importData");
if (!this.canImport(support)) {
return false;
}
DnDTabbedPane target = (DnDTabbedPane) support.getComponent();
DnDTabbedPane.DropLocation dl = target.getDropLocation();
try {
DnDTabData data = (DnDTabData) support.getTransferable().getTransferData(this.localObjectFlavor);
DnDTabbedPane src = data.tabbedPane;
// boolean insert = dl.isInsert();
int index = dl.getIndex();
if (target.equals(src)) {
// getTargetTabIndex(e.getLocation()));
src.convertTab(src.dragTabIndex, index);
} else {
src.exportTab(src.dragTabIndex, target, index);
}
return true;
} catch (UnsupportedFlavorException | IOException ex) {
ex.printStackTrace();
}
return false;
}
Aggregations