|
|
@ -10,15 +10,19 @@ import javafx.fxml.FXML; |
|
|
|
import javafx.fxml.FXMLLoader; |
|
|
|
import javafx.fxml.FXMLLoader; |
|
|
|
import javafx.scene.layout.Pane; |
|
|
|
import javafx.scene.layout.Pane; |
|
|
|
import javafx.scene.layout.VBox; |
|
|
|
import javafx.scene.layout.VBox; |
|
|
|
|
|
|
|
import javafx.scene.text.Text; |
|
|
|
import me.lensferno.dogename.data.History; |
|
|
|
import me.lensferno.dogename.data.History; |
|
|
|
import me.lensferno.dogename.utils.DialogMaker; |
|
|
|
import me.lensferno.dogename.utils.DialogMaker; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
|
|
|
|
public class HistoryPaneController extends VBox { |
|
|
|
public class HistoryPaneController extends VBox { |
|
|
|
|
|
|
|
|
|
|
|
public static final ObservableList<String> shownHistoryList = FXCollections.observableArrayList(); |
|
|
|
|
|
|
|
History history; |
|
|
|
History history; |
|
|
|
Pane rootPane; |
|
|
|
|
|
|
|
int pointer = 0; |
|
|
|
public static final ObservableList<String> historyListCollection = FXCollections.observableArrayList(); |
|
|
|
|
|
|
|
private final Pane rootPane; |
|
|
|
|
|
|
|
|
|
|
|
@FXML |
|
|
|
@FXML |
|
|
|
private JFXListView<String> historyList; |
|
|
|
private JFXListView<String> historyList; |
|
|
|
|
|
|
|
|
|
|
@ -31,6 +35,9 @@ public class HistoryPaneController extends VBox { |
|
|
|
@FXML |
|
|
|
@FXML |
|
|
|
private JFXButton nextBtn; |
|
|
|
private JFXButton nextBtn; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@FXML |
|
|
|
|
|
|
|
private Text searchMessage; |
|
|
|
|
|
|
|
|
|
|
|
public HistoryPaneController(History history, Pane rootPane) { |
|
|
|
public HistoryPaneController(History history, Pane rootPane) { |
|
|
|
FXMLLoader loader = new FXMLLoader(getClass().getResource("/me/lensferno/dogename/FXMLs/HistoryPane.fxml")); |
|
|
|
FXMLLoader loader = new FXMLLoader(getClass().getResource("/me/lensferno/dogename/FXMLs/HistoryPane.fxml")); |
|
|
|
loader.setRoot(this); |
|
|
|
loader.setRoot(this); |
|
|
@ -40,82 +47,89 @@ public class HistoryPaneController extends VBox { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
loader.load(); |
|
|
|
loader.load(); |
|
|
|
shownHistoryList.setAll(history.getHistoryList()); |
|
|
|
historyListCollection.setAll(history.getHistoryList()); |
|
|
|
historyList.setItems(shownHistoryList); |
|
|
|
historyList.setItems(historyListCollection); |
|
|
|
searchBar.textProperty().addListener((observable, oldValue, newValue) -> pointer = 0); |
|
|
|
searchBar.textProperty().addListener((observable, oldValue, newValue) -> searchIndex = 0); |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void pointOutSearchResult(int pointer) { |
|
|
|
private void pointOutSearchResult(int pointer) { |
|
|
|
|
|
|
|
historyList.scrollTo(pointer); |
|
|
|
historyList.getSelectionModel().select(pointer); |
|
|
|
historyList.getSelectionModel().select(pointer); |
|
|
|
|
|
|
|
historyList.getFocusModel().focus(pointer); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int searchIndex = 0; |
|
|
|
|
|
|
|
|
|
|
|
@FXML |
|
|
|
@FXML |
|
|
|
void upSearch(ActionEvent event) { |
|
|
|
void upSearch(ActionEvent event) { |
|
|
|
|
|
|
|
searchMessage.textProperty().set(""); |
|
|
|
|
|
|
|
|
|
|
|
String searchText = searchBar.getText(); |
|
|
|
String searchText = searchBar.getText(); |
|
|
|
String[] historyArrayList = history.getHistoryList().toArray(new String[0]); |
|
|
|
if (searchText.isEmpty()) { |
|
|
|
|
|
|
|
|
|
|
|
if (historyArrayList.length == 0) { |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (pointer > historyArrayList.length - 1 || pointer < 0) { |
|
|
|
ArrayList<String> historyArrayList = history.getHistoryList(); |
|
|
|
pointer = historyArrayList.length - 1; |
|
|
|
if (historyArrayList.isEmpty()) { |
|
|
|
} |
|
|
|
searchIndex = 0; |
|
|
|
|
|
|
|
|
|
|
|
while (!historyArrayList[pointer].contains(searchText)) { |
|
|
|
|
|
|
|
pointer--; |
|
|
|
|
|
|
|
if (pointer < 0) { |
|
|
|
|
|
|
|
pointer = historyArrayList.length - 1; |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 逐个查找,直到searchIndex == 0
|
|
|
|
|
|
|
|
while (searchIndex > 0 && !historyArrayList.get(searchIndex).contains(searchText)) { |
|
|
|
|
|
|
|
searchIndex--; |
|
|
|
} |
|
|
|
} |
|
|
|
pointOutSearchResult(pointer); |
|
|
|
|
|
|
|
pointer--; |
|
|
|
|
|
|
|
if (pointer < 0) { |
|
|
|
|
|
|
|
pointer = historyArrayList.length - 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pointOutSearchResult(searchIndex); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 上移索引,避免原地停留
|
|
|
|
|
|
|
|
searchIndex--; |
|
|
|
|
|
|
|
if (searchIndex < 0) { |
|
|
|
|
|
|
|
searchIndex = historyArrayList.size() - 1; |
|
|
|
|
|
|
|
searchMessage.textProperty().set("到达列表开头,再次点击将从列表尾部重新搜索"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@FXML |
|
|
|
@FXML |
|
|
|
void downSearch(ActionEvent event) { |
|
|
|
void downSearch(ActionEvent event) { |
|
|
|
|
|
|
|
searchMessage.textProperty().set(""); |
|
|
|
|
|
|
|
|
|
|
|
String searchText = searchBar.getText(); |
|
|
|
String searchText = searchBar.getText(); |
|
|
|
String[] historyArrayList = history.getHistoryList().toArray(new String[0]); |
|
|
|
if (searchText.isEmpty()) { |
|
|
|
|
|
|
|
|
|
|
|
if (historyArrayList.length == 0) { |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (pointer > historyArrayList.length - 1 || pointer < 0) { |
|
|
|
ArrayList<String> historyList = history.getHistoryList(); |
|
|
|
pointer = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (!historyArrayList[pointer].contains(searchText)) { |
|
|
|
if (historyList.isEmpty()) { |
|
|
|
pointer++; |
|
|
|
searchIndex = 0; |
|
|
|
if (pointer < historyArrayList.length - 1) { |
|
|
|
|
|
|
|
pointer = 0; |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
pointOutSearchResult(pointer); |
|
|
|
// 逐个查找,直到最后一个元素
|
|
|
|
pointer++; |
|
|
|
while (searchIndex < historyList.size() - 1 && !historyList.get(searchIndex).contains(searchText)) { |
|
|
|
if (pointer < historyArrayList.length - 1) { |
|
|
|
searchIndex++; |
|
|
|
pointer = 0; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pointOutSearchResult(searchIndex); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 下移索引,避免原地停留
|
|
|
|
|
|
|
|
searchIndex++; |
|
|
|
|
|
|
|
if (searchIndex >= historyList.size()) { |
|
|
|
|
|
|
|
searchIndex = 0; |
|
|
|
|
|
|
|
searchMessage.textProperty().set("到达列表尾部,再次点击将返回列表开头重新搜索"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@FXML |
|
|
|
@FXML |
|
|
|
void clearHistory() { |
|
|
|
void clearHistory() { |
|
|
|
new DialogMaker(rootPane).createDialogWithOKAndCancel("且慢!", "真的要清除全部历史记录吗?", (e) -> { |
|
|
|
new DialogMaker(rootPane).createDialogWithOKAndCancel("且慢!", "真的要清除全部历史记录吗?", (e) -> { |
|
|
|
this.history.clearHistory(); |
|
|
|
this.history.clearHistory(); |
|
|
|
pointer = 0; |
|
|
|
historyListCollection.clear(); |
|
|
|
|
|
|
|
searchIndex = 0; |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|