├── db ├── data.db └── sqlite3.exe ├── lib ├── chart.jar ├── swingx-core-1.6.2.jar ├── sqlite-jdbc-3.20.0.jar └── pgslookandfeel-1.1.2.jar ├── resources ├── img │ ├── home.png │ ├── backup.png │ ├── config.png │ ├── history.png │ ├── record.png │ ├── report.png │ ├── restore.png │ └── category.png └── github │ └── demo.gif ├── .idea ├── vcs.xml ├── misc.xml ├── modules.xml ├── libraries │ └── lib.xml ├── SmallAccount.iml └── uiDesigner.xml ├── src ├── gui │ ├── panel │ │ ├── WorkingPanel.java │ │ ├── BackupPanel.java │ │ ├── HistoryPanel.java │ │ ├── RecoverPanel.java │ │ ├── ReportPanel.java │ │ ├── ConfigPanel.java │ │ ├── HistoryListPanel.java │ │ ├── MonthPickerPanel.java │ │ ├── CategoryPanel.java │ │ ├── MainPanel.java │ │ ├── RecordPanel.java │ │ └── SpendPanel.java │ ├── frame │ │ └── MainFrame.java │ ├── listener │ │ ├── MonthPickerListener.java │ │ ├── ConfigListener.java │ │ ├── ToolBarListener.java │ │ ├── RecoverListener.java │ │ ├── BackupListener.java │ │ ├── RecordListener.java │ │ ├── CategoryListener.java │ │ └── HistoryListListener.java │ ├── page │ │ └── SpendPage.java │ └── model │ │ ├── CategoryComboBoxModel.java │ │ ├── CategoryTableModel.java │ │ └── RecordTableModel.java ├── util │ ├── DBUtil.java │ ├── ColorUtil.java │ ├── SQLUtil.java │ ├── CenterPanel.java │ ├── GUIUtil.java │ ├── DateUtil.java │ ├── CircleProgressBar.java │ └── ChartUtil.java ├── entity │ ├── Config.java │ ├── Category.java │ └── Record.java ├── startup │ └── Bootstrap.java ├── service │ ├── ConfigService.java │ ├── CategoryService.java │ ├── RecordService.java │ ├── SpendService.java │ └── ReportService.java └── dao │ ├── CategoryDAO.java │ ├── ConfigDAO.java │ └── RecordDAO.java ├── test ├── test2.java └── test1.java ├── SmallAccount.iml ├── README.md └── LICENSE /db/data.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xenv/SmallAccount/HEAD/db/data.db -------------------------------------------------------------------------------- /db/sqlite3.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xenv/SmallAccount/HEAD/db/sqlite3.exe -------------------------------------------------------------------------------- /lib/chart.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xenv/SmallAccount/HEAD/lib/chart.jar -------------------------------------------------------------------------------- /resources/img/home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xenv/SmallAccount/HEAD/resources/img/home.png -------------------------------------------------------------------------------- /lib/swingx-core-1.6.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xenv/SmallAccount/HEAD/lib/swingx-core-1.6.2.jar -------------------------------------------------------------------------------- /resources/github/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xenv/SmallAccount/HEAD/resources/github/demo.gif -------------------------------------------------------------------------------- /resources/img/backup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xenv/SmallAccount/HEAD/resources/img/backup.png -------------------------------------------------------------------------------- /resources/img/config.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xenv/SmallAccount/HEAD/resources/img/config.png -------------------------------------------------------------------------------- /resources/img/history.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xenv/SmallAccount/HEAD/resources/img/history.png -------------------------------------------------------------------------------- /resources/img/record.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xenv/SmallAccount/HEAD/resources/img/record.png -------------------------------------------------------------------------------- /resources/img/report.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xenv/SmallAccount/HEAD/resources/img/report.png -------------------------------------------------------------------------------- /resources/img/restore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xenv/SmallAccount/HEAD/resources/img/restore.png -------------------------------------------------------------------------------- /lib/sqlite-jdbc-3.20.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xenv/SmallAccount/HEAD/lib/sqlite-jdbc-3.20.0.jar -------------------------------------------------------------------------------- /resources/img/category.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xenv/SmallAccount/HEAD/resources/img/category.png -------------------------------------------------------------------------------- /lib/pgslookandfeel-1.1.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xenv/SmallAccount/HEAD/lib/pgslookandfeel-1.1.2.jar -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/libraries/lib.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/gui/panel/WorkingPanel.java: -------------------------------------------------------------------------------- 1 | package gui.panel; 2 | 3 | import javax.swing.*; 4 | /** 5 | * 抽象界面类 WorkingPanel 强制子类实现两个方法 6 | * WorkingPanel 存在 在 CenterPanel workingPanel 中 7 | * workingPanel有方法 .show(WorkingPanel p) 可以居中显示子面板 并 更新数据 即调用 this.updateData() 方法 8 | */ 9 | public abstract class WorkingPanel extends JPanel{ 10 | public abstract void updateData(); 11 | public abstract void addListener(); 12 | } 13 | -------------------------------------------------------------------------------- /test/test2.java: -------------------------------------------------------------------------------- 1 | import dao.CategoryDAO; 2 | import dao.ConfigDAO; 3 | import dao.RecordDAO; 4 | import entity.Category; 5 | import entity.Config; 6 | import entity.Record; 7 | import util.DBUtil; 8 | import util.DateUtil; 9 | 10 | import java.text.ParseException; 11 | import java.text.SimpleDateFormat; 12 | import java.util.*; 13 | 14 | public class test2 { 15 | public static void main(String[] args){ 16 | System.out.println(new RecordDAO().getTotal()); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/util/DBUtil.java: -------------------------------------------------------------------------------- 1 | package util; 2 | 3 | import java.sql.Connection; 4 | import java.sql.DriverManager; 5 | import java.sql.SQLException; 6 | 7 | /** 8 | * 工具类 DBUtil 获取数据库 Connection 9 | */ 10 | 11 | public class DBUtil { 12 | static final String database = "db/data.db"; 13 | 14 | static { 15 | try { 16 | Class.forName("org.sqlite.JDBC"); 17 | } catch (ClassNotFoundException e) { 18 | e.printStackTrace(); 19 | } 20 | } 21 | 22 | public static Connection getConnection() throws SQLException { 23 | String url = String.format("jdbc:sqlite:%s", database); 24 | return DriverManager.getConnection(url); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/util/ColorUtil.java: -------------------------------------------------------------------------------- 1 | package util; 2 | 3 | import java.awt.*; 4 | 5 | /** 6 | * 工具类 ColorUtil 色彩 7 | */ 8 | public class ColorUtil { 9 | //预设颜色 10 | public static Color blueColor = Color.decode("#3399FF"); 11 | public static Color grayColor = Color.decode("#999999"); 12 | public static Color backgroundColor = Color.decode("#eeeeee"); 13 | public static Color warningColor = Color.decode("#FF3333"); 14 | 15 | //根据百分比绘制颜色 16 | public static Color getByPercentage(int per) { 17 | if (per > 100) 18 | per = 100; 19 | int b = 51; 20 | float rate = per / 100f; 21 | int r = (int) ((255 - 51) * rate + 51); 22 | int g = 255 - r + 51; 23 | return new Color(r, g, b); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/gui/frame/MainFrame.java: -------------------------------------------------------------------------------- 1 | package gui.frame; 2 | 3 | import gui.panel.MainPanel; 4 | import util.GUIUtil; 5 | 6 | import javax.swing.*; 7 | 8 | /** 9 | * 程序主窗体 10 | * 设置了程序窗体的长宽标题和退出操作等 11 | */ 12 | 13 | public class MainFrame extends JFrame { 14 | static { 15 | GUIUtil.useLNF(); 16 | } 17 | 18 | public static MainFrame instance = new MainFrame(); 19 | 20 | private MainFrame() { 21 | this.setSize(513, 450); 22 | this.setTitle("小小记账本"); 23 | this.setContentPane(MainPanel.instance); 24 | this.setLocationRelativeTo(null); 25 | this.setResizable(false); 26 | this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 27 | } 28 | 29 | public static void main(String[] args) { 30 | instance.setVisible(true); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /SmallAccount.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/entity/Config.java: -------------------------------------------------------------------------------- 1 | package entity; 2 | 3 | /** 4 | * 实体类 Config 5 | */ 6 | 7 | public class Config { 8 | private int id; 9 | private String key; 10 | private String value; 11 | 12 | public Config() { 13 | } 14 | 15 | public Config(int id, String key, String value) { 16 | this.id = id; 17 | this.key = key; 18 | this.value = value; 19 | } 20 | 21 | public int getId() { 22 | return id; 23 | } 24 | 25 | public void setId(int id) { 26 | this.id = id; 27 | } 28 | 29 | public String getKey() { 30 | return key; 31 | } 32 | 33 | public void setKey(String key) { 34 | this.key = key; 35 | } 36 | 37 | public String getValue() { 38 | return value; 39 | } 40 | 41 | public void setValue(String value) { 42 | this.value = value; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /.idea/SmallAccount.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/startup/Bootstrap.java: -------------------------------------------------------------------------------- 1 | package startup; 2 | 3 | import gui.frame.MainFrame; 4 | import gui.panel.MainPanel; 5 | import gui.panel.SpendPanel; 6 | import util.GUIUtil; 7 | 8 | import javax.swing.*; 9 | 10 | /** 11 | * 启动类 Bootstrap 12 | * main为本程序的总入口 13 | * 会加载一个 MainFrame 程序窗体 和 一个 MainPanel 程序 主面板 ,并且初始化 MainPanel 中的 workingPanel 14 | * workingPanel有方法 .show(WorkingPanel p) 可以居中显示子面板 并 更新数据 15 | * 使用swing的阻塞机制,优先加载整个启动窗口 16 | * 17 | * @see MainFrame 18 | * @see MainPanel 19 | */ 20 | public class Bootstrap { 21 | public static void main(String[] args) throws Exception { 22 | GUIUtil.useLNF(); 23 | 24 | SwingUtilities.invokeAndWait(new Runnable() { 25 | @Override 26 | public void run() { 27 | MainFrame.instance.setVisible(true); 28 | //居中显示子面板 并 更新数据 29 | MainPanel.instance.workingPanel.show(SpendPanel.instance); 30 | } 31 | }); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/entity/Category.java: -------------------------------------------------------------------------------- 1 | package entity; 2 | 3 | /** 4 | * 实体类 Category 5 | */ 6 | 7 | public class Category { 8 | private int id; 9 | private String name; 10 | 11 | private int recordNumber; 12 | 13 | public Category() { 14 | } 15 | 16 | public Category(int id, String name) { 17 | this.id = id; 18 | this.name = name; 19 | } 20 | 21 | public int getId() { 22 | return id; 23 | } 24 | 25 | public void setId(int id) { 26 | this.id = id; 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | 33 | public void setName(String name) { 34 | this.name = name; 35 | } 36 | 37 | public int getRecordNumber() { 38 | return recordNumber; 39 | } 40 | 41 | public void setRecordNumber(int recordNumber) { 42 | this.recordNumber = recordNumber; 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return name; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/gui/panel/BackupPanel.java: -------------------------------------------------------------------------------- 1 | package gui.panel; 2 | 3 | import javax.swing.JButton; 4 | 5 | import gui.listener.BackupListener; 6 | import util.ColorUtil; 7 | import util.GUIUtil; 8 | 9 | /** 10 | * 界面类 BackupPanel 备份页 11 | */ 12 | 13 | public class BackupPanel extends WorkingPanel { 14 | static { 15 | GUIUtil.useLNF(); 16 | } 17 | 18 | public static BackupPanel instance = new BackupPanel(); 19 | private JButton bBackup = new JButton("备份"); 20 | 21 | public BackupPanel() { 22 | GUIUtil.setColor(ColorUtil.blueColor, bBackup); 23 | this.add(bBackup); 24 | addListener(); 25 | } 26 | 27 | public static void main(String[] args) { 28 | GUIUtil.showPanel(BackupPanel.instance); 29 | } 30 | 31 | @Override 32 | public void updateData() { 33 | 34 | } 35 | 36 | @Override 37 | public void addListener() { 38 | BackupListener listener = new BackupListener(); 39 | bBackup.addActionListener(listener); 40 | } 41 | } -------------------------------------------------------------------------------- /src/gui/panel/HistoryPanel.java: -------------------------------------------------------------------------------- 1 | package gui.panel; 2 | 3 | import util.GUIUtil; 4 | 5 | import java.awt.*; 6 | 7 | /** 8 | * 界面类 HistoryPanel 历史消费页 9 | * 调用了 MonthPickerPanel 和 HistoryListPanel 两个子面板 10 | * 11 | * @author xenv 12 | * @see MonthPickerPanel 13 | * @see HistoryListPanel 14 | */ 15 | public class HistoryPanel extends WorkingPanel { 16 | static { 17 | GUIUtil.useLNF(); 18 | } 19 | 20 | public static HistoryPanel instance = new HistoryPanel(); 21 | 22 | private HistoryPanel() { 23 | this.setLayout(new BorderLayout()); 24 | this.add(MonthPickerPanel.instance, BorderLayout.NORTH); 25 | this.add(HistoryListPanel.instance, BorderLayout.CENTER); 26 | } 27 | 28 | public static void main(String[] args) { 29 | GUIUtil.showPanel(HistoryPanel.instance); 30 | } 31 | 32 | @Override 33 | public void updateData() { 34 | HistoryListPanel.instance.updateData(); 35 | } 36 | 37 | @Override 38 | public void addListener() { 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/gui/panel/RecoverPanel.java: -------------------------------------------------------------------------------- 1 | package gui.panel; 2 | 3 | import javax.swing.JButton; 4 | import javax.swing.JPanel; 5 | 6 | import gui.listener.RecoverListener; 7 | import util.ColorUtil; 8 | import util.GUIUtil; 9 | 10 | /** 11 | * 界面类 RecoverPanel 恢复页 12 | */ 13 | 14 | public class RecoverPanel extends WorkingPanel { 15 | static{ 16 | GUIUtil.useLNF(); 17 | } 18 | public static RecoverPanel instance = new RecoverPanel(); 19 | 20 | private JButton bRecover =new JButton("恢复"); 21 | 22 | public RecoverPanel() { 23 | GUIUtil.setColor(ColorUtil.blueColor, bRecover); 24 | this.add(bRecover); 25 | addListener(); 26 | } 27 | 28 | public static void main(String[] args) { 29 | GUIUtil.showPanel(RecoverPanel.instance); 30 | } 31 | @Override 32 | public void updateData() { 33 | 34 | } 35 | 36 | @Override 37 | public void addListener() { 38 | RecoverListener listener = new RecoverListener(); 39 | bRecover.addActionListener(listener); 40 | } 41 | } -------------------------------------------------------------------------------- /src/gui/panel/ReportPanel.java: -------------------------------------------------------------------------------- 1 | package gui.panel; 2 | 3 | import java.awt.BorderLayout; 4 | import java.awt.Image; 5 | 6 | import javax.swing.ImageIcon; 7 | import javax.swing.JLabel; 8 | import javax.swing.JPanel; 9 | 10 | import service.ReportService; 11 | import util.ChartUtil; 12 | import util.GUIUtil; 13 | 14 | /** 15 | * 界面类 ReportPanel 月度报告页 16 | */ 17 | 18 | public class ReportPanel extends WorkingPanel { 19 | static { 20 | GUIUtil.useLNF(); 21 | } 22 | 23 | public static ReportPanel instance = new ReportPanel(); 24 | 25 | public JLabel l = new JLabel(); 26 | 27 | 28 | public ReportPanel() { 29 | this.add(l); 30 | } 31 | 32 | public static void main(String[] args) { 33 | GUIUtil.showPanel(ReportPanel.instance); 34 | } 35 | 36 | @Override 37 | public void updateData() { 38 | Image i = ChartUtil.getImage(new ReportService().listThisMonthRecords(), 400, 260); 39 | ImageIcon icon = new ImageIcon(i); 40 | l.setIcon(icon); 41 | } 42 | 43 | @Override 44 | public void addListener() { 45 | 46 | } 47 | } -------------------------------------------------------------------------------- /test/test1.java: -------------------------------------------------------------------------------- 1 | import service.ReportService; 2 | import util.ChartUtil; 3 | import util.GUIUtil; 4 | 5 | import javax.swing.*; 6 | import java.awt.*; 7 | 8 | //测试图表 9 | public class test1 { 10 | private static double[] sampleValues() { 11 | 12 | double[] result = new double[30]; 13 | for (int i = 0; i < result.length; i++) { 14 | result[i] = (int) (Math.random() * 300); 15 | } 16 | return result; 17 | 18 | } 19 | 20 | private static String[] sampleLabels() { 21 | String[] sampleLabels = new String[30]; 22 | 23 | for (int i = 0; i < sampleLabels.length; i++) { 24 | if (0 == i % 5) 25 | sampleLabels[i] = String.valueOf(i + 1 + "日"); 26 | } 27 | return sampleLabels; 28 | } 29 | 30 | public static void main(String[] args) { 31 | JPanel p = new JPanel(); 32 | JLabel l = new JLabel(); 33 | Image img = ChartUtil.getImage(new ReportService().listThisMonthRecords(),400, 300); 34 | Icon icon = new ImageIcon(img); 35 | l.setIcon(icon); 36 | p.add(l); 37 | GUIUtil.showPanel(p); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/gui/listener/MonthPickerListener.java: -------------------------------------------------------------------------------- 1 | package gui.listener; 2 | 3 | import gui.panel.HistoryListPanel; 4 | import gui.panel.MonthPickerPanel; 5 | 6 | import java.awt.event.ActionEvent; 7 | import java.awt.event.ActionListener; 8 | import java.text.ParseException; 9 | import java.text.SimpleDateFormat; 10 | 11 | /** 12 | * MonthPickerPanel 的监听器,按钮后会修改 MonthPickerPanel.instance.date 为 选择月份的月初 13 | * 14 | * @author xenv 15 | * @see MonthPickerPanel 16 | */ 17 | 18 | public class MonthPickerListener implements ActionListener { 19 | @Override 20 | public void actionPerformed(ActionEvent e) { 21 | MonthPickerPanel p = MonthPickerPanel.instance; 22 | Integer year = (Integer) p.cbYear.getSelectedItem(); 23 | Integer month = (Integer) p.cbMonth.getSelectedItem(); 24 | //用SimpleDateFormat获取所选月月初的 Date 25 | try { 26 | p.date = new SimpleDateFormat("yyyy-MM").parse(String.format("%4d-%02d", year, month)); 27 | //更新 HistoryListPanel ,重新获取数据 28 | HistoryListPanel.instance.updateData(); 29 | } catch (ParseException e1) { 30 | e1.printStackTrace(); 31 | } 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/service/ConfigService.java: -------------------------------------------------------------------------------- 1 | package service; 2 | 3 | import dao.ConfigDAO; 4 | import entity.Config; 5 | 6 | /** 7 | * 业务类 ConfigService 对 config 数据库的业务进行封装 8 | */ 9 | 10 | public class ConfigService { 11 | public static final String budget = "budget"; 12 | private static final String default_budget = "500"; 13 | 14 | private static ConfigDAO dao = new ConfigDAO(); 15 | 16 | static { 17 | init(); 18 | } 19 | 20 | //初始化数据库的数据 21 | public static void init() { 22 | init(budget, default_budget); 23 | } 24 | 25 | private static void init(String key, String value) { 26 | Config config = dao.getByKey(key); 27 | if (config == null) { 28 | Config c = new Config(); 29 | c.setKey(key); 30 | c.setValue(value); 31 | dao.add(c); 32 | } 33 | } 34 | 35 | public String get(String key) { 36 | return dao.getByKey(key).getValue(); 37 | } 38 | 39 | public void update(String key, String value) { 40 | Config c = dao.getByKey(key); 41 | c.setValue(value); 42 | dao.update(c); 43 | } 44 | 45 | public int getIntBudget() { 46 | return Integer.parseInt(get(budget)); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/service/CategoryService.java: -------------------------------------------------------------------------------- 1 | package service; 2 | 3 | import dao.CategoryDAO; 4 | import dao.RecordDAO; 5 | import entity.Category; 6 | import entity.Record; 7 | 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * 业务类 CategoryService 对category数据库的业务进行封装 13 | */ 14 | 15 | public class CategoryService { 16 | private CategoryDAO categoryDAO = new CategoryDAO(); 17 | private RecordDAO recordDAO = new RecordDAO(); 18 | 19 | public List list() { 20 | List cs = categoryDAO.list(); 21 | for (Category c : cs) { 22 | List rs = recordDAO.list(c.getId()); 23 | c.setRecordNumber(rs.size()); 24 | } 25 | //lambda表达式实现comparator接口 26 | cs.sort((c1, c2) -> c2.getRecordNumber() - c1.getRecordNumber()); 27 | return cs; 28 | } 29 | 30 | public void add(String name) { 31 | Category c = new Category(); 32 | c.setName(name); 33 | categoryDAO.add(c); 34 | } 35 | 36 | public void update(int id, String name) { 37 | Category c = new Category(); 38 | c.setId(id); 39 | c.setName(name); 40 | categoryDAO.update(c); 41 | } 42 | 43 | public void delete(int id) { 44 | categoryDAO.delete(id); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/gui/page/SpendPage.java: -------------------------------------------------------------------------------- 1 | package gui.page; 2 | 3 | /** 4 | * SpendPanel的页面类 ,用来装载所有数据 5 | * 6 | * @see gui.panel.SpendPanel 7 | */ 8 | public class SpendPage { 9 | public String monthSpend; 10 | public String todaySpend; 11 | public String avgSpendPerDay; 12 | public String monthAvailable; 13 | public String dayAvgAvailable; 14 | public String monthLeftDay; 15 | public int usagePercentage; 16 | public boolean isOverSpend = false; 17 | 18 | public SpendPage(int monthSpend, int todaySpend, int avgSpendPerDay, 19 | int monthAvailable, int dayAvgAvailable, int monthLeftDay, int usagePercentage) { 20 | this.monthSpend = "¥" + monthSpend; 21 | this.todaySpend = "¥" + todaySpend; 22 | this.avgSpendPerDay = "¥" + avgSpendPerDay; 23 | 24 | if (monthAvailable < 0) 25 | isOverSpend = false; 26 | if (!isOverSpend) { 27 | this.monthAvailable = "¥" + monthAvailable; 28 | this.dayAvgAvailable = "¥" + dayAvgAvailable; 29 | } else { 30 | this.monthAvailable = "超支¥" + (-monthAvailable); 31 | this.dayAvgAvailable = "¥" + 0; 32 | } 33 | 34 | this.monthLeftDay = monthLeftDay + "天"; 35 | this.usagePercentage = usagePercentage; 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /src/service/RecordService.java: -------------------------------------------------------------------------------- 1 | package service; 2 | 3 | import dao.RecordDAO; 4 | import entity.Record; 5 | import util.DateUtil; 6 | 7 | import java.util.Date; 8 | import java.util.List; 9 | 10 | /** 11 | * 业务类 RecordService 对 record 数据库的业务进行封装 12 | * 13 | * @author xenv 14 | */ 15 | 16 | public class RecordService { 17 | private static RecordDAO dao = new RecordDAO(); 18 | 19 | public void add(int spend, int cid, String comment, Date date) { 20 | Record r = new Record(); 21 | r.setSpend(spend); 22 | r.setCid(cid); 23 | r.setComment(comment); 24 | r.setDate(date); 25 | dao.add(r); 26 | } 27 | 28 | public void update(int id, int spend, int cid, String comment, Date date) { 29 | Record r = new Record(); 30 | r.setSpend(spend); 31 | r.setId(id); 32 | r.setCid(cid); 33 | r.setComment(comment); 34 | r.setDate(date); 35 | dao.update(r); 36 | } 37 | 38 | public void delete(int id) { 39 | dao.delete(id); 40 | } 41 | 42 | /** 43 | * 获取指定月的 record 数据 44 | * 45 | * @param startDay 指定月的第一天的 Date 46 | * @return record 的列表 47 | */ 48 | public List listMonth(Date startDay) { 49 | Date endDay = DateUtil.monthEnd(startDay); 50 | return dao.list(startDay, endDay); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/entity/Record.java: -------------------------------------------------------------------------------- 1 | package entity; 2 | 3 | import java.util.Date; 4 | 5 | /** 6 | * 实体类 Record 7 | */ 8 | 9 | public class Record { 10 | private int spend; 11 | private int id; 12 | private int cid; 13 | private String comment; 14 | private Date date; 15 | 16 | public Record() { 17 | } 18 | 19 | public Record(int id,int spend, int cid, String comment, Date date) { 20 | this.spend = spend; 21 | this.id = id; 22 | this.cid = cid; 23 | this.comment = comment; 24 | this.date = date; 25 | } 26 | 27 | public int getSpend() { 28 | return spend; 29 | } 30 | 31 | public void setSpend(int spend) { 32 | this.spend = spend; 33 | } 34 | 35 | public int getId() { 36 | return id; 37 | } 38 | 39 | public void setId(int id) { 40 | this.id = id; 41 | } 42 | 43 | public int getCid() { 44 | return cid; 45 | } 46 | 47 | public void setCid(int cid) { 48 | this.cid = cid; 49 | } 50 | 51 | public String getComment() { 52 | return comment; 53 | } 54 | 55 | public void setComment(String comment) { 56 | this.comment = comment; 57 | } 58 | 59 | public Date getDate() { 60 | return date; 61 | } 62 | 63 | public void setDate(Date date) { 64 | this.date = date; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/gui/model/CategoryComboBoxModel.java: -------------------------------------------------------------------------------- 1 | package gui.model; 2 | 3 | import entity.Category; 4 | import service.CategoryService; 5 | 6 | import java.util.List; 7 | 8 | import javax.swing.ComboBoxModel; 9 | import javax.swing.event.ListDataListener; 10 | 11 | /** 12 | * CategoryPanel 的 ComboBox 的数据模型,实现了 ComboBoxModel<> 接口 13 | * 14 | * @see gui.panel.CategoryPanel 15 | */ 16 | 17 | public class CategoryComboBoxModel implements ComboBoxModel { 18 | //从service层获取数据 19 | public List cs = new CategoryService().list(); 20 | public Category c; 21 | 22 | public CategoryComboBoxModel() { 23 | if (!cs.isEmpty()) 24 | c = cs.get(0); 25 | } 26 | 27 | @Override 28 | public int getSize() { 29 | return cs.size(); 30 | } 31 | 32 | @Override 33 | public Category getElementAt(int index) { 34 | return cs.get(index); 35 | } 36 | 37 | @Override 38 | public void addListDataListener(ListDataListener l) { 39 | 40 | } 41 | 42 | @Override 43 | public void removeListDataListener(ListDataListener l) { 44 | 45 | } 46 | 47 | @Override 48 | //被选中就把选中的对象存到模型 49 | public void setSelectedItem(Object anItem) { 50 | c = (Category) anItem; 51 | } 52 | 53 | @Override 54 | //获取选中的时候从模型读出 55 | public Object getSelectedItem() { 56 | return c; 57 | } 58 | 59 | } -------------------------------------------------------------------------------- /src/gui/listener/ConfigListener.java: -------------------------------------------------------------------------------- 1 | package gui.listener; 2 | 3 | import gui.panel.ConfigPanel; 4 | import service.ConfigService; 5 | import util.DBUtil; 6 | import util.GUIUtil; 7 | import util.SQLUtil; 8 | 9 | import javax.swing.*; 10 | import java.awt.event.ActionEvent; 11 | import java.awt.event.ActionListener; 12 | 13 | /** 14 | * ConfigPanel的监听器,监听按钮后进行config的改操作 和 调用工具类进行重置操作 15 | * 16 | * @author xenv 17 | * @see ConfigPanel 18 | */ 19 | 20 | public class ConfigListener implements ActionListener { 21 | @Override 22 | public void actionPerformed(ActionEvent e) { 23 | ConfigPanel p = ConfigPanel.instance; 24 | if (p.bSubmit == e.getSource()) { 25 | if (!GUIUtil.checkNumber(p.tfBudget, "本月预算")) { 26 | return; 27 | } 28 | ConfigService service = new ConfigService(); 29 | //改操作 30 | service.update(ConfigService.budget, p.tfBudget.getText()); 31 | 32 | JOptionPane.showMessageDialog(p, "设置成功"); 33 | } 34 | 35 | if (p.bTruncate == e.getSource()) { 36 | if (JOptionPane.OK_OPTION != JOptionPane.showConfirmDialog(p, "确实清空所有数据?")) { 37 | return; 38 | } 39 | SQLUtil.truncate(); 40 | //重新初始化数据库 41 | ConfigService.init(); 42 | JOptionPane.showMessageDialog(p, "重置成功"); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/gui/listener/ToolBarListener.java: -------------------------------------------------------------------------------- 1 | package gui.listener; 2 | 3 | import gui.panel.*; 4 | 5 | import javax.swing.*; 6 | import java.awt.event.ActionEvent; 7 | import java.awt.event.ActionListener; 8 | 9 | /** 10 | * MainPanel 的监听器,监听 Toolbar 的按钮操作并切换面板 11 | * workingPanel有方法 .show(WorkingPanel p) 可以居中显示子面板 并 更新数据 12 | * @see MainPanel 13 | */ 14 | 15 | public class ToolBarListener implements ActionListener { 16 | @Override 17 | public void actionPerformed(ActionEvent e) { 18 | MainPanel p = MainPanel.instance; 19 | JButton b = (JButton) e.getSource(); 20 | if (b == p.bBackup) { 21 | p.workingPanel.show(BackupPanel.instance); 22 | } 23 | if (b == p.bCategory) { 24 | p.workingPanel.show(CategoryPanel.instance); 25 | } 26 | if (b == p.bRecover) { 27 | p.workingPanel.show(RecoverPanel.instance); 28 | } 29 | if (b == p.bConfig) { 30 | p.workingPanel.show(ConfigPanel.instance); 31 | } 32 | if (b == p.bRecord) { 33 | p.workingPanel.show(RecordPanel.instance); 34 | } 35 | if (b == p.bReport) { 36 | p.workingPanel.show(ReportPanel.instance); 37 | } 38 | if (b == p.bSpend) { 39 | p.workingPanel.show(SpendPanel.instance); 40 | } 41 | if (b == p.bHistory) { 42 | p.workingPanel.show(HistoryPanel.instance); 43 | } 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/service/SpendService.java: -------------------------------------------------------------------------------- 1 | package service; 2 | 3 | import dao.RecordDAO; 4 | import entity.Record; 5 | import gui.page.SpendPage; 6 | import util.DateUtil; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * 业务类 SpendService 对 多个 数据库的业务进行封装 供 SpendPanel 使用 12 | * 13 | * @see gui.panel.SpendPanel 14 | */ 15 | 16 | public class SpendService { 17 | public SpendPage getSpendPage() { 18 | RecordDAO dao = new RecordDAO(); 19 | 20 | List thisMonthRecords = dao.listThisMonth(); 21 | List todayRecords = dao.listToday(); 22 | int thisMonthTotalday = DateUtil.thisMonthTotalDay(); 23 | 24 | int monthSpend = 0; 25 | int todaySpend = 0; 26 | int avgSpendPerDay = 0; 27 | int monthAvailable = 0; 28 | int dayAvgAvailable = 0; 29 | int monthLeftDay = 0; 30 | int usagePercentage = 0; 31 | 32 | int monthBudget = new ConfigService().getIntBudget(); 33 | 34 | for (Record record : thisMonthRecords) { 35 | monthSpend += record.getSpend(); 36 | } 37 | 38 | for (Record record : todayRecords) { 39 | todaySpend += record.getSpend(); 40 | } 41 | avgSpendPerDay = monthSpend / thisMonthTotalday; 42 | monthAvailable = monthBudget - monthSpend; 43 | monthLeftDay = DateUtil.thisMonthLeftDay(); 44 | dayAvgAvailable = monthAvailable / monthLeftDay; 45 | usagePercentage = monthSpend * 100 / monthBudget; 46 | 47 | return new SpendPage(monthSpend, todaySpend, avgSpendPerDay, monthAvailable, dayAvgAvailable, monthLeftDay, usagePercentage); 48 | } 49 | 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/gui/listener/RecoverListener.java: -------------------------------------------------------------------------------- 1 | package gui.listener; 2 | 3 | import java.awt.event.ActionEvent; 4 | import java.awt.event.ActionListener; 5 | import java.io.File; 6 | 7 | import javax.swing.JFileChooser; 8 | import javax.swing.JOptionPane; 9 | import javax.swing.filechooser.FileFilter; 10 | 11 | import gui.panel.BackupPanel; 12 | import gui.panel.ConfigPanel; 13 | import gui.panel.MainPanel; 14 | import service.ConfigService; 15 | import util.SQLUtil; 16 | 17 | /** 18 | * RecoverPanel 的监听器,监听按钮动作后进行导入操作 19 | */ 20 | 21 | public class RecoverListener implements ActionListener { 22 | 23 | @Override 24 | public void actionPerformed(ActionEvent e) { 25 | BackupPanel p = BackupPanel.instance; 26 | 27 | JFileChooser fc = new JFileChooser(); 28 | fc.setSelectedFile(new File("xiaoxiao.db")); 29 | fc.setFileFilter(new FileFilter() { 30 | 31 | @Override 32 | public String getDescription() { 33 | return ".db"; 34 | } 35 | 36 | @Override 37 | public boolean accept(File f) { 38 | return f.getName().toLowerCase().endsWith(".db"); 39 | } 40 | }); 41 | 42 | int returnVal = fc.showOpenDialog(p); 43 | File file = fc.getSelectedFile(); 44 | if (returnVal == JFileChooser.APPROVE_OPTION) { 45 | try { 46 | SQLUtil.recover(file.getAbsolutePath()); 47 | JOptionPane.showMessageDialog(p, "恢复成功"); 48 | } catch (Exception e1) { 49 | e1.printStackTrace(); 50 | JOptionPane.showMessageDialog(p, "恢复失败\r\n,错误:\r\n" + e1.getMessage()); 51 | } 52 | 53 | } 54 | } 55 | 56 | } -------------------------------------------------------------------------------- /src/service/ReportService.java: -------------------------------------------------------------------------------- 1 | package service; 2 | 3 | import dao.RecordDAO; 4 | import entity.Record; 5 | import util.DateUtil; 6 | 7 | import java.util.ArrayList; 8 | import java.util.Calendar; 9 | import java.util.Date; 10 | import java.util.List; 11 | 12 | /** 13 | * 业务类 ReportService 对 record 数据库的业务进行封装 供 ReportPanel 使用 14 | * 15 | * @see gui.panel.ReportPanel 16 | */ 17 | public class ReportService { 18 | /** 19 | * @param d 指定的一天 20 | * @param monthRawData 这个月的所有数据的 record了列表 21 | * @return 统计这一天花了多少钱 22 | */ 23 | private int getDaySpend(Date d, List monthRawData) { 24 | int daySpend = 0; 25 | for (Record record : monthRawData) { 26 | if (record.getDate().equals(d)) 27 | daySpend += record.getSpend(); 28 | } 29 | return daySpend; 30 | } 31 | 32 | /** 33 | * @return 一个当前月每天的 record 列表 34 | */ 35 | public List listThisMonthRecords() { 36 | RecordDAO dao = new RecordDAO(); 37 | List monthRawData = dao.listThisMonth(); 38 | List result = new ArrayList<>(); 39 | Date monthBegin = DateUtil.monthBegin(); 40 | int monthTotalDay = DateUtil.thisMonthTotalDay(); 41 | Calendar c = Calendar.getInstance(); 42 | for (int i = 0; i < monthTotalDay; i++) { 43 | Record r = new Record(); 44 | c.setTime(monthBegin); 45 | c.add(Calendar.DATE, i); 46 | Date theDayOfThisMonth = c.getTime(); 47 | int daySpend = getDaySpend(theDayOfThisMonth, monthRawData); 48 | r.setSpend(daySpend); 49 | result.add(r); 50 | } 51 | return result; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/gui/model/CategoryTableModel.java: -------------------------------------------------------------------------------- 1 | package gui.model; 2 | 3 | import entity.Category; 4 | import service.CategoryService; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | import javax.swing.event.TableModelListener; 10 | import javax.swing.table.TableModel; 11 | 12 | /** 13 | * CategoryPanel 的 Table 的数据模型,实现了 TableModel 接口 14 | * 15 | * @see gui.panel.CategoryPanel 16 | */ 17 | 18 | public class CategoryTableModel implements TableModel{ 19 | //列 20 | private String[] columnNames = new String[]{"分类名称","消费次数"}; 21 | //行数据 22 | public List cs = new CategoryService().list(); 23 | 24 | @Override 25 | public int getRowCount() { 26 | return cs.size(); 27 | } 28 | 29 | @Override 30 | public int getColumnCount() { 31 | return columnNames.length; 32 | } 33 | 34 | @Override 35 | public String getColumnName(int columnIndex) { 36 | return columnNames[columnIndex]; 37 | } 38 | 39 | @Override 40 | public Class getColumnClass(int columnIndex) { 41 | return String.class; 42 | } 43 | 44 | @Override 45 | public boolean isCellEditable(int rowIndex, int columnIndex) { 46 | return false; 47 | } 48 | 49 | @Override 50 | public Object getValueAt(int rowIndex, int columnIndex) { 51 | if(0==columnIndex) 52 | return cs.get(rowIndex).getName(); 53 | if(1==columnIndex) 54 | return cs.get(rowIndex).getRecordNumber(); 55 | return null; 56 | } 57 | 58 | @Override 59 | public void setValueAt(Object aValue, int rowIndex, int columnIndex) { 60 | 61 | } 62 | 63 | @Override 64 | public void addTableModelListener(TableModelListener l) { 65 | 66 | } 67 | 68 | @Override 69 | public void removeTableModelListener(TableModelListener l) { 70 | 71 | } 72 | } -------------------------------------------------------------------------------- /src/gui/listener/BackupListener.java: -------------------------------------------------------------------------------- 1 | package gui.listener; 2 | 3 | import java.awt.event.ActionEvent; 4 | import java.awt.event.ActionListener; 5 | import java.io.File; 6 | 7 | import javax.swing.JFileChooser; 8 | import javax.swing.JOptionPane; 9 | import javax.swing.filechooser.FileFilter; 10 | 11 | import gui.panel.BackupPanel; 12 | import util.SQLUtil; 13 | 14 | /** 15 | * BackupPanel的监听器,监听按钮动作后进行导出操作 16 | * 17 | * @author xenv 18 | * @see BackupPanel 19 | */ 20 | 21 | public class BackupListener implements ActionListener { 22 | 23 | @Override 24 | public void actionPerformed(ActionEvent e) { 25 | BackupPanel p = BackupPanel.instance; 26 | //拉起选择器 27 | JFileChooser fc = new JFileChooser(); 28 | fc.setSelectedFile(new File("xiaoxiao.db")); 29 | //定义过滤器 30 | fc.setFileFilter(new FileFilter() { 31 | 32 | @Override 33 | public String getDescription() { 34 | return ".db"; 35 | } 36 | 37 | @Override 38 | public boolean accept(File f) { 39 | return f.getName().toLowerCase().endsWith(".db"); 40 | } 41 | }); 42 | 43 | int returnVal = fc.showSaveDialog(p); 44 | File file = fc.getSelectedFile(); 45 | //捕捉是否点击保存 46 | if (returnVal == JFileChooser.APPROVE_OPTION) { 47 | //如果保存的文件名没有以.db结尾,自动加上.db 48 | System.out.println(file); 49 | if (!file.getName().toLowerCase().endsWith(".db")) 50 | file = new File(file.getParent(), file.getName() + ".db"); 51 | System.out.println(file); 52 | 53 | try { 54 | SQLUtil.backup(file.getAbsolutePath()); 55 | JOptionPane.showMessageDialog(p, "备份成功,备份文件位于:\r\n" + file.getAbsolutePath()); 56 | } catch (Exception e1) { 57 | e1.printStackTrace(); 58 | JOptionPane.showMessageDialog(p, "备份失败\r\n,错误:\r\n" + e1.getMessage()); 59 | } 60 | 61 | } 62 | } 63 | 64 | } -------------------------------------------------------------------------------- /src/gui/panel/ConfigPanel.java: -------------------------------------------------------------------------------- 1 | package gui.panel; 2 | 3 | import java.awt.BorderLayout; 4 | import java.awt.GridLayout; 5 | 6 | import javax.swing.JButton; 7 | import javax.swing.JLabel; 8 | import javax.swing.JPanel; 9 | import javax.swing.JTextField; 10 | 11 | import gui.listener.ConfigListener; 12 | import service.ConfigService; 13 | import util.ColorUtil; 14 | import util.GUIUtil; 15 | 16 | /** 17 | * 界面类 ConfigPanel 设置页 18 | */ 19 | 20 | public class ConfigPanel extends WorkingPanel { 21 | static{ 22 | GUIUtil.useLNF(); 23 | } 24 | public static ConfigPanel instance = new ConfigPanel(); 25 | 26 | 27 | private JLabel lBudget = new JLabel("本月预算(¥)"); 28 | public JTextField tfBudget = new JTextField(); 29 | public JButton bTruncate = new JButton("重置数据库"); 30 | public JButton bSubmit = new JButton("更新"); 31 | 32 | public ConfigPanel() { 33 | GUIUtil.setColor(ColorUtil.grayColor, lBudget); 34 | GUIUtil.setColor(ColorUtil.blueColor, bSubmit); 35 | 36 | JPanel pNorth =new JPanel(); 37 | JPanel pSouth = new JPanel(); 38 | int gap =40; 39 | pNorth.setLayout(new GridLayout(3,1,gap,gap)); 40 | 41 | pNorth.add(lBudget); 42 | pNorth.add(tfBudget); 43 | pNorth.add(bSubmit); 44 | this.setLayout(new BorderLayout()); 45 | this.add(pNorth,BorderLayout.NORTH); 46 | 47 | 48 | pSouth.add(bTruncate); 49 | this.add(pSouth,BorderLayout.SOUTH); 50 | 51 | addListener(); 52 | } 53 | public void addListener(){ 54 | ConfigListener l =new ConfigListener(); 55 | bSubmit.addActionListener(l); 56 | bTruncate.addActionListener(l); 57 | } 58 | public void updateData(){ 59 | ConfigService service = new ConfigService(); 60 | tfBudget.setText(service.get(ConfigService.budget)); 61 | tfBudget.grabFocus(); 62 | } 63 | public static void main(String[] args) { 64 | GUIUtil.showPanel(ConfigPanel.instance); 65 | } 66 | 67 | } -------------------------------------------------------------------------------- /src/gui/listener/RecordListener.java: -------------------------------------------------------------------------------- 1 | package gui.listener; 2 | 3 | import entity.Category; 4 | import gui.panel.*; 5 | import service.RecordService; 6 | import util.GUIUtil; 7 | 8 | import javax.swing.*; 9 | import java.awt.event.ActionEvent; 10 | import java.awt.event.ActionListener; 11 | import java.util.Date; 12 | 13 | /** 14 | * RecordPanel 的监听器,按钮后会 增改Record 15 | * 增改由 RecordPanel.instance.updateId 决定 ,默认为 -1 ,可能被 HistoryListPanel 修改 16 | * 17 | * @author xenv 18 | * @see RecordPanel 19 | * @see HistoryListPanel 20 | * @see HistoryListListener 21 | */ 22 | 23 | public class RecordListener implements ActionListener { 24 | @Override 25 | public void actionPerformed(ActionEvent e) { 26 | RecordPanel p = RecordPanel.instance; 27 | //判断数据 28 | if (p.cbModel.cs.size() == 0) { 29 | JOptionPane.showMessageDialog(p, "请先添加分类"); 30 | } 31 | String spend = p.tfSpend.getText(); 32 | if (!GUIUtil.checkNumber(p.tfSpend, "输入的金额")) { 33 | return; 34 | } 35 | if (spend.equals("0")) { 36 | JOptionPane.showMessageDialog(p, "输入金额有误"); 37 | } 38 | Category c = p.getSelectedCategory(); 39 | String comment = p.tfComment.getText(); 40 | Date d = p.datepick.getDate(); 41 | //根据 updateId 确定模式 42 | if (p.updateId < 0) { //默认的添加模式 43 | new RecordService().add(Integer.parseInt(spend), c.getId(), comment, d); 44 | JOptionPane.showMessageDialog(p, "添加成功"); 45 | 46 | MainPanel.instance.workingPanel.show(SpendPanel.instance); 47 | } else { //修改模式 48 | new RecordService().update(p.updateId, Integer.parseInt(spend), c.getId(), comment, d); 49 | JOptionPane.showMessageDialog(p, "修改成功"); 50 | MainPanel.instance.workingPanel.show(HistoryPanel.instance); 51 | //重置p.updateId 52 | p.updateId = -1; 53 | //刷新 HistoryListPanel 54 | HistoryListPanel.instance.updateData(); 55 | } 56 | 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/gui/panel/HistoryListPanel.java: -------------------------------------------------------------------------------- 1 | package gui.panel; 2 | 3 | import entity.Record; 4 | import gui.listener.HistoryListListener; 5 | import gui.model.RecordTableModel; 6 | import service.RecordService; 7 | import util.ColorUtil; 8 | import util.GUIUtil; 9 | 10 | import javax.swing.*; 11 | import java.awt.*; 12 | 13 | /** 14 | * HistoryListPanel 是 HistoryPanel 中的历史记录面板 15 | * @see HistoryPanel 16 | * 17 | * @author xenv 18 | */ 19 | public class HistoryListPanel extends WorkingPanel { 20 | static { 21 | GUIUtil.useLNF(); 22 | } 23 | 24 | public static HistoryListPanel instance = new HistoryListPanel(); 25 | public JButton bAdd = new JButton("新增"); 26 | public JButton bEdit = new JButton("编辑"); 27 | public JButton bDelete = new JButton("删除"); 28 | 29 | private RecordTableModel rtm = new RecordTableModel(); 30 | private JTable t =new JTable(rtm); 31 | 32 | private HistoryListPanel(){ 33 | GUIUtil.setColor(ColorUtil.blueColor, bAdd,bEdit,bDelete); 34 | JScrollPane sp =new JScrollPane(t); 35 | JPanel pSubmit = new JPanel(); 36 | pSubmit.add(bAdd); 37 | pSubmit.add(bEdit); 38 | pSubmit.add(bDelete); 39 | 40 | this.setLayout(new BorderLayout()); 41 | this.add(sp,BorderLayout.CENTER); 42 | this.add(pSubmit,BorderLayout.SOUTH); 43 | 44 | this.addListener(); 45 | } 46 | public static void main(String[] args) { 47 | GUIUtil.showPanel(HistoryListPanel.instance); 48 | } 49 | public boolean checkSelected(){ 50 | return t.getSelectedRow()>=0; 51 | } 52 | public Record getSelectedRecord(){ 53 | int index = t.getSelectedRow(); 54 | return rtm.rs.get(index>0?index:0); 55 | } 56 | @Override 57 | public void updateData() { 58 | rtm.rs = new RecordService().listMonth(MonthPickerPanel.instance.date); 59 | t.updateUI(); 60 | } 61 | 62 | @Override 63 | public void addListener() { 64 | HistoryListListener l = new HistoryListListener(); 65 | bDelete.addActionListener(l); 66 | bEdit.addActionListener(l); 67 | bAdd.addActionListener(l); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/gui/panel/MonthPickerPanel.java: -------------------------------------------------------------------------------- 1 | package gui.panel; 2 | 3 | import gui.listener.MonthPickerListener; 4 | import util.DateUtil; 5 | import util.GUIUtil; 6 | 7 | import javax.swing.*; 8 | import java.awt.*; 9 | import java.util.Date; 10 | 11 | /** 12 | * MonthPickerPanel 是 HistoryPanel 中的月份选择器 13 | * 外部通过调用 MonthPickerPanel.instance.date 来获取选择器的时间 14 | * 本类写死了起始年份并保证了一定的年份使用的扩展性 15 | * 16 | * @author xenv 17 | * @see HistoryPanel 18 | */ 19 | 20 | public class MonthPickerPanel extends WorkingPanel { 21 | static { 22 | GUIUtil.useLNF(); 23 | } 24 | 25 | public static MonthPickerPanel instance = new MonthPickerPanel(); 26 | //写死起始年份 27 | private final int startYear = 2017; 28 | //当前面板实例的时间 29 | public Date date = DateUtil.monthBegin(); 30 | public JComboBox cbMonth = new JComboBox<>(makeMonths()); 31 | public JComboBox cbYear = new JComboBox<>(makeYears()); 32 | private JButton bSubmit = new JButton("查询"); 33 | 34 | private MonthPickerPanel() { 35 | this.setLayout(new GridLayout(1, 3, 8, 8)); 36 | //调整到当前月 37 | cbYear.setSelectedIndex(DateUtil.thisYear() - startYear); 38 | cbMonth.setSelectedIndex(DateUtil.thisMonth()); 39 | this.add(cbYear); 40 | this.add(cbMonth); 41 | this.add(bSubmit); 42 | addListener(); 43 | } 44 | 45 | /** 46 | * @return 2017 - 今年的Integer数组 47 | */ 48 | private Integer[] makeYears() { 49 | int thisYear = DateUtil.thisYear(); 50 | Integer[] result = new Integer[thisYear - startYear + 1]; 51 | for (int i = 0; i <= thisYear - startYear; i++) { 52 | result[i] = startYear + i; 53 | } 54 | return result; 55 | } 56 | 57 | /** 58 | * @return 1-12的Integer数组 59 | */ 60 | private Integer[] makeMonths() { 61 | Integer[] result = new Integer[12]; 62 | for (int i = 0; i < 12; i++) { 63 | result[i] = i + 1; 64 | } 65 | return result; 66 | } 67 | 68 | @Override 69 | public void updateData() { 70 | 71 | } 72 | 73 | @Override 74 | public void addListener() { 75 | bSubmit.addActionListener(new MonthPickerListener()); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/gui/model/RecordTableModel.java: -------------------------------------------------------------------------------- 1 | package gui.model; 2 | 3 | import dao.CategoryDAO; 4 | import entity.Record; 5 | import gui.panel.MonthPickerPanel; 6 | import service.RecordService; 7 | 8 | import javax.swing.event.TableModelListener; 9 | import javax.swing.table.TableModel; 10 | import java.util.List; 11 | 12 | /** 13 | * HistoryListPanel 的 Table 的数据模型,实现了 TableModel 接口 14 | * 15 | * @author xenv 16 | * @see gui.panel.HistoryListPanel 17 | */ 18 | 19 | public class RecordTableModel implements TableModel { 20 | private String[] columnNames = new String[]{"ID", "花费", "分类", "备注", "日期"}; 21 | public List rs = new RecordService().listMonth(MonthPickerPanel.instance.date); 22 | 23 | @Override 24 | public int getRowCount() { 25 | return rs.size(); 26 | } 27 | 28 | @Override 29 | public int getColumnCount() { 30 | return columnNames.length; 31 | } 32 | 33 | @Override 34 | public String getColumnName(int columnIndex) { 35 | return columnNames[columnIndex]; 36 | } 37 | 38 | @Override 39 | public Class getColumnClass(int columnIndex) { 40 | return String.class; 41 | } 42 | 43 | @Override 44 | public boolean isCellEditable(int rowIndex, int columnIndex) { 45 | return false; 46 | } 47 | 48 | @Override 49 | public Object getValueAt(int rowIndex, int columnIndex) { 50 | if (0 == columnIndex) 51 | return rs.get(rowIndex).getId(); 52 | if (1 == columnIndex) 53 | return rs.get(rowIndex).getSpend(); 54 | 55 | if (2 == columnIndex) { 56 | int cid = rs.get(rowIndex).getCid(); 57 | return new CategoryDAO().get(cid).getName(); 58 | } 59 | if (3 == columnIndex) 60 | return rs.get(rowIndex).getComment(); 61 | if (4 == columnIndex) 62 | return rs.get(rowIndex).getDate(); 63 | 64 | return null; 65 | } 66 | 67 | @Override 68 | public void setValueAt(Object aValue, int rowIndex, int columnIndex) { 69 | 70 | } 71 | 72 | @Override 73 | public void addTableModelListener(TableModelListener l) { 74 | 75 | } 76 | 77 | @Override 78 | public void removeTableModelListener(TableModelListener l) { 79 | 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/gui/panel/CategoryPanel.java: -------------------------------------------------------------------------------- 1 | package gui.panel; 2 | 3 | import java.awt.BorderLayout; 4 | 5 | import javax.swing.JButton; 6 | import javax.swing.JPanel; 7 | import javax.swing.JScrollPane; 8 | import javax.swing.JTable; 9 | 10 | import entity.Category; 11 | import gui.listener.CategoryListener; 12 | import gui.model.CategoryTableModel; 13 | import service.CategoryService; 14 | import util.ColorUtil; 15 | import util.GUIUtil; 16 | 17 | /** 18 | * 界面类 CategoryPanel 分类页 19 | */ 20 | 21 | public class CategoryPanel extends WorkingPanel{ 22 | static{ 23 | GUIUtil.useLNF(); 24 | } 25 | public static CategoryPanel instance = new CategoryPanel(); 26 | 27 | public JButton bAdd = new JButton("新增"); 28 | public JButton bEdit = new JButton("编辑"); 29 | public JButton bDelete = new JButton("删除"); 30 | 31 | private CategoryTableModel ctm = new CategoryTableModel(); 32 | private JTable t =new JTable(ctm); 33 | 34 | public CategoryPanel() { 35 | GUIUtil.setColor(ColorUtil.blueColor, bAdd,bEdit,bDelete); 36 | JScrollPane sp =new JScrollPane(t); 37 | JPanel pSubmit = new JPanel(); 38 | pSubmit.add(bAdd); 39 | pSubmit.add(bEdit); 40 | pSubmit.add(bDelete); 41 | 42 | this.setLayout(new BorderLayout()); 43 | this.add(sp,BorderLayout.CENTER); 44 | this.add(pSubmit,BorderLayout.SOUTH); 45 | 46 | this.addListener(); 47 | } 48 | 49 | public static void main(String[] args) { 50 | GUIUtil.showPanel(CategoryPanel.instance); 51 | } 52 | public boolean checkSelected(){ 53 | return t.getSelectedRow()>=0; 54 | } 55 | public Category getSelectedCategory(){ 56 | int index = t.getSelectedRow(); 57 | return ctm.cs.get(index>0?index:0); 58 | } 59 | public void updateData(){ 60 | ctm.cs = new CategoryService().list(); 61 | t.updateUI(); 62 | if(0==ctm.cs.size()){ 63 | bEdit.setEnabled(false); 64 | bDelete.setEnabled(false); 65 | }else{ 66 | bEdit.setEnabled(true); 67 | bDelete.setEnabled(true); 68 | } 69 | } 70 | public void addListener(){ 71 | CategoryListener categoryListener = new CategoryListener(); 72 | bDelete.addActionListener(categoryListener); 73 | bEdit.addActionListener(categoryListener); 74 | bAdd.addActionListener(categoryListener); 75 | } 76 | } -------------------------------------------------------------------------------- /src/util/SQLUtil.java: -------------------------------------------------------------------------------- 1 | package util; 2 | 3 | 4 | import java.io.File; 5 | import java.io.FileInputStream; 6 | import java.io.FileOutputStream; 7 | import java.io.IOException; 8 | import java.sql.Connection; 9 | import java.sql.SQLException; 10 | import java.sql.Statement; 11 | 12 | /** 13 | * 工具类 SQLUtil 数据库导入,导出和清空 14 | * 15 | * @author xenv 16 | */ 17 | public class SQLUtil { 18 | /** 19 | * 数据库源文件对象 20 | */ 21 | private static final File SQLFile = new File(DBUtil.database); 22 | 23 | /** 24 | * 直接复制数据库文件到指定文件 25 | * 26 | * @param filePath : 导出数据库的文件路径,是以.db结尾的绝对路径 27 | * @throws IOException : 导出文件中可能遇到IO错误 28 | */ 29 | public static void backup(String filePath) throws IOException { 30 | //获取目标文件对象 31 | File toFile = new File(filePath); 32 | //新建字节流 33 | try (FileInputStream is = new FileInputStream(SQLFile); 34 | FileOutputStream os = new FileOutputStream(toFile)) { 35 | byte[] bytes = new byte[(int) SQLFile.length()]; 36 | //读取字节数组 37 | int result = is.read(bytes); 38 | //写出字节数组 39 | os.write(bytes); 40 | //清理 41 | os.flush(); 42 | } 43 | } 44 | 45 | /** 46 | * 从指定文件导入到数据库文件 47 | * 48 | * @param filePath 指定备份文件的路径 49 | * @throws IOException : 导出文件中可能遇到IO错误 50 | */ 51 | public static void recover(String filePath) throws IOException { 52 | //获取来源文件对象 53 | File fromFile = new File(filePath); 54 | //字节流复制文件 55 | try (FileInputStream is = new FileInputStream(fromFile); 56 | FileOutputStream os = new FileOutputStream(SQLFile)) { 57 | byte[] bytes = new byte[(int) fromFile.length()]; 58 | //读取字节数组 59 | int result = is.read(bytes); 60 | //写出字节数组 61 | os.write(bytes); 62 | //清理 63 | os.flush(); 64 | } 65 | } 66 | 67 | /** 68 | * 清空数据库,重置自增值 69 | */ 70 | public static void truncate(){ 71 | try(Connection c = DBUtil.getConnection(); 72 | Statement s = c.createStatement()){ 73 | s.execute("delete from config;"); 74 | s.execute("delete from record;"); 75 | s.execute("delete from category;"); 76 | s.execute("delete from sqlite_sequence;"); 77 | }catch (SQLException e){ 78 | e.printStackTrace(); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/gui/listener/CategoryListener.java: -------------------------------------------------------------------------------- 1 | package gui.listener; 2 | 3 | import entity.Category; 4 | import gui.panel.CategoryPanel; 5 | import service.CategoryService; 6 | 7 | import javax.swing.*; 8 | import java.awt.event.ActionEvent; 9 | import java.awt.event.ActionListener; 10 | 11 | /** 12 | * CategoryPanel的监听器,监听按钮后进行增改删操作 13 | * 14 | * @see CategoryPanel 15 | */ 16 | 17 | public class CategoryListener implements ActionListener { 18 | @Override 19 | public void actionPerformed(ActionEvent e) { 20 | CategoryService categoryService = new CategoryService(); 21 | CategoryPanel p = CategoryPanel.instance; 22 | //拉回按钮比对看用户按了哪个 23 | JButton b = (JButton) e.getSource(); 24 | if (p.bAdd == b) { 25 | //检查数据 26 | String name = JOptionPane.showInputDialog(null); 27 | if (null == name) { 28 | return; 29 | } 30 | if (0 == name.length()) { 31 | JOptionPane.showMessageDialog(p, "名称不为空"); 32 | return; 33 | } 34 | categoryService.add(name); 35 | } 36 | if (p.bEdit == b) { 37 | //检查数据 38 | if (!p.checkSelected()) { 39 | JOptionPane.showMessageDialog(p, "请先选择一行"); 40 | return; 41 | } 42 | Category c = p.getSelectedCategory(); 43 | int id = c.getId(); 44 | String name = JOptionPane.showInputDialog("修改名称", c.getName()); 45 | if (null == name) { 46 | return; 47 | } 48 | if (0 == name.length()) { 49 | JOptionPane.showMessageDialog(p, "名称不为空"); 50 | return; 51 | } 52 | categoryService.update(id, name); 53 | } 54 | if (p.bDelete == b) { 55 | //检查数据 56 | if (!p.checkSelected()) { 57 | JOptionPane.showMessageDialog(p, "请先选择一行"); 58 | return; 59 | } 60 | Category c = p.getSelectedCategory(); 61 | //外键约束所以不能直接删 62 | if (0 != c.getRecordNumber()) { 63 | JOptionPane.showMessageDialog(p, "分类下还有数据"); 64 | return; 65 | } 66 | if (JOptionPane.OK_OPTION != JOptionPane.showConfirmDialog(p, "确实删除?")) { 67 | return; 68 | } 69 | int id = c.getId(); 70 | categoryService.delete(id); 71 | } 72 | p.updateData(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/util/CenterPanel.java: -------------------------------------------------------------------------------- 1 | package util; 2 | 3 | import gui.panel.WorkingPanel; 4 | 5 | import javax.swing.*; 6 | import java.awt.*; 7 | 8 | /** 9 | * 工具类 CenterPanel 居中面板,实现了一个 可以有一个子面板 并且该子面板 居中 的面板 10 | */ 11 | 12 | public class CenterPanel extends JPanel { 13 | private double rate; 14 | private JComponent c; 15 | private boolean stretch; 16 | 17 | /** 18 | * @param rate 拉伸比列 19 | * @param stretch 是否拉伸 20 | */ 21 | public CenterPanel(double rate, boolean stretch) { 22 | this.setLayout(null); 23 | this.rate = rate; 24 | this.stretch = stretch; 25 | } 26 | 27 | public CenterPanel(double rate) { 28 | this(rate, true); 29 | } 30 | 31 | /** 32 | * swing在更新界面的时候会调用这个方法 33 | */ 34 | public void repaint() { 35 | //只对本类的swing组件进行操作,其他不管 36 | if (null != c) { 37 | Dimension containerSize = this.getSize(); 38 | Dimension componentSize = c.getPreferredSize(); 39 | //如果是拉伸 40 | if (stretch) 41 | c.setSize((int) (containerSize.width * rate), 42 | (int) (containerSize.height * rate)); 43 | else 44 | c.setSize(componentSize); 45 | //重置位置使其居中 46 | c.setLocation(containerSize.width / 2 - c.getSize().width / 2, 47 | containerSize.height / 2 - c.getSize().height / 2); 48 | } 49 | //调用父方法更新 50 | super.repaint(); 51 | } 52 | 53 | /** 54 | * 新建一个CenterPanel后可以用show方法,就可以将 一个子面板 进行居中显示 55 | * 56 | * @param p 待居中的子面板 57 | */ 58 | public void show(JComponent p) { 59 | this.c = p; 60 | //获取当前面板的所有子面板 61 | Component[] cs = getComponents(); 62 | //全部清除 63 | for (Component c : cs) { 64 | remove(c); 65 | } 66 | //加进来一个子面板 67 | add(p); 68 | //如果是一个实现了 WorkingPanel 的子类,会执行它的 updateData() 方法 69 | if ((p instanceof WorkingPanel)) { 70 | ((WorkingPanel) p).updateData(); 71 | } 72 | //居中处理 73 | this.updateUI(); 74 | } 75 | 76 | //测试用 77 | public static void main(String[] args) { 78 | JFrame f = new JFrame(); 79 | f.setSize(400, 400); 80 | f.setLocationRelativeTo(null); 81 | CenterPanel cp = new CenterPanel(0.85, true); 82 | f.setContentPane(cp); 83 | f.setDefaultCloseOperation(3); 84 | f.setVisible(true); 85 | JButton b = new JButton("abc"); 86 | cp.show(b); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/util/GUIUtil.java: -------------------------------------------------------------------------------- 1 | package util; 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | import java.io.File; 6 | 7 | /** 8 | * 工具类 GUIUtil GUI的各种常用工具 9 | */ 10 | public class GUIUtil { 11 | //图片的文件夹 12 | private static final String imgFolder = "resources/img/"; 13 | 14 | //定义皮肤 15 | public static void useLNF() { 16 | try { 17 | javax.swing.UIManager.setLookAndFeel("com.pagosoft.plaf.PgsLookAndFeel"); 18 | } catch (Exception e) { 19 | e.printStackTrace(); 20 | } 21 | } 22 | 23 | /** 24 | * @param textField 文本框组件 25 | * @param name 文本框名字 26 | * @return 文本框输入是否正确 27 | */ 28 | public static boolean checkNumber(JTextField textField, String name) { 29 | String text = textField.getText().trim(); 30 | if (text.length() <= 0) { 31 | JOptionPane.showMessageDialog(null, "输入有误," + name + "不能为空"); 32 | textField.grabFocus(); 33 | return false; 34 | } 35 | //直接用try检查 36 | try { 37 | Integer.parseInt(text); 38 | } catch (Exception e) { 39 | JOptionPane.showMessageDialog(null, "输入有误," + name + "不是数字"); 40 | return false; 41 | } 42 | return true; 43 | } 44 | 45 | /** 46 | * 测试用,直接把面板放进去拉起一个窗体 47 | * 48 | * @param p 待测试的面板 49 | * @param stretch 缩放比例 50 | */ 51 | public static void showPanel(JPanel p, double stretch) { 52 | GUIUtil.useLNF(); 53 | JFrame f = new JFrame(); 54 | f.setLocationRelativeTo(null); 55 | f.setSize(500, 500); 56 | CenterPanel cp = new CenterPanel(stretch); 57 | f.setContentPane(cp); 58 | f.setDefaultCloseOperation(3); 59 | f.setVisible(true); 60 | cp.show(p); 61 | } 62 | 63 | public static void showPanel(JPanel p) { 64 | showPanel(p, 0.85); 65 | } 66 | 67 | /** 68 | * 把一个按钮设置成图文形式 69 | * 70 | * @param b 按钮 71 | * @param fileName 图片名 72 | * @param tip 按钮下文字 73 | */ 74 | public static void setImageIcon(JButton b, String fileName, String tip) { 75 | ImageIcon i = new ImageIcon((new File(imgFolder, fileName)).getAbsolutePath()); 76 | b.setIcon(i); 77 | b.setPreferredSize(new Dimension(61, 81)); 78 | b.setToolTipText(tip); 79 | b.setVerticalTextPosition(JButton.BOTTOM); 80 | b.setHorizontalTextPosition(JButton.CENTER); 81 | b.setText(tip); 82 | } 83 | 84 | /** 85 | * 把若干个组件设置成指定颜色 86 | * 87 | * @param color 颜色 88 | * @param cs 组件 89 | */ 90 | public static void setColor(Color color, JComponent... cs) { 91 | for (JComponent c : cs) { 92 | c.setForeground(color); 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/gui/panel/MainPanel.java: -------------------------------------------------------------------------------- 1 | package gui.panel; 2 | 3 | import java.awt.BorderLayout; 4 | 5 | import javax.swing.JButton; 6 | import javax.swing.JPanel; 7 | import javax.swing.JToolBar; 8 | 9 | import gui.listener.ToolBarListener; 10 | import util.CenterPanel; 11 | import util.GUIUtil; 12 | 13 | /** 14 | * 界面类 MainPanel 主界面 15 | * 主要有一个 Toolbar 的工具栏 和 一个 workingPanel 的 CenterPanel 的 工作区 16 | * workingPanel工作区内为本包中的各个页面,它们都是抽象类 WorkingPanel 的 子类 17 | * 各个页面有它们独自的监听器负责用户操作的监听 18 | * 19 | * @see CenterPanel 20 | */ 21 | 22 | public class MainPanel extends JPanel { 23 | static { 24 | GUIUtil.useLNF(); 25 | } 26 | 27 | public static MainPanel instance = new MainPanel(); 28 | private JToolBar tb = new JToolBar(); 29 | public JButton bSpend = new JButton(); 30 | public JButton bRecord = new JButton(); 31 | public JButton bHistory = new JButton(); 32 | public JButton bCategory = new JButton(); 33 | public JButton bReport = new JButton(); 34 | public JButton bConfig = new JButton(); 35 | public JButton bBackup = new JButton(); 36 | public JButton bRecover = new JButton(); 37 | 38 | public CenterPanel workingPanel; 39 | 40 | private MainPanel() { 41 | 42 | GUIUtil.setImageIcon(bSpend, "home.png", "本月一览"); 43 | GUIUtil.setImageIcon(bRecord, "record.png", "记一笔"); 44 | GUIUtil.setImageIcon(bHistory, "history.png", "历史消费"); 45 | GUIUtil.setImageIcon(bReport, "report.png", "月消费报表"); 46 | GUIUtil.setImageIcon(bCategory, "category.png", "消费分类"); 47 | GUIUtil.setImageIcon(bConfig, "config.png", "设置"); 48 | GUIUtil.setImageIcon(bBackup, "backup.png", "备份"); 49 | GUIUtil.setImageIcon(bRecover, "restore.png", "恢复"); 50 | 51 | tb.add(bSpend); 52 | tb.add(bRecord); 53 | tb.add(bHistory); 54 | tb.add(bReport); 55 | tb.add(bCategory); 56 | tb.add(bConfig); 57 | tb.add(bBackup); 58 | tb.add(bRecover); 59 | tb.setFloatable(false); 60 | 61 | workingPanel = new CenterPanel(0.85); 62 | 63 | this.setLayout(new BorderLayout()); 64 | this.add(tb, BorderLayout.NORTH); 65 | this.add(workingPanel, BorderLayout.CENTER); 66 | 67 | addListeners(); 68 | } 69 | 70 | private void addListeners() { 71 | ToolBarListener l = new ToolBarListener(); 72 | bSpend.addActionListener(l); 73 | bHistory.addActionListener(l); 74 | bBackup.addActionListener(l); 75 | bCategory.addActionListener(l); 76 | bConfig.addActionListener(l); 77 | bRecord.addActionListener(l); 78 | bRecover.addActionListener(l); 79 | bReport.addActionListener(l); 80 | } 81 | 82 | public static void main(String[] args) { 83 | GUIUtil.showPanel(MainPanel.instance, 1); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/util/DateUtil.java: -------------------------------------------------------------------------------- 1 | package util; 2 | 3 | import java.util.Calendar; 4 | import java.util.Date; 5 | 6 | /** 7 | * 工具类 DateUtil 时间 8 | */ 9 | 10 | public class DateUtil { 11 | //定义一天的时间 12 | private static final long millisecondsOfOneDay = 1000 * 60 * 60 * 24; 13 | //获取日历 14 | private static Calendar c = Calendar.getInstance(); 15 | 16 | /** 17 | * @param d java.util.Date 18 | * @return java.sql.Date 去掉了时分秒 19 | */ 20 | public static java.sql.Date util2sql(java.util.Date d) { 21 | return new java.sql.Date(d.getTime()); 22 | } 23 | 24 | /** 25 | * @return 今天0点的时间 26 | */ 27 | public static Date today() { 28 | c.setTime(new Date()); 29 | c.set(Calendar.HOUR_OF_DAY, 0); 30 | c.set(Calendar.MINUTE, 0); 31 | c.set(Calendar.SECOND, 0); 32 | c.set(Calendar.MILLISECOND, 0); 33 | return c.getTime(); 34 | } 35 | 36 | /** 37 | * @return 月初0点的时间 38 | */ 39 | public static Date monthBegin() { 40 | c.setTime(new Date()); 41 | c.set(Calendar.DATE, 1); 42 | c.set(Calendar.HOUR_OF_DAY, 0); 43 | c.set(Calendar.MINUTE, 0); 44 | c.set(Calendar.SECOND, 0); 45 | c.set(Calendar.MILLISECOND, 0); 46 | return c.getTime(); 47 | } 48 | 49 | public static Date monthEnd() { 50 | return monthEnd(monthBegin()); 51 | } 52 | 53 | /** 54 | * @param start 月初时间 55 | * @return 月末0点的时间 56 | */ 57 | public static Date monthEnd(Date start) { 58 | c.setTime(start); 59 | c.set(Calendar.DATE, 1); 60 | c.add(Calendar.MONTH, 1); 61 | c.add(Calendar.DATE, -1); 62 | c.set(Calendar.HOUR_OF_DAY, 0); 63 | c.set(Calendar.MINUTE, 0); 64 | c.set(Calendar.SECOND, 0); 65 | c.set(Calendar.MILLISECOND, 0); 66 | return c.getTime(); 67 | } 68 | 69 | /** 70 | * @return 本月天数 71 | */ 72 | public static int thisMonthTotalDay() { 73 | c.setTime(new Date()); 74 | monthEnd(); 75 | return c.get(Calendar.DATE); 76 | } 77 | 78 | /** 79 | * @return 本月剩余天数 80 | */ 81 | public static int thisMonthLeftDay() { 82 | int TotalDay = thisMonthTotalDay(); 83 | today(); 84 | int today = c.get(Calendar.DATE); 85 | return TotalDay - today + 1; 86 | } 87 | 88 | /** 89 | * @return 本年年份数 90 | */ 91 | public static int thisYear() { 92 | today(); 93 | return c.get(Calendar.YEAR); 94 | } 95 | 96 | /** 97 | * @return 本年月份数 98 | */ 99 | public static int thisMonth() { 100 | today(); 101 | return c.get(Calendar.MONTH); 102 | } 103 | 104 | 105 | } 106 | -------------------------------------------------------------------------------- /src/gui/listener/HistoryListListener.java: -------------------------------------------------------------------------------- 1 | package gui.listener; 2 | 3 | import entity.Category; 4 | import entity.Record; 5 | import gui.panel.*; 6 | import service.RecordService; 7 | 8 | import javax.swing.*; 9 | import java.awt.event.ActionEvent; 10 | import java.awt.event.ActionListener; 11 | import java.util.List; 12 | 13 | /** 14 | * HistoryListPanel的监听器,监听按钮后进行record的删操作,增改操作交给RecordPanel 15 | * 16 | * @author xenv 17 | * @see HistoryListPanel 18 | * @see RecordPanel 19 | */ 20 | public class HistoryListListener implements ActionListener { 21 | @Override 22 | public void actionPerformed(ActionEvent e) { 23 | RecordService service = new RecordService(); 24 | HistoryListPanel p = HistoryListPanel.instance; 25 | JButton b = (JButton) e.getSource(); 26 | 27 | if (p.bAdd == b) { 28 | //交给RecordPanel处理 29 | MainPanel.instance.workingPanel.show(RecordPanel.instance); 30 | RecordPanel.instance.datepick.setDate(MonthPickerPanel.instance.date); 31 | } 32 | if (p.bEdit == b) { 33 | //交给RecordPanel处理 34 | if (!p.checkSelected()) { 35 | JOptionPane.showMessageDialog(p, "请先选择一行 "); 36 | } else { 37 | Record r = p.getSelectedRecord(); 38 | //修改 updateId 设置,在 RecordPanel 提交的时候就会使用修改入库而不是直接入库 39 | RecordPanel.instance.updateId = r.getId(); 40 | //切换到 RecordPanel 41 | MainPanel.instance.workingPanel.show(RecordPanel.instance); 42 | //把旧数据读出来,写到 RecordPanel 待用户修改完直接更新入库即可 43 | RecordPanel.instance.tfSpend.setText(String.valueOf(r.getSpend())); 44 | RecordPanel.instance.tfComment.setText(r.getComment()); 45 | //获取模型里的id而不是数据库的id,即帮用户选择分类 46 | RecordPanel.instance.cbCategory.setSelectedIndex(getModelId(r.getCid())); 47 | RecordPanel.instance.datepick.setDate(r.getDate()); 48 | } 49 | } 50 | if (p.bDelete == b) { 51 | if (!p.checkSelected()) { 52 | JOptionPane.showMessageDialog(p, "请先选择一行 "); 53 | return; 54 | } 55 | if (JOptionPane.OK_OPTION != JOptionPane.showConfirmDialog(p, "确实删除?")) { 56 | return; 57 | } 58 | service.delete(p.getSelectedRecord().getId()); 59 | p.updateData(); 60 | } 61 | } 62 | 63 | 64 | /** 65 | * @param cid 分类在数据库中的cid 66 | * @return 分类在 CategoryComboBoxModel 模型列表中的实际序数id 67 | */ 68 | private int getModelId(int cid) { 69 | List categoryComBoxList = RecordPanel.instance.cbModel.cs; 70 | for (int i = 0; i < categoryComBoxList.size(); i++) { 71 | if (categoryComBoxList.get(i).getId() == cid) { 72 | return i; 73 | } 74 | } 75 | return 0; //若分类已经删除则返回第0个分类 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/gui/panel/RecordPanel.java: -------------------------------------------------------------------------------- 1 | package gui.panel; 2 | 3 | import java.awt.BorderLayout; 4 | import java.awt.GridLayout; 5 | import java.util.Date; 6 | 7 | import javax.swing.JButton; 8 | import javax.swing.JComboBox; 9 | import javax.swing.JLabel; 10 | import javax.swing.JPanel; 11 | import javax.swing.JTextField; 12 | 13 | import entity.Category; 14 | import gui.listener.RecordListener; 15 | import gui.model.CategoryComboBoxModel; 16 | import service.CategoryService; 17 | import util.*; 18 | 19 | import org.jdesktop.swingx.JXDatePicker; 20 | 21 | /** 22 | * 界面类 RecordPanel 记一笔页面 23 | * 24 | */ 25 | 26 | public class RecordPanel extends WorkingPanel { 27 | static { 28 | GUIUtil.useLNF(); 29 | } 30 | 31 | public static RecordPanel instance = new RecordPanel(); 32 | public int updateId = -1; //如果changeId>0则为修改模式,<0为模式的添加模式 33 | 34 | private JLabel lSpend = new JLabel("花费(¥)"); 35 | private JLabel lCategory = new JLabel("分类"); 36 | private JLabel lComment = new JLabel("备注"); 37 | private JLabel lDate = new JLabel("日期"); 38 | 39 | public JTextField tfSpend = new JTextField("0"); 40 | 41 | public CategoryComboBoxModel cbModel = new CategoryComboBoxModel(); 42 | public JComboBox cbCategory = new JComboBox<>(cbModel); 43 | public JTextField tfComment = new JTextField(); 44 | public JXDatePicker datepick = new JXDatePicker(new Date()); 45 | 46 | private JButton bSubmit = new JButton("保存"); 47 | 48 | public RecordPanel() { 49 | GUIUtil.setColor(ColorUtil.grayColor, lSpend, lCategory, lComment, lDate); 50 | GUIUtil.setColor(ColorUtil.blueColor, bSubmit); 51 | JPanel pInput = new JPanel(); 52 | JPanel pSubmit = new JPanel(); 53 | int gap = 40; 54 | pInput.setLayout(new GridLayout(4, 2, gap, gap)); 55 | 56 | pInput.add(lSpend); 57 | pInput.add(tfSpend); 58 | pInput.add(lCategory); 59 | pInput.add(cbCategory); 60 | pInput.add(lComment); 61 | pInput.add(tfComment); 62 | pInput.add(lDate); 63 | pInput.add(datepick); 64 | 65 | pSubmit.add(bSubmit); 66 | 67 | this.setLayout(new BorderLayout()); 68 | this.add(pInput, BorderLayout.NORTH); 69 | this.add(pSubmit, BorderLayout.CENTER); 70 | 71 | addListener(); 72 | } 73 | 74 | public static void main(String[] args) { 75 | GUIUtil.showPanel(RecordPanel.instance); 76 | } 77 | 78 | @Override 79 | public void updateData() { 80 | cbModel.cs = new CategoryService().list(); 81 | cbCategory.updateUI(); 82 | tfSpend.setText(""); 83 | tfComment.setText(""); 84 | datepick.setDate(new Date()); 85 | tfSpend.grabFocus(); 86 | } 87 | 88 | public Category getSelectedCategory() { 89 | return (Category) cbCategory.getSelectedItem(); 90 | } 91 | 92 | @Override 93 | public void addListener() { 94 | bSubmit.addActionListener(new RecordListener()); 95 | } 96 | } -------------------------------------------------------------------------------- /src/util/CircleProgressBar.java: -------------------------------------------------------------------------------- 1 | package util; 2 | 3 | import java.awt.BasicStroke; 4 | import java.awt.Color; 5 | import java.awt.Font; 6 | import java.awt.FontMetrics; 7 | import java.awt.Graphics; 8 | import java.awt.Graphics2D; 9 | import java.awt.RenderingHints; 10 | 11 | import javax.swing.JPanel; 12 | 13 | 14 | /** 15 | * 工具类 CircleProgressBar 环形图 16 | * 借鉴了网上的写法 17 | */ 18 | 19 | public class CircleProgressBar extends JPanel { 20 | 21 | private int minimumProgress; 22 | 23 | private int maximumProgress; 24 | 25 | private int progress; 26 | 27 | private String progressText; 28 | 29 | private Color backgroundColor; 30 | 31 | private Color foregroundColor; 32 | 33 | public CircleProgressBar() { 34 | minimumProgress = 0; 35 | maximumProgress = 100; 36 | progressText = "0%"; 37 | } 38 | 39 | /** 40 | * 根据百分比 绘制 漂亮的环形图 41 | * 42 | * @param g 百分比 43 | */ 44 | public void paint(Graphics g) { 45 | super.paint(g); 46 | Graphics2D graphics2d = (Graphics2D) g; 47 | // 开启抗锯齿 48 | graphics2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 49 | int x; 50 | int y; 51 | int width; 52 | int height; 53 | int fontSize; 54 | if (getWidth() >= getHeight()) { 55 | x = (getWidth() - getHeight()) / 2 + 25; 56 | y = 25; 57 | width = getHeight() - 50; 58 | height = getHeight() - 50; 59 | fontSize = getWidth() / 8; 60 | } else { 61 | x = 25; 62 | y = (getHeight() - getWidth()) / 2 + 25; 63 | width = getWidth() - 50; 64 | height = getWidth() - 50; 65 | fontSize = getHeight() / 8; 66 | } 67 | graphics2d.setStroke(new BasicStroke(20.0f)); 68 | graphics2d.setColor(backgroundColor); 69 | graphics2d.drawArc(x, y, width, height, 0, 360); 70 | graphics2d.setColor(foregroundColor); 71 | graphics2d.drawArc(x, y, width, height, 90, 72 | -(int) (360 * ((progress * 1.0) / (maximumProgress - minimumProgress)))); 73 | graphics2d.setFont(new Font("黑体", Font.BOLD, fontSize)); 74 | FontMetrics fontMetrics = graphics2d.getFontMetrics(); 75 | int digitalWidth = fontMetrics.stringWidth(progressText); 76 | int digitalAscent = fontMetrics.getAscent(); 77 | graphics2d.setColor(foregroundColor); 78 | graphics2d.drawString(progressText, getWidth() / 2 - digitalWidth / 2, getHeight() / 2 + digitalAscent / 2); 79 | } 80 | 81 | public int getProgress() { 82 | return progress; 83 | } 84 | 85 | public void setProgress(int progress) { 86 | if (progress >= minimumProgress && progress <= maximumProgress) 87 | this.progress = progress; 88 | if (progress > maximumProgress) 89 | this.progress = maximumProgress; 90 | 91 | this.progressText = String.valueOf(progress + "%"); 92 | 93 | this.repaint(); 94 | } 95 | 96 | public Color getBackgroundColor() { 97 | return backgroundColor; 98 | } 99 | 100 | public void setBackgroundColor(Color backgroundColor) { 101 | this.backgroundColor = backgroundColor; 102 | this.repaint(); 103 | } 104 | 105 | public Color getForegroundColor() { 106 | return foregroundColor; 107 | } 108 | 109 | public void setForegroundColor(Color foregroundColor) { 110 | this.foregroundColor = foregroundColor; 111 | this.repaint(); 112 | } 113 | 114 | } -------------------------------------------------------------------------------- /src/util/ChartUtil.java: -------------------------------------------------------------------------------- 1 | package util; 2 | 3 | import java.awt.Color; 4 | import java.awt.Font; 5 | import java.awt.Image; 6 | import java.util.*; 7 | 8 | import javax.swing.Icon; 9 | import javax.swing.ImageIcon; 10 | import javax.swing.JLabel; 11 | import javax.swing.JPanel; 12 | 13 | import com.objectplanet.chart.BarChart; 14 | import com.objectplanet.chart.Chart; 15 | import entity.Record; 16 | import service.ReportService; 17 | 18 | /** 19 | * 工具类 CharUtil 图表 20 | */ 21 | 22 | public class ChartUtil { 23 | /** 24 | * @param rs 每个月天数这么多的 每天的record数据 25 | * @param width 图表长 26 | * @param height 图表宽 27 | * @return 一个月的消费柱状图 28 | */ 29 | public static Image getImage(List rs, int width, int height) { 30 | // 样本数据 31 | double[] sampleValues = sampleValues(rs); 32 | // 下方显示的文字 33 | String[] sampleLabels = sampleLabels(rs); 34 | // 样本中的最大值 35 | int max = max(sampleValues); 36 | 37 | // 数据颜色 38 | Color[] sampleColors = new Color[]{ColorUtil.blueColor}; 39 | 40 | // 生成柱状图 41 | BarChart chart = new BarChart(); 42 | 43 | // 设置样本个数 44 | chart.setSampleCount(sampleValues.length); 45 | // 设置样本数据 46 | chart.setSampleValues(0, sampleValues); 47 | // 设置文字 48 | chart.setSampleLabels(sampleLabels); 49 | // 设置样本颜色 50 | chart.setSampleColors(sampleColors); 51 | // 设置取值范围 52 | chart.setRange(0, max * 1.2); 53 | // 显示背景横线 54 | chart.setValueLinesOn(true); 55 | // 显示文字 56 | chart.setSampleLabelsOn(true); 57 | // 把文字显示在下方 58 | chart.setSampleLabelStyle(Chart.BELOW); 59 | 60 | // 样本值的字体 61 | chart.setFont("rangeLabelFont", new Font("Arial", Font.BOLD, 12)); 62 | // 显示图例说明 63 | chart.setLegendOn(true); 64 | // 把图例说明放在左侧 65 | chart.setLegendPosition(Chart.LEFT); 66 | // 图例说明中的文字 67 | chart.setLegendLabels(new String[]{"月消费报表"}); 68 | // 图例说明的字体 69 | chart.setFont("legendFont", new Font("Dialog", Font.BOLD, 13)); 70 | // 下方文字的字体 71 | chart.setFont("sampleLabelFont", new Font("Dialog", Font.BOLD, 13)); 72 | // 图表中间背景颜色 73 | chart.setChartBackground(Color.white); 74 | // 图表整体背景颜色 75 | chart.setBackground(ColorUtil.backgroundColor); 76 | // 把图表转换为Image类型 77 | return chart.getImage(width, height); 78 | } 79 | 80 | /** 81 | * @param rs 每个月天数这么多的 每天的record数据 82 | * @return 每天的消费金额组成的数组 83 | */ 84 | private static double[] sampleValues(List rs) { 85 | 86 | double[] result = new double[rs.size()]; 87 | for (int i = 0; i < result.length; i++) { 88 | result[i] = rs.get(i).getSpend(); 89 | } 90 | return result; 91 | 92 | } 93 | 94 | private static int max(double[] sampleValues) { 95 | int max = 0; 96 | for (double v : sampleValues) { 97 | if (v > max) 98 | max = (int) v; 99 | } 100 | return max; 101 | 102 | } 103 | 104 | private static String[] sampleLabels(List rs) { 105 | String[] sampleLabels = new String[rs.size()]; 106 | for (int i = 0; i < sampleLabels.length; i++) { 107 | if (0 == i % 5) 108 | sampleLabels[i] = String.valueOf(i + 1 + "日"); 109 | } 110 | return sampleLabels; 111 | } 112 | 113 | public static void main(String[] args) { 114 | JPanel p = new JPanel(); 115 | JLabel l = new JLabel(); 116 | Image img = ChartUtil.getImage(new ReportService().listThisMonthRecords(), 400, 300); 117 | Icon icon = new ImageIcon(img); 118 | l.setIcon(icon); 119 | p.add(l); 120 | GUIUtil.showPanel(p); 121 | } 122 | 123 | } -------------------------------------------------------------------------------- /src/gui/panel/SpendPanel.java: -------------------------------------------------------------------------------- 1 | package gui.panel; 2 | 3 | import gui.page.SpendPage; 4 | import service.SpendService; 5 | import util.CircleProgressBar; 6 | import util.ColorUtil; 7 | import util.GUIUtil; 8 | 9 | import javax.swing.*; 10 | import java.awt.*; 11 | 12 | /** 13 | * 界面类 SpendPanel 本月一览页 14 | */ 15 | 16 | public class SpendPanel extends WorkingPanel { 17 | static { 18 | GUIUtil.useLNF(); 19 | } 20 | 21 | public static SpendPanel instance = new SpendPanel(); 22 | 23 | private JLabel lMonthSpend = new JLabel("本月消费"); 24 | private JLabel lTodaySpend = new JLabel("今日消费"); 25 | private JLabel lAvgSpendPerDay = new JLabel("日均消费"); 26 | private JLabel lMonthLeft = new JLabel("本月剩余"); 27 | private JLabel lDayAvgAvailable = new JLabel("日均可用"); 28 | private JLabel lMonthLeftDay = new JLabel("距离月末"); 29 | 30 | private JLabel vMonthSpend = new JLabel("¥2300"); 31 | private JLabel vTodaySpend = new JLabel("¥25"); 32 | private JLabel vAvgSpendPerDay = new JLabel("¥120"); 33 | private JLabel vMonthAvailable = new JLabel("¥2084"); 34 | private JLabel vDayAvgAvailable = new JLabel("¥389"); 35 | private JLabel vMonthLeftDay = new JLabel("15天"); 36 | 37 | private CircleProgressBar bar; 38 | 39 | private SpendPanel() { 40 | this.setLayout(new BorderLayout()); 41 | bar = new CircleProgressBar(); 42 | bar.setBackgroundColor(ColorUtil.blueColor); 43 | 44 | GUIUtil.setColor(ColorUtil.grayColor, lMonthSpend, lTodaySpend, lAvgSpendPerDay, lMonthLeft, lDayAvgAvailable, 45 | lMonthLeftDay, vAvgSpendPerDay, vMonthAvailable, vDayAvgAvailable, vMonthLeftDay); 46 | GUIUtil.setColor(ColorUtil.blueColor, vMonthSpend, vTodaySpend); 47 | 48 | vMonthSpend.setFont(new Font("微软雅黑", Font.BOLD, 23)); 49 | vTodaySpend.setFont(new Font("微软雅黑", Font.BOLD, 23)); 50 | 51 | this.add(center(), BorderLayout.CENTER); 52 | this.add(south(), BorderLayout.SOUTH); 53 | 54 | } 55 | 56 | private JPanel south() { 57 | JPanel p = new JPanel(); 58 | p.setLayout(new GridLayout(2, 4)); 59 | p.add(lAvgSpendPerDay); 60 | p.add(lMonthLeft); 61 | p.add(lDayAvgAvailable); 62 | p.add(lMonthLeftDay); 63 | p.add(vAvgSpendPerDay); 64 | p.add(vMonthAvailable); 65 | p.add(vDayAvgAvailable); 66 | p.add(vMonthLeftDay); 67 | return p; 68 | } 69 | 70 | private JPanel center() { 71 | JPanel p = new JPanel(); 72 | p.setLayout(new BorderLayout()); 73 | p.add(west(), BorderLayout.WEST); 74 | p.add(east(), BorderLayout.CENTER); 75 | return p; 76 | } 77 | 78 | private Component west() { 79 | JPanel p = new JPanel(); 80 | p.setLayout(new GridLayout(4, 1)); 81 | p.add(lMonthSpend); 82 | p.add(vMonthSpend); 83 | p.add(lTodaySpend); 84 | p.add(vTodaySpend); 85 | return p; 86 | } 87 | 88 | private Component east() { 89 | return bar; 90 | } 91 | 92 | public static void main(String[] args) { 93 | 94 | GUIUtil.showPanel(SpendPanel.instance); 95 | } 96 | 97 | 98 | @Override 99 | public void updateData() { 100 | SpendPage spend = new SpendService().getSpendPage(); 101 | vMonthSpend.setText(spend.monthSpend); 102 | vTodaySpend.setText(spend.todaySpend); 103 | vAvgSpendPerDay.setText(spend.avgSpendPerDay); 104 | vDayAvgAvailable.setText(spend.dayAvgAvailable); 105 | vMonthAvailable.setText(spend.monthAvailable); 106 | vMonthLeftDay.setText(spend.monthLeftDay); 107 | bar.setProgress(spend.usagePercentage); 108 | if (spend.isOverSpend) { 109 | vMonthAvailable.setForeground(ColorUtil.warningColor); 110 | vMonthSpend.setForeground(ColorUtil.warningColor); 111 | vTodaySpend.setForeground(ColorUtil.warningColor); 112 | } else { 113 | vMonthAvailable.setForeground(ColorUtil.grayColor); 114 | vMonthSpend.setForeground(ColorUtil.blueColor); 115 | vTodaySpend.setForeground(ColorUtil.blueColor); 116 | } 117 | bar.setForegroundColor(ColorUtil.getByPercentage(spend.usagePercentage)); 118 | addListener(); 119 | } 120 | 121 | @Override 122 | public void addListener() { 123 | 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SmallAccount 2 | 小小记账本,拥有基础记账功能,是一个JAVA (J2SE) 练手+自用的小项目。 3 | 4 | * 实现了基础记账功能 5 | - [x] 记账分类的增改删查 6 | - [x] 记账记录的增改删查 7 | - [x] 月度一览和月度每日统计(柱状图) 8 | - [x] 配置信息的修改与保存 (每月预算) 9 | - [x] 数据导出、导入和重置 10 | 11 | * 使用Swing和SQLite数据库,无需额外配置数据库 12 | * Entity层、DAO层、Service层和GUI层分离,GUI层界面、数据、监听器分离 13 | * 面板使用单例模式,数据库采用外键约束 14 | * 带有详细的注释 15 | 16 | ## 启动 17 | 入口为 18 | ``` 19 | startup.Bootstrap.main 20 | ``` 21 | 22 | ## 演示 23 | ![](https://github.com/xenv/SmallAccount/blob/master/resources/github/demo.gif?raw=true) 24 | 25 | 26 | ## 目录结构 27 | 28 | ``` 29 | ├─db 30 | │ data.db 数据库 31 | │ 32 | ├─lib 33 | │ chart.jar 表格库 34 | │ pgslookandfeel-1.1.2.jar 皮肤库 35 | │ sqlite-jdbc-3.20.0.jar SQLite JDBC 36 | │ swingx-core-1.6.2.jar 日期控件 37 | │ 38 | ├─resources 39 | │ ├─img 图片资源(按钮图片) 40 | │ │ backup.png 41 | │ │ category1.png 42 | │ │ category2.png 43 | │ │ config.png 44 | │ │ home.png 45 | │ │ record.png 46 | │ │ report.png 47 | │ │ restore.png 48 | │ 49 | ├─src 50 | │ ├─dao DAO操作类 51 | │ │ CategoryDAO.java 52 | │ │ ConfigDAO.java 53 | │ │ RecordDAO.java 54 | │ │ 55 | │ ├─entity 实体类(三个表) 56 | │ │ Category.java 57 | │ │ Config.java 58 | │ │ Record.java 59 | │ │ 60 | │ ├─gui 界面类 61 | │ │ ├─frame 主框架 62 | │ │ │ MainFrame.java 63 | │ │ │ 64 | │ │ ├─listener 监听器(按钮及菜单栏) 65 | │ │ │ BackupListener.java 66 | │ │ │ CategoryListener.java 67 | │ │ │ ConfigListener.java 68 | │ │ │ RecordListener.java 69 | │ │ │ RecoverListener.java 70 | │ │ │ ToolBarListener.java 71 | │ │ │ 72 | │ │ ├─model 表格和下拉框的model 73 | │ │ │ CategoryComboBoxModel.java 74 | │ │ │ CategoryTableModel.java 75 | │ │ │ 76 | │ │ ├─page SpendPage的页面数据 77 | │ │ │ SpendPage.java 78 | │ │ │ 79 | │ │ └─panel 主面板及其他面板 80 | │ │ BackupPanel.java 81 | │ │ CategoryPanel.java 82 | │ │ ConfigPanel.java 83 | │ │ MainPanel.java 84 | │ │ RecordPanel.java 85 | │ │ RecoverPanel.java 86 | │ │ ReportPanel.java 87 | │ │ SpendPanel.java 88 | │ │ WorkingPanel.java 89 | │ │ 90 | │ ├─service 负责部分业务逻辑 91 | │ │ CategoryService.java 92 | │ │ ConfigService.java 93 | │ │ RecordService.java 94 | │ │ ReportService.java 95 | │ │ SpendService.java 96 | │ │ 97 | │ ├─startup 启动类 98 | │ │ Bootstrap.java 99 | │ │ 100 | │ └─util 工具类 101 | │ CenterPanel.java 102 | │ ChartUtil.java 103 | │ CircleProgressBar.java 104 | │ ColorUtil.java 105 | │ DateUtil.java 106 | │ DBUtil.java 107 | │ GUIUtil.java 108 | │ SQLUtil.java 109 | ``` 110 | 111 | 112 | ## 数据库结构 113 | db/data.db已经包含了完整的数据结构和测试数据 114 | ```sqlite 115 | CREATE TABLE config ( 116 | id INTEGER PRIMARY KEY AUTOINCREMENT 117 | NOT NULL, 118 | key_ VARCHAR (255) UNIQUE, 119 | value VARCHAR (255) 120 | ); 121 | 122 | CREATE TABLE category ( 123 | id INTEGER PRIMARY KEY AUTOINCREMENT 124 | NOT NULL, 125 | name VARCHAR (255) UNIQUE 126 | NOT NULL 127 | ); 128 | 129 | CREATE TABLE record ( 130 | id INTEGER PRIMARY KEY AUTOINCREMENT 131 | NOT NULL, 132 | cid INTEGER CONSTRAINT fk_record_category REFERENCES category (id), 133 | spend INTEGER NOT NULL, 134 | comment TEXT, 135 | date DATE 136 | ); 137 | 138 | ``` 139 | 140 | ## 启动流程 141 | ``` 142 | startup.Bootstrap.main() 主类 143 | ↓ 144 | gui.panel.MainFrame.instance 程序窗体 145 | ├─gui.listener.ToolBarListener等 监控按钮操作 146 | ↓ 147 | gui.panel.MainPanel.instance 底层Panel及导航栏 148 | ↓ 149 | MainPanel.instance.workingPanel 功能Panel的底Panel,实现了居中的功能 150 | ↓ 151 | gui.panel.SpendPanel.instance 本月一览界面 152 | ↓ 153 | gui.panel.* 通过监控菜单栏实现其他Panel的切换 154 | ``` 155 | 156 | ## License 157 | 158 | GPL v3.0 -------------------------------------------------------------------------------- /src/dao/CategoryDAO.java: -------------------------------------------------------------------------------- 1 | package dao; 2 | 3 | import entity.Category; 4 | import util.DBUtil; 5 | 6 | import java.sql.*; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | /** 11 | * DAO类-Category,对category表进行增改删查操作,还做了一些冗余的方法,不再过多注释 12 | */ 13 | 14 | public class CategoryDAO { 15 | public void add(Category category) { 16 | String sql = "insert into category (`name`) values (?)"; 17 | try (Connection c = DBUtil.getConnection(); 18 | PreparedStatement ps = c.prepareStatement(sql)) { 19 | ps.setString(1, category.getName()); 20 | ps.execute(); 21 | ResultSet rs = ps.getGeneratedKeys(); 22 | if (rs.next()) { 23 | int id = rs.getInt(1); 24 | category.setId(id); 25 | } 26 | } catch (SQLException e) { 27 | e.printStackTrace(); 28 | } 29 | } 30 | 31 | public int update(Category category) { 32 | String sql = "update category set name = ? where id = ?"; 33 | int result = 0; 34 | try (Connection c = DBUtil.getConnection(); 35 | PreparedStatement ps = c.prepareStatement(sql)) { 36 | ps.setString(1, category.getName()); 37 | ps.setInt(2, category.getId()); 38 | result = ps.executeUpdate(); 39 | } catch (SQLException e) { 40 | e.printStackTrace(); 41 | } 42 | return result; 43 | } 44 | 45 | public int delete(int id) { 46 | String sql = "delete from category where id = ?"; 47 | int result = 0; 48 | try (Connection c = DBUtil.getConnection(); 49 | PreparedStatement ps = c.prepareStatement(sql)) { 50 | ps.setInt(1, id); 51 | result = ps.executeUpdate(); 52 | } catch (SQLException e) { 53 | e.printStackTrace(); 54 | } 55 | return result; 56 | } 57 | 58 | public Category get(int id) { 59 | Category category = null; 60 | String sql = "select * from category where id = ?"; 61 | try (Connection c = DBUtil.getConnection(); 62 | PreparedStatement ps = c.prepareStatement(sql)) { 63 | ps.setInt(1, id); 64 | ResultSet result = ps.executeQuery(); 65 | if (result.next()) { 66 | category = new Category(result.getInt("id"), 67 | result.getString("name")); 68 | } 69 | } catch (SQLException e) { 70 | e.printStackTrace(); 71 | } 72 | return category; 73 | } 74 | 75 | public Category getByKey(String key) { 76 | Category category = null; 77 | String sql = "select * from category where key_ = ?"; 78 | try (Connection c = DBUtil.getConnection(); 79 | PreparedStatement ps = c.prepareStatement(sql)) { 80 | ps.setString(1, key); 81 | ResultSet result = ps.executeQuery(); 82 | if (result.next()) { 83 | category = new Category(result.getInt("id"), 84 | result.getString("name")); 85 | } 86 | } catch (SQLException e) { 87 | e.printStackTrace(); 88 | } 89 | return category; 90 | } 91 | 92 | public List list(int start, int count) { 93 | String sql = "select * from category order by id desc limit ?,?"; 94 | List categories = new ArrayList<>(); 95 | try (Connection c = DBUtil.getConnection(); 96 | PreparedStatement ps = c.prepareStatement(sql)) { 97 | ps.setInt(1, start); 98 | ps.setInt(2, count); 99 | ResultSet rs = ps.executeQuery(); 100 | while (rs.next()) { 101 | Category category = new Category(rs.getInt("id"), 102 | rs.getString("name")); 103 | categories.add(category); 104 | } 105 | } catch (SQLException e) { 106 | e.printStackTrace(); 107 | } 108 | return categories; 109 | } 110 | 111 | public List list() { 112 | return list(0, Short.MAX_VALUE); 113 | } 114 | 115 | public int getTotal() { 116 | String sql = "select count(*) from category"; 117 | try (Connection c = DBUtil.getConnection(); 118 | Statement s = c.createStatement()) { 119 | ResultSet rs = s.executeQuery(sql); 120 | if (rs.next()) { 121 | return rs.getInt(1); 122 | } 123 | } catch (SQLException e) { 124 | e.printStackTrace(); 125 | } 126 | return 0; 127 | } 128 | 129 | 130 | } 131 | -------------------------------------------------------------------------------- /src/dao/ConfigDAO.java: -------------------------------------------------------------------------------- 1 | package dao; 2 | 3 | import java.sql.*; 4 | import java.util.*; 5 | 6 | import entity.Config; 7 | import util.DBUtil; 8 | 9 | /** 10 | * DAO类-Config,对config表进行增改删查操作,还做了一些冗余的方法,不再过多注释 11 | */ 12 | 13 | public class ConfigDAO { 14 | public void add(Config config) { 15 | String sql = "insert into config (`key_`,`value`) values (?,?)"; 16 | try (Connection c = DBUtil.getConnection(); 17 | PreparedStatement ps = c.prepareStatement(sql)) { 18 | ps.setString(1, config.getKey()); 19 | ps.setString(2, config.getValue()); 20 | ps.execute(); 21 | ResultSet rs = ps.getGeneratedKeys(); 22 | if (rs.next()) { 23 | int id = rs.getInt(1); 24 | config.setId(id); 25 | } 26 | } catch (SQLException e) { 27 | e.printStackTrace(); 28 | } 29 | } 30 | 31 | public int update(Config config) { 32 | String sql = "update config set key_ = ? , value = ? where id = ?"; 33 | int result = 0; 34 | try (Connection c = DBUtil.getConnection(); 35 | PreparedStatement ps = c.prepareStatement(sql)) { 36 | ps.setString(1, config.getKey()); 37 | ps.setString(2, config.getValue()); 38 | ps.setInt(3, config.getId()); 39 | result = ps.executeUpdate(); 40 | } catch (SQLException e) { 41 | e.printStackTrace(); 42 | } 43 | return result; 44 | } 45 | 46 | public int delete(int id) { 47 | String sql = "delete from config where id = ?"; 48 | int result = 0; 49 | try (Connection c = DBUtil.getConnection(); 50 | PreparedStatement ps = c.prepareStatement(sql)) { 51 | ps.setInt(1, id); 52 | result = ps.executeUpdate(); 53 | } catch (SQLException e) { 54 | e.printStackTrace(); 55 | } 56 | return result; 57 | } 58 | 59 | public Config get(int id) { 60 | Config config = null; 61 | String sql = "select * from config where id = ?"; 62 | try (Connection c = DBUtil.getConnection(); 63 | PreparedStatement ps = c.prepareStatement(sql)) { 64 | ps.setInt(1, id); 65 | ResultSet result = ps.executeQuery(); 66 | if (result.next()) { 67 | config = new Config(result.getInt("id"), 68 | result.getString("key_"), 69 | result.getString("value")); 70 | } 71 | } catch (SQLException e) { 72 | e.printStackTrace(); 73 | } 74 | return config; 75 | } 76 | 77 | public Config getByKey(String key) { 78 | Config config = null; 79 | String sql = "select * from config where key_ = ?"; 80 | try (Connection c = DBUtil.getConnection(); 81 | PreparedStatement ps = c.prepareStatement(sql)) { 82 | ps.setString(1, key); 83 | ResultSet result = ps.executeQuery(); 84 | if (result.next()) { 85 | config = new Config(result.getInt("id"), 86 | result.getString("key_"), 87 | result.getString("value")); 88 | } 89 | } catch (SQLException e) { 90 | e.printStackTrace(); 91 | } 92 | return config; 93 | } 94 | 95 | public List list(int start, int count) { 96 | String sql = "select * from config order by id desc limit ?,?"; 97 | List configs = new ArrayList<>(); 98 | try (Connection c = DBUtil.getConnection(); 99 | PreparedStatement ps = c.prepareStatement(sql)) { 100 | ps.setInt(1, start); 101 | ps.setInt(2, count); 102 | ResultSet rs = ps.executeQuery(); 103 | while (rs.next()) { 104 | Config config = new Config(rs.getInt("id"), 105 | rs.getString("key_"), 106 | rs.getString("value")); 107 | configs.add(config); 108 | } 109 | } catch (SQLException e) { 110 | e.printStackTrace(); 111 | } 112 | return configs; 113 | } 114 | 115 | public List list() { 116 | return list(0, Short.MAX_VALUE); 117 | } 118 | 119 | public int getTotal() { 120 | String sql = "select count(*) from config"; 121 | try (Connection c = DBUtil.getConnection(); 122 | Statement s = c.createStatement()) { 123 | ResultSet rs = s.executeQuery(sql); 124 | if (rs.next()) { 125 | return rs.getInt(1); 126 | } 127 | } catch (SQLException e) { 128 | e.printStackTrace(); 129 | } 130 | return 0; 131 | } 132 | 133 | 134 | } 135 | -------------------------------------------------------------------------------- /src/dao/RecordDAO.java: -------------------------------------------------------------------------------- 1 | package dao; 2 | 3 | import entity.Record; 4 | import util.DBUtil; 5 | import util.DateUtil; 6 | 7 | import java.sql.*; 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | /** 12 | * DAO类-Record,对 record 表进行增改删查操作,还做了一些冗余的方法,不再过多注释 13 | */ 14 | 15 | public class RecordDAO { 16 | public void add(Record record) { 17 | String sql = "insert into record (`spend`,`cid`,`comment`,`date`) values (?,?,?,?)"; 18 | try (Connection c = DBUtil.getConnection(); 19 | PreparedStatement ps = c.prepareStatement(sql)) { 20 | ps.setInt(1, record.getSpend()); 21 | ps.setInt(2, record.getCid()); 22 | ps.setString(3, record.getComment()); 23 | ps.setDate(4, DateUtil.util2sql(record.getDate())); 24 | 25 | ps.execute(); 26 | ResultSet rs = ps.getGeneratedKeys(); 27 | if (rs.next()) { 28 | int id = rs.getInt(1); 29 | record.setId(id); 30 | } 31 | } catch (SQLException e) { 32 | e.printStackTrace(); 33 | } 34 | } 35 | 36 | public int update(Record record) { 37 | String sql = "update record set `spend` = ? , `cid` = ? , `comment` = ? , `date` = ? where id = ?"; 38 | int result = 0; 39 | try (Connection c = DBUtil.getConnection(); 40 | PreparedStatement ps = c.prepareStatement(sql)) { 41 | ps.setInt(1, record.getSpend()); 42 | ps.setInt(2, record.getCid()); 43 | ps.setString(3, record.getComment()); 44 | ps.setDate(4, DateUtil.util2sql(record.getDate())); 45 | ps.setInt(5, record.getId()); 46 | result = ps.executeUpdate(); 47 | } catch (SQLException e) { 48 | e.printStackTrace(); 49 | } 50 | return result; 51 | } 52 | 53 | public int delete(int id) { 54 | String sql = "delete from record where id = ?"; 55 | int result = 0; 56 | try (Connection c = DBUtil.getConnection(); 57 | PreparedStatement ps = c.prepareStatement(sql)) { 58 | ps.setInt(1, id); 59 | result = ps.executeUpdate(); 60 | } catch (SQLException e) { 61 | e.printStackTrace(); 62 | } 63 | return result; 64 | } 65 | 66 | public Record get(int id) { 67 | Record record = null; 68 | String sql = "select * from record where id = ?"; 69 | try (Connection c = DBUtil.getConnection(); 70 | PreparedStatement ps = c.prepareStatement(sql)) { 71 | ps.setInt(1, id); 72 | ResultSet rs = ps.executeQuery(); 73 | if (rs.next()) { 74 | record = new Record(rs.getInt("id"), 75 | rs.getInt("spend"), 76 | rs.getInt("cid"), 77 | rs.getString("comment"), 78 | rs.getDate("date")); 79 | } 80 | } catch (SQLException e) { 81 | e.printStackTrace(); 82 | } 83 | return record; 84 | } 85 | 86 | 87 | public List list(int start, int count) { 88 | String sql = "select * from record order by id desc limit ?,?"; 89 | List records = new ArrayList<>(); 90 | try (Connection c = DBUtil.getConnection(); 91 | PreparedStatement ps = c.prepareStatement(sql)) { 92 | ps.setInt(1, start); 93 | ps.setInt(2, count); 94 | ResultSet rs = ps.executeQuery(); 95 | while (rs.next()) { 96 | Record record = new Record(rs.getInt("id"), 97 | rs.getInt("spend"), 98 | rs.getInt("cid"), 99 | rs.getString("comment"), 100 | rs.getDate("date")); 101 | records.add(record); 102 | } 103 | } catch (SQLException e) { 104 | e.printStackTrace(); 105 | } 106 | return records; 107 | } 108 | 109 | public List list() { 110 | return list(0, Short.MAX_VALUE); 111 | } 112 | 113 | public List list(int cid) { 114 | String sql = "select * from record where `cid` = ?"; 115 | List records = new ArrayList<>(); 116 | try (Connection c = DBUtil.getConnection(); 117 | PreparedStatement ps = c.prepareStatement(sql)) { 118 | ps.setInt(1, cid); 119 | ResultSet rs = ps.executeQuery(); 120 | while (rs.next()) { 121 | Record record = new Record(rs.getInt("id"), 122 | rs.getInt("spend"), 123 | rs.getInt("cid"), 124 | rs.getString("comment"), 125 | rs.getDate("date")); 126 | records.add(record); 127 | } 128 | } catch (SQLException e) { 129 | e.printStackTrace(); 130 | } 131 | return records; 132 | } 133 | 134 | public List list(java.util.Date day) { 135 | String sql = "select * from record where `date` = ?"; 136 | List records = new ArrayList<>(); 137 | try (Connection c = DBUtil.getConnection(); 138 | PreparedStatement ps = c.prepareStatement(sql)) { 139 | ps.setDate(1, DateUtil.util2sql(day)); 140 | ResultSet rs = ps.executeQuery(); 141 | while (rs.next()) { 142 | Record record = new Record(rs.getInt("id"), 143 | rs.getInt("spend"), 144 | rs.getInt("cid"), 145 | rs.getString("comment"), 146 | rs.getDate("date")); 147 | records.add(record); 148 | } 149 | } catch (SQLException e) { 150 | e.printStackTrace(); 151 | } 152 | return records; 153 | } 154 | 155 | public List listToday() { 156 | return list(new java.util.Date()); 157 | } 158 | 159 | public List list(java.util.Date start, java.util.Date end) { 160 | String sql = "select * from record where `date` >= ? and `date` <= ?"; 161 | List records = new ArrayList<>(); 162 | try (Connection c = DBUtil.getConnection(); 163 | PreparedStatement ps = c.prepareStatement(sql)) { 164 | ps.setDate(1, DateUtil.util2sql(start)); 165 | ps.setDate(2, DateUtil.util2sql(end)); 166 | ResultSet rs = ps.executeQuery(); 167 | while (rs.next()) { 168 | Record record = new Record(rs.getInt("id"), 169 | rs.getInt("spend"), 170 | rs.getInt("cid"), 171 | rs.getString("comment"), 172 | rs.getDate("date")); 173 | records.add(record); 174 | } 175 | } catch (SQLException e) { 176 | e.printStackTrace(); 177 | } 178 | return records; 179 | } 180 | 181 | public List listThisMonth() { 182 | return list(DateUtil.monthBegin(), DateUtil.monthEnd()); 183 | } 184 | 185 | public int getTotal() { 186 | String sql = "select count(*) from record"; 187 | try (Connection c = DBUtil.getConnection(); 188 | Statement s = c.createStatement()) { 189 | ResultSet rs = s.executeQuery(sql); 190 | if (rs.next()) { 191 | return rs.getInt(1); 192 | } 193 | } catch (SQLException e) { 194 | e.printStackTrace(); 195 | } 196 | return 0; 197 | } 198 | 199 | 200 | } -------------------------------------------------------------------------------- /.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------