|
@@ -0,0 +1,563 @@
|
|
|
|
+package com.example.mos.container;
|
|
|
|
+
|
|
|
|
+import com.example.mos.common.model.vo.ArticleDataVO;
|
|
|
|
+import com.example.mos.container.JCheckBox.CheckHeaderCellRenderer;
|
|
|
|
+import com.example.mos.container.JCheckBox.CheckTableModle;
|
|
|
|
+import com.example.mos.handler.*;
|
|
|
|
+import com.example.mos.service.ArticleInfoService;
|
|
|
|
+import com.example.mos.service.ExportToWordService;
|
|
|
|
+import com.example.mos.service.WeChatAccountInfoService;
|
|
|
|
+import org.apache.xpath.operations.Bool;
|
|
|
|
+
|
|
|
|
+import javax.swing.*;
|
|
|
|
+import javax.swing.border.Border;
|
|
|
|
+import javax.swing.border.EmptyBorder;
|
|
|
|
+import javax.swing.event.ChangeEvent;
|
|
|
|
+import javax.swing.event.ChangeListener;
|
|
|
|
+import javax.swing.event.TableModelEvent;
|
|
|
|
+import javax.swing.event.TableModelListener;
|
|
|
|
+import javax.swing.table.*;
|
|
|
|
+import java.awt.*;
|
|
|
|
+import java.awt.event.*;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileOutputStream;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.net.URI;
|
|
|
|
+import java.net.URISyntaxException;
|
|
|
|
+import java.text.ParseException;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @Author xiexiang
|
|
|
|
+ * @Date 2024/6/19
|
|
|
|
+ */
|
|
|
|
+public class MainView extends JFrame {
|
|
|
|
+
|
|
|
|
+ OpenSearchPanelHandler openSearchPanelHandler;
|
|
|
|
+ GetAllSourceHandler getAllSourceHandler;
|
|
|
|
+ GetArticlesHandler getArticlesHandler;
|
|
|
|
+ private JTable table;
|
|
|
|
+ CheckHeaderCellRenderer checkHeaderCellRenderer;
|
|
|
|
+ private DefaultTableModel tableModel;
|
|
|
|
+ private JComboBox cob;
|
|
|
|
+
|
|
|
|
+ public MainView() {
|
|
|
|
+ setTitle("知识产权资讯监控系统");
|
|
|
|
+ ArticleInfoService articleInfoService = new ArticleInfoService();
|
|
|
|
+ WeChatAccountInfoService weChatAccountInfoService = new WeChatAccountInfoService(articleInfoService);
|
|
|
|
+ List<String> fakeIds = weChatAccountInfoService.getAllFakeIds();
|
|
|
|
+ if (fakeIds != null && !fakeIds.isEmpty()) {
|
|
|
|
+ JFrame weChatFrame = new JFrame();
|
|
|
|
+ WeChatLoginHandler weChatLoginHandler = new WeChatLoginHandler();
|
|
|
|
+ try {
|
|
|
|
+ weChatLoginHandler.weChatLogin();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ JOptionPane.showMessageDialog(weChatFrame, "微信公众平台登陆失败!");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //用于设置窗体关闭时的默认操作
|
|
|
|
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
|
+ setLayout(new BorderLayout());
|
|
|
|
+ setLocation(100, 100);
|
|
|
|
+ setSize(1000, 800);
|
|
|
|
+
|
|
|
|
+ openSearchPanelHandler = new OpenSearchPanelHandler(this);
|
|
|
|
+ getAllSourceHandler = new GetAllSourceHandler(this);
|
|
|
|
+ getArticlesHandler = new GetArticlesHandler(this);
|
|
|
|
+
|
|
|
|
+ JMenuBar menuBar = new JMenuBar();
|
|
|
|
+ // 检索微信公众号按钮
|
|
|
|
+ JMenu searchMenu = new JMenu("来源");
|
|
|
|
+ JMenuItem searchMI = new JMenuItem("搜索微信公众号");
|
|
|
|
+ JMenuItem allSourceMI = new JMenuItem("查看所有关注");
|
|
|
|
+ searchMenu.add(searchMI);
|
|
|
|
+ searchMenu.add(allSourceMI);
|
|
|
|
+
|
|
|
|
+ JMenu articleMenu = new JMenu("文章");
|
|
|
|
+ JMenuItem articleMI = new JMenuItem("查看文章");
|
|
|
|
+ articleMenu.add(articleMI);
|
|
|
|
+
|
|
|
|
+ searchMI.addActionListener(openSearchPanelHandler);
|
|
|
|
+ allSourceMI.addActionListener(getAllSourceHandler);
|
|
|
|
+
|
|
|
|
+ articleMI.addActionListener(getArticlesHandler);
|
|
|
|
+
|
|
|
|
+ menuBar.add(searchMenu);
|
|
|
|
+ menuBar.add(articleMenu);
|
|
|
|
+
|
|
|
|
+ setJMenuBar(menuBar);
|
|
|
|
+ setVisible(true);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void openSearchPanel() {
|
|
|
|
+ getContentPane().removeAll();
|
|
|
|
+ SearchController controller = new SearchController();
|
|
|
|
+ getContentPane().add(controller.searchUI);
|
|
|
|
+ revalidate(); // 刷新窗体内容
|
|
|
|
+ repaint();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void openSourcePanel() {
|
|
|
|
+ GetAccountModel model = new GetAccountModel();
|
|
|
|
+ GetAccountUI ui = new GetAccountUI();
|
|
|
|
+ GetAccountController controller = new GetAccountController(model, ui);
|
|
|
|
+
|
|
|
|
+ getContentPane().removeAll();
|
|
|
|
+ controller.search();
|
|
|
|
+
|
|
|
|
+ getContentPane().add(ui);
|
|
|
|
+ revalidate();// 刷新窗体内容
|
|
|
|
+ repaint();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void openArticlePanel() {
|
|
|
|
+ //获取数据
|
|
|
|
+ List<ArticleDataVO> articles = getArticlesFromAPI();
|
|
|
|
+
|
|
|
|
+ JPanel mainPanel = new JPanel(new BorderLayout());
|
|
|
|
+ JPanel topPane = new JPanel(new BorderLayout());
|
|
|
|
+
|
|
|
|
+// JComboBox<String> monthComboBox = new JComboBox<>(new String[]{"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"});
|
|
|
|
+// // 添加监听器处理按照月份筛选的逻辑
|
|
|
|
+// monthComboBox.addActionListener(new ActionListener() {
|
|
|
|
+// @Override
|
|
|
|
+// public void actionPerformed(ActionEvent actionEvent) {
|
|
|
|
+// filterDataByMonth(monthComboBox.getSelectedItem().toString());
|
|
|
|
+// }
|
|
|
|
+// });
|
|
|
|
+// topPane.add(new JLabel("月份"));
|
|
|
|
+// topPane.add(monthComboBox);
|
|
|
|
+
|
|
|
|
+// JComboBox<String> monthComboBox = new JComboBox<>();
|
|
|
|
+// for (int i = 1; i <= 12; i++) {
|
|
|
|
+// monthComboBox.addItem(String.valueOf(i));
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// JComboBox<String> yearComboBox = new JComboBox<>();
|
|
|
|
+// int currentYear = java.time.Year.now().getValue();
|
|
|
|
+// for (int i = currentYear - 10; i <= currentYear + 10; i++) {
|
|
|
|
+// yearComboBox.addItem(String.valueOf(i));
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// // 添加¥¥¥处理按照月份筛选的逻辑
|
|
|
|
+// yearComboBox.addActionListener(new ActionListener() {
|
|
|
|
+// @Override
|
|
|
|
+// public void actionPerformed(ActionEvent actionEvent) {
|
|
|
|
+// filterDataByMonth(Integer.parseInt(yearComboBox.getSelectedItem().toString()), Integer.parseInt(monthComboBox.getSelectedItem().toString()));
|
|
|
|
+// }
|
|
|
|
+// });
|
|
|
|
+//
|
|
|
|
+// monthComboBox.addActionListener(new ActionListener() {
|
|
|
|
+// @Override
|
|
|
|
+// public void actionPerformed(ActionEvent actionEvent) {
|
|
|
|
+// filterDataByMonth(Integer.parseInt(yearComboBox.getSelectedItem().toString()), Integer.parseInt(monthComboBox.getSelectedItem().toString()));
|
|
|
|
+// }
|
|
|
|
+// });
|
|
|
|
+// topPane.add(new JLabel("年份"));
|
|
|
|
+// topPane.add(yearComboBox);
|
|
|
|
+// topPane.add(new JLabel("月份"));
|
|
|
|
+// topPane.add(monthComboBox);
|
|
|
|
+
|
|
|
|
+ JButton exportButton = new JButton("导出");
|
|
|
|
+ exportButton.addActionListener(new ActionListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
|
+ JFrame frame = new JFrame();
|
|
|
|
+ // 获取选定行的数据并导出为 Word 文档
|
|
|
|
+ List<ArticleDataVO> selectedArticles = new ArrayList<>();
|
|
|
|
+ for (int i = 0; i < tableModel.getRowCount(); i++) {
|
|
|
|
+ Object value = tableModel.getValueAt(i, 0);
|
|
|
|
+ boolean isSelected;
|
|
|
|
+ if (value instanceof Boolean) {
|
|
|
|
+ isSelected = (Boolean) value;
|
|
|
|
+ } else if (value instanceof String){
|
|
|
|
+ isSelected = Boolean.parseBoolean((String) value);
|
|
|
|
+ } else {
|
|
|
|
+ isSelected = false; // 或者您可以使用其他默认值
|
|
|
|
+ }
|
|
|
|
+ if (isSelected) {
|
|
|
|
+ ArticleDataVO selectedArticle = articles.get(i); // 根据行索引获取对应的文章数据
|
|
|
|
+ selectedArticles.add(selectedArticle); // 将所选数据添加到列表中
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (selectedArticles.isEmpty()) {
|
|
|
|
+ JOptionPane.showMessageDialog(frame, "请选择需要导出的文章!");
|
|
|
|
+ } else {
|
|
|
|
+ Boolean isClassifyExist = true;
|
|
|
|
+ System.out.println("isClassifyExist first" + isClassifyExist);
|
|
|
|
+ for (ArticleDataVO selectedArticle : selectedArticles) {
|
|
|
|
+ if (selectedArticle.getClassify() == null || selectedArticle.getClassify() == 0) {
|
|
|
|
+ isClassifyExist = false;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ System.out.println("isClassifyExist after" + isClassifyExist);
|
|
|
|
+ if (!isClassifyExist) {
|
|
|
|
+ JOptionPane.showMessageDialog(frame, "所选文章中存在分类为空的文章,请填写完整分类信息!");
|
|
|
|
+ } else {
|
|
|
|
+ // 调用导出方法,传入选定的文章数据
|
|
|
|
+ ExportToWordService exportToWordService = new ExportToWordService();
|
|
|
|
+ try {
|
|
|
|
+ byte[] data = exportToWordService.exprotArticlesToWord(selectedArticles);
|
|
|
|
+ // 创建文件选择器并指定默认保存路径
|
|
|
|
+ JFileChooser fileChooser = new JFileChooser();
|
|
|
|
+ fileChooser.setDialogTitle("导出报告");
|
|
|
|
+ fileChooser.setSelectedFile(new File("知识产权相关法律法规资讯整理.docx"));
|
|
|
|
+
|
|
|
|
+ // 显示保存对话框并处理用户的选择
|
|
|
|
+ int userSelection = fileChooser.showSaveDialog(frame);
|
|
|
|
+ if (userSelection == JFileChooser.APPROVE_OPTION) {
|
|
|
|
+ File fileToSave = fileChooser.getSelectedFile();
|
|
|
|
+
|
|
|
|
+ try (FileOutputStream fos = new FileOutputStream(fileToSave.getAbsolutePath() + ".docx")) {
|
|
|
|
+ fos.write(data);
|
|
|
|
+ JOptionPane.showMessageDialog(frame, "文件已成功保存!");
|
|
|
|
+ } catch (IOException ex) {
|
|
|
|
+ ex.printStackTrace();
|
|
|
|
+ JOptionPane.showMessageDialog(frame, "保存文件时出现错误!");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e2) {
|
|
|
|
+ JOptionPane.showMessageDialog(frame, "导出时出现错误!");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ // 将导出按钮添加到 topPane
|
|
|
|
+ topPane.add(exportButton, BorderLayout.EAST);
|
|
|
|
+
|
|
|
|
+ //创建表格的tableModel
|
|
|
|
+ Vector headerNames = new Vector();
|
|
|
|
+ headerNames.add("全选");
|
|
|
|
+ headerNames.add("标题");
|
|
|
|
+ headerNames.add("分类");
|
|
|
|
+ headerNames.add("文章来源");
|
|
|
|
+ headerNames.add("发布时间");
|
|
|
|
+ headerNames.add("更新时间");
|
|
|
|
+ headerNames.add("摘要");
|
|
|
|
+ headerNames.add("操作");
|
|
|
|
+ Vector data = this.getData(articles);
|
|
|
|
+ tableModel = new CheckTableModle(data, headerNames) {
|
|
|
|
+ @Override
|
|
|
|
+ public Class<?> getColumnClass(int columnIndex) {
|
|
|
|
+ if (columnIndex == 0) {
|
|
|
|
+ return Boolean.class;
|
|
|
|
+ } else if (columnIndex == 7) {
|
|
|
|
+ return JButton.class;
|
|
|
|
+ } else {
|
|
|
|
+ return super.getColumnClass(columnIndex);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean isCellEditable(int row, int column) {
|
|
|
|
+ return column == 0 || column == 2 || column == 7;
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ table = new JTable();
|
|
|
|
+ table.setModel(tableModel);
|
|
|
|
+ table.setRowHeight(40);// 行高
|
|
|
|
+ table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); // 多选
|
|
|
|
+ table.putClientProperty("terminateEditOnFocusLost", true);
|
|
|
|
+ table.getTableHeader().setReorderingAllowed(false);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ JTableHeader header = table.getTableHeader();
|
|
|
|
+ header.setPreferredSize(new Dimension(header.getWidth(), 30));// 表头高度
|
|
|
|
+ checkHeaderCellRenderer = new CheckHeaderCellRenderer(table);
|
|
|
|
+ header.setDefaultRenderer(checkHeaderCellRenderer);
|
|
|
|
+
|
|
|
|
+ TableColumnModel columnModel = table.getColumnModel();
|
|
|
|
+ columnModel.getColumn(0).setCellRenderer(new CheckBoxRenderer());
|
|
|
|
+ columnModel.getColumn(0).setCellEditor(new CheckBoxCellEditor());
|
|
|
|
+ columnModel.getColumn(0).setPreferredWidth(30);
|
|
|
|
+ columnModel.getColumn(1).setPreferredWidth(350);
|
|
|
|
+
|
|
|
|
+ Vector<String> vector = new Vector<>();
|
|
|
|
+ vector.add(0, "");
|
|
|
|
+ vector.add("国家知识产权局");
|
|
|
|
+ vector.add("地方法规及规章");
|
|
|
|
+ vector.add("地方标准");
|
|
|
|
+ vector.add("判例");
|
|
|
|
+ vector.add("国外相关资讯");
|
|
|
|
+ vector.add("行业资讯");
|
|
|
|
+ cob = new JComboBox<>(vector);
|
|
|
|
+ cob.setSelectedIndex(-1);
|
|
|
|
+
|
|
|
|
+ cob.addItemListener(new ItemListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void itemStateChanged(ItemEvent e) {
|
|
|
|
+ if(e.getStateChange() == ItemEvent.SELECTED && table.getSelectedRow() >= 0 && table.getSelectedColumn() >= 0) {
|
|
|
|
+ int column = table.getColumnModel().getColumnIndex("分类");
|
|
|
|
+ int selectedColumn = table.getSelectedColumn();
|
|
|
|
+ int selectedRow = table.getSelectedRow();
|
|
|
|
+ int modelRow = table.convertRowIndexToModel(selectedRow);
|
|
|
|
+ if (selectedColumn == column) {
|
|
|
|
+ ArticleDataVO selectArticle = articles.get(modelRow);
|
|
|
|
+ selectArticle.setClassifyName(cob.getSelectedItem().toString());
|
|
|
|
+ Integer classify;
|
|
|
|
+ switch (cob.getSelectedItem().toString()) {
|
|
|
|
+ case "国家知识产权局":
|
|
|
|
+ classify = 1;
|
|
|
|
+ break;
|
|
|
|
+ case "地方法规及规章":
|
|
|
|
+ classify = 2;
|
|
|
|
+ break;
|
|
|
|
+ case "地方标准":
|
|
|
|
+ classify = 3;
|
|
|
|
+ break;
|
|
|
|
+ case "判例":
|
|
|
|
+ classify = 4;
|
|
|
|
+ break;
|
|
|
|
+ case "国外相关资讯":
|
|
|
|
+ classify = 5;
|
|
|
|
+ break;
|
|
|
|
+ case "行业资讯":
|
|
|
|
+ classify = 6;
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ classify = 0;
|
|
|
|
+ }
|
|
|
|
+ if (classify != null && classify != 0) {
|
|
|
|
+ selectArticle.setClassify(classify);
|
|
|
|
+ ArticleInfoService articleInfoService = new ArticleInfoService();
|
|
|
|
+ articleInfoService.updateInfo(selectArticle);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ columnModel.getColumn(2).setCellEditor(new DefaultCellEditor(cob));
|
|
|
|
+
|
|
|
|
+ columnModel.getColumn(7).setCellRenderer(new MyButtonRender());
|
|
|
|
+ columnModel.getColumn(7).setCellEditor(new MyButtonEditor(table, articles));
|
|
|
|
+
|
|
|
|
+ // 创建 TableRowSorter 对象,并将其与表格模型关联
|
|
|
|
+ TableRowSorter<DefaultTableModel> sorter = new TableRowSorter<>(tableModel);
|
|
|
|
+ table.setRowSorter(sorter);
|
|
|
|
+
|
|
|
|
+ //设置鼠标点击跳转外部网页
|
|
|
|
+ table.addMouseListener(new MouseAdapter() {
|
|
|
|
+ @Override
|
|
|
|
+ public void mouseClicked(MouseEvent e) {
|
|
|
|
+ // 获取标题列的索引
|
|
|
|
+ int column = table.getColumnModel().getColumnIndex("标题");
|
|
|
|
+ if (table.columnAtPoint(e.getPoint()) == column) {
|
|
|
|
+ // 获取所点击的行和列
|
|
|
|
+ int viewRow = table.rowAtPoint(e.getPoint());
|
|
|
|
+ int modelRow = table.convertRowIndexToModel(viewRow);
|
|
|
|
+ // 如果点击的是文章链接列
|
|
|
|
+ // 获取链接的地址
|
|
|
|
+ String link = articles.get(modelRow).getLink();
|
|
|
|
+ try {
|
|
|
|
+ Desktop.getDesktop().browse(new URI(link));
|
|
|
|
+ } catch (IOException | URISyntaxException ex) {
|
|
|
|
+ ex.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ // 创建滚动窗格并将表格添加到其中
|
|
|
|
+ JScrollPane scrollPane = new JScrollPane(table);
|
|
|
|
+ // 添加顶部面板和滚动窗格到主面板
|
|
|
|
+ mainPanel.add(topPane, BorderLayout.NORTH);
|
|
|
|
+ mainPanel.add(scrollPane, BorderLayout.CENTER);
|
|
|
|
+ // 清空原有内容,添加主面板,重新绘制
|
|
|
|
+ getContentPane().removeAll();
|
|
|
|
+ getContentPane().add(mainPanel);
|
|
|
|
+ revalidate();
|
|
|
|
+ repaint();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+// private void filterDataByMonth(String selectedMonth) {
|
|
|
|
+// RowFilter<DefaultTableModel, Integer> filter = new RowFilter<DefaultTableModel, Integer>() {
|
|
|
|
+// public boolean include(Entry<? extends DefaultTableModel, ? extends Integer> entry) {
|
|
|
|
+// SimpleDateFormat sdf = new SimpleDateFormat("MMMM");
|
|
|
|
+// Date date = (Date) entry.getValue(3);
|
|
|
|
+// String month = sdf.format(date);
|
|
|
|
+// return month.equals(selectedMonth);
|
|
|
|
+// }
|
|
|
|
+// };
|
|
|
|
+//
|
|
|
|
+// TableRowSorter<DefaultTableModel> sorter = new TableRowSorter<>(tableModel);
|
|
|
|
+// sorter.setRowFilter(filter);
|
|
|
|
+// table.setRowSorter(sorter);
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+ private void filterDataByMonth(int selectedYear, int selectedMonth) {
|
|
|
|
+ RowFilter<DefaultTableModel, Integer> filter = new RowFilter<DefaultTableModel, Integer>() {
|
|
|
|
+ public boolean include(Entry<? extends DefaultTableModel, ? extends Integer> entry) {
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
+ try {
|
|
|
|
+ Date date = sdf.parse(entry.getStringValue(3)); // Parse the String date to Date object
|
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
|
+ calendar.setTime(date);
|
|
|
|
+
|
|
|
|
+ // Extracting year and month from the date
|
|
|
|
+ int year = calendar.get(Calendar.YEAR);
|
|
|
|
+ int month = calendar.get(Calendar.MONTH) + 1; // Adjusting month index
|
|
|
|
+
|
|
|
|
+ // Checking if the month and year match the selected criteria
|
|
|
|
+ return (year == selectedYear && month == selectedMonth);
|
|
|
|
+ } catch (ParseException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ TableRowSorter<DefaultTableModel> sorter = new TableRowSorter<>(tableModel);
|
|
|
|
+ sorter.setRowFilter(filter);
|
|
|
|
+ table.setRowSorter(sorter);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public List<ArticleDataVO> getArticlesFromAPI() {
|
|
|
|
+ ArticleInfoService articleInfoService = new ArticleInfoService();
|
|
|
|
+ List<ArticleDataVO> articleDataVOS = articleInfoService.getArticles();
|
|
|
|
+ for (ArticleDataVO articleDataVO : articleDataVOS) {
|
|
|
|
+ Integer classify = articleDataVO.getClassify();
|
|
|
|
+ switch (classify) {
|
|
|
|
+ case 1:
|
|
|
|
+ articleDataVO.setClassifyName("国家知识产权局");
|
|
|
|
+ break;
|
|
|
|
+ case 2:
|
|
|
|
+ articleDataVO.setClassifyName("地方法规及规章");
|
|
|
|
+ break;
|
|
|
|
+ case 3:
|
|
|
|
+ articleDataVO.setClassifyName("地方标准");
|
|
|
|
+ break;
|
|
|
|
+ case 4:
|
|
|
|
+ articleDataVO.setClassifyName("判例");
|
|
|
|
+ break;
|
|
|
|
+ case 5:
|
|
|
|
+ articleDataVO.setClassifyName("国外相关资讯");
|
|
|
|
+ break;
|
|
|
|
+ case 6:
|
|
|
|
+ articleDataVO.setClassifyName("行业资讯");
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ articleDataVO.setClassifyName(" ");
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return articleDataVOS;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Vector getData(List<ArticleDataVO> articles) {
|
|
|
|
+ Vector data = new Vector();
|
|
|
|
+ for (ArticleDataVO articleDataVO : articles) {
|
|
|
|
+ Vector rowVector = new Vector();
|
|
|
|
+ rowVector.add("");
|
|
|
|
+ rowVector.add(articleDataVO.getTitle());
|
|
|
|
+ rowVector.add(articleDataVO.getClassifyName());
|
|
|
|
+ rowVector.add(articleDataVO.getCameFrom());
|
|
|
|
+ rowVector.add(articleDataVO.getTime());
|
|
|
|
+ rowVector.add(articleDataVO.getCreateTime());
|
|
|
|
+ rowVector.add(articleDataVO.getAbs());
|
|
|
|
+ data.add(rowVector);
|
|
|
|
+ }
|
|
|
|
+ return data;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ class CheckBoxRenderer extends JCheckBox implements TableCellRenderer {
|
|
|
|
+ // 声明一个序列化版本标识符,用于控制对象序列化的版本一致性
|
|
|
|
+ private static final long serialVersionUID = 1L;
|
|
|
|
+ // 定义一个边框对象
|
|
|
|
+ Border border = new EmptyBorder(1, 2, 1, 2);
|
|
|
|
+
|
|
|
|
+ // CheckBoxRenderer 类的构造函数,初始化复选框渲染器
|
|
|
|
+ public CheckBoxRenderer() {
|
|
|
|
+ super();// 调用父类 JCheckBox 的构造函数
|
|
|
|
+ setOpaque(true);// 设置组件为不透明
|
|
|
|
+ setHorizontalAlignment(SwingConstants.CENTER);// 设置水平对齐方式为居中
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 实现 TableCellRenderer 接口中的 getTableCellRendererComponent 方法
|
|
|
|
+ @Override
|
|
|
|
+ public Component getTableCellRendererComponent (
|
|
|
|
+ JTable table,
|
|
|
|
+ Object value,
|
|
|
|
+ boolean isSelected,
|
|
|
|
+ boolean hasFocus,
|
|
|
|
+ int row,
|
|
|
|
+ int column) {
|
|
|
|
+ // 检查值是否为 Boolean 类型
|
|
|
|
+ if (value instanceof Boolean) {
|
|
|
|
+ // 根据 Boolean 值设置复选框选择状态
|
|
|
|
+ setSelected(((Boolean) value).booleanValue());
|
|
|
|
+ setForeground(table.getForeground());// 设置前景色
|
|
|
|
+ setBackground(table.getBackground());// 设置背景色
|
|
|
|
+ }
|
|
|
|
+ return this;// 返回渲染完成的组件
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ class CheckBoxCellEditor extends AbstractCellEditor implements TableCellEditor {
|
|
|
|
+ private static final long serialVersionUID = 1L;
|
|
|
|
+ // 声明一个 JCheckBox 类型的变量 checkBox
|
|
|
|
+ protected JCheckBox checkBox;
|
|
|
|
+
|
|
|
|
+ public CheckBoxCellEditor() {
|
|
|
|
+ checkBox = new JCheckBox();// 创建新的复选框实例
|
|
|
|
+ checkBox.setHorizontalAlignment(SwingConstants.CENTER);// 设置复选框水平对齐方式为居中
|
|
|
|
+ checkBox.addChangeListener(new ChangeListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void stateChanged(ChangeEvent e) {
|
|
|
|
+ fireEditingStopped();
|
|
|
|
+
|
|
|
|
+ if (checkBox.isSelected()) { // 勾选,判断是否已经全部勾选,如果是将header勾选
|
|
|
|
+ int count = 0;
|
|
|
|
+ for (int rowNo = 0; rowNo < table.getRowCount(); rowNo++) {
|
|
|
|
+ Object value = table.getValueAt(rowNo, 0);
|
|
|
|
+ Boolean cbx;
|
|
|
|
+ if (value instanceof String) {
|
|
|
|
+ String stringValue = (String) value;
|
|
|
|
+ System.out.println("stringValue" + stringValue);
|
|
|
|
+ cbx = Boolean.parseBoolean(stringValue);
|
|
|
|
+ } else if (value instanceof Boolean) {
|
|
|
|
+ cbx = (Boolean) value;
|
|
|
|
+ } else {
|
|
|
|
+ cbx = false;
|
|
|
|
+ }
|
|
|
|
+// Boolean cbx = (Boolean) table.getValueAt(rowNo, 0);
|
|
|
|
+ if (cbx) count++;
|
|
|
|
+ }
|
|
|
|
+ if (count == table.getRowCount()) {
|
|
|
|
+ checkHeaderCellRenderer.setSelectBox(true);
|
|
|
|
+ } else {
|
|
|
|
+ checkHeaderCellRenderer.setSelectBox(false);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 覆盖 AbstractCellEditor 类的方法,获取当前单元格编辑器的值
|
|
|
|
+ @Override
|
|
|
|
+ public Object getCellEditorValue() {
|
|
|
|
+ return Boolean.valueOf(checkBox.isSelected());// 返回当前复选框的选择状态
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 覆盖 TableCellEditor 接口的方法,返回单元格编辑器组件
|
|
|
|
+ @Override
|
|
|
|
+ public Component getTableCellEditorComponent(
|
|
|
|
+ JTable table,
|
|
|
|
+ Object value,
|
|
|
|
+ boolean isSelected,
|
|
|
|
+ int row,
|
|
|
|
+ int column) {
|
|
|
|
+ if (value instanceof Boolean) {
|
|
|
|
+ checkBox.setSelected((Boolean) value); // 如果值是布尔类型,则直接设置选中状态
|
|
|
|
+ } else if (value instanceof String) {
|
|
|
|
+ checkBox.setSelected(Boolean.parseBoolean((String) value)); // 如果值是字符串类型,则解析为布尔值后设置选中状态
|
|
|
|
+ }
|
|
|
|
+ return checkBox; // 返回复选框组件
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|