comparison src/name/blackcap/imageprep/Menus.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 d71523cde521
children 71029c9bf7cd
comparison
equal deleted inserted replaced
18:43884786343e 19:5fa5d15b4a7b
27 * Our menu bar. What we display depends somewhat on the system type, as 27 * Our menu bar. What we display depends somewhat on the system type, as
28 * the Mac gives us a gratuitous menu bar entry for handling some stuff. 28 * the Mac gives us a gratuitous menu bar entry for handling some stuff.
29 */ 29 */
30 class MyMenuBar: JMenuBar() { 30 class MyMenuBar: JMenuBar() {
31 private var currentInputDirectory = File(System.getProperty("user.dir")) 31 private var currentInputDirectory = File(System.getProperty("user.dir"))
32 private var currentOutputDirectory = File(Settings.outputTo) 32 private var currentOutputDirectory = File(Application.settingsDialog.outputTo)
33 33
34 init { 34 init {
35 add(JMenu("File").apply { 35 add(JMenu("File").apply {
36 add(JMenuItem("Open & Scale…").apply { 36 add(JMenuItem("Open & Scale…").apply {
37 addActionListener(ActionListener { doOpen() }) 37 addActionListener(ActionListener { doOpen() })
43 add(JMenuItem("Save & Close…").apply { 43 add(JMenuItem("Save & Close…").apply {
44 addActionListener(ActionListener { doClose() }) 44 addActionListener(ActionListener { doClose() })
45 makeShortcut(KeyEvent.VK_S) 45 makeShortcut(KeyEvent.VK_S)
46 }) 46 })
47 if (OS.type != OS.MAC) { 47 if (OS.type != OS.MAC) {
48 add(JMenuItem("Preferences…").apply {
49 addActionListener(ActionListener {
50 Application.settingsDialog.setVisible(true)
51 })
52 makeShortcut(KeyEvent.VK_COMMA)
53 })
48 add(JMenuItem("Quit").apply { 54 add(JMenuItem("Quit").apply {
49 addActionListener(ActionListener { 55 addActionListener(ActionListener {
50 LOGGER.log(Level.INFO, "execution complete") 56 LOGGER.log(Level.INFO, "execution complete")
51 System.exit(0) 57 System.exit(0)
52 }) 58 })
75 } 81 }
76 return null 82 return null
77 } 83 }
78 84
79 private fun doOpen() { 85 private fun doOpen() {
86 val maxDim = MaxDimSpinner(Application.settingsDialog.maxDimension)
87 val acc = JPanel().apply {
88 layout = BoxLayout(this, BoxLayout.X_AXIS)
89 add(JLabel("Max. dimension:"))
90 add(maxDim)
91 }
80 val chooser = JFileChooser().apply { 92 val chooser = JFileChooser().apply {
93 accessory = acc
81 currentDirectory = currentInputDirectory 94 currentDirectory = currentInputDirectory
82 fileFilter = FileNameExtensionFilter("Image Files", *ImageIO.getReaderFileSuffixes()) 95 fileFilter = FileNameExtensionFilter("Image Files", *ImageIO.getReaderFileSuffixes())
83 } 96 }
84 if (chooser.showOpenDialog(Application.mainFrame) == JFileChooser.APPROVE_OPTION) { 97 if (chooser.showOpenDialog(Application.mainFrame) == JFileChooser.APPROVE_OPTION) {
85 currentInputDirectory = chooser.selectedFile.canonicalFile.parentFile 98 currentInputDirectory = chooser.selectedFile.canonicalFile.parentFile
86 RotateDialog.makeDialog(chooser.selectedFile) 99 RotateDialog.makeDialog(chooser.selectedFile, maxDim.value as Int)
87 } 100 }
88 } 101 }
89 102
90 private fun doDiscard() { 103 private fun doDiscard() {
91 val w = FocusManager.getCurrentManager().activeWindow as? RotateDialog 104 val w = FocusManager.getCurrentManager().activeWindow as? RotateDialog
106 if (w == null) { 119 if (w == null) {
107 LOGGER.log(Level.INFO, "beep!") 120 LOGGER.log(Level.INFO, "beep!")
108 Toolkit.getDefaultToolkit().beep() 121 Toolkit.getDefaultToolkit().beep()
109 return 122 return
110 } 123 }
111 val outName = splitext(w.file.name).first + Settings.outputSuffix + ".jpg" 124 val outQual = OutQualSpinner(Application.settingsDialog.outputQuality)
125 val acc = JPanel().apply {
126 layout = BoxLayout(this, BoxLayout.X_AXIS)
127 add(JLabel("Quality:"))
128 add(outQual)
129 }
130 val outName = splitext(w.file.name).first + Application.settingsDialog.outputSuffix + ".jpg"
112 val chooser = JFileChooser().apply { 131 val chooser = JFileChooser().apply {
132 accessory = acc
113 currentDirectory = currentOutputDirectory 133 currentDirectory = currentOutputDirectory
114 selectedFile = File(currentOutputDirectory, outName) 134 selectedFile = File(currentOutputDirectory, outName)
115 } 135 }
116 if (chooser.showSaveDialog(Application.mainFrame) != JFileChooser.APPROVE_OPTION) { 136 if (chooser.showSaveDialog(Application.mainFrame) != JFileChooser.APPROVE_OPTION) {
117 return 137 return
148 ios.use { 168 ios.use {
149 val writer = ImageIO.getImageWritersByFormatName("jpeg").next() 169 val writer = ImageIO.getImageWritersByFormatName("jpeg").next()
150 try { 170 try {
151 val iwp = writer.getDefaultWriteParam().apply { 171 val iwp = writer.getDefaultWriteParam().apply {
152 setCompressionMode(ImageWriteParam.MODE_EXPLICIT) 172 setCompressionMode(ImageWriteParam.MODE_EXPLICIT)
153 setCompressionQuality(Settings.outputQuality.toFloat() / 100.0f) 173 setCompressionQuality((outQual.value as Int).toFloat() / 100.0f)
154 } 174 }
155 writer.setOutput(it) 175 writer.setOutput(it)
156 writer.write(null, IIOImage(w.image, null, null), iwp) 176 writer.write(null, IIOImage(w.image, null, null), iwp)
157 } finally { 177 } finally {
158 writer.dispose() 178 writer.dispose()