mirror of
https://bitbucket.org/projectswg/packet-master.git
synced 2026-10-17 08:03:00 -04:00
Added finding system, next/prev is still a bit sketchy though
This commit is contained in:
@@ -116,7 +116,7 @@ public class PacketMaster {
|
||||
InetAddress addr = null;
|
||||
Payload p = null;
|
||||
while (pcap.nextEx(packet) == 1) {
|
||||
if (packet == null)
|
||||
if (packet == null || gui.isClosed())
|
||||
return;
|
||||
if (packet.hasHeader(ip)) {
|
||||
addr = InetAddress.getByAddress(ip.source());
|
||||
|
||||
@@ -33,6 +33,7 @@ public class GUI extends JFrame {
|
||||
private PacketMaster packetMaster;
|
||||
private PacketFrame packetFrame;
|
||||
private AnalysisFrame analysisFrame;
|
||||
private ToolbarFrame toolbarFrame;
|
||||
private boolean closed;
|
||||
|
||||
public GUI(PacketMaster packetMaster, List <GUIPacket> packets) {
|
||||
@@ -51,6 +52,9 @@ public class GUI extends JFrame {
|
||||
analysisFrame = new AnalysisFrame(this);
|
||||
getContentPane().add(analysisFrame);
|
||||
|
||||
toolbarFrame = new ToolbarFrame(this);
|
||||
getContentPane().add(toolbarFrame);
|
||||
|
||||
resizeComponents();
|
||||
createMenus();
|
||||
|
||||
@@ -64,28 +68,17 @@ public class GUI extends JFrame {
|
||||
});
|
||||
|
||||
addWindowListener(new WindowListener() {
|
||||
public void windowOpened(WindowEvent e) {
|
||||
}
|
||||
|
||||
public void windowIconified(WindowEvent e) {
|
||||
}
|
||||
|
||||
public void windowDeiconified(WindowEvent e) {
|
||||
}
|
||||
|
||||
public void windowDeactivated(WindowEvent e) {
|
||||
}
|
||||
|
||||
public void windowOpened(WindowEvent e) { }
|
||||
public void windowIconified(WindowEvent e) { }
|
||||
public void windowDeiconified(WindowEvent e) { }
|
||||
public void windowDeactivated(WindowEvent e) { }
|
||||
public void windowActivated(WindowEvent e) { }
|
||||
public void windowClosing(WindowEvent e) {
|
||||
closed = true;
|
||||
}
|
||||
|
||||
public void windowClosed(WindowEvent e) {
|
||||
closed = true;
|
||||
}
|
||||
|
||||
public void windowActivated(WindowEvent e) {
|
||||
}
|
||||
});
|
||||
setVisible(true);
|
||||
}
|
||||
@@ -98,6 +91,14 @@ public class GUI extends JFrame {
|
||||
analysisFrame.setPacket(packet);
|
||||
}
|
||||
|
||||
public void onPacketSelected(int index) {
|
||||
if (index < 0 || index >= packets.size())
|
||||
return;
|
||||
GUIPacket packet = packets.get(index);
|
||||
packetFrame.onPacketSelected(index);
|
||||
analysisFrame.setPacket(packet);
|
||||
}
|
||||
|
||||
public PacketStructure getPacketStructure(PacketType type) {
|
||||
return packetMaster.getPacketStructure(type);
|
||||
}
|
||||
@@ -105,6 +106,7 @@ public class GUI extends JFrame {
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
packetFrame.setPackets(packets);
|
||||
toolbarFrame.setPackets(packets);
|
||||
super.paint(g);
|
||||
packetFrame.revalidate();
|
||||
}
|
||||
@@ -113,8 +115,9 @@ public class GUI extends JFrame {
|
||||
int maxWidth = getWidth() - getInsets().left - getInsets().right;
|
||||
int maxHeight = getHeight() - getInsets().top - getInsets().bottom;
|
||||
Dimension packetFrameDim = packetFrame.getPreferredDimensions(maxWidth, maxHeight);
|
||||
packetFrameScroll.setBounds(0, 0, packetFrameDim.width+10, packetFrameDim.height);
|
||||
analysisFrame.setBounds(packetFrameDim.width+10, 0, analysisFrame.getDesiredWidth(maxWidth), maxHeight);
|
||||
toolbarFrame.setBounds(0, 0, toolbarFrame.getDesiredWidth(maxWidth), toolbarFrame.getDesiredHeight(maxHeight));
|
||||
packetFrameScroll.setBounds(0, toolbarFrame.getHeight(), packetFrameDim.width+10, packetFrameDim.height-toolbarFrame.getHeight());
|
||||
analysisFrame.setBounds(packetFrameDim.width+10, toolbarFrame.getHeight(), analysisFrame.getDesiredWidth(maxWidth), maxHeight-toolbarFrame.getHeight());
|
||||
}
|
||||
|
||||
private void createMenus() {
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.awt.Dimension;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.ScrollPane;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.util.ArrayList;
|
||||
@@ -107,6 +108,13 @@ public class PacketFrame extends JPanel implements Scrollable, MouseListener {
|
||||
return dimensions;
|
||||
}
|
||||
|
||||
public void onPacketSelected(int index) {
|
||||
int middle = index * ROW_HEIGHT; //getVisibleRect().y / ROW_HEIGHT;
|
||||
scrollRectToVisible(new Rectangle(0, middle-getParent().getHeight()/2, getWidth(), middle+getParent().getHeight()/2));
|
||||
highlightedIndex = index;
|
||||
repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
return getSize();
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
package me.joshlarson.gui;
|
||||
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class ToolbarFrame extends JPanel {
|
||||
|
||||
private static final long serialVersionUID = 5520601215345135883L;
|
||||
private List <GUIPacket> packets = null;
|
||||
private JTextField searchText;
|
||||
private JButton previousButton;
|
||||
private JButton nextButton;
|
||||
private GUI gui;
|
||||
private int searchIndex;
|
||||
|
||||
public ToolbarFrame(GUI gui) {
|
||||
super();
|
||||
this.gui = gui;
|
||||
searchText = new JTextField();
|
||||
searchText.setFont(searchText.getFont().deriveFont(13f));
|
||||
searchText.addKeyListener(new KeyListener() {
|
||||
public void keyTyped(KeyEvent e) { }
|
||||
public void keyPressed(KeyEvent e) { }
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
search();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
add(searchText);
|
||||
|
||||
previousButton = new JButton("Prev");
|
||||
previousButton.addMouseListener(new MouseListener() {
|
||||
public void mouseClicked(MouseEvent e) { }
|
||||
public void mousePressed(MouseEvent e) { }
|
||||
public void mouseEntered(MouseEvent e) { }
|
||||
public void mouseExited(MouseEvent e) { }
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
findPrevious();
|
||||
}
|
||||
});
|
||||
add(previousButton);
|
||||
nextButton = new JButton("Next");
|
||||
nextButton.addMouseListener(new MouseListener() {
|
||||
public void mouseClicked(MouseEvent e) { }
|
||||
public void mousePressed(MouseEvent e) { }
|
||||
public void mouseEntered(MouseEvent e) { }
|
||||
public void mouseExited(MouseEvent e) { }
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
findNext();
|
||||
}
|
||||
});
|
||||
add(nextButton);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
public void setPackets(List <GUIPacket> packets) {
|
||||
this.packets = packets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBounds(int x, int y, int width, int height) {
|
||||
super.setBounds(x, y, width, height);
|
||||
updateComponents();
|
||||
}
|
||||
|
||||
public void setSize(int width, int height) {
|
||||
super.setSize(width, height);
|
||||
updateComponents();
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
super.paint(g);
|
||||
FontMetrics metrics = g.getFontMetrics();
|
||||
g.drawRect(0, 0, getWidth(), getHeight());
|
||||
g.drawString("Search:", 5, getHeight()-10);
|
||||
searchText.setLocation(metrics.stringWidth("Search:")+10, 5);
|
||||
}
|
||||
|
||||
public int getDesiredWidth(int maxWidth) {
|
||||
return maxWidth;
|
||||
}
|
||||
|
||||
public int getDesiredHeight(int maxHeight) {
|
||||
return 30;
|
||||
}
|
||||
|
||||
private void updateComponents() {
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
if (width/4 >= 200)
|
||||
searchText.setSize(200, height-10);
|
||||
else
|
||||
searchText.setSize(width/4, height-10);
|
||||
}
|
||||
|
||||
private void search() {
|
||||
if (packets == null)
|
||||
return;
|
||||
searchIndex = find(0, packets.size());
|
||||
gui.onPacketSelected(searchIndex);
|
||||
}
|
||||
|
||||
private void findNext() {
|
||||
if (packets == null)
|
||||
return;
|
||||
searchIndex = find(searchIndex+1, packets.size());
|
||||
if (searchIndex == -1)
|
||||
searchIndex = find(0, packets.size());
|
||||
gui.onPacketSelected(searchIndex);
|
||||
}
|
||||
|
||||
private void findPrevious() {
|
||||
if (packets == null)
|
||||
return;
|
||||
searchIndex = find(0, searchIndex);
|
||||
if (searchIndex == -1) {
|
||||
int ind = -2;
|
||||
while (ind != -1) {
|
||||
ind = find(ind+1, packets.size());
|
||||
if (ind != -1)
|
||||
searchIndex = ind;
|
||||
}
|
||||
}
|
||||
gui.onPacketSelected(searchIndex);
|
||||
}
|
||||
|
||||
private int find(int start, int end) {
|
||||
if (start < 0)
|
||||
start = 0;
|
||||
if (start >= packets.size())
|
||||
start = packets.size()-1;
|
||||
if (end < 0)
|
||||
end = 0;
|
||||
if (end > packets.size())
|
||||
end = packets.size();
|
||||
if (end < start)
|
||||
return -1;
|
||||
String text = searchText.getText();
|
||||
int index = -1;
|
||||
int textIntDec = -1;
|
||||
try { textIntDec = Integer.valueOf(text); } catch (NumberFormatException e) { }
|
||||
int textIntHex = -1;
|
||||
try { textIntHex = Integer.valueOf(text); } catch (NumberFormatException e) { }
|
||||
for (int i = start; i < end && i < packets.size(); i++) {
|
||||
GUIPacket packet = packets.get(i);
|
||||
String packetName = "";
|
||||
if (packet.getPacket() != null)
|
||||
packetName = packet.getPacket().getClass().getSimpleName();
|
||||
if (packetName.toLowerCase().contains(text.toLowerCase())) {
|
||||
index = i;
|
||||
break;
|
||||
} else if (packet.getSOEOpcode() == textIntDec || packet.getSWGOpcode() == textIntDec) {
|
||||
index = i;
|
||||
break;
|
||||
} else if (packet.getSOEOpcode() == textIntHex || packet.getSWGOpcode() == textIntHex) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user