Exemplo n.º 1
0
  public ViewPane(GameSessionViewer gsv) {
    _gameSessionViewer = gsv;

    this.setLayout(_layout);

    GridBagConstraints cons = new GridBagConstraints();
    cons.insets = new Insets(5, 5, 5, 5);
    cons.weightx = 0.5;
    cons.gridy = 0;
    cons.gridheight = 5;
    cons.weighty = 0.95;
    cons.fill = GridBagConstraints.BOTH;
    _packetTableModel = new PacketTableModel();
    _packetTable = new JTable(_packetTableModel);
    _packetTable.addMouseListener(new PacketTableMouseListener());
    _packetTable.setDefaultRenderer(Object.class, new PacketTableRenderer(_packetTableModel));
    _packetTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    _packetTable.getSelectionModel().addListSelectionListener(new PacketSelectionListener());
    _packetTable.getColumnModel().getColumn(0).setMaxWidth(35);
    _packetTable.getColumnModel().getColumn(1).setMaxWidth(50);
    _packetTable.getColumnModel().getColumn(2).setMaxWidth(90);
    _packetTable.getColumnModel().getColumn(3).setMaxWidth(45);
    JScrollPane scrollPane = new JScrollPane(_packetTable);
    this.add(scrollPane, cons);

    cons.fill = GridBagConstraints.BOTH;
    // cons.anchor = GridBagConstraints.NORTH;
    cons.weightx = 0.5;
    cons.weighty = 0.5;
    cons.gridx = 1;
    cons.gridy = 1;
    cons.gridheight = 1;
    _hexDumpArea = new JTextPane();
    _hexDumpArea.setPreferredSize(new Dimension(100, 317));
    // _hexDumpArea.setDoubleBuffered(true);
    _hexStyledDoc = (DefaultStyledDocument) _hexDumpArea.getStyledDocument();
    addStylesToHexDump(_hexStyledDoc);
    // Font font = new Font("Monospaced", Font.PLAIN, 12);
    // _hexDumpArea.setFont(font);
    // _hexDumpArea.setRows(18);
    // _hexDumpArea.setColumns(20);
    JScrollPane hexDumpScrollPane =
        new JScrollPane(
            _hexDumpArea,
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    this.add(hexDumpScrollPane, cons);

    JPanel smallPane = new JPanel();
    smallPane.setLayout(_layout);
    cons.fill = GridBagConstraints.NONE;
    cons.weightx = 0.05;
    cons.weighty = 0.1;
    cons.gridx = 0;
    cons.gridy = 2;
    cons.gridheight = 1;
    JLabel label = new JLabel("Format:");
    _packetFormat = new JTextField();
    _packetFormat.setEditable(false);
    cons.anchor = GridBagConstraints.WEST;
    smallPane.add(label, cons);
    cons.gridx = 1;
    cons.weightx = 0.95;
    cons.fill = GridBagConstraints.HORIZONTAL;
    smallPane.add(_packetFormat, cons);
    cons.weightx = 0.5;
    this.add(smallPane, cons);

    cons.fill = GridBagConstraints.BOTH;
    cons.weightx = 0.5;
    cons.weighty = 0.4;
    cons.gridx = 1;
    cons.gridy = 4;
    cons.gridheight = 1;
    _packetViewTableModel = new PacketViewTableModel(null);
    _packetViewTable = new JXTreeTable(_packetViewTableModel);
    _packetViewTable.setSelectionModel(new DefaultListSelectionModel());
    _packetViewTable
        .getSelectionModel()
        .addListSelectionListener(new PartSelectionListener(_packetViewTable));
    _packetViewTable.setDefaultRenderer(Object.class, new IconTableRenderer());
    _packetViewTable.addMouseListener(new JTableButtonMouseListener(_packetViewTable));
    _packetViewTable.setTreeCellRenderer(new PacketViewTreeRenderer());
    JScrollPane packetViewScrollPane = new JScrollPane(_packetViewTable);
    this.add(packetViewScrollPane, cons);

    cons.fill = GridBagConstraints.BOTH;
    cons.anchor = GridBagConstraints.NORTH;
    cons.gridx = 1;
    cons.gridy = 0;
    cons.weighty = 0.1;
    cons.gridwidth = 1;
    _detailsPanel = new SessionDetailPanel(_gameSessionViewer.getSession());
    this.add(_detailsPanel, cons);

    this.displaySession();
  }
Exemplo n.º 2
0
  public void updateCurrentPacket(boolean forced) {
    if (!forced && _currentSelectedPacket == _packetTable.getSelectedRow()) return;
    /*try
    {
        DataStructure gp = _gameSessionViewer.getPacket(_currentSelectedPacket);
        if(gp!= null)
            gp.setViewed(false);
    }
    catch (IndexOutOfBoundsException e)
    {

    }*/
    _currentSelectedPacket = _packetTable.getSelectedRow();

    // reset the selected part as we selected another packet
    _currentSelectedPart = null;

    DataPacket gp = _gameSessionViewer.getPacket(_currentSelectedPacket);
    // gp.setViewed(true);
    // System.out.println("Selected row/packet: "+_table.getSelectedRow());

    _hexDumpArea.setText("");
    if (gp.getPacketFormat() != null && gp.isValid()) {
      _packetFormat.setText(gp.getPacketFormat().getPartsStr());

      // colorfull hex dump :P
      // opcode
      if (gp.getPacketId() != null) {
        for (IdPart part : gp.getPacketId().getParts()) {
          int bytes = part.getType().getTypeByteNumber();
          for (int i2 = 0; i2 < bytes; i2++) {
            addStyledText(
                Util.zeropad(Long.toHexString(part.getValue() << (8 * i2) & 0xff), 2).toUpperCase(),
                "op");
            if (i2 < bytes - 1) addStyledText(" ", "op");
          }
          addStyledText(" ", "base");
        }
      }

      // chksum
      if (gp.getProtocol().getChecksumSize() > 0) {
        int size = gp.getProtocol().getChecksumSize();
        for (int i = 1; i < size + 1; i++) {
          addStyledText(
              Util.zeropad(Integer.toHexString(gp.getIdData()[i] & 0xff), 2).toUpperCase(), "chk");
          if (i < size) addStyledText(" ", "chk");
        }
        addStyledText(" ", "base");
      }

      // parsed packet parts
      for (ValuePart part : gp.getValuePartList()) {
        addStyledText(Util.rawHexDump(part.getBytes()), part.getType().getName(), true);
        addStyledText(" ", "base");
      }

      // unparsed data (if any)
      addStyledText(Util.rawHexDump(gp.getUnparsedData()), "base");

      this.addLineBreaksToHexDump(gp.getIdData(), gp.getByteBuffer().array());

      int opSize = 0;
      for (PartType pt : gp.getPacketFormat().getIdParts()) {
        opSize += pt.getTypeByteNumber() * 3;
      }
      DataPartNode root =
          new DataPartNode(gp.getRootNode(), opSize + gp.getProtocol().getChecksumSize() * 3);
      _packetViewTableModel.setRoot(root);
      _packetViewTable.revalidate();
      _packetViewTable.expandAll();
    } else {
      // clear the format
      _packetFormat.setText("");

      // dump everything
      _hexDumpArea.setText("");

      // if we know the opcode but the format was invalid still show the opcode
      if (gp.getFormat() != null) {
        for (IdPart part : gp.getPacketId().getParts()) {
          int bytes = part.getType().getTypeByteNumber();
          for (int i2 = 0; i2 < bytes; i2++) {
            addStyledText(
                Util.zeropad(Long.toHexString(part.getValue() << (8 * i2) & 0xff), 2).toUpperCase(),
                "op");
            if (i2 < bytes - 1) addStyledText(" ", "op");
          }
          addStyledText(" ", "base");
        }
      }

      ViewPane.this.addStyledText(Util.rawHexDump(gp.getData()), "base");

      this.addLineBreaksToHexDump(gp.getIdData(), gp.getByteBuffer().array());

      // no part for u
      _packetViewTableModel.setRoot(null);
    }
  }