diff --git a/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java b/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java index b193afe0b9..dd0406c7c0 100644 --- a/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java +++ b/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java @@ -163,29 +163,29 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider public void mouseClicked(MouseEvent e) { super.mouseClicked(e); if (SwingUtilities.isRightMouseButton(e)) { - mxICell cellAt = (mxICell) graphComponent.getCellAt(e.getX(), e.getY()); + mxCell cellAt = (mxCell) graphComponent.getCellAt(e.getX(), e.getY()); if (cellAt != null && cellAt.isVertex()) { JPopupMenu jPopupMenu = new JPopupMenu(); AccountDeviceInstanceKey adiKey = (AccountDeviceInstanceKey) cellAt.getValue(); - if (graph.isAccountLocked(adiKey)) { + if (graph.isVertexLocked(cellAt)) { jPopupMenu.add(new JMenuItem(new AbstractAction("UnLock " + cellAt.getId(), unlockIcon) { @Override public void actionPerformed(ActionEvent e) { - graph.unlockAccount((AccountDeviceInstanceKey) cellAt.getValue()); + graph.unlockVertex(cellAt); } })); - }else { + } else { jPopupMenu.add(new JMenuItem(new AbstractAction("Lock " + cellAt.getId(), lockIcon) { @Override public void actionPerformed(ActionEvent e) { - graph.lockAccount((AccountDeviceInstanceKey) cellAt.getValue()); + graph.lockVertex(cellAt); } })); } - if (graph.isAccountPinned(adiKey)) { + if (graph.isAccountPinned(adiKey)) { jPopupMenu.add(new JMenuItem(new AbstractAction("Unpin " + cellAt.getId(), unpinIcon) { @Override public void actionPerformed(ActionEvent e) { @@ -583,7 +583,22 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider }//GEN-LAST:event_zoomOutButtonActionPerformed private void circleLayoutButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_circleLayoutButtonActionPerformed - final mxCircleLayout mxCircleLayout = new mxCircleLayout(graph); + final mxCircleLayout mxCircleLayout = new mxCircleLayout(graph) { + @Override + public boolean isVertexIgnored(Object vertex) { + return super.isVertexIgnored(vertex) + || VisualizationPanel.this.graph.isVertexLocked((mxCell) vertex); + } + + @Override + public mxRectangle setVertexLocation(Object vertex, double x, double y) { + if (isVertexIgnored(vertex)) { + return getVertexBounds(vertex); + } else { + return super.setVertexLocation(vertex, x, y); + } + } + }; mxCircleLayout.setResetEdges(true); morph(mxCircleLayout); }//GEN-LAST:event_circleLayoutButtonActionPerformed @@ -593,23 +608,62 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider }//GEN-LAST:event_OrganicLayoutButtonActionPerformed private void fastOrganicLayoutButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_fastOrganicLayoutButtonActionPerformed - final mxFastOrganicLayout mxFastOrganicLayout = new mxFastOrganicLayout(graph); + final mxFastOrganicLayout mxFastOrganicLayout = new mxFastOrganicLayout(graph) { + @Override + public boolean isVertexIgnored(Object vertex) { + return super.isVertexIgnored(vertex) + || VisualizationPanel.this.graph.isVertexLocked((mxCell) vertex); + } + + @Override + public mxRectangle setVertexLocation(Object vertex, double x, double y) { + if (isVertexIgnored(vertex)) { + return getVertexBounds(vertex); + } else { + return super.setVertexLocation(vertex, x, y); + } + } + }; morph(mxFastOrganicLayout); }//GEN-LAST:event_fastOrganicLayoutButtonActionPerformed private void hierarchyLayoutButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_hierarchyLayoutButtonActionPerformed - final mxHierarchicalLayout mxHierarchicalLayout = new mxHierarchicalLayout(graph); + final mxHierarchicalLayout mxHierarchicalLayout = new mxHierarchicalLayout(graph) { + @Override + public boolean isVertexIgnored(Object vertex) { + return super.isVertexIgnored(vertex) + || VisualizationPanel.this.graph.isVertexLocked((mxCell) vertex); + } + + @Override + public mxRectangle setVertexLocation(Object vertex, double x, double y) { + if (isVertexIgnored(vertex)) { + return getVertexBounds(vertex); + } else { + return super.setVertexLocation(vertex, x, y); + } + } + }; morph(mxHierarchicalLayout); }//GEN-LAST:event_hierarchyLayoutButtonActionPerformed private void applyOrganicLayout(int iterations) { mxOrganicLayout mxOrganicLayout = new mxOrganicLayout(graph) { @Override - public boolean isVertexMovable(Object vertex) { - return super.isVertexMovable(vertex); //To change body of generated methods, choose Tools | Templates. + public boolean isVertexIgnored(Object vertex) { + return super.isVertexIgnored(vertex) + || VisualizationPanel.this.graph.isVertexLocked((mxCell) vertex); } + @Override + public mxRectangle setVertexLocation(Object vertex, double x, double y) { + if (isVertexIgnored(vertex)) { + return getVertexBounds(vertex); + } else { + return super.setVertexLocation(vertex, x, y); + } + } }; mxOrganicLayout.setResetEdges(true); mxOrganicLayout.setMaxIterations(iterations); diff --git a/Core/src/org/sleuthkit/autopsy/communications/mxGraphImpl.java b/Core/src/org/sleuthkit/autopsy/communications/mxGraphImpl.java index 8cda3c5e66..101e803624 100644 --- a/Core/src/org/sleuthkit/autopsy/communications/mxGraphImpl.java +++ b/Core/src/org/sleuthkit/autopsy/communications/mxGraphImpl.java @@ -55,7 +55,7 @@ final class mxGraphImpl extends mxGraph { static final private mxStylesheet mxStylesheet = new mxStylesheet(); private final HashSet pinnedAccountDevices = new HashSet<>(); - private final HashSet lockedAccountDevices = new HashSet<>(); + private final HashSet lockedVertices = new HashSet<>(); private final Map nodeMap = new HashMap<>(); private final Multimap edgeMap = MultimapBuilder.hashKeys().hashSetValues().build(); @@ -123,23 +123,6 @@ final class mxGraphImpl extends mxGraph { // }; } - @Override - public boolean isCellMovable(Object cell) { - final mxICell mxCell = (mxICell) cell; - if (mxCell.isEdge()) { - return super.isCellMovable(cell); - } else { - final boolean cellMovable = super.isCellMovable(cell); - final boolean unlocked = false == lockedAccountDevices.contains((AccountDeviceInstanceKey) mxCell.getValue()); - - if (cellMovable && unlocked) { - return true; - } else { - return false; - } - } - } - void clear() { nodeMap.clear(); edgeMap.clear(); @@ -163,10 +146,10 @@ final class mxGraphImpl extends mxGraph { if (pinnedAccountDevices.contains(adiKey)) { label += ""; } - if (lockedAccountDevices.contains(adiKey)) { + if (lockedVertices.contains((mxCell) cell)) { label += ""; } - return "
" + label + "
"; + return "
" + label + "
"; } else { return ""; } @@ -185,12 +168,21 @@ final class mxGraphImpl extends mxGraph { pinnedAccountDevices.addAll(accountDeviceInstances); } - void lockAccount(AccountDeviceInstanceKey accountDeviceInstance) { - lockedAccountDevices.add(accountDeviceInstance); + void lockVertex(mxCell vertex) { + lockedVertices.add(vertex); + + final mxCellState state = getView().getState(vertex, true); + getView().clear(vertex, true, true); + getView().validate(); } - void unlockAccount(AccountDeviceInstanceKey accountDeviceInstance) { - lockedAccountDevices.remove(accountDeviceInstance); + void unlockVertex(mxCell vertex) { + lockedVertices.remove(vertex); + + final mxCellState state = getView().getState(vertex, true); + getView().updateLabel(state); + getView().updateLabelBounds(state); + getView().updateBoundingBox(state); } SwingWorker rebuild(ProgressIndicator progress, CommunicationsManager commsManager, CommunicationsFilter currentFilter) { @@ -201,7 +193,7 @@ final class mxGraphImpl extends mxGraph { void resetGraph() { clear(); pinnedAccountDevices.clear(); - lockedAccountDevices.clear(); + lockedVertices.clear(); } private mxCell getOrCreateVertex(AccountDeviceInstanceKey accountDeviceInstanceKey) { @@ -241,11 +233,11 @@ final class mxGraphImpl extends mxGraph { final HashSet hashSet = new HashSet<>(relSources); // edgeMap.put(relSource, edge); edge = (mxCell) insertEdge(getDefaultParent(), edgeName, hashSet, vertex1, vertex2, - "strokeWidth=" + (Math.log(hashSet.size())+1)); + "strokeWidth=" + (Math.log(hashSet.size()) + 1)); } else { edge = (mxCell) edgesBetween[0]; ((Collection) edge.getValue()).addAll(relSources); - edge.setStyle("strokeWidth=" +( Math.log(((Collection) edge.getValue()).size())+1)); + edge.setStyle("strokeWidth=" + (Math.log(((Collection) edge.getValue()).size()) + 1)); } return edge; } @@ -258,8 +250,8 @@ final class mxGraphImpl extends mxGraph { return getView().getScale(); } - boolean isAccountLocked(AccountDeviceInstanceKey adiKey) { - return lockedAccountDevices.contains(adiKey); + boolean isVertexLocked(mxCell vertex) { + return lockedVertices.contains(vertex); } private class SwingWorkerImpl extends SwingWorker {