package bluej.stride.generic;
import java.util.IdentityHashMap;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import bluej.Config;
import bluej.editor.stride.CodeOverlayPane;
import bluej.stride.generic.InteractionManager.ShortcutKey;
import bluej.utility.javafx.FXRunnable;
import bluej.utility.javafx.JavaFXUtil;
import threadchecker.OnThread;
import threadchecker.Tag;
public class SuggestedFollowUpDisplay
{
private final InteractionManager editor;
private final FXRunnable action;
private final VBox content = new VBox();
private static final IdentityHashMap<InteractionManager, SuggestedFollowUpDisplay> displays = new IdentityHashMap<>();
public SuggestedFollowUpDisplay(InteractionManager editor, String text, FXRunnable action)
{
this.editor = editor;
this.action = action;
JavaFXUtil.addStyleClass(content, "suggested-followup-pane");
Button yes = new Button("Yes (" + Config.getKeyCodeForYesNo(ShortcutKey.YES_ANYWHERE) + ")");
yes.setOnAction(e -> { action.run(); hide();
});
Button no = new Button("No (" + Config.getKeyCodeForYesNo(ShortcutKey.NO_ANYWHERE) + ")");
no.setOnAction(e -> hide());
HBox hbox = new HBox(yes, no);
JavaFXUtil.addStyleClass(hbox, "suggested-followup-hbox");
content.getChildren().addAll(new Label(text), hbox);
CodeOverlayPane.setDropShadow(content);
}
@OnThread(Tag.FXPlatform)
public void showBefore(final Node n)
{
if (displays.get(editor) != null)
{
displays.get(editor).hide();
}
editor.getCodeOverlayPane().addOverlay(content, n, null, content.heightProperty().add(5.0).negate());
content.toBack();
displays.put(editor, this);
}
public void hide()
{
JavaFXUtil.runNowOrLater(() -> editor.getCodeOverlayPane().removeOverlay(content));
displays.remove(editor);
}
@OnThread(Tag.FXPlatform)
public static void shortcutTyped(InteractionManager editor, ShortcutKey key)
{
SuggestedFollowUpDisplay display = displays.get(editor);
if (display != null)
{
if (key == ShortcutKey.YES_ANYWHERE)
display.action.run();
display.hide();
}
}
public static void modificationIn(InteractionManager editor)
{
SuggestedFollowUpDisplay display = displays.get(editor);
if (display != null)
{
display.hide();
}
}
}
top,
use,
map,
class SuggestedFollowUpDisplay
. SuggestedFollowUpDisplay
. showBefore
. hide
. shortcutTyped
. modificationIn
102 neLoCode
+ 0 LoComm