Skip to content

Commit

Permalink
v1.2.3
Browse files Browse the repository at this point in the history
- New Features: Poetry tags, poetry translation, and poetry information pages.
- Partial Fix #1: Fixed an issue that caused freezing when calculating countdowns on specific dates (e.g., October 31).
- Increased the lesson list limit: Now supports up to a maximum of 15 lessons.
- Optimized error handling logic.
  • Loading branch information
Wudji committed Nov 5, 2023
1 parent f317b00 commit ea88146
Show file tree
Hide file tree
Showing 17 changed files with 294 additions and 132 deletions.
66 changes: 47 additions & 19 deletions src/main/java/com/wudji/lessonlist/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,58 @@
package com.wudji.lessonlist;

import com.wudji.lessonlist.screens.MainWindow;
import com.wudji.lessonlist.screens.NoticeScreen;
import com.wudji.lessonlist.screens.PoemScreen;
import com.wudji.lessonlist.screens.WelcomeScreen;
import com.wudji.lessonlist.utils.ExceptionManager;
import com.wudji.lessonlist.utils.FileControl;
import com.wudji.lessonlist.obj.WindowConfig;

import java.awt.*;
import java.text.ParseException;
import java.util.*;
import java.util.Timer;

import com.wudji.lessonlist.Screens.*;
import com.wudji.lessonlist.Utils.FileControl;
import com.wudji.lessonlist.network.PoemNetworkRequest;
import com.wudji.lessonlist.obj.WindowConfig;
import java.util.TimerTask;


public class MainActivity {

public static WindowConfig globalConfig = FileControl.getWindowConfig();
public static Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
public static String base_version = "v1.1.2";
public static String product_version = "v1.2.0_poem_suggestion_tjyz";
public static String product_version = "v1.2.3-poem-suggestion-tjyz";
public static PoemScreen poemScreen;
public static MainWindow window;
public static WelcomeScreen welcomeScreen;
public static NoticeScreen noticeScreen;

public static void main(String[] args){
MainWindow window = new MainWindow((int)d.getWidth() - globalConfig.getPosx(),globalConfig.getPosy(),globalConfig.getWeight(),(int)d.getHeight() - globalConfig.getHeight());
WelcomeScreen welcomeScreen = new WelcomeScreen();
NoticeScreen noticeScreen = new NoticeScreen(window.getLocation());
Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler());

window = new MainWindow((int)d.getWidth() - globalConfig.getPosx(),globalConfig.getPosy(),globalConfig.getWeight(),(int)d.getHeight() - globalConfig.getHeight());
welcomeScreen = new WelcomeScreen();
noticeScreen = new NoticeScreen(window.getLocation());

Timer timer = new Timer();

if (globalConfig.isEnablePoemSuggestion()){
Thread thread = new Thread(() -> {
String data = PoemNetworkRequest.getPoemData();
System.out.println(data);
PoemScreen poemScreen = new PoemScreen(window.getLocation(),data);
Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler());

poemScreen = new PoemScreen(window.getLocation());
noticeScreen.updatePosition(poemScreen.getHeight());
poemScreen.setVisible(true);

timer.schedule(new TimerTask() {
@Override
public void run() {
refreshPoemInfo(poemScreen);
}

private void refreshPoemInfo(PoemScreen poemScreen){

poemScreen.updatePoemInfo();
}
}, 3600000,3600000);
});
thread.start();
}
Expand All @@ -40,10 +61,10 @@ public static void main(String[] args){
timer.schedule(new TimerTask() {
@Override
public void run() {
showDelayScreen(welcomeScreen, noticeScreen);
showDelayScreen();
}

private void showDelayScreen(WelcomeScreen welcomeScreen,NoticeScreen noticeScreen){
private void showDelayScreen(){

// 隐藏欢迎页面
welcomeScreen.setVisible(false);
Expand All @@ -52,7 +73,7 @@ private void showDelayScreen(WelcomeScreen welcomeScreen,NoticeScreen noticeScre
noticeScreen.setVisible(true);
}
}
},(int) (Math.random()*2000));
}, 3000);

welcomeScreen.setVisible(true);

