本文整理匯總了Java中java.awt.dnd.DropTargetDropEvent.isDataFlavorSupported方法的典型用法代碼示例。如果您正苦於以下問題:Java DropTargetDropEvent.isDataFlavorSupported方法的具體用法?Java DropTargetDropEvent.isDataFlavorSupported怎麽用?Java DropTargetDropEvent.isDataFlavorSupported使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.dnd.DropTargetDropEvent
的用法示例。
在下文中一共展示了DropTargetDropEvent.isDataFlavorSupported方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: drop
import java.awt.dnd.DropTargetDropEvent; //導入方法依賴的package包/類
@Override
public void drop(DropTargetDropEvent dtde) {
if (dtde.isDataFlavorSupported(VillageTransferable.villageDataFlavor) || dtde.isDataFlavorSupported(DataFlavor.stringFlavor)) {
dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
} else {
dtde.rejectDrop();
return;
}
Transferable t = dtde.getTransferable();
List<Village> v;
MapPanel.getSingleton().setCurrentCursor(MapPanel.getSingleton().getCurrentCursor());
try {
v = (List<Village>) t.getTransferData(VillageTransferable.villageDataFlavor);
fireVillagesDraggedEvent(v, dtde.getLocation());
} catch (Exception ignored) {
}
}
示例2: drop
import java.awt.dnd.DropTargetDropEvent; //導入方法依賴的package包/類
@Override
public void drop(DropTargetDropEvent arg0) {
Transferable tr = arg0.getTransferable();
arg0.acceptDrop(DnDConstants.ACTION_REFERENCE);
if(arg0.isDataFlavorSupported(DataFlavor.javaFileListFlavor)){
try {
@SuppressWarnings("unchecked")
List<File> fileList = (List<File>)tr.getTransferData(DataFlavor.javaFileListFlavor);
for(File file: fileList){
AttackResultFrame resultFrame = new AttackResultFrame();
if (resultFrame.loadResult(file) == true){
resultFrame.setVisible(true);
resultFrame.invalidate();
}else{
resultFrame = null;
}
}
} catch (UnsupportedFlavorException | IOException e) {
logger.debug(e);
}
}
}
示例3: getString
import java.awt.dnd.DropTargetDropEvent; //導入方法依賴的package包/類
/**
* Gets the string.
*
* @param event
* the event
* @return the string
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws UnsupportedFlavorException
* the unsupported flavor exception
*/
@SuppressWarnings("unchecked")
static String getString(DropTargetDropEvent event) throws IOException, UnsupportedFlavorException {
String text = null;
DataFlavor fileList = DataFlavor.javaFileListFlavor;
if (event.isDataFlavorSupported(fileList)) {
event.acceptDrop(DnDConstants.ACTION_COPY);
List<File> list = (List<File>) event.getTransferable().getTransferData(fileList);
text = list.get(0).getAbsolutePath();
} else if (event.isDataFlavorSupported(DataFlavor.stringFlavor)) {
event.acceptDrop(DnDConstants.ACTION_COPY);
text = (String) event.getTransferable().getTransferData(DataFlavor.stringFlavor);
if (text.startsWith("file://"))
text = text.substring(7);
text = stripSuffix(stripSuffix(text, "\n"), "\r").replaceAll("%20", " ");
} else {
event.rejectDrop();
return null;
}
event.dropComplete(text != null);
return text;
}
示例4: chooseDropFlavor
import java.awt.dnd.DropTargetDropEvent; //導入方法依賴的package包/類
/**
* Called by drop and retrieves the <code>DataFlavor</code> for the
* input <code>DropTargetDropEvent</code>
*
* @param e
* the DropTargetDropEvent object
* @return the chosen DataFlavor or null if none match
*/
private DataFlavor chooseDropFlavor(final DropTargetDropEvent e) {
if ((e.isLocalTransfer() == true) && e.isDataFlavorSupported(StringTransferable.LOCAL_STRING_FLAVOR)) {
return StringTransferable.LOCAL_STRING_FLAVOR;
}
DataFlavor chosen = null;
if (e.isDataFlavorSupported(StringTransferable.LOCAL_STRING_FLAVOR)) {
chosen = StringTransferable.LOCAL_STRING_FLAVOR;
}
if (e.isDataFlavorSupported(NewObservationUsingConceptNameButton.BUTTON_FLAVOR)) {
chosen = NewObservationUsingConceptNameButton.BUTTON_FLAVOR;
}
return chosen;
}
示例5: drop
import java.awt.dnd.DropTargetDropEvent; //導入方法依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public void drop(DropTargetDropEvent dtde) {
if (!dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
dtde.rejectDrop();
return;
}
dtde.acceptDrop(dtde.getDropAction());
try {
Transferable transferable = dtde.getTransferable();
List<File> transferData = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
if (transferData != null && transferData.size() > 0) {
dtde.dropComplete(true);
// load first file
mainWindow.openFile(transferData.get(0));
}
} catch (Exception e) {
LOG.error("File drop operation failed", e);
}
}
示例6: drop
import java.awt.dnd.DropTargetDropEvent; //導入方法依賴的package包/類
public void drop(DropTargetDropEvent dtde) {
if (dtde.isDataFlavorSupported(DataFlavor.stringFlavor)) {
dtde.dropComplete(true);
if (activeDragItem != null) {
activeDragItem.dragAccepted();
}
} else {
dtde.rejectDrop();
}
component.setCursor(oCursor);
activeDragItem = null;
component.repaint();
}
示例7: drag
import java.awt.dnd.DropTargetDropEvent; //導入方法依賴的package包/類
public static void drag()//定義的拖拽方法
{
//panel表示要接受拖拽的控件
new DropTarget(JlPath, DnDConstants.ACTION_COPY_OR_MOVE, new DropTargetAdapter() {
public void drop(DropTargetDropEvent dtde)//重寫適配器的drop方法
{
try {
if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor))//如果拖入的文件格式受支持
{
dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);//接收拖拽來的數據
List<File> list = (List<File>) (dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor));
String temp = "";
for (File file : list) {
temp = file.getAbsolutePath();
JlPath.setText(temp);
break;
}
//JOptionPane.showMessageDialog(null, temp);
dtde.dropComplete(true);//指示拖拽操作已完成
} else {
dtde.rejectDrop();//否則拒絕拖拽來的數據
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
示例8: drop
import java.awt.dnd.DropTargetDropEvent; //導入方法依賴的package包/類
@Override
public void drop( DropTargetDropEvent dtde ) {
if ( !dtde.isDataFlavorSupported( DataFlavor.javaFileListFlavor ) ) {
dtde.rejectDrop();
return;
}
dtde.acceptDrop( dtde.getDropAction() );
Transferable trans = dtde.getTransferable();
List<File> files;
try {
files = (List<File>) trans.getTransferData( DataFlavor.javaFileListFlavor );
}
catch ( UnsupportedFlavorException | IOException e ) {
log.error( e );
dtde.dropComplete( false );
return;
}
log.debug( "file drop" );
ProgressTask pt = OpenAction.openFiles( DIHelper.getInstance().getDesktop(),
files, null );
OperationsProgress.getInstance( PlayPane.UIPROGRESS ).add( pt );
dtde.dropComplete( true );
}
示例9: drop
import java.awt.dnd.DropTargetDropEvent; //導入方法依賴的package包/類
public void drop(DropTargetDropEvent event) {
try {
Transferable trans = event.getTransferable();
if (event.isDataFlavorSupported(Constraint.dataFlavor)) {
Constraint.ConstraintData cons = (Constraint.ConstraintData) trans.getTransferData(Constraint.dataFlavor);
event.acceptDrop(DnDConstants.ACTION_COPY);
boolean res = processDroppedConstraint(event.getLocation(), cons);
if (res) {
if (cons.getFacetType() == Facet.FacetType.CATEGORICAL)
for (Long id : cons.valueIDs) {
Constraint.ConstraintData sepcons = new Constraint.ConstraintData(cons.facetID);
sepcons.valueIDs.add(id);
rootFrame.historyPanel.addOperation(sepcons);
}
else
rootFrame.historyPanel.addOperation(cons);
}
event.dropComplete(true);
return;
}
else if (event.isDataFlavorSupported(NodesFilter.dataFlavor)) {
NodesFilter f = (NodesFilter) trans.getTransferData(NodesFilter.dataFlavor);
event.acceptDrop(DnDConstants.ACTION_MOVE);
processDroppedFilter(event.getLocation(), f);
event.dropComplete(true);
return;
}
event.rejectDrop();
} catch (Exception e) {
e.printStackTrace();
event.rejectDrop();
rootFrame.showErrorMessage("Drag&Drop error:\n" + e.toString());
}
}
示例10: initJListFileDropOnWindows
import java.awt.dnd.DropTargetDropEvent; //導入方法依賴的package包/類
/**
* Initialisiert Drop auf Windows
* @see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4899516
*/
private void initJListFileDropOnWindows(){
DropTarget target = new DropTarget(jList1, new DropTargetAdapter() {
@Override
public void drop(DropTargetDropEvent dtde) {
if(dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)){
dtde.acceptDrop(dtde.getDropAction());
try {
//siehe: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4899516
final List<File> list = (List<File>) dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
//Hier steht der eigentliche Drop Code
if(CollectionManager.INSTANCE.isACollectionCreated()){
//ImportGUI im extra Thread, damit durch den Import Prozess keine Verzögerungen auftreten
Runnable runImport = new Runnable() {
@Override
public void run() {
ImportDirectoryGUI fileImport = new ImportDirectoryGUI(
MovieManagerGUI.getInstance(),
true,
MovieManagerGUI.getInstance().getTabNames(),
list,
collection);
fileImport.showGUI();
}
};
SwingUtilities.invokeLater(runImport);
}
}
catch (UnsupportedFlavorException | IOException ex) {
LOG.error("Error while dropping file into MovieList.", ex);
}
}
}
});
jList1.setDropTarget(target);
}
示例11: initJListFileDropOnWindows
import java.awt.dnd.DropTargetDropEvent; //導入方法依賴的package包/類
/**
* Initialisiert Drop auf Windows
* @see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4899516
*/
private void initJListFileDropOnWindows(){
DropTarget target = new DropTarget(jTree1, new DropTargetAdapter() {
@Override
public void drop(DropTargetDropEvent dtde) {
if(dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)){
dtde.acceptDrop(dtde.getDropAction());
try {
//siehe: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4899516
final List<File> list = (List<File>) dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
//Hier steht der eigentliche Drop Code
if(CollectionManager.INSTANCE.isACollectionCreated()){
//ImportGUI im extra Thread, damit durch den Import Prozess keine Verzögerungen auftreten
Runnable runImport = new Runnable() {
@Override
public void run() {
ImportDirectoryGUI fileImport = new ImportDirectoryGUI(
MovieManagerGUI.getInstance(),
true,
MovieManagerGUI.getInstance().getTabNames(),
list,
collection);
fileImport.showGUI();
}
};
SwingUtilities.invokeLater(runImport);
}
}
catch (UnsupportedFlavorException | IOException ex) {
LOG.error("Error while dropping file into SeriesTree.", ex);
}
}
}
});
jTree1.setDropTarget(target);
}
示例12: chooseDropFlavor
import java.awt.dnd.DropTargetDropEvent; //導入方法依賴的package包/類
protected DataFlavor chooseDropFlavor(DropTargetDropEvent e)
{
if (e.isDataFlavorSupported(SDFileMoleculeTransferable.DF_SERIALIZEDSTRUCTURETRANSFERDATA))
return SDFileMoleculeTransferable.DF_SERIALIZEDSTRUCTURETRANSFERDATA;
else
return super.chooseDropFlavor(e);
}
示例13: drop
import java.awt.dnd.DropTargetDropEvent; //導入方法依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public void drop(DropTargetDropEvent event) {
if (event.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
event.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
DataFlavor df = DataFlavor.javaFileListFlavor;
List<File> list = null;
try {
list = (List<File>) (event.getTransferable().getTransferData(df));
} catch (Exception e) {
e.printStackTrace();
}
Iterator<File> iterator = list.iterator();
while (iterator.hasNext()) {
File file = iterator.next();
if (file.exists() && file.isFile()) {
String filePath = file.getAbsolutePath();
if (filePath == null || filePath.equals("")) {
System.out.println("文件名為 null 或為 \"\"~");
break;
}
if (!filePath.endsWith(".jar")) {
String str = "此工具專門為jar包設計,不通用!! 請注意!!";
JOptionPane.showMessageDialog(null, str);
break;
}
tas.jTextField_file.setText(filePath);
System.out.println("jarFilePath=" + filePath);
}
// 一次隻能處理一個,要避免處理多個的情況,因此 break 跳出~
break;
}
event.dropComplete(true);
} else {
event.rejectDrop();
}
}
示例14: drop
import java.awt.dnd.DropTargetDropEvent; //導入方法依賴的package包/類
@Override
public void drop(DropTargetDropEvent dtde)
{
if (dtde.isDataFlavorSupported(CardFlavor.cardFlavor) && this.canDrop)
{
Transferable trans = dtde.getTransferable();
try
{
Object data = trans.getTransferData(CardFlavor.cardFlavor);
CardWindow card =(CardWindow)data;
DropTargetContext context = dtde.getDropTargetContext();
CardCollection comp = (CardCollection)context.getComponent();
Container parent = comp.getParent();
GameController.getController(false)
.makeMove(CardCollection.getMoveFromIndex(comp.getCardMouseLocation(), new OrderedCard(card.card, card.cardLocation)));
if (parent != null)
parent.remove(card);
comp.setCard(card, comp.getCardMouseLocation());
dtde.acceptDrop(DnDConstants.ACTION_MOVE);
comp.validate();
comp.repaint();
dtde.dropComplete(true);
}
catch (Exception e)
{
dtde.rejectDrop();
dtde.dropComplete(false);
JOptionPane.showMessageDialog(MainWindow.getMainWindow(), "Invalid move.", "Invalid Move Error", JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
}
}
else
{
dtde.rejectDrop();
dtde.dropComplete(false);
JOptionPane.showMessageDialog(MainWindow.getMainWindow(), "Invalid move.", "Invalid Move Error", JOptionPane.ERROR_MESSAGE);
}
}
示例15: getString
import java.awt.dnd.DropTargetDropEvent; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
static String getString(final DropTargetDropEvent event) throws IOException,
UnsupportedFlavorException
{
String text = null;
final DataFlavor fileList = DataFlavor.javaFileListFlavor;
if (event.isDataFlavorSupported(fileList)) {
event.acceptDrop(DnDConstants.ACTION_COPY);
final List<File> list = (List<File>) event.getTransferable()
.getTransferData(fileList);
text = list.get(0).getAbsolutePath();
}
else if (event.isDataFlavorSupported(DataFlavor.stringFlavor)) {
event.acceptDrop(DnDConstants.ACTION_COPY);
text = (String) event.getTransferable().getTransferData(
DataFlavor.stringFlavor);
if (text.startsWith("file://")) text = text.substring(7);
text = stripSuffix(stripSuffix(text, "\n"), "\r").replaceAll("%20", " ");
}
else {
event.rejectDrop();
return null;
}
event.dropComplete(text != null);
return text;
}