From 5c017d5fee39f7edf168b3d42313126b9bcc8c58 Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Sun, 31 Aug 2014 15:11:50 +0200 Subject: [PATCH] small dumpview UI changes --- .../flash/gui/dumpview/DumpViewPanel.java | 76 ++++++++++++------- .../decompiler/flash/gui/hexview/HexView.java | 65 +++++++++++----- 2 files changed, 93 insertions(+), 48 deletions(-) diff --git a/src/com/jpexs/decompiler/flash/gui/dumpview/DumpViewPanel.java b/src/com/jpexs/decompiler/flash/gui/dumpview/DumpViewPanel.java index c07b27847..81c8ee31c 100644 --- a/src/com/jpexs/decompiler/flash/gui/dumpview/DumpViewPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/dumpview/DumpViewPanel.java @@ -63,49 +63,69 @@ public class DumpViewPanel extends JPanel { dumpViewHexTable = new HexView(); dumpViewHexTable.addListener(new HexViewListener() { + private int lastAddressUnderCursor = -1; + @Override public void byteValueChanged(int address, byte b) { if (skipValueChange) { return; } - TreeModel model = dumpTree.getModel(); - DumpInfo di = DumpInfoSwfNode.getSwfNode(selectedDumpInfo); - while (model.getChildCount(di) > 0) { - boolean found = false; - for (DumpInfo child : di.getChildInfos()) { - if (child.startByte > address) { + if (address != -1) { + TreeModel model = dumpTree.getModel(); + DumpInfo di = DumpInfoSwfNode.getSwfNode(selectedDumpInfo); + while (model.getChildCount(di) > 0) { + boolean found = false; + for (DumpInfo child : di.getChildInfos()) { + if (child.startByte > address) { + break; + } + if (child.getEndByte() >= address) { + di = child; + found = true; + } + } + if (!found) { break; } - if (child.getEndByte() >= address) { - di = child; - found = true; - } } - if (!found) { - break; + List path = new ArrayList<>(); + while (di != null) { + path.add(0, di); + di = di.parent; } + path.add(0, model.getRoot()); + TreePath tp = new TreePath(path.toArray()); + skipNextScroll = true; + dumpTree.setSelectionPath(tp); + dumpTree.scrollPathToVisible(tp); } - List path = new ArrayList<>(); - while (di != null) { - path.add(0, di); - di = di.parent; - } - path.add(0, model.getRoot()); - TreePath tp = new TreePath(path.toArray()); - skipNextScroll = true; - dumpTree.setSelectionPath(tp); - dumpTree.scrollPathToVisible(tp); + + byte[] data = dumpViewHexTable.getData(); + byteMouseMoved(lastAddressUnderCursor, lastAddressUnderCursor == -1 ? 0 : data[lastAddressUnderCursor]); } @Override public void byteMouseMoved(int address, byte b) { - int b2 = b & 0xff; - selectedByteInfo.setText("Addr: " + Helper.padZeros(address, 8) + - " Hex: " + Helper.padZeros(Integer.toHexString(b2), 2) + - " Dec: " + b2 + - " Bin: " + Helper.padZeros(Integer.toBinaryString(b2), 8) + - " Ascii: " + (char) b2); + lastAddressUnderCursor = address; + if (address == -1) { + address = dumpViewHexTable.getFocusedByteIdx(); + if (address != -1) { + byte[] data = dumpViewHexTable.getData(); + b = data[address]; + } + } + + if (address != -1) { + int b2 = b & 0xff; + selectedByteInfo.setText("Addr: " + Helper.padZeros(address, 8) + + " Hex: " + Helper.padZeros(Integer.toHexString(b2), 2) + + " Dec: " + b2 + + " Bin: " + Helper.padZeros(Integer.toBinaryString(b2), 8) + + " Ascii: " + (char) b2); + } else { + selectedByteInfo.setText("-"); + } } }); diff --git a/src/com/jpexs/decompiler/flash/gui/hexview/HexView.java b/src/com/jpexs/decompiler/flash/gui/hexview/HexView.java index 161baec7f..a981ed27d 100644 --- a/src/com/jpexs/decompiler/flash/gui/hexview/HexView.java +++ b/src/com/jpexs/decompiler/flash/gui/hexview/HexView.java @@ -48,8 +48,7 @@ public class HexView extends JTable { private final Color[] highlightColors; private final Color bgColor = Color.decode("#F7F7F7"); private final Color bgColorAlternate = Color.decode("#EDEDED"); - private int itsRow = 0; - private int itsColumn = 0; + private int mouseOverIdx = -1; private HexViewListener listener; private class HighlightCellRenderer extends DefaultTableCellRenderer { @@ -61,8 +60,8 @@ public class HexView extends JTable { JLabel l = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col); int level = -1; - if (col > 0 && highlightStarts != null && col != bytesInRow + 1) { - int idx = row * bytesInRow + ((col > bytesInRow + 1) ? (col - bytesInRow - 2) : (col - 1)); + int idx = getIdxByColAndRow(row, col); + if (highlightStarts != null) { byteIndex = idx; for (int i = 0; i < highlightStarts.length; i++) { if (highlightStarts[i] <= idx && highlightEnds[i] >= idx) { @@ -83,13 +82,12 @@ public class HexView extends JTable { background = row % 2 == 0 ? bgColor : bgColorAlternate; } - if (col == itsColumn && row == itsRow) { + if (idx != -1 && idx == mouseOverIdx) { foreground = new Color(255 - foreground.getRed(), 255 - foreground.getGreen(), 255 - foreground.getBlue()); background = new Color(255 - background.getRed(), 255 - background.getGreen(), 255 - background.getBlue()); } l.setForeground(foreground); l.setBackground(background); - return l; } @@ -109,22 +107,26 @@ public class HexView extends JTable { int col = table.getSelectedColumn(); int row = table.getSelectedRow(); - if (col > 0 && highlightStarts != null && col != bytesInRow + 1) { - int idx = row * bytesInRow + ((col > bytesInRow + 1) ? (col - bytesInRow - 2) : (col - 1)); - byte[] data = getModel().getData(); - if (idx < data.length) { - if (listener != null) { - listener.byteValueChanged(idx, data[idx]); - } - } + int idx = getIdxByColAndRow(row, col); + if (listener != null) { + listener.byteValueChanged(idx, idx == -1 ? 0 : getModel().getData()[idx]); } } } private class HexViewMouseAdapter extends MouseAdapter { - + @Override - public void mouseClicked(MouseEvent e) { + public void mouseExited(MouseEvent e) { + HexView table = (HexView) e.getSource(); + Point point = e.getPoint(); + int col = table.columnAtPoint(point); + int row = table.rowAtPoint(point); + mouseOverIdx = -1; + getModel().fireTableCellUpdated(row, col); + if (listener != null) { + listener.byteMouseMoved(-1, (byte) 0); + } } } @@ -136,13 +138,12 @@ public class HexView extends JTable { Point point = e.getPoint(); int col = table.columnAtPoint(point); int row = table.rowAtPoint(point); - itsColumn = col; - itsRow = row; + int idx = getIdxByColAndRow(row, col); + mouseOverIdx = idx; getModel().fireTableCellUpdated(row, col); if (listener != null) { - int idx = row * bytesInRow + ((col > bytesInRow + 1) ? (col - bytesInRow - 2) : (col - 1)); - listener.byteMouseMoved(idx, getModel().getData()[idx]); + listener.byteMouseMoved(idx, idx == -1 ? 0 : getModel().getData()[idx]); } } } @@ -212,6 +213,10 @@ public class HexView extends JTable { this.highlightEnds = highlightEnds; } + public byte[] getData() { + return getModel().getData(); + } + public void scrollToByte(long byteNum) { int row = (int) (byteNum / bytesInRow); @@ -221,6 +226,26 @@ public class HexView extends JTable { scrollRectToVisible(new Rectangle(getCellRect(row, 0, true))); } + private int getIdxByColAndRow(int row, int col) { + int idx = -1; + if (col > 0 && col != bytesInRow + 1) { + idx = row * bytesInRow + ((col > bytesInRow + 1) ? (col - bytesInRow - 2) : (col - 1)); + } + byte[] data = getModel().getData(); + if (idx >= data.length) { + idx = -1; + } + return idx; + } + + public int getFocusedByteIdx() { + int col = getSelectedColumn(); + int row = getSelectedRow(); + + int idx = getIdxByColAndRow(row, col); + return idx; + } + public void scrollToByte(long[] byteNumStarts, long[] byteNumEnds) { for (int i = 0; i < byteNumStarts.length; i++) { scrollToByte(byteNumStarts[i]);