Mercurial > cgi-bin > hgweb.cgi > ImagePrep
comparison src/name/blackcap/imageprep/RotateDialog.kt @ 6:9129ae110146
Window reshapes to avoid gratuitous scrollbars (as it should).
author | David Barts <n5jrn@me.com> |
---|---|
date | Fri, 17 Jul 2020 17:58:55 -0700 |
parents | 09dcd475d1bf |
children | b5fcabce391f |
comparison
equal
deleted
inserted
replaced
5:884f1415a330 | 6:9129ae110146 |
---|---|
5 | 5 |
6 import java.awt.Dimension | 6 import java.awt.Dimension |
7 import java.awt.Graphics | 7 import java.awt.Graphics |
8 import java.awt.Graphics2D | 8 import java.awt.Graphics2D |
9 import java.awt.RenderingHints | 9 import java.awt.RenderingHints |
10 import java.awt.Toolkit | |
10 import java.awt.event.ActionListener | 11 import java.awt.event.ActionListener |
11 import java.awt.image.BufferedImage | 12 import java.awt.image.BufferedImage |
12 import java.io.File | 13 import java.io.File |
13 import java.io.IOException | 14 import java.io.IOException |
14 import java.util.logging.Level | 15 import java.util.logging.Level |
18 import kotlin.math.* | 19 import kotlin.math.* |
19 | 20 |
20 class RotateDialog(val file: File, initialImage: BufferedImage) : JDialog(Application.mainFrame) { | 21 class RotateDialog(val file: File, initialImage: BufferedImage) : JDialog(Application.mainFrame) { |
21 private val BW = 9 | 22 private val BW = 9 |
22 private val BW2 = BW * 2 | 23 private val BW2 = BW * 2 |
23 private val MINWIDTH = 512 | |
24 private val MINHEIGHT = 384 | |
25 | 24 |
26 private class DrawingPane(initialImage: BufferedImage) : JPanel() { | 25 private class DrawingPane(initialImage: BufferedImage) : JPanel() { |
27 var image: BufferedImage = initialImage | 26 var image: BufferedImage = initialImage |
28 set(value) { | 27 set(value) { |
29 field = value | 28 field = value |
30 revalidate() | 29 revalidate() |
31 repaint() | 30 repaint() |
32 } | 31 } |
33 | 32 |
34 override fun getPreferredSize() = Dimension(image.width, image.height) | 33 override fun getPreferredSize(): Dimension { |
34 val screen = Toolkit.getDefaultToolkit().screenSize | |
35 return Dimension(min(image.width, screen.width/4*3), | |
36 min(image.height, screen.height/4*3)) | |
37 } | |
35 | 38 |
36 override protected fun paintComponent(g: Graphics): Unit { | 39 override protected fun paintComponent(g: Graphics): Unit { |
37 g.drawImage(image, 0, 0, null) | 40 g.drawImage(image, 0, 0, null) |
38 } | 41 } |
39 } | 42 } |
74 rotate(rad, image.width.toDouble()/2.0, image.height.toDouble()/2.0) | 77 rotate(rad, image.width.toDouble()/2.0, image.height.toDouble()/2.0) |
75 drawRenderedImage(image, null) | 78 drawRenderedImage(image, null) |
76 dispose() | 79 dispose() |
77 } | 80 } |
78 drawingPane.image = rotatedImage | 81 drawingPane.image = rotatedImage |
82 revalidate() | |
83 pack() | |
84 repaint() | |
79 } | 85 } |
80 | 86 |
81 init { | 87 init { |
82 defaultCloseOperation = JDialog.DISPOSE_ON_CLOSE | 88 defaultCloseOperation = JDialog.DISPOSE_ON_CLOSE |
83 title = "Untitled" | 89 title = "Untitled" |