Skip to content

Commit

Permalink
feat: improved search functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDead committed Jan 19, 2025
1 parent 1a3c8d3 commit d408baf
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
Expand Down Expand Up @@ -37,6 +38,16 @@

public final class MainWindowController implements IAudioTimer, TrayIconListener {

@FXML
private TitledPane pneOther;
@FXML
private TitledPane pneRadioFrequencyStatic;
@FXML
private TitledPane pneAudiences;
@FXML
private TitledPane pneOffice;
@FXML
private TitledPane pneNature;
@FXML
private Button btnClearSearch;
@FXML
Expand Down Expand Up @@ -289,7 +300,7 @@ public void run() {
* Method that is invoked to initialize the FXML object
*/
@FXML
public void initialize() {
private void initialize() {
mniTimerEnabled.setOnAction(_ -> {
if (mniTimerEnabled.isSelected()) {
final Properties properties = settingsController.getProperties();
Expand All @@ -310,6 +321,26 @@ public void initialize() {
});
btnClearSearch.setVisible(false);
btnClearSearch.setManaged(false);

pneNature.setExpanded(true);
pneNature.setVisible(true);
pneNature.setManaged(true);

pneOffice.setExpanded(false);
pneOffice.setVisible(true);
pneOffice.setManaged(true);

pneAudiences.setExpanded(false);
pneAudiences.setVisible(true);
pneAudiences.setManaged(true);

pneRadioFrequencyStatic.setExpanded(false);
pneRadioFrequencyStatic.setVisible(true);
pneRadioFrequencyStatic.setManaged(true);

pneOther.setExpanded(false);
pneOther.setVisible(true);
pneOther.setManaged(true);
});
return;
}
Expand All @@ -319,6 +350,62 @@ public void initialize() {
e.setVisible(e.getName().toLowerCase().contains(newValue.trim().toLowerCase()));
e.setManaged(e.isVisible());
});

// Check if there are still active sound panes on pneNature
getSoundPanes(grpNature).stream().filter(Node::isVisible).findFirst().ifPresentOrElse(e -> {
pneNature.setExpanded(true);
pneNature.setVisible(true);
pneNature.setManaged(true);
}, () -> {
pneNature.setExpanded(false);
pneNature.setVisible(false);
pneNature.setManaged(false);
});

// Check if there are still active sound panes on pneOffice
getSoundPanes(grpOffice).stream().filter(Node::isVisible).findFirst().ifPresentOrElse(e -> {
pneOffice.setExpanded(true);
pneOffice.setVisible(true);
pneOffice.setManaged(true);
}, () -> {
pneOffice.setExpanded(false);
pneOffice.setVisible(false);
pneOffice.setManaged(false);
});

// Check if there are still active sound panes on pneAudiences
getSoundPanes(grpAudiences).stream().filter(Node::isVisible).findFirst().ifPresentOrElse(e -> {
pneAudiences.setExpanded(true);
pneAudiences.setVisible(true);
pneAudiences.setManaged(true);
}, () -> {
pneAudiences.setExpanded(false);
pneAudiences.setVisible(false);
pneAudiences.setManaged(false);
});

// Check if there are still active sound panes on pneRadioFrequencyStatic
getSoundPanes(grpRadioFrequencyStatic).stream().filter(Node::isVisible).findFirst().ifPresentOrElse(e -> {
pneRadioFrequencyStatic.setExpanded(true);
pneRadioFrequencyStatic.setVisible(true);
pneRadioFrequencyStatic.setManaged(true);
}, () -> {
pneRadioFrequencyStatic.setExpanded(false);
pneRadioFrequencyStatic.setVisible(false);
pneRadioFrequencyStatic.setManaged(false);
});

// Check if there are still active sound panes on pneOther
getSoundPanes(grpOther).stream().filter(Node::isVisible).findFirst().ifPresentOrElse(e -> {
pneOther.setExpanded(true);
pneOther.setVisible(true);
pneOther.setManaged(true);
}, () -> {
pneOther.setExpanded(false);
pneOther.setVisible(false);
pneOther.setManaged(false);
});

btnClearSearch.setVisible(true);
btnClearSearch.setManaged(true);
});
Expand Down Expand Up @@ -586,7 +673,7 @@ private void updateAction() {
* Method that is called when the search field should be cleared
*/
@FXML
public void clearSearchAction() {
private void clearSearchAction() {
txtSearch.clear();
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/resources/windows/MainWindow.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
<GridPane.margin>
<Insets left="5" right="5" top="10" bottom="10"/>
</GridPane.margin>
<TitledPane text="%Nature">
<TitledPane fx:id="pneNature" text="%Nature">
<GridPane fx:id="grpNature">
<rowConstraints>
<RowConstraints vgrow="ALWAYS"/>
Expand Down Expand Up @@ -251,7 +251,7 @@
image="/images/ocean.png"/>
</GridPane>
</TitledPane>
<TitledPane text="%Office" expanded="false">
<TitledPane fx:id="pneOffice" text="%Office" expanded="false">
<GridPane fx:id="grpOffice">
<rowConstraints>
<RowConstraints vgrow="ALWAYS"/>
Expand Down Expand Up @@ -290,7 +290,7 @@
image="/images/coffee.png"/>
</GridPane>
</TitledPane>
<TitledPane text="%Audiences" expanded="false">
<TitledPane fx:id="pneAudiences" text="%Audiences" expanded="false">
<GridPane fx:id="grpAudiences">
<rowConstraints>
<RowConstraints vgrow="ALWAYS"/>
Expand Down Expand Up @@ -325,7 +325,7 @@
image="/images/rugbyfootball.png"/>
</GridPane>
</TitledPane>
<TitledPane text="%RadioFrequencyStatic" expanded="false">
<TitledPane fx:id="pneRadioFrequencyStatic" text="%RadioFrequencyStatic" expanded="false">
<GridPane fx:id="grpRadioFrequencyStatic">
<GridPane.margin>
<Insets bottom="10"/>
Expand Down Expand Up @@ -355,7 +355,7 @@
image="/images/radio.png"/>
</GridPane>
</TitledPane>
<TitledPane text="%Other" expanded="false">
<TitledPane fx:id="pneOther" text="%Other" expanded="false">
<GridPane fx:id="grpOther">
<GridPane.margin>
<Insets bottom="10"/>
Expand Down

0 comments on commit d408baf

Please sign in to comment.