Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bit4woo committed Apr 26, 2024
1 parent ced5b4b commit 52a3054
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 21 deletions.
43 changes: 31 additions & 12 deletions src/config/ConfigTable.java
Original file line number Diff line number Diff line change
@@ -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 {
/**
Expand Down Expand Up @@ -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() {
Expand All @@ -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) {
Expand Down
21 changes: 12 additions & 9 deletions src/config/ConfigTableMenu.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
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 {


private static final long serialVersionUID = 1L;
PrintWriter stdout = BurpExtender.getStdout();
PrintWriter stderr = BurpExtender.getStderr();

private ConfigTable configTable;

/**
* 这处理传入的行index数据是经过转换的 model中的index,不是原始的JTable中的index。
* @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) {
Expand All @@ -39,7 +42,7 @@ public void actionPerformed(ActionEvent actionEvent) {
}
}
});

JMenuItem disableItem = new JMenuItem(new AbstractAction("Disable Config") {
@Override
public void actionPerformed(ActionEvent actionEvent) {
Expand All @@ -49,7 +52,7 @@ public void actionPerformed(ActionEvent actionEvent) {
}
}
});

add(itemNumber);
add(enableItem);
add(disableItem);
Expand Down

0 comments on commit 52a3054

Please sign in to comment.