From 52a30546b4652cefcc1019f2d1bfacc3d13c2e13 Mon Sep 17 00:00:00 2001 From: bit4woo Date: Fri, 26 Apr 2024 17:51:45 +0800 Subject: [PATCH] update --- src/config/ConfigTable.java | 43 ++++++++++++++++++++++++--------- src/config/ConfigTableMenu.java | 21 +++++++++------- 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/src/config/ConfigTable.java b/src/config/ConfigTable.java index 6a3ca9b..88b35aa 100644 --- a/src/config/ConfigTable.java +++ b/src/config/ConfigTable.java @@ -1,28 +1,25 @@ package config; -import java.awt.*; +import static config.ConfigTableModel.titles; + +import java.awt.Color; +import java.awt.Font; +import java.awt.FontMetrics; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.io.PrintWriter; import java.util.Arrays; import javax.swing.DefaultCellEditor; -import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JTable; import javax.swing.ListSelectionModel; import javax.swing.RowFilter; -import javax.swing.RowFilter.Entry; +import javax.swing.SwingUtilities; import javax.swing.border.LineBorder; -import javax.swing.table.JTableHeader; import javax.swing.table.TableColumn; import javax.swing.table.TableColumnModel; import javax.swing.table.TableRowSorter; -import burp.BurpExtender; - -import static config.ConfigTableModel.titles; - public class ConfigTable extends JTable { /** @@ -96,6 +93,17 @@ public void tableHeaderLengthInit() { //this.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);//配合横向滚动条 } + + //将选中的行(图形界面的行)转换为Model中的行数(数据队列中的index).因为图形界面排序等操作会导致图像和数据队列的index不是线性对应的。 + public int[] SelectedRowsToModelRows(int[] SelectedRows) { + + for (int i = 0; i < SelectedRows.length; i++){ + SelectedRows[i] = convertRowIndexToModel(SelectedRows[i]);//转换为Model的索引,否则排序后索引不对应〿 + } + Arrays.sort(SelectedRows);//升序 + + return SelectedRows; + } private void registerListeners() { this.addMouseListener(new MouseAdapter() { @@ -112,9 +120,20 @@ public void mouseClicked(MouseEvent e) { } } - @Override - public void mouseReleased(MouseEvent e) { - } + @Override//title表格中的鼠标右键菜单 + public void mouseReleased( MouseEvent e ){ + if ( SwingUtilities.isRightMouseButton( e )){ + if (e.isPopupTrigger() && e.getComponent() instanceof ConfigTable ) { + int[] rows = getSelectedRows(); + int col = ((ConfigTable) e.getSource()).columnAtPoint(e.getPoint()); // 获得列位置 + int modelCol = ConfigTable.this.convertColumnIndexToModel(col); + if (rows.length>0){ + int[] modelRows = SelectedRowsToModelRows(rows); + new ConfigTableMenu(ConfigTable.this, modelRows, modelCol).show(e.getComponent(), e.getX(), e.getY()); + } + } + } + } @Override public void mousePressed(MouseEvent e) { diff --git a/src/config/ConfigTableMenu.java b/src/config/ConfigTableMenu.java index a99048f..9423c30 100644 --- a/src/config/ConfigTableMenu.java +++ b/src/config/ConfigTableMenu.java @@ -1,11 +1,14 @@ package config; -import burp.BurpExtender; - -import javax.swing.*; import java.awt.event.ActionEvent; import java.io.PrintWriter; +import javax.swing.AbstractAction; +import javax.swing.JMenuItem; +import javax.swing.JPopupMenu; + +import burp.BurpExtender; + public class ConfigTableMenu extends JPopupMenu { @@ -13,7 +16,7 @@ public class ConfigTableMenu extends JPopupMenu { private static final long serialVersionUID = 1L; PrintWriter stdout = BurpExtender.getStdout(); PrintWriter stderr = BurpExtender.getStderr(); - + private ConfigTable configTable; /** @@ -21,15 +24,15 @@ public class ConfigTableMenu extends JPopupMenu { * @param modelRows * @param columnIndex */ - ConfigTableMenu(final GUI gui, final int[] modelRows,final int columnIndex){ - + ConfigTableMenu(final ConfigTable configTable, final int[] modelRows,final int columnIndex){ + this.configTable = configTable; JMenuItem itemNumber = new JMenuItem(new AbstractAction(modelRows.length+" Items Selected") { @Override public void actionPerformed(ActionEvent actionEvent) { } }); - + JMenuItem enableItem = new JMenuItem(new AbstractAction("Enable Config") { @Override public void actionPerformed(ActionEvent actionEvent) { @@ -39,7 +42,7 @@ public void actionPerformed(ActionEvent actionEvent) { } } }); - + JMenuItem disableItem = new JMenuItem(new AbstractAction("Disable Config") { @Override public void actionPerformed(ActionEvent actionEvent) { @@ -49,7 +52,7 @@ public void actionPerformed(ActionEvent actionEvent) { } } }); - + add(itemNumber); add(enableItem); add(disableItem);