名单列表可多选删除

main
lensfrex 3 years ago
parent 347f481879
commit 0fd9a6dfcb
Signed by: lensfrex
GPG Key ID: 0F69A0A2FBEE98A0
  1. 28
      Dogename/src/main/java/me/lensferno/dogename/controllers/NameManagerPaneController.java
  2. 27
      Dogename/src/main/java/me/lensferno/dogename/data/Data.java

@ -10,6 +10,7 @@ import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Parent; import javafx.scene.Parent;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.SelectionMode;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.stage.FileChooser; import javafx.stage.FileChooser;
@ -54,26 +55,23 @@ public class NameManagerPaneController extends VBox {
shownNameList.setAll(data.getNameList()); shownNameList.setAll(data.getNameList());
this.nameList.setItems(shownNameList); this.nameList.setItems(shownNameList);
this.nameList.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
this.ocrTool = ocrTool; this.ocrTool = ocrTool;
} }
@FXML @FXML
void deleteName(ActionEvent event) { void deleteName(ActionEvent event) {
new DialogMaker(rootPane).createDialogWithOKAndCancel( new DialogMaker(rootPane).createDialogWithOKAndCancel(
"问一下", "问一下",
"真的要这个名字吗?该操作无法撤销,除非您已经备份了名单。", "真的要这个(些)名字吗?该操作无法撤销,除非您已经备份了名单。",
e -> { e -> {
String deletedName = nameList.getSelectionModel().getSelectedItems().get(0); String[] deletedNames = nameList.getSelectionModel().getSelectedItems().toArray(new String[0]);
for (String deletedName : deletedNames) {
data.delete(deletedName); data.delete(deletedName);
shownNameList.remove(deletedName); shownNameList.remove(deletedName);
}
data.saveToFile();
System.gc();
}); });
} }
@FXML @FXML
@ -82,12 +80,9 @@ public class NameManagerPaneController extends VBox {
"问一下", "问一下",
"真的要删掉所有名字吗?该操作无法撤销,除非您已经备份了名单。", "真的要删掉所有名字吗?该操作无法撤销,除非您已经备份了名单。",
e -> { e -> {
//delete all name
data.deleteAllName(); data.deleteAllName();
shownNameList.setAll(data.getNameList()); shownNameList.setAll(data.getNameList());
data.saveToFile();
}); });
} }
@FXML @FXML
@ -95,7 +90,6 @@ public class NameManagerPaneController extends VBox {
data.makeMass(); data.makeMass();
shownNameList.clear(); shownNameList.clear();
shownNameList.setAll(data.getNameList()); shownNameList.setAll(data.getNameList());
data.saveToFile();
} }
@FXML @FXML
@ -110,7 +104,6 @@ public class NameManagerPaneController extends VBox {
@FXML @FXML
void importNameList(ActionEvent event) { void importNameList(ActionEvent event) {
new DialogMaker(rootPane).createDialogWithOKAndCancel( new DialogMaker(rootPane).createDialogWithOKAndCancel(
"问一下", "问一下",
"导入恢复名单会覆盖当前已有的名单,是否继续?", "导入恢复名单会覆盖当前已有的名单,是否继续?",
@ -126,15 +119,12 @@ public class NameManagerPaneController extends VBox {
data.clearNameIgnoreList(); data.clearNameIgnoreList();
data.clearNumberIgnoreList(); data.clearNumberIgnoreList();
data.saveToFile();
System.gc(); System.gc();
}); });
} }
@FXML @FXML
void addName(ActionEvent event) { void addName(ActionEvent event) {
if (inputName.getText().equals("")) { if (inputName.getText().equals("")) {
new DialogMaker(rootPane).createMessageDialog("诶诶诶~", "输入框怎么是空的呢?"); new DialogMaker(rootPane).createMessageDialog("诶诶诶~", "输入框怎么是空的呢?");
return; return;
@ -145,7 +135,6 @@ public class NameManagerPaneController extends VBox {
shownNameList.clear(); shownNameList.clear();
shownNameList.setAll(data.getNameList()); shownNameList.setAll(data.getNameList());
data.saveToFile();
inputName.clear(); inputName.clear();
System.gc(); System.gc();
} }
@ -173,13 +162,10 @@ public class NameManagerPaneController extends VBox {
OcrPaneController ocrPaneController = fxmlLoader.getController(); OcrPaneController ocrPaneController = fxmlLoader.getController();
ocrPaneController.setMainStage((Stage) inputName.getScene().getWindow()); ocrPaneController.setMainStage((Stage) inputName.getScene().getWindow());
stage.show(); stage.show();
} }
@FXML @FXML
void copyTo(ActionEvent event) { void paste(ActionEvent event) {
inputName.setText(inputName.getText() + Clipboard.getClipboardString()); inputName.setText(inputName.getText() + Clipboard.getClipboardString());
} }
} }

