Пример #1
1
 @FXML
 void loadSelectedPlaylist() {
   Playlist p = (Playlist) playlistsView.getSelectionModel().getSelectedItem();
   if (p == null) return;
   tracksView.setPlaceholder(offlinePlaceHolder);
   Platform.runLater(
       () -> {
         List<Track> tracks = p.getTracks();
         tracksView.getItems().clear();
         for (int i = tracks.size() - 1; i >= 0; i--) {
           tracksView.getItems().add(tracks.get(i));
         }
         if (findTrack) {
           Platform.runLater(
               () -> {
                 tracksView.getSelectionModel().select(currentTrack);
                 tracksView.scrollTo(currentTrack);
                 tracksView.requestFocus();
                 findTrack = false;
               });
         } else {
           if (tracksView.getItems().size() > 0) {
             tracksView.scrollTo(0);
           }
         }
       });
 }
 // TODO try to use a binding
 private void updateSkills() {
   skillsTableView.getItems().clear();
   Official selectedMember = officialsFilteredTableView.getSelectionModel().getSelectedItem();
   if (selectedMember != null) {
     skillsTableView.getItems().addAll(selectedMember.getSkillLevels().values());
     Collections.sort(
         skillsTableView.getItems(),
         new Comparator<SkillLevel>() {
           @Override
           public int compare(SkillLevel arg0, SkillLevel arg1) {
             return arg0.getSkill().getName().compareTo(arg1.getSkill().getName());
           }
         });
   }
 }
  private void initializeFilteredPersonnelTableView() {
    personnelNameColumn.setCellValueFactory(new PropertyValueFactory<Official, String>("name"));
    personnelRankColumn.setCellValueFactory(
        new Callback<TableColumn.CellDataFeatures<Official, String>, ObservableValue<String>>() {
          @Override
          public ObservableValue<String> call(CellDataFeatures<Official, String> arg0) {
            final Official official = arg0.getValue();
            final StringExpression concat =
                Bindings.selectString(official.rankProperty(), "designation");
            return concat;
          }
        });
    Bindings.bindContent(officialsFilteredTableView.getItems(), officialFilteredList);
    gameData
        .getOfficials()
        .addListener(
            new ListChangeListener<Official>() {
              @Override
              public void onChanged(Change<? extends Official> arg0) {
                updateOfficialFiltersResult();
              }
            });

    // TODO initialize assignOfficialMenuItem to be sure that it's not
    // enable if not correct values are selected
  }
Пример #4
0
 void addToPlaylist(List<File> files, Playlist p) {
   if (interfaceDisabled) return;
   new Thread(
           () -> {
             setInterfaceDisabled(true);
             int total = files.size();
             AtomicInteger current = new AtomicInteger(0);
             Cache.pushToPlaylist(
                 files,
                 p,
                 (Track t) -> {
                   Platform.runLater(
                       () -> {
                         infoLabel.setText(
                             String.format(
                                 res.getString("processed"),
                                 current.incrementAndGet(),
                                 total,
                                 t.getTitle()));
                         if (p == getSelectedPlaylist()) {
                           tracksView.getItems().remove(t);
                           tracksView.getItems().add(0, t);
                         }
                       });
                 });
             setInterfaceDisabled(false);
           })
       .start();
   if (p == getSelectedPlaylist()) {
     Platform.runLater(
         () -> {
           loadSelectedPlaylist();
         });
   }
 }
 private void deleteSelectedSkillFilter() {
   SkillFilter selectedItem = skillFiltersTableView.getSelectionModel().getSelectedItem();
   if (selectedItem != null) {
     skillFiltersTableView.getItems().remove(selectedItem);
     skillFiltersTableView.getSelectionModel().clearSelection();
     updateOfficialFiltersResult();
   }
 }
Пример #6
0
 void menuAddToPlaylist() {
   Track t = getSelectedTrack();
   if (t == null) {
     return;
   }
   ChoiceDialog<Playlist> dialog = playlistSelectionDialog(playlistsView.getItems());
   Optional<Playlist> result = dialog.showAndWait();
   result.ifPresent(playlist -> addToPlaylist(t, playlist));
 }
