Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bit4woo committed May 16, 2024
1 parent 3bc60e5 commit 3f2f5bf
Show file tree
Hide file tree
Showing 3 changed files with 206 additions and 167 deletions.
25 changes: 5 additions & 20 deletions src/messageTab/Info/InfoTab.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package messageTab.Info;

import java.awt.Component;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.SwingWorker;

import com.bit4woo.utilbox.utils.ByteArrayUtils;
Expand Down Expand Up @@ -90,6 +88,7 @@ protected Void doInBackground() throws Exception {
}

List<String> emails = EmailUtils.grepEmail(text);
emails = TextUtils.deduplicate(emails);
for (String email:emails) {
InfoEntry aaa = new InfoEntry(email,InfoEntry.Type_Email);
((InfoPanel)panel).getTable().getInfoTableModel().addNewInfoEntry(aaa);
Expand Down Expand Up @@ -118,30 +117,16 @@ public boolean isModified()
{
return false;
}

/**
* ctrl+c复制数据逻辑会调用这个函数
*/
@Override
public byte[] getSelectedData()
{
JTable table = ((InfoPanel)panel).getTable();
int[] rows = table.getSelectedRows();
int[] columns = table.getSelectedColumns();
List<String> result = new ArrayList<>();
for (int row:rows) {
List<String> line = new ArrayList<>();
for (int column:columns) {
try {
String value = (String)table.getValueAt(row, column);
line.add(value);
} catch (Exception e) {
//e.printStackTrace();
}
}
result.add(String.join(" ", line));
}
return String.join(System.lineSeparator(), result).getBytes();
InfoTable table = (InfoTable)((InfoPanel)panel).getTable();
String content = table.getSelectedContent();
return content.getBytes();
}


Expand Down
309 changes: 162 additions & 147 deletions src/messageTab/Info/InfoTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.awt.FontMetrics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

Expand All @@ -21,152 +22,166 @@


public class InfoTable extends JTable {
/**
*
*/
private static final long serialVersionUID = 1L;

//public static final String[] headers = {"Value", "Type"};
public static final String[] headers = {"Value"};

public InfoTable(InfoTableModel tableModel) {
super(tableModel);
this.setColumnModel(columnModel);
this.setFillsViewportHeight(true);//在table的空白区域显示右键菜单
//https://stackoverflow.com/questions/8903040/right-click-mouselistener-on-whole-jtable-component
this.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
this.setBorder(new LineBorder(new Color(0, 0, 0)));

addClickSort();
registerListeners();
//switchEnable();//no need
//table.setupTypeColumn()//can't set here, only can after table data loaded.
//tableHeaderLengthInit();//can't set here, only can after table data loaded.
}

public static List<String> getHeaders() {
return Arrays.asList(headers);
}


public InfoTableModel getInfoTableModel() {
return (InfoTableModel) this.getModel();
}


public int[] getSelectedModelRows() {
int[] rows = getSelectedRows();

for (int i = 0; i < rows.length; i++) {
rows[i] = convertRowIndexToModel(rows[i]);//转换为Model的索引,否则排序后索引不对应〿
}
Arrays.sort(rows);//升序
return rows;
}

public InfoEntry getEntryAt(int row) {
return ((InfoTableModel) this.getModel()).getEntryAt(convertRowIndexToModel(row));
}

private void addClickSort() {
TableRowSorter<InfoTableModel> sorter = new TableRowSorter<>((InfoTableModel) this.getModel());
this.setRowSorter(sorter);
}

/**
* 需要在数据加载后,即setModel后才有效果!
*/
public void tableHeaderLengthInit() {
Font f = this.getFont();
FontMetrics fm = this.getFontMetrics(f);
int width = fm.stringWidth("A");//一个字符的宽度
for (int index = 0; index < this.getColumnCount(); index++) {
TableColumn column = this.getColumnModel().getColumn(index);

if (column.getIdentifier().equals("#")) {
column.setMaxWidth(width * "100".length());
}

if (column.getIdentifier().equals("Enable")) {
column.setMaxWidth(width * "Enable++".length());
//需要预留排序时箭头符合的位置,2个字符宽度
}
}
//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() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
InfoTable target = (InfoTable) e.getSource();
int row = target.getSelectedRow();
int column = target.getSelectedColumn();

//双击浏览器打开url
if (headers[column].equalsIgnoreCase("Value")) {//双击url在浏览器中打开
try {
InfoEntry entry = getEntryAt(row);
if (entry.getType().equals(InfoEntry.Type_URL)) {
String url = (String) getValueAt(row, column);
if (url.toLowerCase().startsWith("http://") || url.toLowerCase().startsWith("https://")) {
String browserPath = BurpExtender.getConfigTableModel().getConfigValueByKey("browserPath");
SystemUtils.browserOpen(url, browserPath);
return;
}
}
} catch (Exception e1) {
e1.printStackTrace(BurpExtender.getStderr());
}
}

//默认行为,复制到剪切板
String value = (String) getValueAt(row, column);
SystemUtils.writeToClipboard(value);
}
}

@Override//title表格中的鼠标右键菜单
public void mouseReleased(MouseEvent e) {
if (SwingUtilities.isRightMouseButton(e)) {
if (e.isPopupTrigger() && e.getComponent() instanceof InfoTable) {
int[] rows = getSelectedRows();
int col = ((InfoTable) e.getSource()).columnAtPoint(e.getPoint()); // 获得列位置
int modelCol = InfoTable.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) {
//no need
}
});
}


