X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTButton.java;h=fc93c782b5fda5c66ff01a9297fc23ee53588837;hb=a325f111c91ec64c0bb0319dedd18d36f4b720c9;hp=748fe247c035b5dccf22acc913271fb0dbc30b10;hpb=e16dda65585466c8987bd1efd718431450a96605;p=fanfix.git diff --git a/src/jexer/TButton.java b/src/jexer/TButton.java index 748fe24..fc93c78 100644 --- a/src/jexer/TButton.java +++ b/src/jexer/TButton.java @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (C) 2016 Kevin Lamonte + * Copyright (C) 2017 Kevin Lamonte * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -73,13 +73,27 @@ public final class TButton extends TWidget { */ private TAction action; + /** + * The time at which dispatch() was called. + */ + private long dispatchTime; + + /** + * How long to animate dispatch of the event in millis. + */ + private static final long DISPATCH_TIME = 75; + /** * Act as though the button was pressed. This is useful for other UI * elements to get the same action as if the user clicked the button. */ public void dispatch() { if (action != null) { - action.DO(); + long now = System.currentTimeMillis(); + if (now - dispatchTime > DISPATCH_TIME) { + action.DO(); + dispatchTime = now; + } } } @@ -153,6 +167,12 @@ public final class TButton extends TWidget { shadowColor.setForeColor(Color.BLACK); shadowColor.setBold(false); + long now = System.currentTimeMillis(); + boolean inDispatch = false; + if (now - dispatchTime < DISPATCH_TIME) { + inDispatch = true; + } + if (!isEnabled()) { buttonColor = getTheme().getColor("tbutton.disabled"); menuMnemonicColor = getTheme().getColor("tbutton.disabled"); @@ -164,7 +184,7 @@ public final class TButton extends TWidget { menuMnemonicColor = getTheme().getColor("tbutton.mnemonic"); } - if (inButtonPress) { + if (inButtonPress || inDispatch) { getScreen().putCharXY(1, 0, ' ', buttonColor); getScreen().putStringXY(2, 0, mnemonic.getRawLabel(), buttonColor); getScreen().putCharXY(getWidth() - 1, 0, ' ', buttonColor); @@ -179,7 +199,7 @@ public final class TButton extends TWidget { GraphicsChars.CP437[0xDF], shadowColor); } if (mnemonic.getShortcutIdx() >= 0) { - if (inButtonPress) { + if (inButtonPress || inDispatch) { getScreen().putCharXY(2 + mnemonic.getShortcutIdx(), 0, mnemonic.getShortcut(), menuMnemonicColor); } else { @@ -217,9 +237,7 @@ public final class TButton extends TWidget { if (inButtonPress && mouse.isMouse1()) { inButtonPress = false; // Dispatch the event - if (action != null) { - action.DO(); - } + dispatch(); } } @@ -249,9 +267,7 @@ public final class TButton extends TWidget { || keypress.equals(kbSpace) ) { // Dispatch - if (action != null) { - action.DO(); - } + dispatch(); return; }