Mercurial > cgi-bin > hgweb.cgi > ImagePrep
comparison src/name/blackcap/imageprep/Main.kt @ 19:5fa5d15b4a7b
Attempt to make it a std. app. Builds, sorta runs, needs more work.
author | David Barts <n5jrn@me.com> |
---|---|
date | Fri, 20 Nov 2020 21:38:06 -0800 |
parents | 884f1415a330 |
children | 92afaa27f40a |
comparison
equal
deleted
inserted
replaced
18:43884786343e | 19:5fa5d15b4a7b |
---|---|
20 val MYNAME = "ImagePrep" | 20 val MYNAME = "ImagePrep" |
21 | 21 |
22 /* global UI objects */ | 22 /* global UI objects */ |
23 var mainFrame: MainFrame by setOnce() | 23 var mainFrame: MainFrame by setOnce() |
24 var helpDialog: HelpDialog by setOnce() | 24 var helpDialog: HelpDialog by setOnce() |
25 var settingsDialog: SettingsDialog by setOnce() | |
25 | 26 |
26 fun initialize() { | 27 fun initialize() { |
27 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | 28 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
28 mainFrame = MainFrame() /* must be created first */ | 29 mainFrame = MainFrame() /* must be created first */ |
30 settingsDialog = SettingsDialog() | |
29 mainFrame.jMenuBar = MyMenuBar() | 31 mainFrame.jMenuBar = MyMenuBar() |
30 setMacMenus() /* always safe to call; no-op if not a Mac */ | 32 setMacMenus() /* always safe to call; no-op if not a Mac */ |
31 helpDialog = HelpDialog() | 33 helpDialog = HelpDialog() |
32 mainFrame.setVisible(true) | 34 mainFrame.setVisible(true) |
33 } | 35 } |
38 LOGGER.log(Level.INFO, "beginning execution") | 40 LOGGER.log(Level.INFO, "beginning execution") |
39 if (OS.type == OS.MAC) { | 41 if (OS.type == OS.MAC) { |
40 System.setProperty("apple.laf.useScreenMenuBar", "true") | 42 System.setProperty("apple.laf.useScreenMenuBar", "true") |
41 } | 43 } |
42 | 44 |
43 /* parse command line */ | |
44 if (Settings.outputToInputDir) | |
45 Settings.outputTo = System.getProperty("user.dir") | |
46 val options = Options().apply { | |
47 addOption(Option<Unit>("?", "help", false, "Print this help message.")) | |
48 addOption(Option<Int>("m", "maxdim", true, "Maximum dimension (default: ${Settings.maxDimension})").apply { | |
49 default = Settings.maxDimension | |
50 interpolater = { | |
51 val ret = try { it.toInt() } catch (e: NumberFormatException) { -1 } | |
52 if (ret < 1) | |
53 throw InvalidArgumentException("Dimension must be a positive integer.") | |
54 Settings.maxDimension = ret | |
55 ret | |
56 } | |
57 }) | |
58 addOption(Option<File>("o", "output", true, "Output directory (default: ${Settings.outputTo})").apply { | |
59 default = File(Settings.outputTo) | |
60 interpolater = { | |
61 val ret = File(tilde(it)) | |
62 if (!ret.exists()) | |
63 throw InvalidArgumentException("'${it}' does not exist") | |
64 if (!ret.isDirectory()) | |
65 throw InvalidArgumentException("'${it}' is not a directory") | |
66 Settings.outputTo = ret.canonicalPath | |
67 ret | |
68 } | |
69 }) | |
70 addOption(Option<Int>("q", "quality", true, "JPEG quality for output (0-100, default ${Settings.outputQuality})").apply { | |
71 default = Settings.outputQuality | |
72 interpolater = { | |
73 val ret = try { it.toInt() } catch (e: NumberFormatException) { -1 } | |
74 if (ret < 0 || ret > 100) | |
75 throw InvalidArgumentException("Quality must be an integer from 0 to 100, inclusive.") | |
76 Settings.outputQuality = ret | |
77 ret | |
78 } | |
79 }) | |
80 } | |
81 val cmdLine: CommandLine? = try { | |
82 PromptingParser().parse(options, args) | |
83 } catch (e: ParseException) { | |
84 System.err.println("${Application.MYNAME}: Syntax error - ${e.message}") | |
85 System.exit(2) | |
86 null | |
87 } | |
88 if (cmdLine!!.hasOption("help")) { | |
89 val usage = Application.MYNAME + " [--maxdim=integer] [--output=directory] [--quality=integer] file [...]" | |
90 HelpFormatter().printHelp(usage, options, false); | |
91 System.exit(0); | |
92 } | |
93 | |
94 /* launch GUI */ | 45 /* launch GUI */ |
95 inSwingThread { | 46 inSwingThread { |
96 Application.initialize() | 47 Application.initialize() |
97 for (fileName in cmdLine!!.args) | |
98 RotateDialog.makeDialog(File(fileName)) | |
99 } | 48 } |
100 } | 49 } |