Mercurial > cgi-bin > hgweb.cgi > ImagePrep
comparison src/name/blackcap/imageprep/Menus.kt @ 1:0bded24f746e
Compiles, still untested.
author | David Barts <n5jrn@me.com> |
---|---|
date | Thu, 16 Jul 2020 21:51:08 -0700 |
parents | e0efe7848130 |
children | 09dcd475d1bf |
comparison
equal
deleted
inserted
replaced
0:e0efe7848130 | 1:0bded24f746e |
---|---|
3 */ | 3 */ |
4 package name.blackcap.imageprep | 4 package name.blackcap.imageprep |
5 | 5 |
6 import java.awt.Graphics2D | 6 import java.awt.Graphics2D |
7 import java.awt.RenderingHints | 7 import java.awt.RenderingHints |
8 import java.awt.Toolkit | |
8 import java.awt.Window | 9 import java.awt.Window |
9 import java.awt.event.ActionEvent | 10 import java.awt.event.ActionEvent |
10 import java.awt.event.ActionListener | 11 import java.awt.event.ActionListener |
11 import java.awt.event.KeyEvent | 12 import java.awt.event.KeyEvent |
12 import java.awt.image.BufferedImage | 13 import java.awt.image.BufferedImage |
13 import java.io.File | 14 import java.io.File |
15 import java.io.IOException | |
14 import java.util.logging.Level | 16 import java.util.logging.Level |
15 import java.util.logging.Logger | 17 import java.util.logging.Logger |
16 import javax.imageio.IIOImage | 18 import javax.imageio.IIOImage |
17 import javax.imageio.ImageIO | 19 import javax.imageio.ImageIO |
18 import javax.imageio.ImageWriteParam | 20 import javax.imageio.ImageWriteParam |
19 import javax.imageio.ImageWriter | 21 import javax.imageio.ImageWriter |
20 import javax.imageio.stream.ImageOutputStream | 22 import javax.imageio.stream.ImageOutputStream |
21 import javax.swing.* | 23 import javax.swing.* |
24 import javax.swing.filechooser.FileNameExtensionFilter | |
22 | 25 |
23 /** | 26 /** |
24 * 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 |
25 * 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. |
26 */ | 29 */ |
37 add(JMenuItem("Save & Close…").apply { | 40 add(JMenuItem("Save & Close…").apply { |
38 addActionListener(ActionListener { doClose() }) | 41 addActionListener(ActionListener { doClose() }) |
39 makeShortcut(KeyEvent.VK_S) | 42 makeShortcut(KeyEvent.VK_S) |
40 }) | 43 }) |
41 if (OS.type != OS.MAC) { | 44 if (OS.type != OS.MAC) { |
42 add(JMenuItem("Preferences…").apply { | |
43 addActionListener(ActionListener { | |
44 Application.settingsDialog.setVisible(true) | |
45 }) | |
46 makeShortcut(KeyEvent.VK_COMMA) | |
47 }) | |
48 add(JMenuItem("Quit").apply { | 45 add(JMenuItem("Quit").apply { |
49 addActionListener(ActionListener { | 46 addActionListener(ActionListener { |
50 LOGGER.log(Level.INFO, "execution complete") | 47 LOGGER.log(Level.INFO, "execution complete") |
51 System.exit(0) | 48 System.exit(0) |
52 }) | 49 }) |
76 return null | 73 return null |
77 } | 74 } |
78 | 75 |
79 private fun doOpen() { | 76 private fun doOpen() { |
80 val chooser = JFileChooser().apply { | 77 val chooser = JFileChooser().apply { |
81 fileFilter = FileNameExtensionFilter("Image files", ImageIO.getReaderFileSuffixes()) | 78 fileFilter = FileNameExtensionFilter("Image files", *ImageIO.getReaderFileSuffixes()) |
82 } | 79 } |
83 if (chooser.showOpenDialog(Application.mainFrame) == JFileChooser.APPROVE_OPTION) { | 80 if (chooser.showOpenDialog(Application.mainFrame) == JFileChooser.APPROVE_OPTION) { |
84 RotateDialog.makeDialog(chooser.selectedFile) | 81 RotateDialog.makeDialog(chooser.selectedFile) |
85 } | 82 } |
86 } | 83 } |
87 | 84 |
88 private fun doDiscard() { | 85 private fun doDiscard() { |
89 val w = FocusManager.currentManager.activeWindow as? RotateDialog | 86 val w = FocusManager.getCurrentManager().activeWindow as? RotateDialog |
90 if (w == null) { | 87 if (w == null) { |
91 Toolkit.defaultToolkit.beep() | 88 Toolkit.getDefaultToolkit().beep() |
92 return | 89 return |
93 } | 90 } |
94 w.setVisible(false) | 91 w.setVisible(false) |
95 w.dispose() | 92 w.dispose() |
96 } | 93 } |
97 | 94 |
98 private fun doClose() { | 95 private fun doClose() { |
99 val w = FocusManager.currentManager.activeWindow as? RotateDialog | 96 val w = FocusManager.getCurrentManager().activeWindow as? RotateDialog |
100 if (w == null) { | 97 if (w == null) { |
101 Toolkit.defaultToolkit.beep() | 98 Toolkit.getDefaultToolkit().beep() |
102 return | 99 return |
103 } | 100 } |
104 val outName = splitext(w.file.name).first + Settings.outputSuffix + ".jpg" | 101 val outName = splitext(w.file.name).first + Settings.outputSuffix + ".jpg" |
105 val chooser = JFileChooser(w).apply { | 102 val chooser = JFileChooser().apply { |
106 selectedFile = File( | 103 selectedFile = File( |
107 if (Settings.outputToInputDir) w.file.parent else Settings.outputTo, | 104 if (Settings.outputToInputDir) w.file.parent else Settings.outputTo, |
108 outName) | 105 outName) |
109 } | 106 } |
110 if (chooser.showOpenDialog(Application.mainFrame) != JFileChooser.APPROVE_OPTION) { | 107 if (chooser.showOpenDialog(Application.mainFrame) != JFileChooser.APPROVE_OPTION) { |
141 val error = get() | 138 val error = get() |
142 if (error == null) { | 139 if (error == null) { |
143 w.setVisible(false) | 140 w.setVisible(false) |
144 w.dispose() | 141 w.dispose() |
145 } else { | 142 } else { |
146 ioExceptionDialog(w, file, "write", e) | 143 ioExceptionDialog(w, file, "write", error) |
147 } | 144 } |
148 } | 145 } |
149 } | 146 } |
150 } | 147 } |
151 | 148 |