Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.

Commit 2ad36e1

Browse files
committed
13 rename several classes, add quick swap function
, add handler of buttons in grid pane, add randSortM, fix some bugs, modify init process, add GlobalVariables
1 parent cc8beb2 commit 2ad36e1

File tree

17 files changed

+333
-113
lines changed

17 files changed

+333
-113
lines changed

.idea/dictionaries/ma201.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/libraries/poi_5_0_0.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/libraries/poi_ooxml_5_0_0.xml

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

DeskSorting.iml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,5 @@
2323
<orderEntry type="library" name="commons-collections4-4.4" level="project" />
2424
<orderEntry type="library" name="jfoenix-8.0.10" level="project" />
2525
<orderEntry type="library" name="poi-ooxml-lite-5.0.0" level="project" />
26-
<orderEntry type="library" name="commons-collections4-4.4 (2)" level="project" />
27-
<orderEntry type="library" name="commons-collections4-4.4 (3)" level="project" />
2826
</component>
2927
</module>
3.12 KB
Binary file not shown.

out/production/DeskSorting/cn/rocket/deksrt/resource/MainWindow.fxml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

33
<?import com.jfoenix.controls.JFXButton?>
4+
<?import com.jfoenix.controls.JFXCheckBox?>
45
<?import com.jfoenix.controls.JFXTextField?>
56
<?import javafx.scene.control.Label?>
67
<?import javafx.scene.layout.AnchorPane?>
@@ -46,22 +47,22 @@
4647
<Font size="15.0" />
4748
</font></Label>
4849
</GridPane>
49-
<JFXButton fx:id="importB" buttonType="RAISED" layoutX="40.0" layoutY="25.0" onAction="#impM" prefHeight="40.0" prefWidth="100.0" ripplerFill="BLACK" stylesheets="@style.css" text="导入...">
50+
<JFXButton fx:id="importB" buttonType="RAISED" layoutX="40.0" layoutY="25.0" onAction="#impM" prefHeight="40.0" prefWidth="100.0" ripplerFill="BLACK" stylesheets="@style.css" text="导入..." AnchorPane.leftAnchor="40.0">
5051
<font>
5152
<Font size="15.0" />
5253
</font>
5354
</JFXButton>
54-
<JFXButton fx:id="exportB" buttonType="RAISED" layoutX="220.0" layoutY="25.0" onAction="#expM" prefHeight="40.0" prefWidth="100.0" ripplerFill="BLACK" stylesheets="@style.css" text="导出...">
55+
<JFXButton fx:id="exportB" buttonType="RAISED" layoutX="173.0" layoutY="25.0" onAction="#expM" prefHeight="40.0" prefWidth="100.0" ripplerFill="BLACK" stylesheets="@style.css" text="导出..." AnchorPane.leftAnchor="173.0" AnchorPane.topAnchor="25.0">
5556
<font>
5657
<Font size="15.0" />
5758
</font>
5859
</JFXButton>
59-
<JFXButton fx:id="radSort" buttonType="RAISED" layoutX="400.0" layoutY="25.0" onAction="#radsM" prefHeight="40.0" prefWidth="100.0" ripplerFill="BLACK" stylesheets="@style.css" text="随机排">
60+
<JFXButton fx:id="randSort" buttonType="RAISED" layoutX="436.0" layoutY="25.0" onAction="#randM" prefHeight="40.0" prefWidth="100.0" ripplerFill="BLACK" stylesheets="@style.css" text="随机排">
6061
<font>
6162
<Font size="15.0" />
6263
</font>
6364
</JFXButton>
64-
<JFXButton fx:id="MSLSort" buttonType="RAISED" layoutX="580.0" layoutY="25.0" onAction="#mslsM" prefHeight="40.0" prefWidth="100.0" ripplerFill="BLACK" stylesheets="@style.css" text="随机排">
65+
<JFXButton fx:id="MSLSort" buttonType="RAISED" layoutX="580.0" layoutY="25.0" onAction="#mslM" prefHeight="40.0" prefWidth="100.0" ripplerFill="BLACK" stylesheets="@style.css" text="世龙排">
6566
<font>
6667
<Font size="15.0" />
6768
</font>
@@ -71,4 +72,9 @@
7172
<Font size="15.0" />
7273
</font>
7374
</JFXTextField>
75+
<JFXCheckBox fx:id="quickSwapCB" layoutX="310.0" layoutY="25.0" onAction="#quickSwapM" prefHeight="40.0" prefWidth="100.0" stylesheets="@style.css" text="快速交换">
76+
<font>
77+
<Font size="15.0" />
78+
</font>
79+
</JFXCheckBox>
7480
</AnchorPane>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package cn.rocket.deksrt.exceptions;
2+
3+
/**
4+
* @author Rocket
5+
* @version 1.0
6+
*/
7+
public class StuInfoException extends Exception{
8+
public StuInfoException() {
9+
super();
10+
}
11+
12+
public StuInfoException(String message) {
13+
super(message);
14+
}
15+
16+
public StuInfoException(String message, Throwable cause) {
17+
super(message, cause);
18+
}
19+
20+
public StuInfoException(Throwable cause) {
21+
super(cause);
22+
}
23+
}
Lines changed: 134 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
package cn.rocket.deksrt.main;
22

