# HG changeset patch # User David Barts # Date 1595011687 25200 # Node ID 09dcd475d1bf51499deb4d498d851b4234133198 # Parent a6f9b51d5e8da8461599b5214b80277f1ee84dcb Works (prelim tests only). diff -r a6f9b51d5e8d -r 09dcd475d1bf src/name/blackcap/imageprep/Menus.kt --- a/src/name/blackcap/imageprep/Menus.kt Fri Jul 17 10:34:48 2020 -0700 +++ b/src/name/blackcap/imageprep/Menus.kt Fri Jul 17 11:48:07 2020 -0700 @@ -75,7 +75,7 @@ private fun doOpen() { val chooser = JFileChooser().apply { - fileFilter = FileNameExtensionFilter("Image files", *ImageIO.getReaderFileSuffixes()) + fileFilter = FileNameExtensionFilter("Image Files", *ImageIO.getReaderFileSuffixes()) } if (chooser.showOpenDialog(Application.mainFrame) == JFileChooser.APPROVE_OPTION) { RotateDialog.makeDialog(chooser.selectedFile) @@ -104,7 +104,7 @@ if (Settings.outputToInputDir) w.file.parent else Settings.outputTo, outName) } - if (chooser.showOpenDialog(Application.mainFrame) != JFileChooser.APPROVE_OPTION) { + if (chooser.showSaveDialog(Application.mainFrame) != JFileChooser.APPROVE_OPTION) { return } val (name, ext) = splitext(chooser.selectedFile.name) diff -r a6f9b51d5e8d -r 09dcd475d1bf src/name/blackcap/imageprep/RotateDialog.kt --- a/src/name/blackcap/imageprep/RotateDialog.kt Fri Jul 17 10:34:48 2020 -0700 +++ b/src/name/blackcap/imageprep/RotateDialog.kt Fri Jul 17 11:48:07 2020 -0700 @@ -11,6 +11,8 @@ import java.awt.image.BufferedImage import java.io.File import java.io.IOException +import java.util.logging.Level +import java.util.logging.Logger import javax.imageio.ImageIO import javax.swing.* import kotlin.math.* @@ -57,12 +59,15 @@ manipulating data used by Swing itself. Since the size of the images being rotated are small, we do it in the foreground. */ private fun doRotate(deg: Int) { + rootPane.defaultButton = null // https://stackoverflow.com/questions/15927014/rotating-an-image-90-degrees-in-java + if (deg % 90 != 0) { + val barf = "${deg} not a multiple of 90!" + LOGGER.log(Level.SEVERE, barf) + throw AssertionError(barf) + } val rad = java.lang.Math.toRadians(deg.toDouble()) - val sinx = sin(rad) - val cosx = cos(rad) - val w = floor(image.width * cosx + image.height * sinx).toInt() - val h = floor(image.height * cosx + image.width * sinx).toInt() + val (w, h) = if (deg % 180 == 0) Pair(image.width, image.height) else Pair(image.height, image.width) val rotatedImage = BufferedImage(w, h, image.type) rotatedImage.createGraphics().run { translate((w - image.width) / 2, (h - image.height) / 2) @@ -97,6 +102,7 @@ add(r90ccw) }) } + rootPane.defaultButton = null pack() } @@ -137,7 +143,10 @@ if (error != null) ioExceptionDialog(Application.mainFrame, input, "read", error) else if (image != null) - RotateDialog(input, image).title = input.getName() + RotateDialog(input, image).run { + title = input.name + setVisible(true) + } else JOptionPane.showMessageDialog(Application.mainFrame, "Image is too small to be scaled.",