Expand All @@ -61,15 +82,22 @@ private void showDelayScreen(WelcomeScreen welcomeScreen,NoticeScreen noticeScre
@Override
public void run() {
try {
updateA(window);
updateA();
} catch (ParseException e) {
e.printStackTrace();
}
}

private void updateA(MainWindow w) throws ParseException {
w.update();
private void updateA() throws ParseException {
window.update();
}
},1,1000);
}
}
class CustomExceptionHandler implements Thread.UncaughtExceptionHandler{

@Override
public void uncaughtException(Thread t, Throwable e) {
ExceptionManager.showErrorDialog(e);
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/wudji/lessonlist/Screens/AboutScreen.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.wudji.lessonlist.Screens;
package com.wudji.lessonlist.screens;

import com.wudji.lessonlist.MainActivity;
import com.wudji.lessonlist.Utils.FileControl;
import com.wudji.lessonlist.utils.FileControl;

import javax.swing.*;
import java.awt.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.wudji.lessonlist.Screens;
package com.wudji.lessonlist.screens;

import com.wudji.lessonlist.MainActivity;
import com.wudji.lessonlist.Utils.FileControl;
import com.wudji.lessonlist.utils.FileControl;
import com.wudji.lessonlist.obj.WindowConfig;

import javax.swing.*;
import java.awt.*;

public class GeneralConfigScreen extends JFrame {
public class GeneralConfigScreen extends JDialog {
private WindowConfig config = MainActivity.globalConfig;
private JTextField clockFontSizeField;
private JTextField lessonFontSizeField;
Expand All @@ -30,11 +30,12 @@ public class GeneralConfigScreen extends JFrame {
private JTextField noticeHeightField;

public GeneralConfigScreen() {
super((Frame) null, "通用配置界面", true);
initialize();
}

private void initialize() {
setTitle("通用配置页面");
// setTitle("通用配置页面");
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
setResizable(false);

Expand Down Expand Up @@ -323,6 +324,20 @@ private void saveConfig(boolean isRestart) {

dispose(); // Close the config window

if(!MainActivity.globalConfig.isEnablePoemSuggestion()){
MainActivity.poemScreen.setVisible(false);
MainActivity.noticeScreen.updatePosition(-1);
}else{
MainActivity.poemScreen.setVisible(true);
MainActivity.noticeScreen.updatePosition(MainActivity.poemScreen.getHeight());
}

if(!MainActivity.globalConfig.isEnableNotice()){
MainActivity.noticeScreen.setVisible(false);
}else{
MainActivity.noticeScreen.setVisible(true);
}

if(isRestart){
System.exit(0);
}
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/com/wudji/lessonlist/Screens/LessonConfigScreen.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
package com.wudji.lessonlist.Screens;
package com.wudji.lessonlist.screens;

import com.wudji.lessonlist.Utils.ExceptionManager;
import com.wudji.lessonlist.Utils.FileControl;
import com.wudji.lessonlist.utils.ExceptionManager;
import com.wudji.lessonlist.utils.FileControl;
import com.wudji.lessonlist.obj.Lesson;
import com.wudji.lessonlist.obj.LessonConfig;

import javax.swing.*;
import java.awt.*;

public class LessonConfigScreen extends JFrame {
public class LessonConfigScreen extends JDialog {
private Lesson[] lessons;

private LessonConfig[] configs = new LessonConfig[10];
private LessonConfig[] configs = new LessonConfig[15];

private int dateOfWeek;
private static String[] weeks = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};

public LessonConfigScreen(Lesson[] lessons,String date) {
super((Frame) null, "课程配置界面", true);
this.lessons = lessons;
this.dateOfWeek = getDateNumFromString(date);
initialize();
}

private void initialize() {
setTitle("配置课程列表页面");
// setTitle("配置课程列表页面");
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
setResizable(false);

Expand Down Expand Up @@ -88,7 +89,7 @@ private void initialize() {
panel.add(headLabel5, constraints);

// 添加课表配置项
for (int j = 0;j < 10;j++){
for (int j = 0;j < 15;j++){
if(j < lessons.length) {
configs[j] = new LessonConfig(lessons[j], true);
}else {
Expand All @@ -114,7 +115,7 @@ private void initialize() {
saveButton.setFont(titleFont);
saveButton.addActionListener(e -> saveConfig(false));
constraints.gridx = 0;
constraints.gridy = 14;
constraints.gridy = 19;
constraints.gridwidth = 3;
panel.add(saveButton, constraints);

Expand All @@ -123,7 +124,7 @@ private void initialize() {
saveARButton.addActionListener(e -> saveConfig(true));

constraints.gridx = 2;
constraints.gridy = 14;
constraints.gridy = 19;
constraints.gridwidth = 3;
panel.add(saveARButton, constraints);

Expand Down
16 changes: 10 additions & 6 deletions src/main/java/com/wudji/lessonlist/Screens/MainConfigScreen.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package com.wudji.lessonlist.Screens;
package com.wudji.lessonlist.screens;

import com.wudji.lessonlist.Utils.FileControl;
import com.wudji.lessonlist.utils.FileControl;

import javax.swing.*;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.*;

public class MainConfigScreen extends JFrame {
public class MainConfigScreen extends JDialog {
Font fontS = FileControl.getFont(Font.BOLD,20);
Font fontL = FileControl.getFont(Font.BOLD,26);

String targetDay = "Monday";
public MainConfigScreen(){
setTitle("主配置页面");
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
super((Frame) null, "主配置界面", true);
setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
setResizable(false);

JPanel panel = new JPanel();
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/wudji/lessonlist/Screens/MainWindow.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.wudji.lessonlist.Screens;
package com.wudji.lessonlist.screens;


import com.wudji.lessonlist.Utils.ClockButtonManager;
import com.wudji.lessonlist.Utils.ExceptionManager;
import com.wudji.lessonlist.utils.ClockButtonManager;
import com.wudji.lessonlist.utils.ExceptionManager;
import com.wudji.lessonlist.MainActivity;
import com.wudji.lessonlist.Utils.FileControl;
import com.wudji.lessonlist.utils.FileControl;
import com.wudji.lessonlist.obj.Lesson;

import javax.swing.*;
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/com/wudji/lessonlist/Screens/NoticeScreen.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.wudji.lessonlist.Screens;
package com.wudji.lessonlist.screens;

import com.wudji.lessonlist.MainActivity;
import com.wudji.lessonlist.obj.NoticeLine;
import com.wudji.lessonlist.Utils.FileControl;
import com.wudji.lessonlist.utils.FileControl;

import javax.swing.*;
import javax.swing.border.Border;
Expand Down Expand Up @@ -44,7 +44,12 @@ public NoticeScreen(Point mainWindowLocation) {

public void updatePosition(int y){
this.pack();
this.setLocation(this.location.x - this.getWidth(), this.location.y + y + 30);
if(y == -1){ // 未启用诗词推送页面
this.setLocation(this.location.x - this.getWidth(), this.location.y);
}else{
this.setLocation(this.location.x - this.getWidth(), this.location.y + y + 30);
}

}
private void updateNoticeList(NoticeLine[] lines){
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
Expand Down
Loading

0 comments on commit ea88146

Please sign in to comment.