# HG changeset patch # User Thomas Wuerthinger # Date 1328412897 -3600 # Node ID c43083cc96e998d0fc35581bf926349eab52a7e6 # Parent 3c38bdaa6b39125c2c2624edb3b0ca6963f2c805 Fix router and layout actions. Now works also on multiple scenes and uses preferences. Also, use preferences for currently selected factory. diff -r 3c38bdaa6b39 -r c43083cc96e9 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/CfgCompilationViewer.java --- a/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/CfgCompilationViewer.java Sun Feb 05 02:48:13 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/CfgCompilationViewer.java Sun Feb 05 04:34:57 2012 +0100 @@ -226,7 +226,7 @@ @Override public Lookup getLookup() { - return Lookups.fixed(); + return Lookups.fixed(scene); } @Override diff -r 3c38bdaa6b39 -r c43083cc96e9 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/CfgEditorContext.java --- a/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/CfgEditorContext.java Sun Feb 05 02:48:13 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/CfgEditorContext.java Sun Feb 05 04:34:57 2012 +0100 @@ -6,8 +6,5 @@ public static final int LAYOUT_HIERARCHICALNODELAYOUT = 1; public static final int LAYOUT_HIERARCHICALCOMPOUNDLAYOUT = 2; - public static final int ROUTING_DIRECTLINES = 1; - public static final int ROUTING_BEZIER = 2; - public static final int MAX_AUTOEDGESVISIBLE = 8; } diff -r 3c38bdaa6b39 -r c43083cc96e9 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/AbstractRouterAction.java --- a/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/AbstractRouterAction.java Sun Feb 05 02:48:13 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -package at.ssw.visualizer.cfg.action; - -import at.ssw.visualizer.cfg.graph.CfgScene; -import javax.swing.JComponent; -import javax.swing.JMenuItem; -import javax.swing.JRadioButtonMenuItem; -import javax.swing.JToggleButton; -import org.openide.util.actions.Presenter; - -/** - * Common superclass for all actions which set the link router. - * - * @author Bernhard Stiftner - * @author Rumpfhuber Stefan - */ -public abstract class AbstractRouterAction extends AbstractCfgEditorAction implements Presenter.Menu, Presenter.Popup, Presenter.Toolbar { - - public void performAction() { - CfgScene tc = getEditor(); - if (tc != null) { - setLinkRouter(tc); - } - } - - protected abstract void setLinkRouter(CfgScene editor); - - @Override - public JMenuItem getMenuPresenter() { - JMenuItem presenter = new MenuPresenter(); - presenter.setToolTipText(getName()); - return presenter; - } - - @Override - public JMenuItem getPopupPresenter() { - return getMenuPresenter(); - } - - @Override - public JComponent getToolbarPresenter() { - ToolbarPresenter presenter = new ToolbarPresenter(); - presenter.setToolTipText(getName()); - return presenter; - } - - class MenuPresenter extends JRadioButtonMenuItem { - - public MenuPresenter() { - super(AbstractRouterAction.this); - setIcon(null); - } - } - - class ToolbarPresenter extends JToggleButton { - - public ToolbarPresenter() { - super(AbstractRouterAction.this); - setText(null); - } - } -} diff -r 3c38bdaa6b39 -r c43083cc96e9 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/HierarchicalCompoundLayoutAction.java --- a/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/HierarchicalCompoundLayoutAction.java Sun Feb 05 02:48:13 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/HierarchicalCompoundLayoutAction.java Sun Feb 05 04:34:57 2012 +0100 @@ -2,32 +2,28 @@ import at.ssw.visualizer.cfg.CfgEditorContext; import at.ssw.visualizer.cfg.graph.CfgScene; -import org.openide.util.HelpCtx; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.List; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionRegistration; -public class HierarchicalCompoundLayoutAction extends AbstractCfgEditorAction { +@ActionID(id = "HierarchicalCompoundLayout", category = "View") +@ActionRegistration(displayName = "Compound Layout", iconBase="at/ssw/visualizer/cfg/icons/arrangeloop.gif") +@ActionReference(path = "CompilationViewer/CFG/Actions", position = 150) +public class HierarchicalCompoundLayoutAction implements ActionListener { + List scenes; - public void performAction() { - CfgScene tc = getEditor(); - if (tc != null) { - tc.setSceneLayout(CfgEditorContext.LAYOUT_HIERARCHICALCOMPOUNDLAYOUT); - tc.applyLayout(); + public HierarchicalCompoundLayoutAction(List scenes) { + this.scenes = scenes; + } + + @Override + public void actionPerformed(ActionEvent e) { + for (CfgScene s : scenes) { + s.setSceneLayout(CfgEditorContext.LAYOUT_HIERARCHICALCOMPOUNDLAYOUT); } } - - public String getName() { - return "Hierarchical Compound Layout"; - } - - - @Override - protected String iconResource() { - return "at/ssw/visualizer/cfg/icons/arrangeloop.gif"; - } - - public HelpCtx getHelpCtx() { - return HelpCtx.DEFAULT_HELP; - } - - } diff -r 3c38bdaa6b39 -r c43083cc96e9 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/HierarchicalNodeLayoutAction.java --- a/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/HierarchicalNodeLayoutAction.java Sun Feb 05 02:48:13 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/HierarchicalNodeLayoutAction.java Sun Feb 05 04:34:57 2012 +0100 @@ -2,33 +2,28 @@ import at.ssw.visualizer.cfg.CfgEditorContext; import at.ssw.visualizer.cfg.graph.CfgScene; -import org.openide.util.HelpCtx; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.List; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionRegistration; -public class HierarchicalNodeLayoutAction extends AbstractCfgEditorAction { - +@ActionID(id = "HierarchicalNodeLayout", category = "View") +@ActionRegistration(displayName = "Layout", iconBase="at/ssw/visualizer/cfg/icons/arrangehier.gif") +@ActionReference(path = "CompilationViewer/CFG/Actions", position = 160) +public class HierarchicalNodeLayoutAction implements ActionListener { + List scenes; + + public HierarchicalNodeLayoutAction(List scenes) { + this.scenes = scenes; + } + @Override - public void performAction() { - CfgScene tc = getEditor(); - if (tc != null) { - CfgScene scene = tc; - scene.setSceneLayout(CfgEditorContext.LAYOUT_HIERARCHICALNODELAYOUT); - scene.applyLayout(); + public void actionPerformed(ActionEvent e) { + for (CfgScene s : scenes) { + s.setSceneLayout(CfgEditorContext.LAYOUT_HIERARCHICALNODELAYOUT); } } - - public String getName() { - return "Hierarchical Node Layout"; - } - - - @Override - protected String iconResource() { - return "at/ssw/visualizer/cfg/icons/arrangehier.gif"; - } - - public HelpCtx getHelpCtx() { - return HelpCtx.DEFAULT_HELP; - } - } diff -r 3c38bdaa6b39 -r c43083cc96e9 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/UseBezierRouterAction.java --- a/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/UseBezierRouterAction.java Sun Feb 05 02:48:13 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -package at.ssw.visualizer.cfg.action; - -import at.ssw.visualizer.cfg.CfgEditorContext; -import at.ssw.visualizer.cfg.graph.CfgScene; -import org.openide.util.HelpCtx; - - -public class UseBezierRouterAction extends AbstractRouterAction { - - @Override - protected void setLinkRouter(CfgScene editor) { - editor.setRouter(CfgEditorContext.ROUTING_BEZIER); - } - - @Override - public String getName() { - return "Use Bezier Router"; - } - - @Override - protected String iconResource() { - return "at/ssw/visualizer/cfg/icons/bezierrouter.gif"; - } - - public HelpCtx getHelpCtx() { - return HelpCtx.DEFAULT_HELP; - } - -} diff -r 3c38bdaa6b39 -r c43083cc96e9 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/UseDirectLineRouterAction.java --- a/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/UseDirectLineRouterAction.java Sun Feb 05 02:48:13 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -package at.ssw.visualizer.cfg.action; - -import at.ssw.visualizer.cfg.CfgEditorContext; -import at.ssw.visualizer.cfg.graph.CfgScene; -import org.openide.util.HelpCtx; - - -public class UseDirectLineRouterAction extends AbstractRouterAction { - - @Override - protected void setLinkRouter(CfgScene editor) { - editor.setRouter(CfgEditorContext.ROUTING_DIRECTLINES); - } - - @Override - public String getName() { - return "User Direct Router"; - } - - @Override - protected String iconResource() { - return "at/ssw/visualizer/cfg/icons/fanrouter.gif"; - } - - public HelpCtx getHelpCtx() { - return HelpCtx.DEFAULT_HELP; - } -} diff -r 3c38bdaa6b39 -r c43083cc96e9 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/CfgScene.java --- a/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/CfgScene.java Sun Feb 05 02:48:13 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/CfgScene.java Sun Feb 05 04:34:57 2012 +0100 @@ -1,9 +1,7 @@ package at.ssw.visualizer.cfg.graph; - import at.ssw.visualizer.cfg.model.CfgEdge; import at.ssw.visualizer.cfg.CfgEditorContext; -import at.ssw.visualizer.cfg.action.ColorAction; import at.ssw.visualizer.cfg.action.HideEdgesAction; import at.ssw.visualizer.cfg.action.ShowEdgesAction; import at.ssw.visualizer.cfg.graph.layout.HierarchicalCompoundLayout; @@ -32,6 +30,9 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.prefs.PreferenceChangeEvent; +import java.util.prefs.PreferenceChangeListener; +import java.util.prefs.Preferences; import javax.swing.AbstractAction; import javax.swing.JComponent; import javax.swing.JMenu; @@ -58,149 +59,164 @@ import org.netbeans.api.visual.widget.ConnectionWidget; import org.netbeans.api.visual.widget.LayerWidget; import org.netbeans.api.visual.widget.Widget; +import org.openide.util.NbPreferences; import org.openide.util.actions.SystemAction; +public final class CfgScene extends GraphScene implements ChangeListener { -public class CfgScene extends GraphScene implements ChangeListener { private LayerWidget mainLayer = new LayerWidget(this); - private LayerWidget connectionLayer = new LayerWidget(this); + private LayerWidget connectionLayer = new LayerWidget(this); private LayerWidget interractionLayer = new LayerWidget(this); - private LayerWidget clusterLayer = new LayerWidget(this); + private LayerWidget clusterLayer = new LayerWidget(this); private Set selectedNodes = Collections.emptySet(); - private Map loopidx2clusterwidget = new HashMap(); - private Map inputSwitches = new HashMap(); - private Map outputSwitches = new HashMap(); - private WidgetAction moveAction = ActionFactory.createMoveAction (ActionFactory.createFreeMoveStrategy(), this.createMoveProvider()); + private Map loopidx2clusterwidget = new HashMap<>(); + private Map inputSwitches = new HashMap<>(); + private Map outputSwitches = new HashMap<>(); + private WidgetAction moveAction = ActionFactory.createMoveAction(ActionFactory.createFreeMoveStrategy(), this.createMoveProvider()); private SceneLayout sceneLayout; private CfgEnv env; - private int currentLayout=-1; - private int currentRouter=-1; + private int currentLayout = -1; private JScrollPane scrollPane; private EventListenerList listenerList = new EventListenerList(); - private WidgetAction contextPopupAction = this.createContextMenuAction(this); - private List nodeWidgets=null; + private WidgetAction contextPopupAction = this.createContextMenuAction(this); + private List nodeWidgets = null; private boolean loopClustersVisible = true; - - - public CfgScene(final JScrollPane scrollPane, final ControlFlowGraph cfg){ - addChild(clusterLayer); - addChild(mainLayer); + private static String PREFERENCE_ROUTER = "router"; + private static String PREFERENCE_LAYOUT = "layout"; + + public static Preferences getPreferences() { + return NbPreferences.forModule(CfgScene.class); + } + private final PreferenceChangeListener preferenceChangeListener = new PreferenceChangeListener() { + @Override + public void preferenceChange(PreferenceChangeEvent evt) { + if (evt.getKey().equals(PREFERENCE_ROUTER)) { + setUseBezierRouter(Boolean.parseBoolean(evt.getNewValue())); + } + } + }; + + public CfgScene(final JScrollPane scrollPane, final ControlFlowGraph cfg) { + addChild(clusterLayer); + addChild(mainLayer); addChild(interractionLayer); - addChild(connectionLayer); - this.loadDefaults(); - this.scrollPane = scrollPane; - this.loadModel(new CfgEnv(cfg)); - this.setSceneLayout(CfgEditorContext.LAYOUT_HIERARCHICALNODELAYOUT);//default + addChild(connectionLayer); + this.scrollPane = scrollPane; + this.loadModel(new CfgEnv(cfg)); this.getInputBindings().setZoomActionModifiers(0); this.getActions().addAction(ActionFactory.createMouseCenteredZoomAction(1.1)); - this.getActions().addAction(ActionFactory.createPanAction()); + this.getActions().addAction(ActionFactory.createPanAction()); this.getActions().addAction(ActionFactory.createRectangularSelectAction( this.createSelectDecorator(this), - interractionLayer, - this.createRectangularSelectProvider()) - ); + interractionLayer, + this.createRectangularSelectProvider())); this.getActions().addAction(this.contextPopupAction); this.addSceneListener(createSceneListener(this)); this.validate(); + + getPreferences().addPreferenceChangeListener(preferenceChangeListener); + this.loadDefaults(); } - + private void loadModel(CfgEnv cfgenv) { this.env = cfgenv; - for(CfgNode n : env.getNodes()) { + for (CfgNode n : env.getNodes()) { addNode(n); } - for(CfgEdge e : env.getEdges()) { - addEdge(e); + for (CfgEdge e : env.getEdges()) { + addEdge(e); setEdgeSource(e, e.getSourceNode()); setEdgeTarget(e, e.getTargetNode()); - } - this.stackLoops(cfgenv.getLoopMap()); - this.autoHideEdges(); + } + this.stackLoops(cfgenv.getLoopMap()); + this.autoHideEdges(); } - + public void loadDefaults() { - this.setRouter(CfgEditorContext.ROUTING_DIRECTLINES); CfgPreferences prefs = CfgPreferences.getInstance(); this.setBackground(prefs.getBackgroundColor()); + setUseBezierRouter(getPreferences().getBoolean(PREFERENCE_ROUTER, true)); + setSceneLayout(getPreferences().getInt(PREFERENCE_LAYOUT, CfgEditorContext.LAYOUT_HIERARCHICALNODELAYOUT)); } - + //sets the parent Widget of all LoopClusterWidgets - private void stackLoops(Map map) { + private void stackLoops(Map map) { this.clusterLayer.removeChildren(); - - Set cache = new HashSet(); - for(LoopInfo info : map.values()){ - if(cache.contains(info)) continue; - LoopClusterWidget widget = this.loopidx2clusterwidget.get(info.getLoopIndex()); - LoopInfo parent = info.getParent(); - while(parent != null){ + + Set cache = new HashSet<>(); + for (LoopInfo info : map.values()) { + if (cache.contains(info)) { + continue; + } + LoopClusterWidget widget = this.loopidx2clusterwidget.get(info.getLoopIndex()); + LoopInfo parent = info.getParent(); + while (parent != null) { LoopClusterWidget parentWidget = this.loopidx2clusterwidget.get(parent.getLoopIndex()); assert parentWidget != null; - if(widget.getParentWidget()!=null) + if (widget.getParentWidget() != null) { widget.removeFromParent(); + } parentWidget.addChild(widget); - widget=parentWidget; - parent = parent.getParent(); - } + widget = parentWidget; + parent = parent.getParent(); + } widget.removeFromParent(); this.clusterLayer.addChild(widget);//parent == null => parent is clusterlayer - } + } } - + //hide in|output edges - private void autoHideEdges(){ - for(CfgNode n : this.getNodes()){ - int fanin = n.getInputEdges().length; - int fanout = n.getOutputEdges().length; - if (fanin > CfgEditorContext.MAX_AUTOEDGESVISIBLE){ - assert(inputSwitches.containsKey(n)); - if(this.inputSwitches.containsKey(n)){ + private void autoHideEdges() { + for (CfgNode n : this.getNodes()) { + int fanin = n.getInputEdges().length; + int fanout = n.getOutputEdges().length; + if (fanin > CfgEditorContext.MAX_AUTOEDGESVISIBLE) { + assert (inputSwitches.containsKey(n)); + if (this.inputSwitches.containsKey(n)) { EdgeSwitchWidget esw = this.inputSwitches.get(n); esw.changeEdgeVisibility(false); - } - } - if(fanout > CfgEditorContext.MAX_AUTOEDGESVISIBLE){ - if(this.outputSwitches.containsKey(n)){ + } + } + if (fanout > CfgEditorContext.MAX_AUTOEDGESVISIBLE) { + if (this.outputSwitches.containsKey(n)) { EdgeSwitchWidget esw = this.outputSwitches.get(n); esw.changeEdgeVisibility(false); } - } + } } - + } - - //apply current cfggraphscene layout - public void applyLayout(){ - this.sceneLayout.invokeLayoutImmediately(); + + //apply current cfggraphscene layout + public void applyLayout() { + this.sceneLayout.invokeLayoutImmediately(); } - + //returns a Set with the currently selected Nodes public Set getSelectedNodes() { return Collections.unmodifiableSet(selectedNodes); } - - + public Map getLoopidx2clusterwidget() { return loopidx2clusterwidget; } - + /** - * Sets the color of the currently selected Nodes - * If the supplied color is null the default color will be used + * Sets the color of the currently selected Nodes If the supplied color is null the default color will be used */ public void setSelectedNodesColor(Color color) { - if(color == null) { //set default color + if (color == null) { //set default color CfgPreferences prefs = CfgPreferences.getInstance(); - boolean customized=false; - for(CfgNode n : this.selectedNodes){ - color=null; - color = prefs.getFlagsSetting().getColor(n.getBasicBlock().getFlags()); - customized = (color!=null); - NodeWidget nw = (NodeWidget) this.findWidget(n); - nw.setNodeColor((customized) ? color : prefs.getNodeColor(), customized); + boolean customized = false; + for (CfgNode n : this.selectedNodes) { + color = null; + color = prefs.getFlagsSetting().getColor(n.getBasicBlock().getFlags()); + customized = (color != null); + NodeWidget nw = (NodeWidget) this.findWidget(n); + nw.setNodeColor((customized) ? color : prefs.getNodeColor(), customized); } - } else { - for(CfgNode n : this.selectedNodes){ + } else { + for (CfgNode n : this.selectedNodes) { NodeWidget nw = (NodeWidget) this.findWidget(n); nw.setNodeColor(color, true); } @@ -209,187 +225,183 @@ } public void setSelectedEdgesVisibility(boolean visible) { - for(CfgNode n : this.selectedNodes){ + for (CfgNode n : this.selectedNodes) { EdgeSwitchWidget in = this.inputSwitches.get(n); - EdgeSwitchWidget out = this.outputSwitches.get(n); - if(in != null) in.changeEdgeVisibility(visible); - if(out != null) out.changeEdgeVisibility(visible); + EdgeSwitchWidget out = this.outputSwitches.get(n); + if (in != null) { + in.changeEdgeVisibility(visible); + } + if (out != null) { + out.changeEdgeVisibility(visible); + } } - this.fireSelectionChanged(); + this.fireSelectionChanged(); this.validate(); } - public EdgeSwitchWidget getInputSwitch(CfgNode n){ + public EdgeSwitchWidget getInputSwitch(CfgNode n) { return this.inputSwitches.get(n); } - public EdgeSwitchWidget getOutputSwitch(CfgNode n){ + + public EdgeSwitchWidget getOutputSwitch(CfgNode n) { return this.outputSwitches.get(n); } - + public CfgEnv getCfgEnv() { return env; } - + public boolean isLoopClusterVisible() { return loopClustersVisible; } - - public void setLoopWidgets(boolean visible) { - for(Widget w : this.loopidx2clusterwidget.values()){ + + public void setLoopWidgets(boolean visible) { + for (Widget w : this.loopidx2clusterwidget.values()) { w.setVisible(visible); w.revalidate(); } - this.loopClustersVisible=visible; + this.loopClustersVisible = visible; this.validate(); } - public void setRouter(int newRouter){ - if(newRouter == this.currentRouter) return; - - this.currentRouter=newRouter; - + private void setUseBezierRouter(boolean value) { Router router; - - switch (newRouter) { - case CfgEditorContext.ROUTING_BEZIER: - router = new PolylineRouterV2(new WidgetCollisionCollector() { - public void collectCollisions(List collisions) { - collisions.addAll(getNodeWidgets()); - } - }); - break; - case CfgEditorContext.ROUTING_DIRECTLINES: - router = RouterFactory.createDirectRouter(); - break; - default: - throw new IllegalStateException ("Unknown Router ID: " + newRouter); // NOI18N - } - - for(CfgEdge e : this.getEdges()){ - EdgeWidget ew = (EdgeWidget) this.findWidget(e); - ew.setRouter(router); + if (value) { + router = new PolylineRouterV2(new WidgetCollisionCollector() { + @Override + public void collectCollisions(List collisions) { + collisions.addAll(getNodeWidgets()); + } + }); + } else { + router = RouterFactory.createDirectRouter(); + } + + for (CfgEdge e : this.getEdges()) { + EdgeWidget ew = (EdgeWidget) this.findWidget(e); + ew.setRouter(router); } this.validate(); + getPreferences().putBoolean(PREFERENCE_ROUTER, value); } - - - + public Collection getNodeWidgets() { - if(nodeWidgets != null && nodeWidgets.size()==this.getNodes().size()) return nodeWidgets; - - List widgets = new ArrayList(); - for(CfgNode n : this.getNodes()){ + if (nodeWidgets != null && nodeWidgets.size() == this.getNodes().size()) { + return nodeWidgets; + } + + List widgets = new ArrayList<>(); + for (CfgNode n : this.getNodes()) { NodeWidget w = (NodeWidget) this.findWidget(n); widgets.add(w); } - + nodeWidgets = Collections.unmodifiableList(widgets); - return widgets; + return widgets; } - - - - public void setSceneLayout(int newLayout){ - - if(currentLayout == newLayout) return; - - GraphLayout graphLayout=null; - - switch (newLayout) { + + public void setSceneLayout(int newLayout) { + + if (currentLayout == newLayout) { + return; + } + + GraphLayout graphLayout = null; + + switch (newLayout) { case CfgEditorContext.LAYOUT_HIERARCHICALNODELAYOUT: - graphLayout = new HierarchicalNodeLayout(this); + graphLayout = new HierarchicalNodeLayout(this); break; - + case CfgEditorContext.LAYOUT_HIERARCHICALCOMPOUNDLAYOUT: graphLayout = new HierarchicalCompoundLayout(this); break; - } + } + + this.currentLayout = newLayout; + if (graphLayout != null) { + this.sceneLayout = LayoutFactory.createSceneGraphLayout(this, graphLayout); + } - this.currentLayout=newLayout; - if(graphLayout != null) - this.sceneLayout=LayoutFactory.createSceneGraphLayout(this, graphLayout); - } - - - @Override - protected void attachEdgeSourceAnchor(CfgEdge edge, CfgNode oldSourceNode, CfgNode sourceNode) { - Anchor sourceAnchor; - EdgeWidget edgeWidget = (EdgeWidget) findWidget (edge); - Widget sourceWidget = findWidget(sourceNode); - - if (edge.isSymmetric()) { - sourceAnchor = new SymmetricAnchor(sourceWidget, true, true); - } else { - sourceAnchor = AnchorFactory.createRectangularAnchor(sourceWidget); - } - edgeWidget.setSourceAnchor (sourceAnchor); + getPreferences().putInt(PREFERENCE_LAYOUT, newLayout); + sceneLayout.invokeLayout(); } @Override - protected void attachEdgeTargetAnchor(CfgEdge edge, CfgNode oldtarget, CfgNode targetNode) { - Anchor targetAnchor; - ConnectionWidget edgeWidget = (ConnectionWidget) findWidget (edge); + protected void attachEdgeSourceAnchor(CfgEdge edge, CfgNode oldSourceNode, CfgNode sourceNode) { + Anchor sourceAnchor; + EdgeWidget edgeWidget = (EdgeWidget) findWidget(edge); + Widget sourceWidget = findWidget(sourceNode); + + if (edge.isSymmetric()) { + sourceAnchor = new SymmetricAnchor(sourceWidget, true, true); + } else { + sourceAnchor = AnchorFactory.createRectangularAnchor(sourceWidget); + } + edgeWidget.setSourceAnchor(sourceAnchor); + } + + @Override + protected void attachEdgeTargetAnchor(CfgEdge edge, CfgNode oldtarget, CfgNode targetNode) { + Anchor targetAnchor; + ConnectionWidget edgeWidget = (ConnectionWidget) findWidget(edge); Widget targetWidget = findWidget(targetNode); - + if (edge.isSymmetric()) { - targetAnchor = new SymmetricAnchor(targetWidget, true, false); + targetAnchor = new SymmetricAnchor(targetWidget, true, false); } else { targetAnchor = AnchorFactory.createRectangularAnchor(targetWidget); - } - edgeWidget.setTargetAnchor (targetAnchor); + } + edgeWidget.setTargetAnchor(targetAnchor); } - @Override - protected Widget attachEdgeWidget(CfgEdge edge) { + protected Widget attachEdgeWidget(CfgEdge edge) { EdgeWidget widget = new EdgeWidget(this, edge); - connectionLayer.addChild(widget); - attachSourceSwitchWidget(edge); - attachTargetSwitchWidget(edge); + connectionLayer.addChild(widget); + attachSourceSwitchWidget(edge); + attachTargetSwitchWidget(edge); return widget; } - - @Override - protected Widget attachNodeWidget(CfgNode node) { + protected Widget attachNodeWidget(CfgNode node) { this.nodeWidgets = null; - - NodeWidget nw = new NodeWidget(this,node); - WidgetAction.Chain actions = nw.getActions(); + + NodeWidget nw = new NodeWidget(this, node); + WidgetAction.Chain actions = nw.getActions(); actions.addAction(this.contextPopupAction); actions.addAction(this.moveAction); actions.addAction(this.createObjectHoverAction()); - - if ( node.isLoopMember() ) { - LoopClusterWidget loopWidget = this.attachLoopMember(node); - loopWidget.addMember(nw); - } - mainLayer.addChild(nw); + + if (node.isLoopMember()) { + LoopClusterWidget loopWidget = this.attachLoopMember(node); + loopWidget.addMember(nw); + } + mainLayer.addChild(nw); return nw; } - - + private LoopClusterWidget attachLoopMember(CfgNode node) { LoopClusterWidget lw = this.loopidx2clusterwidget.get(node.getLoopIndex()); - if(lw == null) { + if (lw == null) { lw = new LoopClusterWidget(this, node.getLoopDepth(), node.getLoopIndex()); this.loopidx2clusterwidget.put(node.getLoopIndex(), lw); this.clusterLayer.addChild(lw); } return lw; } - - - private boolean detachLoopMember(CfgNode node, NodeWidget nodeWidget) { + + private boolean detachLoopMember(CfgNode node, NodeWidget nodeWidget) { LoopClusterWidget rm = this.loopidx2clusterwidget.get(node.getLoopIndex()); - if( rm == null) return false;//not added - - if ( rm.removeMember(nodeWidget) ) { - if(rm.getMembers().size() == 0){ + if (rm == null) { + return false;//not added + } + if (rm.removeMember(nodeWidget)) { + if (rm.getMembers().isEmpty()) { this.loopidx2clusterwidget.remove(rm.getLoopIndex()); - List childs = new ArrayList(rm.getChildren()); - for (Widget w : childs){//append stacked loopwidgets + List childs = new ArrayList<>(rm.getChildren()); + for (Widget w : childs) {//append stacked loopwidgets w.removeFromParent(); rm.getParentWidget().addChild(w); } @@ -397,95 +409,95 @@ } return true; } - return false; + return false; } //this function is not invoked by any class of the module //however to ensure that the edge switches are treatet corretly //when a future version removes nodes it was implemented too. - @Override protected void detachNodeWidget(CfgNode node, Widget nodeWidget) { - if(node.isLoopMember() && nodeWidget instanceof NodeWidget ) { - this.detachLoopMember(node,(NodeWidget)nodeWidget); + if (node.isLoopMember() && nodeWidget instanceof NodeWidget) { + this.detachLoopMember(node, (NodeWidget) nodeWidget); } super.detachNodeWidget(node, nodeWidget); - assert nodeWidget.getParentWidget()== null; - if(this.inputSwitches.containsKey(node)) { + assert nodeWidget.getParentWidget() == null; + if (this.inputSwitches.containsKey(node)) { EdgeSwitchWidget esw = this.inputSwitches.remove(node); this.connectionLayer.removeChild(esw); } - if(this.outputSwitches.containsKey(node)){ + if (this.outputSwitches.containsKey(node)) { EdgeSwitchWidget esw = this.outputSwitches.remove(node); this.connectionLayer.removeChild(esw); - } + } } - - protected EdgeSwitchWidget attachSourceSwitchWidget(CfgEdge e){ - CfgNode sourceNode = e.getSourceNode(); + + protected EdgeSwitchWidget attachSourceSwitchWidget(CfgEdge e) { + CfgNode sourceNode = e.getSourceNode(); NodeWidget sourceWidget = (NodeWidget) this.findWidget(sourceNode); - EdgeSwitchWidget out = outputSwitches.get(sourceNode); - if (out==null) { + EdgeSwitchWidget out = outputSwitches.get(sourceNode); + if (out == null) { out = new EdgeSwitchWidget(this, sourceWidget, true); - this.connectionLayer.addChild(out); + this.connectionLayer.addChild(out); outputSwitches.put(sourceNode, out); - } - return out; + } + return out; } - - - protected EdgeSwitchWidget attachTargetSwitchWidget(CfgEdge e){ + + protected EdgeSwitchWidget attachTargetSwitchWidget(CfgEdge e) { CfgNode targetNode = e.getTargetNode(); NodeWidget targetWidget = (NodeWidget) this.findWidget(targetNode); - EdgeSwitchWidget in = inputSwitches.get(targetNode); - if (in==null) { + EdgeSwitchWidget in = inputSwitches.get(targetNode); + if (in == null) { in = new EdgeSwitchWidget(this, targetWidget, false); - this.connectionLayer.addChild(in); + this.connectionLayer.addChild(in); inputSwitches.put(targetNode, in); } - return in; + return in; } - + //resets the selection state of all NodeWidgets - private void cleanNodeSelection(){ - if( this.selectedNodes.size() != 0) { + private void cleanNodeSelection() { + if (!this.selectedNodes.isEmpty()) { this.userSelectionSuggested(Collections.emptySet(), false); this.selectedNodes = Collections.emptySet(); this.fireSelectionChanged(); - this.validate(); + this.validate(); } } - - + //sets the scene & global node selection - public void setNodeSelection(Set newSelection){ + public void setNodeSelection(Set newSelection) { this.setSceneSelection(newSelection); - this.updateGlobalSelection(); + this.updateGlobalSelection(); } - + //sets the scene selection - private void setSceneSelection(Set newSelection){ - if(newSelection.equals(selectedNodes)) return; - - this.selectedNodes=newSelection; - - Set selectedObjects = new HashSet(); - - for(CfgNode n : newSelection){ + private void setSceneSelection(Set newSelection) { + if (newSelection.equals(selectedNodes)) { + return; + } + + this.selectedNodes = newSelection; + + Set selectedObjects = new HashSet<>(); + + for (CfgNode n : newSelection) { selectedObjects.addAll(this.findNodeEdges(n, true, true)); } selectedObjects.addAll(newSelection); - + //if the selection gets updated from a change in the block view //the scene will be centered - if(selectionUpdating) + if (selectionUpdating) { this.centerSelection(); - + } + this.userSelectionSuggested(selectedObjects, false); - this.fireSelectionChanged(); + this.fireSelectionChanged(); this.validate(); } - + //updates selection of Block View public void updateGlobalSelection() { // TODO(tw): Add selection management. @@ -497,17 +509,16 @@ // BasicBlock[] curBlocks = newBlocks.toArray(new BasicBlock[newBlocks.size()]); // selection.put(curBlocks); } - private boolean selectionUpdating = false; - + //change of blockview selection - public void stateChanged(ChangeEvent event) { - if (selectionUpdating) { + public void stateChanged(ChangeEvent event) { + if (selectionUpdating) { return; } - + selectionUpdating = true; - + Object source = event.getSource(); // if(source instanceof Selection){ // Selection selection=(Selection) source; @@ -525,63 +536,61 @@ selectionUpdating = false; // TODO(tw): Add selection management. } - + //centers the viewport on the currently selected nodewidgets - private void centerSelection(){ + private void centerSelection() { Point sceneCenter = null; Collection nodes = this.selectedNodes; - if(nodes.size()==0) { + if (nodes.size() == 0) { nodes = this.getNodes(); - } - - for(CfgNode n : nodes) { - if(sceneCenter==null) { + } + + for (CfgNode n : nodes) { + if (sceneCenter == null) { sceneCenter = this.findWidget(n).getLocation(); continue; } Point location = this.findWidget(n).getLocation(); - sceneCenter.x = (location.x+sceneCenter.x)/2; - sceneCenter.y = (location.y+sceneCenter.y)/2; - } - - JComponent view = this.getView (); + sceneCenter.x = (location.x + sceneCenter.x) / 2; + sceneCenter.y = (location.y + sceneCenter.y) / 2; + } + + JComponent view = this.getView(); if (view != null) { - Rectangle viewBounds = view.getVisibleRect (); + Rectangle viewBounds = view.getVisibleRect(); - Point viewCenter = this.convertSceneToView (sceneCenter); + Point viewCenter = this.convertSceneToView(sceneCenter); - view.scrollRectToVisible (new Rectangle ( - viewCenter.x - viewBounds.width / 2, - viewCenter.y - viewBounds.height / 2, - viewBounds.width, - viewBounds.height - )); + view.scrollRectToVisible(new Rectangle( + viewCenter.x - viewBounds.width / 2, + viewCenter.y - viewBounds.height / 2, + viewBounds.width, + viewBounds.height)); } } - + //animated scene Zoom to the max bounds of current viewport - public void zoomScene(){ + public void zoomScene() { JScrollPane pane = scrollPane; - - Rectangle prefBounds = this.getPreferredBounds(); + + Rectangle prefBounds = this.getPreferredBounds(); Dimension viewDim = pane.getViewportBorderBounds().getSize(); - - double realwidth = (double)prefBounds.width*this.getZoomFactor(); - double realheight = (double)prefBounds.height*this.getZoomFactor(); - - double zoomX = (double)viewDim.width / realwidth; - double zoomY = (double)viewDim.height / realheight; - double zoomFactor = Math.min(zoomX, zoomY); - - this.animateZoom(zoomFactor*0.9); + + double realwidth = (double) prefBounds.width * this.getZoomFactor(); + double realheight = (double) prefBounds.height * this.getZoomFactor(); + + double zoomX = (double) viewDim.width / realwidth; + double zoomY = (double) viewDim.height / realheight; + double zoomFactor = Math.min(zoomX, zoomY); + + this.animateZoom(zoomFactor * 0.9); } - - + //animated animateZoom function for scene animateZoom factor public void animateZoom(double zoomfactor) { this.getSceneAnimator().animateZoomFactor(this.getZoomFactor() * zoomfactor); } - + public void addCfgEventListener(CfgEventListener l) { listenerList.add(CfgEventListener.class, l); } @@ -589,65 +598,65 @@ public void removeCfgEventListener(CfgEventListener l) { listenerList.remove(CfgEventListener.class, l); } - + public void fireSelectionChanged() { Object[] listeners = listenerList.getListenerList(); - for (int i = listeners.length-2; i>=0; i-=2) { - if (listeners[i]==CfgEventListener.class) { - ((CfgEventListener)listeners[i+1]).selectionChanged(this); + for (int i = listeners.length - 2; i >= 0; i -= 2) { + if (listeners[i] == CfgEventListener.class) { + ((CfgEventListener) listeners[i + 1]).selectionChanged(this); } } } - - + //Enables Antialiasing @Override - public void paintChildren () { - Object anti = getGraphics ().getRenderingHint (RenderingHints.KEY_ANTIALIASING); - Object textAnti = getGraphics ().getRenderingHint (RenderingHints.KEY_TEXT_ANTIALIASING); + public void paintChildren() { + Object anti = getGraphics().getRenderingHint(RenderingHints.KEY_ANTIALIASING); + Object textAnti = getGraphics().getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING); - getGraphics ().setRenderingHint ( + getGraphics().setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - getGraphics ().setRenderingHint ( + getGraphics().setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); - super.paintChildren (); + super.paintChildren(); - getGraphics ().setRenderingHint (RenderingHints.KEY_ANTIALIASING, anti); - getGraphics ().setRenderingHint (RenderingHints.KEY_TEXT_ANTIALIASING, textAnti); + getGraphics().setRenderingHint(RenderingHints.KEY_ANTIALIASING, anti); + getGraphics().setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, textAnti); } - - - //select provider for node selection + + //select provider for node selection private RectangularSelectProvider createRectangularSelectProvider() { - return new RectangularSelectProvider() { - public void performSelection(Rectangle rectangle) { - HashSet set=new HashSet(); + return new RectangularSelectProvider() { + + public void performSelection(Rectangle rectangle) { + HashSet set = new HashSet<>(); - //change to a rectangle with (x,offsetY) at the top left - if(rectangle.width < 0){ - rectangle.x=rectangle.x+rectangle.width; - rectangle.width*=-1; + //change to a rectangle with (x,offsetY) at the top left + if (rectangle.width < 0) { + rectangle.x = rectangle.x + rectangle.width; + rectangle.width *= -1; + } + if (rectangle.height < 0) { + rectangle.y = rectangle.y + rectangle.height; + rectangle.height *= -1; + } + + for (NodeWidget n : getNodeWidgets()) { + Point p = n.getLocation(); + if (p != null && rectangle.contains(p)) { + set.add(n.getNodeModel()); } - if(rectangle.height < 0){ - rectangle.y=rectangle.y+rectangle.height; - rectangle.height*=-1; - } + } + setNodeSelection(set); + } + }; + } - for(NodeWidget n: getNodeWidgets()) { - Point p = n.getLocation(); - if (p != null && rectangle.contains(p)) { - set.add(n.getNodeModel()); - } - } - setNodeSelection(set); - } - }; - } - //select decorator for node selection - private RectangularSelectDecorator createSelectDecorator(final CfgScene scene){ + private RectangularSelectDecorator createSelectDecorator(final CfgScene scene) { return new RectangularSelectDecorator() { + public Widget createSelectionWidget() { scene.cleanNodeSelection();//unselected all nodes scene.revalidate(); @@ -655,178 +664,184 @@ } }; } - - + private MoveProvider createMoveProvider() { - return new MoveProvider(){ - private HashMap originals = new HashMap(); - - private Point original=null; - + return new MoveProvider() { + + private HashMap originals = new HashMap<>(); + private Point original = null; + public void movementStarted(Widget widget) { - originals.clear(); - NodeWidget nw = (NodeWidget) widget; - if(selectedNodes.contains(nw.getNodeModel())) {//move current selection - for(CfgNode n : selectedNodes){ + originals.clear(); + NodeWidget nw = (NodeWidget) widget; + if (selectedNodes.contains(nw.getNodeModel())) {//move current selection + for (CfgNode n : selectedNodes) { Widget w = findWidget(n); originals.put(w, w.getLocation()); } } else {//a newly-selected node will be moved - CfgNode n = nw.getNodeModel(); - HashSet selectedNode = new HashSet(1); + CfgNode n = nw.getNodeModel(); + HashSet selectedNode = new HashSet<>(1); selectedNode.add(n); setNodeSelection(selectedNode); originals.put(widget, widget.getPreferredLocation()); widget.revalidate(); validate(); - - } + + } } - public void movementFinished(Widget widget) { - NodeWidget nw = (NodeWidget) widget; - if(selectedNodes.contains(nw.getNodeModel())) { + public void movementFinished(Widget widget) { + NodeWidget nw = (NodeWidget) widget; + if (selectedNodes.contains(nw.getNodeModel())) { return;//to be able to move the current selection } - HashSet selectedNode = new HashSet(1); - selectedNode.add(nw.getNodeModel()); - setNodeSelection(selectedNode); - originals.clear (); + HashSet selectedNode = new HashSet<>(1); + selectedNode.add(nw.getNodeModel()); + setNodeSelection(selectedNode); + originals.clear(); original = null; - + } - public Point getOriginalLocation(Widget widget) { - if(original==null) + public Point getOriginalLocation(Widget widget) { + if (original == null) { original = widget.getLocation(); + } - return original; + return original; } //todo : find a cache algorithm which only routes edges //which are intersected by bounds of the moved rectangle + public void setNewLocation(Widget widget, Point location) { Point org = getOriginalLocation(widget); int dx = location.x - org.x; int dy = location.y - org.y; - for (Map.Entry entry : originals.entrySet ()) { - Point point = entry.getValue (); - entry.getKey ().setPreferredLocation (new Point (point.x + dx, point.y + dy)); - } - for(CfgEdge e : getEdges()) { + for (Map.Entry entry : originals.entrySet()) { + Point point = entry.getValue(); + entry.getKey().setPreferredLocation(new Point(point.x + dx, point.y + dy)); + } + for (CfgEdge e : getEdges()) { EdgeWidget ew = (EdgeWidget) findWidget(e); - if(ew.isVisible()) + if (ew.isVisible()) { ew.reroute(); - } + } + } } }; } - - - private WidgetAction createContextMenuAction(final CfgScene scene) { + + private WidgetAction createContextMenuAction(final CfgScene scene) { return ActionFactory.createPopupMenuAction(new PopupMenuProvider() { + public JPopupMenu getPopupMenu(Widget widget, Point point) { - JPopupMenu menu = new JPopupMenu(); + JPopupMenu menu = new JPopupMenu(); NodeWidget nw = null; - if(widget instanceof NodeWidget) { + if (widget instanceof NodeWidget) { nw = (NodeWidget) widget; - if(!selectedNodes.contains(nw.getNodeModel())){ - HashSet selectedNode = new HashSet(1); + if (!selectedNodes.contains(nw.getNodeModel())) { + HashSet selectedNode = new HashSet<>(1); selectedNode.add(nw.getNodeModel()); setNodeSelection(selectedNode); } - } else if (scene.getSelectedNodes().size() == 1) { + } else if (scene.getSelectedNodes().size() == 1) { nw = (NodeWidget) scene.findWidget(scene.getSelectedNodes().iterator().next()); } - - if(nw != null){ - CfgNode node = nw.getNodeModel(); - ArrayList successors = new ArrayList(); - ArrayList predecessors = new ArrayList(); - for(CfgEdge e : node.getOutputEdges()){ + + if (nw != null) { + CfgNode node = nw.getNodeModel(); + ArrayList successors = new ArrayList<>(); + ArrayList predecessors = new ArrayList<>(); + for (CfgEdge e : node.getOutputEdges()) { successors.add(e.getTargetNode()); } - for(CfgEdge e : node.getInputEdges()){ + for (CfgEdge e : node.getInputEdges()) { predecessors.add(e.getSourceNode()); } - - if(predecessors.size()>0){ + + if (predecessors.size() > 0) { Collections.sort(predecessors, new NodeNameComparator()); JMenu predmenu = new JMenu("Go to predecessor"); - for (CfgNode n : predecessors) { - GotoNodeAction action = new GotoNodeAction(n); + for (CfgNode n : predecessors) { + GotoNodeAction action = new GotoNodeAction(n); predmenu.add(action); } - menu.add(predmenu); + menu.add(predmenu); } - if(successors.size()>0){ + if (successors.size() > 0) { Collections.sort(successors, new NodeNameComparator()); - JMenu succmenu = new JMenu("Go to successor"); - for (CfgNode n : successors) { - GotoNodeAction action = new GotoNodeAction(n); + JMenu succmenu = new JMenu("Go to successor"); + for (CfgNode n : successors) { + GotoNodeAction action = new GotoNodeAction(n); succmenu.add(action); } - menu.add(succmenu); - } - if ( successors.size() > 0 || predecessors.size() > 0) - menu.addSeparator(); - } - + menu.add(succmenu); + } + if (successors.size() > 0 || predecessors.size() > 0) { + menu.addSeparator(); + } + } + menu.add(SystemAction.get(ShowEdgesAction.class)); menu.add(SystemAction.get(HideEdgesAction.class)); return menu; } }); } - + private class NodeNameComparator implements Comparator { - public int compare(CfgNode node1, CfgNode node2) { + + public int compare(CfgNode node1, CfgNode node2) { String name1 = node1.getBasicBlock().getName().substring(1); String name2 = node2.getBasicBlock().getName().substring(1); Integer blocknum1 = Integer.parseInt(name1); Integer blocknum2 = Integer.parseInt(name2); - return blocknum1.compareTo(blocknum2); + return blocknum1.compareTo(blocknum2); } } - - private class GotoNodeAction extends AbstractAction { - CfgNode node ; - - GotoNodeAction(CfgNode node){ - super(node.getBasicBlock().getName()); - this.node = node; + + private class GotoNodeAction extends AbstractAction { + + CfgNode node; + + GotoNodeAction(CfgNode node) { + super(node.getBasicBlock().getName()); + this.node = node; } - public void actionPerformed(ActionEvent e) { - Set nodes = new HashSet(1); - nodes.add(node); - setNodeSelection(nodes); - centerSelection(); - } + + public void actionPerformed(ActionEvent e) { + Set nodes = new HashSet<>(1); + nodes.add(node); + setNodeSelection(nodes); + centerSelection(); + } } - - private SceneListener createSceneListener(final CfgScene scene){ + + private SceneListener createSceneListener(final CfgScene scene) { return new SceneListener() { - - public void sceneRepaint() { + + public void sceneRepaint() { } - public void sceneValidating() { + public void sceneValidating() { } - + public void sceneValidated() { - if (scene.isLoopClusterVisible()){ //update only if visible - for(LoopClusterWidget cw : getLoopidx2clusterwidget().values()){ - cw.updateClusterBounds(); + if (scene.isLoopClusterVisible()) { //update only if visible + for (LoopClusterWidget cw : getLoopidx2clusterwidget().values()) { + cw.updateClusterBounds(); } } - for(EdgeSwitchWidget esw : inputSwitches.values()){ + for (EdgeSwitchWidget esw : inputSwitches.values()) { esw.updatePosition(); } - for(EdgeSwitchWidget esw : outputSwitches.values()){ + for (EdgeSwitchWidget esw : outputSwitches.values()) { esw.updatePosition(); - } - } + } + } }; - } + } } diff -r 3c38bdaa6b39 -r c43083cc96e9 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/EdgeSwitchWidget.java --- a/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/EdgeSwitchWidget.java Sun Feb 05 02:48:13 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/EdgeSwitchWidget.java Sun Feb 05 04:34:57 2012 +0100 @@ -173,7 +173,7 @@ endPreview(); ObjectState os = this.getState(); Collection edges = this.getEdges(); - ArrayList updates = new ArrayList(); + ArrayList updates = new ArrayList<>(); boolean visible=os.isSelected(); this.setState(os.deriveSelected(!visible)); for(CfgEdge e: edges) { diff -r 3c38bdaa6b39 -r c43083cc96e9 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/LoopClusterWidget.java --- a/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/LoopClusterWidget.java Sun Feb 05 02:48:13 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/LoopClusterWidget.java Sun Feb 05 04:34:57 2012 +0100 @@ -18,7 +18,7 @@ private int loopIndex; private int loopDepth; private CfgScene cfgscene; - private ArrayList members = new ArrayList(); + private ArrayList members = new ArrayList<>(); public LoopClusterWidget(CfgScene scene, int loopdepth, final int loopindex) { super(scene); diff -r 3c38bdaa6b39 -r c43083cc96e9 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/layout/HierarchicalCompoundLayout.java --- a/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/layout/HierarchicalCompoundLayout.java Sun Feb 05 02:48:13 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/layout/HierarchicalCompoundLayout.java Sun Feb 05 04:34:57 2012 +0100 @@ -39,7 +39,7 @@ NodeList nodeList = dg.nodes; EdgeList edgeList = dg.edges; - Map idx2graph = new HashMap(); + Map idx2graph = new HashMap<>(); Subgraph base = new Subgraph(0); idx2graph.put(0, base); base.insets=getInsets(); diff -r 3c38bdaa6b39 -r c43083cc96e9 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/layer.xml --- a/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/layer.xml Sun Feb 05 02:48:13 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/layer.xml Sun Feb 05 04:34:57 2012 +0100 @@ -6,47 +6,45 @@ - + + + + + + + + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + diff -r 3c38bdaa6b39 -r c43083cc96e9 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/CfgEnv.java --- a/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/CfgEnv.java Sun Feb 05 02:48:13 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/CfgEnv.java Sun Feb 05 04:34:57 2012 +0100 @@ -29,9 +29,9 @@ this.cfg = cfg; int blockCount = cfg.getBasicBlocks().size(); CfgNodeImpl[] nodes = new CfgNodeImpl[blockCount]; - Map block2nodeMap = new HashMap(); - Map> inputMap = new HashMap>(); - ArrayList allEdges = new ArrayList(); + Map block2nodeMap = new HashMap<>(); + Map> inputMap = new HashMap<>(); + ArrayList allEdges = new ArrayList<>(); List blocks = cfg.getBasicBlocks(); //create nodes for(int idx=0 ; idx < blockCount ; idx++) { @@ -54,12 +54,12 @@ //create edges - Set cache = new HashSet();//avoids identical edges with same source and same target + Set cache = new HashSet<>();//avoids identical edges with same source and same target for(int i = 0 ; i < blockCount ; i++) { BasicBlock b = blocks.get(i); - List outputEdges = new ArrayList(); + List outputEdges = new ArrayList<>(); - Set successors = new HashSet(); + Set successors = new HashSet<>(); successors.addAll(b.getSuccessors()); successors.addAll(b.getXhandlers()); for(BasicBlock sb : successors) { @@ -82,7 +82,7 @@ CfgNodeImpl tar = (CfgNodeImpl) e.getTargetNode(); Set set = inputMap.get(tar); if( set == null) { - set = new HashSet(); + set = new HashSet<>(); set.add(e); inputMap.put(tar, set); } @@ -152,7 +152,7 @@ } for(LoopInfo info : env.loopMap.values()) { - HashSet members = new HashSet(info.getMembers()); + HashSet members = new HashSet<>(info.getMembers()); members.remove(info.getHeader());//remove own header for(CfgNode n: members){ if(n.isLoopHeader()) { @@ -174,10 +174,10 @@ private int loopIndex=0; public LoopEnv(Collection nodes){ - allNodes = new HashSet(nodes); - activeNodes = new HashSet(2 * allNodes.size()); - visitedNodes = new HashSet(2 * allNodes.size()); - loopMap = new HashMap(); + allNodes = new HashSet<>(nodes); + activeNodes = new HashSet<>(2 * allNodes.size()); + visitedNodes = new HashSet<>(2 * allNodes.size()); + loopMap = new HashMap<>(); } public int getLoopIndex(){ @@ -229,7 +229,7 @@ LoopInfo loop = new LoopInfo(); loop.setHeader(n); n.setLoopIndex(env.getLoopIndex()); - HashSet members = new HashSet(); + HashSet members = new HashSet<>(); loop.setMembers(members); members.add(n); env.loopMap.put(loop.getHeader(), loop); @@ -264,8 +264,8 @@ } private void setNodeLevels(CfgNode rootNode){ - Set cache = new HashSet(); - Queue queue = new LinkedList(); + Set cache = new HashSet<>(); + Queue queue = new LinkedList<>(); queue.add(rootNode); cache.add(rootNode); int level=0; diff -r 3c38bdaa6b39 -r c43083cc96e9 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/LoopInfo.java --- a/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/LoopInfo.java Sun Feb 05 02:48:13 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/LoopInfo.java Sun Feb 05 04:34:57 2012 +0100 @@ -11,7 +11,7 @@ private int loopDepth; //nested depth >=1 private LoopInfo parent=null; private Set members; - private List backEdges = new ArrayList();//dfs backEdge + private List backEdges = new ArrayList<>();//dfs backEdge protected void setLoopDepth(int depth) { this.loopDepth=depth; diff -r 3c38bdaa6b39 -r c43083cc96e9 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/CFGOptionsPanel.java --- a/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/CFGOptionsPanel.java Sun Feb 05 02:48:13 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/CFGOptionsPanel.java Sun Feb 05 04:34:57 2012 +0100 @@ -27,7 +27,7 @@ */ public class CFGOptionsPanel extends JPanel { - List elements = new ArrayList(); + List elements = new ArrayList<>(); /** Creates a new instance of CFGOptionsPanel */ public CFGOptionsPanel() { diff -r 3c38bdaa6b39 -r c43083cc96e9 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/FlagsSetting.java --- a/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/FlagsSetting.java Sun Feb 05 02:48:13 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/FlagsSetting.java Sun Feb 05 04:34:57 2012 +0100 @@ -18,8 +18,8 @@ public FlagsSetting(String flagString) { this.flagString = flagString; - flag2color = new Hashtable(); - priority = new Hashtable(); + flag2color = new Hashtable<>(); + priority = new Hashtable<>(); String[] flags = flagString.split(";"); int z = 0; diff -r 3c38bdaa6b39 -r c43083cc96e9 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/visual/PolylineRouter.java --- a/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/visual/PolylineRouter.java Sun Feb 05 02:48:13 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/visual/PolylineRouter.java Sun Feb 05 04:34:57 2012 +0100 @@ -58,7 +58,7 @@ return Collections.emptyList(); } - List nodeWidgets = new ArrayList(); + List nodeWidgets = new ArrayList<>(); if(collector != null){ collector.collectCollisions(nodeWidgets); @@ -79,7 +79,7 @@ private List simplify(Collection nodeWidgets, List list) { - List result = new ArrayList(); + List result = new ArrayList<>(); result.add( list.get(0) );//add startpoint for (int i = 1; i < list.size(); i++) { Point prev = list.get(i - 1); @@ -123,7 +123,7 @@ private List optimize(Collection nodeWidgets, ConnectionWidget connWidget, Point start, Point end) { - List list = new ArrayList(); + List list = new ArrayList<>(); list.add(start); list.add(end); @@ -131,7 +131,7 @@ for (int j = 0; progress && j < NUMBER_OF_ITERATIONS ; j++) { progress = false; - List newList = new ArrayList(); + List newList = new ArrayList<>(); for (int i = 0; i < list.size() - 1 ; i++) { Point cur = list.get(i); Point next = list.get(i + 1); @@ -160,7 +160,7 @@ * and the last point is ignored cause the anchor is recalculated * anyway. */ - ArrayList tmp = new ArrayList(); + ArrayList tmp = new ArrayList<>(); int listSize=list.size(); tmp.add(list.get(0)); int i=0; @@ -211,7 +211,7 @@ for (int j = -1; j <= 1; j++) { if (i != 0 || j != 0) { Point cur = new Point(location.x + i * distx, location.y + j * disty); - List list1 = new ArrayList(); + List list1 = new ArrayList<>(); list1.add(p1); list1.add(cur); list1.add(p2); @@ -225,7 +225,7 @@ || (curIntersects == minIntersects && crossProd < min)) { minIntersects = curIntersects; min = crossProd; - minSol = new ArrayList(); + minSol = new ArrayList<>(); minSol.add(cur); } } @@ -252,7 +252,7 @@ cur2 = tmp; } - List list2 = new ArrayList(); + List list2 = new ArrayList<>(); list2.add(p1); list2.add(cur1); list2.add(cur2); @@ -285,7 +285,7 @@ || (curIntersects == minIntersects && crossProd < min)) { minIntersects = curIntersects; min = crossProd; - minSol = new ArrayList(); + minSol = new ArrayList<>(); minSol.add(cur1); minSol.add(cur2); } @@ -320,7 +320,7 @@ private boolean intersects(Collection nodeWidgets, Point start, Point end) { - List pointlist = new ArrayList(); + List pointlist = new ArrayList<>(); pointlist.add(start); pointlist.add(end); diff -r 3c38bdaa6b39 -r c43083cc96e9 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/visual/PolylineRouterV2.java --- a/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/visual/PolylineRouterV2.java Sun Feb 05 02:48:13 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/visual/PolylineRouterV2.java Sun Feb 05 04:34:57 2012 +0100 @@ -68,13 +68,13 @@ Point srcCenter = this.getSceneLocation(sourceWidget); Point tarCenter = this.getSceneLocation(targetWidget); - List widgetObstacles = new ArrayList(); + List widgetObstacles = new ArrayList<>(); if(collector != null){ collector.collectCollisions(widgetObstacles); } - List obstacles = new ArrayList(widgetObstacles.size()); + List obstacles = new ArrayList<>(widgetObstacles.size()); this.collectObstacles(obstacles, widgetObstacles, widget); @@ -167,7 +167,7 @@ } private List simplify(List obstacles, List list) { - List result = new ArrayList(list.size()); + List result = new ArrayList<>(list.size()); result.add( list.get(0) );//add startpoint for (int i = 1; i < list.size(); i++) { Point prev = list.get(i - 1); @@ -184,7 +184,7 @@ private List optimize(List nodeWidgets, Point start, Point end) { - List list = new ArrayList(); + List list = new ArrayList<>(); list.add(start); list.add(end); @@ -192,7 +192,7 @@ for (int j = 0; progress && j < NUMBER_OF_ITERATIONS ; j++) { progress = false; - List newList = new ArrayList(); + List newList = new ArrayList<>(); for (int i = 0; i < list.size() - 1 ; i++) { Point cur = list.get(i); Point next = list.get(i + 1); @@ -225,7 +225,7 @@ Line2D line = new Line2D.Double(p1, p2); boolean inbounds=false; Rectangle ibr=null; - ArrayList sol = new ArrayList(); + ArrayList sol = new ArrayList<>(); boolean leftIntersection; boolean rightIntersection; boolean bottomIntersection; diff -r 3c38bdaa6b39 -r c43083cc96e9 src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/EditorTopComponent.java --- a/src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/EditorTopComponent.java Sun Feb 05 02:48:13 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/EditorTopComponent.java Sun Feb 05 04:34:57 2012 +0100 @@ -34,10 +34,12 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.*; +import java.util.prefs.Preferences; import javax.swing.*; import org.openide.awt.Toolbar; import org.openide.util.Lookup; import org.openide.util.NbBundle; +import org.openide.util.NbPreferences; import org.openide.util.Utilities; import org.openide.util.actions.Presenter; import org.openide.util.lookup.AbstractLookup; @@ -69,6 +71,11 @@ return currentLookup; } }; + private static final String PREFERENCE_FACTORY = "factory"; + + public static Preferences getPreferences() { + return NbPreferences.forModule(EditorTopComponent.class); + } private InputGraph getFirstGraph() { return group.getGraphs().get(getModel().getFirstPosition()); @@ -90,6 +97,7 @@ private void activateFactory(CompilationViewerFactory factory) { this.activeFactory = factory; + getPreferences().put(PREFERENCE_FACTORY, activeFactory.getName()); updateView(); } @@ -99,10 +107,7 @@ initComponents(); - //ToolbarPool.getDefault().setPreferredIconSize(16); Toolbar toolBar = new Toolbar(); - //Border b = (Border) UIManager.get("Nb.Editor.Toolbar.border"); //NOI18N - //toolBar.setBorder(b); this.add(BorderLayout.NORTH, toolBar); this.group = graph.getGroup(); @@ -127,8 +132,9 @@ toolBar.addSeparator(); viewerToolBar = new JToolBar(); + viewerToolBar.setFloatable(false); toolBar.add(viewerToolBar); - toolBar.add(Box.createHorizontalGlue()); + toolBar.add(Box.createHorizontalGlue()); Action action = Utilities.actionsForPath("QuickSearchShadow").get(0); Component quicksearch = ((Presenter.Toolbar) action).getToolbarPresenter(); @@ -140,8 +146,17 @@ viewerPanel.setLayout(viewerPanelCardLayout); this.add(viewerPanel, BorderLayout.CENTER); - ((JToggleButton) factoryButtonGroup.getElements().nextElement()).setSelected(true); - activeFactory = factories.iterator().next(); + if (factories.size() > 0) { + String activeFactoryName = getPreferences().get(PREFERENCE_FACTORY, factories.iterator().next().getName()); + Enumeration buttons = factoryButtonGroup.getElements(); + for (CompilationViewerFactory factory : factories) { + JToggleButton curButton = (JToggleButton) buttons.nextElement(); + if (factory.getName().equals(activeFactoryName)) { + activeFactory = factory; + curButton.setSelected(true); + } + } + } updateView(); } @@ -208,7 +223,13 @@ @Override public void changed(RangeSliderModel source) { - updateView(); + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + updateView(); + } + }); } }; @@ -225,10 +246,11 @@ if (newViewer != activeViewer) { activeViewer = newViewer; viewerPanelCardLayout.show(viewerPanel, id); - initializeToolBar(id); + + currentLookup = new ProxyLookup(activeViewer.getLookup(), Lookups.fixed(getFirstGraph(), getSecondGraph())); + initializeToolBar(activeFactory.getName()); // Make sure that lookup is updated. - currentLookup = new ProxyLookup(activeViewer.getLookup(), Lookups.fixed(getFirstGraph(), getSecondGraph())); proxyLookup.lookup(Object.class); } } @@ -257,8 +279,13 @@ private void initializeToolBar(String id) { viewerToolBar.removeAll(); - for (Action a : LookupUtils.lookupActions(String.format("CompilationViewer/%s/Actions", id))) { - viewerToolBar.add(a); + for (Action a : LookupUtils.lookupActions(String.format("CompilationViewer/%s/Actions", id), activeViewer.getLookup())) { + if (a instanceof Presenter.Toolbar) { + viewerToolBar.add(((Presenter.Toolbar) a).getToolbarPresenter()); + } else { + viewerToolBar.add(a); + } } + viewerToolBar.updateUI(); } } diff -r 3c38bdaa6b39 -r c43083cc96e9 src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/SplitCompilationViewer.java --- a/src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/SplitCompilationViewer.java Sun Feb 05 02:48:13 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/SplitCompilationViewer.java Sun Feb 05 04:34:57 2012 +0100 @@ -36,12 +36,14 @@ import org.openide.util.Lookup; import org.openide.util.NbPreferences; import org.openide.util.lookup.Lookups; +import org.openide.util.lookup.ProxyLookup; class SplitCompilationViewer implements CompilationViewer { private JSplitPane splitPane; private Component firstPanel; private Component secondPanel; + private Lookup combinedLookup; private static final String DIVIDER_LOCATION = "dividerLocation"; private final PropertyChangeListener splitChanged = new PropertyChangeListener() { @@ -74,11 +76,12 @@ splitPane.add(secondPanel); splitPane.addPropertyChangeListener(splitChanged); splitPane.setDividerLocation(getLastDividerLocation()); + combinedLookup = new ProxyLookup(firstViewer.getLookup(), secondViewer.getLookup()); } @Override public Lookup getLookup() { - return Lookups.fixed(); + return combinedLookup; } @Override