Fixed a few issues with sorting in Dictionary page
- The alpha sort button now changes correctly.
This commit is contained in:
parent
14e1e52f25
commit
be12adbe53
10 changed files with 57 additions and 16 deletions
|
@ -14,6 +14,8 @@ import javafx.collections.transformation.SortedList;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
|
import javafx.scene.image.Image;
|
||||||
|
import javafx.scene.image.ImageView;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
@ -42,6 +44,8 @@ import uk.ac.aber.cs22120.group20.json.DictionaryEntry;
|
||||||
public class DictionaryController implements Initializable {
|
public class DictionaryController implements Initializable {
|
||||||
public static Stage primaryStage = null;
|
public static Stage primaryStage = null;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private ImageView alphaSort;
|
||||||
@FXML
|
@FXML
|
||||||
private TextField searchBox;
|
private TextField searchBox;
|
||||||
@FXML
|
@FXML
|
||||||
|
@ -56,9 +60,22 @@ public class DictionaryController implements Initializable {
|
||||||
@FXML
|
@FXML
|
||||||
private void switchLangSort() {
|
private void switchLangSort() {
|
||||||
if (table.getSortOrder().contains(english)) {
|
if (table.getSortOrder().contains(english)) {
|
||||||
|
if (welsh.getSortType().equals(TableColumn.SortType.ASCENDING)) {
|
||||||
|
alphaSort.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/sort-alpha-up-50.png"));
|
||||||
|
}
|
||||||
|
else if (welsh.getSortType().equals(TableColumn.SortType.DESCENDING)) {
|
||||||
|
alphaSort.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/sort-alpha-up-reversed-50.png"));
|
||||||
|
}
|
||||||
table.getSortOrder().clear();
|
table.getSortOrder().clear();
|
||||||
table.getSortOrder().add(welsh);
|
table.getSortOrder().add(welsh);
|
||||||
} else if (table.getSortOrder().contains(welsh)) {
|
}
|
||||||
|
else if (table.getSortOrder().contains(welsh)) {
|
||||||
|
if (english.getSortType().equals(TableColumn.SortType.ASCENDING)) {
|
||||||
|
alphaSort.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/sort-alpha-up-50.png"));
|
||||||
|
}
|
||||||
|
else if (english.getSortType().equals(TableColumn.SortType.DESCENDING)) {
|
||||||
|
alphaSort.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/sort-alpha-up-reversed-50.png"));
|
||||||
|
}
|
||||||
table.getSortOrder().clear();
|
table.getSortOrder().clear();
|
||||||
table.getSortOrder().add(english);
|
table.getSortOrder().add(english);
|
||||||
}
|
}
|
||||||
|
@ -70,14 +87,18 @@ public class DictionaryController implements Initializable {
|
||||||
if (table.getSortOrder().contains(english)) {
|
if (table.getSortOrder().contains(english)) {
|
||||||
if (english.getSortType().equals(TableColumn.SortType.ASCENDING)) {
|
if (english.getSortType().equals(TableColumn.SortType.ASCENDING)) {
|
||||||
english.setSortType(TableColumn.SortType.DESCENDING);
|
english.setSortType(TableColumn.SortType.DESCENDING);
|
||||||
|
alphaSort.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/sort-alpha-up-reversed-50.png"));
|
||||||
} else {
|
} else {
|
||||||
english.setSortType(TableColumn.SortType.ASCENDING);
|
english.setSortType(TableColumn.SortType.ASCENDING);
|
||||||
|
alphaSort.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/sort-alpha-up-50.png"));
|
||||||
}
|
}
|
||||||
} else if (table.getSortOrder().contains(welsh)) {
|
} else if (table.getSortOrder().contains(welsh)) {
|
||||||
if (welsh.getSortType().equals(TableColumn.SortType.ASCENDING)) {
|
if (welsh.getSortType().equals(TableColumn.SortType.ASCENDING)) {
|
||||||
welsh.setSortType(TableColumn.SortType.DESCENDING);
|
welsh.setSortType(TableColumn.SortType.DESCENDING);
|
||||||
|
alphaSort.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/sort-alpha-up-reversed-50.png"));
|
||||||
} else {
|
} else {
|
||||||
welsh.setSortType(TableColumn.SortType.ASCENDING);
|
welsh.setSortType(TableColumn.SortType.ASCENDING);
|
||||||
|
alphaSort.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/sort-alpha-up-50.png"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,10 +13,9 @@ import javafx.collections.transformation.FilteredList;
|
||||||
import javafx.collections.transformation.SortedList;
|
import javafx.collections.transformation.SortedList;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
import javafx.scene.control.TableColumn;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.control.TableRow;
|
import javafx.scene.image.Image;
|
||||||
import javafx.scene.control.TableView;
|
import javafx.scene.image.ImageView;
|
||||||
import javafx.scene.control.TextField;
|
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import uk.ac.aber.cs22120.group20.json.DictionaryEntry;
|
import uk.ac.aber.cs22120.group20.json.DictionaryEntry;
|
||||||
|
|
||||||
|
@ -43,6 +42,8 @@ import java.util.ResourceBundle;
|
||||||
public class PracticeListController implements Initializable {
|
public class PracticeListController implements Initializable {
|
||||||
public static Stage primaryStage = null;
|
public static Stage primaryStage = null;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private ImageView alphaSort;
|
||||||
@FXML
|
@FXML
|
||||||
private TextField searchBox;
|
private TextField searchBox;
|
||||||
@FXML
|
@FXML
|
||||||
|
@ -106,23 +107,25 @@ public class PracticeListController implements Initializable {
|
||||||
// welsh.setCellValueFactory(new PropertyValueFactory<DictionaryEntry, String>("welsh"));
|
// welsh.setCellValueFactory(new PropertyValueFactory<DictionaryEntry, String>("welsh"));
|
||||||
// english.setCellValueFactory(new PropertyValueFactory<DictionaryEntry, String>("english"));
|
// english.setCellValueFactory(new PropertyValueFactory<DictionaryEntry, String>("english"));
|
||||||
|
|
||||||
|
table.setPlaceholder(new Label("No practice words found. Please try adding a practice word from the 'Dictionary' page."));
|
||||||
table.setRowFactory(tv -> {
|
table.setRowFactory(tv -> {
|
||||||
TableRow<DictionaryEntry> row = new TableRow<DictionaryEntry>() {
|
TableRow<DictionaryEntry> row = new TableRow<DictionaryEntry>() {
|
||||||
@Override
|
@Override
|
||||||
protected void updateItem(DictionaryEntry dictionaryEntry, boolean b) {
|
protected void updateItem(DictionaryEntry dictionaryEntry, boolean b) {
|
||||||
super.updateItem(dictionaryEntry, b);
|
super.updateItem(dictionaryEntry, b);
|
||||||
if (!isEmpty()) {
|
if (!isEmpty()) {
|
||||||
if (dictionaryEntry.isPracticeWord()) {
|
setStyle(" ");
|
||||||
setStyle("-fx-background-color: gray;");
|
// if (dictionaryEntry.isPracticeWord()) {
|
||||||
} else {
|
// setStyle("-fx-background-color: gray;");
|
||||||
setStyle(" ");
|
// } else {
|
||||||
}
|
// setStyle(" ");
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
row.setOnMouseClicked(mouseEvent -> {
|
row.setOnMouseClicked(mouseEvent -> {
|
||||||
if (mouseEvent.getClickCount() == 1 && (!row.isEmpty())) {
|
if (mouseEvent.getClickCount() == 1 && (!row.isEmpty())) {
|
||||||
for(DictionaryEntry entry : Application.dictionary) {
|
for (DictionaryEntry entry : Application.dictionary) {
|
||||||
if (entry.equals(row.getItem())) {
|
if (entry.equals(row.getItem())) {
|
||||||
entry.setPracticeWord(false);
|
entry.setPracticeWord(false);
|
||||||
list.remove(row.getItem());
|
list.remove(row.getItem());
|
||||||
|
@ -162,9 +165,22 @@ public class PracticeListController implements Initializable {
|
||||||
@FXML
|
@FXML
|
||||||
private void switchLangSort() {
|
private void switchLangSort() {
|
||||||
if (table.getSortOrder().contains(english)) {
|
if (table.getSortOrder().contains(english)) {
|
||||||
|
if (welsh.getSortType().equals(TableColumn.SortType.ASCENDING)) {
|
||||||
|
alphaSort.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/sort-alpha-up-50.png"));
|
||||||
|
}
|
||||||
|
else if (welsh.getSortType().equals(TableColumn.SortType.DESCENDING)) {
|
||||||
|
alphaSort.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/sort-alpha-up-reversed-50.png"));
|
||||||
|
}
|
||||||
table.getSortOrder().clear();
|
table.getSortOrder().clear();
|
||||||
table.getSortOrder().add(welsh);
|
table.getSortOrder().add(welsh);
|
||||||
} else if (table.getSortOrder().contains(welsh)) {
|
}
|
||||||
|
else if (table.getSortOrder().contains(welsh)) {
|
||||||
|
if (english.getSortType().equals(TableColumn.SortType.ASCENDING)) {
|
||||||
|
alphaSort.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/sort-alpha-up-50.png"));
|
||||||
|
}
|
||||||
|
else if (english.getSortType().equals(TableColumn.SortType.DESCENDING)) {
|
||||||
|
alphaSort.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/sort-alpha-up-reversed-50.png"));
|
||||||
|
}
|
||||||
table.getSortOrder().clear();
|
table.getSortOrder().clear();
|
||||||
table.getSortOrder().add(english);
|
table.getSortOrder().add(english);
|
||||||
}
|
}
|
||||||
|
@ -176,14 +192,18 @@ public class PracticeListController implements Initializable {
|
||||||
if (table.getSortOrder().contains(english)) {
|
if (table.getSortOrder().contains(english)) {
|
||||||
if (english.getSortType().equals(TableColumn.SortType.ASCENDING)) {
|
if (english.getSortType().equals(TableColumn.SortType.ASCENDING)) {
|
||||||
english.setSortType(TableColumn.SortType.DESCENDING);
|
english.setSortType(TableColumn.SortType.DESCENDING);
|
||||||
|
alphaSort.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/sort-alpha-up-reversed-50.png"));
|
||||||
} else {
|
} else {
|
||||||
english.setSortType(TableColumn.SortType.ASCENDING);
|
english.setSortType(TableColumn.SortType.ASCENDING);
|
||||||
|
alphaSort.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/sort-alpha-up-50.png"));
|
||||||
}
|
}
|
||||||
} else if (table.getSortOrder().contains(welsh)) {
|
} else if (table.getSortOrder().contains(welsh)) {
|
||||||
if (welsh.getSortType().equals(TableColumn.SortType.ASCENDING)) {
|
if (welsh.getSortType().equals(TableColumn.SortType.ASCENDING)) {
|
||||||
welsh.setSortType(TableColumn.SortType.DESCENDING);
|
welsh.setSortType(TableColumn.SortType.DESCENDING);
|
||||||
|
alphaSort.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/sort-alpha-up-reversed-50.png"));
|
||||||
} else {
|
} else {
|
||||||
welsh.setSortType(TableColumn.SortType.ASCENDING);
|
welsh.setSortType(TableColumn.SortType.ASCENDING);
|
||||||
|
alphaSort.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/sort-alpha-up-50.png"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
</HBox>
|
</HBox>
|
||||||
<HBox alignment="BOTTOM_CENTER" prefHeight="100.0" prefWidth="200.0">
|
<HBox alignment="BOTTOM_CENTER" prefHeight="100.0" prefWidth="200.0">
|
||||||
<children>
|
<children>
|
||||||
<ImageView fitHeight="20.0" fitWidth="20.0" onMouseClicked="#switchAlphaSort" pickOnBounds="true" preserveRatio="true">
|
<ImageView fx:id="alphaSort" fitHeight="20.0" fitWidth="20.0" onMouseClicked="#switchAlphaSort" pickOnBounds="true" preserveRatio="true">
|
||||||
<image>
|
<image>
|
||||||
<Image url="@../../../../../assets/icons/black_icons/50px/sort-alpha-up-50.png" />
|
<Image url="@../../../../../assets/icons/black_icons/50px/sort-alpha-up-50.png" />
|
||||||
</image>
|
</image>
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
</HBox>
|
</HBox>
|
||||||
<HBox alignment="BOTTOM_CENTER" prefHeight="100.0" prefWidth="200.0">
|
<HBox alignment="BOTTOM_CENTER" prefHeight="100.0" prefWidth="200.0">
|
||||||
<children>
|
<children>
|
||||||
<ImageView fitHeight="20.0" fitWidth="20.0" onMouseClicked="#switchAlphaSort" pickOnBounds="true" preserveRatio="true">
|
<ImageView fx:id="alphaSort" fitHeight="20.0" fitWidth="20.0" onMouseClicked="#switchAlphaSort" pickOnBounds="true" preserveRatio="true">
|
||||||
<image>
|
<image>
|
||||||
<Image url="@../../../../../assets/icons/black_icons/50px/sort-alpha-up-50.png" />
|
<Image url="@../../../../../assets/icons/black_icons/50px/sort-alpha-up-50.png" />
|
||||||
</image>
|
</image>
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -35,7 +35,7 @@
|
||||||
</HBox>
|
</HBox>
|
||||||
<HBox alignment="BOTTOM_CENTER" prefHeight="100.0" prefWidth="200.0">
|
<HBox alignment="BOTTOM_CENTER" prefHeight="100.0" prefWidth="200.0">
|
||||||
<children>
|
<children>
|
||||||
<ImageView fitHeight="20.0" fitWidth="20.0" onMouseClicked="#switchAlphaSort" pickOnBounds="true" preserveRatio="true">
|
<ImageView fx:id="alphaSort" fitHeight="20.0" fitWidth="20.0" onMouseClicked="#switchAlphaSort" pickOnBounds="true" preserveRatio="true">
|
||||||
<image>
|
<image>
|
||||||
<Image url="@../../../../../assets/icons/black_icons/50px/sort-alpha-up-50.png" />
|
<Image url="@../../../../../assets/icons/black_icons/50px/sort-alpha-up-50.png" />
|
||||||
</image>
|
</image>
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
</HBox>
|
</HBox>
|
||||||
<HBox alignment="BOTTOM_CENTER" prefHeight="100.0" prefWidth="200.0">
|
<HBox alignment="BOTTOM_CENTER" prefHeight="100.0" prefWidth="200.0">
|
||||||
<children>
|
<children>
|
||||||
<ImageView fitHeight="20.0" fitWidth="20.0" onMouseClicked="#switchAlphaSort" pickOnBounds="true" preserveRatio="true">
|
<ImageView fx:id="alphaSort" fitHeight="20.0" fitWidth="20.0" onMouseClicked="#switchAlphaSort" pickOnBounds="true" preserveRatio="true">
|
||||||
<image>
|
<image>
|
||||||
<Image url="@../../../../../assets/icons/black_icons/50px/sort-alpha-up-50.png" />
|
<Image url="@../../../../../assets/icons/black_icons/50px/sort-alpha-up-50.png" />
|
||||||
</image>
|
</image>
|
||||||
|
|
Reference in a new issue