use of java.awt.datatransfer.UnsupportedFlavorException in project android-classyshark by google.
the class FileTransferHandler method importData.
public boolean importData(TransferSupport ts) {
try {
@SuppressWarnings("rawtypes") List data = (List) ts.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
if (data.size() < 1) {
return false;
}
for (Object item : data) {
File file = (File) item;
if (isSupportedArchiveFile(file)) {
CurrentFolderConfig.INSTANCE.setCurrentDirectory(file.getParentFile());
RecentArchivesConfig.INSTANCE.addArchive(file.getName(), file.getParentFile());
archiveDisplayer.displayArchive(file);
}
}
return true;
} catch (UnsupportedFlavorException e) {
return false;
} catch (IOException e) {
return false;
}
}
use of java.awt.datatransfer.UnsupportedFlavorException in project logisim-evolution by reds-heig.
the class TableTabClip method paste.
public void paste() {
Clipboard clip = table.getToolkit().getSystemClipboard();
Transferable xfer;
try {
xfer = clip.getContents(this);
} catch (IllegalStateException | ArrayIndexOutOfBoundsException t) {
// I don't know - the above was observed to throw an odd
// ArrayIndexOutOfBounds
// exception on a Linux computer using Sun's Java 5 JVM
JOptionPane.showMessageDialog(table.getRootPane(), Strings.get("clipPasteSupportedError"), Strings.get("clipPasteErrorTitle"), JOptionPane.ERROR_MESSAGE);
return;
}
Entry[][] entries;
if (xfer.isDataFlavorSupported(binaryFlavor)) {
try {
Data data = (Data) xfer.getTransferData(binaryFlavor);
entries = new Entry[data.contents.length][];
for (int i = 0; i < entries.length; i++) {
Entry[] row = new Entry[data.contents[i].length];
for (int j = 0; j < row.length; j++) {
row[j] = Entry.parse(data.contents[i][j]);
}
entries[i] = row;
}
} catch (UnsupportedFlavorException e) {
return;
} catch (IOException e) {
return;
}
} else if (xfer.isDataFlavorSupported(DataFlavor.stringFlavor)) {
try {
String buf = (String) xfer.getTransferData(DataFlavor.stringFlavor);
StringTokenizer lines = new StringTokenizer(buf, "\r\n");
String first;
if (!lines.hasMoreTokens())
return;
first = lines.nextToken();
StringTokenizer toks = new StringTokenizer(first, "\t,");
String[] headers = new String[toks.countTokens()];
Entry[] firstEntries = new Entry[headers.length];
boolean allParsed = true;
for (int i = 0; toks.hasMoreTokens(); i++) {
headers[i] = toks.nextToken();
firstEntries[i] = Entry.parse(headers[i]);
allParsed = allParsed && firstEntries[i] != null;
}
int rows = lines.countTokens();
if (allParsed)
rows++;
entries = new Entry[rows][];
int cur = 0;
if (allParsed) {
entries[0] = firstEntries;
cur++;
}
while (lines.hasMoreTokens()) {
toks = new StringTokenizer(lines.nextToken(), "\t");
Entry[] ents = new Entry[toks.countTokens()];
for (int i = 0; toks.hasMoreTokens(); i++) {
ents[i] = Entry.parse(toks.nextToken());
}
entries[cur] = ents;
cur++;
}
} catch (UnsupportedFlavorException e) {
return;
} catch (IOException e) {
return;
}
} else {
JOptionPane.showMessageDialog(table.getRootPane(), Strings.get("clipPasteSupportedError"), Strings.get("clipPasteErrorTitle"), JOptionPane.ERROR_MESSAGE);
return;
}
TableTabCaret caret = table.getCaret();
int c0 = caret.getCursorCol();
int c1 = caret.getMarkCol();
int r0 = caret.getCursorRow();
int r1 = caret.getMarkRow();
if (r0 < 0 || r1 < 0 || c0 < 0 || c1 < 0)
return;
TruthTable model = table.getTruthTable();
int rows = model.getRowCount();
int inputs = model.getInputColumnCount();
int outputs = model.getOutputColumnCount();
if (c0 == c1 && r0 == r1) {
if (r0 + entries.length > rows || c0 + entries[0].length > inputs + outputs) {
JOptionPane.showMessageDialog(table.getRootPane(), Strings.get("clipPasteEndError"), Strings.get("clipPasteErrorTitle"), JOptionPane.ERROR_MESSAGE);
return;
}
} else {
if (r0 > r1) {
int t = r0;
r0 = r1;
r1 = t;
}
if (c0 > c1) {
int t = c0;
c0 = c1;
c1 = t;
}
if (r1 - r0 + 1 != entries.length || c1 - c0 + 1 != entries[0].length) {
JOptionPane.showMessageDialog(table.getRootPane(), Strings.get("clipPasteSizeError"), Strings.get("clipPasteErrorTitle"), JOptionPane.ERROR_MESSAGE);
return;
}
}
for (int r = 0; r < entries.length; r++) {
for (int c = 0; c < entries[0].length; c++) {
if (c0 + c >= inputs) {
model.setOutputEntry(r0 + r, c0 + c - inputs, entries[r][c]);
}
}
}
}
use of java.awt.datatransfer.UnsupportedFlavorException in project Openfire by igniterealtime.
the class DroppableTextPane method drop.
@Override
public void drop(DropTargetDropEvent dropTargetDropEvent) {
try {
Transferable transferable = dropTargetDropEvent.getTransferable();
if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
dropTargetDropEvent.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
List fileList = (List) transferable.getTransferData(DataFlavor.javaFileListFlavor);
Iterator iterator = fileList.iterator();
while (iterator.hasNext()) {
File file = (File) iterator.next();
if (file.isFile()) {
fileDropped(file);
}
if (file.isDirectory()) {
directoryDropped(file);
}
}
dropTargetDropEvent.getDropTargetContext().dropComplete(true);
} else {
dropTargetDropEvent.rejectDrop();
}
} catch (IOException | UnsupportedFlavorException io) {
io.printStackTrace();
dropTargetDropEvent.rejectDrop();
}
}
use of java.awt.datatransfer.UnsupportedFlavorException in project java-swing-tips by aterai.
the class FileChooserTransferHandler method importData.
@Override
public boolean importData(TransferSupport support) {
try {
JFileChooser fc = (JFileChooser) support.getComponent();
List<?> list = (List<?>) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
File[] files = new File[list.size()];
for (int i = 0; i < list.size(); i++) {
files[i] = (File) list.get(i);
}
if (fc.isMultiSelectionEnabled()) {
fc.setSelectedFiles(files);
} else {
File f = files[0];
if (f.isDirectory()) {
fc.setCurrentDirectory(f);
} else {
fc.setSelectedFile(f);
}
}
return true;
} catch (IOException | UnsupportedFlavorException ex) {
// ex.printStackTrace();
return false;
}
}
use of java.awt.datatransfer.UnsupportedFlavorException in project java-swing-tips by aterai.
the class TabTitleDropTargetListener method drop.
@SuppressWarnings("unchecked")
@Override
public void drop(DropTargetDropEvent e) {
try {
DropTargetContext c = e.getDropTargetContext();
Component o = c.getComponent();
Transferable t = e.getTransferable();
DataFlavor[] f = t.getTransferDataFlavors();
if (o instanceof JTabbedPane) {
JTabbedPane jtp = (JTabbedPane) o;
JScrollPane sp = (JScrollPane) jtp.getComponentAt(targetTabIndex);
JViewport vp = sp.getViewport();
JList<String> targetList = (JList<String>) SwingUtilities.getUnwrappedView(vp);
JList<String> sourceList = (JList<String>) t.getTransferData(f[0]);
DefaultListModel<String> tm = (DefaultListModel<String>) targetList.getModel();
DefaultListModel<String> sm = (DefaultListModel<String>) sourceList.getModel();
int[] indices = sourceList.getSelectedIndices();
for (int j = indices.length - 1; j >= 0; j--) {
tm.addElement(sm.remove(indices[j]));
}
e.dropComplete(true);
} else {
e.dropComplete(false);
}
} catch (UnsupportedFlavorException | IOException ex) {
e.dropComplete(false);
}
}
Aggregations