annotate src/name/blackcap/imageprep/RotateDialog.kt @ 27:404eb7e57fe6

Standardize things for Linux packaging.
author David Barts <n5jrn@me.com>
date Fri, 25 Dec 2020 18:58:45 -0800
parents 5fa5d15b4a7b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
1 /*
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
2 * Represents a file being edited (rotated)
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
3 */
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
4 package name.blackcap.imageprep
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
5
1
0bded24f746e Compiles, still untested.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
6 import java.awt.Dimension
0bded24f746e Compiles, still untested.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
7 import java.awt.Graphics
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
8 import java.awt.Graphics2D
12
26a507e095ab Use ImageObserver and wait if needed.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
9 import java.awt.Image
6
9129ae110146 Window reshapes to avoid gratuitous scrollbars (as it should).
David Barts <n5jrn@me.com>
parents: 3
diff changeset
10 import java.awt.Toolkit
1
0bded24f746e Compiles, still untested.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
11 import java.awt.event.ActionListener
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
12 import java.awt.image.BufferedImage
12
26a507e095ab Use ImageObserver and wait if needed.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
13 import java.awt.image.ImageObserver
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
14 import java.io.File
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
15 import java.io.IOException
12
26a507e095ab Use ImageObserver and wait if needed.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
16 import java.util.concurrent.Semaphore
3
09dcd475d1bf Works (prelim tests only).
David Barts <n5jrn@me.com>
parents: 1
diff changeset
17 import java.util.logging.Level
09dcd475d1bf Works (prelim tests only).
David Barts <n5jrn@me.com>
parents: 1
diff changeset
18 import java.util.logging.Logger
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
19 import javax.imageio.ImageIO
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
20 import javax.swing.*
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
21 import kotlin.math.*
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
22
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
23 class RotateDialog(val file: File, initialImage: BufferedImage) : JDialog(Application.mainFrame) {
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
24 private val BW = 9
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
25 private val BW2 = BW * 2
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
26
1
0bded24f746e Compiles, still untested.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
27 private class DrawingPane(initialImage: BufferedImage) : JPanel() {
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
28 var image: BufferedImage = initialImage
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
29 set(value) {
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
30 field = value
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
31 revalidate()
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
32 repaint()
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
33 }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
34
6
9129ae110146 Window reshapes to avoid gratuitous scrollbars (as it should).
David Barts <n5jrn@me.com>
parents: 3
diff changeset
35 override fun getPreferredSize(): Dimension {
9129ae110146 Window reshapes to avoid gratuitous scrollbars (as it should).
David Barts <n5jrn@me.com>
parents: 3
diff changeset
36 val screen = Toolkit.getDefaultToolkit().screenSize
9129ae110146 Window reshapes to avoid gratuitous scrollbars (as it should).
David Barts <n5jrn@me.com>
parents: 3
diff changeset
37 return Dimension(min(image.width, screen.width/4*3),
9129ae110146 Window reshapes to avoid gratuitous scrollbars (as it should).
David Barts <n5jrn@me.com>
parents: 3
diff changeset
38 min(image.height, screen.height/4*3))
9129ae110146 Window reshapes to avoid gratuitous scrollbars (as it should).
David Barts <n5jrn@me.com>
parents: 3
diff changeset
39 }
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
40
1
0bded24f746e Compiles, still untested.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
41 override protected fun paintComponent(g: Graphics): Unit {
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
42 g.drawImage(image, 0, 0, null)
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
43 }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
44 }
1
0bded24f746e Compiles, still untested.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
45 private val drawingPane = DrawingPane(initialImage)
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
46
12
26a507e095ab Use ImageObserver and wait if needed.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
47 private class ImageWaiter: ImageObserver {
13
3feeb953d9ae val -> var
David Barts <n5jrn@me.com>
parents: 12
diff changeset
48 private val MASK = ImageObserver.ALLBITS or ImageObserver.ERROR or ImageObserver.ABORT
3feeb953d9ae val -> var
David Barts <n5jrn@me.com>
parents: 12
diff changeset
49 private val sem = Semaphore(0)
12
26a507e095ab Use ImageObserver and wait if needed.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
50 @Volatile private var flags: Int? = null
26a507e095ab Use ImageObserver and wait if needed.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
51
26a507e095ab Use ImageObserver and wait if needed.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
52 override fun imageUpdate(img: Image, infoflags: Int, x: Int, y: Int, width: Int, height: Int): Boolean {
13
3feeb953d9ae val -> var
David Barts <n5jrn@me.com>
parents: 12
diff changeset
53 if ((infoflags and MASK) != 0) {
12
26a507e095ab Use ImageObserver and wait if needed.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
54 flags = infoflags
26a507e095ab Use ImageObserver and wait if needed.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
55 sem.release()
26a507e095ab Use ImageObserver and wait if needed.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
56 return false
26a507e095ab Use ImageObserver and wait if needed.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
57 }
26a507e095ab Use ImageObserver and wait if needed.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
58 return true
26a507e095ab Use ImageObserver and wait if needed.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
59 }
26a507e095ab Use ImageObserver and wait if needed.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
60
26a507e095ab Use ImageObserver and wait if needed.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
61 fun wait(): Int {
26a507e095ab Use ImageObserver and wait if needed.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
62 sem.acquire()
26a507e095ab Use ImageObserver and wait if needed.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
63 return flags!!
26a507e095ab Use ImageObserver and wait if needed.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
64 }
26a507e095ab Use ImageObserver and wait if needed.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
65 }
26a507e095ab Use ImageObserver and wait if needed.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
66
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
67 val image: BufferedImage
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
68 get() { return drawingPane.image }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
69
1
0bded24f746e Compiles, still untested.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
70 private val r90cw = JButton("90° CW").also {
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
71 it.addActionListener(ActionListener { doRotate(90) })
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
72 }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
73
1
0bded24f746e Compiles, still untested.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
74 private val r180 = JButton("180°").also {
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
75 it.addActionListener(ActionListener { doRotate(180) })
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
76 }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
77
1
0bded24f746e Compiles, still untested.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
78 private val r90ccw = JButton("90° CCW").also {
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
79 it.addActionListener(ActionListener { doRotate(270) })
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
80 }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
81
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
82 /* Theoretically, this should do the rotation in a background thread.
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
83 Practically, that is fraught with difficulties, as it involves
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
84 manipulating data used by Swing itself. Since the size of the images
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
85 being rotated are small, we do it in the foreground. */
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
86 private fun doRotate(deg: Int) {
3
09dcd475d1bf Works (prelim tests only).
David Barts <n5jrn@me.com>
parents: 1
diff changeset
87 rootPane.defaultButton = null
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
88 // https://stackoverflow.com/questions/15927014/rotating-an-image-90-degrees-in-java
3
09dcd475d1bf Works (prelim tests only).
David Barts <n5jrn@me.com>
parents: 1
diff changeset
89 if (deg % 90 != 0) {
09dcd475d1bf Works (prelim tests only).
David Barts <n5jrn@me.com>
parents: 1
diff changeset
90 val barf = "${deg} not a multiple of 90!"
09dcd475d1bf Works (prelim tests only).
David Barts <n5jrn@me.com>
parents: 1
diff changeset
91 LOGGER.log(Level.SEVERE, barf)
09dcd475d1bf Works (prelim tests only).
David Barts <n5jrn@me.com>
parents: 1
diff changeset
92 throw AssertionError(barf)
09dcd475d1bf Works (prelim tests only).
David Barts <n5jrn@me.com>
parents: 1
diff changeset
93 }
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
94 val rad = java.lang.Math.toRadians(deg.toDouble())
3
09dcd475d1bf Works (prelim tests only).
David Barts <n5jrn@me.com>
parents: 1
diff changeset
95 val (w, h) = if (deg % 180 == 0) Pair(image.width, image.height) else Pair(image.height, image.width)
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
96 val rotatedImage = BufferedImage(w, h, image.type)
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
97 rotatedImage.createGraphics().run {
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
98 translate((w - image.width) / 2, (h - image.height) / 2)
1
0bded24f746e Compiles, still untested.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
99 rotate(rad, image.width.toDouble()/2.0, image.height.toDouble()/2.0)
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
100 drawRenderedImage(image, null)
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
101 dispose()
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
102 }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
103 drawingPane.image = rotatedImage
6
9129ae110146 Window reshapes to avoid gratuitous scrollbars (as it should).
David Barts <n5jrn@me.com>
parents: 3
diff changeset
104 revalidate()
9129ae110146 Window reshapes to avoid gratuitous scrollbars (as it should).
David Barts <n5jrn@me.com>
parents: 3
diff changeset
105 pack()
9129ae110146 Window reshapes to avoid gratuitous scrollbars (as it should).
David Barts <n5jrn@me.com>
parents: 3
diff changeset
106 repaint()
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
107 }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
108
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
109 init {
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
110 defaultCloseOperation = JDialog.DISPOSE_ON_CLOSE
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
111 title = "Untitled"
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
112 contentPane.apply {
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
113 layout = BoxLayout(this, BoxLayout.Y_AXIS)
1
0bded24f746e Compiles, still untested.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
114 add(JScrollPane(drawingPane).apply {
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
115 alignmentX = JScrollPane.CENTER_ALIGNMENT
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
116 addBorder(BorderFactory.createEmptyBorder(BW2, BW2, BW, BW2))
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
117 verticalScrollBarPolicy = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
118 horizontalScrollBarPolicy = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
119 background = Application.mainFrame.background
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
120 })
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
121 add(Box(BoxLayout.X_AXIS).apply {
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
122 alignmentX = Box.CENTER_ALIGNMENT
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
123 addBorder(BorderFactory.createEmptyBorder(BW, BW2, BW2, BW2))
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
124 add(JLabel("Rotate:"))
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
125 add(Box.createHorizontalGlue())
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
126 add(r90cw)
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
127 add(Box.createHorizontalGlue())
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
128 add(r180)
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
129 add(Box.createHorizontalGlue())
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
130 add(r90ccw)
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
131 })
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
132 }
3
09dcd475d1bf Works (prelim tests only).
David Barts <n5jrn@me.com>
parents: 1
diff changeset
133 rootPane.defaultButton = null
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
134 pack()
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
135 }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
136
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
137 companion object Factory {
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
138 /**
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
139 * Make a dialog asynchronously.
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
140 *
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
141 * @param input java.io.File to read for image.
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
142 */
19
5fa5d15b4a7b Attempt to make it a std. app. Builds, sorta runs, needs more work.
David Barts <n5jrn@me.com>
parents: 16
diff changeset
143 fun makeDialog(input: File, maxDim: Int): Unit {
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
144 Application.mainFrame.useWaitCursor()
1
0bded24f746e Compiles, still untested.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
145 swingWorker<Pair<BufferedImage?, IOException?>> {
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
146 inBackground {
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
147 try {
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
148 val imageIn = ImageIO.read(input) /* IOException */
16
2bb46da74667 Detect unsupported file types on input.
David Barts <n5jrn@me.com>
parents: 13
diff changeset
149 if (imageIn == null)
2bb46da74667 Detect unsupported file types on input.
David Barts <n5jrn@me.com>
parents: 13
diff changeset
150 throw IOException("Unsupported file type.")
19
5fa5d15b4a7b Attempt to make it a std. app. Builds, sorta runs, needs more work.
David Barts <n5jrn@me.com>
parents: 16
diff changeset
151 val ratio = maxDim.toDouble() / max(imageIn.width, imageIn.height).toDouble()
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
152 if (ratio >= 1.0) {
1
0bded24f746e Compiles, still untested.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
153 Pair(null, null)
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
154 } else {
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
155 val nWidth = (imageIn.width * ratio).toInt()
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
156 val nHeight = (imageIn.height * ratio).toInt()
11
1f824742e1fa Improve scaling quality.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
157 val imageOut = BufferedImage(nWidth, nHeight, imageIn.type)
1f824742e1fa Improve scaling quality.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
158 imageOut.createGraphics().run {
12
26a507e095ab Use ImageObserver and wait if needed.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
159 val w = ImageWaiter()
26a507e095ab Use ImageObserver and wait if needed.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
160 if (!drawImage(imageIn.getScaledInstance(nWidth, nHeight, BufferedImage.SCALE_SMOOTH), 0, 0, w))
26a507e095ab Use ImageObserver and wait if needed.
David Barts <n5jrn@me.com>
parents: 11
diff changeset
161 w.wait()
11
1f824742e1fa Improve scaling quality.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
162 dispose()
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
163 }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
164 Pair(imageOut, null)
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
165 }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
166 } catch (e: IOException) {
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
167 Pair(null, e)
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
168 }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
169 }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
170 whenDone {
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
171 Application.mainFrame.useNormalCursor()
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
172 val (image, error) = get()
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
173 if (error != null)
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
174 ioExceptionDialog(Application.mainFrame, input, "read", error)
1
0bded24f746e Compiles, still untested.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
175 else if (image != null)
3
09dcd475d1bf Works (prelim tests only).
David Barts <n5jrn@me.com>
parents: 1
diff changeset
176 RotateDialog(input, image).run {
09dcd475d1bf Works (prelim tests only).
David Barts <n5jrn@me.com>
parents: 1
diff changeset
177 title = input.name
09dcd475d1bf Works (prelim tests only).
David Barts <n5jrn@me.com>
parents: 1
diff changeset
178 setVisible(true)
09dcd475d1bf Works (prelim tests only).
David Barts <n5jrn@me.com>
parents: 1
diff changeset
179 }
1
0bded24f746e Compiles, still untested.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
180 else
0bded24f746e Compiles, still untested.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
181 JOptionPane.showMessageDialog(Application.mainFrame,
0bded24f746e Compiles, still untested.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
182 "Image is too small to be scaled.",
19
5fa5d15b4a7b Attempt to make it a std. app. Builds, sorta runs, needs more work.
David Barts <n5jrn@me.com>
parents: 16
diff changeset
183 "Error", JOptionPane.ERROR_MESSAGE)
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
184 }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
185 }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
186 }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
187 }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
188 }