Skip to content

Commit

Permalink
Replace EDITION with TAGS tag in new song wizard (#68)
Browse files Browse the repository at this point in the history
* Refactor code

* Add TAGS tag to New song wizard

* Remove EDITION tag from new song wizard
  • Loading branch information
Nianna authored Oct 12, 2024
1 parent 8a33796 commit 896decf
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public void changeRowVisibility(int index, boolean visible) {
getRowConstraints(index).setMaxHeight(visible ? Region.USE_COMPUTED_SIZE : 0);
}

public void hideRowWith(Node node) {
changeRowVisibility(getChildRowIndex(node), false);
}

public int getMaxRowIndex() {
return getChildren().stream().map(this::getChildRowIndex).max(Integer::compare).orElse(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.github.nianna.karedi.I18N;
import com.github.nianna.karedi.Settings;
import com.github.nianna.karedi.control.ManageableGridPane;
import com.github.nianna.karedi.control.NonNegativeIntegerTextField;
import com.github.nianna.karedi.song.tag.FormatSpecification;
import com.github.nianna.karedi.song.tag.Tag;
Expand All @@ -25,6 +26,8 @@

public class AddSongInfoDialog extends Dialog<List<Tag>> {

@FXML
private ManageableGridPane gridPane;
@FXML
private NonNegativeIntegerTextField gapField;
@FXML
Expand All @@ -36,7 +39,7 @@ public class AddSongInfoDialog extends Dialog<List<Tag>> {
@FXML
private TextField genreField;
@FXML
private TextField editionField;
private TextField tagsField;

private final FormatSpecification formatSpecification;

Expand Down Expand Up @@ -65,12 +68,17 @@ public AddSongInfoDialog(FormatSpecification formatSpecification) {
private void initialize() {
addSuggestions(languageField, TagKey.LANGUAGE);
addSuggestions(genreField, TagKey.GENRE);
addSuggestions(tagsField, TagKey.TAGS);

gapField.setOnScroll(NumericNodeUtils.createUpdateIntValueOnScrollHandler(
gapField::getValue, gapField::setValueIfLegal));
yearField.setOnScroll(NumericNodeUtils.createUpdateIntValueOnScrollHandler(
yearField::getValue, yearField::setValueIfLegal));

if (!FormatSpecification.supports(formatSpecification, TagKey.TAGS)) {
gridPane.hideRowWith(tagsField);
}

Platform.runLater(() -> {
registerValidators();
validationSupport.initInitialDecoration();
Expand All @@ -88,12 +96,16 @@ private void addSuggestions(TextField field, TagKey key) {
}

private void registerValidators() {
validationSupport.registerValidator(gapField, TagValueValidators.forKey(TagKey.GAP));
validationSupport.registerValidator(yearField, TagValueValidators.forKey(TagKey.YEAR));
validationSupport.registerValidator(languageField, TagValueValidators.forKey(TagKey.LANGUAGE));
validationSupport.registerValidator(creatorField, TagValueValidators.forKey(TagKey.CREATOR));
validationSupport.registerValidator(genreField, TagValueValidators.forKey(TagKey.GENRE));
validationSupport.registerValidator(editionField, TagValueValidators.forKey(TagKey.EDITION));
registerValidator(gapField, TagKey.GAP);
registerValidator(yearField, TagKey.YEAR);
registerValidator(languageField, TagKey.LANGUAGE);
registerValidator(creatorField, TagKey.CREATOR);
registerValidator(genreField, TagKey.GENRE);
registerValidator(tagsField, TagKey.TAGS);
}

private void registerValidator(Control control, TagKey key) {
validationSupport.registerValidator(control, TagValueValidators.forKey(key));
}

private List<Tag> generateListOfValidTags() {
Expand All @@ -106,8 +118,8 @@ private List<Tag> generateListOfValidTags() {
addTag(TagKey.YEAR, yearField, invalidFields).ifPresent(list::add);
addTag(TagKey.LANGUAGE, languageField, invalidFields).ifPresent(list::add);
addTag(TagKey.CREATOR, creatorField, invalidFields).ifPresent(list::add);
addTag(TagKey.EDITION, editionField, invalidFields).ifPresent(list::add);
addTag(TagKey.GENRE, genreField, invalidFields).ifPresent(list::add);
addTag(TagKey.TAGS, tagsField, invalidFields).ifPresent(list::add);
return list;
}

Expand Down
26 changes: 13 additions & 13 deletions src/main/resources/fxml/AddSongInfoDialogPaneLayout.fxml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- <?import org.controlsfx.glyphfont.*?> -->

<?import com.github.nianna.karedi.control.ManageableGridPane?>
<?import com.github.nianna.karedi.control.NonNegativeIntegerTextField?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.DialogPane?>
<?import javafx.scene.control.Label?>
Expand All @@ -9,14 +13,10 @@
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import com.github.nianna.karedi.control.NonNegativeIntegerTextField?>

<!-- <?import org.controlsfx.glyphfont.*?> -->

<fx:root type="javafx.scene.control.DialogPane" xmlns="http://javafx.com/javafx/8.0.60"
xmlns:fx="http://javafx.com/fxml/1">
xmlns:fx="http://javafx.com/fxml/1">
<content>
<GridPane fx:id="gridPane" hgap="10.0" vgap="10.0">
<ManageableGridPane fx:id="gridPane" hgap="10.0" vgap="10.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" />
<ColumnConstraints hgrow="SOMETIMES" prefWidth="200.0" />
Expand All @@ -35,8 +35,7 @@
vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0"
vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0"
vgrow="SOMETIMES" />
<RowConstraints prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="GAP" GridPane.columnIndex="0">
Expand Down Expand Up @@ -79,17 +78,18 @@
</Label>
<TextField fx:id="genreField" GridPane.columnIndex="1"
GridPane.rowIndex="5" />
<Label text="EDITION" GridPane.rowIndex="6">

<Label text="TAGS" GridPane.rowIndex="6">
<tooltip>
<Tooltip text="%tag.edition.tooltip" />
<Tooltip text="%tag.tags.tooltip" />
</tooltip>
</Label>
<TextField fx:id="editionField" GridPane.columnIndex="1"
GridPane.rowIndex="6" />
<TextField fx:id="tagsField" GridPane.columnIndex="1"
GridPane.rowIndex="6" />
</children>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
</GridPane>
</ManageableGridPane>
</content>
</fx:root>
2 changes: 1 addition & 1 deletion src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ tag.creator.tooltip=The nick of the creator of this txt file (presumably yours)
tag.language.tooltip=The dominant language of the song
tag.year.tooltip=The year in which this version of the song was released for the first time
tag.genre.tooltip=The song''s genre
tag.edition.tooltip=The edition of the song
tag.tags.tooltip=Any reasonable keyword for this song (like topic or mood)
dialog.delete_audio.title=Delete Audio
dialog.delete_audio.header=Are you sure you want to delete the following audio file?
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/messages_en_GB.properties
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ tag.creator.tooltip=The nick of the creator of this txt file (presumably yours)
tag.language.tooltip=The dominant language of the song
tag.year.tooltip=The year in which this version of the song was released for the first time
tag.genre.tooltip=The song''s genre
tag.edition.tooltip=The edition of the song
tag.tags.tooltip=Any reasonable keyword for this song (like topic or mood)
dialog.delete_audio.title=Delete Audio
dialog.delete_audio.header=Are you sure you want to delete the following audio file?
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/messages_pl_PL.properties
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ tag.creator.tooltip=Nick tw
tag.language.tooltip=J\u0119zyk przewa\u017Caj\u0105cy w tej piosence
tag.year.tooltip=Rok, w którym piosenka zosta\u0142a wydana po raz pierwszy
tag.genre.tooltip=Gatunek muzyczny
tag.edition.tooltip=Edycja
tag.tags.tooltip=Lista tagów przydatnych przy wyszukiwaniu piosenki

dialog.delete_audio.title=Usu\u0144 plik audio
dialog.delete_audio.header=Czy jeste\u015B pewien, \u017Ce chcesz usun\u0105\u0107 ten plik audio?
Expand Down

0 comments on commit 896decf

Please sign in to comment.