package bluej.editor.stride;
import java.io.File;
import java.net.MalformedURLException;
import java.util.Collections;
import java.util.Map;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.input.KeyCode;
import javafx.scene.media.AudioClip;
import bluej.stride.generic.InteractionManager;
import bluej.utility.Debug;
import threadchecker.OnThread;
import threadchecker.Tag;
| A file completion for sound filenames in the scenario's "sounds/" subdirectory
|*/
@OnThread(Tag.FX) class SoundCompletion implements InteractionManager.FileCompletion{
/** The file which the completion refers to */
private final File file;
/** Create a SoundCompletion for the given sound file in the project's sounds/ directory
public SoundCompletion(File file)
{
this.file = file;
}
@Override
public File getFile()
{
return file;
}
@Override
public String getType()
{
return "Sound";
}
| The preview shows a button which will play the sound when clicked
|
@Override
public Node getPreview(double maxWidth, double maxHeight)
{
Button b = new Button("Play (F8)");
b.setOnAction(e -> play());
return b;
}
| Plays the sound clip in full by loading it from the file
|
private void play()
{
try
{
AudioClip clip = new AudioClip(file.toURI().toURL().toString());
clip.play();
} catch (MalformedURLException ex)
{
Debug.reportError(ex);
}
}
| Actually implements the F8-to-play shortcut
|
@Override
public Map getShortcuts()
{
return Collections.singletonMap(KeyCode.F8, this::play);
}
}
. SoundCompletion
. getFile
. getType
. getPreview
. play
. getShortcuts
78 neLoCode
+ 4 LoComm