Пример #7
0
 @FXML
 void search() {
   searching = true;
   new Thread(
           () -> {
             List<Track> tracks = Cache.search(searchText.getText());
             tracksView.setPlaceholder(searchPlaceholder);
             Platform.runLater(
                 () -> {
                   if (tracksView.getItems().size() > 0) {
                     tracksView.scrollTo(0);
                   }
                   tracksView.getItems().clear();
                   tracksView.getItems().addAll(tracks.toArray());
                 });
           })
       .start();
 }
Пример #8
0
 void playRandom() {
   List<Track> tracks = tracksView.getItems();
   Random random = new Random();
   int size = tracks.size();
   int r = random.nextInt(size - 1);
   tracksView.getSelectionModel().select(r);
   tracksView.scrollTo(tracksView.getSelectionModel().getSelectedIndex());
   Track nextTrack = (Track) tracksView.getSelectionModel().getSelectedItem();
   playTrack(nextTrack);
 }
Пример #9
0
 void playNext() {
   List<Track> tracks = tracksView.getItems();
   int selected = tracksView.getSelectionModel().getSelectedIndex();
   int next = selected + 1;
   if (next >= tracks.size()) {
     next = 0;
   }
   tracksView.getSelectionModel().select(next);
   tracksView.scrollTo(tracksView.getSelectionModel().getSelectedIndex());
   Track nextTrack = (Track) tracksView.getSelectionModel().getSelectedItem();
   playTrack(nextTrack);
 }
  public void setFddObjectModel(FddObjectModel fddObjectModel) {
    logger.entry();
    if (fddObjectModel != null) {
      fddObjectModel
          .getInteractionClasses()
          .values()
          .stream()
          .forEach(
              (value) -> {
                interactions.add(new InteractionState(value));
              });
      InteractionTableView.setItems(interactions);
      interactions.forEach(
          (interaction) -> {
            interaction
                .onProperty()
                .addListener(
                    (observable, oldValue, newValue) -> {
                      if (!newValue) {
                        cb.setSelected(false);
                      } else if (interactions.stream().allMatch(a -> a.isOn())) {
                        cb.setSelected(true);
                      }
                    });
          });
      InteractionTableColumn.setCellValueFactory(new PropertyValueFactory<>("interactionName"));
      CheckTableColumn.setCellValueFactory(
          new Callback<
              TableColumn.CellDataFeatures<InteractionState, Boolean>, ObservableValue<Boolean>>() {
            @Override
            public ObservableValue<Boolean> call(
                TableColumn.CellDataFeatures<InteractionState, Boolean> param) {
              return param.getValue().onProperty();
            }
          });

      CheckTableColumn.setCellFactory(CheckBoxTableCell.forTableColumn(CheckTableColumn));
      cb.setUserData(CheckTableColumn);
      cb.setOnAction(
          (ActionEvent event) -> {
            CheckBox cb1 = (CheckBox) event.getSource();
            TableColumn tc = (TableColumn) cb1.getUserData();
            InteractionTableView.getItems()
                .stream()
                .forEach(
                    (item) -> {
                      item.setOn(cb1.isSelected());
                    });
          });
      CheckTableColumn.setGraphic(cb);
    }
    logger.exit();
  }
Пример #11
0
 void updatePlaylists() {
   if (interfaceDisabled) return;
   final ObservableList<Playlist> items = playlistsView.getItems();
   items.clear();
   items.addAll(Cache.playlists());
   if (Settings.rememberedPlaylistId != null)
     for (Playlist p : items) {
       if (p.getId().equals(Settings.rememberedPlaylistId)) {
         rememberedPlaylist = p;
         break;
       }
     }
 }
 public void addSkillFilter(ActionEvent event) {
   final Skill skill = skillFilterComboBox.getSelectionModel().getSelectedItem();
   SkillFilter skillFilter = new SkillFilter();
   skillFilter.setSkill(skill);
   String minValueText = skillFilterMinValueComponent.getText();
   skillFilter.setMinValue(
       (minValueText == null || minValueText.isEmpty()) ? null : Integer.parseInt(minValueText));
   String maxValueText = skillFilterMaxValueComponent.getText();
   skillFilter.setMaxValue(
       (maxValueText == null || maxValueText.isEmpty()) ? null : Integer.parseInt(maxValueText));
   skillFiltersTableView.getItems().add(skillFilter);
   // We don't need to update #skillFiltersMatcher because of the biding
   // betwen skillFiltersMatcher' matchers and the items of
   // skillFiltersTableView
   updateOfficialFiltersResult();
 }