/**
* 搜索功能
* @param caseSensitive
*/
/*
/**
*
*/
private static final long serialVersionUID = 1L;

//public static final String[] headers = {"Value", "Type"};
public static final String[] headers = {"Value"};

public InfoTable(InfoTableModel tableModel) {
super(tableModel);
this.setColumnModel(columnModel);
this.setFillsViewportHeight(true);//在table的空白区域显示右键菜单
//https://stackoverflow.com/questions/8903040/right-click-mouselistener-on-whole-jtable-component
this.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
this.setBorder(new LineBorder(new Color(0, 0, 0)));

addClickSort();
registerListeners();
//switchEnable();//no need
//table.setupTypeColumn()//can't set here, only can after table data loaded.
//tableHeaderLengthInit();//can't set here, only can after table data loaded.
}

public static List<String> getHeaders() {
return Arrays.asList(headers);
}


public InfoTableModel getInfoTableModel() {
return (InfoTableModel) this.getModel();
}


public int[] getSelectedModelRows() {
int[] rows = getSelectedRows();

for (int i = 0; i < rows.length; i++) {
rows[i] = convertRowIndexToModel(rows[i]);//转换为Model的索引,否则排序后索引不对应〿
}
Arrays.sort(rows);//升序
return rows;
}

public InfoEntry getEntryAt(int row) {
return ((InfoTableModel) this.getModel()).getEntryAt(convertRowIndexToModel(row));
}

private void addClickSort() {
TableRowSorter<InfoTableModel> sorter = new TableRowSorter<>((InfoTableModel) this.getModel());
this.setRowSorter(sorter);
}

/**
* 需要在数据加载后,即setModel后才有效果!
*/
public void tableHeaderLengthInit() {
Font f = this.getFont();
FontMetrics fm = this.getFontMetrics(f);
int width = fm.stringWidth("A");//一个字符的宽度
for (int index = 0; index < this.getColumnCount(); index++) {
TableColumn column = this.getColumnModel().getColumn(index);

if (column.getIdentifier().equals("#")) {
column.setMaxWidth(width * "100".length());
}

if (column.getIdentifier().equals("Enable")) {
column.setMaxWidth(width * "Enable++".length());
//需要预留排序时箭头符合的位置,2个字符宽度
}
}
//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() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
InfoTable target = (InfoTable) e.getSource();
int row = target.getSelectedRow();
int column = target.getSelectedColumn();

//双击浏览器打开url
if (headers[column].equalsIgnoreCase("Value")) {//双击url在浏览器中打开
try {
InfoEntry entry = getEntryAt(row);
if (entry.getType().equals(InfoEntry.Type_URL)) {
String url = (String) getValueAt(row, column);
if (url.toLowerCase().startsWith("http://") || url.toLowerCase().startsWith("https://")) {
String browserPath = BurpExtender.getConfigTableModel().getConfigValueByKey("browserPath");
SystemUtils.browserOpen(url, browserPath);
return;
}
}
} catch (Exception e1) {
e1.printStackTrace(BurpExtender.getStderr());
}
}

//默认行为,复制到剪切板
String value = (String) getValueAt(row, column);
SystemUtils.writeToClipboard(value);
}
}

@Override//title表格中的鼠标右键菜单
public void mouseReleased(MouseEvent e) {
if (SwingUtilities.isRightMouseButton(e)) {
if (e.isPopupTrigger() && e.getComponent() instanceof InfoTable) {
new InfoTableMenu(InfoTable.this).show(e.getComponent(), e.getX(), e.getY());
}
}
}

@Override
public void mousePressed(MouseEvent e) {
//no need
}
});
}


public String getSelectedContent () {
int[] rows = this.getSelectedRows();
int[] columns = this.getSelectedColumns();
List<String> result = new ArrayList<>();
for (int row:rows) {
List<String> line = new ArrayList<>();
for (int column:columns) {
try {
String value = (String)this.getValueAt(row, column);
line.add(value);
} catch (Exception e) {
//e.printStackTrace();
}
}
result.add(String.join(" ", line));
}
return String.join(System.lineSeparator(), result);
}


/**
* 搜索功能
* @param caseSensitive
*/
/*
public void search(String Input,boolean caseSensitive) {
final RowFilter filter = new RowFilter() {
@Override
Expand All @@ -182,5 +197,5 @@ public boolean include(Entry entry) {
};
((TableRowSorter)getRowSorter()).setRowFilter(filter);
}
*/
*/
}
Loading

0 comments on commit 3f2f5bf

Please sign in to comment.