-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1657 from pavelbraginskiy/drag-drop
Fix cursor when drag-dropping in MML
- Loading branch information
Showing
4 changed files
with
66 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
megameklab/src/megameklab/util/MMLFileDropTransferHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package megameklab.util; | ||
|
||
import megamek.logging.MMLogger; | ||
import megameklab.ui.MenuBarOwner; | ||
|
||
import javax.swing.*; | ||
import java.awt.datatransfer.DataFlavor; | ||
import java.awt.datatransfer.Transferable; | ||
import java.io.File; | ||
import java.util.List; | ||
|
||
public class MMLFileDropTransferHandler extends TransferHandler { | ||
private static final MMLogger logger = MMLogger.create(MMLFileDropTransferHandler.class); | ||
private final MenuBarOwner owner; | ||
|
||
public MMLFileDropTransferHandler(MenuBarOwner owner) { | ||
this.owner = owner; | ||
} | ||
|
||
@Override | ||
public boolean canImport(TransferSupport support) { | ||
if (!support.isDrop()) { | ||
return false; | ||
} | ||
return support.isDataFlavorSupported(DataFlavor.javaFileListFlavor); | ||
} | ||
|
||
|
||
@Override | ||
public boolean importData(TransferSupport support) { | ||
if (!canImport(support)) { | ||
return false; | ||
} | ||
|
||
try { | ||
var files = (List<File>) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor); | ||
if (files.size() != 1) { | ||
logger.error("Cannot open multiple files at a time!", "Import error"); | ||
return false; | ||
} | ||
|
||
var file = files.get(0); | ||
var name = file.getName(); | ||
|
||
if (name.toLowerCase().endsWith(".mtf") || name.toLowerCase().endsWith(".blk")) { | ||
owner.getMMLMenuBar().loadFile(file); | ||
return true; | ||
} else if (name.toLowerCase().endsWith(".mul")) { | ||
UnitPrintManager.printMUL(owner.getFrame(), CConfig.getBooleanParam(CConfig.MISC_MUL_OPEN_BEHAVIOUR), file); | ||
return true; | ||
} else { | ||
logger.error("Can only open files of type .mtf, .blk, and .mul", "Import error"); | ||
return false; | ||
} | ||
|
||
|
||
} catch (Exception e) { | ||
logger.error(e); | ||
return false; | ||
} | ||
} | ||
} |