Пример #13
0
  @FXML
  void refreshPlaylists() {
    infoLabel.setText(res.getString("refreshing"));
    log.info("Refreshing playlists");

    ObservableList<Playlist> items = playlistsView.getItems();
    items.clear();
    items.addAll(Cache.playlists());

    if (Settings.rememberedPlaylistId != null)
      for (Playlist p : items) {
        if (p.getId().equals(Settings.rememberedPlaylistId)) {
          rememberedPlaylist = p;
          break;
        }
      }

    infoLabel.setText(res.getString("playlists_refreshed"));
    log.info("Playlists refreshed");
  }
Пример #14
0
  /**
   * Create the active column, which holds the activity state and also creates a callback to the
   * string property behind it.
   */
  private void setUpActiveColumn(TableView<FilterInput> tableView) {
    // Set up active column
    final TableColumn<FilterInput, Boolean> activeColumn = new TableColumn<>("Active");
    activeColumn.setMinWidth(50);
    activeColumn.setPrefWidth(50);
    tableView.getColumns().add(activeColumn);
    activeColumn.setSortable(false);

    activeColumn.setCellFactory(
        CheckBoxTableCell.forTableColumn(
            (Callback<Integer, ObservableValue<Boolean>>)
                param -> {
                  final FilterInput input = tableView.getItems().get(param);
                  input
                      .getActiveProperty()
                      .addListener(
                          l -> {
                            notifyUpdateCommand(input);
                          });
                  return input.getActiveProperty();
                }));
  }
Пример #15
0
 void createOfflinePlaylist() {
   if (interfaceDisabled) return;
   TextInputDialog dialog = new TextInputDialog(res.getString("new_offline_playlist"));
   dialog.setTitle(res.getString("create_new_offline_playlist"));
   dialog.setHeaderText(res.getString("create_new_playlist"));
   dialog.setContentText(res.getString("enter_playlist_name"));
   dialog.getDialogPane().getStylesheets().add("/styles/dialogs.css");
   ((Stage) dialog.getDialogPane().getScene().getWindow()).getIcons().addAll(logoImages);
   Optional<String> result = dialog.showAndWait();
   result.ifPresent(
       title -> {
         Platform.runLater(
             () -> {
               Playlist newPlaylist = Cache.createPlaylist(title);
               Platform.runLater(
                   () -> {
                     playlistsView.getItems().add(newPlaylist);
                     playlistsView.getSelectionModel().select(newPlaylist);
                   });
             });
       });
 }
Пример #16
0
  /**
   * Sets up the entire TableView with all its functionalities.
   *
   * @return The created TableView.
   */
  private TableView<FilterInput> setUpTableView() {
    // Set up table view
    final TableView<FilterInput> tableView = new TableView<>();
    tableView.setEditable(true);
    tableView.setMinWidth(522);
    tableView.setMinHeight(280);

    // Set up columns
    setUpFilterColumn(tableView);
    setUpTypeColumn(tableView);
    setUpOriginColumn(tableView);
    setUpColorColumn(tableView);
    setUpPriorityColumn(tableView);
    setUpLegalityColumn(tableView);
    setUpActiveColumn(tableView);

    // Insert data from database into table
    tableView.setItems(data);

    // Set select/deselect on mouse click
    tableView.setRowFactory(
        tableViewLambda -> {
          final TableRow<FilterInput> row = new TableRow<>();
          row.addEventFilter(
              MouseEvent.MOUSE_PRESSED,
              event -> {
                final int index = row.getIndex();
                if (index >= 0
                    && index < tableView.getItems().size()
                    && tableView.getSelectionModel().isSelected(index)) {
                  tableView.getSelectionModel().clearSelection();
                  event.consume();
                }
              });
          return row;
        });

    return tableView;
  }
