0
|
1 /*
|
|
2 * The main application window.
|
|
3 */
|
|
4 package name.blackcap.imageprep
|
|
5
|
|
6 import java.awt.Dimension
|
|
7 import java.awt.datatransfer.DataFlavor
|
|
8 import java.awt.datatransfer.Transferable
|
|
9 import java.awt.datatransfer.UnsupportedFlavorException
|
|
10 import java.awt.event.WindowEvent
|
|
11 import java.awt.event.WindowListener
|
|
12 import java.io.File
|
|
13 import java.io.IOException
|
|
14 import java.util.logging.Level
|
|
15 import java.util.logging.Logger
|
|
16 import javax.swing.*
|
|
17 import javax.imageio.ImageIO
|
|
18
|
|
19 /* the main frame itself */
|
|
20 class MainFrame : JFrame(Application.MYNAME) {
|
|
21 /* default size */
|
|
22 val WIDTH = 512
|
|
23 val HEIGHT = 384
|
|
24
|
|
25 /* does a system exit when needed */
|
|
26 private class KillIt() : WindowListener {
|
|
27 /* events we don't care about */
|
|
28 override fun windowActivated(e: WindowEvent) {}
|
|
29 override fun windowClosed(e: WindowEvent) {}
|
|
30 override fun windowDeactivated(e: WindowEvent) {}
|
|
31 override fun windowDeiconified(e: WindowEvent) {}
|
|
32 override fun windowIconified(e: WindowEvent) {}
|
|
33 override fun windowOpened(e: WindowEvent) {}
|
|
34
|
|
35 /* and the one we do */
|
|
36 override fun windowClosing(e: WindowEvent) {
|
|
37 LOGGER.log(Level.INFO, "execution complete")
|
|
38 System.exit(0)
|
|
39 }
|
|
40 }
|
|
41
|
|
42 /* acts on dragged files */
|
|
43 private class MyTransferHandler : TransferHandler() {
|
|
44 override fun canImport(support: TransferHandler.TransferSupport): Boolean {
|
|
45 return support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
|
|
46 }
|
|
47
|
|
48 override fun importData(support: TransferHandler.TransferSupport): Boolean {
|
|
49 if (!canImport(support)) {
|
|
50 return false
|
|
51 }
|
|
52 val files = try {
|
|
53 support.transferable.getTransferData(DataFlavor.javaFileListFlavor) as List<File>
|
|
54 } catch (e: UnsupportedFlavorException) {
|
|
55 return false
|
|
56 } catch (e: IOException) {
|
|
57 return false
|
|
58 }
|
|
59 for (file in files) {
|
|
60 RotateDialog.makeDialog(file)
|
|
61 }
|
|
62 return true
|
|
63 }
|
|
64 }
|
|
65
|
|
66 init {
|
|
67 contentPane.add(
|
|
68 JLabel("Drag image files into this window or choose Fileā¦ Open & Scale from menu.").apply {
|
|
69 horizontalAlignment = JLabel.CENTER
|
|
70 verticalAlignment = JLabel.CENTER
|
|
71 })
|
|
72 preferredSize = Dimension(WIDTH, HEIGHT)
|
|
73 transferHandler = MyTransferHandler()
|
|
74 pack()
|
|
75 addWindowListener(KillIt())
|
|
76 }
|
|
77 }
|
|
78
|