Skip to content
This repository has been archived by the owner on Dec 17, 2021. It is now read-only.

Commit

Permalink
fix #3
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottCTD committed Oct 5, 2020
1 parent 9c48f0f commit 09dc000
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 8 deletions.
17 changes: 16 additions & 1 deletion src/main/java/xyz/scottc/VocabularyState.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
package xyz.scottc;

public enum VocabularyState {
CORRECT, INCORRECT, NOT_ANSWERED, ANSWERED
CORRECT, INCORRECT, NOT_ANSWERED, ANSWERED;

@Override
public String toString() {
switch (this) {
case CORRECT:
return "CORRECT";
case INCORRECT:
return "INCORRECT";
case ANSWERED:
return "ANSWERED";
case NOT_ANSWERED:
return "NOT ANSWERED";
}
return "ERROR";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class FunctionPanel extends UtilJPanel {

private final CommonModeFrame parentFrame;
private final TopPanel topPanel;
private final Review review;
protected final Review review;

private final UtilJLabel previousQLabel = new UtilJLabel("Previous Question", VDConstantsUtils.MICROSOFT_YAHEI_BOLD_30);
private final VDTextArea previousQ = new VDTextArea(1, 11, VDConstantsUtils.MICROSOFT_YAHEI_BOLD_30, false, true);
Expand All @@ -46,16 +46,16 @@ public class FunctionPanel extends UtilJPanel {
private final UtilJButton answerButton = new UtilJButton("Answer", 35);
private final UtilJButton reviewButton = new UtilJButton("Review", 35);

public boolean isListLoaded = false;
public boolean init = false;
protected boolean isListLoaded = false;
protected boolean init = false;
private boolean suspend = false;
private boolean isAnswerShown = false;

private int index = 0;

public List<Object> questionList;
public List<Object> answerList;
public List<String> inputList = new ArrayList<>();
protected List<Object> questionList;
protected List<Object> answerList;
protected List<String> inputList = new ArrayList<>();

private final Object[] selectionValues = {"Vocabulary - Meaning", "Meaning - Vocabulary"};
private Object selectionValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.json.JSONObject;
import xyz.scottc.frames.commonModeFrame.CommonModeFrame;
import xyz.scottc.frames.commonModeFrame.dialog.review.ReviewData;
import xyz.scottc.frames.mainFrame.MainFrame;
import xyz.scottc.utils.*;

Expand Down Expand Up @@ -43,6 +44,8 @@ public class LeftPanel extends UtilJPanel {
private final List<File> internalVocabularyPool = new ArrayList<>();
private final List<File> externalVocabularyPool = new ArrayList<>();

protected String selectedListName;

public LeftPanel(CommonModeFrame parent, FunctionPanel functionPanel, TopPanel topPanel) {
this.parentFrame = parent;
this.functionPanel = functionPanel;
Expand All @@ -52,8 +55,10 @@ public LeftPanel(CommonModeFrame parent, FunctionPanel functionPanel, TopPanel t
this.add(this.importButton);
this.importButton.setToolTipText("Import the customized VD File which can be acquired by using \"Tools\" menu in the Main windows.");
this.importButton.addActionListener(e -> this.importFile());

this.add(this.exportButton);
this.exportButton.setToolTipText("Export your answer report.");
this.exportButton.addActionListener(e -> this.export());

this.add(this.internalFileListLabel);
this.add(this.internalFileListScrollPane);
Expand Down Expand Up @@ -121,6 +126,39 @@ private void importFile() {
}
}

private void export() {
if (this.functionPanel.init) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setMultiSelectionEnabled(false);
int result = fileChooser.showSaveDialog(this.parentFrame);
if (result == JFileChooser.APPROVE_OPTION) {
StringBuilder builder = new StringBuilder();

String title = "VDList: " + this.selectedListName + VDConstantsUtils.SPACE +
"Finishing Time: " + this.topPanel.timer.getText() + "\n";
builder.append(title);

List<ReviewData> dataList = this.functionPanel.review.dataPanel.allDataList;
for (ReviewData datum : dataList) {
builder.append(datum.toString()).append("\n");
}

File file = new File(fileChooser.getSelectedFile().getAbsolutePath().endsWith(".txt") ?
fileChooser.getSelectedFile().getAbsolutePath() : fileChooser.getSelectedFile().getAbsolutePath() + ".txt");
OutputStream outputStream = null;
try {
outputStream = new FileOutputStream(file);
outputStream.write(builder.toString().getBytes());
outputStream.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
FileUtils.closeStream(null, outputStream);
}
}
}
}

private void addExternalVocabularyPool() {
this.externalVocabularyPool.clear();
this.externalFileListModel.clear();
Expand Down Expand Up @@ -158,6 +196,7 @@ private void addInternalVocabularyPool() {
for (File file : Objects.requireNonNull(MainFrame.internalLibrary.listFiles())) {
this.internalVocabularyPool.add(file);
this.internalFileListModel.addElement(file.getName());
this.selectedListName = file.getName().replace(".json", VDConstantsUtils.EMPTY);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package xyz.scottc.frames.commonModeFrame.dialog.review;

import xyz.scottc.VocabularyState;
import xyz.scottc.utils.VDConstantsUtils;

public class ReviewData {

Expand Down Expand Up @@ -60,4 +61,15 @@ public VocabularyState getCorrect() {
public void setCorrect(VocabularyState correct) {
this.correct = correct;
}

@Override
public String toString() {
if (this.input.equals(VDConstantsUtils.EMPTY)) {
this.input = VDConstantsUtils.SPACE;
}
return this.serialNumber + VDConstantsUtils.SPACE + this.question + VDConstantsUtils.SPACE +
this.answer + VDConstantsUtils.SPACE +
this.input + VDConstantsUtils.SPACE +
this.correct;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ private void generateFile() {
}
JFileChooser fileChooser = new JFileChooser();
int result = fileChooser.showSaveDialog(this);
fileChooser.setCurrentDirectory(new File("D:\\Desktop"));
if (result == JFileChooser.APPROVE_OPTION) {
File output = new File(fileChooser.getSelectedFile().getAbsolutePath().endsWith(".json") ?
fileChooser.getSelectedFile().getAbsolutePath() : fileChooser.getSelectedFile().getAbsolutePath() + ".json");
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/xyz/scottc/utils/VDTimer.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,30 @@ public void stop() {
}
}

public int getSecond() {
return second;
}

public void setSecond(int second) {
this.second = second;
}

public int getMinute() {
return minute;
}

public void setMinute(int minute) {
this.minute = minute;
}

public int getHour() {
return hour;
}

public void setHour(int hour) {
this.hour = hour;
}

private class TimerThread implements Runnable {

@Override
Expand Down

0 comments on commit 09dc000

Please sign in to comment.