Commit d842b5e4 authored by EmaJasekova's avatar EmaJasekova
Browse files

Highlight selected node

parent 89db37f7
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -9,12 +9,15 @@ public class CustomListCellRenderer extends DefaultListCellRenderer {
    private final List<NodeMemory.ObjectState> objects;
    private final List<NodeMemory.Deletion> deletions;

    private boolean showAll;

    private static final Color RED_COLOR = new Color(255, 0, 0, 125);
    private static final Color GREEN_COLOR = new Color(34, 139, 34, 125);

    public CustomListCellRenderer(List<NodeMemory.ObjectState> objects, List<NodeMemory.Deletion> deletions) {
    public CustomListCellRenderer(List<NodeMemory.ObjectState> objects, List<NodeMemory.Deletion> deletions, boolean showAll) {
        this.objects = objects;
        this.deletions = deletions;
        this.showAll = showAll;
    }

    @Override
@@ -31,7 +34,11 @@ public class CustomListCellRenderer extends DefaultListCellRenderer {
        } else if (objectState != null) {
            switch (objectState.type()) {
                case ADDITION:
                    if (showAll) {
                        label.setBackground(Color.WHITE);
                    } else {
                        label.setBackground(GREEN_COLOR);
                    }
                    break;
                case CHANGE:
                    label.setBackground(Color.ORANGE);
@@ -71,10 +78,11 @@ public class CustomListCellRenderer extends DefaultListCellRenderer {
        return null;
    }

    public void updateObjectList(List<NodeMemory.ObjectState> newObjects, List<NodeMemory.Deletion> newDeletions) {
    public void updateObjectList(List<NodeMemory.ObjectState> newObjects, List<NodeMemory.Deletion> newDeletions, boolean showAll) {
        this.objects.clear();
        this.objects.addAll(newObjects);
        this.deletions.clear();
        this.deletions.addAll(newDeletions);
        this.showAll = showAll;
    }
}
+27 −19
Original line number Diff line number Diff line
@@ -59,10 +59,22 @@ public class MemoryViewer extends JPanel implements ListSelectionListener {

        this.add(showAllButton, BorderLayout.NORTH);

        JPanel segment = new JPanel(new BorderLayout());
        JPanel offset = new JPanel(new BorderLayout());

        segmentPanel = new PlanePanel();
        segmentPanel.setBorder(new TitledBorder("Segment"));
        offsetPanel = new PlanePanel();
        offsetPanel.setBorder(new TitledBorder("Offset"));

        segment.add(segmentPanel, BorderLayout.CENTER);
        offset.add(offsetPanel, BorderLayout.CENTER);

        JTabbedPane planesTabbedPane = new JTabbedPane(JTabbedPane.TOP);

        planesTabbedPane.addTab("Offset", offset);
        planesTabbedPane.addTab("Segment", segment);

        this.add(planesTabbedPane);

        objectInfoPanel = new JPanel(new BorderLayout());
        objectInfoPanel.setBorder(new TitledBorder("Object Info"));

@@ -75,7 +87,7 @@ public class MemoryViewer extends JPanel implements ListSelectionListener {
        objectsList.setBorder(new TitledBorder("Objects"));
        objectsList.addListSelectionListener(this);
        objectsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        objectsList.setCellRenderer(new CustomListCellRenderer(objects, new ArrayList<>()));
        objectsList.setCellRenderer(new CustomListCellRenderer(objects, new ArrayList<>(), showAll));

        objectScrollPane = new JScrollPane(objectsList);
        objectsPanel.add(objectScrollPane, BorderLayout.CENTER);
@@ -141,11 +153,7 @@ public class MemoryViewer extends JPanel implements ListSelectionListener {

        objectsPanel.add(entryField, BorderLayout.NORTH);

        planesSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, segmentPanel, offsetPanel);
        planesSplitPane.setDividerLocation(0.5);
        planesSplitPane.setResizeWeight(0.5);

        objectStateSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, planesSplitPane, objectInfoPanel);
        objectStateSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, planesTabbedPane, objectInfoPanel);
        objectStateSplitPane.setDividerLocation(0.9);
        objectStateSplitPane.setResizeWeight(0.9);

@@ -157,8 +165,8 @@ public class MemoryViewer extends JPanel implements ListSelectionListener {
    }

    private void displayTables(NodeMemory.Memory memory) {
        segmentPanel.updateTables(null);
        offsetPanel.updateTables(null);
        segmentPanel.updateTables(null, showAll);
        offsetPanel.updateTables(null, showAll);

        objects = new ArrayList<>();
        objects.addAll(memory.additions());
@@ -171,7 +179,7 @@ public class MemoryViewer extends JPanel implements ListSelectionListener {

        objects.addAll(deletions);

        ((CustomListCellRenderer) objectsList.getCellRenderer()).updateObjectList(objects, memory.deletions());
        ((CustomListCellRenderer) objectsList.getCellRenderer()).updateObjectList(objects, memory.deletions(), showAll);
        ((DefaultListModel<String>) objectsList.getModel()).clear();

        int maxDigits = 0;
@@ -455,8 +463,8 @@ public class MemoryViewer extends JPanel implements ListSelectionListener {

    private void updatePlanes() {
        if (objectsList.getModel().getSize() == 0) {
            segmentPanel.updateTables(null);
            offsetPanel.updateTables(null);
            segmentPanel.updateTables(null, showAll);
            offsetPanel.updateTables(null, showAll);
            return;
        }

@@ -471,11 +479,11 @@ public class MemoryViewer extends JPanel implements ListSelectionListener {
        if (currentObjectState != null) {
            NodeMemory.Plane offsetPlane = currentObjectState.offsetPlane();
            NodeMemory.Plane segmentPlane = currentObjectState.segmentPlane();
            segmentPanel.updateTables(segmentPlane);
            offsetPanel.updateTables(offsetPlane);
            segmentPanel.updateTables(segmentPlane, showAll);
            offsetPanel.updateTables(offsetPlane, showAll);
        } else {
            segmentPanel.updateTables(null);
            offsetPanel.updateTables(null);
            segmentPanel.updateTables(null, showAll);
            offsetPanel.updateTables(null, showAll);
        }
    }

@@ -486,8 +494,8 @@ public class MemoryViewer extends JPanel implements ListSelectionListener {
        if (objectsList.getSelectedIndex() < 0) return;

        // remove table headers for empty tables
        segmentPanel.updateTables(null);
        offsetPanel.updateTables(null);
        segmentPanel.updateTables(null, showAll);
        offsetPanel.updateTables(null, showAll);

        updatePlanes();
        displayObjectInfo();
+9 −9
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ public class PlanePanel extends JPanel {

        sortByOffsetCheckBox = new JCheckBox("Sort by Offset");
        sortByOffsetCheckBox.setSelected(true);
        sortByOffsetCheckBox.addActionListener(e -> updateTables(currentPlane));
        sortByOffsetCheckBox.addActionListener(e -> updateTables(currentPlane, false));

        JPanel controlPanel = new JPanel(new BorderLayout());
        controlPanel.add(sortByOffsetCheckBox, BorderLayout.NORTH);
@@ -57,7 +57,7 @@ public class PlanePanel extends JPanel {
        panel.repaint();
    }

    private void updateBytesTable(NodeMemory.ByteMap additions, NodeMemory.ByteMap deletions, JPanel bytePanel, String[] byteColumns, boolean isConcrete) {
    private void updateBytesTable(NodeMemory.ByteMap additions, NodeMemory.ByteMap deletions, JPanel bytePanel, String[] byteColumns, boolean isConcrete, boolean showAll) {
        if (additions.isEmpty() && deletions.isEmpty()) {
            clearTable(bytePanel);
            return;
@@ -66,8 +66,8 @@ public class PlanePanel extends JPanel {
        ArrayList<Object[]> byteEntries = new ArrayList<>();
        ArrayList<Color> rowColors = new ArrayList<>();

        createByteRows(byteEntries, rowColors, additions, GREEN_COLOR, byteColumns, currentPlane.concreteMask().additions(), isConcrete);
        createByteRows(byteEntries, rowColors, deletions, RED_COLOR, byteColumns, currentPlane.concreteMask().additions(), isConcrete);
        createByteRows(byteEntries, rowColors, additions, showAll ? Color.WHITE : GREEN_COLOR, byteColumns, currentPlane.concreteMask().additions(), isConcrete);
        createByteRows(byteEntries, rowColors, deletions, showAll ? Color.WHITE : RED_COLOR, byteColumns, currentPlane.concreteMask().additions(), isConcrete);

        if (sortByOffsetCheckBox.isSelected()) {
            ArrayList<Integer> indices = new ArrayList<>();
@@ -116,9 +116,9 @@ public class PlanePanel extends JPanel {
                int row = byteTable.rowAtPoint(e.getPoint());
                int column = byteTable.columnAtPoint(e.getPoint());

                if (column == 1) {
                if (column == 1 && !isConcrete) {
                    Object value = byteTable.getValueAt(row, column);
                    boolean isSymbolic = byteTable.getValueAt(row, 2) == "false";
                    boolean isSymbolic = byteTable.getValueAt(row, 2) == "true";
                    if (value != null && value != "" && isSymbolic) {
                        showPopup(value.toString(), "Value");
                    }
@@ -230,7 +230,7 @@ public class PlanePanel extends JPanel {
        return updateTable;
    }

    public void updateTables(NodeMemory.Plane plane) {
    public void updateTables(NodeMemory.Plane plane, boolean showAll) {
        if (plane == null) {
            clearTable(updatePanel);
            clearTable(concretePanel);
@@ -239,8 +239,8 @@ public class PlanePanel extends JPanel {
        }

        this.currentPlane = plane;
        updateBytesTable(currentPlane.concreteStore().additions(), currentPlane.concreteStore().deletions(), concretePanel, concreteColumns, true);
        updateBytesTable(currentPlane.knownSymbolics().additions(), currentPlane.knownSymbolics().deletions(), symbolicPanel, symbolicColumns, false);
        updateBytesTable(currentPlane.concreteStore().additions(), currentPlane.concreteStore().deletions(), concretePanel, concreteColumns, true, showAll);
        updateBytesTable(currentPlane.knownSymbolics().additions(), currentPlane.knownSymbolics().deletions(), symbolicPanel, symbolicColumns, false, showAll);
        updateUpdatesTable(currentPlane);
    }

+4 −0
Original line number Diff line number Diff line
@@ -290,6 +290,8 @@ public class ProgressExplorer implements ListSelectionListener, MouseWheelListen
        if (SwingUtilities.isRightMouseButton(e)) {
            if (nodeInfoTabbedPane.isVisible()) {
                nodeInfoTabbedPane.setVisible(false);
                treeViewer.repaint();
                treeViewer.selectedNode = null;
            }
            sourceC.removeHighLight();
            sourceLL.removeHighLight();
@@ -302,6 +304,8 @@ public class ProgressExplorer implements ListSelectionListener, MouseWheelListen
        if (node != null && SwingUtilities.isRightMouseButton(e)) {
            rightClickMenu.putClientProperty("node", node);
            rightClickMenu.show(e.getComponent(), e.getX(), e.getY());
            treeViewer.selectedNode = node;
            treeViewer.repaint();
        }
    }

+16 −0
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ public class TreeViewer extends JPanel {

    private static final float edgeThickness = 1.0f;

    public Node selectedNode;

    /**
     * Enables mouse dragging to navigate through the process tree displayed in the tree panel.
     *
@@ -112,6 +114,17 @@ public class TreeViewer extends JPanel {
        return null;
    }

    private void drawCross(Graphics g, Node node) {
        Graphics2D g2d = (Graphics2D) g;
        g2d.setColor(Color.GRAY);
        int nodeX = Math.round(zoom * node.getViewProps().x);
        int nodeY = Math.round(zoom * node.getViewProps().y);
        // Draw horizontal line
        g2d.drawLine(0, nodeY, getWidth(), nodeY);
        // Draw vertical line
        g2d.drawLine(nodeX, 0, nodeX, getHeight());
    }

    /**
     * Computes node locations and size of panel needed in each round.
     * Scrolls the view to make the tree root visible.
@@ -169,6 +182,9 @@ public class TreeViewer extends JPanel {
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            g2d.setStroke(new BasicStroke(edgeThickness));
            drawSubTree(g2d, tree.root, getVisibleRect());
            if (selectedNode != null) {
                drawCross(g, selectedNode);
            }
        }
    }