use of javafx.scene.input.MouseEvent in project S4T1TM2 by CSUS-CSC-131-Spring2018.
the class JavaFXDemo method start.
/**
* Typically (or at least, by convention), Java applications that apply JavaFX Stages (Windows) extend the JavaFX Application class
* JEP 153 (http://openjdk.java.net/jeps/153) allows Java to launch JavaFX Applications without a declared main method (although, must be specified in the manifest)
*
* However, a main method with additional procedures may be defined. Implicitly, the default main method for a JavaFX application follows below:
*/
/*
public static void main(String[] args) {
Application.launch(JavaFXDemo.class);
}
*/
@Override
public void start(Stage primaryStage) throws Exception {
// primaryStage is the default stage JavaFX builds for you
// Exception is part of the Application#start(Stage) signature, but can be removed if no exceptions are thrown in your procedure
// define attributes for the primary stage
primaryStage.setTitle("Default Title");
// alternatively, you may set the scene dimensions in the constructor, and the Stage will inherit from those
primaryStage.setHeight(600);
primaryStage.setWidth(800);
// Pane is one of the simplest forms of containers, there exist others for different purposes (StackPane, ScrollPane, etc...)
// Since rootPane will be set as the root pane, it will automatically inherit width/height from the scene (which may inherit from the primary stage)
Pane rootPane = new Pane();
// Creates a text input field, using the JFoenix UI extension. The standard JavaFX one is TextField
JFXTextField field = new JFXTextField();
field.setPromptText("Placeholder value...");
// Most JavaFX elements extend from one of the parent types - javafx.scene.Node
// Nodes have observable and bindable values, and elements that will inherit and possibly add more properties
// Some properties are readonly, and some are read and writeable
// Properties have a datatype
// for example, we can bind the title of the window to the value of the text field, which will overwrite the currently defined title "Default Title" immediately
primaryStage.titleProperty().bind(field.textProperty());
// Mathematical calculations can be done with observable values, such as subtraction
// If any value updates that is being depended on, it will update
// Center the text field to the 3/4th the width, and 1/2 the height
// field.x = rootPane.width * 3/4 - field.width * 1/2
field.layoutXProperty().bind(rootPane.widthProperty().multiply(.75f).subtract(field.widthProperty().divide(2)));
// field.x = rootPane.width * 1/4 - field.width * 1/2
field.layoutYProperty().bind(rootPane.heightProperty().multiply(.5).subtract(field.heightProperty().divide(2)));
// part of JFoenix's material design
// when the textbox is focused
field.setFocusColor(Color.GREEN);
// when it is not focused
field.setUnFocusColor(Color.RED);
// define a background (very cumbersome in java, easier in css)
// field.setBackground(new Background(new BackgroundFill(Color.GRAY, null, null )));
// so why not just use inline CSS?
field.setStyle("-fx-background-color: gray;");
// we need to add field to the rootPane as a child, Nodes can be added to anything that is a `Parent`, which a Pane is
rootPane.getChildren().add(field);
// lets try a button
// text inside button
JFXButton button = new JFXButton("Random Text");
// or just define it later
button.setText("Defined");
// or bind it to a constant value?!
button.textProperty().bind(StringConstant.valueOf("A constant"));
// more JFoenix UI control, let's make the button more defined
button.setButtonType(JFXButton.ButtonType.RAISED);
button.setBackground(new Background(new BackgroundFill(Color.rgb(97, 118, 207), null, null)));
// There's pretty much a infinite amount of ways you can do anything in JavaFX
// lets create a event handler
button.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
// event gives you things you may be interested in
System.out.println("Clicked! Is shift down: " + event.isShiftDown());
}
});
// boilerplate is bothersome, lets try Java 8's concise lambdas
button.setOnMouseClicked(event -> System.out.println("Clicked! Is shift down: " + event.isShiftDown()));
// again, add it
// no layoutX or layoutY was specified, it will just be by default placed in the upper left corner (aka the origin)
rootPane.getChildren().add(button);
// all primary stages need a Scene for the window
Scene scene = new Scene(rootPane);
// additional content can be defined here for a scene, like background color
scene.setFill(Color.GRAY);
// set the scene
primaryStage.setScene(scene);
// Show the stage!
primaryStage.show();
// By default, closing all JavaFX Stages will implicitly exit the JavaFX platform, making it cumbersome to create a new stage
// For applications that get minimized to a tray icon, that is not desirable.
// That can be disabled by executing the following:
// Platform.setImplicitExit(false);
}
use of javafx.scene.input.MouseEvent in project tokentool by RPTools.
the class ManageOverlays_Controller method loadImages.
private void loadImages(File dir) {
// Clear Details panel
clearDetails();
currentDirectory = dir;
File[] files = dir.listFiles(ImageUtil.SUPPORTED_FILENAME_FILTER);
Task<Void> task = new Task<Void>() {
@Override
public Void call() {
for (File file : files) {
Path filePath = file.toPath();
if (loadOverlaysThread.isInterrupted()) {
Platform.runLater(() -> overlayViewFlowPane.getChildren().clear());
break;
}
try {
ToggleButton overlayButton = new ToggleButton();
ImageView imageViewNode = ImageUtil.getOverlayThumb(new ImageView(), filePath);
overlayButton.getStyleClass().add("overlay-toggle-button");
overlayButton.setGraphic(imageViewNode);
overlayButton.setUserData(file);
overlayButton.setToggleGroup(overlayToggleGroup);
overlayButton.addEventHandler(ActionEvent.ACTION, event -> {
// No modifier keys used so add toggle group back to all buttons
resetToggleGroup();
// Also set button to selected due to resetting toggle groups & no unselecting needed, makes for better interface IMO
overlayButton.setSelected(true);
// Update the Details panel with the last selected overlay
File overlayFile = (File) overlayButton.getUserData();
updateDetails(overlayFile, (ImageView) overlayButton.getGraphic(), overlayButton.isSelected());
// Consume the event, no more logic needed
event.consume();
});
overlayButton.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
// Allow multiple selections if shortcutKey+left_mouse is pressed
if (event.getButton().equals(MouseButton.PRIMARY) && event.isShortcutDown()) {
// Update the Details panel with the last selected overlay
File overlayFile = (File) overlayButton.getUserData();
updateDetails(overlayFile, (ImageView) overlayButton.getGraphic(), true);
// Remove the toggle group to allow multiple toggle button selection
overlayButton.setToggleGroup(null);
// Select the button
overlayButton.setSelected(true);
// Consume the event, no more logic needed
event.consume();
}
}
});
Platform.runLater(() -> overlayViewFlowPane.getChildren().add(overlayButton));
} catch (IOException e) {
log.error("Loading image: " + filePath.getFileName(), e);
}
}
return null;
}
};
loadOverlaysThread.interrupt();
executorService.execute(task);
}
use of javafx.scene.input.MouseEvent in project Board-Instrumentation-Framework by intel.
the class SteelGaugeWidget method Create.
@Override
public boolean Create(GridPane pane, DataManager dataMgr) {
SetParent(pane);
_ParentGridPane = pane;
if (false == SetupGauge()) {
return false;
}
_Gauge.setValue(_InitialValue);
ConfigureDimentions();
ConfigureAlignment();
// special because Gauge can be interactive
EventHandler<MouseEvent> eh = SetupTaskAction();
if (null == eh) {
eh = new // create a dummy one, because we dont' want interactive
EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
}
};
}
_Gauge.customKnobClickHandlerProperty().set(eh);
SetupPeekaboo(dataMgr);
pane.add(_Gauge, getColumn(), getRow(), getColumnSpan(), getRowSpan());
dataMgr.AddListener(getMinionID(), getNamespace(), new ChangeListener() {
@Override
public void changed(ObservableValue o, Object oldVal, Object newVal) {
if (IsPaused()) {
return;
}
double newDialValue = 0;
double oldDialValue = 0;
String strVal = newVal.toString();
try {
newDialValue = Double.parseDouble(strVal);
// oldDialValue = Double.parseDouble(oldVal.toString());
} catch (Exception ex) {
LOGGER.severe("Invalid data for Gauge received: " + strVal);
return;
}
_Gauge.setValue(newDialValue);
}
});
return ApplyCSS();
}
use of javafx.scene.input.MouseEvent in project RichTextFX by FXMisc.
the class MouseStationaryHelper method events.
/**
* Returns an {@link EventStream} that emits a {@link Point2D} whenever the mouse becomes stationary
* over the helper's node and emits a {@code null} value whenever the mouse moves after being stationary.
*/
public EventStream<Either<Point2D, Void>> events(Duration delay) {
EventStream<MouseEvent> mouseEvents = eventsOf(node, MouseEvent.ANY);
EventStream<Point2D> stationaryPositions = mouseEvents.successionEnds(delay).filter(e -> e.getEventType() == MOUSE_MOVED).map(e -> new Point2D(e.getX(), e.getY()));
EventStream<Void> stoppers = mouseEvents.supply((Void) null);
return stationaryPositions.or(stoppers).distinct();
}
use of javafx.scene.input.MouseEvent in project assembly64fx by freabemania.
the class SidifyMainContoller method init.
public void init(Boolean showBackButton) {
if (!playerWindowActive.compareAndSet(false, true)) {
setCancelShow(true);
return;
}
imageCache = CachedImageService.getInstance();
playListService = PlaylistService.getInstance();
downloadService = DownloadArtifactsService.getInstance();
pathService = PathService.getInstance();
sidPlayService = SIDPlayerService.getInstance();
volume.setMin(-50L);
volume.setMax(12);
volume.setValue(sidPlayService.getVolume());
volume.valueProperty().addListener(new ChangeListener<Number>() {
public void changed(ObservableValue<? extends Number> ov, Number oldVal, Number newVal) {
sidPlayService.setVolume(newVal.intValue());
}
});
volume.valueChangingProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observableValue, Boolean wasChanging, Boolean changing) {
if (!changing) {
sidPlayService.storeVolume();
}
}
});
if (isOffline()) {
enableSearchImage.setVisible(false);
}
performSearchImage.setVisible(false);
searchField.setVisible(false);
setIconPlaying(false);
name.setCellValueFactory(new PropertyValueFactory<PlaylistEntry, String>("nameMasked"));
group.setCellValueFactory(new PropertyValueFactory<PlaylistEntry, String>("groupMasked"));
year.setCellValueFactory(new PropertyValueFactory<PlaylistEntry, String>("year"));
downloaded.setCellValueFactory(new PropertyValueFactory<PlaylistEntry, ImageView>("downloaded"));
status.setCellValueFactory(new PropertyValueFactory<PlaylistEntry, ImageView>("status"));
progressSlider.setMin(0);
progressSlider.setMax(SLIDERMAX);
progressSlider.disableProperty().setValue(Boolean.TRUE);
progressUpdater = new ProgressUpdater(played, remaining, progressSlider, prevSub, nextSub);
status.setMaxWidth(40);
status.setMinWidth(40);
status.setSortable(false);
name.setSortable(false);
group.setSortable(false);
year.setSortable(false);
// songLength.setSortable(false);
downloaded.setSortable(false);
songlist.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
songlist.setPlaceholder(new Label(""));
songlist.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
searchPeriod.setItems(FXCollections.observableArrayList(SEARCH_PERIOD.ALL, SEARCH_PERIOD.ONE_DAY, SEARCH_PERIOD.TWO_DAYS, SEARCH_PERIOD.FOUR_DAYS, SEARCH_PERIOD.ONE_WEEK, SEARCH_PERIOD.TWO_WEEKS, SEARCH_PERIOD.THREE_WEEKS, SEARCH_PERIOD.ONE_MONTH, SEARCH_PERIOD.TWO_MONTHS));
searchPeriod.getSelectionModel().select(0);
searchPeriod.setVisible(false);
if (openedMain || !showBackButton) {
openedMain = true;
backToAssemblyImage.setVisible(false);
}
getStage().getScene().heightProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneHeight, Number newSceneHeight) {
resizeComponentsHeight();
delayedResize();
}
});
getStage().getScene().widthProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneHeight, Number newSceneWidth) {
resizeComponentsWidth();
delayedResize();
}
});
songlist.setRowFactory(tv -> {
TableRow<PlaylistEntry> row = new TableRow<>();
row.setOnDragDetected(event -> {
if (!row.isEmpty() && isPlaylistMine(activePlaylist)) {
Integer index = row.getIndex();
Dragboard db = row.startDragAndDrop(TransferMode.MOVE);
db.setDragView(row.snapshot(null, null));
ClipboardContent cc = new ClipboardContent();
cc.put(SERIALIZED_MIME_TYPE, index);
db.setContent(cc);
event.consume();
}
});
row.setOnDragOver(event -> {
if (!isSearchActive() && isPlaylistMine(activePlaylist)) {
Dragboard db = event.getDragboard();
if (db.hasContent(SERIALIZED_MIME_TYPE)) {
if (row.getIndex() != ((Integer) db.getContent(SERIALIZED_MIME_TYPE)).intValue()) {
event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
event.consume();
}
}
}
});
row.setOnDragDropped(event -> {
if (!isSearchActive() && isPlaylistMine(activePlaylist)) {
Dragboard db = event.getDragboard();
if (db.hasContent(SERIALIZED_MIME_TYPE)) {
int draggedIndex = (Integer) db.getContent(SERIALIZED_MIME_TYPE);
PlaylistEntry draggedPerson = songlist.getItems().remove(draggedIndex);
int dropIndex;
if (row.isEmpty()) {
dropIndex = songlist.getItems().size();
} else {
dropIndex = row.getIndex();
}
songlist.getItems().add(dropIndex, draggedPerson);
event.setDropCompleted(true);
clearAndSelect(dropIndex);
Analytics.sendEvent("sidify", "dragndrop_song");
playListService.moveSongInList(playListService.getPlaylistForSong(draggedPerson), draggedIndex, dropIndex);
event.consume();
populateLeftList();
}
}
});
return row;
});
getStage().setOnCloseRequest(new EventHandler<WindowEvent>() {
public void handle(WindowEvent we) {
if (GlobalRepoService.getInstance().contains("overridebacktoassembly")) {
closeAndcleanup(true);
} else {
closeAndcleanup(!LocalDBService.getInstance().getSidifyAsDefault());
}
}
});
populateLeftList();
leftlist.setCellFactory(callback -> new ListCell<PlayerItem>() {
@Override
protected void updateItem(PlayerItem t, boolean bln) {
super.updateItem(t, bln);
if (t != null) {
setText(t.getName());
}
}
});
leftlist.setOnMousePressed(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
disableSearch(true, false);
PlayerItem clickedItem = leftlist.getSelectionModel().getSelectedItem();
if (clickedItem.getType() == MENU_TYPE.NONCLICKABLE) {
leftlist.getSelectionModel().clearSelection();
} else if (clickedItem.getType() == MENU_TYPE.PLAYLIST || clickedItem.getType() == MENU_TYPE.PUBLICLIST) {
PlaylistInfo playlist = clickedItem.getPlaylist();
// activePlaylist = playlist;
if ((event.getButton() == MouseButton.SECONDARY || event.isControlDown()) && !isOffline()) {
final ContextMenu contextMenu = new ContextMenu();
if (clickedItem.getType() == MENU_TYPE.PLAYLIST) {
MenuItem tmp = new MenuItem("Delete");
tmp.setOnAction((ActionEvent event2) -> {
playListService.deletePlaylist(playlist);
populateLeftList();
clearSongList();
});
MenuItem rename = new MenuItem("Edit");
rename.setOnAction((ActionEvent event2) -> {
GuiUtils.showDialog("sidifyCreateNewPlaylist.fxml", Boolean.TRUE, "Yada", getStage(), new Object[] { playlist, false });
populateLeftList();
});
contextMenu.getItems().add(tmp);
contextMenu.getItems().add(rename);
leftlist.setContextMenu(contextMenu);
} else {
MenuItem tmp = new MenuItem("Unfollow");
tmp.setOnAction((ActionEvent event2) -> {
playListService.deletePlaylist(playlist);
playListService.resetAndGetPublicPlaylists();
populateLeftList();
});
contextMenu.getItems().add(tmp);
}
MenuItem offline = new MenuItem("Download to offline");
offline.setOnAction((ActionEvent event2) -> {
Analytics.sendEvent("sidify", "download_playlist");
workQueue.offer(playlist);
});
MenuItem info = new MenuItem("Playlistinfo");
info.setOnAction((ActionEvent event2) -> {
GuiUtils.showDialog("sidifyViewPublicPlaylistInfo.fxml", Boolean.TRUE, "Playlistinfo", getStage(), new Object[] { playlist });
});
MenuItem exportLists = new MenuItem("Export playlist");
exportLists.setOnAction((ActionEvent event2) -> {
GuiUtils.showDialog("sidifyExportPlaylist.fxml", Boolean.TRUE, "Playlistinfo", getStage(), new Object[] { playlist });
});
contextMenu.getItems().add(offline);
contextMenu.getItems().add(info);
contextMenu.getItems().add(exportLists);
leftlist.setContextMenu(contextMenu);
} else {
refreshCurrentSongList(playlist);
}
if (event.getClickCount() == 2) {
activePlaylist = playlist;
if (activePlaylist != null) {
List<PlaylistEntry> songsForPlaylist = playListService.getSongsForPlaylist(activePlaylist);
if (songsForPlaylist.size() > 0) {
if (randomSongs.get() == false) {
clearAndSelect(0);
setActiveSongInList(0);
} else {
randomize();
clearAndSelect(getActiveSongInList());
}
startSwitchSongLoopFromScratch();
}
}
songlist.requestFocus();
}
scrollToTop();
populateLeftList();
}
}
});
songlist.setOnKeyTyped(event -> {
if (!isSearchActive()) {
if (event.getCharacter().length() > 0 && event.getCharacter().charAt(0) == Support.ENTER_KEY) {
setBackgroundplaylistState();
setNewSongPlayingState(false);
startSwitchSongLoopFromScratch();
}
}
});
songlist.setOnMousePressed(event -> {
songlist.setContextMenu(null);
List<PlaylistEntry> selectedItems = songlist.getSelectionModel().getSelectedItems();
if (selectedItems == null) {
return;
}
if (isSearchActive()) {
List<List<ContentEntry>> contentEntries = new ArrayList<>();
for (PlaylistEntry playlistEntry : selectedItems) {
ContentEntryInfo entryInfo = SearchService.getInstance().getSearchItems(playlistEntry.getId(), playlistEntry.getCategory());
List<ContentEntry> entries = entryInfo.getContentEntry().stream().filter(item -> item.getName().toLowerCase().endsWith(".sid")).collect(Collectors.toList());
List<ContentEntry> tmp = new ArrayList<>();
tmp.addAll(entries);
contentEntries.add(tmp);
}
boolean addable = !contentEntries.stream().filter(item -> item.size() > 1).findFirst().isPresent();
if (event.getButton() == MouseButton.SECONDARY || event.isControlDown()) {
if (addable) {
final ContextMenu contextMenu = new ContextMenu();
Menu addToPlaylist = new Menu("Add to playlist");
for (PlaylistInfo plist : playListService.getPlaylistInfo()) {
PlaylistMenuItem mItem = new PlaylistMenuItem(plist);
mItem.setOnAction((ActionEvent event2) -> {
PlaylistMenuItem item = (PlaylistMenuItem) event2.getSource();
if (Support.isPlaylistMine(item.getPlaylist())) {
playListService.addSongs(item.getPlaylist(), selectedItems, contentEntries);
songlist.getSelectionModel().clearSelection();
} else {
GenericMessageDialogController.withErrorProps("Sidify", "You can not add song to public lists!").showAndWait();
}
});
addToPlaylist.getItems().add(mItem);
}
MenuItem mItem = new MenuItem("Add to new playlist");
mItem.setOnAction((ActionEvent event2) -> {
SidifyCreatePlaylistController controller = GuiUtils.showDialog("sidifyCreateNewPlaylist.fxml", Boolean.TRUE, "Create new playlist", getStage(), new Object[] { null, false });
PlaylistInfo newPlaylist = controller.getNewlyCreatedPlayList();
if (newPlaylist != null) {
playListService.addSongs(newPlaylist, selectedItems, contentEntries);
songlist.getSelectionModel().clearSelection();
populateLeftList();
}
});
addToPlaylist.getItems().add(mItem);
contextMenu.getItems().add(addToPlaylist);
songlist.setContextMenu(contextMenu);
} else {
// If we have more than one entry and
// want to add all
final ContextMenu contextMenu = new ContextMenu();
long nofSids = contentEntries.stream().collect(Collectors.summarizingInt(item -> item.size())).getSum();
Menu addToPlaylist = new Menu("Add all (" + nofSids + ") songs to playlist");
for (PlaylistInfo plist : playListService.getPlaylistInfo()) {
ContentEntryInfoMenuItem mItem = new ContentEntryInfoMenuItem(plist.getName(), contentEntries);
mItem.setOnAction((ActionEvent event2) -> {
ContentEntryInfoMenuItem item = (ContentEntryInfoMenuItem) event2.getSource();
playListService.addSongs(plist, selectedItems, item.getContentEntries());
songlist.getSelectionModel().clearSelection();
populateLeftList();
});
addToPlaylist.getItems().add(mItem);
}
contextMenu.getItems().add(addToPlaylist);
MenuItem mItem = new MenuItem("Add to new playlist");
mItem.setOnAction((ActionEvent event2) -> {
SidifyCreatePlaylistController controller = GuiUtils.showDialog("sidifyCreateNewPlaylist.fxml", Boolean.TRUE, "Create new playlist", getStage(), new Object[] { null, false });
PlaylistInfo newPlaylist = controller.getNewlyCreatedPlayList();
ContentEntryInfoMenuItem cmItem = new ContentEntryInfoMenuItem(newPlaylist.getName(), contentEntries);
if (newPlaylist != null) {
playListService.addSongs(newPlaylist, selectedItems, cmItem.getContentEntries());
songlist.getSelectionModel().clearSelection();
populateLeftList();
}
});
addToPlaylist.getItems().add(mItem);
songlist.setContextMenu(contextMenu);
}
} else {
if (event.getClickCount() == 2) {
setBackgroundplaylistState();
try {
if (contentEntries.size() == 1 && contentEntries.get(0).size() == 1) {
setNewSongPlayingState(false);
selectedItems.get(0).setFileId(contentEntries.get(0).get(0).getId());
startSwitchSongLoopFromScratch();
} else {
GuiUtils.showDialog("sidifyViewMultipeSongs.fxml", Boolean.TRUE, "Choose", getStage(), new Object[] { Support.flattenAndEnrichEntries(selectedItems, contentEntries) });
refreshPlaylistIfNeeded(playListService.getPlaylistForSong(selectedItems.get(0)));
populateLeftList();
}
} catch (Exception e) {
LOGGER.error("Unable to play item", e);
}
}
}
} else {
List<List<ContentEntry>> contentEntries = new ArrayList<>();
for (PlaylistEntry playlistEntry : selectedItems) {
List<ContentEntry> tmp = new ArrayList<>();
ContentEntry entry = new ContentEntry();
entry.setFullPlaylistInfo(playlistEntry);
entry.setId(playlistEntry.getFileId());
entry.setName(playlistEntry.getName());
tmp.add(entry);
contentEntries.add(tmp);
}
setBackgroundplaylistState();
if ((event.getButton() == MouseButton.SECONDARY || event.isControlDown()) && !isOffline()) {
final ContextMenu contextMenu = new ContextMenu();
Menu addToPlaylist = new Menu("Add to playlist");
for (PlaylistInfo plist : playListService.getPlaylistInfo()) {
PlaylistMenuItem mItem = new PlaylistMenuItem(plist);
mItem.setOnAction((ActionEvent event2) -> {
PlaylistMenuItem item = (PlaylistMenuItem) event2.getSource();
if (Support.isPlaylistMine(item.getPlaylist())) {
playListService.addSongs(item.getPlaylist(), selectedItems, contentEntries);
PlaylistInfo currentPlaylist = playListService.getPlaylistForSong(selectedItems.get(0));
refreshPlaylistIfNeeded(currentPlaylist);
songlist.getSelectionModel().clearSelection();
} else {
GenericMessageDialogController.withErrorProps("Sidify", "You can not add song to public lists!").showAndWait();
}
});
addToPlaylist.getItems().add(mItem);
}
contextMenu.getItems().add(addToPlaylist);
MenuItem mItem = new MenuItem("Add to new playlist");
mItem.setOnAction((ActionEvent event2) -> {
SidifyCreatePlaylistController controller = GuiUtils.showDialog("sidifyCreateNewPlaylist.fxml", Boolean.TRUE, "Create new playlist", getStage(), new Object[] { null, false });
PlaylistInfo newPlaylist = controller.getNewlyCreatedPlayList();
ContentEntryInfoMenuItem cmItem = new ContentEntryInfoMenuItem(newPlaylist.getName(), contentEntries);
if (newPlaylist != null) {
playListService.addSongs(newPlaylist, selectedItems, cmItem.getContentEntries());
songlist.getSelectionModel().clearSelection();
populateLeftList();
}
});
addToPlaylist.getItems().add(mItem);
if (isPlaylistMine(playListService.getPlaylistForSong(selectedItems.get(0)))) {
PlaylistEntryMenuItem deleteItem = new PlaylistEntryMenuItem("Delete", selectedItems);
deleteItem.setOnAction((ActionEvent event2) -> {
PlaylistEntryMenuItem item = (PlaylistEntryMenuItem) event2.getSource();
PlaylistInfo currentPlaylist = playListService.getPlaylistForSong(item.getPlaylistEntry());
playListService.deleteSongs(currentPlaylist, item.getPlaylistEntries());
songlist.getSelectionModel().clearSelection();
populateLeftList();
refreshPlaylistIfNeeded(currentPlaylist);
});
contextMenu.getItems().add(deleteItem);
}
songlist.setContextMenu(contextMenu);
} else if (event.getClickCount() == 2) {
setNewSongPlayingState(false);
startSwitchSongLoopFromScratch();
populateLeftList();
}
}
});
searchField.setOnKeyReleased((event) -> {
if (event.getCode() == KeyCode.ENTER) {
doSearch(searchField.getText());
}
});
try {
searchPeriod.getSelectionModel().selectedItemProperty().addListener((ObservableValue<? extends SEARCH_PERIOD> observable, SEARCH_PERIOD oldValue, SEARCH_PERIOD newValue) -> doSearch(searchField.getText()));
} catch (Exception e) {
LOGGER.info("Unable to add listener", e);
}
disableSearch();
workQueue = new ArrayBlockingQueue<>(1000);
Executors.newSingleThreadExecutor().execute(() -> {
while (true) {
try {
Object queueItem = workQueue.take();
if (queueItem instanceof PoisonPill) {
break;
} else if (queueItem instanceof PlaylistInfo) {
downloadPlaylistOffline((PlaylistInfo) queueItem, true);
} else if (queueItem instanceof String && ((String) queueItem).equals("checklists")) {
for (PlaylistInfo pInfo : playListService.getPlaylistInfo()) {
if (pInfo.isAvailableOffline()) {
downloadPlaylistOffline(pInfo, false);
}
}
}
} catch (Exception e) {
}
}
});
if (!isOffline()) {
checkOfflineScheduler = Executors.newScheduledThreadPool(1);
checkOfflineScheduler.scheduleAtFixedRate(() -> {
workQueue.offer("checklists");
}, 5, 10, TimeUnit.SECONDS);
}
}
Aggregations