3+
import cn.rocket.deksrt.util.Student;
4+
import cn.rocket.deksrt.util.StudentList;
35
import javafx.application.Application;
46
import javafx.fxml.FXMLLoader;
57
import javafx.scene.Parent;
68
import javafx.scene.Scene;
79
import javafx.stage.Stage;
810
import org.apache.poi.ss.usermodel.*;
9-
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
1011

11-
import java.io.File;
12-
import java.io.FileInputStream;
13-
import java.io.IOException;
14-
import java.io.InputStream;
12+
import java.io.*;
13+
import java.nio.charset.StandardCharsets;
1514
import java.nio.file.Files;
16-
import java.util.ArrayList;
1715
import java.util.Objects;
18-
import java.util.Properties;
1916

2017
/**
2118
* @author Rocket
2219
* @version 1.0
2320
*/
2421
public class Entry extends Application {
25-
private Student[] stuInfo;
2622

2723
@Override
2824
public void start(Stage primaryStage) throws Exception {
25+
// File propertiesFile = new File(GlobalVariables.env+"config.properties");
26+
if (!importStuInfo())
27+
System.out.println("errors:" + scanStuInfo());
28+
exportStuInfo();
29+
2930
Parent root = FXMLLoader.load(Objects.requireNonNull(
3031
getClass().getResource("/cn/rocket/deksrt/resource/MainWindow.fxml")
3132
));
@@ -36,66 +37,140 @@ public void start(Stage primaryStage) throws Exception {
3637

3738
}
3839

39-
private void detectUserFile() throws IOException {
40-
String _userProfile = System.getenv("USERPROFILE") + "/DeskSorting/env.properties";
41-
File userProfile = new File(_userProfile);
42-
if (!userProfile.exists()) {
43-
String jarPath = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
44-
String globalPath = new File(jarPath).getParentFile().getPath(); //jar file parent path
45-
InputStream in = this.getClass().getResourceAsStream("/cn/rocket/deksrt/resource/templateOfStuInfo.xlsx");
46-
File out = new File(globalPath + "StuInfo.xlsx");
47-
if (!out.exists()) {
48-
assert in != null;
49-
Files.copy(in, out.toPath());
50-
} else {
51-
XSSFWorkbook wb = (XSSFWorkbook) WorkbookFactory.create(out);
52-
ArrayList<String> names = new ArrayList<>();
53-
ArrayList<String> pinyinList = new ArrayList<>();
54-
ArrayList<Boolean> boarding = new ArrayList<>();
55-
Sheet sheet = wb.getSheetAt(0);
56-
DataFormatter df = new DataFormatter();
57-
for (int row = 1; row <= 50; row++) {
58-
Row r = sheet.getRow(row);
59-
if (r == null)
60-
continue;
40+
/**
41+
* @return errors in xlsx file
42+
* @throws IOException if input a incorrect file
43+
*/
44+
private String scanStuInfo() throws IOException {
45+
StringBuilder errors = new StringBuilder();
46+
InputStream in = this.getClass().getResourceAsStream(GlobalVariables.stuInfoTemplateP);
47+
File infoXlsx = new File(GlobalVariables.jarParentPath + "StuInfo.xlsx");
48+
if (!infoXlsx.exists()) {
49+
assert in != null;
50+
Files.copy(in, infoXlsx.toPath());
51+
System.exit(99);
52+
} else {
53+
Workbook wb = WorkbookFactory.create(infoXlsx);
54+
GlobalVariables.stuInfo = new StudentList<>(52);
55+
StudentList<Student> stuIn = GlobalVariables.stuInfo;
56+
57+
Sheet sheet = wb.getSheetAt(0);
58+
DataFormatter df = new DataFormatter();
59+
60+
Student queue;
61+
String name;
62+
String pinyin;
63+
boolean boarding;
64+
for (int row = 1; row <= 52; row++) {
65+
Row r = sheet.getRow(row);
66+
if (r == null)
67+
continue;
68+
69+
Cell c0 = r.getCell(0, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
70+
Cell c1 = r.getCell(1, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
71+
Cell c2 = r.getCell(2, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
6172

62-
Cell c0 = r.getCell(0, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
63-
Cell c1 = r.getCell(1, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
64-
Cell c2 = r.getCell(2, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
65-
if (c0 != null) {
66-
names.add(c0.getStringCellValue());
67-
pinyinList.add(c1 != null ? c1.getStringCellValue() : "");
68-
if (c2 == null || !df.formatCellValue(c2).equals("1"))
69-
boarding.add(false);
70-
else
71-
boarding.add(true);
73+
if (c0 != null) {
74+
if (c1 == null || !GlobalVariables.validatePinyin((pinyin = df.formatCellValue(c1)))) {
75+
errors.append("B").append(row + 1).append(",");
76+
continue;
7277
}
78+
if (c2 != null) {
79+
String b = df.formatCellValue(c2);
80+
if (!(b.equals("1") || b.equals("0"))) {
81+
errors.append("C").append(row + 1).append(",");
82+
continue;
83+
} else
84+
boarding = b.equals("1");
85+
} else
86+
boarding = false;
87+
name = df.formatCellValue(c0);
88+
} else if (c1 == null && c2 == null)
89+
continue;
90+
else {
91+
errors.append("A").append(row + 1).append(",");
92+
continue;
7393
}
74-
stuInfo = new Student[names.size()];
75-
for (int i = 0; i < stuInfo.length; i++)
76-
stuInfo[i] = new Student(names.get(i), pinyinList.get(i), boarding.get(i));
77-
System.out.println("name\tpy\tboarding");
78-
for (int i = 0; i < names.size(); i++) {
79-
System.out.print(names.get(i) + (names.get(i).length() == 2 ? "\t\t" : "\t"));
80-
System.out.print(pinyinList.get(i) + "\t");
81-
System.out.println(boarding.get(i).toString());
82-
}
94+
queue = new Student(name, pinyin.toLowerCase(), boarding);
95+
if (!stuIn.contains(queue))
96+
stuIn.add(new Student(name, pinyin.toLowerCase(), boarding));
8397
}
98+
System.out.println("name\tpy\tboarding");
99+
for (Student student : stuIn)
100+
System.out.println(student);
101+
wb.close();
102+
}
103+
104+
return errors.length() != 0 ? errors.deleteCharAt(errors.length() - 1).toString() : "";
105+
}
84106

85-
return;
107+
private void exportStuInfo() {
108+
File parent = new File(GlobalVariables.env);
109+
if (!parent.exists())
110+
//noinspection ResultOfMethodCallIgnored
111+
parent.mkdirs();
112+
File infoFile = new File(GlobalVariables.env + "student.info");
113+
if (!infoFile.exists())
114+
try {
115+
//noinspection ResultOfMethodCallIgnored
116+
infoFile.createNewFile();
117+
} catch (IOException e) {
118+
e.printStackTrace();
119+
}
120+
StringBuilder sb = new StringBuilder();
121+
122+
sb.append("default:");
123+
for (Student student : GlobalVariables.stuInfo) {
124+
sb.append(student.getName()).append("$").append(student.getPinyin()).append("$")
125+
.append(Boolean.valueOf(student.isBoarding())).append(",");
126+
}
127+
sb.replace(sb.length() - 1, sb.length() - 1, ";");
128+
sb.deleteCharAt(sb.length() - 1);
129+
try (OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(infoFile), StandardCharsets.UTF_8)) {
130+
osw.write(sb.toString());
131+
osw.flush();
132+
} catch (IOException e) {
133+
e.printStackTrace();
86134
}
87-
FileInputStream fis = new FileInputStream(userProfile);
88-
Properties p = new Properties();
89-
p.load(fis);
90-
String info = p.getProperty("stuinfo");
135+
}
136+
137+
/**
138+
* @return <code>false</code> if no info in "student.info" or the file doesn't exist.
139+
*/
140+
private boolean importStuInfo() {
141+
File infoFile = new File(GlobalVariables.env + "student.info");
142+
String info = null;
143+
if (!infoFile.exists())
144+
return false;
145+
try (BufferedReader reader = new BufferedReader(
146+
new InputStreamReader(
147+
new FileInputStream(infoFile), StandardCharsets.UTF_8))) {
148+
info = reader.readLine();
149+
} catch (IOException e) {
150+
e.printStackTrace();
151+
}
152+
if (info == null)
153+
return false;
154+
// HashMap<String, StudentList<Student>> classMap = new HashMap<>();
155+
String[] classes = new String[]{info}/*.split(";")*/;
156+
for (String cla : classes) {
157+
String[] detailedInfo = cla.split(":");
158+
String[] studentArray = detailedInfo[1].split(",");
159+
StudentList<Student> studentInfo = new StudentList<>(studentArray.length);
160+
for (String student : studentArray) {
161+
String[] basicInfo = student.split("\\$");
162+
studentInfo.add(new Student(basicInfo[0], basicInfo[1], Boolean.parseBoolean(basicInfo[2])));
163+
}
164+
GlobalVariables.stuInfo = studentInfo;
165+
// classMap.put(detailedInfo[0],studentInfo);
166+
}
167+
return true;
91168
}
92169

93170
public static void main(String[] args) {
94-
// try {
95-
// new Entry().detectUserFile();
96-
// } catch (IOException e) {
97-
// e.printStackTrace();
98-
// }
171+
GlobalVariables.jarPath = Entry.class.getProtectionDomain().getCodeSource().getLocation().getPath();
172+
GlobalVariables.jarParentPath = new File(GlobalVariables.jarPath).getParent() + "/";
173+
99174
launch(args);
100175
}
101176
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package cn.rocket.deksrt.main;
2+
3+
import cn.rocket.deksrt.util.StudentList;
4+
import cn.rocket.deksrt.util.Student;
5+
6+
/**
7+
* @author Rocket
8+
* @version 1.0
9+
*/
10+
class GlobalVariables {
11+
static String jarPath; // With '/'
12+
static String jarParentPath; // With '/'
13+
14+
15+
static StudentList<Student> stuInfo;
16+
17+
static final String env = System.getenv("USERPROFILE") + "/.rocketdev/DeskSorting/";
18+
static final String stuInfoTemplateP = "/cn/rocket/deksrt/resource/templateOfStuInfo.xlsx";
19+
20+
static boolean validatePinyin(String pinyin) {
21+
for (int i = 0; i < pinyin.length(); i++) {
22+
char c = pinyin.charAt(i);
23+
if (c<'0'||c>'z'||(c>'9'&&c<'a')) // !'0'~'9'+'a'~'z'
24+
return false;
25+
}
26+
return true;
27+
}
28+
}

0 commit comments

Comments
 (0)