Пример #17
0
 void deleteFromOfflinePlaylist(Track t, Playlist p) {
   if (interfaceDisabled) return;
   tracksView.getItems().remove(t);
   Cache.deleteFromPlaylist(t, p);
 }
  private void initializeSkillFilterTab() {
    skillFilterComboBox.getItems().addAll(skills);
    PropertyListCellFactory<Skill> propertyListCellFactory =
        new PropertyListCellFactory<>("name", null);
    skillFilterComboBox.setButtonCell(
        new ListCell<Skill>() {
          @Override
          protected void updateItem(Skill arg0, boolean arg1) {
            super.updateItem(arg0, arg1);
            if (arg1 || arg0 == null) {
              this.setText(null);
            } else {
              this.setText(arg0.getName());
            }
          }
        });
    skillFilterComboBox.setCellFactory(propertyListCellFactory);
    skillFiltersNameColumn.setCellValueFactory(
        new Callback<CellDataFeatures<SkillFilter, String>, ObservableValue<String>>() {
          @Override
          public ObservableValue<String> call(CellDataFeatures<SkillFilter, String> arg0) {
            return Bindings.selectString(arg0.getValue().skillProperty(), "name");
          }
        });

    skillFilterMinValueColumn.setCellValueFactory(
        new PropertyValueFactory<SkillFilter, Integer>("minValue"));
    skillFilterMaxValueColumn.setCellValueFactory(
        new PropertyValueFactory<SkillFilter, Integer>("maxValue"));
    skillFiltersTableView
        .getItems()
        .addListener(
            new ListChangeListener<SkillFilter>() {
              @Override
              public void onChanged(Change<? extends SkillFilter> arg0) {
                while (arg0.next()) {
                  for (SkillFilter skillFilter : arg0.getAddedSubList()) {
                    final Skill skill = skillFilter.getSkill();
                    TableColumn<Official, Number> skillColumn = new TableColumn<>(skill.getName());
                    skillColumn.setCellValueFactory(
                        new Callback<
                            CellDataFeatures<Official, Number>, ObservableValue<Number>>() {
                          @Override
                          public ObservableValue<Number> call(
                              CellDataFeatures<Official, Number> arg0) {
                            Official official = arg0.getValue();
                            IntegerBinding selectInteger =
                                Bindings.selectInteger(
                                    official.skillLevelsProperty().valueAt(skill), "level");
                            selectInteger.addListener(
                                new ChangeListener<Number>() {
                                  @Override
                                  public void changed(
                                      ObservableValue<? extends Number> arg0,
                                      Number arg1,
                                      Number arg2) {
                                    updateOfficialFiltersResult();
                                  }
                                });
                            return selectInteger;
                          }
                        });
                    officialsFilteredTableView.getColumns().add(skillColumn);
                    skillFiltersColumn.put(skill, skillColumn);
                  }

                  for (SkillFilter skillFilter : arg0.getRemoved()) {
                    final Skill skill = skillFilter.getSkill();
                    TableColumn<Official, Number> column = skillFiltersColumn.remove(skill);

                    if (column != null) {
                      officialsFilteredTableView.getColumns().remove(column);
                    }
                  }
                }
              }
            });
    Bindings.bindContent(skillFiltersMatcher.getMatchers(), skillFiltersTableView.getItems());
  }