@ -18,7 +18,7 @@ public class Data {
private final SecureRandom secRandom = new SecureRandom(); private final SecureRandom secRandom = new SecureRandom();
private final Random random = new Random(); private final Random random = new Random();
private List<String> nameList; private ArrayList<String> nameList;
private final IgnoreList ignoreList = new IgnoreList(); private final IgnoreList ignoreList = new IgnoreList();
public Data() { public Data() {
@ -30,12 +30,11 @@ public class Data {
saveToFile(); saveToFile();
return; return;
} }
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(dataFile)); ObjectInputStream ois = new ObjectInputStream(new FileInputStream(dataFile));
this.nameList = (ArrayList) ois.readObject(); this.nameList = (ArrayList) ois.readObject();
ois.close();
System.out.println(nameList.size() + " names loaded."); System.out.println(nameList.size() + " names loaded.");
} catch (EOFException EOFe) { } catch (EOFException EOFe) {
nameList = new ArrayList<>(); nameList = new ArrayList<>();
System.out.println("Data file is empty."); System.out.println("Data file is empty.");
@ -46,6 +45,7 @@ public class Data {
System.out.println("Failed to load data file."); System.out.println("Failed to load data file.");
e.printStackTrace(); e.printStackTrace();
} }
ignoreList.readIgnoreList(); ignoreList.readIgnoreList();
} }
@ -64,28 +64,33 @@ public class Data {
System.out.println("error in export namelist: " + e); System.out.println("error in export namelist: " + e);
e.printStackTrace(); e.printStackTrace();
} }
this.saveToFile();
} }
} }
public void importNameList(File path) { public void importNameList(File path) {
if (path != null) { if (path != null) {
try { try {
FileInputStream fis = new FileInputStream(path); FileInputStream fis = new FileInputStream(path);
String temp;
BufferedReader bis = new BufferedReader(new InputStreamReader(fis, StandardCharsets.UTF_8)); BufferedReader bis = new BufferedReader(new InputStreamReader(fis, StandardCharsets.UTF_8));
String temp;
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
while ((temp = bis.readLine()) != null) { while ((temp = bis.readLine()) != null) {
sb.append(temp); sb.append(temp);
sb.append("\n"); sb.append("\n");
} }
nameList = new Gson().fromJson(sb.toString(), List.class); fis.close();
nameList = new Gson().fromJson(sb.toString(), ArrayList.class);
System.out.println("Imported list from:" + path.getPath()); System.out.println("Imported list from:" + path.getPath());
} catch (Exception e) { } catch (Exception e) {
System.out.println("error in import namelist:" + e); System.out.println("error in import namelist:" + e);
e.printStackTrace(); e.printStackTrace();
} }
this.saveToFile();
} }
} }
@ -104,6 +109,8 @@ public class Data {
} }
nameList.clear(); nameList.clear();
nameList.addAll(tempList); nameList.addAll(tempList);
this.saveToFile();
} }
public void add(String text) { public void add(String text) {
@ -126,6 +133,7 @@ public class Data {
} }
System.gc(); System.gc();
this.saveToFile();
} }
public boolean compareNameIgnoreList() { public boolean compareNameIgnoreList() {
@ -139,6 +147,7 @@ public class Data {
nameList.remove(name); nameList.remove(name);
ignoreList.removeName(name); ignoreList.removeName(name);
this.saveToFile();
System.gc(); System.gc();
} }
@ -154,7 +163,6 @@ public class Data {
} }
public void saveToFile() { public void saveToFile() {
try { try {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(dataFile)); ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(dataFile));
oos.writeObject(nameList); oos.writeObject(nameList);
@ -162,12 +170,12 @@ public class Data {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
public void deleteAllName() { public void deleteAllName() {
nameList.clear(); nameList.clear();
ignoreList.clearNameIgnoreList(); ignoreList.clearNameIgnoreList();
this.saveToFile();
} }
public boolean checkNameIgnored(String name) { public boolean checkNameIgnored(String name) {
@ -259,7 +267,7 @@ public class Data {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(nameIgnoreFile)); ObjectInputStream ois = new ObjectInputStream(new FileInputStream(nameIgnoreFile));
this.ignoreNameList = (HashSet) ois.readObject(); this.ignoreNameList = (HashSet) ois.readObject();
ois.close();
} catch (EOFException e) { } catch (EOFException e) {
ignoreNameList = new HashSet<>(); ignoreNameList = new HashSet<>();
writeIgnoreList(IGNORELIST_NAME_ONLY); writeIgnoreList(IGNORELIST_NAME_ONLY);
@ -282,6 +290,7 @@ public class Data {
} }
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(numbIgnoreFile)); ObjectInputStream ois = new ObjectInputStream(new FileInputStream(numbIgnoreFile));
this.ignoreNumberList = (HashSet) ois.readObject(); this.ignoreNumberList = (HashSet) ois.readObject();
ois.close();
} catch (EOFException e) { } catch (EOFException e) {
ignoreNumberList = new HashSet<>(); ignoreNumberList = new HashSet<>();
System.out.println("Ignored number list is empty."); System.out.println("Ignored number list is empty.");

Loading…
Cancel
Save