mirror of
https://github.com/TermoraDev/termora.git
synced 2026-01-16 02:12:58 +08:00
chore: improve tick
This commit is contained in:
@@ -13,8 +13,6 @@ import java.nio.channels.FileLock
|
||||
import java.nio.file.Paths
|
||||
import java.nio.file.StandardOpenOption
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import javax.swing.JFrame
|
||||
import javax.swing.SwingUtilities
|
||||
|
||||
class ApplicationSingleton private constructor() : Disposable {
|
||||
|
||||
@@ -195,19 +193,7 @@ class ApplicationSingleton private constructor() : Disposable {
|
||||
}
|
||||
|
||||
private fun onTick() {
|
||||
SwingUtilities.invokeLater(object : Runnable {
|
||||
override fun run() {
|
||||
val windows = TermoraFrameManager.getInstance().getWindows()
|
||||
if (windows.isEmpty()) return
|
||||
for (window in windows) {
|
||||
if (window.extendedState and JFrame.ICONIFIED == JFrame.ICONIFIED) {
|
||||
window.extendedState = window.extendedState and JFrame.ICONIFIED.inv()
|
||||
}
|
||||
}
|
||||
windows.last().toFront()
|
||||
}
|
||||
})
|
||||
|
||||
TermoraFrameManager.getInstance().tick()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,8 +18,11 @@ import java.awt.event.MouseListener
|
||||
import java.awt.event.MouseMotionListener
|
||||
import java.util.*
|
||||
import javax.imageio.ImageIO
|
||||
import javax.swing.*
|
||||
import javax.swing.JComponent
|
||||
import javax.swing.JFrame
|
||||
import javax.swing.SwingUtilities
|
||||
import javax.swing.SwingUtilities.isEventDispatchThread
|
||||
import javax.swing.UIManager
|
||||
|
||||
fun assertEventDispatchThread() {
|
||||
if (!isEventDispatchThread()) throw WrongThreadException("AWT EventQueue")
|
||||
@@ -236,22 +239,4 @@ class TermoraFrame : JFrame(), DataProvider {
|
||||
return id.hashCode()
|
||||
}
|
||||
|
||||
override fun addNotify() {
|
||||
super.addNotify()
|
||||
|
||||
val dialog = object : DialogWrapper(this@TermoraFrame) {
|
||||
init {
|
||||
init()
|
||||
controlsVisible = false
|
||||
}
|
||||
|
||||
override fun createCenterPanel(): JComponent {
|
||||
return JPanel()
|
||||
}
|
||||
}
|
||||
dialog.title = "Hello"
|
||||
dialog.size = Dimension(800, 600)
|
||||
dialog.setLocationRelativeTo(this)
|
||||
// dialog.isVisible = true
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,9 @@ import org.slf4j.LoggerFactory
|
||||
import java.awt.Frame
|
||||
import java.awt.event.WindowAdapter
|
||||
import java.awt.event.WindowEvent
|
||||
import javax.swing.JFrame
|
||||
import javax.swing.JOptionPane
|
||||
import javax.swing.SwingUtilities
|
||||
import javax.swing.UIManager
|
||||
import javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE
|
||||
import kotlin.math.max
|
||||
@@ -96,6 +98,21 @@ class TermoraFrameManager {
|
||||
})
|
||||
}
|
||||
|
||||
fun tick() {
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
val windows = getWindows()
|
||||
if (windows.isEmpty()) return
|
||||
for (window in windows) {
|
||||
if (window.extendedState and JFrame.ICONIFIED == JFrame.ICONIFIED) {
|
||||
window.extendedState = window.extendedState and JFrame.ICONIFIED.inv()
|
||||
}
|
||||
}
|
||||
windows.last().toFront()
|
||||
} else {
|
||||
SwingUtilities.invokeLater { tick() }
|
||||
}
|
||||
}
|
||||
|
||||
private fun dispose() {
|
||||
Disposer.dispose(ApplicationScope.forApplicationScope())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user