This repository has been archived by the owner on Jun 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
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 #230 from oharaandrew314/v1.4
V1.4
- Loading branch information
Showing
34 changed files
with
1,227 additions
and
753 deletions.
There are no files selected for viewing
Submodule Common
updated
from 682fcc to efbff3
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file renamed
BIN
+1.36 KB
res/icon/glyphicons_063_power.png → res/icon/glyphicons_144_folder_open.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,110 @@ | ||
package aohara.tinkertime; | ||
|
||
import java.awt.Component; | ||
import java.awt.datatransfer.DataFlavor; | ||
import java.awt.datatransfer.Transferable; | ||
import java.awt.datatransfer.UnsupportedFlavorException; | ||
import java.awt.dnd.DnDConstants; | ||
import java.awt.dnd.DropTarget; | ||
import java.awt.dnd.DropTargetDragEvent; | ||
import java.awt.dnd.DropTargetDropEvent; | ||
import java.awt.dnd.DropTargetEvent; | ||
import java.awt.dnd.DropTargetListener; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.nio.file.Files; | ||
import java.util.Collection; | ||
|
||
import aohara.common.views.Dialogs; | ||
import aohara.tinkertime.ModManager.ModUpdateFailedError; | ||
import aohara.tinkertime.crawlers.CrawlerFactory.UnsupportedHostException; | ||
|
||
public class AddModDragDropHandler { | ||
|
||
public AddModDragDropHandler(final Component listenTo, final ModManager modManager){ | ||
new DropTarget(listenTo, new DropTargetListener(){ | ||
|
||
@Override | ||
public void dragEnter(DropTargetDragEvent dtde) { | ||
try { | ||
File file = getFile(dtde.getTransferable()); | ||
if (isZip(file) || isUrl(file)){ | ||
dtde.acceptDrag(DnDConstants.ACTION_LINK); | ||
} else { | ||
dtde.rejectDrag(); | ||
} | ||
} catch (UnsupportedFlavorException | IOException e) { | ||
e.printStackTrace(); | ||
dtde.rejectDrag(); | ||
} | ||
listenTo.repaint(); | ||
} | ||
|
||
private File getFile(Transferable t) throws UnsupportedFlavorException, IOException{ | ||
Object td = t.getTransferData(DataFlavor.javaFileListFlavor); | ||
if (td instanceof Collection){ | ||
for (Object value : (Collection<?>) td){ | ||
if (value instanceof File){ | ||
return (File) value; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
private boolean isZip(File file){ | ||
return file != null && file.getName().endsWith(".zip"); | ||
} | ||
|
||
private boolean isUrl(File file){ | ||
return file != null && file.getName().endsWith(".url"); | ||
} | ||
|
||
private void handleUrlFile(File file){ | ||
try { | ||
String contents = new String(Files.readAllBytes(file.toPath())); | ||
String url = contents.split("URL=")[1].split("]")[0]; | ||
modManager.downloadMod(new URL(url)); | ||
} catch (IOException | UnsupportedHostException | ModUpdateFailedError e) { | ||
Dialogs.errorDialog(listenTo, e); | ||
} | ||
} | ||
|
||
private void handleZipFile(File file){ | ||
modManager.addModZip(file.toPath()); | ||
} | ||
|
||
@Override | ||
public void dragOver(DropTargetDragEvent dtde) { | ||
// No Action | ||
} | ||
|
||
@Override | ||
public void dropActionChanged(DropTargetDragEvent dtde) { | ||
// No Action | ||
} | ||
|
||
@Override | ||
public void dragExit(DropTargetEvent dte) { | ||
// No Action | ||
} | ||
|
||
@Override | ||
public void drop(DropTargetDropEvent dtde) { | ||
dtde.acceptDrop(DnDConstants.ACTION_COPY); | ||
try { | ||
File file = getFile(dtde.getTransferable()); | ||
if (isZip(file)){ | ||
handleZipFile(file); | ||
} else if (isUrl(file)){ | ||
handleUrlFile(file); | ||
} | ||
} catch (UnsupportedFlavorException | IOException e) { | ||
Dialogs.errorDialog(listenTo, e); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
} |
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,63 @@ | ||
package aohara.tinkertime; | ||
|
||
import java.awt.event.KeyEvent; | ||
import java.awt.event.KeyListener; | ||
|
||
import aohara.common.selectorPanel.SelectorListListener; | ||
import aohara.common.views.Dialogs; | ||
import aohara.tinkertime.ModManager.NoModSelectedException; | ||
import aohara.tinkertime.models.Mod; | ||
import aohara.tinkertime.views.TinkerDialogs; | ||
|
||
class ModListListener implements KeyListener, SelectorListListener<Mod> { | ||
|
||
private final ModManager mm; | ||
|
||
ModListListener(ModManager mm){ | ||
this.mm = mm; | ||
} | ||
|
||
@Override | ||
public void keyPressed(KeyEvent e) { | ||
// Do Nothing | ||
} | ||
|
||
@Override | ||
public void keyReleased(KeyEvent e) { | ||
// Do Nothing | ||
} | ||
|
||
@Override | ||
public void keyTyped(KeyEvent evt) { | ||
try{ | ||
switch(evt.getKeyChar()){ | ||
case KeyEvent.VK_DELETE: | ||
Mod selectedMod = mm.getSelectedMod(); | ||
if (TinkerDialogs.confirmDeleteMod(evt.getComponent(), selectedMod.name)){ | ||
mm.deleteMod(selectedMod); | ||
} | ||
break; | ||
case KeyEvent.VK_ENTER: | ||
mm.toggleMod(mm.getSelectedMod()); | ||
break; | ||
} | ||
} catch (NoModSelectedException ex){ | ||
// Do nothing | ||
} catch(Exception ex){ | ||
Dialogs.errorDialog(evt.getComponent(), ex); | ||
} | ||
} | ||
|
||
@Override | ||
public void elementClicked(Mod mod, int numTimes) { | ||
if (numTimes == 2){ | ||
mm.toggleMod(mod); | ||
} | ||
} | ||
|
||
@Override | ||
public void elementSelected(Mod element) { | ||
mm.selectMod(element); | ||
} | ||
|
||
} |
Oops, something went wrong.