Small fixes to make things faster
UI Set to native ui since it tends to look better Add a menu bar
This commit is contained in:
parent
67193f8869
commit
d8b4b38c56
|
@ -1,10 +1,7 @@
|
||||||
package nl.aegeedelft.watermarker
|
package nl.aegeedelft.watermarker
|
||||||
|
|
||||||
import org.intellij.lang.annotations.Language
|
import org.intellij.lang.annotations.Language
|
||||||
import java.awt.BorderLayout
|
import java.awt.*
|
||||||
import java.awt.Component
|
|
||||||
import java.awt.Dimension
|
|
||||||
import java.awt.Image
|
|
||||||
import java.awt.image.BufferedImage
|
import java.awt.image.BufferedImage
|
||||||
import java.awt.image.RenderedImage
|
import java.awt.image.RenderedImage
|
||||||
import java.io.BufferedInputStream
|
import java.io.BufferedInputStream
|
||||||
|
@ -31,10 +28,13 @@ val runbtn = JButton("Run!")
|
||||||
|
|
||||||
val pbar = JProgressBar()
|
val pbar = JProgressBar()
|
||||||
|
|
||||||
val dlg = JDialog(jf, "Progress Dialog", true)
|
val dlg = JDialog(jf, "Watermarking Images!", true)
|
||||||
|
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
|
||||||
|
|
||||||
|
|
||||||
var watermark: File? = null
|
var watermark: File? = null
|
||||||
var outdir: File? = null
|
var outdir: File? = null
|
||||||
var basedir: File? = null
|
var basedir: File? = null
|
||||||
|
@ -51,12 +51,19 @@ fun main(args: Array<String>) {
|
||||||
|
|
||||||
|
|
||||||
basepicker.currentDirectory = File(".")
|
basepicker.currentDirectory = File(".")
|
||||||
basepicker.fileSelectionMode = JFileChooser.DIRECTORIES_ONLY
|
basepicker.fileSelectionMode = JFileChooser.FILES_AND_DIRECTORIES
|
||||||
basepicker.isAcceptAllFileFilterUsed = false
|
basepicker.isAcceptAllFileFilterUsed = false
|
||||||
|
basepicker.fileFilter = object : FileFilter() {
|
||||||
|
override fun accept(f: File): Boolean = f.isDirectory
|
||||||
|
|
||||||
|
override fun getDescription(): String = "Folders"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
outpicker.currentDirectory = File(".")
|
outpicker.currentDirectory = File(".")
|
||||||
outpicker.fileSelectionMode = JFileChooser.DIRECTORIES_ONLY
|
outpicker.fileSelectionMode = JFileChooser.FILES_AND_DIRECTORIES
|
||||||
outpicker.isAcceptAllFileFilterUsed = false
|
outpicker.isAcceptAllFileFilterUsed = false
|
||||||
|
outpicker.fileFilter = basepicker.fileFilter
|
||||||
|
|
||||||
wmpicker.currentDirectory = File(".")
|
wmpicker.currentDirectory = File(".")
|
||||||
wmpicker.fileSelectionMode = JFileChooser.FILES_ONLY
|
wmpicker.fileSelectionMode = JFileChooser.FILES_ONLY
|
||||||
|
@ -110,7 +117,7 @@ fun main(args: Array<String>) {
|
||||||
if (watermark != null && outdir != null && basedir != null) {
|
if (watermark != null && outdir != null && basedir != null) {
|
||||||
this.isEnabled = false
|
this.isEnabled = false
|
||||||
thread {
|
thread {
|
||||||
doTheThing(basedir!!, outdir!!, watermark!!)
|
watermarkImages(basedir!!, outdir!!, watermark!!)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
JOptionPane.showMessageDialog(
|
JOptionPane.showMessageDialog(
|
||||||
|
@ -126,6 +133,34 @@ fun main(args: Array<String>) {
|
||||||
|
|
||||||
jf.add(box, BorderLayout.CENTER)
|
jf.add(box, BorderLayout.CENTER)
|
||||||
|
|
||||||
|
val menuBar = JMenuBar()
|
||||||
|
val helpMenu = JMenu("Help")
|
||||||
|
val fileMenu = JMenu("File")
|
||||||
|
menuBar.add(fileMenu)
|
||||||
|
menuBar.add(helpMenu)
|
||||||
|
val infoItem = JMenuItem("About")
|
||||||
|
helpMenu.add(infoItem)
|
||||||
|
infoItem.addActionListener {
|
||||||
|
JOptionPane.showMessageDialog(
|
||||||
|
jf,
|
||||||
|
"WaterMarker\n" +
|
||||||
|
"An app written by Julius de Jeu for AEGEE-Delft. \n" +
|
||||||
|
"\n" +
|
||||||
|
"Copyright (c) Julius de Jeu 2019",
|
||||||
|
"About",
|
||||||
|
JOptionPane.PLAIN_MESSAGE
|
||||||
|
)
|
||||||
|
}
|
||||||
|
fileMenu.add(JMenuItem("Exit").apply {
|
||||||
|
addActionListener {
|
||||||
|
System.exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
accelerator = KeyStroke.getKeyStroke("ALT F4")
|
||||||
|
})
|
||||||
|
|
||||||
|
jf.jMenuBar = menuBar
|
||||||
|
|
||||||
jf.setLocationRelativeTo(null)
|
jf.setLocationRelativeTo(null)
|
||||||
jf.defaultCloseOperation = JFrame.EXIT_ON_CLOSE
|
jf.defaultCloseOperation = JFrame.EXIT_ON_CLOSE
|
||||||
jf.preferredSize = Dimension(300, 300)
|
jf.preferredSize = Dimension(300, 300)
|
||||||
|
@ -136,9 +171,10 @@ fun main(args: Array<String>) {
|
||||||
dlg.defaultCloseOperation = JDialog.DO_NOTHING_ON_CLOSE
|
dlg.defaultCloseOperation = JDialog.DO_NOTHING_ON_CLOSE
|
||||||
dlg.setSize(300, 75)
|
dlg.setSize(300, 75)
|
||||||
dlg.setLocationRelativeTo(jf)
|
dlg.setLocationRelativeTo(jf)
|
||||||
|
pbar.foreground = Color.GREEN.darker()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun doTheThing(basedir: File, outdir: File, watermarkpath: File) {
|
fun watermarkImages(basedir: File, outdir: File, watermarkpath: File) {
|
||||||
val wmbase = ImageIO.read(watermarkpath)
|
val wmbase = ImageIO.read(watermarkpath)
|
||||||
|
|
||||||
val scale = 3.6
|
val scale = 3.6
|
||||||
|
@ -190,7 +226,8 @@ fun doTheThing(basedir: File, outdir: File, watermarkpath: File) {
|
||||||
val iwp = writer.defaultWriteParam
|
val iwp = writer.defaultWriteParam
|
||||||
iwp.compressionMode = ImageWriteParam.MODE_EXPLICIT
|
iwp.compressionMode = ImageWriteParam.MODE_EXPLICIT
|
||||||
iwp.compressionQuality = 0.9f
|
iwp.compressionQuality = 0.9f
|
||||||
val imgOut = MemoryCacheImageOutputStream(File(outdir, f.nameWithoutExtension + ".jpg").outputStream())
|
val imgOut =
|
||||||
|
MemoryCacheImageOutputStream(File(outdir, f.nameWithoutExtension + ".jpg").outputStream())
|
||||||
writer.output = imgOut
|
writer.output = imgOut
|
||||||
val ending = IIOImage(combined, null, imageMetadata)
|
val ending = IIOImage(combined, null, imageMetadata)
|
||||||
writer.write(null, ending, iwp)
|
writer.write(null, ending, iwp)
|
||||||
|
@ -205,7 +242,7 @@ fun doTheThing(basedir: File, outdir: File, watermarkpath: File) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Component.forceToCenter(): Component = JPanel().apply { this.add(this@forceToCenter) }
|
fun Component.forceToCenter(): JPanel = JPanel().apply { this.add(this@forceToCenter) }
|
||||||
|
|
||||||
fun addWM(watermark: BufferedImage, image: BufferedImage): Image {
|
fun addWM(watermark: BufferedImage, image: BufferedImage): Image {
|
||||||
val combined = BufferedImage(image.width, image.height, BufferedImage.TYPE_INT_RGB)
|
val combined = BufferedImage(image.width, image.height, BufferedImage.TYPE_INT_RGB)
|
||||||
|
@ -228,24 +265,3 @@ fun resize(img: BufferedImage, newW: Double, newH: Double): BufferedImage {
|
||||||
|
|
||||||
return dimg
|
return dimg
|
||||||
}
|
}
|
||||||
|
|
||||||
//class FrmPopUpInfo(message: String, image: Image) : JFrame() {
|
|
||||||
// init {
|
|
||||||
// this.title = message
|
|
||||||
// this.add(JLabel(ImageIcon(image)))
|
|
||||||
// this.background = Color.WHITE
|
|
||||||
// this.pack()
|
|
||||||
//
|
|
||||||
// this.setLocationRelativeTo(null)
|
|
||||||
// obs.addObserver { _, _ ->
|
|
||||||
// java.util.Timer().schedule(timerTask {
|
|
||||||
//
|
|
||||||
// }, 5 * 1000)
|
|
||||||
// this@FrmPopUpInfo.isVisible = false
|
|
||||||
//
|
|
||||||
// this@FrmPopUpInfo.dispose()
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// this.isVisible = true
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
Loading…
Reference in a new issue