Mercurial > cgi-bin > hgweb.cgi > ImagePrep
diff src/name/blackcap/imageprep/RotateDialog.kt @ 3:09dcd475d1bf
Works (prelim tests only).
author | David Barts <n5jrn@me.com> |
---|---|
date | Fri, 17 Jul 2020 11:48:07 -0700 |
parents | 0bded24f746e |
children | 9129ae110146 |
line wrap: on
line diff
--- 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.",