-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e16aacf
commit 48d56f6
Showing
19 changed files
with
779 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
package util | ||
|
||
import java.awt.Component | ||
import java.io.File | ||
import javax.swing.JFileChooser | ||
import javax.swing.JOptionPane | ||
import javax.swing.SwingUtilities | ||
import screen.LoadingDialog | ||
import screen.ScreenCache | ||
import utils.InjectedThings.logger | ||
|
||
object DialogUtilNew { | ||
private var loadingDialog: LoadingDialog? = null | ||
|
||
fun showInfo(infoText: String, parent: Component = ScreenCache.getMainScreen()) { | ||
logDialogShown("Info", "Information", infoText) | ||
JOptionPane.showMessageDialog( | ||
parent, | ||
infoText, | ||
"Information", | ||
JOptionPane.INFORMATION_MESSAGE | ||
) | ||
logDialogClosed("Info", null) | ||
} | ||
|
||
fun showCustomMessage(message: Any, parent: Component = ScreenCache.getMainScreen()) { | ||
logDialogShown("CustomInfo", "Information", "?") | ||
JOptionPane.showMessageDialog( | ||
parent, | ||
message, | ||
"Information", | ||
JOptionPane.INFORMATION_MESSAGE | ||
) | ||
logDialogClosed("CustomInfo", null) | ||
} | ||
|
||
fun showError(errorText: String, parent: Component? = ScreenCache.getMainScreen()) { | ||
dismissLoadingDialog() | ||
|
||
logDialogShown("Error", "Error", errorText) | ||
JOptionPane.showMessageDialog(parent, errorText, "Error", JOptionPane.ERROR_MESSAGE) | ||
logDialogClosed("Error", null) | ||
} | ||
|
||
fun showErrorLater(errorText: String) { | ||
SwingUtilities.invokeLater { showError(errorText) } | ||
} | ||
|
||
@JvmOverloads | ||
fun showQuestion( | ||
message: String, | ||
allowCancel: Boolean = false, | ||
parent: Component = ScreenCache.getMainScreen() | ||
): Int { | ||
logDialogShown("Question", "Question", message) | ||
val option = | ||
if (allowCancel) JOptionPane.YES_NO_CANCEL_OPTION else JOptionPane.YES_NO_OPTION | ||
val selection = | ||
JOptionPane.showConfirmDialog( | ||
parent, | ||
message, | ||
"Question", | ||
option, | ||
JOptionPane.QUESTION_MESSAGE | ||
) | ||
logDialogClosed("Question", selection) | ||
return selection | ||
} | ||
|
||
fun showLoadingDialog(text: String) { | ||
logDialogShown("Loading", "", text) | ||
loadingDialog = LoadingDialog() | ||
loadingDialog?.showDialog(text) | ||
} | ||
|
||
fun dismissLoadingDialog() { | ||
val wasVisible = loadingDialog?.isVisible ?: false | ||
loadingDialog?.dismissDialog() | ||
if (wasVisible) { | ||
logDialogClosed("Loading", null) | ||
} | ||
} | ||
|
||
fun showOption(title: String, message: String, options: List<String>): String? { | ||
logDialogShown("Option", title, message) | ||
val typedArray = options.toTypedArray() | ||
val selection = | ||
JOptionPane.showOptionDialog( | ||
null, | ||
message, | ||
title, | ||
JOptionPane.DEFAULT_OPTION, | ||
JOptionPane.QUESTION_MESSAGE, | ||
null, | ||
typedArray, | ||
options.first() | ||
) | ||
val selectionStr = if (selection > -1) typedArray[selection] else null | ||
|
||
logDialogClosed("Option", selectionStr) | ||
return selectionStr | ||
} | ||
|
||
fun <K> showInput( | ||
title: String, | ||
message: String, | ||
options: Array<K>? = null, | ||
defaultOption: K? = null | ||
): K? { | ||
logDialogShown("Input", title, message) | ||
val selection = | ||
JOptionPane.showInputDialog( | ||
null, | ||
message, | ||
title, | ||
JOptionPane.PLAIN_MESSAGE, | ||
null, | ||
options, | ||
defaultOption | ||
) as K? | ||
|
||
logDialogClosed("Input", selection) | ||
return selection | ||
} | ||
|
||
fun chooseDirectory(parent: Component?): File? { | ||
logDialogShown("File selector", "", "") | ||
val fc = JFileChooser() | ||
fc.fileSelectionMode = JFileChooser.DIRECTORIES_ONLY | ||
val option = fc.showDialog(parent, "Select") | ||
if (option != JFileChooser.APPROVE_OPTION) { | ||
return null | ||
} | ||
|
||
val file = fc.selectedFile | ||
logDialogClosed("File selector", file?.absolutePath) | ||
return file | ||
} | ||
|
||
private fun logDialogShown(type: String, title: String, message: String) { | ||
logger.info( | ||
"dialogShown", | ||
"$type dialog shown: $message", | ||
"dialogType" to type, | ||
"dialogTitle" to title, | ||
"dialogMessage" to message | ||
) | ||
} | ||
|
||
private fun logDialogClosed(type: String, selection: Any?) { | ||
var message = "$type dialog closed" | ||
selection?.let { message += " - selected ${translateOption(it)}" } | ||
|
||
logger.info("dialogClosed", message, "dialogType" to type, "dialogSelection" to selection) | ||
} | ||
|
||
private fun translateOption(option: Any?) = | ||
when (option) { | ||
JOptionPane.YES_OPTION -> "Yes" | ||
JOptionPane.NO_OPTION -> "No" | ||
JOptionPane.CANCEL_OPTION -> "Cancel" | ||
else -> option | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
@echo off | ||
|
||
REM %1 = noOfBytes | ||
REM %2 = version number | ||
REM %3 = filename | ||
REM %4 = assetId | ||
|
||
echo Performing download of %1 bytes (Version %2) | ||
|
||
curl -LJO -H "Accept: application/octet-stream" https://api.github.com/repos/alyssaburlton/Dartzee/releases/assets/%4 | ||
|
||
ren Dartzee.jar Dartzee_OLD.jar | ||
ren %3 Dartzee.jar | ||
del Dartzee_OLD.jar | ||
|
||
start javaw -Xms256m -Xmx512m -jar Dartzee.jar justUpdated trueLaunch | ||
exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package bean | ||
|
||
import com.github.alyssaburlton.swingtest.makeMouseEvent | ||
import io.kotest.assertions.throwables.shouldThrow | ||
import io.kotest.matchers.shouldBe | ||
import io.mockk.mockk | ||
import io.mockk.verifySequence | ||
import java.awt.Cursor | ||
import java.awt.event.MouseEvent | ||
import javax.swing.JButton | ||
import javax.swing.JPanel | ||
import main.kotlin.testCore.AbstractTest | ||
import org.junit.jupiter.api.Test | ||
|
||
private val mouseEventOverLink = makeMouseEvent(JButton()) | ||
private val mouseEventNotOverLink = makeMouseEvent(JButton()) | ||
|
||
class HyperlinkAdaptorTest : AbstractTest() { | ||
@Test | ||
fun `Should not accept a non-component listener`() { | ||
shouldThrow<ClassCastException> { HyperlinkAdaptor(NonComponentHyperlinkListener()) } | ||
} | ||
|
||
@Test | ||
fun `Should respond to mouse clicks`() { | ||
val listener = mockk<TestHyperlinkListener>(relaxed = true) | ||
|
||
val adaptor = HyperlinkAdaptor(listener) | ||
adaptor.mouseClicked(mouseEventOverLink) | ||
adaptor.mouseClicked(mouseEventNotOverLink) | ||
|
||
verifySequence { | ||
listener.linkClicked(mouseEventOverLink) | ||
listener.linkClicked(mouseEventNotOverLink) | ||
} | ||
} | ||
|
||
@Test | ||
fun `Should change the cursor on mouse movement`() { | ||
val listener = TestHyperlinkListener() | ||
val adaptor = HyperlinkAdaptor(listener) | ||
|
||
adaptor.mouseMoved(mouseEventNotOverLink) | ||
listener.cursor shouldBe Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR) | ||
|
||
adaptor.mouseMoved(mouseEventOverLink) | ||
listener.cursor shouldBe Cursor.getPredefinedCursor(Cursor.HAND_CURSOR) | ||
|
||
adaptor.mouseMoved(mouseEventNotOverLink) | ||
listener.cursor shouldBe Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR) | ||
|
||
adaptor.mouseEntered(mouseEventNotOverLink) | ||
listener.cursor shouldBe Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR) | ||
|
||
adaptor.mouseEntered(mouseEventOverLink) | ||
listener.cursor shouldBe Cursor.getPredefinedCursor(Cursor.HAND_CURSOR) | ||
} | ||
|
||
@Test | ||
fun `Should revert the cursor on mouseExit`() { | ||
val listener = TestHyperlinkListener() | ||
val adaptor = HyperlinkAdaptor(listener) | ||
|
||
adaptor.mouseMoved(mouseEventOverLink) | ||
listener.cursor shouldBe Cursor.getPredefinedCursor(Cursor.HAND_CURSOR) | ||
|
||
adaptor.mouseExited(null) | ||
listener.cursor shouldBe Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR) | ||
} | ||
|
||
@Test | ||
fun `Should revert the cursor on mouseDragged`() { | ||
val listener = TestHyperlinkListener() | ||
val adaptor = HyperlinkAdaptor(listener) | ||
|
||
adaptor.mouseMoved(mouseEventOverLink) | ||
listener.cursor shouldBe Cursor.getPredefinedCursor(Cursor.HAND_CURSOR) | ||
|
||
adaptor.mouseDragged(null) | ||
listener.cursor shouldBe Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR) | ||
} | ||
} | ||
|
||
private class TestHyperlinkListener : JPanel(), IHyperlinkListener { | ||
override fun isOverHyperlink(arg0: MouseEvent) = arg0 === mouseEventOverLink | ||
|
||
override fun linkClicked(arg0: MouseEvent) {} | ||
} | ||
|
||
private class NonComponentHyperlinkListener : IHyperlinkListener { | ||
override fun isOverHyperlink(arg0: MouseEvent) = false | ||
|
||
override fun linkClicked(arg0: MouseEvent) {} | ||
} |
Oops, something went wrong.