Mercurial > cgi-bin > hgweb.cgi > ImagePrep
diff 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 |
line wrap: on
line diff
--- a/src/name/blackcap/imageprep/Main.kt Fri Nov 20 21:37:37 2020 -0800 +++ b/src/name/blackcap/imageprep/Main.kt Fri Nov 20 21:38:06 2020 -0800 @@ -22,10 +22,12 @@ /* global UI objects */ var mainFrame: MainFrame by setOnce() var helpDialog: HelpDialog by setOnce() + var settingsDialog: SettingsDialog by setOnce() fun initialize() { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); mainFrame = MainFrame() /* must be created first */ + settingsDialog = SettingsDialog() mainFrame.jMenuBar = MyMenuBar() setMacMenus() /* always safe to call; no-op if not a Mac */ helpDialog = HelpDialog() @@ -40,61 +42,8 @@ System.setProperty("apple.laf.useScreenMenuBar", "true") } - /* parse command line */ - if (Settings.outputToInputDir) - Settings.outputTo = System.getProperty("user.dir") - val options = Options().apply { - addOption(Option<Unit>("?", "help", false, "Print this help message.")) - addOption(Option<Int>("m", "maxdim", true, "Maximum dimension (default: ${Settings.maxDimension})").apply { - default = Settings.maxDimension - interpolater = { - val ret = try { it.toInt() } catch (e: NumberFormatException) { -1 } - if (ret < 1) - throw InvalidArgumentException("Dimension must be a positive integer.") - Settings.maxDimension = ret - ret - } - }) - addOption(Option<File>("o", "output", true, "Output directory (default: ${Settings.outputTo})").apply { - default = File(Settings.outputTo) - interpolater = { - val ret = File(tilde(it)) - if (!ret.exists()) - throw InvalidArgumentException("'${it}' does not exist") - if (!ret.isDirectory()) - throw InvalidArgumentException("'${it}' is not a directory") - Settings.outputTo = ret.canonicalPath - ret - } - }) - addOption(Option<Int>("q", "quality", true, "JPEG quality for output (0-100, default ${Settings.outputQuality})").apply { - default = Settings.outputQuality - interpolater = { - val ret = try { it.toInt() } catch (e: NumberFormatException) { -1 } - if (ret < 0 || ret > 100) - throw InvalidArgumentException("Quality must be an integer from 0 to 100, inclusive.") - Settings.outputQuality = ret - ret - } - }) - } - val cmdLine: CommandLine? = try { - PromptingParser().parse(options, args) - } catch (e: ParseException) { - System.err.println("${Application.MYNAME}: Syntax error - ${e.message}") - System.exit(2) - null - } - if (cmdLine!!.hasOption("help")) { - val usage = Application.MYNAME + " [--maxdim=integer] [--output=directory] [--quality=integer] file [...]" - HelpFormatter().printHelp(usage, options, false); - System.exit(0); - } - /* launch GUI */ inSwingThread { Application.initialize() - for (fileName in cmdLine!!.args) - RotateDialog.makeDialog(File(fileName)) } }