Пример #19
0
  @Override
  public void initialize(URL location, ResourceBundle resources) {
    AppController.instance = this;
    this.res = resources;

    ObservableList<String> modeItems =
        FXCollections.observableArrayList(
            Settings.MODE_NEXT, Settings.MODE_RANDOM, Settings.MODE_SAME);
    modeList.setItems(modeItems);
    modeList.getSelectionModel().select(Settings.currentMode);
    modeList
        .valueProperty()
        .addListener(
            (ObservableValue ov, Object oldVal, Object newVal) -> {
              Settings.currentMode = (String) newVal;
            });

    setupPlaylistsView();
    setupPlaylistsContextMenu();

    setupTracksView();

    tracksView.setContextMenu(tracksContextMenu);
    tracksView.setOnContextMenuRequested(
        (ContextMenuEvent evt) -> {
          setupTracksContextMenu();
          evt.consume();
        });
    tracksView
        .getSelectionModel()
        .selectedItemProperty()
        .addListener(
            (ObservableValue observable, Object oldValue, Object newValue) -> {
              Settings.lastTrackId = newValue != null ? ((Track) newValue).getId() : null;
            });

    playlistsView
        .getSelectionModel()
        .selectedItemProperty()
        .addListener(
            (ObservableValue observable, Object oldValue, Object newValue) -> {
              loadSelectedPlaylist();
              Settings.lastPlaylistId = newValue != null ? ((Playlist) newValue).getId() : null;
              searching = false;
              searchText.setText(StringUtils.EMPTY);
            });

    volumeSlider.setCursor(Cursor.HAND);
    volumeSlider
        .valueProperty()
        .addListener(
            (ObservableValue<? extends Number> ov, Number oldVal, Number newVal) -> {
              if (player != null) {
                player.setVolume(newVal.doubleValue());
              }
              Settings.currentVolume = newVal.doubleValue();
              volumeLabel.setText(
                  String.valueOf((int) Math.ceil(newVal.doubleValue() * 100)) + "%");
            });
    volumeSlider.setValue(Settings.currentVolume);

    imagePlay = new ImageView(new Image(getClass().getResourceAsStream("/images/button_play.png")));
    imagePlay.setScaleX(0.40);
    imagePlay.setScaleY(0.40);
    imagePause =
        new ImageView(new Image(getClass().getResourceAsStream("/images/button_pause.png")));
    imagePause.setScaleX(0.5);
    imagePause.setScaleY(0.5);
    imageSettings =
        new ImageView(new Image(getClass().getResourceAsStream("/images/settings.png")));
    imageSettings.setScaleX(0.5);
    imageSettings.setScaleY(0.5);
    imageUpdate = new ImageView(new Image(getClass().getResourceAsStream("/images/refresh.png")));
    imageUpdate.setScaleX(0.5);
    imageUpdate.setScaleY(0.5);
    imageAdd = new ImageView(new Image(getClass().getResourceAsStream("/images/add.png")));
    imageAdd.setScaleX(0.5);
    imageAdd.setScaleY(0.5);
    imageRename = new ImageView(new Image(getClass().getResourceAsStream("/images/rename.png")));
    imageRename.setScaleX(0.5);
    imageRename.setScaleY(0.5);
    imageDelete = new ImageView(new Image(getClass().getResourceAsStream("/images/delete.png")));
    imageDelete.setScaleX(0.5);
    imageDelete.setScaleY(0.5);

    stateButton.setGraphic(imagePlay);
    settingsButton.setGraphic(imageSettings);
    refreshButton.setGraphic(imageUpdate);
    refreshButton.setTooltip(new Tooltip(res.getString("tooltip_sync")));

    addButton.setGraphic(imageAdd);
    addButton.setOnAction((evt) -> createOfflinePlaylist());
    addButton.setTooltip(new Tooltip(res.getString("tooltip_add_offline")));
    renameButton.setGraphic(imageRename);
    renameButton.setOnAction(evt -> renamePlaylist());
    renameButton.setTooltip(new Tooltip(res.getString("rename_playlist")));
    deleteButton.setGraphic(imageDelete);
    deleteButton.setOnAction(evt -> deletePlaylist());
    deleteButton.setTooltip(new Tooltip(res.getString("delete_playlist")));

    loadProgressBar.setCursor(Cursor.HAND);
    volumeSlider.setCursor(Cursor.HAND);
    updatePlaylists();
    if (Settings.lastPlaylistId != null) {
      currentPlaylist =
          ((ObservableList<Playlist>) playlistsView.getItems())
              .stream()
              .filter((playlist) -> playlist.getId().equals(Settings.lastPlaylistId))
              .findFirst()
              .orElse(null);
      playlistsView.getSelectionModel().select(currentPlaylist);
      playlistsView.scrollTo(currentPlaylist);
      Platform.runLater(
          () -> {
            if (Settings.lastTrackId != null) {
              currentTrack =
                  ((ObservableList<Track>) tracksView.getItems())
                      .stream()
                      .filter((track) -> track.getId().equals(Settings.lastTrackId))
                      .findFirst()
                      .orElse(null);
              tracksView.getSelectionModel().select(currentTrack);
              tracksView.scrollTo(currentTrack);
            }
          });
    }
    new Timer()
        .scheduleAtFixedRate(
            new TimerTask() {
              @Override
              public void run() {
                updatePlayProgress();
              }
            },
            100,
            100);
    setupTracksContextMenu();

    setupShortcuts();

    Platform.runLater(
        () -> {
          tracksView.requestFocus();
        });
  }