名单列表可多选删除

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

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

Loading…
Cancel
Save