# HG changeset patch # User Thomas Wuerthinger # Date 1328645371 -3600 # Node ID 9d640941c9c7fa04d3bec8dbfa08bf2c4aef6995 # Parent ab7c258e1cefb541d423bb6c9b7c1db0a54dc4d7# Parent 58ecb156a3e8c2991f9d0b90dab56c7753bbe671 Merge. diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/BytecodeViewTopComponent.java --- a/src/share/tools/IdealGraphVisualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/BytecodeViewTopComponent.java Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/BytecodeViewTopComponent.java Tue Feb 07 21:09:31 2012 +0100 @@ -26,7 +26,6 @@ import com.sun.hotspot.igv.data.Group; import com.sun.hotspot.igv.data.InputGraph; import com.sun.hotspot.igv.data.services.InputGraphProvider; -import com.sun.hotspot.igv.util.LookupHistory; import java.awt.BorderLayout; import java.io.Serializable; import javax.swing.SwingUtilities; @@ -170,7 +169,7 @@ @Override public void resultChanged(LookupEvent lookupEvent) { - final InputGraphProvider p = LookupHistory.getLast(InputGraphProvider.class);//)Utilities.actionsGlobalContext().lookup(InputGraphProvider.class); + final InputGraphProvider p = null; // TODO(tw): FIXME //.getLast(InputGraphProvider.class);//)Utilities.actionsGlobalContext().lookup(InputGraphProvider.class); if (p != null) { SwingUtilities.invokeLater(new Runnable() { @Override diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/SelectBytecodesAction.java --- a/src/share/tools/IdealGraphVisualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/SelectBytecodesAction.java Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/SelectBytecodesAction.java Tue Feb 07 21:09:31 2012 +0100 @@ -24,7 +24,6 @@ package com.sun.hotspot.igv.bytecodes; import com.sun.hotspot.igv.data.services.InputGraphProvider; -import com.sun.hotspot.igv.util.LookupHistory; import org.openide.nodes.Node; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; @@ -39,7 +38,7 @@ @Override protected void performAction(Node[] activatedNodes) { SelectBytecodesCookie c = activatedNodes[0].getCookie(SelectBytecodesCookie.class); - InputGraphProvider p = LookupHistory.getLast(InputGraphProvider.class);//Utilities.actionsGlobalContext().lookup(InputGraphProvider.class); + InputGraphProvider p = null; // TODO: fixme LookupHistory.getLast(InputGraphProvider.class);//Utilities.actionsGlobalContext().lookup(InputGraphProvider.class); if (p != null) { p.setSelectedNodes(c.getNodes()); } diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/manifest.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/manifest.mf Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,6 @@ +Manifest-Version: 1.0 +OpenIDE-Module: at.ssw.visualizer.cfg +OpenIDE-Module-Layer: at/ssw/visualizer/cfg/layer.xml +OpenIDE-Module-Localizing-Bundle: at/ssw/visualizer/cfg/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/META-INF/services/com.oracle.graal.visualizer.editor.CompilationViewerFactory --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/META-INF/services/com.oracle.graal.visualizer.editor.CompilationViewerFactory Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,1 @@ +at.ssw.visualizer.cfg.CfgCompilationViewerFactory \ No newline at end of file diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/Bundle.properties Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,1 @@ +OpenIDE-Module-Name=ControlFlowEditor diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/CfgCompilationViewer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/CfgCompilationViewer.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,236 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +package at.ssw.visualizer.cfg; + +import at.ssw.visualizer.cfg.action.*; +import at.ssw.visualizer.cfg.graph.CfgEventListener; +import at.ssw.visualizer.cfg.graph.CfgScene; +import at.ssw.visualizer.cfg.graph.EdgeWidget; +import at.ssw.visualizer.cfg.graph.NodeWidget; +import at.ssw.visualizer.cfg.model.CfgEdge; +import at.ssw.visualizer.cfg.model.CfgNode; +import at.ssw.visualizer.cfg.preferences.CfgPreferences; +import at.ssw.visualizer.cfg.preferences.FlagsSetting; +import at.ssw.visualizer.model.cfg.ControlFlowGraph; +import com.oracle.graal.visualizer.editor.CompilationViewer; +import com.sun.hotspot.igv.data.InputGraph; +import java.awt.Color; +import java.awt.Component; +import java.beans.PropertyChangeEvent; +import javax.swing.*; +import javax.swing.border.Border; +import org.netbeans.api.visual.widget.Widget; +import org.openide.awt.Toolbar; +import org.openide.util.Lookup; +import org.openide.util.actions.SystemAction; +import org.openide.util.lookup.Lookups; + +class CfgCompilationViewer implements CompilationViewer { + + private CfgScene scene; + private JScrollPane jScrollPane; + private ControlFlowGraph cfg; + private JComponent myView; + + public CfgCompilationViewer(InputGraph cfg) { + this.cfg = cfg; + + // setIcon(ImageUtilities.loadImage("at/ssw/visualizer/cfg/icons/cfg.gif")); +// setName(cfg.getParent().getShortName()); +// setToolTipText(cfg.getCompilation().getMethod() + " - " + cfg.getName()); + // TODO(tw): Add title. + + //panel setup + this.jScrollPane = new JScrollPane(); + this.jScrollPane.setOpaque(true); + this.jScrollPane.setBorder(BorderFactory.createEmptyBorder()); + this.jScrollPane.setViewportBorder(BorderFactory.createEmptyBorder()); + this.scene = new CfgScene(jScrollPane, cfg); + this.myView = scene.createView(); + this.jScrollPane.setViewportView(myView); + jScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); + jScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); + jScrollPane.getVerticalScrollBar().setEnabled(true); + jScrollPane.getHorizontalScrollBar().setEnabled(true); + + //setup enviroment,register listeners + // TODO(tw): Add to lookup. +// selection = new Selection(); +// selection.put(cfg); +// selection.put(scene); +// selection.addChangeListener(scene); + + scene.validate(); + scene.applyLayout(); + } + + public void propertyChange(PropertyChangeEvent evt) { + if (this.scene != null) { + + String propName = evt.getPropertyName(); + CfgPreferences prefs = CfgPreferences.getInstance(); + switch (propName) { + case CfgPreferences.PROP_BACKGROUND_COLOR: + scene.setBackground(prefs.getBackgroundColor()); + scene.revalidate(); + break; + case CfgPreferences.PROP_NODE_COLOR: + for (NodeWidget nw : scene.getNodeWidgets()) { + //only change the node color if its not a custom color + if (!nw.isNodeColorCustomized()) { + nw.setNodeColor(prefs.getNodeColor(), false); + } + } + break; + case CfgPreferences.PROP_EDGE_COLOR: + for (CfgEdge e : scene.getEdges()) { + if (!e.isBackEdge() && !e.isXhandler()) { + EdgeWidget w = (EdgeWidget) scene.findWidget(e); + w.setLineColor(prefs.getEdgeColor()); + } + } + break; + case CfgPreferences.PROP_BACK_EDGE_COLOR: + for (CfgEdge e : scene.getEdges()) { + if (e.isBackEdge()) { + EdgeWidget w = (EdgeWidget) scene.findWidget(e); + w.setLineColor(prefs.getBackedgeColor()); + } + } + break; + case CfgPreferences.PROP_EXCEPTION_EDGE_COLOR: + for (CfgEdge e : scene.getEdges()) { + if (e.isXhandler()) { + EdgeWidget w = (EdgeWidget) scene.findWidget(e); + w.setLineColor(prefs.getExceptionEdgeColor()); + } + } + break; + case CfgPreferences.PROP_BORDER_COLOR: + for (CfgNode n : scene.getNodes()) { + NodeWidget nw = (NodeWidget) scene.findWidget(n); + nw.setBorderColor(prefs.getBorderColor()); + } + break; + case CfgPreferences.PROP_TEXT_FONT: + for (CfgNode n : scene.getNodes()) { + NodeWidget nw = (NodeWidget) scene.findWidget(n); + nw.adjustFont(prefs.getTextFont()); + } + break; + case CfgPreferences.PROP_TEXT_COLOR: + for (CfgNode n : scene.getNodes()) { + NodeWidget nw = (NodeWidget) scene.findWidget(n); + nw.setForeground(prefs.getTextColor()); + } + break; + case CfgPreferences.PROP_FLAGS: + FlagsSetting fs = CfgPreferences.getInstance().getFlagsSetting(); + for (CfgNode n : scene.getNodes()) { + NodeWidget nw = (NodeWidget) scene.findWidget(n); + Color nodeColor = fs.getColor(n.getBasicBlock().getFlags()); + if (nodeColor != null) { + nw.setNodeColor(nodeColor, true); + } else { + nw.setNodeColor(CfgPreferences.getInstance().getNodeColor(), false); + } + } + break; + case CfgPreferences.PROP_SELECTION_COLOR_BG: + case CfgPreferences.PROP_SELECTION_COLOR_FG: + for (CfgNode n : scene.getNodes()) { + Widget w = scene.findWidget(n); + w.revalidate(); + } + break; + } + scene.validate(); + } + + } + + /*@Override + public Component getToolBarComponent() { + Toolbar tb = new Toolbar("CfgToolbar"); + + tb.setBorder((Border) UIManager.get("Nb.Editor.Toolbar.border")); + + //zoomin/zoomout buttons + tb.add(SystemAction.get(ZoominAction.class).getToolbarPresenter()); + tb.add(SystemAction.get(ZoomoutAction.class).getToolbarPresenter()); + tb.addSeparator(); + + //router buttons + ButtonGroup routerButtons = new ButtonGroup(); + UseDirectLineRouterAction direct = SystemAction.get(UseDirectLineRouterAction.class); + UseBezierRouterAction bezier = SystemAction.get(UseBezierRouterAction.class); + JToggleButton button = (JToggleButton) direct.getToolbarPresenter(); + button.getModel().setGroup(routerButtons); + button.setSelected(true); + tb.add(button); + button = (JToggleButton) bezier.getToolbarPresenter(); + button.getModel().setGroup(routerButtons); + tb.add(button); + tb.addSeparator(); + + //layout buttons + tb.add(SystemAction.get(HierarchicalNodeLayoutAction.class).getToolbarPresenter()); + tb.add(SystemAction.get(HierarchicalCompoundLayoutAction.class).getToolbarPresenter()); + + tb.addSeparator(); + tb.add(SystemAction.get(ShowAllAction.class).getToolbarPresenter()); + tb.addSeparator(); + + //cluster button + tb.add(SystemAction.get(SwitchLoopClustersAction.class).getToolbarPresenter()); + tb.addSeparator(); + + //show/hide edge button + tb.add(SystemAction.get(ShowEdgesAction.class).getToolbarPresenter()); + tb.add(SystemAction.get(HideEdgesAction.class).getToolbarPresenter()); + tb.addSeparator(); + + //color button + JComponent colorButton = SystemAction.get(ColorAction.class).getToolbarPresenter(); + scene.addCfgEventListener((CfgEventListener) colorButton); + tb.add(colorButton); + + //export button + tb.add(SystemAction.get(ExportAction.class).getToolbarPresenter()); + tb.doLayout(); + + return tb; + }*/ + + @Override + public Lookup getLookup() { + return Lookups.fixed(scene); + } + + @Override + public Component getComponent() { + return jScrollPane; + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/CfgCompilationViewerFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/CfgCompilationViewerFactory.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,26 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package at.ssw.visualizer.cfg; + +import com.oracle.graal.visualizer.editor.CompilationViewer; +import com.oracle.graal.visualizer.editor.CompilationViewerFactory; +import com.oracle.graal.visualizer.editor.DiagramViewModel; +import com.oracle.graal.visualizer.editor.SplitCompilationViewerFactory; +import com.sun.hotspot.igv.data.InputGraph; + +public class CfgCompilationViewerFactory extends SplitCompilationViewerFactory { + + @Override + public String getName() { + return "CFG"; + } + + @Override + protected CompilationViewer createViewer(InputGraph graph) { + return new CfgCompilationViewer(graph); + } + +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/CfgEditorContext.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/CfgEditorContext.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,10 @@ + +package at.ssw.visualizer.cfg; + +public abstract class CfgEditorContext { + + public static final int LAYOUT_HIERARCHICALNODELAYOUT = 1; + public static final int LAYOUT_HIERARCHICALCOMPOUNDLAYOUT = 2; + + public static final int MAX_AUTOEDGESVISIBLE = 8; +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/AbstractCfgEditorAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/AbstractCfgEditorAction.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,57 @@ +package at.ssw.visualizer.cfg.action; + + +import at.ssw.visualizer.cfg.graph.CfgScene; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JMenuItem; +import org.openide.util.Utilities; +import org.openide.util.actions.CallableSystemAction; + +/** + * The common superclass of all concrete actions related to the CFG visualizer. + * + * @author Bernhard Stiftner + * @author Rumpfhuber Stefan + */ +public abstract class AbstractCfgEditorAction extends CallableSystemAction { + + CfgScene topComponent = null; + + public AbstractCfgEditorAction() { + setEnabled(false); + + } + + protected CfgScene getEditor() { + return Utilities.actionsGlobalContext().lookup(CfgScene.class); + } + + @Override + public JMenuItem getMenuPresenter() { + return new JMenuItem(this); + } + + + @Override + public JComponent getToolbarPresenter() { + JButton b = new JButton(this); + if (getIcon() != null) { + b.setText(null); + b.setToolTipText(getName()); + } + return b; + } + + + @Override + public JMenuItem getPopupPresenter() { + return new JMenuItem(this); + } + + + @Override + protected boolean asynchronous() { + return false; + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/Bundle.properties Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,2 @@ +CTL_SomeAction=test +CTL_SomeAction2=test diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/ExportAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/ExportAction.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,121 @@ +package at.ssw.visualizer.cfg.action; + +import at.ssw.visualizer.cfg.graph.CfgScene; +import java.io.File; +import javax.swing.JComponent; +import javax.swing.JFileChooser; +import javax.swing.filechooser.FileNameExtensionFilter; +import org.openide.DialogDescriptor; +import org.openide.DialogDisplayer; +import org.openide.util.HelpCtx; + +/** + * Exports Scene to various Graphics Formats + * + * @author Rumpfhuber Stefan + */ +public class ExportAction extends AbstractCfgEditorAction { + + public static final String DESCRIPTION_SVG = "Scaleable Vector Format (.svg)"; + public static final String DESCRIPTION_EMF = "Extended Meta File (.emf)"; + public static final String DESCRIPTION_GIF = "Graphics Interchange Format (.gif)"; + public static final String EXT_GIF = "gif", EXT_EMF = "emf", EXT_SVG = "svg"; + + String lastDirectory = null; + + @Override + public void performAction() { + CfgScene scene = this.getEditor(); + JComponent view = scene.getView(); + + JFileChooser chooser = new JFileChooser (); + chooser.setAcceptAllFileFilterUsed(false); + chooser.setDialogTitle (getName()); + chooser.setDialogType (JFileChooser.SAVE_DIALOG); + chooser.setMultiSelectionEnabled (false); + chooser.setFileSelectionMode (JFileChooser.FILES_ONLY); + chooser.addChoosableFileFilter(new FileNameExtensionFilter(DESCRIPTION_SVG, EXT_SVG)); + chooser.addChoosableFileFilter(new FileNameExtensionFilter(DESCRIPTION_EMF, EXT_EMF)); + chooser.addChoosableFileFilter(new FileNameExtensionFilter(DESCRIPTION_GIF, EXT_GIF)); + if(lastDirectory != null) + chooser.setCurrentDirectory(new File(lastDirectory)); + // TODO: chose file. + chooser.setSelectedFile(new File("output")); + + + if (chooser.showSaveDialog (scene.getView()) != JFileChooser.APPROVE_OPTION) + return; + + File file = chooser.getSelectedFile (); + + if(file == null) + return; + + FileNameExtensionFilter filter = (FileNameExtensionFilter) chooser.getFileFilter(); + String fn = file.getAbsolutePath().toLowerCase(); + String ext = filter.getExtensions()[0]; + if(!fn.endsWith("." + ext)){ + file = new File( file.getParentFile(), file.getName() + "." + ext); + } + + if (file.exists ()) { + DialogDescriptor descriptor = new DialogDescriptor ( + "File (" + file.getAbsolutePath () + ") already exists. Do you want to overwrite it?", + "File Exists", true, DialogDescriptor.YES_NO_OPTION, DialogDescriptor.NO_OPTION, null); + DialogDisplayer.getDefault ().createDialog (descriptor).setVisible (true); + if (descriptor.getValue () != DialogDescriptor.YES_OPTION) + return; + } + + lastDirectory = chooser.getCurrentDirectory().getAbsolutePath(); + + /*if(ext.equals(EXT_SVG)){ + SVGGraphics2D g; + try { + g = new SVGGraphics2D(file, scene.getBounds().getSize()); + g.startExport(); + scene.paint(g); + g.endExport(); + } catch(Exception ex){ + } + } else if (ext.equals(EXT_EMF)) { + EMFGraphics2D g; + try { + g = new EMFGraphics2D(file, scene.getBounds().getSize()); + g.startExport(); + scene.paint(g); + g.endExport(); + } catch(Exception ex){ + } + } else if (ext.equals(EXT_GIF)) { + GIFGraphics2D g; + try { + //use the view as image source to get a image with the current zoomfactor + //using the scene.paint() would always return a image with zoomfactor 1.0 + g = new GIFGraphics2D(file, view); + g.startExport(); + view.print(g); + g.endExport(); + } catch(Exception ex){ + } + } */ + // TODO(tw): Add SVG export. + } + + + @Override + public String getName() { + return "Export CFG"; + } + + @Override + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + @Override + protected String iconResource() { + return "at/ssw/visualizer/cfg/icons/disk.gif"; + } + +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/HideEdgesAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/HideEdgesAction.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,37 @@ +package at.ssw.visualizer.cfg.action; + + +import at.ssw.visualizer.cfg.graph.CfgScene; +import at.ssw.visualizer.cfg.graph.EdgeWidget; +import at.ssw.visualizer.cfg.model.CfgEdge; +import at.ssw.visualizer.cfg.model.CfgNode; +import org.openide.util.HelpCtx; + +/** + * Hides all edges connected to the selected node. + * + * @author Bernhard Stiftner + * @author Rumpfhuber Stefan + */ +public class HideEdgesAction extends AbstractCfgEditorAction { + + public void performAction() { + CfgScene tc = getEditor(); + if (tc != null) { + tc.setSelectedEdgesVisibility(false); + } + } + + public String getName() { + return "Hide Edges"; + } + + @Override + protected String iconResource() { + return "at/ssw/visualizer/cfg/icons/hideedges.gif"; + } + + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/HierarchicalCompoundLayoutAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/HierarchicalCompoundLayoutAction.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ +package at.ssw.visualizer.cfg.action; + +import at.ssw.visualizer.cfg.CfgEditorContext; +import at.ssw.visualizer.cfg.graph.CfgScene; +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; + + +@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 HierarchicalCompoundLayoutAction(List scenes) { + this.scenes = scenes; + } + + @Override + public void actionPerformed(ActionEvent e) { + for (CfgScene s : scenes) { + s.setSceneLayout(CfgEditorContext.LAYOUT_HIERARCHICALCOMPOUNDLAYOUT); + } + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/HierarchicalNodeLayoutAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/HierarchicalNodeLayoutAction.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ +package at.ssw.visualizer.cfg.action; + +import at.ssw.visualizer.cfg.CfgEditorContext; +import at.ssw.visualizer.cfg.graph.CfgScene; +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; + + +@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 actionPerformed(ActionEvent e) { + for (CfgScene s : scenes) { + s.setSceneLayout(CfgEditorContext.LAYOUT_HIERARCHICALNODELAYOUT); + } + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/ShowAllAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/ShowAllAction.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,39 @@ +package at.ssw.visualizer.cfg.action; + +import at.ssw.visualizer.cfg.graph.CfgScene; +import org.openide.util.HelpCtx; + + +/** + * Adjusts the Zoom factor of the Scene to the bounds of Scroll panel + * to get a clean view on the whole graph. + * + */ +public class ShowAllAction extends AbstractCfgEditorAction { + + @Override + public void performAction() { + CfgScene tc = getEditor(); + if (tc != null) { + CfgScene scene = tc; + scene.zoomScene(); + + } + } + + @Override + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + @Override + public String getName() { + return "Fit Scene to Window"; + } + + @Override + protected String iconResource() { + return "at/ssw/visualizer/cfg/icons/autosize.gif"; + } + +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/ShowEdgesAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/ShowEdgesAction.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,37 @@ +package at.ssw.visualizer.cfg.action; + +import at.ssw.visualizer.cfg.graph.CfgScene; +import at.ssw.visualizer.cfg.graph.EdgeWidget; +import at.ssw.visualizer.cfg.model.CfgEdge; +import at.ssw.visualizer.cfg.model.CfgNode; +import org.openide.util.HelpCtx; + +/** + * Shows all edges connected to the selected node. + * + * @author Bernhard Stiftner + * @author Rumpfhuber Stefan + */ +public class ShowEdgesAction extends AbstractCfgEditorAction { + + public void performAction() { + CfgScene tc = getEditor(); + if (tc != null) { + tc.setSelectedEdgesVisibility(true); + } + } + + public String getName() { + return "Show edges"; + } + + + @Override + protected String iconResource() { + return "at/ssw/visualizer/cfg/icons/showedges.gif"; + } + + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/SwitchLoopClustersAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/SwitchLoopClustersAction.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,65 @@ +package at.ssw.visualizer.cfg.action; + +import at.ssw.visualizer.cfg.graph.CfgScene; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import javax.swing.JComponent; +import javax.swing.JToggleButton; +import org.openide.util.HelpCtx; +import org.openide.util.actions.Presenter; + +public class SwitchLoopClustersAction extends AbstractCfgEditorAction implements Presenter.Toolbar { + + @Override + public void performAction() { + CfgScene tc = getEditor(); + if (tc != null) { + CfgScene scene = tc; + boolean visible = scene.isLoopClusterVisible(); + scene.setLoopWidgets(!visible); + } + } + + @Override + public String getName() { + return "Enable/Disable Loop Clusters"; + } + + @Override + protected String iconResource() { + return "at/ssw/visualizer/cfg/icons/cluster.gif"; + } + + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + + @Override + public JComponent getToolbarPresenter() { + return new ToolbarPresenter(); + } + + class ToolbarPresenter extends JToggleButton { + private static final String TOOLTIP_ENABLE = "Enable LoopClusters"; + private static final String TOOLTIP_DISABLE = "Disable LoopClusters"; + + public ToolbarPresenter() { + super(SwitchLoopClustersAction.this); + setText(null); + this.setToolTipText(TOOLTIP_DISABLE); + this.setSelected(true); + + this.addItemListener(new ItemListener(){ + public void itemStateChanged(ItemEvent e) { + if(isSelected()){ + setToolTipText(TOOLTIP_DISABLE); + } else { + setToolTipText(TOOLTIP_ENABLE); + } + } + }); + } + } + +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/ZoominAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/ZoominAction.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,32 @@ +package at.ssw.visualizer.cfg.action; + +import at.ssw.visualizer.cfg.graph.CfgScene; +import org.openide.util.HelpCtx; + + +public class ZoominAction extends AbstractCfgEditorAction { + + @Override + public void performAction() { + CfgScene tc = getEditor(); + if (tc != null) { + CfgScene scene = tc; + scene.setZoomFactor(1.1); + } + } + + @Override + protected String iconResource() { + return "at/ssw/visualizer/cfg/icons/zoomin.gif"; + } + + @Override + public String getName() { + return "Zoomin"; + } + + @Override + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/ZoomoutAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/ZoomoutAction.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,32 @@ +package at.ssw.visualizer.cfg.action; + +import at.ssw.visualizer.cfg.graph.CfgScene; +import org.openide.util.HelpCtx; + +public class ZoomoutAction extends AbstractCfgEditorAction { + + @Override + public void performAction() { + CfgScene tc = getEditor(); + if (tc != null) { + CfgScene scene = tc; + scene.setZoomFactor(0.9); + } + } + + @Override + protected String iconResource() { + return "at/ssw/visualizer/cfg/icons/zoomout.gif"; + } + + @Override + public String getName() { + return "Zoomout"; + } + + @Override + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/CfgEventListener.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/CfgEventListener.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,13 @@ +package at.ssw.visualizer.cfg.graph; + +import java.util.EventListener; + + +public interface CfgEventListener extends EventListener { + + /** + * the node or the edge selection got changed + */ + public void selectionChanged(CfgScene scene); + +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/CfgScene.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/CfgScene.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,839 @@ +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.HideEdgesAction; +import at.ssw.visualizer.cfg.action.ShowEdgesAction; +import at.ssw.visualizer.cfg.graph.layout.HierarchicalCompoundLayout; +import at.ssw.visualizer.cfg.graph.layout.HierarchicalNodeLayout; +import at.ssw.visualizer.cfg.model.CfgEnv; +import at.ssw.visualizer.cfg.model.CfgNode; +import at.ssw.visualizer.cfg.model.LoopInfo; +import at.ssw.visualizer.cfg.preferences.CfgPreferences; +import at.ssw.visualizer.cfg.visual.PolylineRouter; +import at.ssw.visualizer.cfg.visual.PolylineRouterV2; +import at.ssw.visualizer.cfg.visual.WidgetCollisionCollector; +import at.ssw.visualizer.model.cfg.BasicBlock; +import at.ssw.visualizer.model.cfg.ControlFlowGraph; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.RenderingHints; +import java.awt.event.ActionEvent; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +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; +import javax.swing.JPopupMenu; +import javax.swing.JScrollPane; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.event.EventListenerList; +import org.netbeans.api.visual.action.ActionFactory; +import org.netbeans.api.visual.action.MoveProvider; +import org.netbeans.api.visual.action.PopupMenuProvider; +import org.netbeans.api.visual.action.RectangularSelectDecorator; +import org.netbeans.api.visual.action.RectangularSelectProvider; +import org.netbeans.api.visual.action.WidgetAction; +import org.netbeans.api.visual.anchor.Anchor; +import org.netbeans.api.visual.anchor.AnchorFactory; +import org.netbeans.api.visual.graph.GraphScene; +import org.netbeans.api.visual.graph.layout.GraphLayout; +import org.netbeans.api.visual.layout.LayoutFactory; +import org.netbeans.api.visual.layout.SceneLayout; +import org.netbeans.api.visual.router.Router; +import org.netbeans.api.visual.router.Router.*; +import org.netbeans.api.visual.router.RouterFactory; +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 { + + private LayerWidget mainLayer = new LayerWidget(this); + private LayerWidget connectionLayer = new LayerWidget(this); + private LayerWidget interractionLayer = 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 SceneLayout sceneLayout; + private CfgEnv env; + private int currentLayout = -1; + private JScrollPane scrollPane; + private EventListenerList listenerList = new EventListenerList(); + private WidgetAction contextPopupAction = this.createContextMenuAction(this); + private List nodeWidgets = null; + private boolean loopClustersVisible = true; + 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.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.createRectangularSelectAction( + this.createSelectDecorator(this), + 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()) { + addNode(n); + } + for (CfgEdge e : env.getEdges()) { + addEdge(e); + setEdgeSource(e, e.getSourceNode()); + setEdgeTarget(e, e.getTargetNode()); + } + this.stackLoops(cfgenv.getLoopMap()); + this.autoHideEdges(); + } + + public void loadDefaults() { + 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) { + 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) { + LoopClusterWidget parentWidget = this.loopidx2clusterwidget.get(parent.getLoopIndex()); + assert parentWidget != null; + if (widget.getParentWidget() != null) { + widget.removeFromParent(); + } + parentWidget.addChild(widget); + 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)) { + EdgeSwitchWidget esw = this.inputSwitches.get(n); + esw.changeEdgeVisibility(false); + } + } + 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(); + } + + //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 + */ + public void setSelectedNodesColor(Color 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); + } + } else { + for (CfgNode n : this.selectedNodes) { + NodeWidget nw = (NodeWidget) this.findWidget(n); + nw.setNodeColor(color, true); + } + } + this.validate(); + } + + public void setSelectedEdgesVisibility(boolean visible) { + 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); + } + } + this.fireSelectionChanged(); + this.validate(); + } + + public EdgeSwitchWidget getInputSwitch(CfgNode n) { + return this.inputSwitches.get(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()) { + w.setVisible(visible); + w.revalidate(); + } + this.loopClustersVisible = visible; + this.validate(); + } + + private void setUseBezierRouter(boolean value) { + Router 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()) { + NodeWidget w = (NodeWidget) this.findWidget(n); + widgets.add(w); + } + + nodeWidgets = Collections.unmodifiableList(widgets); + return widgets; + } + + public void setSceneLayout(int newLayout) { + + if (currentLayout == newLayout) { + return; + } + + GraphLayout graphLayout = null; + + switch (newLayout) { + case CfgEditorContext.LAYOUT_HIERARCHICALNODELAYOUT: + 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); + } + + getPreferences().putInt(PREFERENCE_LAYOUT, newLayout); + sceneLayout.invokeLayoutImmediately(); + } + + @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); + } + + @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); + } else { + targetAnchor = AnchorFactory.createRectangularAnchor(targetWidget); + } + edgeWidget.setTargetAnchor(targetAnchor); + } + + @Override + protected Widget attachEdgeWidget(CfgEdge edge) { + EdgeWidget widget = new EdgeWidget(this, edge); + connectionLayer.addChild(widget); + attachSourceSwitchWidget(edge); + attachTargetSwitchWidget(edge); + return widget; + } + + @Override + protected Widget attachNodeWidget(CfgNode node) { + this.nodeWidgets = null; + + 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); + return nw; + } + + private LoopClusterWidget attachLoopMember(CfgNode node) { + LoopClusterWidget lw = this.loopidx2clusterwidget.get(node.getLoopIndex()); + 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) { + LoopClusterWidget rm = this.loopidx2clusterwidget.get(node.getLoopIndex()); + 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 + w.removeFromParent(); + rm.getParentWidget().addChild(w); + } + rm.removeFromParent(); + } + return true; + } + 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); + } + super.detachNodeWidget(node, nodeWidget); + assert nodeWidget.getParentWidget() == null; + if (this.inputSwitches.containsKey(node)) { + EdgeSwitchWidget esw = this.inputSwitches.remove(node); + this.connectionLayer.removeChild(esw); + } + if (this.outputSwitches.containsKey(node)) { + EdgeSwitchWidget esw = this.outputSwitches.remove(node); + this.connectionLayer.removeChild(esw); + } + } + + protected EdgeSwitchWidget attachSourceSwitchWidget(CfgEdge e) { + CfgNode sourceNode = e.getSourceNode(); + NodeWidget sourceWidget = (NodeWidget) this.findWidget(sourceNode); + EdgeSwitchWidget out = outputSwitches.get(sourceNode); + if (out == null) { + out = new EdgeSwitchWidget(this, sourceWidget, true); + this.connectionLayer.addChild(out); + outputSwitches.put(sourceNode, out); + } + return out; + } + + protected EdgeSwitchWidget attachTargetSwitchWidget(CfgEdge e) { + CfgNode targetNode = e.getTargetNode(); + NodeWidget targetWidget = (NodeWidget) this.findWidget(targetNode); + EdgeSwitchWidget in = inputSwitches.get(targetNode); + if (in == null) { + in = new EdgeSwitchWidget(this, targetWidget, false); + this.connectionLayer.addChild(in); + inputSwitches.put(targetNode, in); + } + return in; + } + + //resets the selection state of all NodeWidgets + private void cleanNodeSelection() { + if (!this.selectedNodes.isEmpty()) { + this.userSelectionSuggested(Collections.emptySet(), false); + this.selectedNodes = Collections.emptySet(); + this.fireSelectionChanged(); + this.validate(); + } + } + + //sets the scene & global node selection + public void setNodeSelection(Set newSelection) { + this.setSceneSelection(newSelection); + 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) { + 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) { + this.centerSelection(); + } + + this.userSelectionSuggested(selectedObjects, false); + this.fireSelectionChanged(); + this.validate(); + } + + //updates selection of Block View + public void updateGlobalSelection() { + // TODO(tw): Add selection management. +// Selection selection = SelectionManager.getDefault().getCurSelection(); +// ArrayList newBlocks = new ArrayList(); +// for (CfgNode n : this.selectedNodes) { +// newBlocks.add(n.getBasicBlock()); +// } +// 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) { + return; + } + + selectionUpdating = true; + + Object source = event.getSource(); +// if(source instanceof Selection){ +// Selection selection=(Selection) source; +// Set newSelection = new HashSet(); +// BasicBlock[] newBlocks = selection.get(BasicBlock[].class); +// if (newBlocks != null) { +// for(BasicBlock b : newBlocks){ +// for(CfgNode n : this.getNodes()){ +// if(n.getBasicBlock() == b) newSelection.add(n); +// } +// } +// this.setSceneSelection(newSelection); +// } +// } + selectionUpdating = false; + // TODO(tw): Add selection management. + } + + //centers the viewport on the currently selected nodewidgets + private void centerSelection() { + Point sceneCenter = null; + Collection nodes = this.selectedNodes; + if (nodes.size() == 0) { + nodes = this.getNodes(); + } + + 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(); + if (view != null) { + Rectangle viewBounds = view.getVisibleRect(); + + Point viewCenter = this.convertSceneToView(sceneCenter); + + view.scrollRectToVisible(new Rectangle( + viewCenter.x - viewBounds.width / 2, + viewCenter.y - viewBounds.height / 2, + viewBounds.width, + viewBounds.height)); + } + } + + public void zoomScene() { + JScrollPane pane = scrollPane; + 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.setZoomFactor(zoomFactor * 0.9); + } + + public void addCfgEventListener(CfgEventListener l) { + listenerList.add(CfgEventListener.class, l); + } + + 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); + } + } + } + + //Enables Antialiasing + @Override + public void paintChildren() { + Object anti = getGraphics().getRenderingHint(RenderingHints.KEY_ANTIALIASING); + Object textAnti = getGraphics().getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING); + + getGraphics().setRenderingHint( + RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + getGraphics().setRenderingHint( + RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + + super.paintChildren(); + + getGraphics().setRenderingHint(RenderingHints.KEY_ANTIALIASING, anti); + getGraphics().setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, textAnti); + } + + //select provider for node selection + private RectangularSelectProvider createRectangularSelectProvider() { + 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; + } + 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()); + } + } + setNodeSelection(set); + } + }; + } + + //select decorator for node selection + private RectangularSelectDecorator createSelectDecorator(final CfgScene scene) { + return new RectangularSelectDecorator() { + + public Widget createSelectionWidget() { + scene.cleanNodeSelection();//unselected all nodes + scene.revalidate(); + return new SelectionWidget(getScene()); + } + }; + } + + private MoveProvider createMoveProvider() { + 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) { + 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); + 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())) { + return;//to be able to move the current selection + } + + HashSet selectedNode = new HashSet<>(1); + selectedNode.add(nw.getNodeModel()); + setNodeSelection(selectedNode); + originals.clear(); + original = null; + + } + + public Point getOriginalLocation(Widget widget) { + if (original == null) { + original = widget.getLocation(); + } + + 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()) { + EdgeWidget ew = (EdgeWidget) findWidget(e); + if (ew.isVisible()) { + ew.reroute(); + } + } + } + }; + } + + private WidgetAction createContextMenuAction(final CfgScene scene) { + return ActionFactory.createPopupMenuAction(new PopupMenuProvider() { + + public JPopupMenu getPopupMenu(Widget widget, Point point) { + JPopupMenu menu = new JPopupMenu(); + NodeWidget nw = null; + if (widget instanceof NodeWidget) { + nw = (NodeWidget) widget; + if (!selectedNodes.contains(nw.getNodeModel())) { + HashSet selectedNode = new HashSet<>(1); + selectedNode.add(nw.getNodeModel()); + setNodeSelection(selectedNode); + } + } 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()) { + successors.add(e.getTargetNode()); + } + for (CfgEdge e : node.getInputEdges()) { + predecessors.add(e.getSourceNode()); + } + + 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); + predmenu.add(action); + } + menu.add(predmenu); + } + 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); + succmenu.add(action); + } + 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) { + 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); + } + } + + 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(); + } + } + + private SceneListener createSceneListener(final CfgScene scene) { + return new SceneListener() { + + public void sceneRepaint() { + } + + public void sceneValidating() { + } + + public void sceneValidated() { + if (scene.isLoopClusterVisible()) { //update only if visible + for (LoopClusterWidget cw : getLoopidx2clusterwidget().values()) { + cw.updateClusterBounds(); + } + } + for (EdgeSwitchWidget esw : inputSwitches.values()) { + esw.updatePosition(); + } + + for (EdgeSwitchWidget esw : outputSwitches.values()) { + esw.updatePosition(); + } + } + }; + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/EdgeSwitchWidget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/EdgeSwitchWidget.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,291 @@ +package at.ssw.visualizer.cfg.graph; + +import at.ssw.visualizer.cfg.model.CfgEdge; +import at.ssw.visualizer.cfg.model.CfgNode; +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.Polygon; +import java.awt.Rectangle; +import java.awt.geom.AffineTransform; +import java.util.ArrayList; +import java.util.Collection; +import org.netbeans.api.visual.action.ActionFactory; +import org.netbeans.api.visual.action.SelectProvider; +import org.netbeans.api.visual.action.TwoStateHoverProvider; +import org.netbeans.api.visual.action.WidgetAction; +import org.netbeans.api.visual.model.ObjectState; +import org.netbeans.api.visual.widget.Widget; + + +public class EdgeSwitchWidget extends Widget { + private final static Color color_enabled = Color.gray; + private final static Color color_hover = Color.lightGray; + private float width=1; + private float height=1; + private CfgScene scene; + private NodeWidget nodeWidget; + private boolean output; + private WidgetAction hoverAction; + private static final String TT_HIDE_EDGES = "Hide Edges"; + private static final String TT_SHOW_EDGES = "Show Edges"; + private static SelectProvider selectProvider = createSelectProvider(); + + + public EdgeSwitchWidget(final CfgScene scene, NodeWidget nodeWidget, boolean output) { + super(scene); + this.scene = scene; + this.output = output; + this.nodeWidget = nodeWidget; + + this.getActions().addAction(ActionFactory.createSelectAction(selectProvider)); + TwoStateHoverProvider ts = new TsHover(this); + WidgetAction wa = ActionFactory.createHoverAction(ts); + this.hoverAction = wa; + this.getActions().addAction(wa); + scene.getActions().addAction(wa); + this.setToolTipText(TT_HIDE_EDGES); + this.setForeground(color_enabled); + this.setState(ObjectState.createNormal()); + } + + + @Override + protected Rectangle calculateClientArea() { + if (this.nodeWidget.getBounds() == null) return new Rectangle(0, 0, 1, 1); + int hw = (int) (this.width / 2); + int hh = (int) (this.height /2); + + return new Rectangle(-hw, -hh, 2*hw, 2*hh); + } + + + public void updatePosition() { + if (this.nodeWidget.getBounds() != null) { + this.width = nodeWidget.getBounds().width*9; + this.width /=10; + this.height = nodeWidget.getBounds().height/4; + int offset=(int)(2 * (height / 3)); + + Rectangle bounds = nodeWidget.getBounds(); + Point location = nodeWidget.getLocation(); + + Point newLoc = new Point(); + newLoc.x = location.x; + + if(output) { + newLoc.y = +location.y + bounds.height/2+offset; + }else { + newLoc.y = location.y - bounds.height/2-offset; + } + this.setPreferredLocation(newLoc); + } + } + + private Collection getEdges(){ + Collection edges; + CfgNode node = nodeWidget.getNodeModel(); + if (output) { + edges = scene.findNodeEdges(node, true, false); + } else { + edges = scene.findNodeEdges(node, false, true); + } + return edges; + } + + //change visibility for all Edges + public void changeEdgeVisibility(boolean visible){ + Collection edges = this.getEdges(); + + for(CfgEdge e: edges) { + EdgeWidget ew = (EdgeWidget) scene.findWidget(e); + if(visible != ew.isEdgeVisible()){ + ew.setEdgeVisible(visible); + if(output){ + scene.getInputSwitch(e.getTargetNode()).updateStatus(); + } else { + scene.getOutputSwitch(e.getSourceNode()).updateStatus(); + } + } + } + if(visible) + this.setToolTipText(TT_HIDE_EDGES); + else + this.setToolTipText(TT_SHOW_EDGES); + + this.setForeground(color_enabled); + this.bringToBack(); + ObjectState os = this.getState(); + this.setState(os.deriveSelected(!visible)); + } + + /** + * Update the status of the switch to the current state of the edges + * usually needed when the opposit switch changes the state + */ + private void updateStatus(){ + Collection edges = this.getEdges(); + boolean hiddenFound=false; + for(CfgEdge e: edges) { + EdgeWidget ew = (EdgeWidget) scene.findWidget(e); + if(!ew.isVisible()) { + hiddenFound=true; + break; + } + } + ObjectState os = this.getState(); + if(os.isSelected() && !hiddenFound) { + this.setState(os.deriveSelected(false)); + setToolTipText(TT_HIDE_EDGES); + } else if (!os.isSelected() && hiddenFound) { + this.setState(os.deriveSelected(true)); + setToolTipText(TT_SHOW_EDGES); + } + this.revalidate(); + } + + + public void startPreview() { + ObjectState os = this.getState(); + + for(CfgEdge e : getEdges()) { + EdgeWidget ew = (EdgeWidget) scene.findWidget(e); + if(!os.isSelected() || !ew.isVisible()){ + ObjectState edgeState = ew.getState(); + ew.setState(edgeState.deriveHighlighted(true)); + } + } + } + + public void endPreview(){ + for(CfgEdge e : getEdges()) { + EdgeWidget ew = (EdgeWidget) scene.findWidget(e); + ObjectState os = ew.getState(); + ew.setState(os.deriveHighlighted(false)); + } + } + + /** + * shows or hides the edges of the switch + */ + public void switchEdges() { + endPreview(); + ObjectState os = this.getState(); + Collection edges = this.getEdges(); + ArrayList updates = new ArrayList<>(); + boolean visible=os.isSelected(); + this.setState(os.deriveSelected(!visible)); + for(CfgEdge e: edges) { + EdgeWidget ew = (EdgeWidget) scene.findWidget(e); + if(ew.isEdgeVisible() != visible){ + updates.add(e); + ew.setEdgeVisible(visible); + if(output){ + scene.getInputSwitch(e.getTargetNode()).updateStatus(); + } else { + scene.getOutputSwitch(e.getSourceNode()).updateStatus(); + } + } + } + if(visible) + this.setToolTipText(TT_HIDE_EDGES); + else + this.setToolTipText(TT_SHOW_EDGES); + + scene.fireSelectionChanged();//updates Edge visibility for context action + revalidate(); + } + + + + + private class TsHover implements TwoStateHoverProvider { + EdgeSwitchWidget tw; + + TsHover(EdgeSwitchWidget tw) { + this.tw = tw; + } + + public void unsetHovering(Widget w) { + w.setForeground(color_enabled); + ObjectState state = w.getState(); + w.setState(state.deriveWidgetHovered(false)); + w.bringToBack(); + endPreview(); + } + + public void setHovering(Widget w) { + ObjectState state = w.getState(); + w.setState(state.deriveWidgetHovered(true)); + w.setForeground(color_hover); + w.bringToFront(); + nodeWidget.bringToFront(); + startPreview(); + } + } + + @Override + public void paintWidget() { + ObjectState os = this.getState(); + if(!os.isHovered() && !os.isSelected()) return; //all previewEdges visible and not hovering, + //no need to paint the switch + float hw = width/2; + Polygon pol = new Polygon(); + pol.addPoint(0,(int) -height/2); + pol.addPoint((int)hw,(int) height/2); + pol.addPoint((int)-hw,(int) height/2); + Graphics2D gr = getGraphics(); + gr.setColor(this.getForeground()); + BasicStroke bs = new BasicStroke(2.0f, BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND); + gr.setStroke(bs); + AffineTransform previousTransform; + previousTransform = gr.getTransform (); + if(output) { + if(os.isSelected() ){//hidden + gr.scale(1.0, -1.0); + } + } else { //input switch + if(os.isHovered() && !os.isSelected()){ + gr.scale(1.0, -1.0); + } + } + gr.fillPolygon(pol); + gr.setTransform(previousTransform); + + } + + + + //the constructor adds the hover WidgetAction to the scene + //the action is removed from the scene when the object gets destroyed + @Override + protected void finalize() throws Throwable { + this.getScene().getActions().removeAction(hoverAction); + this.getActions().removeAction(hoverAction); + } + + @Override + public String toString(){ + return "EDGESWITCH("+this.nodeWidget.getNodeModel().toString()+")"; + } + + private static SelectProvider createSelectProvider() { + return new SelectProvider(){ + public boolean isAimingAllowed(Widget arg0, Point arg1, boolean arg2) { + return false; + } + + public boolean isSelectionAllowed(Widget arg0, Point arg1, boolean arg2) { + return true; + } + + public void select(Widget w, Point arg1, boolean arg2) { + if(w instanceof EdgeSwitchWidget){ + EdgeSwitchWidget tw = (EdgeSwitchWidget) w; + tw.switchEdges(); + } + } + }; + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/EdgeWidget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/EdgeWidget.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,97 @@ +package at.ssw.visualizer.cfg.graph; + +import at.ssw.visualizer.cfg.model.CfgEdge; +import at.ssw.visualizer.cfg.preferences.CfgPreferences; +import at.ssw.visualizer.cfg.visual.BezierWidget; +import at.ssw.visualizer.cfg.visual.SplineConnectionWidget; +import org.netbeans.api.visual.anchor.AnchorShapeFactory; +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Stroke; +import org.netbeans.api.visual.anchor.AnchorShape; +import org.netbeans.api.visual.model.ObjectState; + +//public class EdgeWidget extends BezierWidget { +public class EdgeWidget extends SplineConnectionWidget { + + private boolean visible=true;//to store the visible state when entering the preview + protected static final Stroke selectedStroke = new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); + protected static final Stroke defaultStroke = new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); + protected static final Stroke previewStroke = new BasicStroke( + 0.5f, // Width + BasicStroke.CAP_SQUARE, // End cap + BasicStroke.JOIN_MITER, // Join style + 10.0f, // Miter limit + new float[] {5.0f, 5.0f}, // Dash pattern + 0.0f); + + + + public EdgeWidget(CfgScene scene, CfgEdge edge) { + super(scene); + Color lineColor; + CfgPreferences prefs = CfgPreferences.getInstance(); + + if(edge.isBackEdge()) + lineColor = prefs.getBackedgeColor(); + else if (edge.isXhandler()) + lineColor = prefs.getExceptionEdgeColor(); + else + lineColor = prefs.getEdgeColor(); + + setLineColor(lineColor); + AnchorShape as; + if(edge.isReflexive())//small Arrow + as = AnchorShapeFactory.createTriangleAnchorShape(6, true, false, 5); + else + as =AnchorShapeFactory.createTriangleAnchorShape(10, true, false, 9); + + setTargetAnchorShape(as); + setToolTipText(edge.toString()); + } + + public CfgEdge getEdgeModel() { + CfgScene scene = (CfgScene) this.getScene(); + return (CfgEdge) scene.findObject(this); + } + + public void setEdgeVisible(boolean visible) { + this.visible=visible; + this.setVisible(visible); + this.reroute(); + this.revalidate(); + } + + + public boolean isEdgeVisible(){ + return visible; + } + + + @Override + public void notifyStateChanged(ObjectState oldState, ObjectState newState) { + setForeground (getLineColor()); + + if(newState.isHighlighted() && !oldState.isHighlighted()){ + this.setStroke(previewStroke); + this.setVisible(true); + } else { + if(newState.isSelected()){ + this.setStroke(selectedStroke); + } else { + this.setStroke(defaultStroke); + } + if(this.isEdgeVisible()){ + this.setVisible(true); + } else { + this.setVisible(false); + } + } + } + + + @Override + public String toString(){ + return "EdgeWidget[" + getEdgeModel().toString() + "]"; + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/LoopClusterWidget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/LoopClusterWidget.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,107 @@ +package at.ssw.visualizer.cfg.graph; + +import at.ssw.visualizer.cfg.model.LoopInfo; +import java.awt.Color; +import java.awt.Rectangle; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import org.netbeans.api.visual.action.ActionFactory; +import org.netbeans.api.visual.action.EditProvider; +import org.netbeans.api.visual.border.BorderFactory; +import org.netbeans.api.visual.widget.Widget; + +public class LoopClusterWidget extends Widget implements Comparable { + private static final int INSET = 10;//min space between node members and cluster border + private static final int DASHSIZE = 10; + private Color color = Color.BLUE; + private int loopIndex; + private int loopDepth; + private CfgScene cfgscene; + private ArrayList members = new ArrayList<>(); + + public LoopClusterWidget(CfgScene scene, int loopdepth, final int loopindex) { + super(scene); + this.cfgscene = scene; + this.loopIndex = loopindex; + this.loopDepth = loopdepth; + this.setBorder(BorderFactory.createDashedBorder(color, DASHSIZE, DASHSIZE/2, true)); + this.getActions().addAction(ActionFactory.createEditAction( new EditProvider() { //double click action + public void edit(Widget w) { + if(w instanceof LoopClusterWidget){ + for(LoopInfo info : cfgscene.getCfgEnv().getLoopMap().values()){ + if(info.getLoopIndex() == loopindex){ + cfgscene.setNodeSelection(info.getMembers()); + break; + } + } + } + } + })); + + } + + public List getMembers() { + return members; + } + + public int getLoopIndex() { + return loopIndex; + } + + public void addMember(NodeWidget nw) { + assert(!this.members.contains(nw)); + members.add(nw); + } + + public boolean removeMember(NodeWidget nw) { + if(this.members.contains(nw)){ + members.remove(nw); + return true; + } + return false; + } + + public void setrandomColor(){ + if(this.loopDepth == 0 ) return; + Random rand = new Random(); + Color randColor = Color.getHSBColor(rand.nextFloat()%360,0.1f,1.0f); + this.setBackground(randColor); + } + + //updates the bounds of the widget, + //and revalidates the widget if a membernode changed the scene position + public void updateClusterBounds(){ + Rectangle boundRect=null; + + for(NodeWidget nw : this.members){ + if(boundRect==null){ + boundRect = nw.convertLocalToScene(nw.getBounds()); + } else { + boundRect = boundRect.union(nw.convertLocalToScene(nw.getBounds())); + } + } + if(boundRect==null) return; + for(Widget w : this.getChildren()) { + if(w instanceof LoopClusterWidget) { + LoopClusterWidget lc = (LoopClusterWidget)w; + lc.updateClusterBounds(); + boundRect = boundRect.union(w.convertLocalToScene(w.getBounds())); + } + } + + boundRect.grow(INSET, INSET); + this.setPreferredBounds(boundRect); + } + + + public int compareTo(LoopClusterWidget o) { + return new Integer(this.loopDepth).compareTo(o.loopDepth); + } + + + @Override + public String toString(){ + return "LoopCluster: [DEPTH "+this.loopDepth+ "] [INDEX "+this.loopIndex+"]"; + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/NodeWidget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/NodeWidget.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,155 @@ +package at.ssw.visualizer.cfg.graph; + +import at.ssw.visualizer.cfg.model.CfgNode; +import at.ssw.visualizer.cfg.preferences.CfgPreferences; +import java.awt.AlphaComposite; +import java.awt.Color; +import java.awt.Composite; +import java.awt.Font; +import java.awt.Graphics2D; +import java.awt.Insets; +import java.awt.Rectangle; +import java.awt.font.FontRenderContext; +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; +import java.awt.geom.RoundRectangle2D; +import org.netbeans.api.visual.border.BorderFactory; +import org.netbeans.api.visual.model.ObjectState; +import org.netbeans.api.visual.widget.Widget; + + +public class NodeWidget extends Widget { + + + //basic block node dimension + private final int halfheight=12; + private final int halfwidth=17; + + private final int height=halfheight*2+1; + private final int width=halfwidth*2+1; + private final int arcHeight=(halfheight/4)*3; + private final int arcWidth = arcHeight; + private final int FONT_MAXSIZE=18; + + private int borderWidth; + private boolean selected=false; + private boolean nodeColorCustomized; + private String text; + private Rectangle2D fontRect; + private Color nodeColor; + + protected static final Color HOVER_BACKGROUND = new Color(0xEEEEEE); + protected static final Color HOVER_FOREGROUND = new Color(0xCDCDCD); + + public NodeWidget(CfgScene scene, CfgNode nodeModel ){ + super(scene); + this.setToolTipText("" + nodeModel.getDescription().replaceAll("\n", "
") + ""); + this.selected=false; + this.text = nodeModel.getBasicBlock().getName(); + this.borderWidth = nodeModel.getLoopDepth()+1; + this.setBorder(BorderFactory.createRoundedBorder(arcWidth+borderWidth, arcHeight+borderWidth, borderWidth, borderWidth, Color.BLACK, Color.BLACK)); + CfgPreferences prefs = CfgPreferences.getInstance(); + Color color = prefs.getFlagsSetting().getColor(nodeModel.getBasicBlock().getFlags()); + this.nodeColorCustomized = (color!=null); + this.nodeColor = (nodeColorCustomized) ? color : prefs.getNodeColor(); + this.adjustFont(null); + } + + public void setBorderColor(Color color){ + this.setBorder(BorderFactory.createRoundedBorder(arcWidth+borderWidth, arcHeight+borderWidth, borderWidth, borderWidth, color, color)); + } + + public boolean isNodeColorCustomized() { + return nodeColorCustomized; + } + + //sets a customColor node color + public void setNodeColor(Color color, boolean customColor) { + this.nodeColorCustomized=customColor; + this.nodeColor=color; + this.revalidate(); + } + + public Color getNodeColor() { + return this.nodeColor; + } + + public CfgNode getNodeModel() { + CfgScene scene = (CfgScene) this.getScene(); + return (CfgNode) scene.findObject(this); + } + + + @Override + public void notifyStateChanged(ObjectState oldState, ObjectState newState) { + if(!oldState.equals(newState)) + this.revalidate(); + if(!oldState.isSelected() && newState.isSelected()) + this.bringToFront(); + } + + @Override + protected Rectangle calculateClientArea() { + return new Rectangle(-(halfwidth+1), -(1+halfheight), width+1, height+1);//add border + } + + public void adjustFont(Font font){ + if(font==null) + font = CfgPreferences.getInstance().getTextFont(); + if(font.getSize()>FONT_MAXSIZE){ + font = new Font(font.getFamily(), font.getStyle(), FONT_MAXSIZE); + } + int size=font.getSize(); + int fontStyle = font.getStyle(); + String fontName = font.getFamily(); + FontRenderContext frc = new FontRenderContext(new AffineTransform(), false, false); + Rectangle2D bounds = font.getStringBounds(text, frc); + while(size > 1 && bounds.getWidth() > width) { + font = new Font(fontName, fontStyle, --size); + bounds = font.getStringBounds(text, frc); + } + this.fontRect=bounds; + this.setFont(font); + } + + @Override + protected void paintWidget() { + Graphics2D gr = getGraphics(); + gr.setColor(nodeColor); + Insets borderInsets = this.getBorder().getInsets(); + RoundRectangle2D.Float innerRect = new RoundRectangle2D.Float(-(halfwidth+1), -(halfheight+1), width+1, height+1,arcWidth-1, arcHeight-1); + gr.fill(innerRect); + gr.setColor(getForeground()); + gr.setFont(getFont()); + float textX = (float)( - fontRect.getCenterX()); + float textY = (float)( - fontRect.getCenterY()); + gr.drawString(text, textX, textY); + + RoundRectangle2D.Float outerRect = new RoundRectangle2D.Float(-(halfwidth+borderInsets.left + 1), -(halfheight+borderInsets.top + 1), + width+borderInsets.left + borderInsets.right + 1, height + borderInsets.top + borderInsets.bottom + 1, + arcWidth + borderWidth, arcHeight + borderWidth); + + ObjectState os =this.getState(); + if(os.isSelected()){ + Composite composite = gr.getComposite(); + gr.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.5f)); + gr.setColor(CfgPreferences.getInstance().getSelectionColorForeground()); + gr.fill(outerRect); + gr.setColor(CfgPreferences.getInstance().getSelectionColorBackground()); + gr.setComposite(composite); + } + if(os.isHovered()){ + Composite composite = gr.getComposite(); + gr.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.5f)); + gr.setColor(HOVER_FOREGROUND); + gr.fill(outerRect); + gr.setColor(HOVER_BACKGROUND); + gr.setComposite(composite); + } + } + + @Override + public String toString() { + return "NodeWidget[" + getNodeModel().getBasicBlock().getName() + "]"; + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/SelectionWidget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/SelectionWidget.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,39 @@ +package at.ssw.visualizer.cfg.graph; + +import at.ssw.visualizer.cfg.preferences.CfgPreferences; +import java.awt.AlphaComposite; +import java.awt.Composite; +import java.awt.Graphics2D; +import java.awt.Rectangle; +import org.netbeans.api.visual.widget.Scene; +import org.netbeans.api.visual.widget.Widget; + + +public class SelectionWidget extends Widget { + public SelectionWidget(Scene scene) { + super(scene); + } + + public static void renderSelectedRect(Graphics2D gr, Rectangle rect) { + if (rect == null) { + return; + } + gr.setColor(CfgPreferences.getInstance().getSelectionColorBackground()); + gr.fillRect(rect.x, rect.y, rect.width, rect.height); + gr.setColor(CfgPreferences.getInstance().getSelectionColorForeground()); + } + + public void renderSelectionRectangle(Graphics2D gr, Rectangle selectionRectangle) { + Composite composite = gr.getComposite(); + gr.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.5f)); + + renderSelectedRect(gr, selectionRectangle); + gr.setComposite(composite); + } + + @Override + public void paintWidget(){ + this.renderSelectionRectangle(this.getGraphics(), this.getBounds()); + } + +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/SymmetricAnchor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/SymmetricAnchor.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,157 @@ +package at.ssw.visualizer.cfg.graph; + +import org.netbeans.api.visual.widget.Widget; +import org.netbeans.api.visual.anchor.Anchor; +import java.awt.*; + + +/** + * This Anchor can be used with symmetric edges to create parallel Edges. + * Two Directed Edges are symmetric if they are connecting the same Nodes in different directions. + * e.g. Nodes (1, 2) Edges(a , b) with (1)-a->(2) , (2)-b->(1) + * Start-/End positions are calculated with a fixed offset to prevent edges from overlapping. + * If the edges are drawn as straight lines they will appear as parallel edges. + */ + +public final class SymmetricAnchor extends Anchor { + + private final static int OFFSET = 10; + private boolean includeBorders; + private int offx; + private int offy; + + public SymmetricAnchor (Widget widget, boolean includeBorders, boolean source) { + super (widget); + this.includeBorders = includeBorders; + if (source) { + offx = OFFSET; + offy = OFFSET; + } + else { + offx = -OFFSET; + offy = -OFFSET; + } + } + + public Result compute (Entry entry) { + Point relatedLocation = //center of the widget + getRelatedSceneLocation (); + Point oppositeLocation = //center of the widget + getOppositeSceneLocation (entry); + + Widget widget = getRelatedWidget (); + Rectangle bounds = widget.getBounds (); + if (! includeBorders) { + Insets insets = widget.getBorder ().getInsets (); + bounds.x += insets.left; + bounds.y += insets.top; + bounds.width -= insets.left + insets.right; + bounds.height -= insets.top + insets.bottom; + } + + bounds = widget.convertLocalToScene (bounds); + + if (bounds.isEmpty () || relatedLocation.equals (oppositeLocation)) + return new Anchor.Result (relatedLocation, Anchor.DIRECTION_ANY); + + float dx //distance x-axis + = oppositeLocation.x - relatedLocation.x; + float dy //distance y-axis + = oppositeLocation.y - relatedLocation.y; + + + float ddx + = Math.abs (dx) / (float) bounds.width; + float ddy = + Math.abs (dy) / (float) bounds.height; + + Anchor.Direction direction; + + + if (ddx >= ddy) { + if(dx >= 0.0f){ + direction = Direction.RIGHT; + relatedLocation.y -= offy; + } else { + direction = Direction.LEFT; + relatedLocation.y += offy; + } + } else { + if(dy >= 0.0f){ + direction = Direction.BOTTOM; + relatedLocation.x += offx; + } else { + direction = Direction.TOP; + relatedLocation.x -= offx; + } + } + + + float scale = 0.5f / Math.max (ddx, ddy); + + float ex = scale * dx; + float ey = scale * dy; + + Point point = new Point (Math.round (relatedLocation.x + ex), Math.round (relatedLocation.y + ey)); + + if(direction == Direction.RIGHT) { + int top = bounds.y;//-bounds.height;// left y of the widget + int bottom = bounds.y + bounds.height;// right y of the widget + if(point.y < top) {//above the widget + int cor = top-point.y; + point.x -= cor; + point.y += cor; + } else if ( point.y > bottom) { + int cor = point.y-bottom; + point.x -= cor; + point.y -= cor; + } + + } else if (direction == Direction.LEFT) { + int top = bounds.y;//-bounds.height;// left y of the widget + int bottom = bounds.y + bounds.height;// right y of the widget + + + + if(point.y < top) {//above the widget + int cor = top-point.y; + point.x += cor; + point.y += cor; + } else if ( point.y > bottom) { + int cor = bottom-point.y; + point.x -= cor; + point.y += cor; + } + + + } else if (direction == Direction.BOTTOM) { + int left = bounds.x;//-bounds.height;// left y of the widget + int right = bounds.x + bounds.width;// right y of the widget + if(point.x < left) {//above the widget + int cor = left-point.x; + point.x += cor; + point.y -= cor; + } else if ( point.x > right) { + int cor = point.x- right; + point.x -= cor; + point.y -= cor; + } + + } else if (direction == Direction.TOP) { + int left = bounds.x;//-bounds.height;// left y of the widget + int right = bounds.x + bounds.width;// right y of the widget + if(point.x < left) {//above the widget + int cor = left-point.x; + point.x += cor; + point.y += cor; + } else if ( point.x > right) { + int cor = point.x - right; + point.x -= cor; + point.y += cor; + } + + } + + return new Anchor.Result (point, direction); + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/layout/HierarchicalCompoundLayout.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/layout/HierarchicalCompoundLayout.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,102 @@ +package at.ssw.visualizer.cfg.graph.layout; + +import at.ssw.visualizer.cfg.graph.CfgScene; +import at.ssw.visualizer.cfg.model.CfgEdge; +import at.ssw.visualizer.cfg.model.CfgNode; +import at.ssw.visualizer.cfg.model.LoopInfo; +import java.awt.Point; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import org.eclipse.draw2d.geometry.Insets; +import org.netbeans.api.visual.graph.layout.GraphLayout; +import org.netbeans.api.visual.graph.layout.UniversalGraph; +import org.eclipse.draw2d.graph.CompoundDirectedGraph; +import org.eclipse.draw2d.graph.CompoundDirectedGraphLayout; +import org.eclipse.draw2d.graph.Edge; +import org.eclipse.draw2d.graph.EdgeList; +import org.eclipse.draw2d.graph.Node; +import org.eclipse.draw2d.graph.NodeList; +import org.eclipse.draw2d.graph.Subgraph; +import org.netbeans.api.visual.widget.Widget; + +public class HierarchicalCompoundLayout extends GraphLayout { + + private static final int TOP_BORDER = 20; + private static final int LEFT_BORDER = 20; + private int PADDING = 20; + private static final int INSET = 20; + private CfgScene scene; + + public HierarchicalCompoundLayout(CfgScene scene){ + this.scene = scene; + } + + @Override + protected void performGraphLayout(UniversalGraph ug) { + CompoundDirectedGraph dg = new CompoundDirectedGraph(); + CompoundDirectedGraphLayout layout = new CompoundDirectedGraphLayout(); + NodeList nodeList = dg.nodes; + EdgeList edgeList = dg.edges; + + Map idx2graph = new HashMap<>(); + Subgraph base = new Subgraph(0); + idx2graph.put(0, base); + base.insets=getInsets(); + for(LoopInfo info : scene.getCfgEnv().getLoopMap().values()){ + Subgraph subg = new Subgraph(info.getLoopIndex()); + subg.insets=getInsets(); + idx2graph.put(info.getLoopIndex(), subg); + } + + for(CfgNode n : scene.getCfgEnv().getNodes() ) { + Widget nodeWidget = scene.findWidget(n); + Node node = new Node(n); + node.width=nodeWidget.getBounds().width; + node.height = nodeWidget.getBounds().height; + node.setPadding(new Insets(PADDING, PADDING, PADDING, PADDING)); + Subgraph subg = idx2graph.get(n.getLoopIndex()); + assert(subg != null); + node.setParent(subg); + subg.addMember(node); + nodeList.add(node); + + } + nodeList.addAll(idx2graph.values()); + for(LoopInfo info : scene.getCfgEnv().getLoopMap().values()){ + Subgraph subg = idx2graph.get(info.getLoopIndex()); + if(info.getParent() != null){ + Subgraph parentsubg = idx2graph.get(info.getParent().getLoopIndex()); + Edge edge = new Edge(parentsubg, subg); + parentsubg.addMember(subg); + subg.setParent(parentsubg); + edgeList.add(edge); + } + } + for(CfgEdge e : scene.getCfgEnv().getEdges() ) { + if(e.isBackEdge()) continue; + Edge edge = new Edge(e, nodeList.getNode(e.getSourceNode().getNodeIndex()), nodeList.getNode(e.getTargetNode().getNodeIndex())); + edgeList.add(edge); + } + layout.visit(dg); + + for(Object obj : dg.nodes){ + Node n = (Node) obj; + if(n.data instanceof CfgNode){ + CfgNode cfgNode = (CfgNode) n.data; + Point pos = new Point(n.x + LEFT_BORDER, n.y + TOP_BORDER); + Point scenepos = scene.convertLocalToScene(pos); + this.setResolvedNodeLocation(ug, cfgNode, scenepos); + } + } + } + + @Override + protected void performNodesLayout(UniversalGraph ug, Collection collection) { + } + + private Insets getInsets(){ + return new Insets(INSET, INSET, INSET, INSET); + } + +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/layout/HierarchicalNodeLayout.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/layout/HierarchicalNodeLayout.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,69 @@ +package at.ssw.visualizer.cfg.graph.layout; + +import at.ssw.visualizer.cfg.graph.CfgScene; +import at.ssw.visualizer.cfg.model.CfgEdge; +import at.ssw.visualizer.cfg.model.CfgNode; +import java.awt.Point; +import java.util.Collection; +import org.netbeans.api.visual.graph.layout.GraphLayout; +import org.netbeans.api.visual.graph.layout.UniversalGraph; +import org.eclipse.draw2d.graph.DirectedGraph; +import org.eclipse.draw2d.graph.DirectedGraphLayout; +import org.eclipse.draw2d.graph.Edge; +import org.eclipse.draw2d.graph.EdgeList; +import org.eclipse.draw2d.graph.Node; +import org.eclipse.draw2d.graph.NodeList; +import org.netbeans.api.visual.widget.Widget; + + +public class HierarchicalNodeLayout extends GraphLayout { + + private static final int TOP_BORDER = 20; + private static final int LEFT_BORDER = 40; + + private CfgScene scene; + + public HierarchicalNodeLayout(CfgScene scene){ + this.scene = scene; + } + + @Override + protected void performGraphLayout(UniversalGraph ug) { + DirectedGraph dg = new DirectedGraph(); + DirectedGraphLayout layout = new DirectedGraphLayout(); + + NodeList nodeList = dg.nodes; + EdgeList edgeList = dg.edges; + + for(CfgNode n : scene.getCfgEnv().getNodes() ) { + Widget nodeWidget = scene.findWidget(n); + Node node = new Node(n); + node.width=nodeWidget.getBounds().width; + node.height = nodeWidget.getBounds().height; + nodeList.add(node); + } + + for(CfgEdge e : scene.getCfgEnv().getEdges() ) { + if(e.isBackEdge()) continue; + Edge edge = new Edge(e, nodeList.getNode(e.getSourceNode().getNodeIndex()), + nodeList.getNode(e.getTargetNode().getNodeIndex())); + edgeList.add(edge); + } + + layout.visit(dg); + + for(Object obj : dg.nodes){ + Node n = (Node) obj; + CfgNode cfgNode = (CfgNode) n.data; + Point pos = new Point(n.x + LEFT_BORDER , n.y + TOP_BORDER); + Point scenepos = scene.convertLocalToScene(pos); + setResolvedNodeLocation(ug, cfgNode, scenepos); + } + + } + + @Override + protected void performNodesLayout(UniversalGraph ug, Collection collection) { + } + +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/Icons.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/Icons.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,18 @@ +package at.ssw.visualizer.cfg.icons; + +/** + * + * @author Christian Wimmer + */ +public class Icons { + private static final String PATH = "at/ssw/visualizer/cfg/icons/"; + + public static final String CFG = PATH + "cfg.gif"; + + public static final String ICON_ZOOMIN = PATH + "zoomin.gif"; + public static final String ICON_ZOOMOUT = PATH + "zoomout.gif"; + public static final String ICON_DEFAULT = PATH + "arrangebfs.gif"; + + private Icons() { + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/arrangebfs.gif Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/arrangebfs.gif has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/arrangehier.gif Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/arrangehier.gif has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/arrangeloop.gif Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/arrangeloop.gif has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/autosize.gif Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/autosize.gif has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/autosize_selection.gif Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/autosize_selection.gif has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/bezierrouter.gif Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/bezierrouter.gif has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/cfg.gif Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/cfg.gif has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/cfg32.gif Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/cfg32.gif has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/cluster.gif Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/cluster.gif has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/color.gif Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/color.gif has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/combine.gif Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/combine.gif has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/combine_disabled.gif Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/combine_disabled.gif has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/disk.gif Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/disk.gif has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/fanrouter.gif Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/fanrouter.gif has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/hideedges.gif Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/hideedges.gif has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/hideedges_disabled.gif Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/hideedges_disabled.gif has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/manhattanrouter.gif Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/manhattanrouter.gif has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/showedges.gif Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/showedges.gif has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/showedges_disabled.gif Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/showedges_disabled.gif has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/split.gif Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/split.gif has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/split_disabled.gif Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/split_disabled.gif has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/zoomin.gif Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/zoomin.gif has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/zoomout.gif Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/zoomout.gif has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/layer.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/layer.xml Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/CfgEdge.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/CfgEdge.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,10 @@ +package at.ssw.visualizer.cfg.model; + +public interface CfgEdge { + public CfgNode getSourceNode(); + public CfgNode getTargetNode(); + public boolean isXhandler(); + public boolean isBackEdge(); + public boolean isSymmetric(); + public boolean isReflexive(); +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/CfgEdgeImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/CfgEdgeImpl.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,50 @@ +package at.ssw.visualizer.cfg.model; + +public class CfgEdgeImpl implements CfgEdge { + private CfgNodeImpl sourceNode; + private CfgNodeImpl targetNode; + private boolean symmetric; + private boolean backedge; + + public CfgEdgeImpl(CfgNodeImpl sourceNode, CfgNodeImpl targetNode) { + this.sourceNode = sourceNode; + this.targetNode = targetNode; + } + + public void setSymmetric(boolean symmetric){ + this.symmetric = symmetric; + } + + public void setBackEdge(boolean isBackedge){ + this.backedge = isBackedge; + } + + public CfgNode getSourceNode() { + return sourceNode; + } + + public CfgNode getTargetNode() { + return targetNode; + } + + public boolean isBackEdge() { + return this.backedge; + } + + public boolean isSymmetric() { + return symmetric; + } + + public boolean isReflexive() { + return sourceNode==targetNode; + } + + public boolean isXhandler() { + return sourceNode.getBasicBlock().getXhandlers().contains(targetNode.getBasicBlock()); + } + + @Override + public String toString(){ + return this.sourceNode.getBasicBlock().getName() + "->" + targetNode.getBasicBlock().getName(); + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/CfgEnv.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/CfgEnv.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,297 @@ +package at.ssw.visualizer.cfg.model; + +import at.ssw.visualizer.model.cfg.BasicBlock; +import at.ssw.visualizer.model.cfg.ControlFlowGraph; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Queue; +import java.util.Set; + + +/** + * This is the container class for the data model, + * it prepares creates nodes and edges for the CfgScene + * from a ControlFlowGraph of the Compilation Model + */ +public class CfgEnv { + private ControlFlowGraph cfg; + private Map loopMap;//maps: LoopHeader --> LoopInfo + private CfgNodeImpl[] nodeArr; + private CfgEdgeImpl[] edgeArr; + + public CfgEnv(ControlFlowGraph cfg) { + 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<>(); + List blocks = cfg.getBasicBlocks(); + //create nodes + for(int idx=0 ; idx < blockCount ; idx++) { + BasicBlock b = blocks.get(idx); + + String description = "Name: " + b.getName() + "\n"; + description += "BCI: [" + b.getFromBci() + "," + b.getToBci() + "]\n"; + if (b.getLoopDepth() > 0) { + description += "Loop " + b.getLoopIndex() + " Depth " + b.getLoopDepth() + "\n"; + } + description += "Predecessors: " + getBlockList(b.getPredecessors()) + "\n"; + description += "Successors: " + getBlockList(b.getSuccessors()) + "\n"; + description += "XHandlers: " + getBlockList(b.getXhandlers()); + if (b.getDominator() != null) { + description += "\nDominator: " + b.getDominator().getName(); + } + nodes[idx] = new CfgNodeImpl(b, idx, description); + block2nodeMap.put(b, nodes[idx]); + } + + + //create edges + 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<>(); + + Set successors = new HashSet<>(); + successors.addAll(b.getSuccessors()); + successors.addAll(b.getXhandlers()); + for(BasicBlock sb : successors) { + CfgNodeImpl succNode = block2nodeMap.get(sb); + CfgEdgeImpl edge = new CfgEdgeImpl(nodes[i], succNode); + if(cache.contains(edge.toString())) + continue; + cache.add(edge.toString()); + //check for symtric edges + if(sb.getXhandlers().contains(b) || sb.getSuccessors().contains(b)) + edge.setSymmetric(true); + outputEdges.add(edge); + } + allEdges.addAll(outputEdges); + nodes[i].setOutputEdges(outputEdges.toArray(new CfgEdgeImpl[outputEdges.size()])); + } + + for(CfgEdgeImpl e: allEdges) { + //CfgNodeImpl src = (CfgNodeImpl) e.getSourceNode(); + CfgNodeImpl tar = (CfgNodeImpl) e.getTargetNode(); + Set set = inputMap.get(tar); + if( set == null) { + set = new HashSet<>(); + set.add(e); + inputMap.put(tar, set); + } + set.add(e); + } + for(CfgNodeImpl n : nodes){ + Set inputEdges = inputMap.get(n); + if(inputEdges == null) continue; + n.setInputEdges(inputEdges.toArray(new CfgEdgeImpl[inputEdges.size()])); + } + CfgEdgeImpl[] edges = allEdges.toArray(new CfgEdgeImpl[allEdges.size()]); + this.edgeArr=edges; + this.nodeArr=nodes; + CfgNodeImpl rootNode = nodeArr[0]; + setNodeLevels(rootNode); + indexLoops(rootNode); + + } + + + private String getBlockList(List blocks) { + if (blocks.size() == 0) { + return "None"; + } + StringBuilder sb = new StringBuilder(); + String prefix = ""; + for (BasicBlock b : blocks) { + sb.append(prefix).append(b.getName()); + prefix = ", "; + } + return sb.toString(); + } + + + public CfgNode[] getNodes(){ + return this.nodeArr; + } + + public CfgEdge[] getEdges(){ + return this.edgeArr; + } + + public Map getLoopMap() { + return loopMap; + } + + public void setLoopMap(Map loopMap) { + this.loopMap = loopMap; + } + + private void indexLoops(CfgNodeImpl rootNode){ + LoopEnv env = new LoopEnv(Arrays.asList(nodeArr)); + loopDetection(env, rootNode); + calcLoopDepth(env); + + int loopIndex=1; + + for(LoopInfo info : env.loopMap.values()) { + info.setLoopIndex(loopIndex++); + info.setLoopDepth(info.getHeader().getLoopDepth()); + for(CfgNode n : info.getMembers()){ + if(n.getLoopDepth()>info.getLoopDepth()) continue; + CfgNodeImpl ni = (CfgNodeImpl) n; + ni.setLoopDepth(info.getLoopDepth()); + ni.setLoopIndex(info.getLoopIndex()); + } + } + + for(LoopInfo info : env.loopMap.values()) { + HashSet members = new HashSet<>(info.getMembers()); + members.remove(info.getHeader());//remove own header + for(CfgNode n: members){ + if(n.isLoopHeader()) { + LoopInfo memberInfo = env.loopMap.get(n); + if (info.getLoopDepth() == memberInfo.getLoopDepth()-1) + memberInfo.setParent(info); + } + } + } + this.loopMap = env.loopMap; + } + + + private class LoopEnv { + Set allNodes; + Set activeNodes; + Set visitedNodes; + Map loopMap; + 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<>(); + } + + public int getLoopIndex(){ + return ++loopIndex; + } + } + + + private void loopDetection(LoopEnv env, CfgNodeImpl root) { + for (CfgNodeImpl n : env.allNodes) { + n.setLoopHeader(false); + for (CfgEdge e : n.getInputEdges()) { + CfgEdgeImpl ei = (CfgEdgeImpl) e; + ei.setBackEdge(false); + } + } + visit(env, root, null); + } + + + + private void visit(LoopEnv env, CfgNodeImpl n, CfgEdgeImpl e) { + if (env.activeNodes.contains(n)) { + // This node is b loop header! + n.setLoopHeader(true); + e.setBackEdge(true); + } else if (!env.visitedNodes.contains(n)) { + env.visitedNodes.add(n); + env.activeNodes.add(n); + + for (CfgEdge edge : n.getOutputEdges()) { + if(!edge.getTargetNode().isOSR()) { + CfgEdgeImpl ei = (CfgEdgeImpl) edge; + CfgNodeImpl ni = (CfgNodeImpl) edge.getTargetNode(); + visit(env, ni, ei); + } + } + env.activeNodes.remove(n); + } + } + + + + private void calcLoopDepth(LoopEnv env) { + for (CfgNodeImpl n : env.allNodes) { + env.visitedNodes.clear(); + + if (n.isLoopHeader()) { + LoopInfo loop = new LoopInfo(); + loop.setHeader(n); + n.setLoopIndex(env.getLoopIndex()); + HashSet members = new HashSet<>(); + loop.setMembers(members); + members.add(n); + env.loopMap.put(loop.getHeader(), loop); + int loopDepth = n.getLoopDepth() + 1; + loop.setLoopDepth(loopDepth); + n.setLoopDepth(loopDepth); + for (CfgEdge e : n.getInputEdges()) { + if (e.isBackEdge() && !e.getSourceNode().isOSR()) { + CfgNodeImpl src = (CfgNodeImpl) e.getSourceNode(); + backwardIteration(env, n, src, loop); + loop.getBackEdges().add(e); + } + } + } + } + } + + + private void backwardIteration(LoopEnv env, CfgNodeImpl endNode, CfgNodeImpl n, LoopInfo loop) { + if (endNode != n && !env.visitedNodes.contains(n)) { + env.visitedNodes.add(n); + + for (CfgEdge e : n.getInputEdges()) { + if (!e.getSourceNode().isOSR()) { + CfgNodeImpl src = (CfgNodeImpl) e.getSourceNode(); + backwardIteration(env, endNode, src, loop); + } + } + loop.getMembers().add(n); + n.setLoopDepth(n.getLoopDepth() + 1); + } + } + + private void setNodeLevels(CfgNode rootNode){ + Set cache = new HashSet<>(); + Queue queue = new LinkedList<>(); + queue.add(rootNode); + cache.add(rootNode); + int level=0; + int[] nodeCount = new int[2]; + nodeCount[0]=1; + while(!queue.isEmpty()){ + CfgNodeImpl curNode = (CfgNodeImpl) queue.poll(); + curNode.setLevel(level); + nodeCount[0]--; + for(CfgEdge outEdge : curNode.getOutputEdges()) { + CfgNode succNode = outEdge.getTargetNode(); + if(cache.contains(succNode)) continue; + cache.add(succNode); + queue.add(succNode); + nodeCount[1]++; + } + if(nodeCount[0]==0){ + nodeCount[0]=nodeCount[1]; + nodeCount[1]=0; + level++; + } + } + } + + public ControlFlowGraph getCfg() { + return cfg; + } + +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/CfgNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/CfgNode.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,23 @@ +package at.ssw.visualizer.cfg.model; + +import at.ssw.visualizer.model.cfg.BasicBlock; + + +public interface CfgNode { + //testers + public boolean isOSR(); + public boolean isRoot(); + public boolean isLoopHeader(); + public boolean isLoopMember(); + + //getters + public int getLevel(); + public int getLoopDepth(); + public int getLoopIndex(); + public int getNodeIndex(); + public CfgEdge[] getInputEdges(); + public CfgEdge[] getOutputEdges(); + public BasicBlock getBasicBlock(); + public String getDescription(); + +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/CfgNodeImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/CfgNodeImpl.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,133 @@ +package at.ssw.visualizer.cfg.model; + +import at.ssw.visualizer.model.cfg.BasicBlock; +import java.awt.Color; + + + +public class CfgNodeImpl implements CfgNode { + private int nodeIndex; + private BasicBlock basicBlock; + private int level; + private int loopDepth=0; + private int loopIndex=0; + private boolean osr=false; + private CfgNodeImpl dominator=null; + private CfgEdgeImpl[] inputEdges = new CfgEdgeImpl[0]; + private CfgEdgeImpl[] outputEdges = new CfgEdgeImpl[0]; + private String description; + private Color customColor=null; + private boolean loopHeader; + + public CfgNodeImpl(BasicBlock bb, int nodeIndex, String description) { + this.basicBlock = bb; + this.nodeIndex = nodeIndex; + this.description = description; + + if (bb.getPredecessors().size() == 1) { + BasicBlock pred = bb.getPredecessors().get(0); + boolean isStd = pred.getPredecessors().size() == 0; + if (isStd) { + for (String s : bb.getFlags()) { + if (s.equals("osr")) { + osr = true; + break; + } + } + } + } + } + + public int getNodeIndex() { + return nodeIndex; + } + + + public void setDominator(CfgNodeImpl dominator) { + this.dominator = dominator; + } + + public void setLevel(int level) { + this.level = level; + } + + public void setLoopDepth(int loopDepth) { + this.loopDepth = loopDepth; + } + + public void setLoopHeader(boolean loopHeader) { + this.loopHeader = loopHeader; + } + + public void setLoopIndex(int loopIndex) { + this.loopIndex = loopIndex; + } + + public void setNodeIndex(int nodeIndex) { + this.nodeIndex = nodeIndex; + } + + public boolean isRoot() { + return nodeIndex==0; + } + + public boolean isLoopHeader() { + return loopHeader; + } + + public boolean isLoopMember() { + return loopIndex > 0; + } + + public int getLevel() { + return level; + } + + public BasicBlock getBasicBlock() { + return basicBlock; + } + + public int getLoopDepth() { + return loopDepth; + } + + public int getLoopIndex() { + return loopIndex; + } + + public boolean isOSR() { + return osr; + } + + @Override + public String toString(){ + return basicBlock.getName(); + } + + public void setInputEdges(CfgEdgeImpl[] inputEdges){ + this.inputEdges = inputEdges; + } + + + public void setOutputEdges(CfgEdgeImpl[] outputEdges){ + this.outputEdges = outputEdges; + } + + public CfgEdge[] getInputEdges() { + return this.inputEdges; + } + + public CfgEdge[] getOutputEdges() { + return outputEdges; + } + + public String getDescription() { + return description; + } + + public void setColor(Color color) { + this.customColor=color; + } + + +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/LoopInfo.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/LoopInfo.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,67 @@ +package at.ssw.visualizer.cfg.model; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + + +public class LoopInfo { + private CfgNode header;//the target node of the backedge + private int loopIndex; //index of the min cycleSet + private int loopDepth; //nested depth >=1 + private LoopInfo parent=null; + private Set members; + private List backEdges = new ArrayList<>();//dfs backEdge + + protected void setLoopDepth(int depth) { + this.loopDepth=depth; + } + + protected void setLoopIndex(int loopIndex) { + this.loopIndex = loopIndex; + } + + public int getLoopDepth() { + return loopDepth; + } + + public Set getMembers() { + return members; + } + + protected void setMembers(Set members) { + this.members = members; + } + + public int getLoopIndex() { + return loopIndex; + } + + protected void setParent(LoopInfo parent) { + this.parent = parent; + } + + public LoopInfo getParent(){ + return parent; + } + + public List getBackEdges() { + return backEdges; + } + + public CfgNode getHeader() { + return header; + } + + protected void setHeader(CfgNode header) { + this.header = header; + } + + @Override + public String toString(){ + return "Loop(" + header.toString()+ ")-->" + members.toString(); + } + + + +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/CFGOptionsCategory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/CFGOptionsCategory.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,32 @@ +package at.ssw.visualizer.cfg.preferences; + +import javax.swing.Icon; +import javax.swing.ImageIcon; +import org.netbeans.spi.options.OptionsCategory; +import org.netbeans.spi.options.OptionsPanelController; +import org.openide.util.ImageUtilities; + +/** + * Descriptor for the settings page displayed in the options dialog. + * + * @author Bernhard Stiftner + */ +public class CFGOptionsCategory extends OptionsCategory { + + public OptionsPanelController create() { + return new CFGOptionsPanelController(); + } + + public String getCategoryName() { + return "Control Flow Graph"; + } + + @Override + public Icon getIcon() { + return new ImageIcon(ImageUtilities.loadImage("at/ssw/visualizer/cfg/icons/cfg32.gif")); + } + + public String getTitle() { + return "CFG Visualizer"; + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/CFGOptionsPanel.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/CFGOptionsPanel.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,482 @@ +package at.ssw.visualizer.cfg.preferences; + +import java.awt.Color; +import java.awt.Font; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.List; +import javax.swing.AbstractAction; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.SwingConstants; + +/** + * The actual component for changing the CFG visualizer settings. + * + * @author Bernhard Stiftner + * @author Rumpfhuber Stefan + */ +public class CFGOptionsPanel extends JPanel { + + List elements = new ArrayList<>(); + + /** Creates a new instance of CFGOptionsPanel */ + public CFGOptionsPanel() { + setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + JPanel cfgPanel = new JPanel(new GridBagLayout()); + + // color/font settings + addColorChooser(cfgPanel, "Background color: ", new ColorChooser(CfgPreferences.PROP_BACKGROUND_COLOR){ + @Override + public void apply() { + CfgPreferences.getInstance().setBackgroundColor(getColor()); + } + + @Override + public void update() { + this.originalColor = CfgPreferences.getInstance().getBackgroundColor(); + setColor(this.originalColor); + } + + public void reset() { + this.setColor(CfgPreferencesDefaults.DEFAULT_BACKGROUND_COLOR); + } + + + + }); + addColorChooser(cfgPanel, "Back edge color: ", new ColorChooser(CfgPreferences.PROP_BACK_EDGE_COLOR){ + + @Override + public void apply() { + CfgPreferences.getInstance().setBackedgeColor(getColor()); + } + + @Override + public void update() { + this.originalColor = CfgPreferences.getInstance().getBackedgeColor(); + this.setColor(this.originalColor); + + } + + public void reset() { + this.setColor(CfgPreferencesDefaults.DEFAULT_BACKEDGE_COLOR); + } + }); + addColorChooser(cfgPanel, "Edge color: ", new ColorChooser(CfgPreferences.PROP_EDGE_COLOR){ + + @Override + public void apply() { + CfgPreferences.getInstance().setEdgeColor(getColor()); + } + + @Override + public void update() { + this.originalColor = CfgPreferences.getInstance().getEdgeColor(); + setColor(this.originalColor); + } + + public void reset() { + this.setColor(CfgPreferencesDefaults.DEFAULT_EDGE_COLOR); + } + + }); + addColorChooser(cfgPanel, "Exception edge color: ", new ColorChooser(CfgPreferences.PROP_EXCEPTION_EDGE_COLOR){ + + @Override + public void apply() { + CfgPreferences.getInstance().setExceptionEdgeColor(getColor()); + } + + @Override + public void update() { + this.originalColor = CfgPreferences.getInstance().getExceptionEdgeColor(); + setColor(this.originalColor); + + } + + public void reset() { + this.setColor(CfgPreferencesDefaults.DEFAULT_EXCEPTIONEDGE_COLOR); + } + }); + addColorChooser(cfgPanel, "Node color: ", new ColorChooser(CfgPreferences.PROP_NODE_COLOR){ + + @Override + public void apply() { + CfgPreferences.getInstance().setNodeColor(getColor()); + } + + @Override + public void update() { + this.originalColor = CfgPreferences.getInstance().getNodeColor(); + setColor(this.originalColor); + + } + + public void reset() { + this.setColor(CfgPreferencesDefaults.DEFAUT_NODE_COLOR); + } + }); + addColorChooser(cfgPanel, "Text color: ", new ColorChooser(CfgPreferences.PROP_TEXT_COLOR){ + + @Override + public void apply() { + CfgPreferences.getInstance().setTextColor(getColor()); + } + + @Override + public void update() { + this.originalColor = CfgPreferences.getInstance().getTextColor(); + + } + + public void reset() { + this.setColor(CfgPreferencesDefaults.DEFAULT_TEXT_COLOR); + } + }); + addColorChooser(cfgPanel, "Border color: ", new ColorChooser(CfgPreferences.PROP_BORDER_COLOR){ + + @Override + public void apply() { + CfgPreferences.getInstance().setBorderColor(getColor()); + } + + @Override + public void update() { + this.originalColor = CfgPreferences.getInstance().getBorderColor(); + setColor(this.originalColor); + + } + public void reset() { + this.setColor(CfgPreferencesDefaults.DEFAULT_BORDER_COLOR); + } + }); + addColorChooser(cfgPanel, "Selected Nodes color: ", new ColorChooser(CfgPreferences.PROP_SELECTION_COLOR_FG){ + + @Override + public void apply() { + CfgPreferences.getInstance().setSelectionColorForeground(getColor()); + } + + @Override + public void update() { + this.originalColor = CfgPreferences.getInstance().getSelectionColorForeground(); + setColor(this.originalColor); + } + + public void reset() { + this.setColor(CfgPreferencesDefaults.DEFAULT_SELECTION_COLOR_FOREGROUND); + } + }); + addColorChooser(cfgPanel, "Selection Rect color: ", new ColorChooser(CfgPreferences.PROP_SELECTION_COLOR_BG){ + + @Override + public void apply() { + CfgPreferences.getInstance().setSelectionColorBackground(getColor()); + } + + @Override + public void update() { + this.originalColor = CfgPreferences.getInstance().getSelectionColorBackground(); + setColor(this.originalColor); + } + + public void reset() { + this.setColor(CfgPreferencesDefaults.DEFAULT_SELECTION_COLOR_BACKGROUND); + } + }); + addFontChooser(cfgPanel, "Text font: ", new FontChooser(CfgPreferences.PROP_TEXT_FONT){ + + @Override + public void apply() { + CfgPreferences.getInstance().setTextFont(getSelectedFont()); + } + + @Override + public void update() { + this.originalFont = CfgPreferences.getInstance().getTextFont(); + this.setSelectedFont(originalFont); + + } + + public void reset() { + this.setSelectedFont(CfgPreferencesDefaults.DEFAULT_TEXT_FONT); + } + }); + + // flags editor + addFlagsEditor(cfgPanel, "Flags: "); + add(cfgPanel); + + // add update button + Box hBox = new Box(BoxLayout.X_AXIS); + hBox.add(new JButton(new ResetAction())); + hBox.add(Box.createHorizontalGlue()); + add(hBox); + + add(Box.createVerticalGlue()); + } + + public void update() { + for (ConfigurationElement e : elements) { + e.update(); + } + } + + public void cancel() { + for (ConfigurationElement e : elements) { + e.update(); + } + } + + public void applyChanges() { + for (ConfigurationElement e : elements) { + if(e.isChanged()) + e.apply(); + } + } + + public boolean isDataValid() { + return true; + } + + public boolean isChanged() { + for (ConfigurationElement e : elements) { + if (e.isChanged()) { + return true; + } + } + return false; + } + + public void loadDefault() { + for (ConfigurationElement e : elements) { + e.reset(); + } + } + + private void addColorChooser(JComponent c, String displayName, ColorChooser chooser) { + GridBagLayout layout = (GridBagLayout)c.getLayout(); + GridBagConstraints constraints = new GridBagConstraints(); + constraints.insets = new Insets(3, 3, 3, 3); + constraints.weightx = 0.0; + constraints.fill = GridBagConstraints.NONE; + constraints.anchor = GridBagConstraints.EAST; + JLabel label = new JLabel(displayName, JLabel.TRAILING); + layout.setConstraints(label, constraints); + c.add(label); + constraints.anchor = GridBagConstraints.WEST; + constraints.gridwidth = GridBagConstraints.REMAINDER; + layout.setConstraints(chooser, constraints); + c.add(chooser); + elements.add(chooser); + label.setLabelFor(chooser); + } + + + + private void addFontChooser(JComponent c, String displayName, FontChooser chooser) { + GridBagLayout layout = (GridBagLayout)c.getLayout(); + GridBagConstraints constraints = new GridBagConstraints(); + constraints.insets = new Insets(3, 3, 3, 3); + constraints.weightx = 0.0; + constraints.fill = GridBagConstraints.NONE; + constraints.anchor = GridBagConstraints.EAST; + JLabel label = new JLabel(displayName, JLabel.TRAILING); + layout.setConstraints(label, constraints); + c.add(label); + constraints.insets = new Insets(3, 3, 3, 1); + constraints.weightx = 1.0; + constraints.fill = GridBagConstraints.HORIZONTAL; + constraints.anchor = GridBagConstraints.CENTER; + layout.setConstraints(chooser.getPreview(), constraints); + c.add(chooser.getPreview()); + constraints.insets = new Insets(3, 1, 3, 3); + constraints.weightx = 0.0; + constraints.fill = GridBagConstraints.NONE; + constraints.anchor = GridBagConstraints.EAST; + constraints.gridwidth = GridBagConstraints.REMAINDER; + layout.setConstraints(chooser.getButton(), constraints); + c.add(chooser.getButton()); + elements.add(chooser); + label.setLabelFor(chooser.getButton()); + } + + private void addFlagsEditor(JComponent c, String displayName) { + GridBagLayout layout = (GridBagLayout)c.getLayout(); + GridBagConstraints constraints = new GridBagConstraints(); + constraints.insets = new Insets(3, 3, 3, 3); + constraints.weightx = 0.0; + constraints.fill = GridBagConstraints.NONE; + constraints.anchor = GridBagConstraints.NORTHEAST; + FlagsEditor flagsEditor = new FlagsEditor(); + JLabel flagsLabel = new JLabel(displayName, JLabel.TRAILING); + flagsLabel.setVerticalAlignment(SwingConstants.TOP); + layout.setConstraints(flagsLabel, constraints); + c.add(flagsLabel); + constraints.weightx = 1.0; + constraints.weighty = 1.0; + constraints.fill = GridBagConstraints.BOTH; + constraints.anchor = GridBagConstraints.CENTER; + constraints.gridwidth = GridBagConstraints.REMAINDER; + layout.setConstraints(flagsEditor, constraints); + c.add(flagsEditor); + elements.add(flagsEditor); + flagsLabel.setLabelFor(flagsEditor); + } + + + + + interface ConfigurationElement { + + public boolean isChanged(); + + //apply changes to preferences + public void apply(); + + //optain current value from preferences + public void update(); + + //reset to default value + public void reset(); + + } + + abstract class ColorChooser extends ColorChooserButton implements ConfigurationElement { + + Color originalColor;//the color before any change + String propertyName; + + public ColorChooser(String propertyName) { + this.propertyName = propertyName; + } + + public boolean isChanged() { + return !originalColor.equals(getColor()); + } + + + public abstract void apply(); + public abstract void update(); + + } + + + abstract class FontChooser implements ConfigurationElement, ActionListener { + + Font originalFont; + Font selectedFont; + String propertyName; + JTextField preview; + JButton button; + + public FontChooser(String propertyName) { + this.propertyName = propertyName; + preview = new JTextField(""); + preview.setEditable(false); + button = new JButton("..."); + button.setMargin(new Insets(0, 0, 0, 0)); + button.addActionListener(this); + } + + public boolean isChanged() { + return !originalFont.equals(selectedFont); + } + + public abstract void apply(); + + public abstract void update(); + + public abstract void reset(); + + public JTextField getPreview() { + return preview; + } + + public JButton getButton() { + return button; + }; + + public Font getSelectedFont() { + return selectedFont; + } + + public void setSelectedFont(Font f) { + selectedFont = f; + preview.setText(fontToString(f)); + preview.revalidate(); + } + + public void actionPerformed(ActionEvent e) { + setSelectedFont(FontChooserDialog.show(selectedFont)); + } + + public String fontToString(Font font) { + StringBuffer sb = new StringBuffer(); + sb.append(font.getName()); + sb.append(" "); + sb.append(font.getSize()); + if (font.isBold()) { + sb.append(" bold"); + } + if (font.isItalic()) { + sb.append(" italic"); + } + return sb.toString(); + } + + } + + class FlagsEditor extends FlagsEditorPanel implements ConfigurationElement { + + FlagsSetting originalFlags; + + public FlagsEditor() { + super(null); + } + + public boolean isChanged() { + return !originalFlags.getFlagString().equals(getFlagString()); + } + + public void apply() { + CfgPreferences.getInstance().setFlagsSetting(new FlagsSetting(getFlagString())); + update(); + } + + public void update() { + originalFlags = CfgPreferences.getInstance().getFlagsSetting(); + setFlagString(originalFlags.getFlagString()); + } + + public void reset() { + FlagsSetting defaultFlags = new FlagsSetting(CfgPreferencesDefaults.DEFAULT_FLAGSTRING); + setFlagString(defaultFlags.getFlagString()); + colorButton.setColor(getParent().getBackground()); + } + + } + + class ResetAction extends AbstractAction { + + public ResetAction() { + super("Reset"); + } + + public void actionPerformed(ActionEvent e) { + CFGOptionsPanel.this.loadDefault(); + } + + } + +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/CFGOptionsPanelController.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/CFGOptionsPanelController.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,63 @@ +package at.ssw.visualizer.cfg.preferences; + +import java.beans.PropertyChangeListener; +import javax.swing.JComponent; +import org.netbeans.spi.options.OptionsPanelController; +import org.openide.util.HelpCtx; +import org.openide.util.Lookup; + +/** + * Controller for the settings page displayed in the options dialog. + * + * @author Bernhard Stiftner + */ +public class CFGOptionsPanelController extends OptionsPanelController { + + CFGOptionsPanel optionsPanel; + + + public void update() { + getOptionsPanel().update(); + } + + public void applyChanges() { + getOptionsPanel().applyChanges(); + } + + public void cancel() { + getOptionsPanel().cancel(); + } + + public boolean isValid() { + return getOptionsPanel().isDataValid(); + } + + public boolean isChanged() { + return getOptionsPanel().isChanged(); + } + + public JComponent getComponent(Lookup masterLookup) { + return getOptionsPanel(); + } + + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + public void addPropertyChangeListener(PropertyChangeListener l) { + getOptionsPanel().addPropertyChangeListener(l); + } + + //todo: investigate - who removes the changelistener ? + public void removePropertyChangeListener(PropertyChangeListener l) { + getOptionsPanel().removePropertyChangeListener(l); + } + + private CFGOptionsPanel getOptionsPanel() { + if (optionsPanel == null) { + optionsPanel = new CFGOptionsPanel(); + } + return optionsPanel; + } + +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/CfgPreferences.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/CfgPreferences.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,239 @@ +package at.ssw.visualizer.cfg.preferences; + +import java.awt.Color; +import java.awt.Font; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.prefs.Preferences; +import javax.swing.event.EventListenerList; +import org.openide.util.NbPreferences; + +/** + * Replacement for old CFGSettings to remove dependency on deprecated SystemOption package + * + * @author Rumpfhuber Stefan + */ +public class CfgPreferences { + public static final String PROP_FLAGS = "flagsPreference"; + public static final String PROP_TEXT_FONT = "textFontPreference"; + public static final String PROP_TEXT_COLOR = "textColorPreference"; + public static final String PROP_NODE_COLOR = "nodeColorPreference"; + public static final String PROP_EDGE_COLOR = "edgeColorPreference"; + public static final String PROP_BORDER_COLOR = "borderColorPreference"; + public static final String PROP_BACK_EDGE_COLOR = "backEdgeColorPreference"; + public static final String PROP_BACKGROUND_COLOR = "backgroundColorPreference"; + public static final String PROP_SELECTION_COLOR_FG = "selectionColorFgPreference"; + public static final String PROP_SELECTION_COLOR_BG = "selectionColorBgPreference"; + public static final String PROP_EXCEPTION_EDGE_COLOR = "exceptionEdgeColorPreference"; + + private static final String PROP_FONTNAME = "_FontFamily"; + private static final String PROP_FONTSIZE = "_FontSize"; + private static final String PROP_FONTSTYLE = "_FontStyle"; + + protected static final String nodeName = "CfgPreferences"; + + private static CfgPreferences instance = new CfgPreferences(); + private EventListenerList listenerList; + + private FlagsSetting flagsSetting; + private Color node_color; + private Color background_color; + private Color backedge_color; + private Color edge_color; + private Color border_color; + private Color exceptionEdgeColor; + private Color text_color; + private Font text_font; + private Color selection_color_fg; + private Color selection_color_bg; + + + private CfgPreferences(){ + listenerList = new EventListenerList(); + init(); + } + + public static CfgPreferences getInstance(){ + return instance; + } + + protected final Preferences getPreferences() { + return NbPreferences.forModule(this.getClass()).node("options").node(nodeName); + } + + + protected void init(){ + Preferences prefs = this.getPreferences(); + String flagString = prefs.get(PROP_FLAGS, CfgPreferencesDefaults.DEFAULT_FLAGSTRING); + flagsSetting = new FlagsSetting(flagString); + node_color = this.getColorProperty(PROP_NODE_COLOR, CfgPreferencesDefaults.DEFAUT_NODE_COLOR); + background_color = this.getColorProperty(PROP_BACKGROUND_COLOR, CfgPreferencesDefaults.DEFAULT_BACKGROUND_COLOR); + backedge_color = this.getColorProperty(PROP_BACK_EDGE_COLOR, CfgPreferencesDefaults.DEFAULT_BACKEDGE_COLOR); + edge_color = this.getColorProperty(PROP_EDGE_COLOR, CfgPreferencesDefaults.DEFAULT_EDGE_COLOR); + selection_color_fg= this.getColorProperty(PROP_SELECTION_COLOR_FG, CfgPreferencesDefaults.DEFAULT_SELECTION_COLOR_FOREGROUND); + border_color = this.getColorProperty(PROP_BORDER_COLOR, CfgPreferencesDefaults.DEFAULT_BORDER_COLOR); + exceptionEdgeColor = this.getColorProperty(PROP_EXCEPTION_EDGE_COLOR, CfgPreferencesDefaults.DEFAULT_EXCEPTIONEDGE_COLOR); + text_color= this.getColorProperty(PROP_TEXT_COLOR, CfgPreferencesDefaults.DEFAULT_TEXT_COLOR); + selection_color_bg = this.getColorProperty(PROP_SELECTION_COLOR_BG, CfgPreferencesDefaults.DEFAULT_SELECTION_COLOR_BACKGROUND); + selection_color_fg = this.getColorProperty(PROP_SELECTION_COLOR_FG, CfgPreferencesDefaults.DEFAULT_SELECTION_COLOR_FOREGROUND); + text_font = this.getFontProperty(PROP_TEXT_FONT, CfgPreferencesDefaults.DEFAULT_TEXT_FONT); + } + + private void firePropertyChange(String propertyName, Object oldValue, Object newValue) { + Object[] listeners = listenerList.getListenerList(); + + PropertyChangeEvent event = new PropertyChangeEvent(this, propertyName, oldValue, newValue); + for (int i = listeners.length - 2; i >= 0; i -= 2) { + if (listeners[i] == PropertyChangeListener.class) { + ((PropertyChangeListener) listeners[i+1]).propertyChange(event); + } + } + } + + private Font getFontProperty(String propName, Font defaultFont){ + Preferences prefs = this.getPreferences(); + String fontName = prefs.get(propName+PROP_FONTNAME, defaultFont.getFamily()); + int fontSize = prefs.getInt(propName+PROP_FONTSIZE, defaultFont.getSize()); + int fontStyle = prefs.getInt(propName+PROP_FONTSTYLE, defaultFont.getStyle()); + return new Font(fontName, fontStyle, fontSize); + } + + private Color getColorProperty(String propName, Color defaultColor){ + Preferences prefs = this.getPreferences(); + int srgb = prefs.getInt(propName, defaultColor.getRGB()); + if(srgb == defaultColor.getRGB()) + return defaultColor; + return new Color(srgb); + } + + public Color getBackedgeColor() { + return backedge_color; + } + + public Color getBackgroundColor() { + return background_color; + } + + public Color getBorderColor() { + return border_color; + } + + public Color getEdgeColor() { + return edge_color; + } + + public Color getExceptionEdgeColor() { + return exceptionEdgeColor; + } + + public Color getNodeColor() { + return node_color; + } + + public Color getSelectionColorForeground() { + return selection_color_fg; + } + + public Color getSelectionColorBackground() { + return selection_color_bg; + } + + public Color getTextColor() { + return text_color; + } + + public Font getTextFont() { + return text_font; + } + + public FlagsSetting getFlagsSetting() { + return flagsSetting; + } + + + public void setFlagsSetting(FlagsSetting flagsSetting) { + FlagsSetting old = this.getFlagsSetting(); + this.flagsSetting = flagsSetting; + Preferences prefs = getPreferences(); + firePropertyChange(PROP_FLAGS, old, flagsSetting); + prefs.put(PROP_FLAGS, flagsSetting.getFlagString()); + } + + + public void setTextFont(Font text_font) { + Font old = this.getTextFont(); + Preferences prefs = getPreferences(); + this.text_font = text_font; + firePropertyChange(PROP_TEXT_FONT, old, text_font); + prefs.put(PROP_TEXT_FONT + PROP_FONTNAME , text_font.getFamily()); + prefs.putInt(PROP_TEXT_FONT + PROP_FONTSIZE, text_font.getSize()); + prefs.putInt(PROP_TEXT_FONT + PROP_FONTSTYLE, text_font.getStyle()); + } + + public void setBackedgeColor(Color backedge_color) { + Color old = this.getBackedgeColor(); + this.backedge_color = backedge_color; + firePropertyChange(PROP_BACK_EDGE_COLOR, old, backedge_color); + getPreferences().putInt(PROP_BACK_EDGE_COLOR, backedge_color.getRGB()); + } + + public void setBackgroundColor(Color bg_color) { + Color old = this.getBackgroundColor(); + background_color = bg_color; + firePropertyChange(PROP_BACKGROUND_COLOR, old, bg_color ); + getPreferences().putInt(PROP_BACKGROUND_COLOR, bg_color.getRGB()); + } + + public void setBorderColor(Color border_color) { + Color old = getBorderColor(); + this.border_color = border_color; + firePropertyChange(PROP_BORDER_COLOR, old, border_color ); + getPreferences().putInt(PROP_BORDER_COLOR, border_color.getRGB()); + } + + public void setEdgeColor(Color edge_color) { + Color old = getEdgeColor(); + this.edge_color = edge_color; + firePropertyChange(PROP_EDGE_COLOR, old, edge_color); + getPreferences().putInt(PROP_EDGE_COLOR, edge_color.getRGB()); + } + + public void setNodeColor(Color node_color) { + Color old = getNodeColor(); + this.node_color = node_color; + firePropertyChange(PROP_NODE_COLOR, old, node_color); + getPreferences().putInt(PROP_NODE_COLOR, node_color.getRGB()); + + } + + public void setSelectionColorForeground(Color selection_color) { + Color old = this.getSelectionColorForeground(); + this.selection_color_fg = selection_color; + firePropertyChange(PROP_SELECTION_COLOR_FG, old, selection_color); + getPreferences().putInt(PROP_SELECTION_COLOR_FG, selection_color.getRGB()); + } + + public void setSelectionColorBackground(Color selection_color) { + Color old = this.getSelectionColorBackground(); + this.selection_color_bg = selection_color; + firePropertyChange(PROP_SELECTION_COLOR_BG, old, selection_color); + getPreferences().putInt(PROP_SELECTION_COLOR_BG, selection_color.getRGB()); + } + + public void setTextColor(Color text_color) { + Color old = this.getTextColor(); + this.text_color = text_color; + firePropertyChange(PROP_TEXT_COLOR, old, text_color); + getPreferences().putInt(PROP_TEXT_COLOR, text_color.getRGB()); + } + + public void setExceptionEdgeColor(Color exceptionEdgeColor) { + Color old = this.getExceptionEdgeColor(); + this.exceptionEdgeColor = exceptionEdgeColor; + firePropertyChange(PROP_EXCEPTION_EDGE_COLOR, old, exceptionEdgeColor); + getPreferences().putInt(PROP_EXCEPTION_EDGE_COLOR, exceptionEdgeColor.getRGB()); + } + + + +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/CfgPreferencesDefaults.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/CfgPreferencesDefaults.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,23 @@ +package at.ssw.visualizer.cfg.preferences; + +import java.awt.Color; +import java.awt.Font; + +/** + * Default Configuration for options panel + * + * @author Rumpfhuber Stefan + */ +public final class CfgPreferencesDefaults { + public static final String DEFAULT_FLAGSTRING = "std(224,224,128);osr(224,224,0);ex(128,128,224);sr(128,224,128);llh(224,128,128);lle(224,192,192);plh(128,224,128);bb(160,0,0);ces(192,192,192)"; + public static final Color DEFAUT_NODE_COLOR = new Color(208, 208, 208); + public static final Color DEFAULT_BACKGROUND_COLOR = new Color(255, 255, 255); + public static final Color DEFAULT_BACKEDGE_COLOR = new Color(160, 0, 0); + public static final Color DEFAULT_EDGE_COLOR = new Color(0, 0, 0); + public static final Color DEFAULT_SELECTION_COLOR_FOREGROUND = Color.BLUE; + public static final Color DEFAULT_SELECTION_COLOR_BACKGROUND = Color.BLUE; + public static final Color DEFAULT_BORDER_COLOR = new Color(0, 0, 0); + public static final Color DEFAULT_EXCEPTIONEDGE_COLOR = new Color(0, 0, 160); + public static final Color DEFAULT_TEXT_COLOR = new Color(0, 0, 0); + public static final Font DEFAULT_TEXT_FONT = new Font("Dialog", Font.PLAIN, 18); +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/ColorChooserButton.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/ColorChooserButton.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,94 @@ +package at.ssw.visualizer.cfg.preferences; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.Icon; +import javax.swing.JButton; +import javax.swing.JColorChooser; + +/** + * A color selection button. It will preview the currently selected color as + * an icon. Clicking the button will bring up the JColorChooser dialog. + * + * @author Bernhard Stiftner + */ +public class ColorChooserButton extends JButton implements ActionListener { + + public static final Dimension ICON_SIZE = new Dimension(24, 8); + + Color color; + boolean colorChooserEnabled = true; // bring up dialog when clicked? + + + public ColorChooserButton() { + this(Color.black); + } + + public ColorChooserButton(Color defaultColor) { + setIcon(new ColorBoxIcon()); + addActionListener(this); + color = defaultColor; + Dimension size = new Dimension(ICON_SIZE); + size.width += getInsets().left + getInsets().right; + size.height += getInsets().top + getInsets().bottom; + setPreferredSize(size); + } + + public void setColor(Color newColor) { + color = newColor; + repaint(); + } + + public Color getColor() { + return color; + } + + public boolean isColorChooserEnabled() { + return colorChooserEnabled; + } + + public void setColorChooserEnabled(boolean enabled) { + this.colorChooserEnabled = enabled; + } + + public void actionPerformed(ActionEvent e) { + if (!colorChooserEnabled) { + return; + } + + Color c = JColorChooser.showDialog(this, "Choose color", color); + if (c != null) { + setColor(c); + } + } + + class ColorBoxIcon implements Icon { + + public int getIconWidth() { + return ICON_SIZE.width; + } + + public int getIconHeight() { + return ICON_SIZE.height; + } + + public void paintIcon(Component c, Graphics g, int x, int y) { + Color oldColor = g.getColor(); + g.translate(x, y); + + g.setColor(color); + g.fillRect(0, 0, ICON_SIZE.width, ICON_SIZE.height); + + g.setColor(Color.black); + g.drawRect(0, 0, ICON_SIZE.width, ICON_SIZE.height); + + g.translate(-x, -y); + g.setColor(oldColor); + } + } +} + diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/FlagsEditorPanel.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/FlagsEditorPanel.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,247 @@ +package at.ssw.visualizer.cfg.preferences; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Enumeration; +import java.util.StringTokenizer; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.DefaultListModel; +import javax.swing.JButton; +import javax.swing.JColorChooser; +import javax.swing.JComponent; +import javax.swing.JList; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.ListSelectionModel; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; + +/** + * + * @author Bernhard Stiftner + * @author Rumpfhuber Stefan + */ +public class FlagsEditorPanel extends JPanel implements ActionListener, + ListSelectionListener { + + FlagListModel listModel; + JList list; + ColorChooserButton colorButton; + JButton newButton; + JButton removeButton; + JButton upButton; + JButton downButton; + + + /** Creates a new instance of FlagsEditorPanel */ + public FlagsEditorPanel(String flagString) { + setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); + + listModel = new FlagListModel(flagString); + list = new JList(listModel); + list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + list.addListSelectionListener(this); + add(new JScrollPane(list)); + + add(Box.createHorizontalStrut(3)); + + Box buttonBox = new Box(BoxLayout.Y_AXIS); + buttonBox.add(colorButton = new ColorChooserButton()); + buttonBox.add(newButton = new JButton("New...")); + buttonBox.add(removeButton = new JButton("Remove")); + buttonBox.add(upButton = new JButton("Up")); + buttonBox.add(downButton = new JButton("Down")); + buttonBox.add(Box.createVerticalGlue()); + add(buttonBox); + layoutButtonContainer(buttonBox); + + colorButton.setColorChooserEnabled(false); + colorButton.addActionListener(this); + newButton.addActionListener(this); + removeButton.addActionListener(this); + upButton.addActionListener(this); + downButton.addActionListener(this); + + selectionChanged(-1); // no selection + } + + /** + * Ugly helper to make a nice layout for vertically aligned buttons. + */ + private static void layoutButtonContainer(JComponent buttonContainer) { + int width = 0; + int height = 0; + + for (int i=0; i= listModel.size()-1) { + return; + } + Object o = listModel.getElementAt(index); + listModel.removeElementAt(index); + listModel.insertElementAt(o, index+1); + } + } + + public void valueChanged(ListSelectionEvent e) { + if (e.getValueIsAdjusting()) { + return; // another event will be fired soon + } + selectionChanged(list.getSelectedIndex()); + } + + protected void selectionChanged(int index) { //index is -1 if there is no selection + colorButton.setEnabled(index >= 0); + removeButton.setEnabled(index >= 0); + upButton.setEnabled(index > 0); + downButton.setEnabled(index >= 0 && index < listModel.getSize()-1); + + if (index >= 0) { + FlagListItem item = (FlagListItem)listModel.elementAt(index); + colorButton.setColor(item.getColor()); + list.setSelectedIndex(index); + } else { + colorButton.setColor(getBackground()); + } + } + + protected void changeColor() { + int selectedIndex = list.getSelectedIndex(); + FlagListItem item = (FlagListItem)listModel.elementAt(selectedIndex); + Color c = JColorChooser.showDialog(this, "Choose color", item.getColor()); + + if (c != null) { + item.setColor(c); + colorButton.setColor(c); + } + } + + class FlagListModel extends DefaultListModel { + + public FlagListModel(String flagString) { + if (flagString != null) { + setFlagString(flagString); + } + } + + public String getFlagString() { + StringBuffer sb = new StringBuffer(); + Enumeration e = elements(); + while (e.hasMoreElements()) { + FlagListItem item = (FlagListItem)e.nextElement(); + sb.append(item.getFlagString()); + Color c = item.getColor(); + sb.append("(").append(c.getRed()).append(",").append(c.getGreen()).append(",").append(c.getBlue()).append(")"); + if (e.hasMoreElements()) { + sb.append(";"); + } + } + return sb.toString(); + } + + public void setFlagString(String flagString) { + clear(); + StringTokenizer st = new StringTokenizer(flagString, ";"); + while (st.hasMoreTokens()) { + String s = st.nextToken(); + String flag = s.split("\\(")[0]; + Color color = FlagsSetting.toColor(s); + addElement(new FlagListItem(flag, color)); + } + } + + } + + class FlagListItem { + + Color color; + String flagString; + + public FlagListItem(String flagString, Color color) { + this.flagString = flagString; + this.color = color; + } + + public Color getColor() { + return color; + } + + public String getFlagString() { + return flagString; + } + + public void setColor(Color c) { + color = c; + } + + @Override + public String toString() { + return flagString; + } + } + +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/FlagsSetting.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/FlagsSetting.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,85 @@ +package at.ssw.visualizer.cfg.preferences; + +import java.awt.Color; +import java.io.Serializable; +import java.util.Hashtable; +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public class FlagsSetting implements Serializable { + + private Hashtable flag2color; + private Hashtable priority; + private String flagString; + + + public FlagsSetting(String flagString) { + this.flagString = flagString; + flag2color = new Hashtable<>(); + priority = new Hashtable<>(); + String[] flags = flagString.split(";"); + + int z = 0; + for(String s : flags) { + String flag = s.split("\\(")[0]; + Color c = toColor(s); + flag2color.put(flag, c); + priority.put(flag, z); + z++; + } + } + + public Color getColor(List strings) { + int minPriority = Integer.MAX_VALUE; + Color result = null; + + for(String s : strings) { + Color curColor = flag2color.get(s); + if(curColor != null) { + int curPriority = priority.get(s); + if(curPriority < minPriority) { + minPriority = curPriority; + result = curColor; + } + } + } + + return result; + } + + public static Color toColor(String s) { + String sArr[] = s.split("\\("); + String Color = sArr[1].substring(0, sArr[1].length() - 1); + String ColorArr[] = Color.split(","); + int r = Integer.parseInt(ColorArr[0]); + int g = Integer.parseInt(ColorArr[1]); + int b = Integer.parseInt(ColorArr[2]); + return new Color(r, g, b); + } + + public String getFlagString() { + return flagString; + } + + @Override + public boolean equals(Object o) { + if(o==null) + return false; + return this.toString().equals(o.toString()); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 19 * hash + (this.flagString != null ? this.flagString.hashCode() : 0); + return hash; + } + + @Override + public String toString(){ + return "FlagSetting[" + flagString + "]"; + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/FontChooserDialog.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/FontChooserDialog.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,37 @@ +package at.ssw.visualizer.cfg.preferences; + +import java.awt.Font; +import java.beans.PropertyEditor; +import java.beans.PropertyEditorManager; +import org.openide.DialogDescriptor; +import org.openide.DialogDisplayer; + +/** + * + * @author Bernhard Stiftner + */ +public class FontChooserDialog { + + /* + * Displays a font selection dialog. + * @return The selected font, or the initial font if the user chose + * to bail out + */ + public static Font show(Font initialFont) { + PropertyEditor pe = PropertyEditorManager.findEditor(Font.class); + if (pe == null) { + throw new RuntimeException("Could not find font editor component."); + } + pe.setValue(initialFont); + DialogDescriptor dd = new DialogDescriptor( + pe.getCustomEditor(), + "Choose Font"); + DialogDisplayer.getDefault().createDialog(dd).setVisible(true); + if (dd.getValue() == DialogDescriptor.OK_OPTION) { + Font f = (Font)pe.getValue(); + return f; + } + return initialFont; + } + +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/visual/BezierWidget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/visual/BezierWidget.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,345 @@ +package at.ssw.visualizer.cfg.visual; + +import org.netbeans.api.visual.widget.ConnectionWidget; +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Shape; +import java.awt.Stroke; +import java.awt.geom.AffineTransform; +import java.awt.geom.CubicCurve2D; +import java.awt.geom.GeneralPath; +import java.awt.geom.Point2D; +import java.util.List; +import org.netbeans.api.visual.anchor.AnchorShape; +import org.netbeans.api.visual.graph.GraphScene; +import org.netbeans.api.visual.widget.Scene; +import org.netbeans.api.visual.widget.Widget; + + +/** + * In comparison to the default ConnectionWidget this class is able to connect + * Widgets with a curve instead of a straight line sequence. Between two control + * points a curve is painted as cubic bezier curve the control points are + * calculated automaticaly they depend on the position of the prior- and the + * following control points. + * In conjunction with a suitable router the connection will be a straight line + * or a curve depending on the amount and the position of the controlpoints. + * Controlpoints supplied by the router, are treated as curve intersection points. + * For Reflexive edges the router doesn`t need to supply controlpoints, they + * get painted by this class automatically. If the router supplys more as 2 + * control points for a recursive edge the edge gets painted with the default + * curve approximation algorithm. + */ +public class BezierWidget extends ConnectionWidget { + private static final double BEZIER_SCALE = 0.3; + private static final double ENDPOINT_DEVIATION = 3;//curve endpoint approximation accuracy + + private GraphScene scene=null; + + public BezierWidget(Scene scene) { + super(scene); + } + + public BezierWidget(GraphScene scene) { + super(scene); + this.scene=scene; + } + + + private boolean isReflexive(){ + return getSourceAnchor().getRelatedWidget() == getTargetAnchor().getRelatedWidget(); + } + + + @Override + protected Rectangle calculateClientArea() { + Rectangle bounds = null; + if(this.getControlPoints().size()>0){ + for(Point p : this.getControlPoints()){ + if(bounds==null) + bounds = new Rectangle(p); + else + bounds.add(p); + } + bounds.grow(5,5); + } + if(isReflexive()){ + Widget related = this.getTargetAnchor().getRelatedWidget(); + bounds = related.convertLocalToScene(related.getBounds()); + bounds.grow(10, 10); + } + if(bounds==null) + bounds = super.calculateClientArea(); + + return bounds; + } + + + + //returns prefered location for an edge -1 for left and 1 for right + private int edgeBalance(Widget nodeWidget) { + if(scene == null) + return 1; + + Point nodeLocation = nodeWidget.getLocation(); + int left = 0, right = 0; + + Object node = scene.findObject(nodeWidget); + + for(Object e : scene.findNodeEdges(node, true, true)) {//inputedges + ConnectionWidget cw = (ConnectionWidget) scene.findWidget(e); + + if(cw != this) { + Widget targetNodeWidget = cw.getTargetAnchor().getRelatedWidget(); + + Point location; + if(targetNodeWidget == nodeWidget) { + Widget sourceNodeWidget = cw.getSourceAnchor().getRelatedWidget(); + location = sourceNodeWidget.getLocation(); + } else { + location = targetNodeWidget.getLocation(); + } + + if(location.x < nodeLocation.x) + left++; + else + right++; + } + } + if(left < right) + return -1; + else + return 1; + } + + + + + /** + * if the edge is reflexive its painted as a cyclic edge + * if there are 2 controlpoints the connection is painted as a straight line from the source to the targetanchor + * if there are more as 2 controlpoints the connection path between 2 control points is painted as bezier curve + */ + + @Override + protected void paintWidget () { + + List contrPoints = this.getControlPoints(); + int listSize = contrPoints.size(); + + Graphics2D gr = getGraphics (); + + if (listSize <= 2) { + if(isReflexive()) { //special case for reflexive connection widgets + Widget related = this.getTargetAnchor().getRelatedWidget(); + int position = this.edgeBalance(related); + Rectangle bounds = related.convertLocalToScene(related.getBounds()); + gr.setColor (getLineColor()); + Point first = new Point(); + Point last = new Point(); + double centerX = bounds.getCenterX(); + first.x = (int) (centerX + bounds.width / 4); + first.y = bounds.y + bounds.height; + last.x = first.x; + last.y = bounds.y; + + gr.setStroke(this.getStroke()); + + double cutDistance = this.getTargetAnchorShape().getCutDistance(); + double anchorAngle = Math.PI/-3.0; + double cutX = Math.abs(Math.cos(anchorAngle)*cutDistance); + double cutY = Math.abs(Math.sin(anchorAngle)*cutDistance); + int ydiff=first.y-last.y; + int endy = -ydiff; + double height=bounds.getHeight(); + double cy = height/4.0; + double cx=bounds.getWidth()/5.0; + double dcx = cx*2; + GeneralPath gp = new GeneralPath(); + gp.moveTo(0, 0); + gp.quadTo(0, cy, cx, cy); + gp.quadTo(dcx, cy, dcx, -height/2.0); + gp.quadTo(dcx, endy - cy, cy, -(cy+ydiff)); + gp.quadTo(cutX*1.5, endy - cy, cutX, endy-cutY); + + AffineTransform af = new AffineTransform(); + AnchorShape anchorShape = this.getTargetAnchorShape(); + + if(position < 0) { + first.x = (int) (centerX - bounds.width / 4); + af.translate(first.x, first.y); + af.scale(-1.0, 1.0); + last.x = first.x; + } else { + af.translate(first.x, first.y); + } + Shape s = gp.createTransformedShape(af); + gr.draw(s); + + if (last != null) { + AffineTransform previousTransform = gr.getTransform (); + gr.translate (last.x, last.y); + + if(position < 0) + gr.rotate(Math.PI - anchorAngle); + else + gr.rotate (anchorAngle); + + anchorShape.paint (gr, false); + gr.setTransform (previousTransform); + } + + } else { + super.paintWidget(); + } + return; + } + + //bezier curve... + GeneralPath curvePath = new GeneralPath(); + Point lastControlPoint = null; + double lastControlPointRotation = 0.0; + + Point prev = null; + for (int i = 0; i < listSize - 1; i++) { + Point cur = contrPoints.get(i); + Point next = contrPoints.get(i + 1); + Point nextnext = null; + if (i < listSize - 2) { + nextnext = contrPoints.get(i + 2); + } + + double len = cur.distance(next); + double scale = len * BEZIER_SCALE; + Point bezierFrom = null;//first ControlPoint + Point bezierTo = null;//second ControlPoint + + if (prev == null) { + //first point + curvePath.moveTo(cur.x, cur.y);//startpoint + bezierFrom = cur; + } else { + bezierFrom = new Point(next.x - prev.x, next.y - prev.y); + bezierFrom = scaleVector(bezierFrom, scale); + bezierFrom.translate(cur.x, cur.y); + } + + if (nextnext == null) {//next== last point (curve to) + lastControlPoint=next; + bezierTo = next;//set 2nd intermediate point to endpoint + GeneralPath lastseg = this.subdivide(cur, bezierFrom, bezierTo, next); + if(lastseg != null) + curvePath.append(lastseg, true); + break; + } else { + bezierTo = new Point(cur.x - nextnext.x, cur.y - nextnext.y); + bezierTo = scaleVector(bezierTo, scale); + bezierTo.translate(next.x, next.y); + } + + curvePath.curveTo( + bezierFrom.x, bezierFrom.y,//controlPoint1 + bezierTo.x, bezierTo.y,//controlPoint2 + next.x,next.y + ); + prev = cur; + } + Point2D cur = curvePath.getCurrentPoint(); + Point next = lastControlPoint; + + lastControlPointRotation = //anchor anchorAngle + Math.atan2 (cur.getY() - next.y, cur.getX() - next.x); + + Color previousColor = gr.getColor(); + gr.setColor (getLineColor()); + Stroke s = this.getStroke(); + gr.setStroke(s); + gr.setColor(this.getLineColor()); + gr.draw(curvePath); + + AffineTransform previousTransform = gr.getTransform (); + gr.translate (lastControlPoint.x, lastControlPoint.y); + gr.rotate (lastControlPointRotation); + AnchorShape targetAnchorShape = this.getTargetAnchorShape(); + targetAnchorShape.paint (gr, false); + gr.setTransform (previousTransform); + + //paint ControlPoints if enabled + if (isPaintControlPoints()) { + int last = listSize - 1; + for (int index = 0; index <= last; index ++) { + Point point = contrPoints.get (index); + previousTransform = gr.getTransform (); + gr.translate (point.x, point.y); + if (index == 0 || index == last) + getEndPointShape().paint (gr); + else + getControlPointShape().paint (gr); + gr.setTransform (previousTransform); + } + + } + gr.setColor(previousColor); + } + + + + private GeneralPath subdivide (Point b0, Point b1, Point b2, Point b3) { + double cutDistance = getTargetAnchorShape().getCutDistance(); + double minDistance = cutDistance - ENDPOINT_DEVIATION; + /** + * if the cutDistance is valid the last segment of the curve + * gets reduced by subdivision until the distance of the endpoint(epDistance) + * satisfys the condition (cutDistance > epDistance > (cutDistance - ENDPOINT-DEVIATION) + */ + if(cutDistance > minDistance && minDistance > 0 ) { + GeneralPath path = new GeneralPath(); + + path.moveTo(b0.x, b0.y); + + CubicCurve2D.Double left = new CubicCurve2D.Double( + b0.x, b0.y, + b1.x, b1.y, + b2.x, b2.y, + b3.x, b3.y); + + CubicCurve2D right=new CubicCurve2D.Double(); + left.subdivide(left, right); + double distance = b3.distance(left.getP2()); + //if the distance is bigger as the cutDistance the left segment is added + //and the right segment is divided again + while(distance>cutDistance){ + path.append(left, true); + right.subdivide(left, right); + distance = b3.distance(left.getP2()); + //if the devision removed to much the left segment is divided + while(distance < minDistance) { + //changes the distance to ~ (distance+distance/2) + left.subdivide(left, right); + distance = b3.distance(left.getP2()); + } + } + //append the last segment with (minDistance < distance < cutDistance) + //actually we should check if the a division happend, but this is very unlikly + path.append(left, true); + return path; + } + return null; + } + + + + + + private static Point scaleVector(Point vector, double len) { + double scale = Math.sqrt(vector.x * vector.x + vector.y * vector.y); + if(scale==0.0) return vector; + scale = len / scale; + return new Point( + Math.round(vector.x * (float)scale), + Math.round(vector.y * (float)scale)); + } + +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/visual/PolylineRouter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/visual/PolylineRouter.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,360 @@ +package at.ssw.visualizer.cfg.visual; + +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.geom.Line2D; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import org.netbeans.api.visual.anchor.Anchor; +import org.netbeans.api.visual.router.Router; +import org.netbeans.api.visual.widget.ConnectionWidget; +import org.netbeans.api.visual.widget.Widget; + +/** + * Router Class with Collision Detection + * + * + * The returned path is a straight line there is no node widget between the source and the target node, + * if there are nodewidgets in between it tries to find a path around those abstacles to avoid collisions. + * The algorithm for the search of this path is limited by a fixed number of iterations defined in + * NUMER_OF_ITERATIONS to return a result in reasonable time. If the calculation exceeds this limit the + * path returned contains at least 1 collision with a nodewidget. + */ + +public class PolylineRouter implements Router { + private static final float FACTOR = 0.70f; + + private static final int HEXPAND = 3; + private static final int VEXPAND = 3; + private static final int NUMBER_OF_ITERATIONS = 8; + + WidgetCollisionCollector collector; + + + public PolylineRouter(WidgetCollisionCollector collector){ + this.collector=collector; + } + + + public List routeConnection(final ConnectionWidget widget) { + if(!widget.isVisible()) return Collections.emptyList(); + + Anchor sourceAnchor = widget.getSourceAnchor(); + Anchor targetAnchor = widget.getTargetAnchor(); + + if(sourceAnchor == null || targetAnchor == null) + return null; + + Point start = sourceAnchor.compute(widget.getSourceAnchorEntry()).getAnchorSceneLocation(); + Point end = targetAnchor.compute(widget.getTargetAnchorEntry()).getAnchorSceneLocation(); + + Widget sourceWidget = sourceAnchor.getRelatedWidget(); + Widget targetWidget = targetAnchor.getRelatedWidget(); + + + if(sourceWidget == targetWidget){//reflexive edges doesnt need any path + return Collections.emptyList(); + } + + List nodeWidgets = new ArrayList<>(); + + if(collector != null){ + collector.collectCollisions(nodeWidgets); + //source and target widget are not treatet as obstacle + nodeWidgets.remove(sourceWidget); + nodeWidgets.remove(targetWidget); + } + + List controlPoints = optimize(nodeWidgets, widget, start, end); + + //size==2 => straight line + //size==3 => ensures a collision between cp0 and cp2 therefore its not possible to simplify it + if(controlPoints.size() > 3) + controlPoints = simplify(nodeWidgets, controlPoints); + + return controlPoints; + } + + + private List simplify(Collection nodeWidgets, List list) { + 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); + for (int j = i; j < list.size(); j++) { + Point cur = list.get(j); + if (!intersects(nodeWidgets, prev, cur)) { + i = j; + } + } + result.add(list.get(i)); + } + return result; + } + + /** + * Computates the Anchorposition like the Rectangular anchor for a + * given widget as source/target and a controlpoint as opposit anchorposition + */ + + private Point computateAnchorPosition(Widget relatedWidget, Point controlPoint) { + Rectangle bounds = relatedWidget.getBounds(); + Point relatedLocation = relatedWidget.getLocation();//center of the widget + + if (bounds.isEmpty () || relatedLocation.equals (controlPoint)) + return relatedLocation; + + float dx = controlPoint.x - relatedLocation.x; + float dy = controlPoint.y - relatedLocation.y; + + float ddx = Math.abs (dx) / (float) bounds.width; + float ddy = Math.abs (dy) / (float) bounds.height; + + float scale = 0.5f / Math.max (ddx, ddy); + + Point point = new Point (Math.round (relatedLocation.x + scale * dx), + Math.round (relatedLocation.y + scale * dy)); + return point; + } + + + + private List optimize(Collection nodeWidgets, ConnectionWidget connWidget, Point start, Point end) { + + List list = new ArrayList<>(); + list.add(start); + list.add(end); + + boolean progress = true; + + for (int j = 0; progress && j < NUMBER_OF_ITERATIONS ; j++) { + progress = false; + List newList = new ArrayList<>(); + for (int i = 0; i < list.size() - 1 ; i++) { + Point cur = list.get(i); + Point next = list.get(i + 1); + newList.add(cur); + List intermediate = optimizeLine(nodeWidgets, cur, next); + if (intermediate != null && intermediate.size() > 0) { + progress = true; + newList.addAll(intermediate);//insert new controlpoints between cur and next + } + } + newList.add(list.get(list.size()-1));//add endpoint of the polyline + list = newList; + + } + + if(list.size() > 2) { + Widget sourceNode = connWidget.getSourceAnchor().getRelatedWidget(); + Widget targetNode = connWidget.getTargetAnchor().getRelatedWidget(); + Rectangle sourceBounds = sourceNode.convertLocalToScene(sourceNode.getBounds()); + Rectangle targetBounds = targetNode.convertLocalToScene(targetNode.getBounds()); + sourceBounds.grow(HEXPAND, VEXPAND); + + /** + * add only points which are not intersecting the source and the target + * widget bounds caused by invalid bad anchor positions. The first + * and the last point is ignored cause the anchor is recalculated + * anyway. + */ + ArrayList tmp = new ArrayList<>(); + int listSize=list.size(); + tmp.add(list.get(0)); + int i=0; + while(++i < listSize-1) { + Point p = list.get(i); + if(!sourceBounds.contains(p) || !targetBounds.contains(p)) + tmp.add(p); + } + + tmp.add(list.get(i)); + if(tmp.size() < 3) + return tmp; + + list=tmp; + //calculate a proper anchor position using the second/penultimate controlpoint for start/end + start = this.computateAnchorPosition(connWidget.getSourceAnchor().getRelatedWidget(), list.get(1)); + end = this.computateAnchorPosition(connWidget.getTargetAnchor().getRelatedWidget(), list.get(list.size()-2)); + list.set(0,start); + list.set(list.size()-1, end); + } + return list; + } + + + /** + * trys to optimize a line from p1 to p2 to avoid collisions with node widgets + * returns null if the line doesn`t intersect with any nodewidget + * or a list with immediate points between p1 and p2 to avoid collisions + */ + private List optimizeLine(Collection nodeWidgets, Point p1, Point p2) { + Line2D line = new Line2D.Double(p1, p2); + + for(Widget w : nodeWidgets ) { + if( w.isVisible() ) { + Rectangle r = w.convertLocalToScene(w.getBounds()); + r.grow(HEXPAND, VEXPAND); + + if (!line.intersects(r)) continue; + + Point location = w.getLocation(); + int distx = (int) (r.width * FACTOR); + int disty = (int) (r.height * FACTOR); + + int minIntersects = Integer.MAX_VALUE; + int min = Integer.MAX_VALUE; + List minSol = null; + for (int i = -1; i <= 1; i++) { + 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<>(); + list1.add(p1); + list1.add(cur); + list1.add(p2); + int crossProd = Math.abs(crossProduct(p1, cur, p2)); + if (!intersects(w, list1)) { + Line2D line1 = new Line2D.Float(p1, cur); + Line2D line2 = new Line2D.Float(p2, cur); + int curIntersects = this.countNodeIntersections(nodeWidgets, line1, line2); + + if (curIntersects < minIntersects + || (curIntersects == minIntersects && crossProd < min)) { + minIntersects = curIntersects; + min = crossProd; + minSol = new ArrayList<>(); + minSol.add(cur); + } + } + + if (i == 0 || j == 0) { + Point cur1, cur2; + if (i == 0) { + cur1 = new Point(location.x + distx/2, location.y + j * disty); + cur2 = new Point(location.x - distx/2, location.y + j * disty); + } else { // (j == 0) + cur1 = new Point(location.x + i * distx, location.y + disty/2); + cur2 = new Point(location.x + i * distx, location.y - disty/2); + } + + Point vec1 = new Point(p1.x - cur1.x, p1.y - cur1.y); + int offset1 = vec1.x * vec1.x + vec1.y * vec1.y; + + Point vec2 = new Point(p1.x - cur2.x, p1.y - cur2.y); + int offset2 = vec2.x * vec2.x + vec2.y * vec2.y; + + if (offset2 < offset1) { + Point tmp = cur1; + cur1 = cur2; + cur2 = tmp; + } + + List list2 = new ArrayList<>(); + list2.add(p1); + list2.add(cur1); + list2.add(cur2); + list2.add(p2); + + int cross1 = crossProduct(p1, cur1, cur2); + int cross2 = crossProduct(cur1, cur2, p2); + + if (cross1 > 0) { + cross1 = 1; + } else if (cross1 < 0) { + cross1 = -1; + } + + if (cross2 > 0) { + cross2 = 1; + } else if (cross2 < 0) { + cross2 = -1; + } + if ((cross1 == cross2 || cross1 == 0 || cross2 == 0) && !intersects(w, list2)) { + Line2D line1 = new Line2D.Float(p1, cur1); + Line2D line2 = new Line2D.Float(cur1, cur2); + Line2D line3 = new Line2D.Float(p2, cur2); + int curIntersects = this.countNodeIntersections(nodeWidgets, line1, line2, line3); + + // This is a bit better + crossProd--; + + if (curIntersects < minIntersects + || (curIntersects == minIntersects && crossProd < min)) { + minIntersects = curIntersects; + min = crossProd; + minSol = new ArrayList<>(); + minSol.add(cur1); + minSol.add(cur2); + } + } + } + } + } + } + if (minSol != null) { + return minSol; + } + } + } + return null; + } + + + + private int countNodeIntersections(Collection nodeWidgets, Line2D... lines){ + int count=0; + for(Widget nw : nodeWidgets){ + if(nw.isVisible()) { + Rectangle bounds = nw.convertLocalToScene(nw.getBounds()); + for( Line2D line : lines){ + if(line.intersects(bounds)) + count++; + } + } + } + return count; + } + + + private boolean intersects(Collection nodeWidgets, Point start, Point end) { + List pointlist = new ArrayList<>(); + pointlist.add(start); + pointlist.add(end); + + for(Widget w : nodeWidgets){ + if(w.isVisible() && intersects(w, pointlist)) { + return true; + } + } + return false; + } + + + private boolean intersects(Widget w, List list) { + Rectangle r = w.convertLocalToScene(w.getBounds()); + r.grow(HEXPAND, VEXPAND); + return intersects(list, r); + } + + + private boolean intersects(List list, Rectangle rect){ + for(int i=1; i < list.size(); i++) { + Point cur = list.get(i-1); + Point next = list.get(i); + if(rect.intersectsLine(cur.x, cur.y, next.x, next.y)) + return true; + } + return false; + } + + + private int crossProduct(Point p1, Point p2, Point p3) { + Point off1 = new Point(p1.x - p2.x, p1.y - p2.y); + Point off2 = new Point(p3.x - p2.x, p3.y - p2.y); + return (off1.x * off2.y - off1.y * off2.x); + } + +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/visual/PolylineRouterV2.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/visual/PolylineRouterV2.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,393 @@ +package at.ssw.visualizer.cfg.visual; + +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.geom.Line2D; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import org.netbeans.api.visual.anchor.Anchor; +import org.netbeans.api.visual.router.Router; +import org.netbeans.api.visual.widget.ConnectionWidget; +import org.netbeans.api.visual.widget.Widget; + +/** + * Router Class with Collision Detection + * + * + * The returned path is a straight line there is no node widget between the source and the target node, + * if there are nodewidgets in between it tries to find a path around those abstacles to avoid collisions. + * The algorithm for the search of this path is limited by a fixed number of iterations defined in + * NUMER_OF_ITERATIONS to return a result in reasonable time. If the calculation exceeds this limit the + * path returned contains at least 1 collision with a nodewidget. + * + * This class intend to solve the same problem as the class PolyLineRouter but + * uses slightly different methods. + * + uses another algorithm for solving the collision. + * + the obstacle bounds are calulated in advance to avoid a recalculation. + * - there is no heuristic, the shortest path around the widget is choosen asap. + * + * + * + */ + +public class PolylineRouterV2 implements Router { + private static final int HEXPAND = 3; + private static final int VEXPAND = 3; + private static final int NUMBER_OF_ITERATIONS = 8; + + WidgetCollisionCollector collector; + + + public PolylineRouterV2(WidgetCollisionCollector collector){ + this.collector=collector; + } + + + public List routeConnection(final ConnectionWidget widget) { + if(!widget.isVisible()) return Collections.emptyList(); + + Anchor sourceAnchor = widget.getSourceAnchor(); + Anchor targetAnchor = widget.getTargetAnchor(); + + if(sourceAnchor == null || targetAnchor == null) + return null; + + Point start = sourceAnchor.compute(widget.getSourceAnchorEntry()).getAnchorSceneLocation(); + Point end = targetAnchor.compute(widget.getTargetAnchorEntry()).getAnchorSceneLocation(); + + Widget sourceWidget = sourceAnchor.getRelatedWidget(); + Widget targetWidget = targetAnchor.getRelatedWidget(); + + + if(sourceWidget == targetWidget){//reflexive edges doesnt need any path + return Collections.emptyList(); + } + + + Point srcCenter = this.getSceneLocation(sourceWidget); + Point tarCenter = this.getSceneLocation(targetWidget); + + List widgetObstacles = new ArrayList<>(); + + if(collector != null){ + collector.collectCollisions(widgetObstacles); + } + + List obstacles = new ArrayList<>(widgetObstacles.size()); + this.collectObstacles(obstacles, widgetObstacles, widget); + + + List controlPoints = optimize(obstacles, srcCenter, tarCenter); +// size==2 => straight line +// size==3 => ensures a collision between cp0 and cp2 therefore its not possible to simplify it + if(controlPoints.size() > 3){ + Point rstart = this.computateAnchorPosition(sourceWidget, controlPoints.get(1)); + Point rend = this.computateAnchorPosition(targetWidget, controlPoints.get(controlPoints.size()-2)); + controlPoints.set(0, rstart); + controlPoints.set(controlPoints.size()-1, rend); + controlPoints = simplify(obstacles, controlPoints); + } else if (controlPoints.size()>=2){ + //use old points + controlPoints.set(0, start); + controlPoints.set(controlPoints.size()-1, end); + + } + return controlPoints; + } + + + private int collectObstacles(List colrects, List colwidgets , ConnectionWidget cw){ + int count=0; + Anchor sourceAnchor = cw.getSourceAnchor(); + Anchor targetAnchor = cw.getTargetAnchor(); + Widget sourceWidget = sourceAnchor.getRelatedWidget(); + Widget targetWidget = targetAnchor.getRelatedWidget(); + Point start = sourceAnchor.compute(cw.getSourceAnchorEntry()).getAnchorSceneLocation(); + Point end = targetAnchor.compute(cw.getTargetAnchorEntry()).getAnchorSceneLocation(); + + for(Widget w : colwidgets){ + + if(w==sourceWidget || w == targetWidget) continue; + + Rectangle r = w.convertLocalToScene(w.getBounds()); + r.grow(HEXPAND, VEXPAND); + if(r.intersectsLine(start.x,start.y,end.x,end.y)) + count++; + colrects.add(r); + } + return count; + } + + + private Point center (Rectangle bounds) { + return new Point (bounds.x + bounds.width / 2, bounds.y + bounds.height / 2); + } + + /** + * Returns the scene location of a related widget. + * bounds might be null if the widget was not added to the scene + * @return the scene location; null if no related widget is assigned + */ + public Point getSceneLocation (Widget relatedWidget) { + if (relatedWidget != null) { + Rectangle bounds = relatedWidget.getBounds (); + if(bounds != null) + return center(relatedWidget.convertLocalToScene(bounds)); + } + return null; + } + + /** + * Computates the Anchorposition like the Rectangular anchor for a + * given widget as source/target and a controlpoint as opposit anchorposition + */ + + private Point computateAnchorPosition(Widget relatedWidget, Point controlPoint) { + Rectangle bounds = relatedWidget.getBounds(); + + //todo: fix, center of widget must be cacluated trough the bounds + //since there are some wheird widgets where the location is not the center of the widget + Point relatedLocation = relatedWidget.getLocation();//center of the widget + + if (bounds.isEmpty () || relatedLocation.equals (controlPoint)) + return relatedLocation; + + float dx = controlPoint.x - relatedLocation.x; + float dy = controlPoint.y - relatedLocation.y; + + float ddx = Math.abs (dx) / (float) bounds.width; + float ddy = Math.abs (dy) / (float) bounds.height; + + float scale = 0.5f / Math.max (ddx, ddy); + + Point point = new Point (Math.round (relatedLocation.x + scale * dx), + Math.round (relatedLocation.y + scale * dy)); + return point; + } + + private List simplify(List obstacles, List list) { + 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); + for (int j = i; j < list.size(); j++) { + Point cur = list.get(j); + if (!intersects(obstacles, prev, cur)) { + i = j; + } + } + result.add(list.get(i)); + } + return result; + } + + private List optimize(List nodeWidgets, Point start, Point end) { + + List list = new ArrayList<>(); + list.add(start); + list.add(end); + + boolean progress = true; + + for (int j = 0; progress && j < NUMBER_OF_ITERATIONS ; j++) { + progress = false; + List newList = new ArrayList<>(); + for (int i = 0; i < list.size() - 1 ; i++) { + Point cur = list.get(i); + Point next = list.get(i + 1); + newList.add(cur); + List intermediate = optimizeLine(nodeWidgets, cur, next); + if (intermediate != null && intermediate.size() > 0) { + progress = true; + newList.addAll(intermediate);//insert new controlpoints between cur and next + } + } + newList.add(list.get(list.size()-1));//add endpoint of the polyline + list = newList; + + } + + return list; + } + + + /** + * trys to optimize a line from p1 to p2 to avoid collisions with rectangles + * returns null if the line doesn`t intersect with any nodewidget or + * if the obstacles are overlapping + * ---------------------------------------------------------------------- + * if the collision is solved it returns a list with immediate points + * between p1 and p2. The points are taken from hull points of and grown + * rectangle. + */ + private List optimizeLine(List obstacles, Point p1, Point p2) { + Line2D line = new Line2D.Double(p1, p2); + boolean inbounds=false; + Rectangle ibr=null; + ArrayList sol = new ArrayList<>(); + boolean leftIntersection; + boolean rightIntersection; + boolean bottomIntersection; + boolean topIntersection; + Point interLeft=new Point(); + Point interRight=new Point(); + Point interBot=new Point(); + Point interTop=new Point(); + + + + for(Rectangle r : obstacles ) { + if (!line.intersects(r)) continue; + + int w=r.width+2; + int h=r.height+2; + Point topLeft = r.getLocation(); + topLeft.x-=1; + topLeft.y-=1; + Point topRight = new Point(topLeft.x+w, topLeft.y); + Point bottomLeft = new Point(topLeft.x, topLeft.y+h); + Point bottomRight = new Point(topRight.x, bottomLeft.y); + leftIntersection = findIntersectionPoint(p1, p2, topLeft, bottomLeft, interLeft); + rightIntersection = findIntersectionPoint(p1, p2, topRight, bottomRight, interRight); + bottomIntersection = findIntersectionPoint(p1, p2, bottomLeft, bottomRight, interBot); + topIntersection = findIntersectionPoint(p1, p2, topLeft, topRight, interTop); + + //Intersection points are not used yet. This could be actually a + //good approach to avoid additional collisions because it would be + //still the same vector. + + if(leftIntersection) { + if(topIntersection) {//left and top + sol.add(topLeft); + } + else if(bottomIntersection){//left and bottom + sol.add(bottomLeft); + } + else if(rightIntersection){//left and right + double disttl = topLeft.distance(p1); + double distbl = bottomLeft.distance(p1); + if(disttl > distbl){ + //pass at the bottom + double distbr = bottomRight.distance(p1); + if(distbl < distbr){ + //from the left to the right + sol.add(bottomLeft); + sol.add(bottomRight); + } else { + //from the right to the left + sol.add(bottomRight); + sol.add(bottomLeft); + } + } else { + //pass at the top + double disttr = topRight.distance(p1); + if(disttl < disttr){ + //from the left to the right + sol.add(topLeft); + sol.add(topRight); + } else { + //from the right to the left + sol.add(topRight); + sol.add(topLeft); + } + } + } else {//only left => inside bounds + inbounds=true; + } + } else if (rightIntersection) { + if(topIntersection) {//right and top + sol.add(topRight); + } + else if(bottomIntersection){//right and bottom + sol.add(bottomRight); + } else { //only right => inside the bounds + inbounds=true; + } + } else if (topIntersection && bottomIntersection) {//top and bottom + double disttop = interTop.distance(p1); + double distbot = interBot.distance(p1); + if(disttop < distbot ){ + //from the top to the bottom + double distleft = interTop.distance(topLeft); + double distright = interTop.distance(topRight); + if(distleft < distright){ + //pass left + sol.add(topLeft); + sol.add(bottomLeft); + } else { + //pass right + sol.add(topRight); + sol.add(bottomRight); + } + } else { + //from the bottom to the top + double distleft = interBot.distance(bottomLeft); + double distright = interBot.distance(bottomRight); + if(distleft < distright){ + //pass left + sol.add(bottomLeft); + sol.add(topLeft); + } else { + //pass right + sol.add(bottomRight); + sol.add(topRight); + } + } + } else {//only bottom or only top + inbounds=true; + } /* ENDIF */ + + //breakpoint <-- collision detected + + if(sol.size()>0) {//solution found + assert(!inbounds); + return sol; + } else { //no solution found=> inbounds + assert(inbounds); + assert(sol.size()==0); + //handle collision or just skip it and search for the next collisionj + ibr=r; + //jump out of the loop to able to interate over the obstacles + break; + } + }/* end foreach obstacle */ + + if(inbounds || ibr != null){ + assert(inbounds); + assert(ibr!=null); + } + return null;//no collison found + }/* end optimizeLine */ + + + + //check intersection between line p0->p1 for a given set of obstacles + private static boolean intersects(List obstacles, Point p0, Point p1) { + for(Rectangle r : obstacles){ + if(r.intersectsLine(p0.x, p0.y, p1.x, p1.y)) + return true; + } + return false; + } + + + private boolean findIntersectionPoint( + Point p0, Point p1, Point p2, Point p3, Point pI) { + float q = (p0.y - p2.y)*(p3.x - p2.x) - (p0.x - p2.x)*(p3.y - p2.y); + float d = (p1.x - p0.x)*(p3.y - p2.y) - (p1.y - p0.y)*(p3.x - p2.x); + + //parallel ? + if(d==0) return false; + + float r = q / d; + q = (p0.y - p2.y)*(p1.x - p0.x) - (p0.x - p2.x)*(p1.y - p0.y); + + float s = q / d; + if(r<0 || r>1 || s<0 || s>1) return false; + + pI.x = p0.x + (int) (0.5f + r * (p1.x - p0.x)); + pI.y = p0.y + (int) (0.5f + r * (p1.y - p0.y)); + return true; + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/visual/SplineConnectionWidget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/visual/SplineConnectionWidget.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,541 @@ +package at.ssw.visualizer.cfg.visual; + +import org.netbeans.api.visual.widget.ConnectionWidget; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Shape; +import java.awt.geom.AffineTransform; +import java.awt.geom.CubicCurve2D; +import java.awt.geom.GeneralPath; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; +import java.util.List; +import org.netbeans.api.visual.anchor.AnchorShape; +import org.netbeans.api.visual.graph.GraphScene; +import org.netbeans.api.visual.widget.Scene; +import org.netbeans.api.visual.widget.Widget; + + +/** + * In comparison to the default ConnectionWidget this class is able to connect + * widgets with a curve instead of a straight line sequence. + * In conjunction with a suitable router the connection will be a straight line + * or a curve depending on the amount and the position of the controlpoints. + * Controlpoints supplied by the router, are treated as curve intersection points. + * For Reflexive edges the router doesn`t necessarily need to supply + * any controlpoints, they get painted by this automatically, this can be + * excepted if the router supplys more as 2 control points for a self edge, + * then the edge gets painted with the default curve interpolation algorithm. + * The method used for drawing curves uses a piecewise cubic interpolation + * algorithm. Between two control points a curve is painted as cubic bezier + * curve the, inner bezier points are calculated automatically with FMILL + * tangents and a chord parametrization, this interpolant is also known as + * cutmull-rom spline. The resulting spline fullfills c^1 continuity. + * The the end points the interpolation algorithm uses the bessel end condition. + */ + +public class SplineConnectionWidget extends ConnectionWidget { + private static final double ENDPOINT_DEVIATION = 3;//curve endpoint approximation accuracy + private static final double HIT_DISTANCE_SQUARE = 4.0;//distance for intersection test + private GraphScene scene=null; + private Point2D [] bezierPoints = null; + + public SplineConnectionWidget(Scene scene) { + super(scene); + if(scene instanceof GraphScene) + this.scene=(GraphScene) scene; + } + + //check for self - edge + private boolean isReflexive(){ + return getSourceAnchor().getRelatedWidget() == getTargetAnchor().getRelatedWidget(); + } + + + @Override + protected Rectangle calculateClientArea() { + + Rectangle bounds = null; + + if(this.getControlPoints().size()>2){ + bezierPoints = createBezierPoints(getControlPoints()); + } + //minmax method - returns the smallest bounding rectangle + //Curves and surfaces for CAGD (3rd ed.), p.54 + //exact calculation of the bounding min rect + if(bezierPoints != null) { + Rectangle2D bounds2D = null; + for (int i = 0; i < bezierPoints.length; i++) { + Point2D point = bezierPoints[i]; + if(bounds2D==null) + bounds2D = new Rectangle2D.Double(point.getX(),point.getY(),0,0); + else + bounds2D.add(point); + } + bounds = bounds2D.getBounds(); + bounds.grow(2, 2); + + } else if (getControlPoints().size()>0){ + for(Point p : this.getControlPoints()){ + if(bounds==null) + bounds = new Rectangle(p); + else + bounds.add(p); + } + bounds.grow(5,5); + + } else if (isReflexive()) { + Widget related = this.getTargetAnchor().getRelatedWidget(); + bounds = related.convertLocalToScene(related.getBounds()); + bounds.grow(10, 10); + } + + if(bounds==null) + bounds = super.calculateClientArea(); + + return bounds; + } + + + /** + * if the edge is reflexive its painted as a cyclic self edge, if there + * are two controlpoints the connection is painted as a straight line from + * the source to the targetanchor, if there are more as 2 controlpoints the + * connection path between two control points is painted as cutmull rom + * spline with bessel end tangents. + */ + @Override + protected void paintWidget () { + List contrPoints = this.getControlPoints(); + int listSize = contrPoints.size(); + + Graphics2D gr = getGraphics (); + + if (listSize <= 2) { + this.bezierPoints=null;//set bezier Points null for calulateClientArea() + if(isReflexive()) { //special case for reflexive connection widgets + this.drawReflexive(gr); + } else { + super.paintWidget(); + } + return; + } + + //bezier curve... listSize > 2 + GeneralPath curvePath = new GeneralPath(); + double lastControlPointRotation = 0.0; + + + Point2D [] bezPoints = this.createBezierPoints(contrPoints); + curvePath.moveTo(bezPoints[0].getX(), bezPoints[0].getY());//b00 + + //last segment is added by subdivision thats why its -5 + for (int i = 1; i < bezPoints.length-5; i+=3) { + curvePath.curveTo( + bezPoints[i].getX(), bezPoints[i].getY(),//b1i + bezPoints[i+1].getX(), bezPoints[i+1].getY(),//b2i + bezPoints[i+2].getX(), bezPoints[i+2].getY());//b3i + + } + + GeneralPath lastseg = subdivide2D( + bezPoints[bezPoints.length-4], + bezPoints[bezPoints.length-3], + bezPoints[bezPoints.length-2], + bezPoints[bezPoints.length-1]); + + + if(lastseg != null) + curvePath.append(lastseg, true); + + Point2D cur = curvePath.getCurrentPoint(); + Point lastControlPoint = contrPoints.get(listSize-1); + + lastControlPointRotation = //anchor anchorAngle + Math.atan2 (cur.getY() - lastControlPoint.y, cur.getX() - lastControlPoint.x); + + gr.setStroke(getStroke()); + gr.setColor(getLineColor()); + gr.draw(curvePath); + + + AffineTransform previousTransform = gr.getTransform (); + gr.translate (lastControlPoint.x, lastControlPoint.y); + gr.rotate (lastControlPointRotation); + AnchorShape targetAnchorShape = this.getTargetAnchorShape(); + targetAnchorShape.paint (gr, false); + gr.setTransform (previousTransform); + + //paint ControlPoints if enabled + if (isPaintControlPoints()) { + int last = listSize - 1; + for (int index = 0; index <= last; index ++) { + Point point = contrPoints.get (index); + previousTransform = gr.getTransform (); + gr.translate (point.x, point.y); + if (index == 0 || index == last) + getEndPointShape().paint (gr); + else + getControlPointShape().paint (gr); + gr.setTransform (previousTransform); + } + + } + } + + private void drawReflexive(Graphics2D gr){ + Widget related = this.getTargetAnchor().getRelatedWidget(); + int position = this.edgeBalance(related); + Rectangle bounds = related.convertLocalToScene(related.getBounds()); + gr.setColor (getLineColor()); + Point first = new Point(); + Point last = new Point(); + double centerX = bounds.getCenterX(); + first.x = (int) (centerX + bounds.width / 4); + first.y = bounds.y + bounds.height; + last.x = first.x; + last.y = bounds.y; + + gr.setStroke(this.getStroke()); + + double cutDistance = this.getTargetAnchorShape().getCutDistance(); + double anchorAngle = Math.PI/-3.0; + double cutX = Math.abs(Math.cos(anchorAngle)*cutDistance); + double cutY = Math.abs(Math.sin(anchorAngle)*cutDistance); + int ydiff=first.y-last.y; + int endy = -ydiff; + double height=bounds.getHeight(); + double cy = height/4.0; + double cx=bounds.getWidth()/5.0; + double dcx = cx*2; + GeneralPath gp = new GeneralPath(); + gp.moveTo(0, 0); + gp.quadTo(0, cy, cx, cy); + gp.quadTo(dcx, cy, dcx, -height/2.0); + gp.quadTo(dcx, endy - cy, cy, -(cy+ydiff)); + gp.quadTo(cutX*1.5, endy - cy, cutX, endy-cutY); + + AffineTransform af = new AffineTransform(); + AnchorShape anchorShape = this.getTargetAnchorShape(); + + if(position < 0) { + first.x = (int) (centerX - bounds.width / 4); + af.translate(first.x, first.y); + af.scale(-1.0, 1.0); + last.x = first.x; + } else { + af.translate(first.x, first.y); + } + Shape s = gp.createTransformedShape(af); + gr.draw(s); + + if (last != null) { + AffineTransform previousTransform = gr.getTransform (); + gr.translate (last.x, last.y); + + if(position < 0) + gr.rotate(Math.PI - anchorAngle); + else + gr.rotate (anchorAngle); + + anchorShape.paint (gr, false); + gr.setTransform (previousTransform); + } + } + + //returns prefered location for an edge -1 for left and 1 for right + private int edgeBalance(Widget nodeWidget) { + if(scene == null) + return 1; + + Point nodeLocation = nodeWidget.getLocation(); + int left = 0, right = 0; + + Object node = scene.findObject(nodeWidget); + + for(Object e : scene.findNodeEdges(node, true, true)) {//inputedges + ConnectionWidget cw = (ConnectionWidget) scene.findWidget(e); + + if(cw != this) { + Widget targetNodeWidget = cw.getTargetAnchor().getRelatedWidget(); + + Point location; + if(targetNodeWidget == nodeWidget) { + Widget sourceNodeWidget = cw.getSourceAnchor().getRelatedWidget(); + location = sourceNodeWidget.getLocation(); + } else { + location = targetNodeWidget.getLocation(); + } + + if(location.x < nodeLocation.x) + left++; + else + right++; + } + } + if(left < right) + return -1; + else + return 1; + } + + + private Point2D[] createBezierPoints(List list){ + if(list.size()<3) return null ; + + + int lastIdx = list.size()-1; + + + //chord length parametrization + double[] uis = new double[list.size()]; + uis[0]=0; + uis[1] = list.get(1).distance(list.get(0)); + for (int i = 1; i < uis.length; i++) { + Point cur = list.get(i); + Point prev = list.get(i-1); + uis[i]=uis[i-1]+ cur.distance(prev); + } + + + for (int i = 1; i < uis.length; i++) { + uis[i] /= uis[lastIdx]; + + } + double[] delta = new double[uis.length-1]; + for (int i = 0; i < delta.length; i++) { + double ui = uis[i]; + double uin = uis[i+1]; + delta[i] = uin-ui; + } + + + //FMILL tangent directions (chord length) + Point2D[] tangents = new Point2D[list.size()]; + + for (int i = 1; i < list.size()-1; i++) { + Point xBefore = list.get(i-1); + Point xAfter = list.get(i+1); + Point2D.Double tangent = new Point2D.Double (xAfter.x - xBefore.x, xAfter.y - xBefore.y); + tangents[i] = tangent; + } + + + Point2D [] bezPoints = new Point2D[(list.size()-1)*2+list.size()]; + //Catmull-Rom + for (int i = 1; i < list.size()-1; i++) { + Point b3i = list.get(i); + Point2D b3ib = b3iBefore(b3i, delta[i-1], delta[i], tangents[i]); + Point2D b3ia = b3iAfter(b3i, delta[i-1], delta[i], tangents[i]); + bezPoints[3*i] = b3i; + bezPoints[3*i-1] = b3ib; + bezPoints[3*i+1] = b3ia; + } + bezPoints[0] = list.get(0); + bezPoints[bezPoints.length-1] = list.get(list.size()-1); + + Point p0 = list.get(0); + Point p1 = list.get(1); + Point p2 = list.get(2); + Point pL_2 = list.get(lastIdx-2); + Point pL_1 = list.get(lastIdx-1); + Point pL = list.get(lastIdx); + + Point2D m1 = besselTangent(delta[0], delta[1], p0, p1, p2); + Point2D m0 = besselEndTangent(p0, p1, delta[0], m1); + + Point2D mLb = besselTangent(delta[delta.length-2], delta[delta.length-1], + pL_2,pL_1, pL); + Point2D mL = besselEndTangent(pL_1, pL, delta[delta.length-1], mLb); + + Point2D scaleM0 = scale(normalize(m0), p0.distance(p1));//increase distx/distxl to make curve rounder at the end + Point2D scaleML = scale(normalize(mL), pL.distance(pL_1)); + //Catmull-Rom for bessel points + Point2D b30a = b3iAfter(p0, delta[0], delta[0],scaleM0); + Point2D b33b = b3iBefore(pL, delta[delta.length-1], delta[delta.length-1],scaleML); + + bezPoints[1] = b30a; + bezPoints[bezPoints.length-2] = b33b; + + return bezPoints; + } + + + + private static Point2D besselTangent(double delta_ib, double delta_i, Point2D p0, Point2D p1 , Point2D p2){ + double alpha_i = delta_ib/(delta_ib+delta_i); + + double x = (1-alpha_i)/delta_ib * (p1.getX() - p0.getX()) + + alpha_i/delta_i * (p2.getX()-p1.getX()); + double y = (1-alpha_i)/delta_ib * (p1.getY() - p0.getY()) + + alpha_i/delta_i * (p2.getY()-p1.getY()); + + return new Point2D.Double(x,y); + } + + private static Point2D besselEndTangent(Point2D p0, Point2D p1, double delta_u, Point2D m){ + double x = 2*((p1.getX()-p0.getX())/delta_u) - m.getX(); + double y = 2*((p1.getY()-p0.getY())/delta_u) - m.getY(); + return new Point2D.Double(x,y); + } + + private static Point2D b3iBefore(Point2D b3i, double delta_ib, double delta_i, Point2D li){ + double x = b3i.getX() - (delta_ib/(3*(delta_ib+delta_i)))*li.getX(); + double y = b3i.getY() - (delta_ib/(3*(delta_ib+delta_i)))*li.getY(); + return new Point.Double(x,y); + } + + private static Point2D b3iAfter(Point2D b3i, double delta_ib,double delta_i,Point2D li){ + double x = b3i.getX() + (delta_i/(3*(delta_ib+delta_i)))*li.getX(); + double y = b3i.getY() + (delta_i/(3*(delta_ib+delta_i)))*li.getY(); + return new Point.Double(x,y); + } + + + + + //returns length of vector v + private static double norm(Point2D v){ + return Math.sqrt(v.getX()*v.getX()+v.getY()*v.getY()); + } + + //returns unity vector of vector v + private static Point2D normalize(Point2D v){ + double norm = norm(v); + if(norm==0) return new Point2D.Double(v.getX(), v.getY()); + return new Point2D.Double(v.getX()/norm , v.getY()/norm); + } + + //scale vector to size of length + private static Point2D scale(Point2D v, double length){ + Point2D tmp = normalize(v); + return new Point2D.Double(tmp.getX()*length, tmp.getY()*length); + } + + + + private GeneralPath subdivide2D (Point2D b0, Point2D b1, Point2D b2, Point2D b3) { + //set 2nd intermediate point to endpoint + //we could actually use another "better" point if we like to have a smoother curve + + double cutDistance = getTargetAnchorShape().getCutDistance(); + double minDistance = cutDistance - ENDPOINT_DEVIATION; + /** + * if the cutDistance is valid the last segment of the curve + * gets reduced by subdivision until the distance of the endpoint(epDistance) + * satisfys the condition (cutDistance > epDistance > (cutDistance - ENDPOINT-DEVIATION) + */ + if(cutDistance > minDistance && minDistance > 0 ) { + GeneralPath path = new GeneralPath(); + + path.moveTo(b0.getX(), b0.getY()); + + CubicCurve2D.Double curve = new CubicCurve2D.Double( + b0.getX(), b0.getY(), + b1.getX(), b1.getY(), + b2.getX(), b2.getY(), + b3.getX(), b3.getY()); + + + + CubicCurve2D right=new CubicCurve2D.Double(); + CubicCurve2D left=new CubicCurve2D.Double(); + curve.subdivide(left, right); + double distance = b3.distance(left.getP2()); + //if the distance is bigger as the cutDistance the left segment is added + //and the right segment is divided again + while(distance>cutDistance){ + path.append(left, true); + right.subdivide(left, right); + distance = b3.distance(left.getP2()); + //if the devision removed to much the left segment is divided + while(distance < minDistance) { + //changes the distance to ~ (distance+distance/2) + left.subdivide(left, right); + distance = b3.distance(left.getP2()); + } + } + //append the last segment with (minDistance < distance < cutDistance) + path.append(left, true); + return path; + } + return null; + } + + + /** + * Returns whether a specified local point pL is a part of the connection + * widget. + * First it make a rough bounds check + * for Line Segments => use Super call (ConnectionWidget.isHitAt(pL)). + * for self-edges => its sufficent to return getBounds.contains(pL). + * for Splines => Interate over all Partitial segments of the curve and make + * a minmax check with the bezier points. If pL is inside the minmax + * rectangle of one segment the curve is constructed and subdivided until + * the distance d between center point pC (of the bounding rectangle) + * and pL is below HIT_DISTANCE_SQUARE, in this case it returns true. + * If no no minmax check was successful or the subdivision lead to an + * rectangle witch doesn`t contain pL return false. + * @param localLocation the local location + * @return true, if the location is a part of the connection widget + */ + @Override + public boolean isHitAt(Point localLocation) { + if(!isVisible() || !getBounds ().contains (localLocation)) + return false; + + List controlPoints = getControlPoints (); + if(controlPoints.size() <=2){ + if(isReflexive()) return true; + return super.isHitAt(localLocation); + } + + if(bezierPoints != null) { + for (int i = 0; i < bezierPoints.length-1; i+=3) { + Point2D b0 = bezierPoints[i]; + Point2D b1 = bezierPoints[i+1]; + Point2D b2 = bezierPoints[i+2]; + Point2D b3 = bezierPoints[i+3]; + + CubicCurve2D left = new CubicCurve2D.Double( + b0.getX(), b0.getY(), + b1.getX(), b1.getY(), + b2.getX(), b2.getY(), + b3.getX(), b3.getY()); + + + Rectangle2D bounds = left.getBounds2D(); + while(bounds.contains(localLocation)) { + //calculate the center and use HIT_DISTANCE_SQUARE for a range check + Point2D test = new Point2D.Double(bounds.getCenterX(),bounds.getCenterY()); + if(test.distance(localLocation) < HIT_DISTANCE_SQUARE){ + return true; + } + + + CubicCurve2D right = new CubicCurve2D.Double(); + left.subdivide(left, right); + Rectangle2D lb2d = left.getBounds2D(); + Rectangle2D rb2d = right.getBounds2D(); + if( lb2d.contains(localLocation)){ + bounds = lb2d; + } else if (rb2d.contains(localLocation)) { + left = right; + bounds = rb2d; + } else { + return false; + } + + }//end while + }//end for + } + return false; + } + + +} + + + + diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/visual/WidgetCollisionCollector.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/visual/WidgetCollisionCollector.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,12 @@ +package at.ssw.visualizer.cfg.visual; + +import java.util.List; +import org.netbeans.api.visual.widget.Widget; + + +public interface WidgetCollisionCollector { + + //returns a list of widgets which should be handled as obstacles + void collectCollisions(List collisions); + +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/build.xml --- a/src/share/tools/IdealGraphVisualizer/Coordinator/build.xml Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ - - - - - - Builds, tests, and runs the project com.sun.hotspot.igv.coordinator. - - diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/manifest.mf --- a/src/share/tools/IdealGraphVisualizer/Coordinator/manifest.mf Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -Manifest-Version: 1.0 -OpenIDE-Module: com.sun.hotspot.igv.coordinator -OpenIDE-Module-Layer: com/sun/hotspot/igv/coordinator/layer.xml -OpenIDE-Module-Localizing-Bundle: com/sun/hotspot/igv/coordinator/Bundle.properties -OpenIDE-Module-Specification-Version: 1.0 - diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/nbproject/build-impl.xml --- a/src/share/tools/IdealGraphVisualizer/Coordinator/nbproject/build-impl.xml Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ - - - - - - You must set 'suite.dir' to point to your containing module suite - - - - - - - - - - - - - - - - - - - - - diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/nbproject/genfiles.properties --- a/src/share/tools/IdealGraphVisualizer/Coordinator/nbproject/genfiles.properties Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -build.xml.data.CRC32=077de97c -build.xml.script.CRC32=d29d586c -build.xml.stylesheet.CRC32=79c3b980 -# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. -# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=077de97c -nbproject/build-impl.xml.script.CRC32=03daa42d -nbproject/build-impl.xml.stylesheet.CRC32=deb65f65 diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/nbproject/platform.properties --- a/src/share/tools/IdealGraphVisualizer/Coordinator/nbproject/platform.properties Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -# Deprecated since 5.0u1; for compatibility with 5.0: -disabled.clusters=\ - apisupport1,\ - harness,\ - ide8,\ - java1,\ - nb6.0,\ - profiler2 -disabled.modules=\ - org.netbeans.core.execution,\ - org.netbeans.core.multiview,\ - org.netbeans.core.output2,\ - org.netbeans.modules.applemenu,\ - org.netbeans.modules.autoupdate.services,\ - org.netbeans.modules.autoupdate.ui,\ - org.netbeans.modules.core.kit,\ - org.netbeans.modules.favorites,\ - org.netbeans.modules.javahelp,\ - org.netbeans.modules.masterfs,\ - org.netbeans.modules.options.keymap,\ - org.netbeans.modules.sendopts,\ - org.netbeans.modules.templates,\ - org.openide.compat,\ - org.openide.execution,\ - org.openide.util.enumerations -enabled.clusters=\ - platform7 -nbjdk.active=JDK_1.6 -nbplatform.active=default diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/nbproject/project.properties --- a/src/share/tools/IdealGraphVisualizer/Coordinator/nbproject/project.properties Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -javac.source=1.7 -javac.compilerargs=-Xlint -Xlint:-serial diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/nbproject/project.xml --- a/src/share/tools/IdealGraphVisualizer/Coordinator/nbproject/project.xml Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,142 +0,0 @@ - - - org.netbeans.modules.apisupport.project - - - com.sun.hotspot.igv.coordinator - - - - com.sun.hotspot.igv.connection - - - - 1.0 - - - - com.sun.hotspot.igv.data - - - - 1.0 - - - - com.sun.hotspot.igv.difference - - - - 1.0 - - - - com.sun.hotspot.igv.settings - - - - 1.0 - - - - com.sun.hotspot.igv.util - - - - 1.0 - - - - org.netbeans.api.progress - - - - 1 - 1.23.1 - - - - org.openide.actions - - - - 6.21.1 - - - - org.openide.awt - - - - 7.30.1 - - - - org.openide.dialogs - - - - 7.18.1 - - - - org.openide.explorer - - - - 6.34.1 - - - - org.openide.filesystems - - - - 7.46.1 - - - - org.openide.loaders - - - - 7.20.1 - - - - org.openide.nodes - - - - 7.20.1 - - - - org.openide.util - - - - 8.14.1 - - - - org.openide.util.lookup - - - - 8.6.1 - - - - org.openide.windows - - - - 6.39.1 - - - - - - - diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/nbproject/suite.properties --- a/src/share/tools/IdealGraphVisualizer/Coordinator/nbproject/suite.properties Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -suite.dir=${basedir}/.. diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/Bundle.properties --- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/Bundle.properties Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -AdvancedOption_DisplayName_Coordinator=Settings -AdvancedOption_Tooltip_Coordinator=Visualization Tool Settings -CTL_OutlineTopComponent=Outline -CTL_SomeAction=test -HINT_OutlineTopComponent=Displays loaded groups of graphs. -OpenIDE-Module-Name=Coordinator diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/FolderNode.java --- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/FolderNode.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ -package com.sun.hotspot.igv.coordinator; - -import com.sun.hotspot.igv.coordinator.actions.RemoveCookie; -import com.sun.hotspot.igv.data.*; -import java.awt.Image; -import java.util.List; -import org.openide.nodes.AbstractNode; -import org.openide.nodes.Children; -import org.openide.nodes.Node; -import org.openide.util.ImageUtilities; -import org.openide.util.lookup.AbstractLookup; -import org.openide.util.lookup.InstanceContent; - -/** - * - * @author Thomas Wuerthinger - */ -public class FolderNode extends AbstractNode { - - private InstanceContent content; - private FolderChildren children; - - private static class FolderChildren extends Children.Keys implements ChangedListener { - - private final Folder folder; - - public FolderChildren(Folder folder) { - this.folder = folder; - folder.getChangedEvent().addListener(this); - } - - @Override - protected Node[] createNodes(FolderElement e) { - if (e instanceof InputGraph) { - return new Node[]{new GraphNode((InputGraph) e)}; - } else if (e instanceof Folder) { - return new Node[]{new FolderNode((Folder) e)}; - } else { - return null; - } - } - - @Override - public void addNotify() { - this.setKeys(folder.getElements()); - } - - @Override - public void changed(Object source) { - addNotify(); - } - } - - @Override - public Image getIcon(int i) { - return ImageUtilities.loadImage("com/sun/hotspot/igv/coordinator/images/folder.png"); - } - - protected FolderNode(Folder folder) { - this(folder, new FolderChildren(folder), new InstanceContent()); - } - - private FolderNode(final Folder folder, FolderChildren children, InstanceContent content) { - super(children, new AbstractLookup(content)); - this.content = content; - this.children = children; - if (folder instanceof FolderElement) { - final FolderElement folderElement = (FolderElement) folder; - this.setDisplayName(folderElement.getName()); - content.add(new RemoveCookie() { - @Override - public void remove() { - folderElement.getParent().removeElement(folderElement); - } - }); - } - } - - public void init(String name, List groups) { - this.setDisplayName(name); - children.addNotify(); - - for (Group g : groups) { - content.add(g); - } - } - - @Override - public Image getOpenedIcon(int i) { - return getIcon(i); - } -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/GraphNode.java --- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/GraphNode.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ -package com.sun.hotspot.igv.coordinator; - -import com.sun.hotspot.igv.coordinator.actions.DiffGraphAction; -import com.sun.hotspot.igv.coordinator.actions.DiffGraphCookie; -import com.sun.hotspot.igv.coordinator.actions.GraphOpenCookie; -import com.sun.hotspot.igv.coordinator.actions.GraphRemoveCookie; -import com.sun.hotspot.igv.data.InputGraph; -import com.sun.hotspot.igv.data.Properties; -import com.sun.hotspot.igv.data.services.GraphViewer; -import com.sun.hotspot.igv.util.PropertiesSheet; -import java.awt.Image; -import javax.swing.Action; -import org.openide.actions.OpenAction; -import org.openide.nodes.AbstractNode; -import org.openide.nodes.Children; -import org.openide.nodes.Sheet; -import org.openide.util.ImageUtilities; -import org.openide.util.Lookup; -import org.openide.util.lookup.AbstractLookup; -import org.openide.util.lookup.InstanceContent; - -/** - * - * @author Thomas Wuerthinger - */ -public class GraphNode extends AbstractNode { - private final InputGraph graph; - - /** Creates a new instance of GraphNode */ - public GraphNode(InputGraph graph) { - this(graph, new InstanceContent()); - } - - private GraphNode(InputGraph graph, InstanceContent content) { - super(Children.LEAF, new AbstractLookup(content)); - this.graph = graph; - this.setDisplayName(graph.getName()); - content.add(graph); - - final GraphViewer viewer = Lookup.getDefault().lookup(GraphViewer.class); - - if (viewer != null) { - // Action for opening the graph - content.add(new GraphOpenCookie(viewer, graph)); - } - - // Action for removing a graph - content.add(new GraphRemoveCookie(graph)); - - // Action for diffing to the current graph - content.add(new DiffGraphCookie(graph)); - } - - @Override - protected Sheet createSheet() { - Sheet s = super.createSheet(); - Properties p = new Properties(); - p.add(graph.getProperties()); - p.setProperty("nodeCount", Integer.toString(graph.getNodes().size())); - p.setProperty("edgeCount", Integer.toString(graph.getEdges().size())); - PropertiesSheet.initializeSheet(p, s); - return s; - } - - @Override - public Image getIcon(int i) { - return ImageUtilities.loadImage("com/sun/hotspot/igv/coordinator/images/graph.png"); - } - - @Override - public Image getOpenedIcon(int i) { - return getIcon(i); - } - - @Override - public Action[] getActions(boolean b) { - return new Action[]{(Action) DiffGraphAction.findObject(DiffGraphAction.class, true), (Action) OpenAction.findObject(OpenAction.class, true)}; - } - - @Override - public Action getPreferredAction() { - return (Action) OpenAction.findObject(OpenAction.class, true); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof GraphNode) { - return (graph == ((GraphNode) obj).graph); - } - return false; - } - - @Override - public int hashCode() { - return graph.hashCode(); - } -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/OutlineTopComponent.form --- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/OutlineTopComponent.form Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/OutlineTopComponent.java --- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/OutlineTopComponent.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,241 +0,0 @@ -/* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ -package com.sun.hotspot.igv.coordinator; - -import com.sun.hotspot.igv.connection.Server; -import com.sun.hotspot.igv.coordinator.actions.*; -import com.sun.hotspot.igv.data.GraphDocument; -import com.sun.hotspot.igv.data.Group; -import com.sun.hotspot.igv.data.services.GroupCallback; -import java.awt.BorderLayout; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.io.Serializable; -import javax.swing.UIManager; -import javax.swing.border.Border; -import org.openide.ErrorManager; -import org.openide.actions.GarbageCollectAction; -import org.openide.awt.Toolbar; -import org.openide.awt.ToolbarPool; -import org.openide.explorer.ExplorerManager; -import org.openide.explorer.ExplorerUtils; -import org.openide.explorer.view.BeanTreeView; -import org.openide.util.LookupEvent; -import org.openide.util.LookupListener; -import org.openide.util.NbBundle; -import org.openide.util.actions.NodeAction; -import org.openide.windows.TopComponent; -import org.openide.windows.WindowManager; - -/** - * - * @author Thomas Wuerthinger - */ -public final class OutlineTopComponent extends TopComponent implements ExplorerManager.Provider, LookupListener { - - public static OutlineTopComponent instance; - public static final String PREFERRED_ID = "OutlineTopComponent"; - private ExplorerManager manager; - private GraphDocument document; - private FolderNode root; - private Server server; - - private OutlineTopComponent() { - initComponents(); - - setName(NbBundle.getMessage(OutlineTopComponent.class, "CTL_OutlineTopComponent")); - setToolTipText(NbBundle.getMessage(OutlineTopComponent.class, "HINT_OutlineTopComponent")); - - document = new GraphDocument(); - initListView(); - initToolbar(); - initReceivers(); - } - - private void initListView() { - manager = new ExplorerManager(); - root = new FolderNode(document); - manager.setRootContext(root); - ((BeanTreeView) this.treeView).setRootVisible(false); - - associateLookup(ExplorerUtils.createLookup(manager, getActionMap())); - } - - private void initToolbar() { - - Toolbar toolbar = new Toolbar(); - Border b = (Border) UIManager.get("Nb.Editor.Toolbar.border"); //NOI18N - toolbar.setBorder(b); - this.add(toolbar, BorderLayout.NORTH); - - toolbar.add(ImportAction.get(ImportAction.class)); - - toolbar.add(((NodeAction) SaveAsAction.get(SaveAsAction.class)).createContextAwareInstance(this.getLookup())); - toolbar.add(SaveAllAction.get(SaveAllAction.class)); - - toolbar.add(((NodeAction) RemoveAction.get(RemoveAction.class)).createContextAwareInstance(this.getLookup())); - toolbar.add(RemoveAllAction.get(RemoveAllAction.class)); - - toolbar.add(GarbageCollectAction.get(GarbageCollectAction.class).getToolbarPresenter()); - - for (Toolbar tb : ToolbarPool.getDefault().getToolbars()) { - tb.setVisible(false); - } - } - - private void initReceivers() { - - final GroupCallback callback = new GroupCallback() { - - @Override - public void started(Group g) { - getDocument().addElement(g); - } - }; - - server = new Server(callback); - } - - public void clear() { - document.clear(); - } - - @Override - public ExplorerManager getExplorerManager() { - return manager; - } - - public GraphDocument getDocument() { - return document; - } - - /** - * Gets default instance. Do not use directly: reserved for *.settings files only, - * i.e. deserialization routines; otherwise you could get a non-deserialized instance. - * To obtain the singleton instance, use {@link findInstance}. - */ - public static synchronized OutlineTopComponent getDefault() { - if (instance == null) { - instance = new OutlineTopComponent(); - } - return instance; - } - - /** - * Obtain the OutlineTopComponent instance. Never call {@link #getDefault} directly! - */ - public static synchronized OutlineTopComponent findInstance() { - TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID); - if (win == null) { - ErrorManager.getDefault().log(ErrorManager.WARNING, "Cannot find Outline component. It will not be located properly in the window system."); - return getDefault(); - } - if (win instanceof OutlineTopComponent) { - return (OutlineTopComponent) win; - } - ErrorManager.getDefault().log(ErrorManager.WARNING, "There seem to be multiple components with the '" + PREFERRED_ID + "' ID. That is a potential source of errors and unexpected behavior."); - return getDefault(); - } - - @Override - public int getPersistenceType() { - return TopComponent.PERSISTENCE_ALWAYS; - } - - @Override - public void componentOpened() { - this.requestActive(); - } - - @Override - public void componentClosed() { - } - - @Override - protected String preferredID() { - return PREFERRED_ID; - } - - @Override - public void requestActive() { - super.requestActive(); - treeView.requestFocus(); - } - - @Override - public boolean requestFocus(boolean temporary) { - treeView.requestFocus(); - return super.requestFocus(temporary); - } - - @Override - protected boolean requestFocusInWindow(boolean temporary) { - treeView.requestFocus(); - return super.requestFocusInWindow(temporary); - } - - @Override - public void resultChanged(LookupEvent lookupEvent) { - } - - @Override - public void readExternal(ObjectInput objectInput) throws IOException, ClassNotFoundException { - // Not called when user starts application for the first time - super.readExternal(objectInput); - ((BeanTreeView) this.treeView).setRootVisible(false); - } - - @Override - public void writeExternal(ObjectOutput objectOutput) throws IOException { - super.writeExternal(objectOutput); - } - - static final class ResolvableHelper implements Serializable { - - private static final long serialVersionUID = 1L; - - public Object readResolve() { - return OutlineTopComponent.getDefault(); - } - } - - /** This method is called from within the constructor to - * initialize the form. - * WARNING: Do NOT modify this code. The content of this method is - * always regenerated by the Form Editor. - */ - // //GEN-BEGIN:initComponents - private void initComponents() { - - treeView = new BeanTreeView(); - - setLayout(new java.awt.BorderLayout()); - add(treeView, java.awt.BorderLayout.CENTER); - }// //GEN-END:initComponents - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JScrollPane treeView; - // End of variables declaration//GEN-END:variables -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/OutlineTopComponentSettings.xml --- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/OutlineTopComponentSettings.xml Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ - - - - - - - - diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/OutlineTopComponentWstcref.xml --- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/OutlineTopComponentWstcref.xml Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ - - - - - - - diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/StandardConfiguration.xml --- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/StandardConfiguration.xml Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/Bundle.properties --- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/Bundle.properties Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -CTL_ImportAction=Open... -CTL_OpenGraphAction=View graph -CTL_DiffGraphAction=Difference to current graph -CTL_RemoveAction=Remove selected graphs and groups -CTL_RemoveAllAction=Remove all graphs and groups -CTL_OutlineAction=Outline -CTL_SaveAsAction=Save selected groups... -CTL_SaveAllAction=Save all groups... -CTL_PropertiesAction=Open Properties Window -CTL_NewFilterAction=New filter... diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/DiffGraphAction.java --- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/DiffGraphAction.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ - -package com.sun.hotspot.igv.coordinator.actions; - -import org.openide.nodes.Node; -import org.openide.util.HelpCtx; -import org.openide.util.NbBundle; -import org.openide.util.actions.CookieAction; - -/** - * - * @author Thomas Wuerthinger - */ -public final class DiffGraphAction extends CookieAction { - - @Override - protected void performAction(Node[] activatedNodes) { - DiffGraphCookie c = activatedNodes[0].getCookie(DiffGraphCookie.class); - assert c != null; - c.openDiff(); - } - - @Override - protected int mode() { - return CookieAction.MODE_EXACTLY_ONE; - } - - @Override - protected boolean enable(Node[] activatedNodes) { - boolean b = super.enable(activatedNodes); - if (b) { - assert activatedNodes.length == 1; - DiffGraphCookie c = activatedNodes[0].getCookie(DiffGraphCookie.class); - assert c != null; - return c.isPossible(); - } - - return false; - } - - @Override - public String getName() { - return NbBundle.getMessage(DiffGraphAction.class, "CTL_DiffGraphAction"); - } - - @Override - protected Class[] cookieClasses() { - return new Class[]{ - DiffGraphCookie.class - }; - } - - @Override - protected String iconResource() { - return "com/sun/hotspot/igv/coordinator/images/diff.png"; - } - - @Override - public HelpCtx getHelpCtx() { - return HelpCtx.DEFAULT_HELP; - } - - @Override - protected boolean asynchronous() { - return false; - } -} - diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/DiffGraphCookie.java --- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/DiffGraphCookie.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ -package com.sun.hotspot.igv.coordinator.actions; - -import com.sun.hotspot.igv.data.InputGraph; -import com.sun.hotspot.igv.data.services.GraphViewer; -import com.sun.hotspot.igv.data.services.InputGraphProvider; -import com.sun.hotspot.igv.difference.Difference; -import com.sun.hotspot.igv.util.LookupHistory; -import org.openide.nodes.Node; -import org.openide.util.Lookup; - -/** - * - * @author Thomas Wuerthinger - */ -public class DiffGraphCookie implements Node.Cookie { - - private InputGraph graph; - - public DiffGraphCookie(InputGraph graph) { - this.graph = graph; - } - - private InputGraph getCurrentGraph() { - InputGraphProvider graphProvider = LookupHistory.getLast(InputGraphProvider.class); - if (graphProvider != null) { - return graphProvider.getGraph(); - } - return null; - } - - public boolean isPossible() { - return getCurrentGraph() != null; - } - - public void openDiff() { - InputGraph other = getCurrentGraph(); - final GraphViewer viewer = Lookup.getDefault().lookup(GraphViewer.class); - if (viewer != null) { - InputGraph diffGraph = Difference.createDiffGraph(other, graph); - viewer.view(diffGraph); - } - } -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/GraphOpenCookie.java --- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/GraphOpenCookie.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ -package com.sun.hotspot.igv.coordinator.actions; - -import com.sun.hotspot.igv.data.InputGraph; -import com.sun.hotspot.igv.data.services.GraphViewer; -import org.openide.cookies.OpenCookie; - -public class GraphOpenCookie implements OpenCookie { - - private final GraphViewer viewer; - private final InputGraph graph; - - public GraphOpenCookie(GraphViewer viewer, InputGraph graph) { - this.viewer = viewer; - this.graph = graph; - } - - @Override - public void open() { - viewer.view(graph); - } -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/GraphRemoveCookie.java --- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/GraphRemoveCookie.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ -package com.sun.hotspot.igv.coordinator.actions; - -import com.sun.hotspot.igv.data.InputGraph; - -public class GraphRemoveCookie implements RemoveCookie { - private final InputGraph graph; - - public GraphRemoveCookie(InputGraph graph) { - this.graph = graph; - } - - @Override - public void remove() { - graph.getGroup().removeElement(graph); - } -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/ImportAction.java --- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/ImportAction.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,184 +0,0 @@ -/* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ - -package com.sun.hotspot.igv.coordinator.actions; - -import com.sun.hotspot.igv.coordinator.OutlineTopComponent; -import com.sun.hotspot.igv.data.GraphDocument; -import com.sun.hotspot.igv.data.serialization.Parser; -import com.sun.hotspot.igv.data.serialization.XMLParser; -import com.sun.hotspot.igv.settings.Settings; -import java.awt.event.InputEvent; -import java.awt.event.KeyEvent; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import javax.swing.Action; -import javax.swing.JFileChooser; -import javax.swing.KeyStroke; -import javax.swing.SwingUtilities; -import javax.swing.filechooser.FileFilter; -import org.netbeans.api.progress.ProgressHandle; -import org.netbeans.api.progress.ProgressHandleFactory; -import org.openide.DialogDisplayer; -import org.openide.NotifyDescriptor; -import org.openide.util.HelpCtx; -import org.openide.util.NbBundle; -import org.openide.util.RequestProcessor; -import org.openide.util.actions.CallableSystemAction; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -/** - * - * @author Thomas Wuerthinger - */ -public final class ImportAction extends CallableSystemAction { - - public static FileFilter getFileFilter() { - return new FileFilter() { - - @Override - public boolean accept(File f) { - return f.getName().toLowerCase().endsWith(".xml") || f.isDirectory(); - } - - @Override - public String getDescription() { - return "XML files (*.xml)"; - } - }; - } - - @Override - public void performAction() { - - JFileChooser fc = new JFileChooser(); - fc.setFileFilter(ImportAction.getFileFilter()); - fc.setCurrentDirectory(new File(Settings.get().get(Settings.DIRECTORY, Settings.DIRECTORY_DEFAULT))); - - if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { - File file = fc.getSelectedFile(); - - File dir = file; - if (!dir.isDirectory()) { - dir = dir.getParentFile(); - } - - Settings.get().put(Settings.DIRECTORY, dir.getAbsolutePath()); - - try { - final FileInputStream inputStream = new FileInputStream(file); - final InputSource is = new InputSource(inputStream); - - final ProgressHandle handle = ProgressHandleFactory.createHandle("Opening file " + file.getName()); - final int basis = 1000; - handle.start(basis); - final int start = inputStream.available(); - - final XMLParser.ParseMonitor parseMonitor = new XMLParser.ParseMonitor() { - - @Override - public void setProgress(double d) { - try { - int curAvailable = inputStream.available(); - int prog = (int) (basis * (double) (start - curAvailable) / (double) start); - handle.progress(prog); - } catch (IOException ex) { - } - } - - @Override - public void setState(String state) { - setProgress(0.0); - handle.progress(state); - } - }; - final Parser parser = new Parser(); - final OutlineTopComponent component = OutlineTopComponent.findInstance(); - - component.requestActive(); - - RequestProcessor.getDefault().post(new Runnable() { - - @Override - public void run() { - try { - final GraphDocument document = parser.parse(is, parseMonitor); - parseMonitor.setState("Finishing"); - SwingUtilities.invokeLater(new Runnable(){ - - @Override - public void run() { - component.getDocument().addGraphDocument(document); - } - }); - } catch (SAXException ex) { - String s = "Exception during parsing the XML file, could not load document!"; - if (ex instanceof XMLParser.MissingAttributeException) { - XMLParser.MissingAttributeException e = (XMLParser.MissingAttributeException) ex; - s += "\nMissing attribute \"" + e.getAttributeName() + "\""; - } - ex.printStackTrace(); - NotifyDescriptor d = new NotifyDescriptor.Message(s, NotifyDescriptor.ERROR_MESSAGE); - DialogDisplayer.getDefault().notify(d); - } - handle.finish(); - } - }); - - } catch (FileNotFoundException ex) { - ex.printStackTrace(); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - } - - @Override - public String getName() { - return NbBundle.getMessage(ImportAction.class, "CTL_ImportAction"); - } - - public ImportAction() { - putValue(Action.SHORT_DESCRIPTION, "Open XML graph document..."); - putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK)); - } - - @Override - protected String iconResource() { - return "com/sun/hotspot/igv/coordinator/images/import.png"; - } - - @Override - public HelpCtx getHelpCtx() { - return HelpCtx.DEFAULT_HELP; - } - - @Override - protected boolean asynchronous() { - return false; - } -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/OutlineAction.java --- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/OutlineAction.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ - -package com.sun.hotspot.igv.coordinator.actions; - -import com.sun.hotspot.igv.coordinator.OutlineTopComponent; -import java.awt.event.ActionEvent; -import javax.swing.AbstractAction; -import org.openide.util.NbBundle; -import org.openide.windows.TopComponent; - -/** - * - * @author Thomas Wuerthinger - */ -public class OutlineAction extends AbstractAction { - - public OutlineAction() { - super(NbBundle.getMessage(OutlineAction.class, "CTL_OutlineAction")); - } - - @Override - public void actionPerformed(ActionEvent evt) { - TopComponent win = OutlineTopComponent.findInstance(); - win.open(); - win.requestActive(); - } -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/RemoveAction.java --- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/RemoveAction.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ - -package com.sun.hotspot.igv.coordinator.actions; - -import javax.swing.Action; -import org.openide.nodes.Node; -import org.openide.util.HelpCtx; -import org.openide.util.NbBundle; -import org.openide.util.actions.NodeAction; - -/** - * - * @author Thomas Wuerthinger - */ -public final class RemoveAction extends NodeAction { - - @Override - protected void performAction(Node[] activatedNodes) { - for (Node n : activatedNodes) { - RemoveCookie removeCookie = n.getCookie(RemoveCookie.class); - if (removeCookie != null) { - removeCookie.remove(); - } - } - } - - public RemoveAction() { - putValue(Action.SHORT_DESCRIPTION, "Remove selected graphs and groups"); - } - - @Override - public String getName() { - return NbBundle.getMessage(RemoveAction.class, "CTL_RemoveAction"); - } - - @Override - protected String iconResource() { - return "com/sun/hotspot/igv/coordinator/images/remove.png"; - } - - @Override - public HelpCtx getHelpCtx() { - return HelpCtx.DEFAULT_HELP; - } - - @Override - protected boolean asynchronous() { - return false; - } - - @Override - protected boolean enable(Node[] nodes) { - return nodes.length > 0; - } -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/RemoveAllAction.java --- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/RemoveAllAction.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -/* - * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.sun.hotspot.igv.coordinator.actions; - -import com.sun.hotspot.igv.coordinator.OutlineTopComponent; -import java.awt.event.InputEvent; -import java.awt.event.KeyEvent; -import javax.swing.Action; -import javax.swing.KeyStroke; -import org.openide.util.HelpCtx; -import org.openide.util.NbBundle; -import org.openide.util.actions.CallableSystemAction; - -/** - * - * @author Thomas Wuerthinger - */ -public final class RemoveAllAction extends CallableSystemAction { - - - @Override - public String getName() { - return NbBundle.getMessage(RemoveAllAction.class, "CTL_RemoveAllAction"); - } - - public RemoveAllAction() { - putValue(Action.SHORT_DESCRIPTION, "Remove all graphs and groups"); - putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_SHIFT, InputEvent.CTRL_MASK)); - } - - @Override - protected String iconResource() { - return "com/sun/hotspot/igv/coordinator/images/removeall.png"; - } - - @Override - public HelpCtx getHelpCtx() { - return HelpCtx.DEFAULT_HELP; - } - - @Override - protected boolean asynchronous() { - return false; - } - - @Override - public void performAction() { - OutlineTopComponent.findInstance().clear(); - } -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/RemoveCookie.java --- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/RemoveCookie.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -/* - * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.hotspot.igv.coordinator.actions; - -import org.openide.nodes.Node; - -/** - * - * @author Thomas Wuerthinger - */ -public interface RemoveCookie extends Node.Cookie { - void remove(); -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/SaveAllAction.java --- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/SaveAllAction.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -/* - * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.sun.hotspot.igv.coordinator.actions; - -import com.sun.hotspot.igv.coordinator.OutlineTopComponent; -import java.awt.event.InputEvent; -import java.awt.event.KeyEvent; -import javax.swing.Action; -import javax.swing.KeyStroke; -import org.openide.util.HelpCtx; -import org.openide.util.NbBundle; -import org.openide.util.actions.CallableSystemAction; - -/** - * - * @author Thomas Wuerthinger - */ -public final class SaveAllAction extends CallableSystemAction { - - @Override - public void performAction() { - final OutlineTopComponent component = OutlineTopComponent.findInstance(); - SaveAsAction.save(component.getDocument()); - } - - @Override - public String getName() { - return NbBundle.getMessage(SaveAllAction.class, "CTL_SaveAllAction"); - } - - public SaveAllAction() { - putValue(Action.SHORT_DESCRIPTION, "Save all groups to XML file..."); - putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK)); - } - - @Override - protected String iconResource() { - return "com/sun/hotspot/igv/coordinator/images/saveall.gif"; - } - - @Override - public HelpCtx getHelpCtx() { - return HelpCtx.DEFAULT_HELP; - } - - @Override - protected boolean asynchronous() { - return false; - } -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/SaveAsAction.java --- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/SaveAsAction.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ - -package com.sun.hotspot.igv.coordinator.actions; - -import com.sun.hotspot.igv.data.GraphDocument; -import com.sun.hotspot.igv.data.Group; -import com.sun.hotspot.igv.data.serialization.Printer; -import com.sun.hotspot.igv.settings.Settings; -import java.io.*; -import javax.swing.Action; -import javax.swing.JFileChooser; -import org.openide.nodes.Node; -import org.openide.util.HelpCtx; -import org.openide.util.NbBundle; -import org.openide.util.actions.CookieAction; -import org.openide.util.actions.NodeAction; - -/** - * - * @author Thomas Wuerthinger - */ -public final class SaveAsAction extends NodeAction { - - public SaveAsAction() { - putValue(Action.SHORT_DESCRIPTION, "Save selected groups to XML file..."); - } - - @Override - protected void performAction(Node[] activatedNodes) { - - GraphDocument doc = new GraphDocument(); - for (Node n : activatedNodes) { - Group group = n.getLookup().lookup(Group.class); - doc.addElement(group); - } - - save(doc); - } - - public static void save(GraphDocument doc) { - JFileChooser fc = new JFileChooser(); - fc.setFileFilter(ImportAction.getFileFilter()); - fc.setCurrentDirectory(new File(Settings.get().get(Settings.DIRECTORY, Settings.DIRECTORY_DEFAULT))); - - if (fc.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { - File file = fc.getSelectedFile(); - if (!file.getName().contains(".")) { - file = new File(file.getAbsolutePath() + ".xml"); - } - - File dir = file; - if (!dir.isDirectory()) { - dir = dir.getParentFile(); - } - Settings.get().put(Settings.DIRECTORY, dir.getAbsolutePath()); - try { - try (Writer writer = new OutputStreamWriter(new FileOutputStream(file))) { - Printer p = new Printer(); - p.export(writer, doc); - } - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - - } - } - } - - protected int mode() { - return CookieAction.MODE_SOME; - } - - @Override - public String getName() { - return NbBundle.getMessage(SaveAsAction.class, "CTL_SaveAsAction"); - } - - @Override - protected String iconResource() { - return "com/sun/hotspot/igv/coordinator/images/save.png"; - } - - @Override - public HelpCtx getHelpCtx() { - return HelpCtx.DEFAULT_HELP; - } - - @Override - protected boolean asynchronous() { - return false; - } - - @Override - protected boolean enable(Node[] nodes) { - - int cnt = 0; - for (Node n : nodes) { - cnt += n.getLookup().lookupAll(Group.class).size(); - } - - return cnt > 0; - } -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/customLeftWsmode.xml --- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/customLeftWsmode.xml Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/diff.png Binary file src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/diff.png has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/folder.png Binary file src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/folder.png has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/graph.png Binary file src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/graph.png has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/import.png Binary file src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/import.png has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/remove.png Binary file src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/remove.png has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/removeall.png Binary file src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/removeall.png has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/save.png Binary file src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/save.png has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/saveall.gif Binary file src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/saveall.gif has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/structure.png Binary file src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/structure.png has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/structured.gif Binary file src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/structured.gif has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/layer.xml --- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/layer.xml Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,198 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/manifest.mf --- a/src/share/tools/IdealGraphVisualizer/Data/manifest.mf Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Data/manifest.mf Tue Feb 07 21:09:31 2012 +0100 @@ -1,5 +1,5 @@ -Manifest-Version: 1.0 -OpenIDE-Module: com.sun.hotspot.igv.data -OpenIDE-Module-Localizing-Bundle: com/sun/hotspot/igv/data/Bundle.properties -OpenIDE-Module-Specification-Version: 1.0 - +Manifest-Version: 1.0 +OpenIDE-Module: com.sun.hotspot.igv.data +OpenIDE-Module-Localizing-Bundle: com/sun/hotspot/igv/data/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/nbproject/project.xml --- a/src/share/tools/IdealGraphVisualizer/Data/nbproject/project.xml Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Data/nbproject/project.xml Tue Feb 07 21:09:31 2012 +0100 @@ -1,29 +1,33 @@ - - - org.netbeans.modules.apisupport.project - - - com.sun.hotspot.igv.data - - - - - unit - - org.netbeans.libs.junit4 - - - - org.openide.util - - - - - - com.sun.hotspot.igv.data - com.sun.hotspot.igv.data.serialization - com.sun.hotspot.igv.data.services - - - - + + + org.netbeans.modules.apisupport.project + + + com.sun.hotspot.igv.data + + + + + unit + + org.netbeans.libs.junit4 + + + + org.openide.util + + + + + + at.ssw.visualizer.model.bc + at.ssw.visualizer.model.cfg + at.ssw.visualizer.model.interval + at.ssw.visualizer.model.nc + com.sun.hotspot.igv.data + com.sun.hotspot.igv.data.serialization + com.sun.hotspot.igv.data.services + + + + diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/bc/Bytecodes.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/bc/Bytecodes.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,33 @@ +package at.ssw.visualizer.model.bc; + +import at.ssw.visualizer.model.cfg.ControlFlowGraph; + +/** + * This class holds the bytecode of a method and provides severel methods + * accessing the details. + * + * @author Alexander Reder + * @author Christian Wimmer + */ +public interface Bytecodes { + /** + * Back-link to the control flow graph where the bytecodes were loaded from. + */ + public ControlFlowGraph getControlFlowGraph(); + + /** + * Called before the first call of getBytecodes() or getEpilogue(). Can be called multiple times. + */ + public void parseBytecodes(); + + /** + * The bytecodes of the method in the given bytecode range. + * + * @param fromBCI starting BCI (including this bci) + * @param toBCI ending BCI (not including this bci) + * @return string representation of the bytecodes + */ + public String getBytecodes(int fromBCI, int toBCI); + + public String getEpilogue(); +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/cfg/BasicBlock.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/cfg/BasicBlock.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,41 @@ +package at.ssw.visualizer.model.cfg; + +import java.util.List; + +/** + * + * @author Christian Wimmer + */ +public interface BasicBlock { + public String getName(); + + public int getFromBci(); + + public int getToBci(); + + public List getPredecessors(); + + public List getSuccessors(); + + public List getXhandlers(); + + public List getFlags(); + + public BasicBlock getDominator(); + + public int getLoopIndex(); + + public int getLoopDepth(); + + public boolean hasState(); + + public List getStates(); + + public boolean hasHir(); + + public List getHirInstructions(); + + public boolean hasLir(); + + public List getLirOperations(); +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/cfg/ControlFlowGraph.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/cfg/ControlFlowGraph.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,26 @@ +package at.ssw.visualizer.model.cfg; + +import at.ssw.visualizer.model.bc.Bytecodes; +import at.ssw.visualizer.model.nc.NativeMethod; +import com.sun.hotspot.igv.data.FolderElement; +import java.util.List; + +/** + * + * @author Christian Wimmer + */ +public interface ControlFlowGraph extends FolderElement { + public List getBasicBlocks(); + + public BasicBlock getBasicBlockByName(String name); + + public Bytecodes getBytecodes(); + + public NativeMethod getNativeMethod(); + + public boolean hasState(); + + public boolean hasHir(); + + public boolean hasLir(); +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/cfg/IRInstruction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/cfg/IRInstruction.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,19 @@ +package at.ssw.visualizer.model.cfg; + +import java.util.Collection; + +/** + * + * @author Christian Wimmer + */ +public interface IRInstruction { + public static String HIR_NAME = "tid"; + public static String HIR_TEXT = "instruction"; + public static String HIR_OPERAND = "result"; + + public static String LIR_NUMBER = "nr"; + public static String LIR_TEXT = "instruction"; + + public Collection getNames(); + public String getValue(String name); +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/cfg/State.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/cfg/State.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,17 @@ +package at.ssw.visualizer.model.cfg; + +import java.util.List; + +/** + * + * @author Christian Wimmer + */ +public interface State { + public String getKind(); + + public int getSize(); + + public String getMethod(); + + public List getEntries(); +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/cfg/StateEntry.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/cfg/StateEntry.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,19 @@ +package at.ssw.visualizer.model.cfg; + +import java.util.List; + +/** + * + * @author Christian Wimmer + */ +public interface StateEntry { + public int getIndex(); + + public String getName(); + + public boolean hasPhiOperands(); + + public List getPhiOperands(); + + public String getOperand(); +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/interval/ChildInterval.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/interval/ChildInterval.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,29 @@ +package at.ssw.visualizer.model.interval; + +import java.util.List; + +/** + * + * @author Christian Wimmer + */ +public interface ChildInterval { + public Interval getParent(); + + public String getRegNum(); + + public String getType(); + + public String getOperand(); + + public String getSpillState(); + + public ChildInterval getRegisterHint(); + + public List getRanges(); + + public List getUsePositions(); + + public int getFrom(); + + public int getTo(); +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/interval/Interval.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/interval/Interval.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,19 @@ +package at.ssw.visualizer.model.interval; + +import java.util.List; + +/** + * + * @author Christian Wimmer + */ +public interface Interval { + public IntervalList getParent(); + + public List getChildren(); + + public String getRegNum(); + + public int getFrom(); + + public int getTo(); +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/interval/IntervalList.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/interval/IntervalList.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,16 @@ +package at.ssw.visualizer.model.interval; + +import at.ssw.visualizer.model.cfg.ControlFlowGraph; +import java.util.List; + +/** + * + * @author Christian Wimmer + */ +public interface IntervalList { + public List getIntervals(); + + public ControlFlowGraph getControlFlowGraph(); + + public int getNumLIROperations(); +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/interval/Range.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/interval/Range.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,11 @@ +package at.ssw.visualizer.model.interval; + +/** + * + * @author Christian Wimmer + */ +public interface Range { + public int getFrom(); + + public int getTo(); +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/interval/UsePosition.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/interval/UsePosition.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,11 @@ +package at.ssw.visualizer.model.interval; + +/** + * + * @author Christian Wimmer + */ +public interface UsePosition { + public char getKind(); + + public int getPosition(); +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/nc/NativeMethod.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/nc/NativeMethod.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,15 @@ +package at.ssw.visualizer.model.nc; + +import at.ssw.visualizer.model.cfg.ControlFlowGraph; + +/** + * + * @author Alexander Reder + */ +public interface NativeMethod { + + public ControlFlowGraph getControlFlowGraph(); + + public String getMethodText(); + +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/bc/BytecodesImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/bc/BytecodesImpl.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,166 @@ +package at.ssw.visualizer.modelimpl.bc; + +import at.ssw.visualizer.model.bc.Bytecodes; +import at.ssw.visualizer.model.cfg.BasicBlock; +import at.ssw.visualizer.model.cfg.ControlFlowGraph; +import at.ssw.visualizer.modelimpl.cfg.BasicBlockImpl; +import java.util.Arrays; + +/** + * This class holds the bytecode of a method and provides severel methods + * accessing the details. + * + * @author Christian Wimmer + */ +public class BytecodesImpl implements Bytecodes { + private ControlFlowGraph controlFlowGraph; + private String bytecodeString; + + private String[] bytecodes; + private String epilogue; + + + public BytecodesImpl(ControlFlowGraph controlFlowGraph, String bytecodeString) { + this.controlFlowGraph = controlFlowGraph; + this.bytecodeString = bytecodeString; + } + + public void parseBytecodes() { + String[] lines = bytecodeString.split("\n"); + + boolean inPrologue = true; + String[] result = new String[lines.length * 3]; + int lastBci = -1; + int lnr = 0; + for (; lnr < lines.length; lnr++) { + String line = lines[lnr]; + + line = line.trim(); + if (line.startsWith("[")) { + int end = line.indexOf(']'); + if (end != -1) { + line = line.substring(end + 1, line.length()); + } + } + + line = line.trim(); + int space1 = line.indexOf(' '); + if (space1 <= 0) { + if (inPrologue) { + continue; + } else { + break; + } + } + String bciStr = line.substring(0, space1); + if (bciStr.endsWith(":")) { + bciStr = bciStr.substring(0, bciStr.length() - 1); + } + + int bci; + try { + bci = Integer.parseInt(bciStr); + } catch (NumberFormatException ex) { + // Ignore invalid lines. + if (inPrologue) { + continue; + } else { + break; + } + } + + String opcode = line.substring(space1 + 1); + String params = ""; + int space2 = opcode.indexOf(' '); + if (space2 > 0) { + params = opcode.substring(space2 + 1).trim(); + opcode = opcode.substring(0, space2); + } + String tail = ""; + int space3 = params.indexOf('|'); + if (space3 >= 0) { + tail = params.substring(space3); + params = params.substring(0, space3); + } + +// if (!"ldc".equals(opcode) || !params.startsWith("\"")) { +// // Separate packages with "." instead of "/" +// params = params.replace('/', '.'); +// } + + String printLine = bciStr + ":" + " ".substring(Math.min(bciStr.length(), 3)) + + opcode + " ".substring(Math.min(opcode.length(), 13)) + + params + " ".substring(Math.min(params.length(), 8)) + + tail; + + + if (bci >= result.length) { + result = Arrays.copyOf(result, Math.max(bci + 1, result.length * 2)); + } + result[bci] = printLine; + inPrologue = false; + lastBci = Math.max(lastBci, bci); + } + + StringBuilder epilogueBuilder = new StringBuilder(); + for (; lnr < lines.length; lnr++) { + epilogueBuilder.append(lines[lnr]).append("\n"); + } + epilogue = epilogueBuilder.toString(); + bytecodes = Arrays.copyOf(result, lastBci + 1); + + + BasicBlockImpl[] blocks = new BasicBlockImpl[bytecodes.length]; + for (BasicBlock b : controlFlowGraph.getBasicBlocks()) { + if (b instanceof BasicBlockImpl) { + BasicBlockImpl block = (BasicBlockImpl) b; + if (block.getToBci() != -1) { + // Do not override existing values. + return; + } + if (block.getFromBci() >= 0 && block.getFromBci() < blocks.length) { + blocks[block.getFromBci()] = block; + } + } + } + + int curToBci = -1; + for (int i = blocks.length - 1; i >= 0; i--) { + if (bytecodes[i] != null && curToBci == -1) { + curToBci = i; + } + if (blocks[i] != null) { + blocks[i].setToBci(curToBci); + curToBci = -1; + } + } + } + + public ControlFlowGraph getControlFlowGraph() { + return controlFlowGraph; + } + + public String getBytecodes(int fromBCI, int toBCI) { + if (fromBCI < 0) { + return ""; + } + toBCI = Math.min(toBCI, bytecodes.length); + StringBuilder sb = new StringBuilder(); + for (int i = fromBCI; i < toBCI; i++) { + if (bytecodes[i] != null) { + sb.append(bytecodes[i]).append("\n"); + } + } + return sb.toString(); + } + + @Override + public String getEpilogue() { + return epilogue; + } + + @Override + public String toString() { + return "Bytecodes " + getControlFlowGraph().getName(); + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/cfg/BasicBlockImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/cfg/BasicBlockImpl.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,143 @@ +package at.ssw.visualizer.modelimpl.cfg; + +import at.ssw.visualizer.model.cfg.BasicBlock; +import at.ssw.visualizer.model.cfg.ControlFlowGraph; +import at.ssw.visualizer.model.cfg.IRInstruction; +import at.ssw.visualizer.model.cfg.State; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * + * @author Christian Wimmer + */ +public class BasicBlockImpl implements BasicBlock { + + private ControlFlowGraph parent; + private String name; + private int fromBci; + private int toBci; + private BasicBlock[] predecessors; + private BasicBlock[] successors; + private BasicBlock[] xhandlers; + private String[] flags; + private BasicBlock dominator; + private int loopIndex; + private int loopDepth; + private int firstLirId; + private int lastLirId; + private State[] states; + private IRInstruction[] hirInstructions; + private IRInstruction[] lirOperations; + + public void setValues(String name, int fromBci, int toBci, BasicBlock[] predecessors, BasicBlock[] successors, BasicBlock[] xhandlers, String[] flags, BasicBlock dominator, int loopIndex, int loopDepth, int firstLirId, int lastLirId, State[] states, IRInstruction[] hirInstructions, IRInstruction[] lirOperations) { + this.name = name; + this.fromBci = fromBci; + this.toBci = toBci; + + this.predecessors = predecessors; + this.successors = successors; + this.xhandlers = xhandlers; + + this.flags = flags; + this.dominator = dominator; + this.loopIndex = loopIndex; + this.loopDepth = loopDepth; + this.firstLirId = firstLirId; + this.lastLirId = lastLirId; + + this.states = states; + this.hirInstructions = hirInstructions; + this.lirOperations = lirOperations; + } + + public ControlFlowGraph getParent() { + return parent; + } + + protected void setParent(ControlFlowGraph parent) { + this.parent = parent; + } + + public String getName() { + return name; + } + + public int getFromBci() { + return fromBci; + } + + public int getToBci() { + return toBci; + } + + public void setToBci(int toBci) { + this.toBci = toBci; + } + + public List getPredecessors() { + return Collections.unmodifiableList(Arrays.asList(predecessors)); + } + + public List getSuccessors() { + return Collections.unmodifiableList(Arrays.asList(successors)); + } + + public List getXhandlers() { + return Collections.unmodifiableList(Arrays.asList(xhandlers)); + } + + public List getFlags() { + return Collections.unmodifiableList(Arrays.asList(flags)); + } + + public BasicBlock getDominator() { + return dominator; + } + + public int getLoopIndex() { + return loopIndex; + } + + public int getLoopDepth() { + return loopDepth; + } + + public int getFirstLirId() { + return firstLirId; + } + + public int getLastLirId() { + return lastLirId; + } + + public boolean hasState() { + return states != null; + } + + public List getStates() { + return Collections.unmodifiableList(Arrays.asList(states)); + } + + public boolean hasHir() { + return hirInstructions != null; + } + + public List getHirInstructions() { + return Collections.unmodifiableList(Arrays.asList(hirInstructions)); + } + + public boolean hasLir() { + return lirOperations != null; + } + + public List getLirOperations() { + return Collections.unmodifiableList(Arrays.asList(lirOperations)); + } + + @Override + public String toString() { + return name; + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/cfg/IRInstructionImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/cfg/IRInstructionImpl.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,40 @@ +package at.ssw.visualizer.modelimpl.cfg; + +import at.ssw.visualizer.model.cfg.IRInstruction; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashMap; + +public class IRInstructionImpl implements IRInstruction { + private LinkedHashMap data; + + public IRInstructionImpl(LinkedHashMap data) { + this.data = data; + } + + public IRInstructionImpl(String pinned, int bci, int useCount, String name, String text, String operand) { + data = new LinkedHashMap(); + data.put("p", pinned); + data.put("bci", Integer.toString(bci)); + data.put("use", Integer.toString(useCount)); + data.put(HIR_NAME, name); + if (operand != null) { + data.put(HIR_OPERAND, operand); + } + data.put(HIR_TEXT, text); + } + + public IRInstructionImpl(int number, String text) { + data = new LinkedHashMap(); + data.put(LIR_NUMBER, Integer.toString(number)); + data.put(LIR_TEXT, text); + } + + public Collection getNames() { + return Collections.unmodifiableSet(data.keySet()); + } + + public String getValue(String name) { + return data.get(name); + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/cfg/StateEntryImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/cfg/StateEntryImpl.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,44 @@ +package at.ssw.visualizer.modelimpl.cfg; + +import at.ssw.visualizer.model.cfg.StateEntry; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * + * @author Christian Wimmer + */ +public class StateEntryImpl implements StateEntry { + private int index; + private String name; + private String[] phiOperands; + private String operand; + + public StateEntryImpl(int index, String name, String[] phiOperands, String operand) { + this.index = index; + this.name = name; + this.phiOperands = phiOperands; + this.operand = operand; + } + + public int getIndex() { + return index; + } + + public String getName() { + return name; + } + + public boolean hasPhiOperands() { + return phiOperands != null; + } + + public List getPhiOperands() { + return Collections.unmodifiableList(Arrays.asList(phiOperands)); + } + + public String getOperand() { + return operand; + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/cfg/StateImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/cfg/StateImpl.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,41 @@ +package at.ssw.visualizer.modelimpl.cfg; + +import at.ssw.visualizer.model.cfg.State; +import at.ssw.visualizer.model.cfg.StateEntry; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * + * @author Christian Wimmer + */ +public class StateImpl implements State { + private String kind; + private int size; + private String method; + private StateEntry[] entries; + + public StateImpl(String kind, int size, String method, StateEntryImpl[] entries) { + this.kind = kind; + this.size = size; + this.method = method; + this.entries = entries; + } + + public String getKind() { + return kind; + } + + public int getSize() { + return size; + } + + public String getMethod() { + return method; + } + + public List getEntries() { + return Collections.unmodifiableList(Arrays.asList(entries)); + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/interval/ChildIntervalImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/interval/ChildIntervalImpl.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,118 @@ +package at.ssw.visualizer.modelimpl.interval; + +import at.ssw.visualizer.model.interval.ChildInterval; +import at.ssw.visualizer.model.interval.Interval; +import at.ssw.visualizer.model.interval.Range; +import at.ssw.visualizer.model.interval.UsePosition; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * + * @author Christian Wimmer + */ +public class ChildIntervalImpl implements ChildInterval, Comparable { + private Interval parent; + private String regNum; + private String type; + private String operand; + private String spillState; + private ChildInterval registerHint; + private Range[] ranges; + private UsePosition[] usePositions; + + public void setValues(String regNum, String type, String operand, String spillState, ChildInterval registerHint, Range[] ranges, UsePosition[] usePositions) { + this.regNum = regNum; + this.type = type; + this.operand = operand; + this.spillState = spillState; + this.registerHint = registerHint; + this.ranges = ranges; + this.usePositions = usePositions; + } + + public Interval getParent() { + return parent; + } + + protected void setParent(IntervalImpl parent) { + this.parent = parent; + } + + public String getRegNum() { + return regNum; + } + + public String getType() { + return type; + } + + public String getOperand() { + return operand; + } + + public String getSpillState() { + return spillState; + } + + public ChildInterval getRegisterHint() { + return registerHint; + } + + public List getRanges() { + return Collections.unmodifiableList(Arrays.asList(ranges)); + } + + public List getUsePositions() { + return Collections.unmodifiableList(Arrays.asList(usePositions)); + } + + + public int getFrom() { + return ranges[0].getFrom(); + } + + public int getTo() { + return ranges[ranges.length - 1].getTo(); + } + + + public int compareTo(ChildIntervalImpl other) { + return getFrom() - other.getFrom(); + } + + @Override + public String toString() { + StringBuilder result = new StringBuilder(); + result.append(regNum); + result.append(": "); + result.append(getType()); + result.append(", "); + result.append(getOperand()); + result.append(", "); + if (registerHint != null) { + result.append(registerHint.getRegNum()); + } else { + result.append("null"); + } + + result.append(" "); + for (int i = 0; i < ranges.length; i++) { + if (i > 0) { + result.append(", "); + } + result.append(ranges[i]); + } + + result.append(" "); + for (int i = 0; i < usePositions.length; i++) { + if (i > 0) { + result.append(", "); + } + result.append(usePositions[i]); + } + + return result.toString(); + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/interval/IntervalImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/interval/IntervalImpl.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,60 @@ +package at.ssw.visualizer.modelimpl.interval; + +import at.ssw.visualizer.model.interval.ChildInterval; +import at.ssw.visualizer.model.interval.Interval; +import at.ssw.visualizer.model.interval.IntervalList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * + * @author Christian Wimmer + */ +public class IntervalImpl implements Interval { + private IntervalList parent; + private ChildInterval[] children; + + public IntervalImpl(ChildIntervalImpl[] children) { + this.children = children; + for (ChildIntervalImpl child : children) { + child.setParent(this); + } + } + + public IntervalList getParent() { + return parent; + } + + protected void setParent(IntervalListImpl parent) { + this.parent = parent; + } + + public List getChildren() { + return Collections.unmodifiableList(Arrays.asList(children)); + } + + public String getRegNum() { + return children[0].getRegNum(); + } + + public int getFrom() { + return children[0].getFrom(); + } + + public int getTo() { + return children[children.length - 1].getTo(); + } + + @Override + public String toString() { + StringBuilder result = new StringBuilder(); + for (int i = 0; i < children.length; i++) { + if (i > 0) { + result.append("\n "); + } + result.append(children[i]); + } + return result.toString(); + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/interval/IntervalListImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/interval/IntervalListImpl.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,54 @@ +package at.ssw.visualizer.modelimpl.interval; + +import at.ssw.visualizer.model.cfg.BasicBlock; +import at.ssw.visualizer.model.cfg.ControlFlowGraph; +import at.ssw.visualizer.model.interval.Interval; +import at.ssw.visualizer.model.interval.IntervalList; +import com.sun.hotspot.igv.data.AbstractFolderElement; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * + * @author Christian Wimmer + */ +public class IntervalListImpl extends AbstractFolderElement implements IntervalList { + private Interval[] intervals; + private ControlFlowGraph controlFlowGraph; + private int numLIROperations; + + public IntervalListImpl(String shortName, String name, IntervalImpl[] intervals, ControlFlowGraph controlFlowGraph) { + super(shortName, name); + this.intervals = intervals; + this.controlFlowGraph = controlFlowGraph; + + for (IntervalImpl interval : intervals) { + interval.setParent(this); + numLIROperations = Math.max(numLIROperations, interval.getTo()); + } +// for (BasicBlock basicBlock : controlFlowGraph.getBasicBlocks()) { +// numLIROperations = Math.max(numLIROperations, basicBlock.getLastLirId() + 2); +// } + // TODO(tw): Add number of LIR operations to output. + } + + + public List getIntervals() { + return Collections.unmodifiableList(Arrays.asList(intervals)); + } + + public ControlFlowGraph getControlFlowGraph() { + return controlFlowGraph; + } + + public int getNumLIROperations() { + return numLIROperations; + } + + + @Override + public String toString() { + return " Intervals \"" + getName() + "\": " + intervals.length + " intervals\n"; + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/interval/RangeImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/interval/RangeImpl.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,36 @@ +package at.ssw.visualizer.modelimpl.interval; + +import at.ssw.visualizer.model.interval.Range; + +/** + * + * @author Christian Wimmer + */ +public class RangeImpl implements Range, Comparable { + private int from; + private int to; + + public RangeImpl(int from, int to) { + this.from = from; + this.to = to; + } + + + public int getFrom() { + return from; + } + + public int getTo() { + return to; + } + + + public int compareTo(RangeImpl other) { + return getFrom() - other.getFrom(); + } + + @Override + public String toString() { + return "[" + from + ", " + to + "]"; + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/interval/UsePositionImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/interval/UsePositionImpl.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,36 @@ +package at.ssw.visualizer.modelimpl.interval; + +import at.ssw.visualizer.model.interval.UsePosition; + +/** + * + * @author Christian Wimmer + */ +public class UsePositionImpl implements UsePosition, Comparable { + private int position; + private char kind; + + public UsePositionImpl(int position, char kind) { + this.position = position; + this.kind = kind; + } + + + public char getKind() { + return kind; + } + + public int getPosition() { + return position; + } + + + public int compareTo(UsePositionImpl other) { + return getPosition() - other.getPosition(); + } + + @Override + public String toString() { + return position + "(" + kind + ")"; + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/nc/NativeMethodImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/nc/NativeMethodImpl.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,28 @@ +package at.ssw.visualizer.modelimpl.nc; + +import at.ssw.visualizer.model.cfg.ControlFlowGraph; +import at.ssw.visualizer.model.nc.NativeMethod; + +/** + * + * @author Alexander Reder + */ +public class NativeMethodImpl implements NativeMethod { + + private ControlFlowGraph controlFlowGraph; + private String methodText; + + public NativeMethodImpl(ControlFlowGraph controlFlowGraph, String methodText) { + this.controlFlowGraph = controlFlowGraph; + this.methodText = methodText; + } + + public ControlFlowGraph getControlFlowGraph() { + return controlFlowGraph; + } + + public String getMethodText() { + return methodText; + } + +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/AbstractFolderElement.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/AbstractFolderElement.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.sun.hotspot.igv.data; + +public class AbstractFolderElement implements FolderElement { + + private String name; + private String shortName; + private Folder parent; + + public AbstractFolderElement(String name, String shortName) { + this.name = name; + this.shortName = shortName; + } + + public String getShortName() { + return shortName; + } + + @Override + public String getName() { + return name; + } + + @Override + public Folder getParent() { + return parent; + } + + @Override + public void setParent(Folder parent) { + this.parent = parent; + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Bundle.properties --- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Bundle.properties Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Bundle.properties Tue Feb 07 21:09:31 2012 +0100 @@ -1,1 +1,1 @@ -OpenIDE-Module-Name=Data +OpenIDE-Module-Name=Data diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/ChangedEvent.java --- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/ChangedEvent.java Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/ChangedEvent.java Tue Feb 07 21:09:31 2012 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,18 +23,10 @@ */ package com.sun.hotspot.igv.data; -/** - * Class representing a generic changed event. - * @author Thomas Wuerthinger - * @param - */ public class ChangedEvent extends Event> { private T object; - /** - * Creates a new event with the specific object as the one for which the event gets fired. - */ public ChangedEvent(T object) { this.object = object; } @@ -43,4 +35,11 @@ protected void fire(ChangedListener l) { l.changed(object); } + + public void changeObject(T newObject) { + if (object != newObject) { + this.object = newObject; + fire(); + } + } } diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Event.java --- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Event.java Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Event.java Tue Feb 07 21:09:31 2012 +0100 @@ -45,6 +45,11 @@ listener.add(l); } + public void addListenerAndFire(L l) { + addListener(l); + fire(l); + } + /** * Remove listener * @param l diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Folder.java --- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Folder.java Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Folder.java Tue Feb 07 21:09:31 2012 +0100 @@ -26,6 +26,7 @@ import java.util.List; public interface Folder { + String getName(); List getElements(); void removeElement(FolderElement element); void addElement(FolderElement group); diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/GraphDocument.java --- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/GraphDocument.java Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/GraphDocument.java Tue Feb 07 21:09:31 2012 +0100 @@ -87,6 +87,12 @@ @Override public void addElement(FolderElement element) { elements.add(element); + element.setParent(this); getChangedEvent().fire(); } + + @Override + public String getName() { + return "root"; + } } diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputBlock.java --- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputBlock.java Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputBlock.java Tue Feb 07 21:09:31 2012 +0100 @@ -23,18 +23,23 @@ */ package com.sun.hotspot.igv.data; +import at.ssw.visualizer.model.cfg.BasicBlock; +import at.ssw.visualizer.model.cfg.ControlFlowGraph; +import at.ssw.visualizer.model.cfg.IRInstruction; +import at.ssw.visualizer.model.cfg.State; import java.util.*; /** * * @author Thomas Wuerthinger */ -public class InputBlock { +public class InputBlock implements BasicBlock { private List nodes; private String name; private InputGraph graph; - private Set successors; + private List successors; + private List predecessors; @Override public int hashCode() { @@ -76,7 +81,8 @@ this.graph = graph; this.name = name; nodes = new ArrayList<>(); - successors = new LinkedHashSet<>(2); + successors = new ArrayList<>(); + predecessors = new ArrayList<>(); } public String getName() { @@ -97,8 +103,9 @@ nodes.add(node); } - public Set getSuccessors() { - return Collections.unmodifiableSet(successors); + @Override + public List getSuccessors() { + return Collections.unmodifiableList(successors); } @Override @@ -109,6 +116,90 @@ void addSuccessor(InputBlock b) { if (!successors.contains(b)) { successors.add(b); + b.predecessors.add(this); } } + + @Override + public int getFromBci() { + // TODO(tw): Implement. + return -1; + } + + @Override + public int getToBci() { + // TODO(tw): Implement. + return -1; + } + + @Override + public List getPredecessors() { + return Collections.unmodifiableList(predecessors); + } + + @Override + public List getXhandlers() { + // TODO(tw): Implement. + return Collections.emptyList(); + } + + @Override + public List getFlags() { + // TODO(tw): Implement. + return Collections.emptyList(); + } + + @Override + public BasicBlock getDominator() { + // TODO(tw): Implement. + return null; + } + + @Override + public int getLoopIndex() { + // TODO(tw): Implement. + return -1; + } + + @Override + public int getLoopDepth() { + // TODO(tw): Implement. + return -1; + } + + @Override + public boolean hasState() { + // TODO(tw): Implement. + return false; + } + + @Override + public List getStates() { + // TODO(tw): Implement. + return Collections.emptyList(); + } + + @Override + public boolean hasHir() { + // TODO(tw): Implement. + return false; + } + + @Override + public List getHirInstructions() { + // TODO(tw): Implement. + return Collections.emptyList(); + } + + @Override + public boolean hasLir() { + // TODO(tw): Implement. + return false; + } + + @Override + public List getLirOperations() { + // TODO(tw): Implement. + return Collections.emptyList(); + } } diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputGraph.java --- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputGraph.java Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputGraph.java Tue Feb 07 21:09:31 2012 +0100 @@ -23,13 +23,17 @@ */ package com.sun.hotspot.igv.data; +import at.ssw.visualizer.model.bc.Bytecodes; +import at.ssw.visualizer.model.cfg.BasicBlock; +import at.ssw.visualizer.model.cfg.ControlFlowGraph; +import at.ssw.visualizer.model.nc.NativeMethod; import java.util.*; /** * * @author Thomas Wuerthinger */ -public class InputGraph extends Properties.Entity implements FolderElement { +public class InputGraph extends Properties.Entity implements FolderElement, ControlFlowGraph { private Map nodes; private Set edges; @@ -293,4 +297,44 @@ public Folder getParent() { return parent; } + + @Override + public List getBasicBlocks() { + return new ArrayList(blocks.values()); + } + + @Override + public BasicBlock getBasicBlockByName(String name) { + return blocks.get(name); + } + + @Override + public Bytecodes getBytecodes() { + // TODO(tw): no bytecodes + return null; + } + + @Override + public NativeMethod getNativeMethod() { + // TODO(tw): No native method. + return null; + } + + @Override + public boolean hasState() { + // TODO(tw): implement + return false; + } + + @Override + public boolean hasHir() { + // TODO(tw): Implement + return false; + } + + @Override + public boolean hasLir() { + // TODO(tw): Implement + return false; + } } diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Draw2DLibrary/manifest.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Draw2DLibrary/manifest.mf Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +OpenIDE-Module: org.eclipse.draw2d +OpenIDE-Module-Localizing-Bundle: org/eclipse/draw2d/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Draw2DLibrary/release/modules/ext/org.eclipse.draw2d_3.1.0.jar Binary file src/share/tools/IdealGraphVisualizer/Draw2DLibrary/release/modules/ext/org.eclipse.draw2d_3.1.0.jar has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Draw2DLibrary/src/org/eclipse/draw2d/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Draw2DLibrary/src/org/eclipse/draw2d/Bundle.properties Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,1 @@ +OpenIDE-Module-Name=Draw2DLibrary diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Editor/manifest.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Editor/manifest.mf Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,6 @@ +Manifest-Version: 1.0 +OpenIDE-Module: com.oracle.graal.visualizer.editor +OpenIDE-Module-Layer: com/oracle/graal/visualizer/editor/layer.xml +OpenIDE-Module-Localizing-Bundle: com/oracle/graal/visualizer/editor/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Editor/src/META-INF/services/com.sun.hotspot.igv.data.services.GraphViewer --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Editor/src/META-INF/services/com.sun.hotspot.igv.data.services.GraphViewer Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,1 @@ +com.oracle.graal.visualizer.editor.GraphViewerImplementation diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/Bundle.properties Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,3 @@ +OpenIDE-Module-Name=Editor +CTL_EditorTopComponent=Compilation +HINT_EditorTopComponent=Shows the snapshots of a single compilation. \ No newline at end of file diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/CompilationViewer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/CompilationViewer.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +package com.oracle.graal.visualizer.editor; + +import com.sun.hotspot.igv.graph.Figure; +import java.awt.Component; +import java.awt.Graphics2D; +import java.util.Collection; +import org.openide.awt.UndoRedo; +import org.openide.util.Lookup; + +/** + * + * @author Thomas Wuerthinger + */ +public interface CompilationViewer { + + public Lookup getLookup(); + + public Component getComponent(); +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/CompilationViewerFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/CompilationViewerFactory.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ +package com.oracle.graal.visualizer.editor; + +import com.sun.hotspot.igv.data.InputGraph; + +public interface CompilationViewerFactory { + CompilationViewer createViewer(InputGraph firstGraph, InputGraph secondGraph); + String getName(); +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/DiagramViewModel.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/DiagramViewModel.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,289 @@ +/* + * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.visualizer.editor; + +import com.sun.hotspot.igv.data.*; +import com.sun.hotspot.igv.difference.Difference; +import com.sun.hotspot.igv.filter.CustomFilter; +import com.sun.hotspot.igv.filter.FilterChain; +import com.sun.hotspot.igv.graph.Diagram; +import com.sun.hotspot.igv.graph.Figure; +import com.sun.hotspot.igv.settings.Settings; +import java.util.*; + +public class DiagramViewModel { + + private Set hiddenNodes; + private Set onScreenNodes; + private Set selectedNodes; + private FilterChain filterChain; + private FilterChain sequenceFilterChain; + private Diagram diagram; + private InputGraph inputGraph; + private ChangedEvent diagramChangedEvent; + private ChangedEvent viewChangedEvent; + private ChangedEvent hiddenNodesChangedEvent; + private ChangedEvent viewPropertiesChangedEvent; + private boolean showNodeHull; + private final InputGraph secondGraph; + private final InputGraph firstGraph; + private ChangedListener filterChainChangedListener = new ChangedListener() { + + @Override + public void changed(FilterChain source) { + diagramChanged(); + } + }; + + public boolean getShowNodeHull() { + return showNodeHull; + } + + public void setShowNodeHull(boolean b) { + showNodeHull = b; + viewPropertiesChangedEvent.fire(); + } + + public DiagramViewModel(InputGraph firstGraph, InputGraph secondGraph, Group g, FilterChain filterChain, FilterChain sequenceFilterChain) { + + this.firstGraph = firstGraph; + this.secondGraph = secondGraph; + this.showNodeHull = true; + assert filterChain != null; + this.filterChain = filterChain; + assert sequenceFilterChain != null; + this.sequenceFilterChain = sequenceFilterChain; + hiddenNodes = new HashSet<>(); + onScreenNodes = new HashSet<>(); + selectedNodes = new HashSet<>(); + diagramChangedEvent = new ChangedEvent<>(this); + viewChangedEvent = new ChangedEvent<>(this); + hiddenNodesChangedEvent = new ChangedEvent<>(this); + viewPropertiesChangedEvent = new ChangedEvent<>(this); + + filterChain.getChangedEvent().addListener(filterChainChangedListener); + sequenceFilterChain.getChangedEvent().addListener(filterChainChangedListener); + } + + public ChangedEvent getDiagramChangedEvent() { + return diagramChangedEvent; + } + + public ChangedEvent getViewChangedEvent() { + return viewChangedEvent; + } + + public ChangedEvent getHiddenNodesChangedEvent() { + return hiddenNodesChangedEvent; + } + + public ChangedEvent getViewPropertiesChangedEvent() { + return viewPropertiesChangedEvent; + } + + public Set getSelectedNodes() { + return selectedNodes; + } + + public Set getHiddenNodes() { + return hiddenNodes; + } + + public Set getOnScreenNodes() { + return onScreenNodes; + } + + public void setSelectedNodes(Set nodes) { + this.selectedNodes = nodes; + /* List colors = new ArrayList<>(); + for (int i = 0; i < group.getGraphs().size(); ++i) { + colors.add(Color.black); + } + if (nodes.size() >= 1) { + for (Integer id : nodes) { + if (id < 0) { + id = -id; + } + InputNode last = null; + int index = 0; + for (InputGraph g : group.getGraphs()) { + Color curColor = colors.get(index); + InputNode cur = g.getNode(id); + if (cur != null) { + if (last == null) { + curColor = Color.green; + } else { + if (last.equals(cur)) { + if (curColor == Color.black) { + curColor = Color.white; + } + } else { + if (curColor != Color.green) { + curColor = Color.orange; + } + } + } + } + last = cur; + colors.set(index, curColor); + index++; + } + } + } + compilationViewModel.setColors(colors);*/ + // TODO: Add colorization. + viewChangedEvent.fire(); + } + + public void showNot(final Set nodes) { + System.out.println("Shownot called with " + nodes); + setHiddenNodes(nodes); + } + + public void showFigures(Collection
f) { + HashSet newHiddenNodes = new HashSet<>(getHiddenNodes()); + for (Figure fig : f) { + newHiddenNodes.removeAll(fig.getSource().getSourceNodesAsSet()); + } + setHiddenNodes(newHiddenNodes); + } + + public Set
getSelectedFigures() { + Set
result = new HashSet<>(); + for (Figure f : diagram.getFigures()) { + for (InputNode node : f.getSource().getSourceNodes()) { + if (getSelectedNodes().contains(node.getId())) { + result.add(f); + } + } + } + return result; + } + + public void showAll(final Collection
f) { + showFigures(f); + } + + public void showOnly(final Set nodes) { + final HashSet allNodes = new HashSet<>(getGraphToView().getGroup().getAllNodes()); + allNodes.removeAll(nodes); + setHiddenNodes(allNodes); + } + + public void setHiddenNodes(Set nodes) { + this.hiddenNodes = nodes; + hiddenNodesChangedEvent.fire(); + } + + public void setOnScreenNodes(Set onScreenNodes) { + this.onScreenNodes = onScreenNodes; + viewChangedEvent.fire(); + } + + public FilterChain getSequenceFilterChain() { + return filterChain; + } + + public void setSequenceFilterChain(FilterChain chain) { + assert chain != null : "sequenceFilterChain must never be null"; + sequenceFilterChain.getChangedEvent().removeListener(filterChainChangedListener); + sequenceFilterChain = chain; + sequenceFilterChain.getChangedEvent().addListener(filterChainChangedListener); + diagramChanged(); + } + + private void diagramChanged() { + // clear diagram + diagram = null; + getDiagramChangedEvent().fire(); + + } + + public FilterChain getFilterChain() { + return filterChain; + } + + public void setFilterChain(FilterChain chain) { + assert chain != null : "filterChain must never be null"; + filterChain.getChangedEvent().removeListener(filterChainChangedListener); + filterChain = chain; + filterChain.getChangedEvent().addListener(filterChainChangedListener); + diagramChanged(); + } + + private static List calculateStringList(Group g) { + List result = new ArrayList<>(); + for (InputGraph graph : g.getGraphs()) { + result.add(graph.getName()); + } + return result; + } + + public InputGraph getFirstGraph() { + return firstGraph; + } + + public InputGraph getSecondGraph() { + return secondGraph; + } + + public Diagram getDiagramToView() { + + if (diagram == null) { + diagram = Diagram.createDiagram(getGraphToView(), Settings.get().get(Settings.NODE_TEXT, Settings.NODE_TEXT_DEFAULT)); + getFilterChain().apply(diagram, getSequenceFilterChain()); + if (getFirstGraph() != getSecondGraph()) { + CustomFilter f = new CustomFilter( + "difference", "colorize('state', 'same', white);" + + "colorize('state', 'changed', orange);" + + "colorize('state', 'new', green);" + + "colorize('state', 'deleted', red);"); + f.apply(diagram); + } + } + + return diagram; + } + + public InputGraph getGraphToView() { + if (inputGraph == null) { + if (getFirstGraph() != getSecondGraph()) { + inputGraph = Difference.createDiffGraph(getFirstGraph(), getSecondGraph()); + } else { + inputGraph = getFirstGraph(); + } + } + + return inputGraph; + } + + void setSelectedFigures(List
list) { + Set newSelectedNodes = new HashSet<>(); + for (Figure f : list) { + newSelectedNodes.addAll(f.getSource().getSourceNodesAsSet()); + } + this.setSelectedNodes(newSelectedNodes); + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/EditorTopComponent.form --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/EditorTopComponent.form Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,33 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/EditorTopComponent.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/EditorTopComponent.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,291 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ +package com.oracle.graal.visualizer.editor; + +import com.oracle.graal.visualizer.util.LookupUtils; +import com.sun.hotspot.igv.data.ChangedListener; +import com.sun.hotspot.igv.data.Group; +import com.sun.hotspot.igv.data.InputGraph; +import com.sun.hotspot.igv.util.RangeSliderModel; +import java.awt.BorderLayout; +import java.awt.CardLayout; +import java.awt.Component; +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; +import org.openide.util.lookup.InstanceContent; +import org.openide.util.lookup.Lookups; +import org.openide.util.lookup.ProxyLookup; +import org.openide.windows.Mode; +import org.openide.windows.TopComponent; +import org.openide.windows.WindowManager; + +public final class EditorTopComponent extends TopComponent { + + private InstanceContent content; + private static final String PREFERRED_ID = "EditorTopComponent"; + private RangeSliderModel rangeSliderModel; + private CompilationViewer activeViewer; + private CompilationViewerFactory activeFactory; + private Group group; + private final JToolBar viewerToolBar; + private final JPanel viewerPanel; + private final CardLayout viewerPanelCardLayout; + private final Map createdComponents = new HashMap<>(); + private final Lookup proxyLookup; + private Lookup currentLookup = Lookups.fixed(); + private final Lookup.Provider currentViewLookupProvider = new Lookup.Provider() { + + @Override + public Lookup getLookup() { + 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()); + } + + private InputGraph getSecondGraph() { + return group.getGraphs().get(getModel().getSecondPosition()); + } + + private void updateDisplayName() { + int first = getModel().getFirstPosition(); + int second = getModel().getSecondPosition(); + if (first == second) { + setDisplayName(getModel().getPositions().get(first)); + } else { + setDisplayName(String.format("%s: %s - %s", activeFactory.getName(), getModel().getPositions().get(first), getModel().getPositions().get(second))); + } + } + + private void activateFactory(CompilationViewerFactory factory) { + this.activeFactory = factory; + getPreferences().put(PREFERENCE_FACTORY, activeFactory.getName()); + updateView(); + } + + public EditorTopComponent(InputGraph graph) { + setName(NbBundle.getMessage(EditorTopComponent.class, "CTL_EditorTopComponent")); + setToolTipText(NbBundle.getMessage(EditorTopComponent.class, "HINT_EditorTopComponent")); + + initComponents(); + + Toolbar toolBar = new Toolbar(); + this.add(BorderLayout.NORTH, toolBar); + + this.group = graph.getGroup(); + rangeSliderModel = new RangeSliderModel(calculateStringList(group)); + content = new InstanceContent(); + content.add(rangeSliderModel); + int graphPos = group.getGraphs().indexOf(graph); + rangeSliderModel.setPositions(graphPos, graphPos); + + Collection factories = Lookup.getDefault().lookupAll(CompilationViewerFactory.class); + proxyLookup = Lookups.proxy(currentViewLookupProvider); + this.associateLookup(new ProxyLookup(new Lookup[]{proxyLookup, new AbstractLookup(content)})); + + rangeSliderModel.getChangedEvent().addListener(rangeSliderListener); + + ButtonGroup factoryButtonGroup = new ButtonGroup(); + for (CompilationViewerFactory factory : factories) { + AbstractButton button = createFactoryChangeButton(factory); + factoryButtonGroup.add(button); + toolBar.add(button); + } + toolBar.addSeparator(); + + viewerToolBar = new JToolBar(); + viewerToolBar.setFloatable(false); + toolBar.add(viewerToolBar); + toolBar.add(Box.createHorizontalGlue()); + + Action action = Utilities.actionsForPath("QuickSearchShadow").get(0); + Component quicksearch = ((Presenter.Toolbar) action).getToolbarPresenter(); + quicksearch.setMinimumSize(quicksearch.getPreferredSize()); // necessary for GTK LAF + toolBar.add(quicksearch); + + viewerPanel = new JPanel(); + viewerPanelCardLayout = new CardLayout(); + viewerPanel.setLayout(viewerPanelCardLayout); + this.add(viewerPanel, BorderLayout.CENTER); + + 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(); + } + + private static List calculateStringList(Group g) { + List result = new ArrayList<>(); + for (InputGraph graph : g.getGraphs()) { + result.add(graph.getName()); + } + return result; + } + + private RangeSliderModel getModel() { + return rangeSliderModel; + } + + public static EditorTopComponent getActive() { + Set modes = WindowManager.getDefault().getModes(); + for (Mode m : modes) { + TopComponent tc = m.getSelectedTopComponent(); + if (tc instanceof EditorTopComponent) { + return (EditorTopComponent) tc; + } + } + return null; + } + + /** + * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + jCheckBox1 = new javax.swing.JCheckBox(); + + org.openide.awt.Mnemonics.setLocalizedText(jCheckBox1, "jCheckBox1"); + jCheckBox1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); + jCheckBox1.setMargin(new java.awt.Insets(0, 0, 0, 0)); + + setLayout(new java.awt.BorderLayout()); + }// //GEN-END:initComponents + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JCheckBox jCheckBox1; + // End of variables declaration//GEN-END:variables + + @Override + public int getPersistenceType() { + return TopComponent.PERSISTENCE_NEVER; + } + + @Override + public void componentOpened() { + } + + @Override + public void componentClosed() { + } + + @Override + protected String preferredID() { + return PREFERRED_ID; + } + private ChangedListener rangeSliderListener = new ChangedListener() { + + @Override + public void changed(RangeSliderModel source) { + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + updateView(); + } + }); + } + }; + + private void updateView() { + updateDisplayName(); + String id = getViewStringIdentifier(); + if (!createdComponents.containsKey(id)) { + CompilationViewer newViewer = createViewer(activeFactory); + createdComponents.put(id, newViewer); + viewerPanel.add(newViewer.getComponent(), id); + } + + CompilationViewer newViewer = createdComponents.get(id); + if (newViewer != activeViewer) { + activeViewer = newViewer; + viewerPanelCardLayout.show(viewerPanel, id); + + currentLookup = new ProxyLookup(activeViewer.getLookup(), Lookups.fixed(getFirstGraph(), getSecondGraph())); + initializeToolBar(activeFactory.getName()); + + // Make sure that lookup is updated. + proxyLookup.lookup(Object.class); + } + } + + private String getViewStringIdentifier() { + return String.format("%s/%d/%d", activeFactory.getName(), getModel().getFirstPosition(), getModel().getSecondPosition()); + } + + private AbstractButton createFactoryChangeButton(final CompilationViewerFactory factory) { + JToggleButton toggleButton = new JToggleButton(factory.getName()); + toggleButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + activateFactory(factory); + } + }); + return toggleButton; + } + + private CompilationViewer createViewer(CompilationViewerFactory activeFactory) { + InputGraph firstSnapshot = getFirstGraph(); + InputGraph secondSnapshot = getSecondGraph(); + return activeFactory.createViewer(firstSnapshot, secondSnapshot); + } + + private void initializeToolBar(String id) { + viewerToolBar.removeAll(); + 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 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/ExportCookie.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/ExportCookie.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.visualizer.editor; + +import java.io.File; + +/** + * + * @author Thomas Wuerthinger + */ +public interface ExportCookie { + + void export(File f); +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/GraphViewerImplementation.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/GraphViewerImplementation.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ +package com.oracle.graal.visualizer.editor; + +import com.sun.hotspot.igv.data.InputGraph; +import com.sun.hotspot.igv.data.services.GraphViewer; + +/** + * + * @author Thomas Wuerthinger + */ +public class GraphViewerImplementation implements GraphViewer { + + @Override + public void view(InputGraph graph) { + EditorTopComponent tc = new EditorTopComponent(graph); + tc.open(); + tc.requestActive(); + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/NodeQuickSearch.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/NodeQuickSearch.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ +package com.oracle.graal.visualizer.editor; + +import com.sun.hotspot.igv.data.InputNode; +import com.sun.hotspot.igv.data.Properties; +import com.sun.hotspot.igv.data.Properties.RegexpPropertyMatcher; +import com.sun.hotspot.igv.data.services.InputGraphProvider; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.regex.Pattern; +import org.netbeans.spi.quicksearch.SearchProvider; +import org.netbeans.spi.quicksearch.SearchRequest; +import org.netbeans.spi.quicksearch.SearchResponse; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.NotifyDescriptor.Message; + +/** + * + * @author Thomas Wuerthinger + */ +public class NodeQuickSearch implements SearchProvider { + + private static final String DEFAULT_PROPERTY = "name"; + + /** + * Method is called by infrastructure when search operation was requested. + * Implementors should evaluate given request and fill response object with + * apropriate results + * + * @param request Search request object that contains information what to search for + * @param response Search response object that stores search results. Note that it's important to react to return value of SearchResponse.addResult(...) method and stop computation if false value is returned. + */ + @Override + public void evaluate(SearchRequest request, SearchResponse response) { + String query = request.getText(); + if (query.trim().isEmpty()) { + return; + } + + final String[] parts = query.split("=", 2); + + String name; + String value; + + if (parts.length == 1) { + name = DEFAULT_PROPERTY; + value = ".*" + Pattern.quote(parts[0]) + ".*"; + } else { + name = parts[0]; + value = parts[1]; + } + + if (value.isEmpty()) { + value = ".*"; + } + + final InputGraphProvider p = null;// TODO: FIXME LookupHistory.getLast(InputGraphProvider.class); + if (p != null && p.getGraph() != null) { + List matches = null; + try { + RegexpPropertyMatcher matcher = new RegexpPropertyMatcher(name, value, Pattern.CASE_INSENSITIVE); + Properties.PropertySelector selector = new Properties.PropertySelector<>(p.getGraph().getNodes()); + + matches = selector.selectMultiple(matcher); + } catch (Exception e) { + final String msg = e.getMessage(); + response.addResult(new Runnable() { + @Override + public void run() { + Message desc = new NotifyDescriptor.Message("An exception occurred during the search, " + + "perhaps due to a malformed query string:\n" + msg, + NotifyDescriptor.WARNING_MESSAGE); + DialogDisplayer.getDefault().notify(desc); + } + }, + "(Error during search)" + ); + } + + if (matches != null) { + final Set set = new HashSet<>(matches); + response.addResult(new Runnable() { + @Override + public void run() { + final EditorTopComponent comp = EditorTopComponent.getActive(); + if (comp != null) { + // TODO: find connection again! + //comp.setSelectedNodes(set); + comp.requestActive(); + } + } + }, + "All " + matches.size() + " matching nodes (" + name + "=" + value + ")" + ); + + // Single matches + for (final InputNode n : matches) { + response.addResult(new Runnable() { + @Override + public void run() { + final EditorTopComponent comp = EditorTopComponent.getActive(); + if (comp != null) { + final Set tmpSet = new HashSet<>(); + tmpSet.add(n); + // TODO: find connection again! + //comp.setSelectedNodes(tmpSet); + comp.requestActive(); + } + } + }, + n.getProperties().get(name) + " (" + n.getId() + " " + n.getProperties().get("name") + ")" + ); + } + } + } else { + System.out.println("no input graph provider!"); + } + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/SplitCompilationViewer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/SplitCompilationViewer.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ +package com.oracle.graal.visualizer.editor; + +import com.sun.hotspot.igv.graph.Figure; +import java.awt.BorderLayout; +import java.awt.Component; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.Collection; +import java.util.prefs.Preferences; +import javax.swing.JPanel; +import javax.swing.JSplitPane; +import javax.swing.JToolBar; +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() { + + @Override + public void propertyChange(PropertyChangeEvent changeEvent) { + String propertyName = changeEvent.getPropertyName(); + if (propertyName.equals(JSplitPane.DIVIDER_LOCATION_PROPERTY)) { + setLastDividerLocation((Integer) changeEvent.getNewValue()); + } + } + }; + + private static void setLastDividerLocation(int pos) { + NbPreferences.forModule(SplitCompilationViewer.class).put(DIVIDER_LOCATION, Integer.toString(pos)); + } + + private static int getLastDividerLocation() { + try { + return Integer.parseInt(NbPreferences.forModule(SplitCompilationViewer.class).get(DIVIDER_LOCATION, "400")); + } catch (NumberFormatException e) { + return 400; + } + } + + public SplitCompilationViewer(CompilationViewer firstViewer, CompilationViewer secondViewer) { + splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); + firstPanel = createComponent(firstViewer); + secondPanel = createComponent(secondViewer); + splitPane.add(firstPanel); + splitPane.add(secondPanel); + splitPane.addPropertyChangeListener(splitChanged); + splitPane.setDividerLocation(getLastDividerLocation()); + combinedLookup = new ProxyLookup(firstViewer.getLookup(), secondViewer.getLookup()); + } + + @Override + public Lookup getLookup() { + return combinedLookup; + } + + @Override + public Component getComponent() { + return splitPane; + } + + private Component createComponent(CompilationViewer viewer) { + return viewer.getComponent(); + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/SplitCompilationViewerFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/SplitCompilationViewerFactory.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +package com.oracle.graal.visualizer.editor; + +import com.sun.hotspot.igv.data.InputGraph; + +public abstract class SplitCompilationViewerFactory implements CompilationViewerFactory { + + @Override + public CompilationViewer createViewer(InputGraph firstGraph, InputGraph secondGraph) { + if (firstGraph == secondGraph) { + return createViewer(firstGraph); + } else { + CompilationViewer firstViewer = createViewer(firstGraph); + CompilationViewer secondViewer = createViewer(secondGraph); + return new SplitCompilationViewer(firstViewer, secondViewer); + } + } + + protected abstract CompilationViewer createViewer(InputGraph graph); +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/layer.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/layer.xml Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Graal/src/com/sun/hotspot/igv/graal/Bundle.properties --- a/src/share/tools/IdealGraphVisualizer/Graal/src/com/sun/hotspot/igv/graal/Bundle.properties Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Graal/src/com/sun/hotspot/igv/graal/Bundle.properties Tue Feb 07 21:09:31 2012 +0100 @@ -1,1 +1,1 @@ -OpenIDE-Module-Name=Graal Compiler Support +OpenIDE-Module-Name=GraalCompilerSupport diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/NetworkConnection/build.xml --- a/src/share/tools/IdealGraphVisualizer/NetworkConnection/build.xml Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ - - - - - - Builds, tests, and runs the project com.sun.hotspot.igv.connection. - - diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/NetworkConnection/manifest.mf --- a/src/share/tools/IdealGraphVisualizer/NetworkConnection/manifest.mf Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -Manifest-Version: 1.0 -OpenIDE-Module: com.sun.hotspot.igv.connection -OpenIDE-Module-Layer: com/sun/hotspot/igv/connection/layer.xml -OpenIDE-Module-Localizing-Bundle: com/sun/hotspot/igv/connection/Bundle.properties -OpenIDE-Module-Specification-Version: 1.0 - diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/NetworkConnection/nbproject/build-impl.xml --- a/src/share/tools/IdealGraphVisualizer/NetworkConnection/nbproject/build-impl.xml Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ - - - - - - - - - - - - - You must set 'suite.dir' to point to your containing module suite - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/NetworkConnection/nbproject/genfiles.properties --- a/src/share/tools/IdealGraphVisualizer/NetworkConnection/nbproject/genfiles.properties Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. -# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=5a0e591e -nbproject/build-impl.xml.script.CRC32=61516e53 -nbproject/build-impl.xml.stylesheet.CRC32=238281d1@1.45.1 diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/NetworkConnection/nbproject/project.properties --- a/src/share/tools/IdealGraphVisualizer/NetworkConnection/nbproject/project.properties Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -javac.source=1.7 -javac.compilerargs=-Xlint -Xlint:-serial diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/NetworkConnection/nbproject/project.xml --- a/src/share/tools/IdealGraphVisualizer/NetworkConnection/nbproject/project.xml Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ - - - org.netbeans.modules.apisupport.project - - - com.sun.hotspot.igv.connection - - - - com.sun.hotspot.igv.data - - - - 1.0 - - - - com.sun.hotspot.igv.settings - - - - 1.0 - - - - org.openide.awt - - - - 7.30.1 - - - - org.openide.dialogs - - - - 7.18.1 - - - - org.openide.util - - - - 8.14.1 - - - - org.openide.util.lookup - - - - 8.6.1 - - - - - com.sun.hotspot.igv.connection - - - - diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/NetworkConnection/nbproject/suite.properties --- a/src/share/tools/IdealGraphVisualizer/NetworkConnection/nbproject/suite.properties Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -suite.dir=${basedir}/.. diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Bundle.properties --- a/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Bundle.properties Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -OpenIDE-Module-Name=NetworkConnection diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Client.java --- a/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Client.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,74 +0,0 @@ -/* - * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.sun.hotspot.igv.connection; - -import com.sun.hotspot.igv.data.serialization.Parser; -import com.sun.hotspot.igv.data.services.GroupCallback; -import java.io.BufferedInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.Socket; -import org.openide.util.Exceptions; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -/** - * - * @author Thomas Wuerthinger - */ -public class Client implements Runnable { - - private Socket socket; - private GroupCallback callback; - - public Client(Socket socket, GroupCallback callback) { - this.callback = callback; - this.socket = socket; - } - - @Override - public void run() { - - try { - InputStream inputStream = new BufferedInputStream(socket.getInputStream()); - InputSource is = new InputSource(inputStream); - - try { - Parser parser = new Parser(callback); - parser.parse(is, null); - } catch (SAXException ex) { - ex.printStackTrace(); - } - } catch (IOException ex) { - Exceptions.printStackTrace(ex); - } finally { - try { - socket.close(); - } catch (IOException ex) { - Exceptions.printStackTrace(ex); - } - } - } -} \ No newline at end of file diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Server.java --- a/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Server.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,103 +0,0 @@ -/* - * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.sun.hotspot.igv.connection; - -import com.sun.hotspot.igv.data.services.GroupCallback; -import com.sun.hotspot.igv.settings.Settings; -import java.io.IOException; -import java.net.ServerSocket; -import java.net.Socket; -import java.util.prefs.PreferenceChangeEvent; -import java.util.prefs.PreferenceChangeListener; -import org.openide.DialogDisplayer; -import org.openide.NotifyDescriptor; -import org.openide.util.RequestProcessor; - -/** - * - * @author Thomas Wuerthinger - */ -public class Server implements PreferenceChangeListener { - - private ServerSocket serverSocket; - private GroupCallback callback; - private int port; - private Runnable serverRunnable; - - public Server(GroupCallback callback) { - - this.callback = callback; - initializeNetwork(); - Settings.get().addPreferenceChangeListener(this); - } - - @Override - public void preferenceChange(PreferenceChangeEvent e) { - - int curPort = Integer.parseInt(Settings.get().get(Settings.PORT, Settings.PORT_DEFAULT)); - if (curPort != port) { - initializeNetwork(); - } - } - - private void initializeNetwork() { - - int curPort = Integer.parseInt(Settings.get().get(Settings.PORT, Settings.PORT_DEFAULT)); - this.port = curPort; - try { - serverSocket = new java.net.ServerSocket(curPort); - } catch (IOException ex) { - NotifyDescriptor message = new NotifyDescriptor.Message("Could not create server. Listening for incoming data is disabled.", NotifyDescriptor.ERROR_MESSAGE); - DialogDisplayer.getDefault().notifyLater(message); - return; - } - - Runnable runnable = new Runnable() { - - @Override - public void run() { - while (true) { - try { - Socket clientSocket = serverSocket.accept(); - if (serverRunnable != this) { - clientSocket.close(); - return; - } - RequestProcessor.getDefault().post(new Client(clientSocket, callback), 0, Thread.MAX_PRIORITY); - } catch (IOException ex) { - serverSocket = null; - NotifyDescriptor message = new NotifyDescriptor.Message("Error during listening for incoming connections. Listening for incoming data is disabled.", NotifyDescriptor.ERROR_MESSAGE); - DialogDisplayer.getDefault().notifyLater(message); - return; - } - } - } - }; - - serverRunnable = runnable; - - RequestProcessor.getDefault().post(runnable, 0, Thread.MAX_PRIORITY); - } -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/layer.xml --- a/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/layer.xml Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ - - - - diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/OutlineView/manifest.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/OutlineView/manifest.mf Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,6 @@ +Manifest-Version: 1.0 +OpenIDE-Module: com.oracle.graal.visualizer.outline +OpenIDE-Module-Layer: com/oracle/graal/visualizer/outline/layer.xml +OpenIDE-Module-Localizing-Bundle: com/oracle/graal/visualizer/outline/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/Bundle.properties Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,5 @@ +AdvancedOption_DisplayName_Coordinator=Settings +AdvancedOption_Tooltip_Coordinator=Visualization Tool Settings +CTL_OutlineTopComponent=Outline +HINT_OutlineTopComponent=Displays loaded compilations. +OpenIDE-Module-Name=OutlineView diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/CompilationNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/CompilationNode.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ +package com.oracle.graal.visualizer.outline; + +import com.sun.hotspot.igv.data.*; +import com.sun.hotspot.igv.data.services.GraphViewer; +import java.awt.Image; +import java.util.ArrayList; +import java.util.List; +import javax.swing.Action; +import javax.swing.JOptionPane; +import org.openide.actions.OpenAction; +import org.openide.cookies.OpenCookie; +import org.openide.nodes.AbstractNode; +import org.openide.nodes.Children; +import org.openide.nodes.Node; +import org.openide.util.ImageUtilities; +import org.openide.util.Lookup; +import org.openide.util.lookup.AbstractLookup; +import org.openide.util.lookup.InstanceContent; +import org.openide.util.lookup.Lookups; + +public class CompilationNode extends AbstractNode implements ChangedListener { + + private CompilationNode(final Folder folder, Children children, InstanceContent content) { + super(children, new AbstractLookup(content)); + this.setDisplayName(folder.getName()); + + if (folder instanceof Group) { + content.add(new OpenCookie() { + + @Override + public void open() { + final List graphs = ((Group) folder).getGraphs(); + if (graphs.isEmpty()) { + JOptionPane.showMessageDialog(null, "Cannot open compilation, because there was no snapshots recorded!"); + } else { + Lookup.getDefault().lookup(GraphViewer.class).view(graphs.get(0)); + } + } + }); + } + content.add(folder); + folder.getChangedEvent().addListener(this); + } + + @Override + public void changed(Object folder) { + if (this.getChildren() == Children.LEAF) { + setChildren(createFolderChildren((Folder) folder)); + this.fireIconChange(); + } + } + + private static class FolderChildren extends Children.Keys { + + private final Folder folder; + + public FolderChildren(Folder folder) { + this.folder = folder; + folder.getChangedEvent().addListener(changedListener); + } + + @Override + protected Node[] createNodes(Folder e) { + return new Node[]{new CompilationNode(e)}; + } + + @Override + public void addNotify() { + List result = new ArrayList<>(); + for (FolderElement o : folder.getElements()) { + if (o instanceof Folder) { + result.add((Folder) o); + } + } + this.setKeys(result); + } + private final ChangedListener changedListener = new ChangedListener() { + + @Override + public void changed(Object source) { + addNotify(); + } + }; + } + + @Override + public Image getIcon(int i) { + if (this.getChildren() == Children.LEAF) { + return ImageUtilities.loadImage("com/oracle/graal/visualizer/outline/images/leaf_node.gif"); + } else { + return ImageUtilities.loadImage("com/oracle/graal/visualizer/outline/images/node.gif"); + } + } + + protected CompilationNode(Folder folder) { + this(folder, createFolderChildren(folder), new InstanceContent()); + } + + private static Children createFolderChildren(Folder folder) { + for (FolderElement elem : folder.getElements()) { + if (elem instanceof Folder) { + return new FolderChildren(folder); + } + } + return Children.LEAF; + } + + @Override + public Action[] getActions(boolean context) { + List actions = new ArrayList<>(); + actions.add((Action) OpenAction.findObject(OpenAction.class, true)); + actions.addAll(Lookups.forPath(OutlineTopComponent.NODE_ACTIONS_FOLDER).lookupAll(Action.class)); + return actions.toArray(new Action[actions.size()]); + } + + @Override + public Action getPreferredAction() { + return (Action) OpenAction.findObject(OpenAction.class, true); + } + + @Override + public Image getOpenedIcon(int i) { + return getIcon(i); + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/OutlineTopComponent.form --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/OutlineTopComponent.form Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,32 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/OutlineTopComponent.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/OutlineTopComponent.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ +package com.oracle.graal.visualizer.outline; + +import com.oracle.graal.visualizer.outline.server.ServerPanel; +import com.oracle.graal.visualizer.util.LookupUtils; +import com.sun.hotspot.igv.data.GraphDocument; +import java.awt.BorderLayout; +import javax.swing.Action; +import org.openide.actions.GarbageCollectAction; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.Toolbar; +import org.openide.explorer.ExplorerManager; +import org.openide.explorer.ExplorerUtils; +import org.openide.explorer.view.BeanTreeView; +import org.openide.util.NbBundle; +import org.openide.windows.TopComponent; +import org.openide.windows.WindowManager; + +@TopComponent.Description(preferredID = OutlineTopComponent.PREFERRED_ID, persistenceType = TopComponent.PERSISTENCE_ALWAYS) +@TopComponent.Registration(mode = "explorer", openAtStartup = true) +@ActionID(category = "Window", id = "com.oracle.graal.visualizer.outline.OutlineTopComponent") +@ActionReference(path = "Menu/Window") +@TopComponent.OpenActionRegistration(displayName = "Outline", preferredID = OutlineTopComponent.PREFERRED_ID) +public final class OutlineTopComponent extends TopComponent implements ExplorerManager.Provider { + + public static final String GLOBAL_ACTIONS_FOLDER = "Actions/Outline/Global"; + public static final String NODE_ACTIONS_FOLDER = "Actions/Outline/Nodes"; + public static OutlineTopComponent instance; + public static final String PREFERRED_ID = "OutlineTopComponent"; + private ExplorerManager manager; + private GraphDocument document; + + private OutlineTopComponent() { + initComponents(); + + setName(NbBundle.getMessage(OutlineTopComponent.class, "CTL_OutlineTopComponent")); + setToolTipText(NbBundle.getMessage(OutlineTopComponent.class, "HINT_OutlineTopComponent")); + + document = new GraphDocument(); + initListView(); + initToolbar(); + } + + private void initListView() { + manager = new ExplorerManager(); + manager.setRootContext(new CompilationNode(document)); + ((BeanTreeView) this.treeView).setRootVisible(false); + associateLookup(ExplorerUtils.createLookup(manager, getActionMap())); + } + + private void initToolbar() { + Toolbar toolbar = new Toolbar(); + this.add(toolbar, BorderLayout.NORTH); + for (Action a : LookupUtils.lookupActions(GLOBAL_ACTIONS_FOLDER, getLookup())) { + toolbar.add(a); + } + toolbar.add(GarbageCollectAction.get(GarbageCollectAction.class).getToolbarPresenter()); + toolbar.add(new ServerPanel(getDocument())); + } + + @Override + public ExplorerManager getExplorerManager() { + return manager; + } + + public GraphDocument getDocument() { + return document; + } + + public static OutlineTopComponent findInstance() { + return (OutlineTopComponent) WindowManager.getDefault().findTopComponent(PREFERRED_ID); + } + + @Override + public int getPersistenceType() { + return TopComponent.PERSISTENCE_NEVER; + } + + @Override + protected String preferredID() { + return PREFERRED_ID; + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + treeView = new BeanTreeView(); + + setLayout(new java.awt.BorderLayout()); + add(treeView, java.awt.BorderLayout.CENTER); + }// //GEN-END:initComponents + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JScrollPane treeView; + // End of variables declaration//GEN-END:variables +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/actions/ImportAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/actions/ImportAction.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +package com.oracle.graal.visualizer.outline.actions; + +import com.oracle.graal.visualizer.outline.OutlineTopComponent; +import com.sun.hotspot.igv.data.GraphDocument; +import com.sun.hotspot.igv.data.serialization.Parser; +import com.sun.hotspot.igv.data.serialization.XMLParser; +import com.sun.hotspot.igv.settings.Settings; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import javax.swing.JFileChooser; +import javax.swing.SwingUtilities; +import javax.swing.filechooser.FileFilter; +import org.netbeans.api.progress.ProgressHandle; +import org.netbeans.api.progress.ProgressHandleFactory; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; +import org.openide.awt.ActionRegistration; +import org.openide.util.RequestProcessor; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +@ActionID(id = "com.oracle.graal.visualizer.outline.actions.ImportAction", category = "File") +@ActionRegistration(displayName = "Import", iconBase="com/oracle/graal/visualizer/outline/images/import.png") +@ActionReferences(value = { + @ActionReference(path = "Menu/File", position = 100), + @ActionReference(path = OutlineTopComponent.GLOBAL_ACTIONS_FOLDER)}) +public final class ImportAction implements ActionListener { + + public static FileFilter getFileFilter() { + return new FileFilter() { + + @Override + public boolean accept(File f) { + return f.getName().toLowerCase().endsWith(".xml") || f.isDirectory(); + } + + @Override + public String getDescription() { + return "XML files (*.xml)"; + } + }; + } + + @Override + public void actionPerformed(ActionEvent e) { + + JFileChooser fc = new JFileChooser(); + fc.setFileFilter(ImportAction.getFileFilter()); + fc.setCurrentDirectory(new File(Settings.get().get(Settings.DIRECTORY, Settings.DIRECTORY_DEFAULT))); + + if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { + File file = fc.getSelectedFile(); + + File dir = file; + if (!dir.isDirectory()) { + dir = dir.getParentFile(); + } + + Settings.get().put(Settings.DIRECTORY, dir.getAbsolutePath()); + + try { + final FileInputStream inputStream = new FileInputStream(file); + final InputSource is = new InputSource(inputStream); + + final ProgressHandle handle = ProgressHandleFactory.createHandle("Opening file " + file.getName()); + final int basis = 1000; + handle.start(basis); + final int start = inputStream.available(); + + final XMLParser.ParseMonitor parseMonitor = new XMLParser.ParseMonitor() { + + @Override + public void setProgress(double d) { + try { + int curAvailable = inputStream.available(); + int prog = (int) (basis * (double) (start - curAvailable) / (double) start); + handle.progress(prog); + } catch (IOException ex) { + } + } + + @Override + public void setState(String state) { + setProgress(0.0); + handle.progress(state); + } + }; + final Parser parser = new Parser(); + final OutlineTopComponent component = OutlineTopComponent.findInstance(); + + component.requestActive(); + + RequestProcessor.getDefault().post(new Runnable() { + + @Override + public void run() { + try { + final GraphDocument document = parser.parse(is, parseMonitor); + parseMonitor.setState("Finishing"); + SwingUtilities.invokeLater(new Runnable(){ + + @Override + public void run() { + component.getDocument().addGraphDocument(document); + } + }); + } catch (SAXException ex) { + String s = "Exception during parsing the XML file, could not load document!"; + if (ex instanceof XMLParser.MissingAttributeException) { + XMLParser.MissingAttributeException e = (XMLParser.MissingAttributeException) ex; + s += "\nMissing attribute \"" + e.getAttributeName() + "\""; + } + NotifyDescriptor d = new NotifyDescriptor.Message(s, NotifyDescriptor.ERROR_MESSAGE); + DialogDisplayer.getDefault().notify(d); + } + handle.finish(); + } + }); + + } catch (IOException ex) { + DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message("Error reading file!", NotifyDescriptor.ERROR_MESSAGE)); + } + } + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/actions/RemoveAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/actions/RemoveAction.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ +package com.oracle.graal.visualizer.outline.actions; + +import com.oracle.graal.visualizer.outline.OutlineTopComponent; +import com.sun.hotspot.igv.data.FolderElement; +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.ActionReferences; +import org.openide.awt.ActionRegistration; + +@ActionID(id = "com.oracle.graal.visualizer.outline.actions.RemoveAction", category = "Edit") +@ActionRegistration(displayName = "Remove", iconBase = "com/oracle/graal/visualizer/outline/images/remove.png") +@ActionReferences(value = { + @ActionReference(path = "Menu/File", position = 400), + @ActionReference(path = OutlineTopComponent.NODE_ACTIONS_FOLDER)}) +public final class RemoveAction implements ActionListener { + + List elements; + + public RemoveAction(List elements) { + this.elements = elements; + } + + @Override + public void actionPerformed(ActionEvent e) { + for (FolderElement element : elements) { + element.getParent().removeElement(element); + } + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/actions/RemoveAllAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/actions/RemoveAllAction.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.visualizer.outline.actions; + +import com.oracle.graal.visualizer.outline.OutlineTopComponent; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; +import org.openide.awt.ActionRegistration; + +@ActionID(id = "com.oracle.graal.visualizer.outline.actions.RemoveAllAction", category = "Edit") +@ActionRegistration(displayName = "Remove all", iconBase = "com/oracle/graal/visualizer/outline/images/removeall.png") +@ActionReferences(value = { + @ActionReference(path = "Menu/File", position = 500), + @ActionReference(path = OutlineTopComponent.GLOBAL_ACTIONS_FOLDER)}) +public final class RemoveAllAction implements ActionListener { + + @Override + public void actionPerformed(ActionEvent e) { + OutlineTopComponent.findInstance().getDocument().clear(); + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/actions/SaveAllAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/actions/SaveAllAction.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.visualizer.outline.actions; + +import com.oracle.graal.visualizer.outline.OutlineTopComponent; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; +import org.openide.awt.ActionRegistration; + +@ActionID(id = "com.oracle.graal.visualizer.outline.actions.SaveAllAction", category = "File") +@ActionRegistration(displayName = "Save all..", iconBase = "com/oracle/graal/visualizer/outline/images/saveall.gif") +@ActionReferences(value = { + @ActionReference(path = "Menu/File", position = 300), + @ActionReference(path = OutlineTopComponent.GLOBAL_ACTIONS_FOLDER)}) +public final class SaveAllAction implements ActionListener { + + @Override + public void actionPerformed(ActionEvent e) { + final OutlineTopComponent component = OutlineTopComponent.findInstance(); + SaveAsAction.save(component.getDocument()); + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/actions/SaveAsAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/actions/SaveAsAction.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +package com.oracle.graal.visualizer.outline.actions; + +import com.oracle.graal.visualizer.outline.OutlineTopComponent; +import com.sun.hotspot.igv.data.Folder; +import com.sun.hotspot.igv.data.FolderElement; +import com.sun.hotspot.igv.data.GraphDocument; +import com.sun.hotspot.igv.data.serialization.Printer; +import com.sun.hotspot.igv.settings.Settings; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.*; +import java.util.List; +import javax.swing.JFileChooser; +import javax.swing.JOptionPane; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; +import org.openide.awt.ActionRegistration; + +@ActionID(id = "com.oracle.graal.visualizer.outline.actions.SaveAsAction", category = "File") +@ActionRegistration(displayName = "Save as...", iconBase="com/oracle/graal/visualizer/outline/images/save.png") +@ActionReferences(value = { + @ActionReference(path = "Menu/File", position = 200), + @ActionReference(path = OutlineTopComponent.NODE_ACTIONS_FOLDER)}) +public final class SaveAsAction implements ActionListener { + + private final List elements; + + public SaveAsAction(List elements) { + this.elements = elements; + } + + + @Override + public void actionPerformed(ActionEvent e) { + GraphDocument doc = new GraphDocument(); + outer: for (FolderElement element : elements) { + Folder cur = element.getParent(); + while (cur instanceof FolderElement) { + FolderElement curElement = (FolderElement) cur; + if (elements.contains(curElement)) { + continue outer; + } + cur = curElement.getParent(); + } + + Folder previousParent = element.getParent(); + doc.addElement(element); + element.setParent(previousParent); + } + + save(doc); + } + + public static void save(GraphDocument doc) { + JFileChooser fc = new JFileChooser(); + fc.setFileFilter(ImportAction.getFileFilter()); + fc.setCurrentDirectory(new File(Settings.get().get(Settings.DIRECTORY, Settings.DIRECTORY_DEFAULT))); + + if (fc.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { + File file = fc.getSelectedFile(); + if (!file.getName().contains(".")) { + file = new File(file.getAbsolutePath() + ".xml"); + } + + File dir = file; + if (!dir.isDirectory()) { + dir = dir.getParentFile(); + } + Settings.get().put(Settings.DIRECTORY, dir.getAbsolutePath()); + try { + try (Writer writer = new OutputStreamWriter(new FileOutputStream(file))) { + Printer p = new Printer(); + p.export(writer, doc); + } + } catch (IOException e) { + JOptionPane.showMessageDialog(null, "Error writing file " + file.getAbsolutePath()); + } + } + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/import.png Binary file src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/import.png has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/leaf_node.gif Binary file src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/leaf_node.gif has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/node.gif Binary file src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/node.gif has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/remove.png Binary file src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/remove.png has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/removeall.png Binary file src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/removeall.png has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/save.png Binary file src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/save.png has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/saveall.gif Binary file src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/saveall.gif has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/layer.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/layer.xml Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,161 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/server/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/server/Bundle.properties Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,1 @@ +OpenIDE-Module-Name=NetworkConnection diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/server/Client.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/server/Client.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.visualizer.outline.server; + +import com.sun.hotspot.igv.data.serialization.Parser; +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.Socket; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +public class Client implements Runnable { + + private Socket socket; + private ServerCallback callback; + + public Client(Socket socket, ServerCallback callback) { + this.callback = callback; + this.socket = socket; + } + + @Override + public void run() { + callback.connectionOpened(socket.getInetAddress()); + try { + InputStream inputStream = new BufferedInputStream(socket.getInputStream()); + InputSource is = new InputSource(inputStream); + + try { + Parser parser = new Parser(callback); + parser.parse(is, null); + } catch (SAXException ex) { + throw new IOException(ex); + } + } catch (IOException ex) { + } finally { + try { + socket.close(); + } catch (IOException ex) { + } + callback.connectionClosed(); + } + } +} \ No newline at end of file diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/server/Server.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/server/Server.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.visualizer.outline.server; + +import java.io.IOException; +import java.net.ServerSocket; +import java.net.Socket; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.util.RequestProcessor; + +public class Server { + + private Runnable serverRunnable; + private ServerSocket serverSocket; + + private Server() {} + + + public static Server start(final ServerCallback callback, int port) { + + final Server server = new Server(); + + try { + server.serverSocket = new java.net.ServerSocket(port); + } catch (IOException ex) { + NotifyDescriptor message = new NotifyDescriptor.Message("Could not create server. Listening for incoming data is disabled.", NotifyDescriptor.ERROR_MESSAGE); + DialogDisplayer.getDefault().notifyLater(message); + return null; + } + + Runnable runnable = new Runnable() { + + @Override + public void run() { + while (true) { + try { + Socket clientSocket = server.serverSocket.accept(); + if (server.serverRunnable != this) { + clientSocket.close(); + return; + } + RequestProcessor.getDefault().post(new Client(clientSocket, callback), 0, Thread.MAX_PRIORITY); + } catch (IOException ex) { + server.serverSocket = null; + NotifyDescriptor message = new NotifyDescriptor.Message("Error during listening for incoming connections. Listening for incoming data is disabled.", NotifyDescriptor.ERROR_MESSAGE); + DialogDisplayer.getDefault().notifyLater(message); + return; + } + } + } + }; + + server.serverRunnable = runnable; + RequestProcessor.getDefault().post(runnable, 0, Thread.MAX_PRIORITY); + return server; + } + + void shutdown() { + try { + serverSocket.close(); + } catch (IOException ex) { + } + + serverSocket = null; + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/server/ServerCallback.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/server/ServerCallback.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.oracle.graal.visualizer.outline.server; + +import com.sun.hotspot.igv.data.services.GroupCallback; +import java.net.InetAddress; + +public interface ServerCallback extends GroupCallback { + + public void connectionOpened(InetAddress inetAddress); + + public void connectionClosed(); + +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/server/ServerPanel.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/server/ServerPanel.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.visualizer.outline.server; + +import com.sun.hotspot.igv.data.GraphDocument; +import com.sun.hotspot.igv.data.Group; +import com.sun.hotspot.igv.settings.Settings; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Font; +import java.net.InetAddress; +import java.util.prefs.PreferenceChangeEvent; +import java.util.prefs.PreferenceChangeListener; +import javax.swing.BorderFactory; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; + +public class ServerPanel extends JPanel { + + private final static int BORDER_SIZE = 2; + JLabel label; + private Server server; + private int port = -1; + private int numberOfConnections; + private final GraphDocument document; + private final PreferenceChangeListener preferenceChanged = new PreferenceChangeListener() { + + @Override + public void preferenceChange(PreferenceChangeEvent evt) { + updateServer(); + } + }; + private ServerCallback callback = new ServerCallback() { + + @Override + public void connectionOpened(InetAddress inetAddress) { + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + numberOfConnections++; + updateLabel(); + } + }); + } + + @Override + public void connectionClosed() { + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + numberOfConnections--; + updateLabel(); + } + }); + } + + @Override + public void started(Group g) { + document.addElement(g); + } + }; + + private void updateLabel() { + if (numberOfConnections == 0) { + label.setText(String.format("Listening on %d", port)); + label.setFont(label.getFont().deriveFont(Font.PLAIN)); + } else { + label.setText(String.format("%d connections", numberOfConnections)); + label.setFont(label.getFont().deriveFont(Font.BOLD)); + } + } + + private void updateServer() { + int curPort = Integer.parseInt(Settings.get().get(Settings.PORT, Settings.PORT_DEFAULT)); + if (curPort != port) { + port = curPort; + if (server != null) { + server.shutdown(); + } + server = Server.start(callback, port); + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + updateLabel(); + } + }); + } + } + + public ServerPanel(GraphDocument document) { + + this.document = document; + Settings.get().addPreferenceChangeListener(preferenceChanged); + label = new JLabel(); + label.setBorder(BorderFactory.createEmptyBorder(0, BORDER_SIZE, 0, BORDER_SIZE)); + this.setLayout(new BorderLayout()); + this.add(label, BorderLayout.WEST); + updateServer(); + } + + public Component getToolbarPresenter() { + return label; + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/SelectionCoordinator/build.xml --- a/src/share/tools/IdealGraphVisualizer/SelectionCoordinator/build.xml Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ - - - - - - Builds, tests, and runs the project com.sun.hotspot.igv.selectioncoordinator. - - diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/SelectionCoordinator/manifest.mf --- a/src/share/tools/IdealGraphVisualizer/SelectionCoordinator/manifest.mf Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -Manifest-Version: 1.0 -OpenIDE-Module: com.sun.hotspot.igv.selectioncoordinator -OpenIDE-Module-Localizing-Bundle: com/sun/hotspot/igv/selectioncoordinator/Bundle.properties -OpenIDE-Module-Specification-Version: 1.0 - diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/SelectionCoordinator/nbproject/build-impl.xml --- a/src/share/tools/IdealGraphVisualizer/SelectionCoordinator/nbproject/build-impl.xml Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ - - - - - - - - - - - - - You must set 'suite.dir' to point to your containing module suite - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/SelectionCoordinator/nbproject/genfiles.properties --- a/src/share/tools/IdealGraphVisualizer/SelectionCoordinator/nbproject/genfiles.properties Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. -# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=13553862 -nbproject/build-impl.xml.script.CRC32=3db87c68 -nbproject/build-impl.xml.stylesheet.CRC32=238281d1@1.45.1 diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/SelectionCoordinator/nbproject/platform.properties --- a/src/share/tools/IdealGraphVisualizer/SelectionCoordinator/nbproject/platform.properties Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,129 +0,0 @@ -# Deprecated since 5.0u1; for compatibility with 5.0: -disabled.clusters=\ - apisupport1,\ - gsf1,\ - harness,\ - java2,\ - nb6.1,\ - profiler3 -disabled.modules=\ - org.apache.xml.resolver,\ - org.netbeans.api.debugger,\ - org.netbeans.api.xml,\ - org.netbeans.core.execution,\ - org.netbeans.core.ide,\ - org.netbeans.core.multiview,\ - org.netbeans.core.nativeaccess,\ - org.netbeans.core.output2,\ - org.netbeans.insane,\ - org.netbeans.lib.cvsclient,\ - org.netbeans.libs.commons_logging,\ - org.netbeans.libs.freemarker,\ - org.netbeans.libs.ini4j,\ - org.netbeans.libs.jna,\ - org.netbeans.libs.jsch,\ - org.netbeans.libs.jsr223,\ - org.netbeans.libs.lucene,\ - org.netbeans.libs.svnClientAdapter,\ - org.netbeans.libs.xerces,\ - org.netbeans.modules.applemenu,\ - org.netbeans.modules.autoupdate.services,\ - org.netbeans.modules.autoupdate.ui,\ - org.netbeans.modules.classfile,\ - org.netbeans.modules.core.kit,\ - org.netbeans.modules.db,\ - org.netbeans.modules.db.core,\ - org.netbeans.modules.db.drivers,\ - org.netbeans.modules.db.kit,\ - org.netbeans.modules.db.mysql,\ - org.netbeans.modules.db.sql.editor,\ - org.netbeans.modules.db.sql.visualeditor,\ - org.netbeans.modules.dbapi,\ - org.netbeans.modules.defaults,\ - org.netbeans.modules.diff,\ - org.netbeans.modules.editor.bookmarks,\ - org.netbeans.modules.editor.bracesmatching,\ - org.netbeans.modules.editor.codetemplates,\ - org.netbeans.modules.editor.completion,\ - org.netbeans.modules.editor.errorstripe,\ - org.netbeans.modules.editor.errorstripe.api,\ - org.netbeans.modules.editor.guards,\ - org.netbeans.modules.editor.highlights,\ - org.netbeans.modules.editor.macros,\ - org.netbeans.modules.editor.plain,\ - org.netbeans.modules.editor.plain.lib,\ - org.netbeans.modules.editor.structure,\ - org.netbeans.modules.extbrowser,\ - org.netbeans.modules.favorites,\ - org.netbeans.modules.gototest,\ - org.netbeans.modules.httpserver,\ - org.netbeans.modules.ide.kit,\ - org.netbeans.modules.image,\ - org.netbeans.modules.javahelp,\ - org.netbeans.modules.jumpto,\ - org.netbeans.modules.languages,\ - org.netbeans.modules.languages.bat,\ - org.netbeans.modules.languages.diff,\ - org.netbeans.modules.languages.manifest,\ - org.netbeans.modules.languages.sh,\ - org.netbeans.modules.lexer.editorbridge,\ - org.netbeans.modules.lexer.nbbridge,\ - org.netbeans.modules.localhistory,\ - org.netbeans.modules.masterfs,\ - org.netbeans.modules.mercurial,\ - org.netbeans.modules.progress.ui,\ - org.netbeans.modules.project.ant,\ - org.netbeans.modules.project.libraries,\ - org.netbeans.modules.projectui,\ - org.netbeans.modules.projectuiapi,\ - org.netbeans.modules.properties,\ - org.netbeans.modules.properties.syntax,\ - org.netbeans.modules.refactoring.api,\ - org.netbeans.modules.schema2beans,\ - org.netbeans.modules.sendopts,\ - org.netbeans.modules.server,\ - org.netbeans.modules.servletapi,\ - org.netbeans.modules.subversion,\ - org.netbeans.modules.tasklist.kit,\ - org.netbeans.modules.tasklist.projectint,\ - org.netbeans.modules.tasklist.todo,\ - org.netbeans.modules.tasklist.ui,\ - org.netbeans.modules.templates,\ - org.netbeans.modules.timers,\ - org.netbeans.modules.usersguide,\ - org.netbeans.modules.utilities,\ - org.netbeans.modules.utilities.project,\ - org.netbeans.modules.versioning,\ - org.netbeans.modules.versioning.system.cvss,\ - org.netbeans.modules.versioning.util,\ - org.netbeans.modules.web.flyingsaucer,\ - org.netbeans.modules.xml,\ - org.netbeans.modules.xml.axi,\ - org.netbeans.modules.xml.catalog,\ - org.netbeans.modules.xml.core,\ - org.netbeans.modules.xml.lexer,\ - org.netbeans.modules.xml.multiview,\ - org.netbeans.modules.xml.retriever,\ - org.netbeans.modules.xml.schema.completion,\ - org.netbeans.modules.xml.schema.model,\ - org.netbeans.modules.xml.tax,\ - org.netbeans.modules.xml.text,\ - org.netbeans.modules.xml.tools,\ - org.netbeans.modules.xml.wsdl.model,\ - org.netbeans.modules.xml.xam,\ - org.netbeans.modules.xml.xdm,\ - org.netbeans.modules.xsl,\ - org.netbeans.spi.debugger.ui,\ - org.netbeans.spi.editor.hints,\ - org.netbeans.spi.navigator,\ - org.netbeans.spi.palette,\ - org.netbeans.spi.tasklist,\ - org.netbeans.spi.viewmodel,\ - org.netbeans.swing.dirchooser,\ - org.openide.compat,\ - org.openide.util.enumerations -enabled.clusters=\ - ide9,\ - platform8 -nbjdk.active=default -nbplatform.active=default diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/SelectionCoordinator/nbproject/project.properties --- a/src/share/tools/IdealGraphVisualizer/SelectionCoordinator/nbproject/project.properties Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -javac.source=1.7 -javac.compilerargs=-Xlint -Xlint:-serial diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/SelectionCoordinator/nbproject/project.xml --- a/src/share/tools/IdealGraphVisualizer/SelectionCoordinator/nbproject/project.xml Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ - - - org.netbeans.modules.apisupport.project - - - com.sun.hotspot.igv.selectioncoordinator - - - - com.sun.hotspot.igv.data - - - - 1.0 - - - - - com.sun.hotspot.igv.selectioncoordinator - - - - diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/SelectionCoordinator/nbproject/suite.properties --- a/src/share/tools/IdealGraphVisualizer/SelectionCoordinator/nbproject/suite.properties Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -suite.dir=${basedir}/.. diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/SelectionCoordinator/src/com/sun/hotspot/igv/selectioncoordinator/SelectionCoordinator.java --- a/src/share/tools/IdealGraphVisualizer/SelectionCoordinator/src/com/sun/hotspot/igv/selectioncoordinator/SelectionCoordinator.java Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/SelectionCoordinator/src/com/sun/hotspot/igv/selectioncoordinator/SelectionCoordinator.java Tue Feb 07 21:09:31 2012 +0100 @@ -100,7 +100,6 @@ private void highlightedObjectsChanged() { highlightedChangedEvent.fire(); - } public void addAllSelected(Set s) { diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ServerCompiler/build.xml --- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/build.xml Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ - - - - - - Builds, tests, and runs the project com.sun.hotspot.igv.servercompilerscheduler. - - diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ServerCompiler/manifest.mf --- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/manifest.mf Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -Manifest-Version: 1.0 -OpenIDE-Module: com.sun.hotspot.igv.servercompiler -OpenIDE-Module-Layer: com/sun/hotspot/igv/servercompiler/layer.xml -OpenIDE-Module-Localizing-Bundle: com/sun/hotspot/igv/servercompiler/Bundle.properties -OpenIDE-Module-Specification-Version: 1.0 - diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/build-impl.xml --- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/build-impl.xml Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ - - - - - - You must set 'suite.dir' to point to your containing module suite - - - - - - - - - - - - - - - - - - - - - diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/genfiles.properties --- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/genfiles.properties Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -build.xml.data.CRC32=d1360a65 -build.xml.script.CRC32=a9d94ef8 -build.xml.stylesheet.CRC32=79c3b980 -# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. -# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=d1360a65 -nbproject/build-impl.xml.script.CRC32=52847236 -nbproject/build-impl.xml.stylesheet.CRC32=deb65f65 diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/platform.properties --- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/platform.properties Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -# Deprecated since 5.0u1; for compatibility with 5.0: -disabled.clusters=\ - apisupport1,\ - harness,\ - ide8,\ - java1,\ - nb6.0,\ - profiler2 -disabled.modules=\ - org.netbeans.core.execution,\ - org.netbeans.core.multiview,\ - org.netbeans.core.output2,\ - org.netbeans.modules.applemenu,\ - org.netbeans.modules.autoupdate.services,\ - org.netbeans.modules.autoupdate.ui,\ - org.netbeans.modules.core.kit,\ - org.netbeans.modules.favorites,\ - org.netbeans.modules.javahelp,\ - org.netbeans.modules.masterfs,\ - org.netbeans.modules.options.keymap,\ - org.netbeans.modules.sendopts,\ - org.netbeans.modules.templates,\ - org.openide.compat,\ - org.openide.execution,\ - org.openide.util.enumerations -enabled.clusters=\ - platform7 -nbjdk.active=JDK_1.6 -nbplatform.active=default diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/project.properties --- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/project.properties Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -javac.source=1.7 -javac.compilerargs=-Xlint -Xlint:-serial diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/project.xml --- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/project.xml Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ - - - org.netbeans.modules.apisupport.project - - - com.sun.hotspot.igv.servercompiler - - - - com.sun.hotspot.igv.data - - - - 1.0 - - - - com.sun.hotspot.igv.graph - - - - 1.0 - - - - - - - diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/suite.properties --- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/suite.properties Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -suite.dir=${basedir}/.. diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ServerCompiler/src/META-INF/services/com.sun.hotspot.igv.data.services.Scheduler --- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/META-INF/services/com.sun.hotspot.igv.data.services.Scheduler Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -com.sun.hotspot.igv.servercompiler.ServerCompilerScheduler diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/Bundle.properties --- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/Bundle.properties Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -OpenIDE-Module-Name=ServerCompiler diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/ServerCompilerScheduler.java --- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/ServerCompilerScheduler.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,624 +0,0 @@ -/* - * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.sun.hotspot.igv.servercompiler; - -import com.sun.hotspot.igv.data.InputBlock; -import com.sun.hotspot.igv.data.InputEdge; -import com.sun.hotspot.igv.data.InputGraph; -import com.sun.hotspot.igv.data.InputNode; -import com.sun.hotspot.igv.data.services.Scheduler; -import java.util.*; - -/** - * - * @author Thomas Wuerthinger - */ -public class ServerCompilerScheduler implements Scheduler { - - private static class Node { - - public InputNode inputNode; - public Set succs = new HashSet<>(); - public List preds = new ArrayList<>(); - public InputBlock block; - public boolean isBlockProjection; - public boolean isBlockStart; - } - private InputGraph graph; - private Collection nodes; - private Map inputNodeToNode; - private Vector blocks; - private Map dominatorMap; - private Map blockIndex; - private InputBlock[][] commonDominator; - private static final Comparator edgeComparator = new Comparator() { - - @Override - public int compare(InputEdge o1, InputEdge o2) { - return o1.getToIndex() - o2.getToIndex(); - } - }; - - public void buildBlocks() { - - blocks = new Vector<>(); - Node root = findRoot(); - if (root == null) { - return; - } - Stack stack = new Stack<>(); - Set visited = new HashSet<>(); - stack.add(root); - int blockCount = 0; - InputBlock rootBlock = null; - - - while (!stack.isEmpty()) { - Node proj = stack.pop(); - Node parent = proj; - if (proj.isBlockProjection && proj.preds.size() > 0) { - parent = proj.preds.get(0); - } - - if (!visited.contains(parent)) { - visited.add(parent); - InputBlock block = graph.addBlock(Integer.toString(blockCount)); - blocks.add(block); - if (parent == root) { - rootBlock = block; - } - blockCount++; - parent.block = block; - if (proj != parent && proj.succs.size() == 1 && proj.succs.contains(root)) { - // Special treatment of Halt-nodes - proj.block = block; - } - - Node p = proj; - do { - if (p.preds.size() == 0 || p.preds.get(0) == null) { - p = parent; - break; - } - - p = p.preds.get(0); - if (p == proj) { - // Cycle, stop - break; - } - - if (p.block == null) { - p.block = block; - } - } while (!p.isBlockProjection && !p.isBlockStart); - - if (block != rootBlock) { - for (Node n : p.preds) { - if (n != null && n != p) { - if (n.isBlockProjection) { - n = n.preds.get(0); - } - if (n.block != null) { - graph.addBlockEdge(n.block, block); - } - } - } - } - - for (Node n : parent.succs) { - if (n != root && n.isBlockProjection) { - for (Node n2 : n.succs) { - - if (n2 != parent && n2.block != null && n2.block != rootBlock) { - graph.addBlockEdge(block, n2.block); - } - } - } else { - if (n != parent && n.block != null && n.block != rootBlock) { - graph.addBlockEdge(block, n.block); - } - } - } - - int num_preds = p.preds.size(); - int bottom = -1; - if (isRegion(p) || isPhi(p)) { - bottom = 0; - } - - int pushed = 0; - for (int i = num_preds - 1; i > bottom; i--) { - if (p.preds.get(i) != null && p.preds.get(i) != p) { - stack.push(p.preds.get(i)); - pushed++; - } - } - - if (pushed == 0 && p == root) { - // TODO: special handling when root backedges are not built yet - } - } - } - - for (Node n : nodes) { - InputBlock block = n.block; - if (block != null) { - block.addNode(n.inputNode.getId()); - } - } - - int z = 0; - blockIndex = new HashMap<>(blocks.size()); - for (InputBlock b : blocks) { - blockIndex.put(b, z); - z++; - } - } - - private String getBlockName(InputNode n) { - return n.getProperties().get("block"); - } - - @Override - public Collection schedule(InputGraph graph) { - if (graph.getNodes().isEmpty()) { - return Collections.emptyList(); - } - - if (graph.getBlocks().size() > 0) { - Collection tmpNodes = new ArrayList<>(graph.getNodes()); - for (InputNode n : tmpNodes) { - String block = getBlockName(n); - if (graph.getBlock(n) == null) { - graph.getBlock(block).addNode(n.getId()); - assert graph.getBlock(n) != null; - } - } - return graph.getBlocks(); - } else { - nodes = new ArrayList<>(); - inputNodeToNode = new HashMap<>(graph.getNodes().size()); - - this.graph = graph; - buildUpGraph(); - buildBlocks(); - buildDominators(); - buildCommonDominators(); - scheduleLatest(); - - InputBlock noBlock = null; - for (InputNode n : graph.getNodes()) { - if (graph.getBlock(n) == null) { - if (noBlock == null) { - noBlock = graph.addBlock("(no block)"); - blocks.add(noBlock); - } - - graph.setBlock(n, noBlock); - } - assert graph.getBlock(n) != null; - } - - return blocks; - } - } - - private void scheduleLatest() { - Node root = findRoot(); - if(root == null) { - assert false : "No root found!"; - return; - } - - // Mark all nodes reachable in backward traversal from root - Set reachable = new HashSet<>(); - reachable.add(root); - Stack stack = new Stack<>(); - stack.push(root); - while (!stack.isEmpty()) { - Node cur = stack.pop(); - for (Node n : cur.preds) { - if (!reachable.contains(n)) { - reachable.add(n); - stack.push(n); - } - } - } - - Set unscheduled = new HashSet<>(); - for (Node n : this.nodes) { - if (n.block == null && reachable.contains(n)) { - unscheduled.add(n); - } - } - - while (unscheduled.size() > 0) { - boolean progress = false; - - Set newUnscheduled = new HashSet<>(); - for (Node n : unscheduled) { - - InputBlock block = null; - if (this.isPhi(n) && n.preds.get(0) != null) { - // Phi nodes in same block as region nodes - block = n.preds.get(0).block; - } else { - for (Node s : n.succs) { - if (reachable.contains(s)) { - if (s.block == null) { - block = null; - break; - } else { - if (block == null) { - block = s.block; - } else { - block = commonDominator[this.blockIndex.get(block)][blockIndex.get(s.block)]; - } - } - } - } - } - - if (block != null) { - n.block = block; - block.addNode(n.inputNode.getId()); - progress = true; - } else { - newUnscheduled.add(n); - } - } - - unscheduled = newUnscheduled; - - if (!progress) { - break; - } - } - - Set curReachable = new HashSet<>(reachable); - for (Node n : curReachable) { - if (n.block != null) { - for (Node s : n.succs) { - if (!reachable.contains(s)) { - markWithBlock(s, n.block, reachable); - } - } - } - } - - } - - private void markWithBlock(Node n, InputBlock b, Set reachable) { - assert !reachable.contains(n); - Stack stack = new Stack<>(); - stack.push(n); - n.block = b; - b.addNode(n.inputNode.getId()); - reachable.add(n); - - while (!stack.isEmpty()) { - Node cur = stack.pop(); - for (Node s : cur.succs) { - if (!reachable.contains(s)) { - reachable.add(s); - s.block = b; - b.addNode(s.inputNode.getId()); - stack.push(s); - } - } - - for (Node s : cur.preds) { - if (!reachable.contains(s)) { - reachable.add(s); - s.block = b; - b.addNode(s.inputNode.getId()); - stack.push(s); - } - } - } - } - - private class BlockIntermediate { - - InputBlock block; - int index; - int dominator; - int semi; - int parent; - int label; - int ancestor; - List pred; - List bucket; - } - - public void buildCommonDominators() { - commonDominator = new InputBlock[this.blocks.size()][this.blocks.size()]; - for (int i = 0; i < blocks.size(); i++) { - for (int j = 0; j < blocks.size(); j++) { - commonDominator[i][j] = getCommonDominator(i, j); - } - } - } - - public InputBlock getCommonDominator(int a, int b) { - InputBlock ba = blocks.get(a); - InputBlock bb = blocks.get(b); - if (ba == bb) { - return ba; - } - Set visited = new HashSet<>(); - while (ba != null) { - visited.add(ba); - ba = dominatorMap.get(ba); - } - - while (bb != null) { - if (visited.contains(bb)) { - return bb; - } - bb = dominatorMap.get(bb); - } - - assert false; - return null; - } - - public void buildDominators() { - dominatorMap = new HashMap<>(graph.getBlocks().size()); - if (blocks.size() == 0) { - return; - } - Vector intermediate = new Vector<>(graph.getBlocks().size()); - Map map = new HashMap<>(graph.getBlocks().size()); - int z = 0; - for (InputBlock b : blocks) { - BlockIntermediate bi = new BlockIntermediate(); - bi.block = b; - bi.index = z; - bi.dominator = -1; - bi.semi = -1; - bi.parent = -1; - bi.label = z; - bi.ancestor = -1; - bi.pred = new ArrayList<>(); - bi.bucket = new ArrayList<>(); - intermediate.add(bi); - map.put(b, bi); - z++; - } - Stack stack = new Stack<>(); - stack.add(0); - - Vector array = new Vector<>(); - intermediate.get(0).dominator = 0; - - int n = 0; - while (!stack.isEmpty()) { - int index = stack.pop(); - BlockIntermediate ib = intermediate.get(index); - ib.semi = n; - array.add(ib); - n = n + 1; - for (InputBlock b : ib.block.getSuccessors()) { - BlockIntermediate succ = map.get(b); - if (succ.semi == -1) { - succ.parent = index; - stack.push(succ.index); // TODO: check if same node could be pushed twice - } - succ.pred.add(index); - } - } - - for (int i = n - 1; i > 0; i--) { - BlockIntermediate block = array.get(i); - int block_index = block.index; - for (int predIndex : block.pred) { - int curIndex = eval(predIndex, intermediate); - BlockIntermediate curBlock = intermediate.get(curIndex); - if (curBlock.semi < block.semi) { - block.semi = curBlock.semi; - } - } - - - int semiIndex = block.semi; - BlockIntermediate semiBlock = array.get(semiIndex); - semiBlock.bucket.add(block_index); - - link(block.parent, block_index, intermediate); - BlockIntermediate parentBlock = intermediate.get(block.parent); - - for (int j = 0; j < parentBlock.bucket.size(); j++) { - for (int curIndex : parentBlock.bucket) { - int newIndex = eval(curIndex, intermediate); - BlockIntermediate curBlock = intermediate.get(curIndex); - BlockIntermediate newBlock = intermediate.get(newIndex); - int dom = block.parent; - if (newBlock.semi < curBlock.semi) { - dom = newIndex; - } - - curBlock.dominator = dom; - } - } - - - parentBlock.bucket.clear(); - } - - for (int i = 1; i < n; i++) { - - BlockIntermediate block = array.get(i); - int block_index = block.index; - - int semi_index = block.semi; - BlockIntermediate semi_block = array.get(semi_index); - - if (block.dominator != semi_block.index) { - int new_dom = intermediate.get(block.dominator).dominator; - block.dominator = new_dom; - } - } - - for (BlockIntermediate ib : intermediate) { - if (ib.dominator == -1) { - ib.dominator = 0; - } - } - - for (BlockIntermediate bi : intermediate) { - InputBlock b = bi.block; - int dominator = bi.dominator; - InputBlock dominatorBlock = null; - if (dominator != -1) { - dominatorBlock = intermediate.get(dominator).block; - } - - if (dominatorBlock == b) { - dominatorBlock = null; - } - this.dominatorMap.put(b, dominatorBlock); - } - } - - private void compress(int index, Vector blocks) { - BlockIntermediate block = blocks.get(index); - - int ancestor = block.ancestor; - assert ancestor != -1; - - BlockIntermediate ancestor_block = blocks.get(ancestor); - if (ancestor_block.ancestor != -1) { - compress(ancestor, blocks); - - int label = block.label; - BlockIntermediate label_block = blocks.get(label); - - int ancestor_label = ancestor_block.label; - BlockIntermediate ancestor_label_block = blocks.get(label); - if (ancestor_label_block.semi < label_block.semi) { - block.label = ancestor_label; - } - - block.ancestor = ancestor_block.ancestor; - } - } - - private int eval(int index, Vector blocks) { - BlockIntermediate block = blocks.get(index); - if (block.ancestor == -1) { - return index; - } else { - compress(index, blocks); - return block.label; - } - } - - private void link(int index1, int index2, Vector blocks) { - BlockIntermediate block2 = blocks.get(index2); - block2.ancestor = index1; - } - - private boolean isRegion(Node n) { - return n.inputNode.getProperties().get("name").equals("Region"); - } - - private boolean isPhi(Node n) { - return n.inputNode.getProperties().get("name").equals("Phi"); - } - - private Node findRoot() { - Node minNode = null; - Node alternativeRoot = null; - - for (Node node : nodes) { - InputNode inputNode = node.inputNode; - String s = inputNode.getProperties().get("name"); - if (s != null && s.equals("Root")) { - return node; - } - - if (alternativeRoot == null && node.preds.isEmpty()) { - alternativeRoot = node; - } - - if (minNode == null || node.inputNode.getId() < minNode.inputNode.getId()) { - minNode = node; - } - } - - if (alternativeRoot != null) { - return alternativeRoot; - } else { - return minNode; - } - } - - public void buildUpGraph() { - - for (InputNode n : graph.getNodes()) { - Node node = new Node(); - node.inputNode = n; - nodes.add(node); - String p = n.getProperties().get("is_block_proj"); - node.isBlockProjection = (p != null && p.equals("true")); - p = n.getProperties().get("is_block_start"); - node.isBlockStart = (p != null && p.equals("true")); - inputNodeToNode.put(n, node); - } - - Map> edgeMap = new HashMap<>(graph.getEdges().size()); - for (InputEdge e : graph.getEdges()) { - - int to = e.getTo(); - if (!edgeMap.containsKey(to)) { - edgeMap.put(to, new ArrayList()); - } - - - List list = edgeMap.get(to); - list.add(e); - } - - - for (Integer i : edgeMap.keySet()) { - - List list = edgeMap.get(i); - Collections.sort(list, edgeComparator); - - int to = i; - InputNode toInputNode = graph.getNode(to); - Node toNode = inputNodeToNode.get(toInputNode); - for (InputEdge e : list) { - assert to == e.getTo(); - int from = e.getFrom(); - InputNode fromInputNode = graph.getNode(from); - Node fromNode = inputNodeToNode.get(fromInputNode); - fromNode.succs.add(toNode); - toNode.preds.add(fromNode); - } - } - } -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/color.filter --- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/color.filter Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -colorize("name", ".*", yellow); -colorize("name", "Catch.*", blue); -colorize("name", "Region|Loop|CountedLoop|Root", red); -colorize("name", "CProj|IfFalse|IfTrue|JProj|CatchProj", magenta); -colorize("name", "Con.*", orange); -colorize("name", "Parm|Proj", lightGray); - -// Nodes with bci -colorize("bci", "..*", magenta); - -// Line style -var f = new ColorFilter("Line Style filter"); -f.addRule(new ColorFilter.ColorRule(new MatcherSelector(new Properties.StringPropertyMatcher("type", "int:")), null, Color.BLUE, null)); -f.addRule(new ColorFilter.ColorRule(new MatcherSelector(new Properties.StringPropertyMatcher("type", "control")), null, Color.RED, null)); -f.addRule(new ColorFilter.ColorRule(new MatcherSelector(new Properties.StringPropertyMatcher("type", "memory")), null, Color.GREEN, null)); -f.addRule(new ColorFilter.ColorRule(new MatcherSelector(new Properties.StringPropertyMatcher("type", "tuple:")), null, Color.MAGENTA, null)); -f.addRule(new ColorFilter.ColorRule(new MatcherSelector(new Properties.StringPropertyMatcher("type", "bottom")), null, Color.LIGHT_GRAY, null)); -f.apply(graph); \ No newline at end of file diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/difference.filter --- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/difference.filter Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -colorize("state", "same", white); -colorize("state", "changed", orange); -colorize("state", "new", green); -colorize("state", "deleted", red); diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/matchingFlags.filter --- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/matchingFlags.filter Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -colorize("is_dontcare", "false", white); -colorize("is_shared", "true", green); -colorize("is_dontcare", "true", red); diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/onlyControlFlow.filter --- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/onlyControlFlow.filter Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -var f = new RemoveFilter("Show only control flow"); -f.addRule( - new RemoveFilter.RemoveRule( - new InvertSelector( - new OrSelector( - new OrSelector( - new SuccessorSelector( - new MatcherSelector( - new Properties.StringPropertyMatcher("type", "control") - ) - ), - new MatcherSelector( - new Properties.StringPropertyMatcher("type", "control") - ) - ), - new MatcherSelector( - new Properties.StringPropertyMatcher("name", "Start") - ) - ) - ), false - ) -); -f.addRule(new RemoveFilter.RemoveRule(new MatcherSelector(new Properties.RegexpPropertyMatcher("name", "Phi|Store.")))); -f.apply(graph); \ No newline at end of file diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/register.filter --- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/register.filter Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -// Register coloring -colorize("reg", "EAX", green); -colorize("reg", "EFLAGS", gray); -colorize("reg", "EBP", orange); -colorize("reg", "ECX", cyan); \ No newline at end of file diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/remove.filter --- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/remove.filter Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -remove("dump_spec", "FramePtr|ReturnAdr|I_O"); -removeInputs("name", "Root"); -var f = new RemoveSelfLoopsFilter("Remove Self-Loops"); -f.apply(graph); -removeInputs("name", "SafePoint|CallStaticJava|CallDynamicJava|CallJava|CallLeaf|CallRuntime|AbstractLock|CallLeafNoFP|Call|CallStaticJavaDirect", 5); -removeInputs("name", "Unlock|Lock", 7); -removeInputs("name", "Allocate", 7); -removeInputs("name", "AllocateArray", 9); \ No newline at end of file diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/structural.filter --- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/structural.filter Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -var f = new CombineFilter("Combine Filter"); -f.addRule(new CombineFilter.CombineRule(new Properties.RegexpPropertyMatcher("name", ".*"), new Properties.RegexpPropertyMatcher("name", "Proj|IfFalse|IfTrue|JProj|MachProj|JumpProj|CatchProj"))); -f.addRule(new CombineFilter.CombineRule(new Properties.RegexpPropertyMatcher("name", "Cmp.*"), new Properties.RegexpPropertyMatcher("name", "Bool"))); -f.apply(graph); -split("name", "BoxLock"); -split("name", "(Con.*)|(loadCon.*)", "[dump_spec]"); \ No newline at end of file diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/layer.xml --- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/layer.xml Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/SnapshotsView/manifest.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/SnapshotsView/manifest.mf Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,7 @@ +Manifest-Version: 1.0 +OpenIDE-Module: com.oracle.graal.visualizer.snapshots +OpenIDE-Module-Layer: com/oracle/graal/visualizer/snapshots/layer.xml +OpenIDE-Module-Localizing-Bundle: com/oracle/graal/visualizer/snapshots/Bundle.properties +OpenIDE-Module-Requires: org.openide.windows.WindowManager +OpenIDE-Module-Specification-Version: 1.0 + diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/Bundle.properties Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,1 @@ +OpenIDE-Module-Name=SnapshotsView diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/SnapshotTopComponent.form --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/SnapshotTopComponent.form Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,28 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/SnapshotTopComponent.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/SnapshotTopComponent.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ +package com.oracle.graal.visualizer.snapshots; + +import com.oracle.graal.visualizer.editor.EditorTopComponent; +import com.oracle.graal.visualizer.util.LookupUtils; +import com.sun.hotspot.igv.data.ChangedEvent; +import com.sun.hotspot.igv.data.ChangedListener; +import com.sun.hotspot.igv.util.RangeSlider; +import com.sun.hotspot.igv.util.RangeSliderModel; +import java.awt.BorderLayout; +import javax.swing.JScrollPane; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.util.Lookup.Result; +import org.openide.util.LookupEvent; +import org.openide.util.LookupListener; +import org.openide.windows.TopComponent; +import org.openide.windows.WindowManager; + +@TopComponent.Description(preferredID = SnapshotTopComponent.PREFERRED_ID, persistenceType = TopComponent.PERSISTENCE_ALWAYS) +@TopComponent.Registration(mode = "belowExplorer", openAtStartup = true) +@ActionID(category = "Window", id = "com.oracle.graal.visualizer.snapshots.SnapshotTopComponent") +@ActionReference(path = "Menu/Window") +@TopComponent.OpenActionRegistration(displayName = "Snapshot", preferredID = SnapshotTopComponent.PREFERRED_ID) +public final class SnapshotTopComponent extends TopComponent { + public static final String PREFERRED_ID = "SnapshotTopComponent"; + + private final Result result; + private final RangeSlider rangeSlider; + private final ChangedEvent rangeSliderChangedEvent = new ChangedEvent(null); + private final LookupListener lookupListener = new LookupListener() { + + @Override + public void resultChanged(LookupEvent le) { + update(); + } + }; + + private final ChangedListener rangeSliderChangedListener = new ChangedListener(){ + + @Override + public void changed(RangeSliderModel source) { + rangeSliderChangedEvent.fire(); + } + }; + + public SnapshotTopComponent() { + initComponents(); + setName("Snapshot Window"); + setToolTipText("This is a Snapshot window"); + + result = LookupUtils.getLastActiveDelegatingLookup(EditorTopComponent.class).lookupResult(RangeSliderModel.class); + result.addLookupListener(lookupListener); + this.rangeSlider = new RangeSlider(null); + this.setLayout(new BorderLayout()); + this.add(new JScrollPane(rangeSlider), BorderLayout.CENTER); + update(); + } + + private void update() { + RangeSliderModel newModel; + if (result.allInstances().size() > 0) { + newModel = result.allInstances().iterator().next(); + } else { + newModel = null; + } + if (rangeSlider.getModel() != null) { + rangeSlider.getModel().getChangedEvent().removeListener(rangeSliderChangedListener); + } + rangeSlider.setModel(newModel); + rangeSliderChangedEvent.changeObject(newModel); + if (newModel != null) { + newModel.getChangedEvent().addListener(rangeSliderChangedListener); + } + } + + public ChangedEvent getRangeSliderChangedEvent() { + return rangeSliderChangedEvent; + } + + public static SnapshotTopComponent findInstance() { + return (SnapshotTopComponent) WindowManager.getDefault().findTopComponent(PREFERRED_ID); + } + + /** + * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 400, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 300, Short.MAX_VALUE) + ); + }// //GEN-END:initComponents + // Variables declaration - do not modify//GEN-BEGIN:variables + // End of variables declaration//GEN-END:variables + +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/actions/NextSnapshotAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/actions/NextSnapshotAction.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ +package com.oracle.graal.visualizer.snapshots.actions; + +import com.oracle.graal.visualizer.snapshots.SnapshotTopComponent; +import com.sun.hotspot.igv.data.ChangedListener; +import com.sun.hotspot.igv.util.RangeSliderModel; +import java.awt.event.ActionEvent; +import javax.swing.AbstractAction; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionRegistration; + +@ActionID(id = "com.oracle.graal.visualizer.editor.actions.NextSnapshotAction", category = "View") +@ActionRegistration(displayName = "Next snapshot", iconBase = "com/oracle/graal/visualizer/snapshots/images/next_snapshot.png") +@ActionReference(path = "Menu/View", position = 150) +public final class NextSnapshotAction extends AbstractAction{ + + private RangeSliderModel model; + + public NextSnapshotAction() { + SnapshotTopComponent.findInstance().getRangeSliderChangedEvent().addListenerAndFire(changeListener); + } + private final ChangedListener changeListener = new ChangedListener() { + + @Override + public void changed(RangeSliderModel source) { + model = source; + setEnabled(model != null && model.getSecondPosition() != model.getPositions().size() - 1); + } + }; + + @Override + public void actionPerformed(ActionEvent e) { + if (model != null) { + int fp = model.getFirstPosition(); + int sp = model.getSecondPosition(); + if (sp != model.getPositions().size() - 1) { + int nfp = fp + 1; + int nsp = sp + 1; + model.setPositions(nfp, nsp); + } + } + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/actions/PrevSnapshotAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/actions/PrevSnapshotAction.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ +package com.oracle.graal.visualizer.snapshots.actions; + +import com.oracle.graal.visualizer.snapshots.SnapshotTopComponent; +import com.sun.hotspot.igv.data.ChangedListener; +import com.sun.hotspot.igv.util.RangeSliderModel; +import java.awt.event.ActionEvent; +import javax.swing.AbstractAction; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionRegistration; + +@ActionID(id = "com.oracle.graal.visualizer.editor.actions.PrevSnapshotAction", category = "View") +@ActionRegistration(displayName = "Previous snapshot", iconBase = "com/oracle/graal/visualizer/snapshots/images/prev_snapshot.png") +@ActionReference(path = "Menu/View", position = 100) +public final class PrevSnapshotAction extends AbstractAction { + + private RangeSliderModel model; + + public PrevSnapshotAction() { + SnapshotTopComponent.findInstance().getRangeSliderChangedEvent().addListenerAndFire(changeListener); + } + private final ChangedListener changeListener = new ChangedListener() { + + @Override + public void changed(RangeSliderModel source) { + model = source; + setEnabled(model != null && model.getFirstPosition() != 0); + } + }; + + @Override + public void actionPerformed(ActionEvent e) { + if (model != null) { + int fp = model.getFirstPosition(); + int sp = model.getSecondPosition(); + if (fp != 0) { + int nfp = fp - 1; + int nsp = sp - 1; + model.setPositions(nfp, nsp); + } + } + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/belowExplorerWsmode.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/belowExplorerWsmode.xml Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/images/next_snapshot.png Binary file src/share/tools/IdealGraphVisualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/images/next_snapshot.png has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/images/prev_snapshot.png Binary file src/share/tools/IdealGraphVisualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/images/prev_snapshot.png has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/layer.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/layer.xml Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,9 @@ + + + + + + + + + diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Util/nbproject/project.xml --- a/src/share/tools/IdealGraphVisualizer/Util/nbproject/project.xml Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Util/nbproject/project.xml Tue Feb 07 21:09:31 2012 +0100 @@ -1,55 +1,64 @@ - - - org.netbeans.modules.apisupport.project - - - com.sun.hotspot.igv.util - - - - com.sun.hotspot.igv.data - - - - 1.0 - - - - org.netbeans.api.visual - - - - 2.27.1 - - - - org.openide.nodes - - - - 7.20.1 - - - - org.openide.util - - - - 8.14.1 - - - - org.openide.util.lookup - - - - 8.6.1 - - - - - com.sun.hotspot.igv.util - - - - + + + org.netbeans.modules.apisupport.project + + + com.sun.hotspot.igv.util + + + + com.sun.hotspot.igv.data + + + + 1.0 + + + + org.netbeans.api.visual + + + + 2.27.1 + + + + org.openide.nodes + + + + 7.20.1 + + + + org.openide.util + + + + 8.14.1 + + + + org.openide.util.lookup + + + + 8.6.1 + + + + org.openide.windows + + + + 6.48.1 + + + + + com.oracle.graal.visualizer.util + com.sun.hotspot.igv.util + + + + diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Util/src/com/oracle/graal/visualizer/util/LookupUtils.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Util/src/com/oracle/graal/visualizer/util/LookupUtils.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +package com.oracle.graal.visualizer.util; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.ArrayList; +import java.util.List; +import javax.swing.Action; +import org.openide.util.ContextAwareAction; +import org.openide.util.Lookup; +import org.openide.util.Lookup.Provider; +import org.openide.util.lookup.Lookups; +import org.openide.windows.TopComponent; + +/** + * Utilities that build upon the Lookup API. + */ +public class LookupUtils { + + + /** + * Creates a new lookup that will delegate to the last open window of a specified top component class. If the window is closed, the lookup will be empty. + * @param clazz the class identifying the top component type + * @return a delegating lookup + */ + public static Lookup getLastActiveDelegatingLookup(Class clazz) { + final TopComponentLookup topComponentLookupImpl = new TopComponentLookup(clazz); + TopComponent.getRegistry().addPropertyChangeListener(topComponentLookupImpl); + return topComponentLookupImpl.lookup; + } + + public static Iterable lookupActions(String path) { + return lookupActions(path, null); + } + + public static Iterable lookupActions(String path, Lookup context) { + List actions = new ArrayList<>(); + for (Action a : Lookups.forPath(path).lookupAll(Action.class)) { + Action newAction = a; + if (a instanceof ContextAwareAction && context != null) { + newAction = ((ContextAwareAction) a).createContextAwareInstance(context); + } + newAction.putValue(Action.SHORT_DESCRIPTION, newAction.getValue(Action.NAME)); + actions.add(newAction); + + } + return actions; + } + + private static class TopComponentLookup implements PropertyChangeListener { + private final Class clazz; + private final Lookup lookup; + private TopComponent lastActive; + + private final Provider lookupProvider = new Provider() { + + @Override + public Lookup getLookup() { + if (lastActive == null) { + return Lookup.EMPTY; + } else { + return lastActive.getLookup(); + } + } + }; + + public TopComponentLookup(Class clazz) { + this.clazz = clazz; + lookup = Lookups.proxy(lookupProvider); + update(); + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + update(); + } + + private void update() { + TopComponent curActivated = TopComponent.getRegistry().getActivated(); + if (curActivated != lastActive) { + if (clazz.isAssignableFrom(curActivated.getClass())) { + // We have a new top component for our lookup. + lastActive = curActivated; + refreshLookup(); + } else { + // We have no new top component. Check if the old one is still opened. + if (lastActive != null && !TopComponent.getRegistry().getOpened().contains(lastActive)) { + // The top component was closed => Remove lookup. + lastActive = null; + refreshLookup(); + } + } + } + } + + private void refreshLookup() { + lookup.lookup(Object.class); + } + }; +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/BoundedZoomAction.java --- a/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/BoundedZoomAction.java Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/BoundedZoomAction.java Tue Feb 07 21:09:31 2012 +0100 @@ -93,13 +93,11 @@ Point mouseLocation = scene.convertSceneToView(event.getPoint()); int xOffset = 0; int yOffset = 0; - Point oldViewPosition = null; Rectangle bounds = new Rectangle(scene.getBounds()); Dimension componentSize = new Dimension(scene.getView().getPreferredSize()); if (scrollPane != null) { viewPosition = new Point(scrollPane.getViewport().getViewPosition()); - oldViewPosition = new Point(viewPosition); xOffset = (mouseLocation.x - viewPosition.x); yOffset = (mouseLocation.y - viewPosition.y); viewPosition.x += xOffset; diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/Bundle.properties --- a/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/Bundle.properties Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/Bundle.properties Tue Feb 07 21:09:31 2012 +0100 @@ -1,1 +1,1 @@ -OpenIDE-Module-Name=Util +OpenIDE-Module-Name=Util diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/CompilationViewModel.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/CompilationViewModel.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,47 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.sun.hotspot.igv.util; + +import com.sun.hotspot.igv.data.*; +import java.awt.Color; +import java.util.List; + +public class CompilationViewModel implements ChangedEventProvider { + + private final ChangedEvent changedEvent = new ChangedEvent<>(this); + private final RangeSliderModel model; + private final Group group; + + @Override + public ChangedEvent getChangedEvent() { + return changedEvent; + } + + public CompilationViewModel(RangeSliderModel model, Group group) { + this.model = model; + this.group = group; + model.getChangedEvent().addListener(rangeSliderChangedListener); + } + + private final ChangedListener rangeSliderChangedListener = new ChangedListener() { + @Override + public void changed(RangeSliderModel source) { + changedEvent.fire(); + } + }; + + public InputGraph getFirstSnapshot() { + return group.getGraphs().get(model.getFirstPosition()); + } + + public InputGraph getSecondSnapshot() { + return group.getGraphs().get(model.getSecondPosition()); + } + + public void setColors(List colors) { + model.setColors(colors); + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/ContextAction.java --- a/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/ContextAction.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,93 +0,0 @@ -/* - * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.sun.hotspot.igv.util; - -import java.awt.EventQueue; -import org.openide.util.*; -import org.openide.util.actions.CallableSystemAction; - -/** - * - * @author Thomas Wuerthinger - */ -public abstract class ContextAction extends CallableSystemAction implements LookupListener, ContextAwareAction { - - private Lookup context = null; - private Lookup.Result result = null; - - public ContextAction() { - this(Utilities.actionsGlobalContext()); - } - - public ContextAction(Lookup context) { - init(context); - } - - private void init(Lookup context) { - this.context = context; - result = context.lookupResult(contextClass()); - result.addLookupListener(this); - resultChanged(null); - } - - @Override - public void resultChanged(LookupEvent e) { - if (result.allItems().size() != 0) { - update(result.allInstances().iterator().next()); - } else { - update(null); - } - } - - @Override - public void performAction() { - final T t = result.allInstances().iterator().next(); - - // Ensure it's AWT event thread - EventQueue.invokeLater(new Runnable() { - - @Override - public void run() { - performAction(t); - } - }); - } - - public void update(T t) { - if (t == null) { - setEnabled(false); - } else { - setEnabled(isEnabled(t)); - } - } - - public boolean isEnabled(T context) { - return true; - } - - public abstract Class contextClass(); - - public abstract void performAction(T context); -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/LookupHistory.java --- a/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/LookupHistory.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ -package com.sun.hotspot.igv.util; - -import java.util.HashMap; -import java.util.Map; -import org.openide.util.Lookup.Result; -import org.openide.util.LookupEvent; -import org.openide.util.LookupListener; -import org.openide.util.Utilities; - -/** - * - * @author Thomas - */ -public class LookupHistory { - - private static Map cache = new HashMap<>(); - - private static class LookupHistoryImpl implements LookupListener { - - private Class klass; - private Result result; - private T last; - - public LookupHistoryImpl(Class klass) { - this.klass = klass; - result = Utilities.actionsGlobalContext().lookupResult(klass); - result.addLookupListener(this); - last = Utilities.actionsGlobalContext().lookup(klass); - } - - public T getLast() { - return last; - } - - @Override - public void resultChanged(LookupEvent ev) { - T current = Utilities.actionsGlobalContext().lookup(klass); - if (current != null) { - last = current; - } - } - } - - public static void init(Class klass) { - if (!cache.containsKey(klass)) { - cache.put(klass, new LookupHistoryImpl<>(klass)); - } - } - - @SuppressWarnings("unchecked") - public static T getLast(Class klass) { - init(klass); - assert cache.containsKey(klass); - return (T) cache.get(klass).getLast(); - } -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/RangeSlider.java --- a/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/RangeSlider.java Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/RangeSlider.java Tue Feb 07 21:09:31 2012 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -32,55 +32,26 @@ import java.util.List; import javax.swing.JComponent; -/** - * - * @author Thomas Wuerthinger - */ -public class RangeSlider extends JComponent implements ChangedListener, MouseListener, MouseMotionListener { +public final class RangeSlider extends JComponent { - public static final int HEIGHT = 40; - public static final int BAR_HEIGHT = 22; - public static final int BAR_SELECTION_ENDING_HEIGHT = 16; - public static final int BAR_SELECTION_HEIGHT = 10; public static final int BAR_THICKNESS = 2; public static final int BAR_CIRCLE_SIZE = 9; public static final int MOUSE_ENDING_OFFSET = 3; public static final Color BACKGROUND_COLOR = Color.white; public static final Color BAR_COLOR = Color.black; public static final Color BAR_SELECTION_COLOR = new Color(255, 0, 0, 120); - public static final Color BAR_SELECTION_COLOR_ROLLOVER = new Color(255, 0, 255, 120); - public static final Color BAR_SELECTION_COLOR_DRAG = new Color(0, 0, 255, 120); + public static final Color TEXT_SELECTION_COLOR = new Color(200, 200, 200, 255); + public static final int ITEM_HEIGHT = 30; + public static final int ITEM_WIDTH = 30; private RangeSliderModel model; - private State state; private Point startPoint; private RangeSliderModel tempModel; - private boolean isOverBar; - - private enum State { - - Initial, - DragBar, - DragFirstPosition, - DragSecondPosition - } + private Point lastMouseMove; - public RangeSlider() { - state = State.Initial; - this.addMouseMotionListener(this); - this.addMouseListener(this); - } - - public void setModel(RangeSliderModel newModel) { - if (model != null) { - model.getChangedEvent().removeListener(this); - model.getColorChangedEvent().removeListener(this); - } - if (newModel != null) { - newModel.getChangedEvent().addListener(this); - newModel.getColorChangedEvent().addListener(this); - } - this.model = newModel; - update(); + public RangeSlider(RangeSliderModel newModel) { + this.addMouseMotionListener(mouseMotionListener); + this.addMouseListener(mouseListener); + setModel(newModel); } private RangeSliderModel getPaintingModel() { @@ -92,37 +63,41 @@ @Override public Dimension getPreferredSize() { - Dimension d = super.getPreferredSize(); - d.height = HEIGHT; - return d; + if (getPaintingModel() != null) { + Graphics g = this.getGraphics(); + int maxWidth = 0; + List list = getPaintingModel().getPositions(); + for (int i = 0; i < list.size(); i++) { + String curS = list.get(i); + if (curS != null && curS.length() > 0) { + FontMetrics metrics = g.getFontMetrics(); + Rectangle bounds = metrics.getStringBounds(curS, g).getBounds(); + maxWidth = Math.max(maxWidth, (int) bounds.getWidth()); + } + } + return new Dimension(maxWidth + ITEM_WIDTH, ITEM_HEIGHT * list.size()); + } + return super.getPreferredSize(); } + private ChangedListener modelChangedListener = new ChangedListener() { - @Override - public void changed(RangeSliderModel source) { - update(); - } + @Override + public void changed(RangeSliderModel source) { + update(); + } + }; private void update() { this.repaint(); } - private int getXPosition(int index) { - assert index >= 0 && index < getPaintingModel().getPositions().size(); - return getXOffset() * (index + 1); - } - - private int getXOffset() { - int size = getPaintingModel().getPositions().size(); - int width = getWidth(); - return (width / (size + 1)); - } - - private int getEndXPosition(int index) { - return getXPosition(index) + getXOffset() / 2; - } - - private int getStartXPosition(int index) { - return getXPosition(index) - getXOffset() / 2; + private Rectangle getItemBounds(int index) { + Rectangle r = new Rectangle(); + r.width = ITEM_WIDTH; + r.height = ITEM_HEIGHT; + r.x = 0; + r.y = ITEM_HEIGHT * index; + return r; } @Override @@ -138,223 +113,150 @@ g2.fillRect(0, 0, width, height); // Nothing to paint? - if (getPaintingModel() == null || getPaintingModel().getPositions().size() == 0) { + if (getPaintingModel() == null || getPaintingModel().getPositions().isEmpty()) { return; } - int firstPos = getPaintingModel().getFirstPosition(); - int secondPos = getPaintingModel().getSecondPosition(); - - paintSelected(g2, firstPos, secondPos); + paintSelected(g2); paintBar(g2); } - private int getBarStartY() { - return getHeight() - BAR_HEIGHT; + private void fillRect(Graphics2D g, int startX, int startY, int endY, int thickness) { + g.fillRect(startX - thickness / 2, startY, thickness, endY - startY); } private void paintBar(Graphics2D g) { List list = getPaintingModel().getPositions(); - int barStartY = getBarStartY(); g.setColor(BAR_COLOR); - g.fillRect(getXPosition(0), barStartY + BAR_HEIGHT / 2 - BAR_THICKNESS / 2, getXPosition(list.size() - 1) - getXPosition(0), BAR_THICKNESS); + Rectangle firstItemBounds = getItemBounds(0); + Rectangle lastItemBounds = getItemBounds(list.size() - 1); + fillRect(g, (int) firstItemBounds.getCenterX(), (int) firstItemBounds.getCenterY(), (int) lastItemBounds.getCenterY(), BAR_THICKNESS); - int circleCenterY = barStartY + BAR_HEIGHT / 2; for (int i = 0; i < list.size(); i++) { - int curX = getXPosition(i); + Rectangle curItemBounds = getItemBounds(i); g.setColor(getPaintingModel().getColors().get(i)); - g.fillOval(curX - BAR_CIRCLE_SIZE / 2, circleCenterY - BAR_CIRCLE_SIZE / 2, BAR_CIRCLE_SIZE, BAR_CIRCLE_SIZE); + g.fillOval((int) curItemBounds.getCenterX() - BAR_CIRCLE_SIZE / 2, (int) curItemBounds.getCenterY() - BAR_CIRCLE_SIZE / 2, BAR_CIRCLE_SIZE, BAR_CIRCLE_SIZE); g.setColor(Color.black); - g.drawOval(curX - BAR_CIRCLE_SIZE / 2, circleCenterY - BAR_CIRCLE_SIZE / 2, BAR_CIRCLE_SIZE, BAR_CIRCLE_SIZE); - + g.drawOval((int) curItemBounds.getCenterX() - BAR_CIRCLE_SIZE / 2, (int) curItemBounds.getCenterY() - BAR_CIRCLE_SIZE / 2, BAR_CIRCLE_SIZE, BAR_CIRCLE_SIZE); String curS = list.get(i); if (curS != null && curS.length() > 0) { - int startX = getStartXPosition(i); - int endX = getEndXPosition(i); FontMetrics metrics = g.getFontMetrics(); Rectangle bounds = metrics.getStringBounds(curS, g).getBounds(); - if (bounds.width < endX - startX && bounds.height < barStartY) { - g.setColor(Color.black); - g.drawString(curS, startX + (endX - startX) / 2 - bounds.width / 2, barStartY / 2 + bounds.height / 2); - } + g.setColor(Color.black); + g.drawString(curS, curItemBounds.x + curItemBounds.width, (int) curItemBounds.getCenterY() + bounds.height / 2 - 2); } } } - private void paintSelected(Graphics2D g, int start, int end) { - - int startX = getStartXPosition(start); - int endX = getEndXPosition(end); - int barStartY = getBarStartY(); - int barSelectionEndingStartY = barStartY + BAR_HEIGHT / 2 - BAR_SELECTION_ENDING_HEIGHT / 2; - paintSelectedEnding(g, startX, barSelectionEndingStartY); - paintSelectedEnding(g, endX, barSelectionEndingStartY); + private void paintSelected(Graphics2D g) { + List list = getPaintingModel().getPositions(); + for (int i = 0; i < list.size(); i++) { + Rectangle curItemBounds = getItemBounds(i); + if (lastMouseMove != null && curItemBounds.y <= lastMouseMove.y && curItemBounds.y + curItemBounds.height > lastMouseMove.y) { + g.setColor(TEXT_SELECTION_COLOR); + g.fillRect(0, curItemBounds.y, getWidth(), curItemBounds.height); + } + } + final Rectangle barBounds = getBarBounds(); g.setColor(BAR_SELECTION_COLOR); - if (state == State.DragBar) { - g.setColor(BAR_SELECTION_COLOR_DRAG); - } else if (isOverBar) { - g.setColor(BAR_SELECTION_COLOR_ROLLOVER); - } - g.fillRect(startX, barStartY + BAR_HEIGHT / 2 - BAR_SELECTION_HEIGHT / 2, endX - startX, BAR_SELECTION_HEIGHT); - } - - private void paintSelectedEnding(Graphics g, int x, int y) { - g.setColor(BAR_COLOR); - g.fillRect(x - BAR_THICKNESS / 2, y, BAR_THICKNESS, BAR_SELECTION_ENDING_HEIGHT); - } - - private boolean isOverSecondPosition(Point p) { - if (p.y >= getBarStartY()) { - int destX = getEndXPosition(getPaintingModel().getSecondPosition()); - int off = Math.abs(destX - p.x); - return off <= MOUSE_ENDING_OFFSET; - } - return false; - } - - private boolean isOverFirstPosition(Point p) { - if (p.y >= getBarStartY()) { - int destX = getStartXPosition(getPaintingModel().getFirstPosition()); - int off = Math.abs(destX - p.x); - return off <= MOUSE_ENDING_OFFSET; - } - return false; + g.fill(barBounds); } - private boolean isOverSelection(Point p) { - if (p.y >= getBarStartY() && !isOverFirstPosition(p) && !isOverSecondPosition(p)) { - return p.x > getStartXPosition(getPaintingModel().getFirstPosition()) && p.x < getEndXPosition(getPaintingModel().getSecondPosition()); - } - return false; + private Rectangle getBarBounds() { + final Rectangle startItemBounds = getItemBounds(getPaintingModel().getFirstPosition()); + final Rectangle endItemBounds = getItemBounds(getPaintingModel().getSecondPosition()); + int startY = startItemBounds.y; + int endY = endItemBounds.y + endItemBounds.height; + return new Rectangle(0, startY, getWidth(), endY - startY); } - @Override - public void mouseDragged(MouseEvent e) { - if (state == State.DragBar) { - int firstX = this.getStartXPosition(model.getFirstPosition()); - int newFirstX = firstX + e.getPoint().x - startPoint.x; - int newIndex = getIndexFromPosition(newFirstX) + 1; - if (newIndex + model.getSecondPosition() - model.getFirstPosition() >= model.getPositions().size()) { - newIndex = model.getPositions().size() - (model.getSecondPosition() - model.getFirstPosition()) - 1; - } - int secondPosition = newIndex + model.getSecondPosition() - model.getFirstPosition(); - tempModel.setPositions(newIndex, secondPosition); - update(); - } else if (state == State.DragFirstPosition) { - int firstPosition = getIndexFromPosition(e.getPoint().x) + 1; - int secondPosition = model.getSecondPosition(); - if (firstPosition > secondPosition) { - firstPosition--; - } - tempModel.setPositions(firstPosition, secondPosition); - update(); - } else if (state == State.DragSecondPosition) { - int firstPosition = model.getFirstPosition(); - int secondPosition = getIndexFromPosition(e.getPoint().x); - if (secondPosition < firstPosition) { - secondPosition++; - } - tempModel.setPositions(firstPosition, secondPosition); - update(); - } - } - - private int getIndexFromPosition(int x) { - if (x < getXPosition(0)) { - return -1; - } + private int getIndexFromPosition(int y) { for (int i = 0; i < getPaintingModel().getPositions().size() - 1; i++) { - int startX = getXPosition(i); - int endX = getXPosition(i + 1); - if (x >= startX && x <= endX) { + Rectangle bounds = getItemBounds(i); + if (bounds.y <= y && bounds.y + bounds.height >= y) { return i; } } return getPaintingModel().getPositions().size() - 1; } + private final MouseMotionListener mouseMotionListener = new MouseMotionListener() { - private int getCircleIndexFromPosition(int x) { - int result = 0; - for (int i = 1; i < getPaintingModel().getPositions().size() - 1; i++) { - if (x > getStartXPosition(i)) { - result = i; + @Override + public void mouseDragged(MouseEvent e) { + if (startPoint != null) { + int startIndex = getIndexFromPosition(startPoint.y); + int curIndex = getIndexFromPosition(e.getPoint().y); + tempModel.setPositions(startIndex, curIndex); } } - return result; - } - @Override - public void mouseMoved(MouseEvent e) { - isOverBar = false; - if (model == null) { - return; + @Override + public void mouseMoved(MouseEvent e) { + lastMouseMove = e.getPoint(); + update(); + } + }; + private final MouseListener mouseListener = new MouseListener() { + + @Override + public void mouseClicked(MouseEvent e) { + if (model != null) { + int index = getIndexFromPosition(e.getPoint().y); + model.setPositions(index, index); + } } - - Point p = e.getPoint(); - if (isOverFirstPosition(p) || isOverSecondPosition(p)) { - setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR)); - } else if (isOverSelection(p)) { - isOverBar = true; - setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - } else { - this.setCursor(Cursor.getDefaultCursor()); + @Override + public void mousePressed(MouseEvent e) { + if (model != null) { + int index = getIndexFromPosition(e.getPoint().y); + startPoint = e.getPoint(); + tempModel = model.copy(); + tempModel.getChangedEvent().addListener(modelChangedListener); + tempModel.setPositions(index, index); + } } - repaint(); - } + + @Override + public void mouseReleased(MouseEvent e) { + if (tempModel != null) { + model.setPositions(tempModel.getFirstPosition(), tempModel.getSecondPosition()); + tempModel = null; + startPoint = null; + } + } - @Override - public void mouseClicked(MouseEvent e) { - if (e.getClickCount() > 1) { - // Double click - int index = getCircleIndexFromPosition(e.getPoint().x); - model.setPositions(index, index); + @Override + public void mouseEntered(MouseEvent e) { } + + @Override + public void mouseExited(MouseEvent e) { + lastMouseMove = null; + repaint(); + } + }; + + public RangeSliderModel getModel() { + return model; } - @Override - public void mousePressed(MouseEvent e) { - if (model == null) { - return; - } - - Point p = e.getPoint(); - if (isOverFirstPosition(p)) { - state = State.DragFirstPosition; - } else if (isOverSecondPosition(p)) { - state = State.DragSecondPosition; - } else if (isOverSelection(p)) { - state = State.DragBar; - } else { - return; + public void setModel(RangeSliderModel newModel) { + if (newModel != this.model) { + if (this.model != null) { + this.model.getChangedEvent().removeListener(modelChangedListener); + } + this.model = newModel; + if (newModel != null) { + newModel.getChangedEvent().addListener(modelChangedListener); + } + this.tempModel = null; + update(); } - - startPoint = e.getPoint(); - tempModel = model.copy(); - } - - @Override - public void mouseReleased(MouseEvent e) { - if (model == null || tempModel == null) { - return; - } - state = State.Initial; - model.setPositions(tempModel.getFirstPosition(), tempModel.getSecondPosition()); - tempModel = null; - } - - @Override - public void mouseEntered(MouseEvent e) { - } - - @Override - public void mouseExited(MouseEvent e) { - isOverBar = false; - repaint(); } } diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/RangeSliderModel.java --- a/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/RangeSliderModel.java Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/RangeSliderModel.java Tue Feb 07 21:09:31 2012 +0100 @@ -39,7 +39,6 @@ // Warning: Update setData method if fields are added private ChangedEvent changedEvent; - private ChangedEvent colorChangedEvent; private List positions; private int firstPosition; private int secondPosition; @@ -53,24 +52,20 @@ firstPosition = model.firstPosition; changed |= (secondPosition != model.secondPosition); secondPosition = model.secondPosition; - boolean colorChanged = (colors != model.colors); + changed |= (colors != model.colors); colors = model.colors; if (changed) { changedEvent.fire(); } - if (colorChanged) { - colorChangedEvent.fire(); - } } public RangeSliderModel(List positions) { assert positions.size() > 0; this.changedEvent = new ChangedEvent<>(this); - this.colorChangedEvent = new ChangedEvent<>(this); setPositions(positions); } - protected void setPositions(List positions) { + protected final void setPositions(List positions) { this.positions = positions; colors = new ArrayList<>(); for (int i = 0; i < positions.size(); i++) { @@ -79,12 +74,11 @@ firstPosition = Math.min(firstPosition, positions.size() - 1); secondPosition = Math.min(secondPosition, positions.size() - 1); changedEvent.fire(); - colorChangedEvent.fire(); } public void setColors(List colors) { this.colors = colors; - colorChangedEvent.fire(); + changedEvent.fire(); } public List getColors() { @@ -126,10 +120,6 @@ } } - public ChangedEvent getColorChangedEvent() { - return colorChangedEvent; - } - @Override public ChangedEvent getChangedEvent() { return changedEvent; diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/nbproject/project.xml --- a/src/share/tools/IdealGraphVisualizer/View/nbproject/project.xml Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/nbproject/project.xml Tue Feb 07 21:09:31 2012 +0100 @@ -1,175 +1,175 @@ - - - org.netbeans.modules.apisupport.project - - - com.sun.hotspot.igv.view - - - - com.sun.hotspot.igv.data - - - - 1.0 - - - - com.sun.hotspot.igv.difference - - - - 1.0 - - - - com.sun.hotspot.igv.filter - - - - 1.0 - - - - com.sun.hotspot.igv.graph - - - - 1.0 - - - - com.sun.hotspot.igv.hierarchicallayout - - - - 1.0 - - - - com.sun.hotspot.igv.layout - - - - 1.0 - - - - com.sun.hotspot.igv.selectioncoordinator - - - - 1.0 - - - - com.sun.hotspot.igv.settings - - - - 1.0 - - - - com.sun.hotspot.igv.svg - - - - 1.0 - - - - com.sun.hotspot.igv.util - - - - 1.0 - - - - org.netbeans.api.visual - - - - 2.27.1 - - - - org.netbeans.spi.quicksearch - - - - 1.0 - - - - org.openide.actions - - - - 6.21.1 - - - - org.openide.awt - - - - 7.30.1 - - - - org.openide.dialogs - - - - 7.18.1 - - - - org.openide.loaders - - - - 7.20.1 - - - - org.openide.nodes - - - - 7.20.1 - - - - org.openide.util - - - - 8.14.1 - - - - org.openide.util.lookup - - - - 8.6.1 - - - - org.openide.windows - - - - 6.39.1 - - - - - com.sun.hotspot.igv.view - - - - + + + org.netbeans.modules.apisupport.project + + + com.sun.hotspot.igv.view + + + + com.oracle.graal.visualizer.editor + + + + 1.0 + + + + com.sun.hotspot.igv.data + + + + 1.0 + + + + com.sun.hotspot.igv.difference + + + + 1.0 + + + + com.sun.hotspot.igv.filter + + + + 1.0 + + + + com.sun.hotspot.igv.graph + + + + 1.0 + + + + com.sun.hotspot.igv.hierarchicallayout + + + + 1.0 + + + + com.sun.hotspot.igv.layout + + + + 1.0 + + + + com.sun.hotspot.igv.settings + + + + 1.0 + + + + com.sun.hotspot.igv.svg + + + + 1.0 + + + + com.sun.hotspot.igv.util + + + + 1.0 + + + + org.netbeans.api.visual + + + + 2.27.1 + + + + org.netbeans.spi.quicksearch + + + + 1.0 + + + + org.openide.actions + + + + 6.21.1 + + + + org.openide.awt + + + + 7.30.1 + + + + org.openide.dialogs + + + + 7.18.1 + + + + org.openide.loaders + + + + 7.20.1 + + + + org.openide.nodes + + + + 7.20.1 + + + + org.openide.util + + + + 8.14.1 + + + + org.openide.util.lookup + + + + 8.6.1 + + + + org.openide.windows + + + + 6.39.1 + + + + + com.sun.hotspot.igv.view + + + + diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/META-INF/services/com.oracle.graal.visualizer.editor.CompilationViewerFactory --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/View/src/META-INF/services/com.oracle.graal.visualizer.editor.CompilationViewerFactory Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,1 @@ +com.sun.hotspot.igv.view.scene.GraphCompilationViewerFactory diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/META-INF/services/com.sun.hotspot.igv.data.services.GraphViewer --- a/src/share/tools/IdealGraphVisualizer/View/src/META-INF/services/com.sun.hotspot.igv.data.services.GraphViewer Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -com.sun.hotspot.igv.view.GraphViewerImplementation diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/BoundedZoomAction.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/BoundedZoomAction.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,175 +0,0 @@ -/* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ -package com.sun.hotspot.igv.view; - -import java.awt.Container; -import java.awt.Dimension; -import java.awt.Point; -import java.awt.Rectangle; -import javax.swing.JComponent; -import javax.swing.JScrollPane; -import org.netbeans.api.visual.action.WidgetAction; -import org.netbeans.api.visual.action.WidgetAction.State; -import org.netbeans.api.visual.action.WidgetAction.WidgetMouseWheelEvent; -import org.netbeans.api.visual.animator.SceneAnimator; -import org.netbeans.api.visual.widget.Scene; -import org.netbeans.api.visual.widget.Widget; - -/** - * - * @author Thomas Wuerthinger - */ -public class BoundedZoomAction extends WidgetAction.Adapter { - - private double minFactor = 0.0; - private double maxFactor = Double.MAX_VALUE; - private double zoomMultiplier; - private boolean useAnimator; - - public BoundedZoomAction(double zoomMultiplier, boolean useAnimator) { - assert zoomMultiplier > 1.0; - this.zoomMultiplier = zoomMultiplier; - this.useAnimator = useAnimator; - } - - public double getMinFactor() { - return minFactor; - } - - public void setMinFactor(double d) { - minFactor = d; - } - - public double getMaxFactor() { - return maxFactor; - } - - public void setMaxFactor(double d) { - maxFactor = d; - } - - private JScrollPane findScrollPane(JComponent component) { - for (;;) { - if (component == null) { - return null; - } - if (component instanceof JScrollPane) { - return ((JScrollPane) component); - } - Container parent = component.getParent(); - if (!(parent instanceof JComponent)) { - return null; - } - component = (JComponent) parent; - } - } - - @Override - public State mouseWheelMoved(Widget widget, WidgetMouseWheelEvent event) { - final Scene scene = widget.getScene(); - int amount = event.getWheelRotation(); - JScrollPane scrollPane = findScrollPane(scene.getView()); - Point viewPosition = null; - Point mouseLocation = scene.convertSceneToView(event.getPoint()); - int xOffset = 0; - int yOffset = 0; - Rectangle bounds = new Rectangle(scene.getBounds()); - Dimension componentSize = new Dimension(scene.getView().getPreferredSize()); - if (scrollPane != null) { - viewPosition = new Point(scrollPane.getViewport().getViewPosition()); - xOffset = (mouseLocation.x - viewPosition.x); - yOffset = (mouseLocation.y - viewPosition.y); - viewPosition.x += xOffset; - viewPosition.y += yOffset; - } - - if (useAnimator) { - SceneAnimator sceneAnimator = scene.getSceneAnimator(); - synchronized (sceneAnimator) { - double zoom = sceneAnimator.isAnimatingZoomFactor() ? sceneAnimator.getTargetZoomFactor() : scene.getZoomFactor(); - while (amount > 0 && zoom / zoomMultiplier >= minFactor) { - zoom /= zoomMultiplier; - if (viewPosition != null) { - viewPosition.x /= zoomMultiplier; - viewPosition.y /= zoomMultiplier; - bounds.width /= zoomMultiplier; - bounds.height /= zoomMultiplier; - componentSize.width /= zoomMultiplier; - componentSize.height /= zoomMultiplier; - } - amount--; - } - while (amount < 0 && zoom * zoomMultiplier <= maxFactor) { - zoom *= zoomMultiplier; - if (viewPosition != null) { - viewPosition.x *= zoomMultiplier; - viewPosition.y *= zoomMultiplier; - bounds.width *= zoomMultiplier; - bounds.height *= zoomMultiplier; - componentSize.width *= zoomMultiplier; - componentSize.height *= zoomMultiplier; - } - amount++; - } - sceneAnimator.animateZoomFactor(zoom); - } - } else { - double zoom = scene.getZoomFactor(); - while (amount > 0 && zoom / zoomMultiplier >= minFactor) { - zoom /= zoomMultiplier; - if (viewPosition != null) { - viewPosition.x /= zoomMultiplier; - viewPosition.y /= zoomMultiplier; - bounds.width /= zoomMultiplier; - bounds.height /= zoomMultiplier; - componentSize.width /= zoomMultiplier; - componentSize.height /= zoomMultiplier; - } - amount--; - } - while (amount < 0 && zoom * zoomMultiplier <= maxFactor) { - zoom *= zoomMultiplier; - if (viewPosition != null) { - viewPosition.x *= zoomMultiplier; - viewPosition.y *= zoomMultiplier; - bounds.width *= zoomMultiplier; - bounds.height *= zoomMultiplier; - componentSize.width *= zoomMultiplier; - componentSize.height *= zoomMultiplier; - } - amount++; - } - scene.setZoomFactor(zoom); - } - - if (scrollPane != null) { - viewPosition.x -= xOffset; - viewPosition.y -= yOffset; - scrollPane.getViewport().setViewPosition(viewPosition); - } - - - return WidgetAction.State.CONSUMED; - } -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/Bundle.properties --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/Bundle.properties Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/Bundle.properties Tue Feb 07 21:09:31 2012 +0100 @@ -1,3 +1,1 @@ -HINT_EditorTopComponent=Visualizes a graph. -OpenIDE-Module-Name=View -CTL_EditorTopComponent=Graph \ No newline at end of file +OpenIDE-Module-Name=View \ No newline at end of file diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/DiagramScene.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/DiagramScene.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1180 +0,0 @@ -/* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ -package com.sun.hotspot.igv.view; - -import com.sun.hotspot.igv.data.ChangedListener; -import com.sun.hotspot.igv.data.ControllableChangedListener; -import com.sun.hotspot.igv.data.Pair; -import com.sun.hotspot.igv.data.Properties; -import com.sun.hotspot.igv.graph.*; -import com.sun.hotspot.igv.hierarchicallayout.HierarchicalLayoutManager; -import com.sun.hotspot.igv.layout.LayoutGraph; -import com.sun.hotspot.igv.selectioncoordinator.SelectionCoordinator; -import com.sun.hotspot.igv.util.ColorIcon; -import com.sun.hotspot.igv.util.DoubleClickAction; -import com.sun.hotspot.igv.util.PropertiesSheet; -import com.sun.hotspot.igv.view.actions.CustomizablePanAction; -import com.sun.hotspot.igv.view.widgets.*; -import java.awt.*; -import java.awt.event.*; -import java.util.List; -import java.util.*; -import javax.swing.*; -import javax.swing.event.UndoableEditEvent; -import javax.swing.undo.AbstractUndoableEdit; -import javax.swing.undo.CannotRedoException; -import javax.swing.undo.CannotUndoException; -import org.netbeans.api.visual.action.*; -import org.netbeans.api.visual.animator.SceneAnimator; -import org.netbeans.api.visual.layout.LayoutFactory; -import org.netbeans.api.visual.model.*; -import org.netbeans.api.visual.widget.LayerWidget; -import org.netbeans.api.visual.widget.Widget; -import org.openide.awt.UndoRedo; -import org.openide.nodes.AbstractNode; -import org.openide.nodes.Children; -import org.openide.nodes.Sheet; -import org.openide.util.Lookup; -import org.openide.util.lookup.AbstractLookup; -import org.openide.util.lookup.InstanceContent; - -/** - * - * @author Thomas Wuerthinger - */ -public class DiagramScene extends ObjectScene implements DiagramViewer { - - private CustomizablePanAction panAction; - private WidgetAction hoverAction; - private WidgetAction selectAction; - private Lookup lookup; - private InstanceContent content; - private Action[] actions; - private LayerWidget connectionLayer; - private JScrollPane scrollPane; - private UndoRedo.Manager undoRedoManager; - private LayerWidget mainLayer; - private LayerWidget blockLayer; - private Widget topLeft; - private Widget bottomRight; - private DiagramViewModel model; - private DiagramViewModel modelCopy; - private WidgetAction zoomAction; - private boolean rebuilding; - - /** - * The alpha level of partially visible figures. - */ - public static final float ALPHA = 0.4f; - - /** - * The offset of the graph to the border of the window showing it. - */ - public static final int BORDER_SIZE = 20; - - - public static final int UNDOREDO_LIMIT = 100; - public static final int SCROLL_UNIT_INCREMENT = 80; - public static final int SCROLL_BLOCK_INCREMENT = 400; - public static final float ZOOM_MAX_FACTOR = 3.0f; - public static final float ZOOM_MIN_FACTOR = 0.0f;//0.15f; - public static final float ZOOM_INCREMENT = 1.5f; - public static final int SLOT_OFFSET = 6; - public static final int ANIMATION_LIMIT = 40; - - private PopupMenuProvider popupMenuProvider = new PopupMenuProvider() { - - @Override - public JPopupMenu getPopupMenu(Widget widget, Point localLocation) { - return DiagramScene.this.createPopupMenu(); - } - }; - private RectangularSelectDecorator rectangularSelectDecorator = new RectangularSelectDecorator() { - - @Override - public Widget createSelectionWidget() { - Widget widget = new Widget(DiagramScene.this); - widget.setBorder(BorderFactory.createLineBorder(Color.black, 2)); - widget.setForeground(Color.red); - return widget; - } - }; - - @SuppressWarnings("unchecked") - public T getWidget(Object o) { - Widget w = this.findWidget(o); - return (T) w; - } - - @SuppressWarnings("unchecked") - public T getWidget(Object o, Class klass) { - Widget w = this.findWidget(o); - return (T) w; - } - - private static boolean intersects(Set s1, Set s2) { - for (Object o : s1) { - if (s2.contains(o)) { - return true; - } - } - return false; - } - - @Override - public void zoomOut() { - double zoom = getZoomFactor(); - Point viewPosition = getScrollPane().getViewport().getViewPosition(); - double newZoom = zoom / DiagramScene.ZOOM_INCREMENT; - if (newZoom > DiagramScene.ZOOM_MIN_FACTOR) { - setZoomFactor(newZoom); - validate(); - getScrollPane().getViewport().setViewPosition(new Point((int) (viewPosition.x / DiagramScene.ZOOM_INCREMENT), (int) (viewPosition.y / DiagramScene.ZOOM_INCREMENT))); - } - } - - @Override - public void zoomIn() { - - double zoom = getZoomFactor(); - Point viewPosition = getScrollPane().getViewport().getViewPosition(); - double newZoom = zoom * DiagramScene.ZOOM_INCREMENT; - if (newZoom < DiagramScene.ZOOM_MAX_FACTOR) { - setZoomFactor(newZoom); - validate(); - getScrollPane().getViewport().setViewPosition(new Point((int) (viewPosition.x * DiagramScene.ZOOM_INCREMENT), (int) (viewPosition.y * DiagramScene.ZOOM_INCREMENT))); - } - } - - - @Override - public void centerFigures(List
list) { - - boolean b = getUndoRedoEnabled(); - setUndoRedoEnabled(false); - gotoFigures(list); - setUndoRedoEnabled(b); - } - - private Set getObjectsFromIdSet(Set set) { - Set selectedObjects = new HashSet<>(); - for (Figure f : getModel().getDiagramToView().getFigures()) { - if (intersects(f.getSource().getSourceNodesAsSet(), set)) { - selectedObjects.add(f); - } - - for (Slot s : f.getSlots()) { - if (intersects(s.getSource().getSourceNodesAsSet(), set)) { - selectedObjects.add(s); - } - } - } - return selectedObjects; - } - private ControllableChangedListener highlightedCoordinatorListener = new ControllableChangedListener() { - - @Override - public void filteredChanged(SelectionCoordinator source) { - DiagramScene.this.setHighlightedObjects(getObjectsFromIdSet(source.getHighlightedObjects())); - DiagramScene.this.validate(); - } - }; - private ControllableChangedListener selectedCoordinatorListener = new ControllableChangedListener() { - - @Override - public void filteredChanged(SelectionCoordinator source) { - DiagramScene.this.gotoSelection(source.getSelectedObjects()); - DiagramScene.this.validate(); - } - }; - - private RectangularSelectProvider rectangularSelectProvider = new RectangularSelectProvider() { - - @Override - public void performSelection(Rectangle rectangle) { - if (rectangle.width < 0) { - rectangle.x += rectangle.width; - rectangle.width *= -1; - } - - if (rectangle.height < 0) { - rectangle.y += rectangle.height; - rectangle.height *= -1; - } - - Set selectedObjects = new HashSet<>(); - for (Figure f : getModel().getDiagramToView().getFigures()) { - FigureWidget w = getWidget(f); - if (w != null) { - Rectangle r = new Rectangle(w.getBounds()); - r.setLocation(w.getLocation()); - - if (r.intersects(rectangle)) { - selectedObjects.add(f); - } - - for (Slot s : f.getSlots()) { - SlotWidget sw = getWidget(s); - Rectangle r2 = new Rectangle(sw.getBounds()); - r2.setLocation(sw.convertLocalToScene(new Point(0, 0))); - - if (r2.intersects(rectangle)) { - selectedObjects.add(s); - } - } - } else { - assert false : "w should not be null here!"; - } - } - - setSelectedObjects(selectedObjects); - } - }; - - private MouseWheelListener mouseWheelListener = new MouseWheelListener() { - - @Override - public void mouseWheelMoved(MouseWheelEvent e) { - if (e.isControlDown()) { - DiagramScene.this.relayoutWithoutLayout(null); - } - } - }; - - public Point getScrollPosition() { - return getScrollPane().getViewport().getViewPosition(); - } - - public void setScrollPosition(Point p) { - getScrollPane().getViewport().setViewPosition(p); - } - - private JScrollPane createScrollPane() { - JComponent comp = this.createView(); - comp.setDoubleBuffered(true); - comp.setBackground(Color.WHITE); - comp.setOpaque(true); - this.setBackground(Color.WHITE); - this.setOpaque(true); - JScrollPane result = new JScrollPane(comp); - result.setBackground(Color.WHITE); - result.getVerticalScrollBar().setUnitIncrement(SCROLL_UNIT_INCREMENT); - result.getVerticalScrollBar().setBlockIncrement(SCROLL_BLOCK_INCREMENT); - result.getHorizontalScrollBar().setUnitIncrement(SCROLL_UNIT_INCREMENT); - result.getHorizontalScrollBar().setBlockIncrement(SCROLL_BLOCK_INCREMENT); - return result; - } - private ObjectSceneListener selectionChangedListener = new ObjectSceneListener() { - - @Override - public void objectAdded(ObjectSceneEvent arg0, Object arg1) { - } - - @Override - public void objectRemoved(ObjectSceneEvent arg0, Object arg1) { - } - - @Override - public void objectStateChanged(ObjectSceneEvent e, Object o, ObjectState oldState, ObjectState newState) { - } - - @Override - public void selectionChanged(ObjectSceneEvent e, Set oldSet, Set newSet) { - DiagramScene scene = (DiagramScene) e.getObjectScene(); - if (scene.isRebuilding()) { - return; - } - - content.set(newSet, null); - - Set nodeSelection = new HashSet<>(); - for (Object o : newSet) { - if (o instanceof Properties.Provider) { - final Properties.Provider provider = (Properties.Provider) o; - AbstractNode node = new AbstractNode(Children.LEAF) { - - @Override - protected Sheet createSheet() { - Sheet s = super.createSheet(); - PropertiesSheet.initializeSheet(provider.getProperties(), s); - return s; - } - }; - node.setDisplayName(provider.getProperties().get("name")); - content.add(node); - } - - - if (o instanceof Figure) { - nodeSelection.addAll(((Figure) o).getSource().getSourceNodesAsSet()); - } else if (o instanceof Slot) { - nodeSelection.addAll(((Slot) o).getSource().getSourceNodesAsSet()); - } - } - getModel().setSelectedNodes(nodeSelection); - - boolean b = selectedCoordinatorListener.isEnabled(); - selectedCoordinatorListener.setEnabled(false); - SelectionCoordinator.getInstance().setSelectedObjects(nodeSelection); - selectedCoordinatorListener.setEnabled(b); - - } - - @Override - public void highlightingChanged(ObjectSceneEvent e, Set oldSet, Set newSet) { - Set nodeHighlighting = new HashSet<>(); - for (Object o : newSet) { - if (o instanceof Figure) { - nodeHighlighting.addAll(((Figure) o).getSource().getSourceNodesAsSet()); - } else if (o instanceof Slot) { - nodeHighlighting.addAll(((Slot) o).getSource().getSourceNodesAsSet()); - } - } - boolean b = highlightedCoordinatorListener.isEnabled(); - highlightedCoordinatorListener.setEnabled(false); - SelectionCoordinator.getInstance().setHighlightedObjects(nodeHighlighting); - highlightedCoordinatorListener.setEnabled(true); - } - - @Override - public void hoverChanged(ObjectSceneEvent e, Object oldObject, Object newObject) { - Set newHighlightedObjects = new HashSet<>(DiagramScene.this.getHighlightedObjects()); - if (oldObject != null) { - newHighlightedObjects.remove(oldObject); - } - if (newObject != null) { - newHighlightedObjects.add(newObject); - } - DiagramScene.this.setHighlightedObjects(newHighlightedObjects); - } - - @Override - public void focusChanged(ObjectSceneEvent arg0, Object arg1, Object arg2) { - } - }; - - public DiagramScene(Action[] actions, DiagramViewModel model) { - - this.actions = actions; - - content = new InstanceContent(); - lookup = new AbstractLookup(content); - - this.setCheckClipping(true); - - scrollPane = createScrollPane(); - - hoverAction = createObjectHoverAction(); - - // This panAction handles the event only when the left mouse button is - // pressed without any modifier keys, otherwise it will not consume it - // and the selection action (below) will handle the event - panAction = new CustomizablePanAction(~0, MouseEvent.BUTTON1_DOWN_MASK); - this.getActions().addAction(panAction); - - selectAction = createSelectAction(); - this.getActions().addAction(selectAction); - - blockLayer = new LayerWidget(this); - this.addChild(blockLayer); - - mainLayer = new LayerWidget(this); - this.addChild(mainLayer); - - topLeft = new Widget(this); - topLeft.setPreferredLocation(new Point(-BORDER_SIZE, -BORDER_SIZE)); - this.addChild(topLeft); - - bottomRight = new Widget(this); - bottomRight.setPreferredLocation(new Point(-BORDER_SIZE, -BORDER_SIZE)); - this.addChild(bottomRight); - - connectionLayer = new LayerWidget(this); - this.addChild(connectionLayer); - - LayerWidget selectionLayer = new LayerWidget(this); - this.addChild(selectionLayer); - - this.setLayout(LayoutFactory.createAbsoluteLayout()); - - this.getInputBindings().setZoomActionModifiers(KeyEvent.CTRL_MASK); - zoomAction = ActionFactory.createMouseCenteredZoomAction(1.2); - this.getActions().addAction(zoomAction); - this.getView().addMouseWheelListener(mouseWheelListener); - this.getActions().addAction(ActionFactory.createPopupMenuAction(popupMenuProvider)); - - this.getActions().addAction(ActionFactory.createWheelPanAction()); - - LayerWidget selectLayer = new LayerWidget(this); - this.addChild(selectLayer); - this.getActions().addAction(ActionFactory.createRectangularSelectAction(rectangularSelectDecorator, selectLayer, rectangularSelectProvider)); - - boolean b = this.getUndoRedoEnabled(); - this.setUndoRedoEnabled(false); - this.setNewModel(model); - this.setUndoRedoEnabled(b); - this.addObjectSceneListener(selectionChangedListener, ObjectSceneEventType.OBJECT_SELECTION_CHANGED, ObjectSceneEventType.OBJECT_HIGHLIGHTING_CHANGED, ObjectSceneEventType.OBJECT_HOVER_CHANGED); - } - - public DiagramViewModel getModel() { - return model; - } - - public JScrollPane getScrollPane() { - return scrollPane; - } - - @Override - public Component getComponent() { - return scrollPane; - } - - public boolean isAllVisible() { - return getModel().getHiddenNodes().size() == 0; - } - - public Action createGotoAction(final Figure f) { - final DiagramScene diagramScene = this; - Action a = new AbstractAction() { - - @Override - public void actionPerformed(ActionEvent e) { - diagramScene.gotoFigure(f); - } - }; - - a.setEnabled(true); - a.putValue(Action.SMALL_ICON, new ColorIcon(f.getColor())); - String name = f.getLines()[0]; - - name += " ("; - - if (!this.getWidget(f, FigureWidget.class).isVisible()) { - name += "hidden"; - } - name += ")"; - a.putValue(Action.NAME, name); - return a; - } - - public void setNewModel(DiagramViewModel model) { - assert this.model == null : "can set model only once!"; - this.model = model; - this.modelCopy = null; - - model.getDiagramChangedEvent().addListener(fullChange); - model.getViewPropertiesChangedEvent().addListener(fullChange); - model.getViewChangedEvent().addListener(selectionChange); - model.getHiddenNodesChangedEvent().addListener(hiddenNodesChange); - update(); - } - - private void update() { - mainLayer.removeChildren(); - blockLayer.removeChildren(); - - rebuilding = true; - - Collection objects = new ArrayList<>(this.getObjects()); - for (Object o : objects) { - this.removeObject(o); - } - - Diagram d = getModel().getDiagramToView(); - - for (Figure f : d.getFigures()) { - FigureWidget w = new FigureWidget(f, hoverAction, selectAction, this, mainLayer); - w.getActions().addAction(ActionFactory.createPopupMenuAction(w)); - w.getActions().addAction(selectAction); - w.getActions().addAction(hoverAction); - w.setVisible(false); - - this.addObject(f, w); - - for (InputSlot s : f.getInputSlots()) { - SlotWidget sw = new InputSlotWidget(s, this, w, w); - addObject(s, sw); - sw.getActions().addAction(new DoubleClickAction(sw)); - sw.getActions().addAction(hoverAction); - sw.getActions().addAction(selectAction); - } - - for (OutputSlot s : f.getOutputSlots()) { - SlotWidget sw = new OutputSlotWidget(s, this, w, w); - addObject(s, sw); - sw.getActions().addAction(new DoubleClickAction(sw)); - sw.getActions().addAction(hoverAction); - sw.getActions().addAction(selectAction); - } - } - - rebuilding = false; - this.smallUpdate(true); - } - - public boolean isRebuilding() { - return rebuilding; - } - - private void smallUpdate(boolean relayout) { - - System.out.println("smallUpdate " + relayout); - this.updateHiddenNodes(model.getHiddenNodes(), relayout); - boolean b = this.getUndoRedoEnabled(); - this.setUndoRedoEnabled(false); - this.setUndoRedoEnabled(b); - this.validate(); - } - - private boolean isVisible(Connection c) { - FigureWidget w1 = getWidget(c.getInputSlot().getFigure()); - FigureWidget w2 = getWidget(c.getOutputSlot().getFigure()); - - if (w1.isVisible() && w2.isVisible()) { - return true; - } - - return false; - } - - private void relayout(Set oldVisibleWidgets) { - System.out.println("relayout called with old visible widgets: " + oldVisibleWidgets); - - Diagram diagram = getModel().getDiagramToView(); - - HashSet
figures = new HashSet<>(); - - for (Figure f : diagram.getFigures()) { - FigureWidget w = getWidget(f); - if (w.isVisible()) { - figures.add(f); - } - } - - HashSet edges = new HashSet<>(); - - for (Connection c : diagram.getConnections()) { - if (isVisible(c)) { - edges.add(c); - } - } - - HierarchicalLayoutManager manager = new HierarchicalLayoutManager(HierarchicalLayoutManager.Combine.SAME_OUTPUTS); - manager.setMaxLayerLength(10); - manager.doLayout(new LayoutGraph(edges, figures)); - relayoutWithoutLayout(oldVisibleWidgets); - } - private Set> lineCache = new HashSet<>(); - - private void relayoutWithoutLayout(Set oldVisibleWidgets) { - - System.out.println("relayout without layout with visible widgets: " + oldVisibleWidgets); - - Diagram diagram = getModel().getDiagramToView(); - - int maxX = -BORDER_SIZE; - int maxY = -BORDER_SIZE; - for (Figure f : diagram.getFigures()) { - FigureWidget w = getWidget(f); - if (w.isVisible()) { - Point p = f.getPosition(); - Dimension d = f.getSize(); - maxX = Math.max(maxX, p.x + d.width); - maxY = Math.max(maxY, p.y + d.height); - } - } - - for (Connection c : diagram.getConnections()) { - List points = c.getControlPoints(); - FigureWidget w1 = getWidget((Figure) c.getTo().getVertex()); - FigureWidget w2 = getWidget((Figure) c.getFrom().getVertex()); - if (w1.isVisible() && w2.isVisible()) { - for (Point p : points) { - if (p != null) { - maxX = Math.max(maxX, p.x); - maxY = Math.max(maxY, p.y); - } - } - } - } - - bottomRight.setPreferredLocation(new Point(maxX + BORDER_SIZE, maxY + BORDER_SIZE)); - int offx = 0; - int offy = 0; - int curWidth = maxX + 2 * BORDER_SIZE; - int curHeight = maxY + 2 * BORDER_SIZE; - - Rectangle bounds = this.getScrollPane().getBounds(); - bounds.width /= getZoomFactor(); - bounds.height /= getZoomFactor(); - if (curWidth < bounds.width) { - offx = (bounds.width - curWidth) / 2; - } - - if (curHeight < bounds.height) { - offy = (bounds.height - curHeight) / 2; - } - - final int offx2 = offx; - final int offy2 = offy; - - SceneAnimator animator = this.getSceneAnimator(); - connectionLayer.removeChildren(); - int visibleFigureCount = 0; - for (Figure f : diagram.getFigures()) { - if (getWidget(f, FigureWidget.class).isVisible()) { - visibleFigureCount++; - } - } - - - Set> lastLineCache = lineCache; - lineCache = new HashSet<>(); - for (Figure f : diagram.getFigures()) { - for (OutputSlot s : f.getOutputSlots()) { - SceneAnimator anim = animator; - if (visibleFigureCount > ANIMATION_LIMIT || oldVisibleWidgets == null) { - anim = null; - } - processOutputSlot(lastLineCache, s, s.getConnections(), 0, null, null, offx2, offy2, anim); - } - } - - for (Figure f : diagram.getFigures()) { - FigureWidget w = getWidget(f); - if (w.isVisible()) { - Point p = f.getPosition(); - Point p2 = new Point(p.x + offx2, p.y + offy2); - if ((visibleFigureCount <= ANIMATION_LIMIT && oldVisibleWidgets != null && oldVisibleWidgets.contains(w))) { - animator.animatePreferredLocation(w, p2); - } else { - w.setPreferredLocation(p2); - animator.animatePreferredLocation(w, p2); - } - } - } - - this.validate(); - } - private final Point specialNullPoint = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE); - - private void processOutputSlot(Set> lastLineCache, OutputSlot s, List connections, int controlPointIndex, Point lastPoint, LineWidget predecessor, int offx, int offy, SceneAnimator animator) { - Map> pointMap = new HashMap<>(connections.size()); - - for (Connection c : connections) { - - if (!isVisible(c)) { - continue; - } - - List controlPoints = c.getControlPoints(); - if (controlPointIndex >= controlPoints.size()) { - continue; - } - - Point cur = controlPoints.get(controlPointIndex); - if (cur == null) { - cur = specialNullPoint; - } else if (controlPointIndex == 0 && !s.shouldShowName()) { - cur = new Point(cur.x, cur.y - SLOT_OFFSET); - } else if (controlPointIndex == controlPoints.size() - 1 && !c.getInputSlot().shouldShowName()) { - cur = new Point(cur.x, cur.y + SLOT_OFFSET); - } - - if (pointMap.containsKey(cur)) { - pointMap.get(cur).add(c); - } else { - List newList = new ArrayList<>(2); - newList.add(c); - pointMap.put(cur, newList); - } - - } - - for (Point p : pointMap.keySet()) { - List connectionList = pointMap.get(p); - - boolean isBold = false; - boolean isDashed = true; - - for (Connection c : connectionList) { - - if (c.getStyle() == Connection.ConnectionStyle.BOLD) { - isBold = true; - } - - if (c.getStyle() != Connection.ConnectionStyle.DASHED) { - isDashed = false; - } - } - - LineWidget newPredecessor = predecessor; - if (p == specialNullPoint) { - } else if (lastPoint == specialNullPoint) { - } else if (lastPoint != null) { - Point p1 = new Point(lastPoint.x + offx, lastPoint.y + offy); - Point p2 = new Point(p.x + offx, p.y + offy); - - Pair curPair = new Pair<>(p1, p2); - SceneAnimator curAnimator = animator; - if (lastLineCache.contains(curPair)) { - curAnimator = null; - } - LineWidget w = new LineWidget(this, s, connectionList, p1, p2, predecessor, curAnimator, isBold, isDashed); - lineCache.add(curPair); - - newPredecessor = w; - connectionLayer.addChild(w); - this.addObject(new ConnectionSet(connectionList), w); - w.getActions().addAction(hoverAction); - } - - processOutputSlot(lastLineCache, s, connectionList, controlPointIndex + 1, p, newPredecessor, offx, offy, animator); - } - } - - @Override - public void setInteractionMode(InteractionMode mode) { - panAction.setEnabled(mode == InteractionMode.PANNING); - // When panAction is not enabled, it does not consume the event - // and the selection action handles it instead - } - - private class ConnectionSet { - - private Set connections; - - public ConnectionSet(Collection connections) { - connections = new HashSet<>(connections); - } - - public Set getConnectionSet() { - return Collections.unmodifiableSet(connections); - } - } - - @Override - public Lookup getLookup() { - return lookup; - } - - @Override - public void initialize() { - Figure f = getModel().getDiagramToView().getRootFigure(); - if (f != null) { - setUndoRedoEnabled(false); - gotoFigure(f); - setUndoRedoEnabled(true); - } - } - - public void gotoFigures(final List
figures) { - Rectangle overall = null; - getModel().showFigures(figures); - for (Figure f : figures) { - - FigureWidget fw = getWidget(f); - if (fw != null) { - Rectangle r = fw.getBounds(); - Point p = fw.getLocation(); - Rectangle r2 = new Rectangle(p.x, p.y, r.width, r.height); - - if (overall == null) { - overall = r2; - } else { - overall = overall.union(r2); - } - } - } - if (overall != null) { - centerRectangle(overall); - } - } - - private Set idSetToObjectSet(Set ids) { - - Set result = new HashSet<>(); - for (Figure f : getModel().getDiagramToView().getFigures()) { - if (DiagramScene.doesIntersect(f.getSource().getSourceNodesAsSet(), ids)) { - result.add(f); - } - - for (Slot s : f.getSlots()) { - if (DiagramScene.doesIntersect(s.getSource().getSourceNodesAsSet(), ids)) { - result.add(s); - } - } - } - return result; - } - - public void gotoSelection(Set ids) { - - Rectangle overall = null; - Set hiddenNodes = new HashSet<>(this.getModel().getHiddenNodes()); - hiddenNodes.removeAll(ids); - this.getModel().showNot(hiddenNodes); - - Set objects = idSetToObjectSet(ids); - for (Object o : objects) { - - Widget w = getWidget(o); - if (w != null) { - Rectangle r = w.getBounds(); - Point p = w.convertLocalToScene(new Point(0, 0)); - - Rectangle r2 = new Rectangle(p.x, p.y, r.width, r.height); - - if (overall == null) { - overall = r2; - } else { - overall = overall.union(r2); - } - } - } - if (overall != null) { - centerRectangle(overall); - } - - setSelectedObjects(objects); - } - - private Point calcCenter(Rectangle r) { - - Point center = new Point((int) r.getCenterX(), (int) r.getCenterY()); - center.x -= getScrollPane().getViewport().getViewRect().width / 2; - center.y -= getScrollPane().getViewport().getViewRect().height / 2; - - // Ensure to be within area - center.x = Math.max(0, center.x); - center.x = Math.min(getScrollPane().getViewport().getViewSize().width - getScrollPane().getViewport().getViewRect().width, center.x); - center.y = Math.max(0, center.y); - center.y = Math.min(getScrollPane().getViewport().getViewSize().height - getScrollPane().getViewport().getViewRect().height, center.y); - - return center; - } - - private void centerRectangle(Rectangle r) { - - if (getScrollPane().getViewport().getViewRect().width == 0 || getScrollPane().getViewport().getViewRect().height == 0) { - return; - } - - Rectangle r2 = new Rectangle(r.x, r.y, r.width, r.height); - r2 = convertSceneToView(r2); - - double factorX = (double) r2.width / (double) getScrollPane().getViewport().getViewRect().width; - double factorY = (double) r2.height / (double) getScrollPane().getViewport().getViewRect().height; - double factor = Math.max(factorX, factorY); - if (factor >= 1.0) { - Point p = getScrollPane().getViewport().getViewPosition(); - setZoomFactor(getZoomFactor() / factor); - r2.x /= factor; - r2.y /= factor; - r2.width /= factor; - r2.height /= factor; - getScrollPane().getViewport().setViewPosition(calcCenter(r2)); - } else { - getScrollPane().getViewport().setViewPosition(calcCenter(r2)); - } - } - - @Override - public void setSelection(Collection
list) { - super.setSelectedObjects(new HashSet<>(list)); - } - - private UndoRedo.Manager getUndoRedoManager() { - if (undoRedoManager == null) { - undoRedoManager = new UndoRedo.Manager(); - undoRedoManager.setLimit(UNDOREDO_LIMIT); - } - - return undoRedoManager; - } - - @Override - public UndoRedo getUndoRedo() { - return getUndoRedoManager(); - } - - private boolean isVisible(Figure f) { - for (Integer n : f.getSource().getSourceNodesAsSet()) { - if (getModel().getHiddenNodes().contains(n)) { - return false; - } - } - return true; - } - - public static boolean doesIntersect(Set s1, Set s2) { - if (s1.size() > s2.size()) { - Set tmp = s1; - s1 = s2; - s2 = tmp; - } - - for (Object o : s1) { - if (s2.contains(o)) { - return true; - } - } - - return false; - } - - @Override - public void componentHidden() { - SelectionCoordinator.getInstance().getHighlightedChangedEvent().removeListener(highlightedCoordinatorListener); - SelectionCoordinator.getInstance().getSelectedChangedEvent().removeListener(selectedCoordinatorListener); - } - - @Override - public void componentShowing() { - SelectionCoordinator.getInstance().getHighlightedChangedEvent().addListener(highlightedCoordinatorListener); - SelectionCoordinator.getInstance().getSelectedChangedEvent().addListener(selectedCoordinatorListener); - } - - private void updateHiddenNodes(Set newHiddenNodes, boolean doRelayout) { - - System.out.println("newHiddenNodes: " + newHiddenNodes); - - Diagram diagram = getModel().getDiagramToView(); - assert diagram != null; - - Set oldVisibleWidgets = new HashSet<>(); - - for (Figure f : diagram.getFigures()) { - FigureWidget w = getWidget(f); - if (w != null && w.isVisible()) { - oldVisibleWidgets.add(w); - } - } - - for (Figure f : diagram.getFigures()) { - boolean hiddenAfter = doesIntersect(f.getSource().getSourceNodesAsSet(), newHiddenNodes); - - FigureWidget w = getWidget(f); - w.setBoundary(false); - if (!hiddenAfter) { - // Figure is shown - w.setVisible(true); - } else { - // Figure is hidden - w.setVisible(false); - } - } - - if (getModel().getShowNodeHull()) { - List boundaries = new ArrayList<>(); - for (Figure f : diagram.getFigures()) { - FigureWidget w = getWidget(f); - if (!w.isVisible()) { - Set
set = new HashSet<>(f.getPredecessorSet()); - set.addAll(f.getSuccessorSet()); - - boolean b = false; - for (Figure neighbor : set) { - FigureWidget neighborWidget = getWidget(neighbor); - if (neighborWidget.isVisible()) { - b = true; - break; - } - } - - if (b) { - w.setBoundary(true); - boundaries.add(w); - } - } - } - - for (FigureWidget w : boundaries) { - if (w.isBoundary()) { - w.setVisible(true); - } - } - } - - if (doRelayout) { - relayout(oldVisibleWidgets); - } - this.validate(); - addUndo(); - } - - private void showFigure(Figure f) { - HashSet newHiddenNodes = new HashSet<>(getModel().getHiddenNodes()); - newHiddenNodes.removeAll(f.getSource().getSourceNodesAsSet()); - updateHiddenNodes(newHiddenNodes, true); - } - - public void show(final Figure f) { - showFigure(f); - } - - public void setSelectedObjects(Object... args) { - Set set = new HashSet<>(); - for (Object o : args) { - set.add(o); - } - super.setSelectedObjects(set); - } - - private void centerWidget(Widget w) { - Rectangle r = w.getBounds(); - Point p = w.getLocation(); - centerRectangle(new Rectangle(p.x, p.y, r.width, r.height)); - } - - public void gotoFigure(final Figure f) { - if (!isVisible(f)) { - showFigure(f); - } - - FigureWidget fw = getWidget(f); - if (fw != null) { - centerWidget(fw); - setSelection(Arrays.asList(f)); - } - } - - public JPopupMenu createPopupMenu() { - JPopupMenu menu = new JPopupMenu(); - for (Action a : actions) { - if (a == null) { - menu.addSeparator(); - } else { - menu.add(a); - } - } - return menu; - } - - private static class DiagramUndoRedo extends AbstractUndoableEdit implements ChangedListener { - - private DiagramViewModel oldModel; - private DiagramViewModel newModel; - private Point oldScrollPosition; - private DiagramScene scene; - - public DiagramUndoRedo(DiagramScene scene, Point oldScrollPosition, DiagramViewModel oldModel, DiagramViewModel newModel) { - assert oldModel != null; - assert newModel != null; - this.oldModel = oldModel; - this.newModel = newModel; - this.scene = scene; - this.oldScrollPosition = oldScrollPosition; - } - - @Override - public void redo() throws CannotRedoException { - super.redo(); - boolean b = scene.getUndoRedoEnabled(); - scene.setUndoRedoEnabled(false); - scene.getModel().getViewChangedEvent().addListener(this); - scene.getModel().setData(newModel); - scene.getModel().getViewChangedEvent().removeListener(this); - scene.setUndoRedoEnabled(b); - } - - @Override - public void undo() throws CannotUndoException { - super.undo(); - boolean b = scene.getUndoRedoEnabled(); - scene.setUndoRedoEnabled(false); - scene.getModel().getViewChangedEvent().addListener(this); - scene.getModel().setData(oldModel); - scene.getModel().getViewChangedEvent().removeListener(this); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - scene.setScrollPosition(oldScrollPosition); - } - }); - - scene.setUndoRedoEnabled(b); - } - - @Override - public void changed(DiagramViewModel source) { - scene.getModel().getViewChangedEvent().removeListener(this); - if (oldModel.getHiddenNodes().equals(newModel.getHiddenNodes())) { - scene.smallUpdate(false); - } else { - scene.smallUpdate(true); - } - } - } - private boolean undoRedoEnabled = true; - - public void setUndoRedoEnabled(boolean b) { - this.undoRedoEnabled = b; - } - - public boolean getUndoRedoEnabled() { - return undoRedoEnabled; - } - - private final ChangedListener fullChange = new ChangedListener() { - @Override - public void changed(DiagramViewModel source) { - assert source == model : "Receive only changed event from current model!"; - assert source != null; - update(); - } - }; - - private final ChangedListener hiddenNodesChange = new ChangedListener() { - @Override - public void changed(DiagramViewModel source) { - assert source == model : "Receive only changed event from current model!"; - assert source != null; - smallUpdate(true); - } - }; - - private final ChangedListener selectionChange = new ChangedListener() { - @Override - public void changed(DiagramViewModel source) { - assert source == model : "Receive only changed event from current model!"; - assert source != null; - smallUpdate(false); - } - }; - - - private void addUndo() { - - DiagramViewModel newModelCopy = model.copy(); - - if (undoRedoEnabled) { - this.getUndoRedoManager().undoableEditHappened(new UndoableEditEvent(this, new DiagramUndoRedo(this, this.getScrollPosition(), modelCopy, newModelCopy))); - } - - this.modelCopy = newModelCopy; - } -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/DiagramViewModel.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/DiagramViewModel.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,388 +0,0 @@ -/* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.sun.hotspot.igv.view; - -import com.sun.hotspot.igv.data.*; -import com.sun.hotspot.igv.difference.Difference; -import com.sun.hotspot.igv.filter.CustomFilter; -import com.sun.hotspot.igv.filter.FilterChain; -import com.sun.hotspot.igv.graph.Diagram; -import com.sun.hotspot.igv.graph.Figure; -import com.sun.hotspot.igv.settings.Settings; -import com.sun.hotspot.igv.util.RangeSliderModel; -import java.awt.Color; -import java.util.*; - -/** - * - * @author Thomas Wuerthinger - */ -public class DiagramViewModel extends RangeSliderModel implements ChangedListener { - - // Warning: Update setData method if fields are added - private Group group; - private Set hiddenNodes; - private Set onScreenNodes; - private Set selectedNodes; - private FilterChain filterChain; - private FilterChain sequenceFilterChain; - private Diagram diagram; - private InputGraph inputGraph; - private ChangedEvent groupChangedEvent; - private ChangedEvent diagramChangedEvent; - private ChangedEvent viewChangedEvent; - private ChangedEvent hiddenNodesChangedEvent; - private ChangedEvent viewPropertiesChangedEvent; - private boolean showNodeHull; - private ChangedListener filterChainChangedListener = new ChangedListener() { - - @Override - public void changed(FilterChain source) { - diagramChanged(); - } - }; - - @Override - public DiagramViewModel copy() { - DiagramViewModel result = new DiagramViewModel(group, filterChain, sequenceFilterChain); - result.setData(this); - return result; - } - - public void setData(DiagramViewModel newModel) { - super.setData(newModel); - boolean diagramChanged = false; - boolean viewChanged = false; - boolean viewPropertiesChanged = false; - - boolean groupChanged = (group == newModel.group); - this.group = newModel.group; - diagramChanged |= (filterChain != newModel.filterChain); - this.filterChain = newModel.filterChain; - diagramChanged |= (sequenceFilterChain != newModel.sequenceFilterChain); - this.sequenceFilterChain = newModel.sequenceFilterChain; - diagramChanged |= (diagram != newModel.diagram); - this.diagram = newModel.diagram; - viewChanged |= (hiddenNodes != newModel.hiddenNodes); - this.hiddenNodes = newModel.hiddenNodes; - viewChanged |= (onScreenNodes != newModel.onScreenNodes); - this.onScreenNodes = newModel.onScreenNodes; - viewChanged |= (selectedNodes != newModel.selectedNodes); - this.selectedNodes = newModel.selectedNodes; - viewPropertiesChanged |= (showNodeHull != newModel.showNodeHull); - this.showNodeHull = newModel.showNodeHull; - - if (groupChanged) { - groupChangedEvent.fire(); - } - - if (diagramChanged) { - diagramChangedEvent.fire(); - } - if (viewPropertiesChanged) { - viewPropertiesChangedEvent.fire(); - } - if (viewChanged) { - viewChangedEvent.fire(); - } - } - - public boolean getShowNodeHull() { - return showNodeHull; - } - - public void setShowNodeHull(boolean b) { - showNodeHull = b; - viewPropertiesChangedEvent.fire(); - } - - public DiagramViewModel(Group g, FilterChain filterChain, FilterChain sequenceFilterChain) { - super(calculateStringList(g)); - - this.showNodeHull = true; - this.group = g; - assert filterChain != null; - this.filterChain = filterChain; - assert sequenceFilterChain != null; - this.sequenceFilterChain = sequenceFilterChain; - hiddenNodes = new HashSet<>(); - onScreenNodes = new HashSet<>(); - selectedNodes = new HashSet<>(); - super.getChangedEvent().addListener(this); - diagramChangedEvent = new ChangedEvent<>(this); - viewChangedEvent = new ChangedEvent<>(this); - hiddenNodesChangedEvent = new ChangedEvent<>(this); - viewPropertiesChangedEvent = new ChangedEvent<>(this); - - groupChangedEvent = new ChangedEvent<>(this); - groupChangedEvent.addListener(groupChangedListener); - groupChangedEvent.fire(); - - filterChain.getChangedEvent().addListener(filterChainChangedListener); - sequenceFilterChain.getChangedEvent().addListener(filterChainChangedListener); - } - private final ChangedListener groupChangedListener = new ChangedListener() { - - private Group oldGroup; - - @Override - public void changed(DiagramViewModel source) { - if (oldGroup != null) { - oldGroup.getChangedEvent().removeListener(groupContentChangedListener); - } - group.getChangedEvent().addListener(groupContentChangedListener); - oldGroup = group; - } - }; - private final ChangedListener groupContentChangedListener = new ChangedListener() { - - @Override - public void changed(Group source) { - assert source == group; - setPositions(calculateStringList(source)); - setSelectedNodes(selectedNodes); - } - }; - - public ChangedEvent getDiagramChangedEvent() { - return diagramChangedEvent; - } - - public ChangedEvent getViewChangedEvent() { - return viewChangedEvent; - } - - public ChangedEvent getHiddenNodesChangedEvent() { - return hiddenNodesChangedEvent; - } - - public ChangedEvent getViewPropertiesChangedEvent() { - return viewPropertiesChangedEvent; - } - - public Set getSelectedNodes() { - return selectedNodes; - } - - public Set getHiddenNodes() { - return hiddenNodes; - } - - public Set getOnScreenNodes() { - return onScreenNodes; - } - - public void setSelectedNodes(Set nodes) { - this.selectedNodes = nodes; - List colors = new ArrayList<>(); - for (String s : getPositions()) { - colors.add(Color.black); - } - if (nodes.size() >= 1) { - for (Integer id : nodes) { - if (id < 0) { - id = -id; - } - InputNode last = null; - int index = 0; - for (InputGraph g : group.getGraphs()) { - Color curColor = colors.get(index); - InputNode cur = g.getNode(id); - if (cur != null) { - if (last == null) { - curColor = Color.green; - } else { - if (last.equals(cur)) { - if (curColor == Color.black) { - curColor = Color.white; - } - } else { - if (curColor != Color.green) { - curColor = Color.orange; - } - } - } - } - last = cur; - colors.set(index, curColor); - index++; - } - } - } - setColors(colors); - viewChangedEvent.fire(); - } - - public void showNot(final Set nodes) { - System.out.println("Shownot called with " + nodes); - setHiddenNodes(nodes); - } - - public void showFigures(Collection
f) { - HashSet newHiddenNodes = new HashSet<>(getHiddenNodes()); - for (Figure fig : f) { - newHiddenNodes.removeAll(fig.getSource().getSourceNodesAsSet()); - } - setHiddenNodes(newHiddenNodes); - } - - - public Set
getSelectedFigures() { - Set
result = new HashSet<>(); - for (Figure f : diagram.getFigures()) { - for (InputNode node : f.getSource().getSourceNodes()) { - if (getSelectedNodes().contains(node.getId())) { - result.add(f); - } - } - } - return result; - } - - public void showAll(final Collection
f) { - showFigures(f); - } - - public void showOnly(final Set nodes) { - final HashSet allNodes = new HashSet<>(getGraphToView().getGroup().getAllNodes()); - allNodes.removeAll(nodes); - setHiddenNodes(allNodes); - } - - public void setHiddenNodes(Set nodes) { - this.hiddenNodes = nodes; - hiddenNodesChangedEvent.fire(); - } - - public void setOnScreenNodes(Set onScreenNodes) { - this.onScreenNodes = onScreenNodes; - viewChangedEvent.fire(); - } - - public FilterChain getSequenceFilterChain() { - return filterChain; - } - - public void setSequenceFilterChain(FilterChain chain) { - assert chain != null : "sequenceFilterChain must never be null"; - sequenceFilterChain.getChangedEvent().removeListener(filterChainChangedListener); - sequenceFilterChain = chain; - sequenceFilterChain.getChangedEvent().addListener(filterChainChangedListener); - diagramChanged(); - } - - private void diagramChanged() { - // clear diagram - diagram = null; - getDiagramChangedEvent().fire(); - - } - - public FilterChain getFilterChain() { - return filterChain; - } - - public void setFilterChain(FilterChain chain) { - assert chain != null : "filterChain must never be null"; - filterChain.getChangedEvent().removeListener(filterChainChangedListener); - filterChain = chain; - filterChain.getChangedEvent().addListener(filterChainChangedListener); - diagramChanged(); - } - - private static List calculateStringList(Group g) { - List result = new ArrayList<>(); - for (InputGraph graph : g.getGraphs()) { - result.add(graph.getName()); - } - return result; - } - - public InputGraph getFirstGraph() { - List graphs = group.getGraphs(); - if (getFirstPosition() < graphs.size()) { - return graphs.get(getFirstPosition()); - } - return graphs.get(graphs.size() - 1); - } - - public InputGraph getSecondGraph() { - List graphs = group.getGraphs(); - if (getSecondPosition() < graphs.size()) { - return graphs.get(getSecondPosition()); - } - return getFirstGraph(); - } - - public void selectGraph(InputGraph g) { - int index = group.getGraphs().indexOf(g); - assert index != -1; - setPositions(index, index); - } - - public Diagram getDiagramToView() { - - if (diagram == null) { - diagram = Diagram.createDiagram(getGraphToView(), Settings.get().get(Settings.NODE_TEXT, Settings.NODE_TEXT_DEFAULT)); - getFilterChain().apply(diagram, getSequenceFilterChain()); - if (getFirstPosition() != getSecondPosition()) { - CustomFilter f = new CustomFilter( - "difference", "colorize('state', 'same', white);" - + "colorize('state', 'changed', orange);" - + "colorize('state', 'new', green);" - + "colorize('state', 'deleted', red);"); - f.apply(diagram); - } - } - - return diagram; - } - - public InputGraph getGraphToView() { - if (inputGraph == null) { - if (getFirstGraph() != getSecondGraph()) { - inputGraph = Difference.createDiffGraph(getFirstGraph(), getSecondGraph()); - } else { - inputGraph = getFirstGraph(); - } - } - - return inputGraph; - } - - @Override - public void changed(RangeSliderModel source) { - inputGraph = null; - diagramChanged(); - } - - void setSelectedFigures(List
list) { - Set newSelectedNodes = new HashSet<>(); - for (Figure f : list) { - newSelectedNodes.addAll(f.getSource().getSourceNodesAsSet()); - } - this.setSelectedNodes(newSelectedNodes); - } -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/DiagramViewer.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/DiagramViewer.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ - -package com.sun.hotspot.igv.view; - -import com.sun.hotspot.igv.graph.Figure; -import java.awt.Component; -import java.awt.Graphics2D; -import java.util.Collection; -import java.util.List; -import javax.swing.JComponent; -import org.openide.awt.UndoRedo; -import org.openide.util.Lookup; - -/** - * - * @author Thomas Wuerthinger - */ -interface DiagramViewer { - - enum InteractionMode { - SELECTION, - PANNING, - } - - public void paint(Graphics2D svgGenerator); - - public Lookup getLookup(); - - public JComponent createSatelliteView(); - - public Component getComponent(); - - public void zoomOut(); - - public void zoomIn(); - - public UndoRedo getUndoRedo(); - - public void componentHidden(); - - public void componentShowing(); - - public void initialize(); - - public void setSelection(Collection
list); - - public void centerFigures(List
list); - - public void setInteractionMode(InteractionMode mode); - -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorInputGraphProvider.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorInputGraphProvider.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -/* - * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.sun.hotspot.igv.view; - -import com.sun.hotspot.igv.data.InputGraph; -import com.sun.hotspot.igv.data.InputNode; -import com.sun.hotspot.igv.data.services.InputGraphProvider; -import java.util.Set; - -/** - * - * @author Thomas Wuerthinger - */ -public class EditorInputGraphProvider implements InputGraphProvider { - - private EditorTopComponent editor; - - public EditorInputGraphProvider(EditorTopComponent editor) { - this.editor = editor; - } - - @Override - public InputGraph getGraph() { - return editor.getDiagramModel().getGraphToView(); - } - - @Override - public void setSelectedNodes(Set nodes) { - editor.setSelectedNodes(nodes); - } -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorTopComponent.form --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorTopComponent.form Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorTopComponent.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorTopComponent.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,578 +0,0 @@ -/* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ -package com.sun.hotspot.igv.view; - -import com.sun.hotspot.igv.data.ChangedEvent; -import com.sun.hotspot.igv.data.ChangedListener; -import com.sun.hotspot.igv.data.InputNode; -import com.sun.hotspot.igv.data.Properties; -import com.sun.hotspot.igv.data.Properties.PropertyMatcher; -import com.sun.hotspot.igv.data.services.InputGraphProvider; -import com.sun.hotspot.igv.filter.FilterChain; -import com.sun.hotspot.igv.filter.FilterChainProvider; -import com.sun.hotspot.igv.graph.Diagram; -import com.sun.hotspot.igv.graph.Figure; -import com.sun.hotspot.igv.graph.services.DiagramProvider; -import com.sun.hotspot.igv.svg.BatikSVG; -import com.sun.hotspot.igv.util.LookupHistory; -import com.sun.hotspot.igv.util.RangeSlider; -import com.sun.hotspot.igv.view.actions.*; -import java.awt.*; -import java.awt.event.HierarchyBoundsListener; -import java.awt.event.HierarchyEvent; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.io.*; -import java.util.List; -import java.util.*; -import javax.swing.*; -import javax.swing.border.Border; -import org.openide.DialogDisplayer; -import org.openide.NotifyDescriptor; -import org.openide.actions.RedoAction; -import org.openide.actions.UndoAction; -import org.openide.awt.Toolbar; -import org.openide.awt.ToolbarPool; -import org.openide.awt.UndoRedo; -import org.openide.util.Lookup; -import org.openide.util.NbBundle; -import org.openide.util.Utilities; -import org.openide.util.actions.Presenter; -import org.openide.util.lookup.AbstractLookup; -import org.openide.util.lookup.InstanceContent; -import org.openide.util.lookup.ProxyLookup; -import org.openide.windows.Mode; -import org.openide.windows.TopComponent; -import org.openide.windows.WindowManager; - -/** - * - * @author Thomas Wuerthinger - */ -public final class EditorTopComponent extends TopComponent implements PropertyChangeListener { - - private DiagramViewer scene; - private InstanceContent content; - private InstanceContent graphContent; - private OverviewAction overviewAction; - private PredSuccAction predSuccAction; - private SelectionModeAction selectionModeAction; - private PanModeAction panModeAction; - private boolean notFirstTime; - private JComponent satelliteComponent; - private JPanel centerPanel; - private CardLayout cardLayout; - private RangeSlider rangeSlider; - private JToggleButton overviewButton; - private static final String PREFERRED_ID = "EditorTopComponent"; - private static final String SATELLITE_STRING = "satellite"; - private static final String SCENE_STRING = "scene"; - private DiagramViewModel rangeSliderModel; - private ExportCookie exportCookie = new ExportCookie() { - - @Override - public void export(File f) { - - Graphics2D svgGenerator = BatikSVG.createGraphicsObject(); - - if (svgGenerator == null) { - NotifyDescriptor message = new NotifyDescriptor.Message("For export to SVG files the Batik SVG Toolkit must be intalled.", NotifyDescriptor.ERROR_MESSAGE); - DialogDisplayer.getDefault().notifyLater(message); - } else { - scene.paint(svgGenerator); - FileOutputStream os = null; - try { - os = new FileOutputStream(f); - Writer out = new OutputStreamWriter(os, "UTF-8"); - BatikSVG.printToStream(svgGenerator, out, true); - } catch (FileNotFoundException e) { - NotifyDescriptor message = new NotifyDescriptor.Message("For export to SVG files the Batik SVG Toolkit must be intalled.", NotifyDescriptor.ERROR_MESSAGE); - DialogDisplayer.getDefault().notifyLater(message); - - } catch (UnsupportedEncodingException e) { - } finally { - if (os != null) { - try { - os.close(); - } catch (IOException e) { - } - } - } - - } - } - }; - - private DiagramProvider diagramProvider = new DiagramProvider() { - - @Override - public Diagram getDiagram() { - return getModel().getDiagramToView(); - } - - @Override - public ChangedEvent getChangedEvent() { - return diagramChangedEvent; - } - }; - - private ChangedEvent diagramChangedEvent = new ChangedEvent<>(diagramProvider); - - - private void updateDisplayName() { - setDisplayName(getDiagram().getName()); - } - - public EditorTopComponent(Diagram diagram) { - - LookupHistory.init(InputGraphProvider.class); - LookupHistory.init(DiagramProvider.class); - this.setFocusable(true); - FilterChain filterChain = null; - FilterChain sequence = null; - FilterChainProvider provider = Lookup.getDefault().lookup(FilterChainProvider.class); - if (provider == null) { - filterChain = new FilterChain(); - sequence = new FilterChain(); - } else { - filterChain = provider.getFilterChain(); - sequence = provider.getSequence(); - } - - setName(NbBundle.getMessage(EditorTopComponent.class, "CTL_EditorTopComponent")); - setToolTipText(NbBundle.getMessage(EditorTopComponent.class, "HINT_EditorTopComponent")); - - Action[] actions = new Action[]{ - PrevDiagramAction.get(PrevDiagramAction.class), - NextDiagramAction.get(NextDiagramAction.class), - null, - ExtractAction.get(ExtractAction.class), - ShowAllAction.get(HideAction.class), - ShowAllAction.get(ShowAllAction.class), - null, - ZoomInAction.get(ZoomInAction.class), - ZoomOutAction.get(ZoomOutAction.class), - null, - ExpandPredecessorsAction.get(ExpandPredecessorsAction.class), - ExpandSuccessorsAction.get(ExpandSuccessorsAction.class) - }; - - - initComponents(); - - ToolbarPool.getDefault().setPreferredIconSize(16); - Toolbar toolBar = new Toolbar(); - Border b = (Border) UIManager.get("Nb.Editor.Toolbar.border"); //NOI18N - toolBar.setBorder(b); - JPanel container = new JPanel(); - this.add(container, BorderLayout.NORTH); - container.setLayout(new BorderLayout()); - container.add(BorderLayout.NORTH, toolBar); - - rangeSliderModel = new DiagramViewModel(diagram.getGraph().getGroup(), filterChain, sequence); - rangeSlider = new RangeSlider(); - rangeSlider.setModel(rangeSliderModel); - container.add(BorderLayout.CENTER, rangeSlider); - - scene = new DiagramScene(actions, rangeSliderModel); - content = new InstanceContent(); - graphContent = new InstanceContent(); - this.associateLookup(new ProxyLookup(new Lookup[]{scene.getLookup(), new AbstractLookup(graphContent), new AbstractLookup(content)})); - content.add(exportCookie); - content.add(rangeSliderModel); - content.add(diagramProvider); - - rangeSliderModel.getDiagramChangedEvent().addListener(diagramChangedListener); - rangeSliderModel.selectGraph(diagram.getGraph()); - - toolBar.add(NextDiagramAction.get(NextDiagramAction.class)); - toolBar.add(PrevDiagramAction.get(PrevDiagramAction.class)); - toolBar.addSeparator(); - toolBar.add(ExtractAction.get(ExtractAction.class)); - toolBar.add(ShowAllAction.get(HideAction.class)); - toolBar.add(ShowAllAction.get(ShowAllAction.class)); - toolBar.addSeparator(); - toolBar.add(ShowAllAction.get(ZoomInAction.class)); - toolBar.add(ShowAllAction.get(ZoomOutAction.class)); - - overviewAction = new OverviewAction(); - overviewButton = new JToggleButton(overviewAction); - overviewButton.setSelected(false); - toolBar.add(overviewButton); - overviewAction.addPropertyChangeListener(this); - - predSuccAction = new PredSuccAction(); - JToggleButton button = new JToggleButton(predSuccAction); - button.setSelected(true); - toolBar.add(button); - predSuccAction.addPropertyChangeListener(this); - - toolBar.addSeparator(); - toolBar.add(UndoAction.get(UndoAction.class)); - toolBar.add(RedoAction.get(RedoAction.class)); - - toolBar.addSeparator(); - ButtonGroup interactionButtons = new ButtonGroup(); - - panModeAction = new PanModeAction(); - panModeAction.setSelected(true); - button = new JToggleButton(panModeAction); - button.setSelected(true); - interactionButtons.add(button); - toolBar.add(button); - panModeAction.addPropertyChangeListener(this); - - selectionModeAction = new SelectionModeAction(); - button = new JToggleButton(selectionModeAction); - interactionButtons.add(button); - toolBar.add(button); - selectionModeAction.addPropertyChangeListener(this); - - toolBar.add(Box.createHorizontalGlue()); - Action action = Utilities.actionsForPath("QuickSearchShadow").get(0); - Component quicksearch = ((Presenter.Toolbar) action).getToolbarPresenter(); - quicksearch.setMinimumSize(quicksearch.getPreferredSize()); // necessary for GTK LAF - toolBar.add(quicksearch); - - centerPanel = new JPanel(); - this.add(centerPanel, BorderLayout.CENTER); - cardLayout = new CardLayout(); - centerPanel.setLayout(cardLayout); - centerPanel.add(SCENE_STRING, scene.getComponent()); - centerPanel.setBackground(Color.WHITE); - satelliteComponent = scene.createSatelliteView(); - satelliteComponent.setSize(200, 200); - centerPanel.add(SATELLITE_STRING, satelliteComponent); - - // TODO: Fix the hot key for entering the satellite view - this.addKeyListener(keyListener); - - scene.getComponent().addHierarchyBoundsListener(new HierarchyBoundsListener() { - - @Override - public void ancestorMoved(HierarchyEvent e) { - } - - @Override - public void ancestorResized(HierarchyEvent e) { - if (!notFirstTime && scene.getComponent().getBounds().width > 0) { - notFirstTime = true; - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - EditorTopComponent.this.scene.initialize(); - } - }); - } - } - }); - - if (diagram.getGraph().getGroup().getGraphsCount() == 1) { - rangeSlider.setVisible(false); - } - - updateDisplayName(); - } - private KeyListener keyListener = new KeyListener() { - - @Override - public void keyTyped(KeyEvent e) { - } - - @Override - public void keyPressed(KeyEvent e) { - if (e.getKeyCode() == KeyEvent.VK_S) { - EditorTopComponent.this.overviewButton.setSelected(true); - EditorTopComponent.this.overviewAction.setState(true); - } - } - - @Override - public void keyReleased(KeyEvent e) { - if (e.getKeyCode() == KeyEvent.VK_S) { - EditorTopComponent.this.overviewButton.setSelected(false); - EditorTopComponent.this.overviewAction.setState(false); - } - } - }; - - public DiagramViewModel getDiagramModel() { - return rangeSliderModel; - } - - private void showSatellite() { - cardLayout.show(centerPanel, SATELLITE_STRING); - satelliteComponent.requestFocus(); - - } - - private void showScene() { - cardLayout.show(centerPanel, SCENE_STRING); - scene.getComponent().requestFocus(); - } - - public void zoomOut() { - scene.zoomOut(); - } - - public void zoomIn() { - scene.zoomIn(); - } - - public void showPrevDiagram() { - int fp = getModel().getFirstPosition(); - int sp = getModel().getSecondPosition(); - if (fp != 0) { - fp--; - sp--; - getModel().setPositions(fp, sp); - } - } - - public DiagramViewModel getModel() { - return rangeSliderModel; - } - - public FilterChain getFilterChain() { - return getModel().getFilterChain(); - } - - public static EditorTopComponent getActive() { - Set modes = WindowManager.getDefault().getModes(); - for (Mode m : modes) { - TopComponent tc = m.getSelectedTopComponent(); - if (tc instanceof EditorTopComponent) { - return (EditorTopComponent) tc; - } - } - return null; - } - - /** This method is called from within the constructor to - * initialize the form. - * WARNING: Do NOT modify this code. The content of this method is - * always regenerated by the Form Editor. - */ - // //GEN-BEGIN:initComponents - private void initComponents() { - jCheckBox1 = new javax.swing.JCheckBox(); - - org.openide.awt.Mnemonics.setLocalizedText(jCheckBox1, "jCheckBox1"); - jCheckBox1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); - jCheckBox1.setMargin(new java.awt.Insets(0, 0, 0, 0)); - - setLayout(new java.awt.BorderLayout()); - - }// //GEN-END:initComponents - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JCheckBox jCheckBox1; - // End of variables declaration//GEN-END:variables - - @Override - public int getPersistenceType() { - return TopComponent.PERSISTENCE_NEVER; - } - - @Override - public void componentOpened() { - } - - @Override - public void componentClosed() { - } - - @Override - protected String preferredID() { - return PREFERRED_ID; - } - - private ChangedListener diagramChangedListener = new ChangedListener() { - - @Override - public void changed(DiagramViewModel source) { - updateDisplayName(); - Collection list = new ArrayList<>(); - list.add(new EditorInputGraphProvider(EditorTopComponent.this)); - graphContent.set(list, null); - diagramProvider.getChangedEvent().fire(); - } - - }; - - public boolean showPredSucc() { - return (Boolean) predSuccAction.getValue(PredSuccAction.STATE); - } - - public void setSelection(PropertyMatcher matcher) { - - Properties.PropertySelector
selector = new Properties.PropertySelector<>(getModel().getDiagramToView().getFigures()); - List
list = selector.selectMultiple(matcher); - setSelectedFigures(list); - } - - public void setSelectedFigures(List
list) { - scene.setSelection(list); - scene.centerFigures(list); - } - - public void setSelectedNodes(Set nodes) { - - List
list = new ArrayList<>(); - Set ids = new HashSet<>(); - for (InputNode n : nodes) { - ids.add(n.getId()); - } - - for (Figure f : getModel().getDiagramToView().getFigures()) { - for (InputNode n : f.getSource().getSourceNodes()) { - if (ids.contains(n.getId())) { - list.add(f); - break; - } - } - } - - setSelectedFigures(list); - } - - @Override - public void propertyChange(PropertyChangeEvent evt) { - if (evt.getSource() == this.predSuccAction) { - boolean b = (Boolean) predSuccAction.getValue(PredSuccAction.STATE); - this.getModel().setShowNodeHull(b); - } else if (evt.getSource() == this.overviewAction) { - boolean b = (Boolean) overviewAction.getValue(OverviewAction.STATE); - if (b) { - showSatellite(); - } else { - showScene(); - } - } else if (evt.getSource() == this.selectionModeAction || evt.getSource() == this.panModeAction) { - if (panModeAction.isSelected()) { - scene.setInteractionMode(DiagramViewer.InteractionMode.PANNING); - } else if (selectionModeAction.isSelected()) { - scene.setInteractionMode(DiagramViewer.InteractionMode.SELECTION); - } - } else { - assert false : "Unknown event source"; - } - } - - public void extract() { - getModel().showOnly(getModel().getSelectedNodes()); - } - - public void hideNodes() { - Set selectedNodes = this.getModel().getSelectedNodes(); - HashSet nodes = new HashSet<>(getModel().getHiddenNodes()); - nodes.addAll(selectedNodes); - this.getModel().showNot(nodes); - } - - public void expandPredecessors() { - Set
oldSelection = getModel().getSelectedFigures(); - Set
figures = new HashSet<>(); - - for (Figure f : this.getDiagramModel().getDiagramToView().getFigures()) { - boolean ok = false; - if (oldSelection.contains(f)) { - ok = true; - } else { - for (Figure pred : f.getSuccessors()) { - if (oldSelection.contains(pred)) { - ok = true; - break; - } - } - } - - if (ok) { - figures.add(f); - } - } - - getModel().showAll(figures); - } - - public void expandSuccessors() { - Set
oldSelection = getModel().getSelectedFigures(); - Set
figures = new HashSet<>(); - - for (Figure f : this.getDiagramModel().getDiagramToView().getFigures()) { - boolean ok = false; - if (oldSelection.contains(f)) { - ok = true; - } else { - for (Figure succ : f.getPredecessors()) { - if (oldSelection.contains(succ)) { - ok = true; - break; - } - } - } - - if (ok) { - figures.add(f); - } - } - - getModel().showAll(figures); - } - - public void showAll() { - getModel().showNot(new HashSet()); - } - - public Diagram getDiagram() { - return getDiagramModel().getDiagramToView(); - } - - @Override - protected void componentHidden() { - super.componentHidden(); - scene.componentHidden(); - - } - - @Override - protected void componentShowing() { - super.componentShowing(); - scene.componentShowing(); - } - - @Override - public void requestActive() { - super.requestActive(); - scene.getComponent().requestFocus(); - } - - @Override - public UndoRedo getUndoRedo() { - return scene.getUndoRedo(); - } - -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/ExportCookie.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/ExportCookie.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -/* - * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.sun.hotspot.igv.view; - -import java.io.File; - -/** - * - * @author Thomas Wuerthinger - */ -public interface ExportCookie { - - void export(File f); -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/ExtendedSatelliteComponent.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/ExtendedSatelliteComponent.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,217 +0,0 @@ -/* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ -package com.sun.hotspot.igv.view; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.JComponent; -import org.netbeans.api.visual.widget.Scene; - -/** - * @author David Kaspar - * @author Thomas Wuerthinger - */ -public class ExtendedSatelliteComponent extends JComponent implements MouseListener, MouseMotionListener, Scene.SceneListener, ComponentListener { - - private DiagramScene scene; - private Image image; - private int imageWidth; - private int imageHeight; - - public ExtendedSatelliteComponent(DiagramScene scene) { - this.scene = scene; - setDoubleBuffered(true); - setPreferredSize(new Dimension(128, 128)); - addMouseListener(this); - addMouseMotionListener(this); - } - - @Override - public void addNotify() { - super.addNotify(); - scene.addSceneListener(this); - JComponent viewComponent = scene.getView(); - if (viewComponent == null) { - viewComponent = scene.createView(); - } - viewComponent.addComponentListener(this); - repaint(); - } - - @Override - public void removeNotify() { - scene.getView().removeComponentListener(this); - scene.removeSceneListener(this); - super.removeNotify(); - } - - public void update() { - this.image = null; - if (this.isVisible()) { - repaint(); - revalidate(); - validate(); - } - } - - @Override - public void paint(Graphics g) { - Graphics2D gr = (Graphics2D) g; - super.paint(g); - Rectangle bounds = scene.getBounds(); - Dimension size = getSize(); - - double sx = bounds.width > 0 ? (double) size.width / bounds.width : 0.0; - double sy = bounds.width > 0 ? (double) size.height / bounds.height : 0.0; - double scale = Math.min(sx, sy); - - int vw = (int) (scale * bounds.width); - int vh = (int) (scale * bounds.height); - int vx = (size.width - vw) / 2; - int vy = (size.height - vh) / 2; - - - if (image == null || vw != imageWidth || vh != imageHeight) { - - imageWidth = vw; - imageHeight = vh; - image = this.createImage(imageWidth, imageHeight); - Graphics2D ig = (Graphics2D) image.getGraphics(); - ig.scale(scale, scale); - double oldFactor = scene.getZoomFactor(); - scene.setZoomFactor(scale); - scene.paint(ig); - scene.setZoomFactor(oldFactor); - } - - gr.drawImage(image, vx, vy, this); - - JComponent component = scene.getView(); - double zoomFactor = scene.getZoomFactor(); - Rectangle viewRectangle = component != null ? component.getVisibleRect() : null; - if (viewRectangle != null) { - Rectangle window = new Rectangle( - (int) ((double) viewRectangle.x * scale / zoomFactor), - (int) ((double) viewRectangle.y * scale / zoomFactor), - (int) ((double) viewRectangle.width * scale / zoomFactor), - (int) ((double) viewRectangle.height * scale / zoomFactor)); - window.translate(vx, vy); - gr.setColor(new Color(200, 200, 200, 128)); - gr.fill(window); - gr.setColor(Color.BLACK); - gr.drawRect(window.x, window.y, window.width - 1, window.height - 1); - } - } - - @Override - public void mouseClicked(MouseEvent e) { - } - - @Override - public void mousePressed(MouseEvent e) { - moveVisibleRect(e.getPoint()); - } - - @Override - public void mouseReleased(MouseEvent e) { - moveVisibleRect(e.getPoint()); - } - - @Override - public void mouseEntered(MouseEvent e) { - } - - @Override - public void mouseExited(MouseEvent e) { - } - - @Override - public void mouseDragged(MouseEvent e) { - moveVisibleRect(e.getPoint()); - } - - @Override - public void mouseMoved(MouseEvent e) { - } - - private void moveVisibleRect(Point center) { - JComponent component = scene.getView(); - if (component == null) { - return; - } - double zoomFactor = scene.getZoomFactor(); - Rectangle bounds = scene.getBounds(); - Dimension size = getSize(); - - double sx = bounds.width > 0 ? (double) size.width / bounds.width : 0.0; - double sy = bounds.width > 0 ? (double) size.height / bounds.height : 0.0; - double scale = Math.min(sx, sy); - - int vw = (int) (scale * bounds.width); - int vh = (int) (scale * bounds.height); - int vx = (size.width - vw) / 2; - int vy = (size.height - vh) / 2; - - int cx = (int) ((double) (center.x - vx) / scale * zoomFactor); - int cy = (int) ((double) (center.y - vy) / scale * zoomFactor); - - Rectangle visibleRect = component.getVisibleRect(); - visibleRect.x = cx - visibleRect.width / 2; - visibleRect.y = cy - visibleRect.height / 2; - component.scrollRectToVisible(visibleRect); - - this.repaint(); - } - - @Override - public void sceneRepaint() { - //repaint (); - } - - @Override - public void sceneValidating() { - } - - @Override - public void sceneValidated() { - } - - @Override - public void componentResized(ComponentEvent e) { - repaint(); - } - - @Override - public void componentMoved(ComponentEvent e) { - repaint(); - } - - @Override - public void componentShown(ComponentEvent e) { - } - - @Override - public void componentHidden(ComponentEvent e) { - } -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/GraphViewerImplementation.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/GraphViewerImplementation.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ -package com.sun.hotspot.igv.view; - -import com.sun.hotspot.igv.data.InputGraph; -import com.sun.hotspot.igv.data.services.GraphViewer; -import com.sun.hotspot.igv.graph.Diagram; -import com.sun.hotspot.igv.settings.Settings; - -/** - * - * @author Thomas Wuerthinger - */ -public class GraphViewerImplementation implements GraphViewer { - - @Override - public void view(InputGraph graph) { - Diagram diagram = Diagram.createDiagram(graph, Settings.get().get(Settings.NODE_TEXT, Settings.NODE_TEXT_DEFAULT)); - EditorTopComponent tc = new EditorTopComponent(diagram); - tc.open(); - tc.requestActive(); - } -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/NodeQuickSearch.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/NodeQuickSearch.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,142 +0,0 @@ -/* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ -package com.sun.hotspot.igv.view; - -import com.sun.hotspot.igv.data.InputNode; -import com.sun.hotspot.igv.data.Properties; -import com.sun.hotspot.igv.data.Properties.RegexpPropertyMatcher; -import com.sun.hotspot.igv.data.services.InputGraphProvider; -import com.sun.hotspot.igv.util.LookupHistory; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.regex.Pattern; -import org.netbeans.spi.quicksearch.SearchProvider; -import org.netbeans.spi.quicksearch.SearchRequest; -import org.netbeans.spi.quicksearch.SearchResponse; -import org.openide.DialogDisplayer; -import org.openide.NotifyDescriptor; -import org.openide.NotifyDescriptor.Message; - -/** - * - * @author Thomas Wuerthinger - */ -public class NodeQuickSearch implements SearchProvider { - - private static final String DEFAULT_PROPERTY = "name"; - - /** - * Method is called by infrastructure when search operation was requested. - * Implementors should evaluate given request and fill response object with - * apropriate results - * - * @param request Search request object that contains information what to search for - * @param response Search response object that stores search results. Note that it's important to react to return value of SearchResponse.addResult(...) method and stop computation if false value is returned. - */ - @Override - public void evaluate(SearchRequest request, SearchResponse response) { - String query = request.getText(); - if (query.trim().isEmpty()) { - return; - } - - final String[] parts = query.split("=", 2); - - String name; - String value; - - if (parts.length == 1) { - name = DEFAULT_PROPERTY; - value = ".*" + Pattern.quote(parts[0]) + ".*"; - } else { - name = parts[0]; - value = parts[1]; - } - - if (value.isEmpty()) { - value = ".*"; - } - - final InputGraphProvider p = LookupHistory.getLast(InputGraphProvider.class); - if (p != null && p.getGraph() != null) { - List matches = null; - try { - RegexpPropertyMatcher matcher = new RegexpPropertyMatcher(name, value, Pattern.CASE_INSENSITIVE); - Properties.PropertySelector selector = new Properties.PropertySelector<>(p.getGraph().getNodes()); - - matches = selector.selectMultiple(matcher); - } catch (Exception e) { - final String msg = e.getMessage(); - response.addResult(new Runnable() { - @Override - public void run() { - Message desc = new NotifyDescriptor.Message("An exception occurred during the search, " - + "perhaps due to a malformed query string:\n" + msg, - NotifyDescriptor.WARNING_MESSAGE); - DialogDisplayer.getDefault().notify(desc); - } - }, - "(Error during search)" - ); - } - - if (matches != null) { - final Set set = new HashSet<>(matches); - response.addResult(new Runnable() { - @Override - public void run() { - final EditorTopComponent comp = EditorTopComponent.getActive(); - if (comp != null) { - comp.setSelectedNodes(set); - comp.requestActive(); - } - } - }, - "All " + matches.size() + " matching nodes (" + name + "=" + value + ")" - ); - - // Single matches - for (final InputNode n : matches) { - response.addResult(new Runnable() { - @Override - public void run() { - final EditorTopComponent comp = EditorTopComponent.getActive(); - if (comp != null) { - final Set tmpSet = new HashSet<>(); - tmpSet.add(n); - comp.setSelectedNodes(tmpSet); - comp.requestActive(); - } - } - }, - n.getProperties().get(name) + " (" + n.getId() + " " + n.getProperties().get("name") + ")" - ); - } - } - } else { - System.out.println("no input graph provider!"); - } - } -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/Bundle.properties --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/Bundle.properties Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/Bundle.properties Tue Feb 07 21:09:31 2012 +0100 @@ -1,6 +1,4 @@ CTL_EditorAction=Open Editor Window -CTL_NextDiagramAction=Show next graph CTL_EnableBlockLayoutAction=Enable block layout CTL_NodeFindAction=Find -CTL_PrevDiagramAction=Show previous graph CTL_ExportAction=Export current graph... diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/CustomizablePanAction.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/CustomizablePanAction.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,146 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package com.sun.hotspot.igv.view.actions; - -import java.awt.Container; -import java.awt.Point; -import java.awt.Rectangle; -import javax.swing.JComponent; -import javax.swing.JScrollPane; -import javax.swing.SwingUtilities; -import org.netbeans.api.visual.action.WidgetAction; -import org.netbeans.api.visual.action.WidgetAction.State; -import org.netbeans.api.visual.action.WidgetAction.WidgetMouseEvent; -import org.netbeans.api.visual.widget.Scene; -import org.netbeans.api.visual.widget.Widget; - -/** - * @author David Kaspar - * @author Peter Hofer - */ -public class CustomizablePanAction extends WidgetAction.LockedAdapter { - private boolean enabled = true; - - private Scene scene; - private JScrollPane scrollPane; - private Point lastLocation; - - private final int modifiersExMask; - private final int modifiersEx; - - public CustomizablePanAction(int modifiersExMask, int modifiersEx) { - this.modifiersExMask = modifiersExMask; - this.modifiersEx = modifiersEx; - } - - @Override - protected boolean isLocked() { - return scrollPane != null; - } - - public void setEnabled(boolean enabled) { - if (this.enabled != enabled) { - if (isLocked()) - throw new IllegalStateException(); - - this.enabled = enabled; - } - } - - @Override - public State mousePressed (Widget widget, WidgetMouseEvent event) { - if (isLocked ()) - return State.createLocked (widget, this); - if (enabled && (event.getModifiersEx() & modifiersExMask) == modifiersEx) { - scene = widget.getScene (); - scrollPane = findScrollPane (scene.getView ()); - if (scrollPane != null) { - lastLocation = scene.convertSceneToView (widget.convertLocalToScene (event.getPoint ())); - SwingUtilities.convertPointToScreen (lastLocation, scene.getView ()); - return State.createLocked (widget, this); - } - } - return State.REJECTED; - } - - private JScrollPane findScrollPane (JComponent component) { - for (;;) { - if (component == null) - return null; - if (component instanceof JScrollPane) - return ((JScrollPane) component); - Container parent = component.getParent (); - if (! (parent instanceof JComponent)) - return null; - component = (JComponent) parent; - } - } - - @Override - public State mouseReleased (Widget widget, WidgetMouseEvent event) { - boolean state = pan (widget, event.getPoint ()); - if (state) - scrollPane = null; - return state ? State.createLocked (widget, this) : State.REJECTED; - } - - @Override - public State mouseDragged (Widget widget, WidgetMouseEvent event) { - return pan (widget, event.getPoint ()) ? State.createLocked (widget, this) : State.REJECTED; - } - - private boolean pan (Widget widget, Point newLocation) { - if (scrollPane == null || scene != widget.getScene ()) - return false; - newLocation = scene.convertSceneToView (widget.convertLocalToScene (newLocation)); - SwingUtilities.convertPointToScreen (newLocation, scene.getView ()); - JComponent view = scene.getView (); - Rectangle rectangle = view.getVisibleRect (); - rectangle.x += lastLocation.x - newLocation.x; - rectangle.y += lastLocation.y - newLocation.y; - view.scrollRectToVisible (rectangle); - lastLocation = newLocation; - return true; - } -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExpandPredecessorsAction.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExpandPredecessorsAction.java Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExpandPredecessorsAction.java Tue Feb 07 21:09:31 2012 +0100 @@ -23,7 +23,7 @@ */ package com.sun.hotspot.igv.view.actions; -import com.sun.hotspot.igv.view.EditorTopComponent; +import com.oracle.graal.visualizer.editor.EditorTopComponent; import org.openide.util.HelpCtx; import org.openide.util.actions.CallableSystemAction; @@ -37,7 +37,7 @@ public void performAction() { EditorTopComponent editor = EditorTopComponent.getActive(); if (editor != null) { - editor.expandPredecessors(); + //editor.expandPredecessors(); } } diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExpandSuccessorsAction.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExpandSuccessorsAction.java Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExpandSuccessorsAction.java Tue Feb 07 21:09:31 2012 +0100 @@ -23,7 +23,7 @@ */ package com.sun.hotspot.igv.view.actions; -import com.sun.hotspot.igv.view.EditorTopComponent; +import com.oracle.graal.visualizer.editor.EditorTopComponent; import org.openide.util.HelpCtx; import org.openide.util.actions.CallableSystemAction; @@ -37,7 +37,7 @@ public void performAction() { EditorTopComponent editor = EditorTopComponent.getActive(); if (editor != null) { - editor.expandSuccessors(); + //editor.expandSuccessors(); } } diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExportAction.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExportAction.java Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExportAction.java Tue Feb 07 21:09:31 2012 +0100 @@ -24,7 +24,7 @@ package com.sun.hotspot.igv.view.actions; import com.sun.hotspot.igv.settings.Settings; -import com.sun.hotspot.igv.view.ExportCookie; +import com.oracle.graal.visualizer.editor.ExportCookie; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; import java.io.File; diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExtractAction.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExtractAction.java Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExtractAction.java Tue Feb 07 21:09:31 2012 +0100 @@ -23,11 +23,14 @@ */ package com.sun.hotspot.igv.view.actions; -import com.sun.hotspot.igv.view.EditorTopComponent; +import com.oracle.graal.visualizer.editor.EditorTopComponent; import java.awt.Event; import java.awt.event.KeyEvent; import javax.swing.Action; import javax.swing.KeyStroke; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionRegistration; import org.openide.util.HelpCtx; import org.openide.util.actions.CallableSystemAction; @@ -35,13 +38,16 @@ * * @author Thomas Wuerthinger */ +@ActionID(id = "com.sun.hotspot.igv.view.actions.ExtractAction", category = "View") +@ActionRegistration(displayName = "Extract nodes") +@ActionReference(path = "Menu/View", position = 300) public final class ExtractAction extends CallableSystemAction { @Override public void performAction() { EditorTopComponent editor = EditorTopComponent.getActive(); if (editor != null) { - editor.extract(); + //editor.extract(); } } diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/HideAction.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/HideAction.java Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/HideAction.java Tue Feb 07 21:09:31 2012 +0100 @@ -23,11 +23,14 @@ */ package com.sun.hotspot.igv.view.actions; -import com.sun.hotspot.igv.view.EditorTopComponent; +import com.oracle.graal.visualizer.editor.EditorTopComponent; import java.awt.Event; import java.awt.event.KeyEvent; import javax.swing.Action; import javax.swing.KeyStroke; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionRegistration; import org.openide.util.HelpCtx; import org.openide.util.actions.CallableSystemAction; @@ -35,13 +38,16 @@ * * @author Thomas Wuerthinger */ +@ActionID(id = "com.sun.hotspot.igv.view.actions.HideAction", category = "View") +@ActionRegistration(displayName = "Hide nodes") +@ActionReference(path = "Menu/View", position = 400) public final class HideAction extends CallableSystemAction { @Override public void performAction() { EditorTopComponent editor = EditorTopComponent.getActive(); if (editor != null) { - editor.hideNodes(); + //editor.hideNodes(); } } diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/NextDiagramAction.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/NextDiagramAction.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ -package com.sun.hotspot.igv.view.actions; - -import com.sun.hotspot.igv.data.ChangedListener; -import com.sun.hotspot.igv.util.ContextAction; -import com.sun.hotspot.igv.view.DiagramViewModel; -import javax.swing.Action; -import javax.swing.ImageIcon; -import org.openide.util.*; - -/** - * - * @author Thomas Wuerthinger - */ -public final class NextDiagramAction extends ContextAction implements ChangedListener { - - private DiagramViewModel model; - - public NextDiagramAction() { - this(Utilities.actionsGlobalContext()); - } - - public NextDiagramAction(Lookup lookup) { - putValue(Action.SHORT_DESCRIPTION, "Show next graph of current group"); - putValue(Action.SMALL_ICON, new ImageIcon(ImageUtilities.loadImage("com/sun/hotspot/igv/view/images/next_diagram.png"))); - } - - @Override - public String getName() { - return NbBundle.getMessage(NextDiagramAction.class, "CTL_NextDiagramAction"); - } - - @Override - public HelpCtx getHelpCtx() { - return HelpCtx.DEFAULT_HELP; - } - - @Override - public Class contextClass() { - return DiagramViewModel.class; - } - - @Override - public void performAction(DiagramViewModel model) { - int fp = model.getFirstPosition(); - int sp = model.getSecondPosition(); - if (sp != model.getPositions().size() - 1) { - int nfp = fp + 1; - int nsp = sp + 1; - model.setPositions(nfp, nsp); - } - } - - @Override - public void update(DiagramViewModel model) { - super.update(model); - - if (this.model != model) { - if (this.model != null) { - this.model.getDiagramChangedEvent().removeListener(this); - } - - this.model = model; - if (this.model != null) { - this.model.getDiagramChangedEvent().addListener(this); - } - } - } - - @Override - public boolean isEnabled(DiagramViewModel model) { - return model.getSecondPosition() != model.getPositions().size() - 1; - } - - @Override - public Action createContextAwareInstance(Lookup arg0) { - return new NextDiagramAction(arg0); - } - - @Override - public void changed(DiagramViewModel source) { - update(source); - } -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/OverviewAction.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/OverviewAction.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ -package com.sun.hotspot.igv.view.actions; - -import java.awt.event.ActionEvent; -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ImageIcon; -import org.openide.util.ImageUtilities; - -/** - * - * @author Thomas Wuerthinger - */ -public class OverviewAction extends AbstractAction { - - private boolean state; - public static final String STATE = "state"; - - public OverviewAction() { - putValue(AbstractAction.SMALL_ICON, new ImageIcon(ImageUtilities.loadImage(iconResource()))); - putValue(Action.SHORT_DESCRIPTION, "Show satellite view of whole graph"); - setState(false); - } - - @Override - public void actionPerformed(ActionEvent ev) { - setState(!state); - } - - public void setState(boolean b) { - this.putValue(STATE, b); - this.state = b; - } - - protected String iconResource() { - return "com/sun/hotspot/igv/view/images/overview.png"; - } -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/PanModeAction.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/PanModeAction.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ -package com.sun.hotspot.igv.view.actions; - -import java.awt.event.ActionEvent; -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ImageIcon; -import org.openide.util.ImageUtilities; - -public class PanModeAction extends AbstractAction { - - private boolean state; - - public PanModeAction() { - putValue(AbstractAction.SMALL_ICON, new ImageIcon(ImageUtilities.loadImage(iconResource()))); - putValue(SELECTED_KEY, false); - putValue(Action.SHORT_DESCRIPTION, "Panning mode"); - } - - public boolean isSelected() { - return (Boolean)getValue(SELECTED_KEY); - } - - public void setSelected(boolean b) { - if (isSelected() != b) { - this.putValue(SELECTED_KEY, b); - } - } - - protected String iconResource() { - return "com/sun/hotspot/igv/view/images/pan_mode.png"; - } - - @Override - public void actionPerformed(ActionEvent e) { - } -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/PrevDiagramAction.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/PrevDiagramAction.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ -package com.sun.hotspot.igv.view.actions; - -import com.sun.hotspot.igv.data.ChangedListener; -import com.sun.hotspot.igv.util.ContextAction; -import com.sun.hotspot.igv.view.DiagramViewModel; -import javax.swing.Action; -import javax.swing.ImageIcon; -import org.openide.util.*; - -/** - * - * @author Thomas Wuerthinger - */ -public final class PrevDiagramAction extends ContextAction implements ChangedListener { - - private DiagramViewModel model; - - public PrevDiagramAction() { - this(Utilities.actionsGlobalContext()); - } - - public PrevDiagramAction(Lookup lookup) { - putValue(Action.SHORT_DESCRIPTION, "Show previous graph of current group"); - putValue(Action.SMALL_ICON, new ImageIcon(ImageUtilities.loadImage("com/sun/hotspot/igv/view/images/prev_diagram.png"))); - } - - @Override - public String getName() { - return NbBundle.getMessage(PrevDiagramAction.class, "CTL_PrevDiagramAction"); - } - - @Override - public HelpCtx getHelpCtx() { - return HelpCtx.DEFAULT_HELP; - } - - @Override - public Class contextClass() { - return DiagramViewModel.class; - } - - @Override - public void performAction(DiagramViewModel model) { - int fp = model.getFirstPosition(); - int sp = model.getSecondPosition(); - if (fp != 0) { - int nfp = fp - 1; - int nsp = sp - 1; - model.setPositions(nfp, nsp); - } - } - - @Override - public void update(DiagramViewModel model) { - super.update(model); - - if (this.model != model) { - if (this.model != null) { - this.model.getDiagramChangedEvent().removeListener(this); - } - - this.model = model; - if (this.model != null) { - this.model.getDiagramChangedEvent().addListener(this); - } - } - } - - @Override - public boolean isEnabled(DiagramViewModel model) { - return model.getFirstPosition() != 0; - } - - @Override - public Action createContextAwareInstance(Lookup arg0) { - return new PrevDiagramAction(arg0); - } - - @Override - public void changed(DiagramViewModel source) { - update(source); - } -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/SelectionModeAction.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/SelectionModeAction.java Tue Feb 07 19:41:28 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ -package com.sun.hotspot.igv.view.actions; - -import java.awt.event.ActionEvent; -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ImageIcon; -import org.openide.util.ImageUtilities; - -public class SelectionModeAction extends AbstractAction { - - public SelectionModeAction() { - putValue(AbstractAction.SMALL_ICON, new ImageIcon(ImageUtilities.loadImage(iconResource()))); - putValue(SELECTED_KEY, false); - putValue(Action.SHORT_DESCRIPTION, "Selection mode"); - } - - public boolean isSelected() { - return (Boolean)getValue(SELECTED_KEY); - } - - public void setSelected(boolean b) { - if (isSelected() != b) { - this.putValue(SELECTED_KEY, b); - } - } - - protected String iconResource() { - return "com/sun/hotspot/igv/view/images/selection_mode.png"; - } - - @Override - public void actionPerformed(ActionEvent e) { - } -} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ShowAllAction.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ShowAllAction.java Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ShowAllAction.java Tue Feb 07 21:09:31 2012 +0100 @@ -23,11 +23,14 @@ */ package com.sun.hotspot.igv.view.actions; -import com.sun.hotspot.igv.view.EditorTopComponent; +import com.oracle.graal.visualizer.editor.EditorTopComponent; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; import javax.swing.Action; import javax.swing.KeyStroke; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionRegistration; import org.openide.util.HelpCtx; import org.openide.util.actions.CallableSystemAction; @@ -35,13 +38,16 @@ * * @author Thomas Wuerthinger */ +@ActionID(id = "com.sun.hotspot.igv.view.actions.ShowAllAction", category = "View") +@ActionRegistration(displayName = "Show all nodes") +@ActionReference(path = "Menu/View", position = 200) public final class ShowAllAction extends CallableSystemAction { @Override public void performAction() { EditorTopComponent editor = EditorTopComponent.getActive(); if (editor != null) { - editor.showAll(); + //editor.showAll(); } } diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ZoomInAction.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ZoomInAction.java Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ZoomInAction.java Tue Feb 07 21:09:31 2012 +0100 @@ -23,11 +23,16 @@ */ package com.sun.hotspot.igv.view.actions; -import com.sun.hotspot.igv.view.EditorTopComponent; +import com.oracle.graal.visualizer.editor.EditorTopComponent; +import com.sun.hotspot.igv.view.scene.DiagramScene; +import com.sun.hotspot.igv.view.scene.GraphCompilationViewer; import java.awt.Event; import java.awt.event.KeyEvent; import javax.swing.Action; import javax.swing.KeyStroke; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionRegistration; import org.openide.util.HelpCtx; import org.openide.util.actions.CallableSystemAction; @@ -36,13 +41,11 @@ * @author Thomas Wuerthinger */ public final class ZoomInAction extends CallableSystemAction { + private final DiagramScene scene; @Override public void performAction() { - EditorTopComponent editor = EditorTopComponent.getActive(); - if (editor != null) { - editor.zoomIn(); - } + scene.zoomIn(); } @Override @@ -50,7 +53,8 @@ return "Zoom in"; } - public ZoomInAction() { + public ZoomInAction(DiagramScene scene) { + this.scene = scene; putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, Event.CTRL_MASK, false)); putValue(Action.SHORT_DESCRIPTION, "Zoom in"); } diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ZoomOutAction.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ZoomOutAction.java Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ZoomOutAction.java Tue Feb 07 21:09:31 2012 +0100 @@ -23,11 +23,16 @@ */ package com.sun.hotspot.igv.view.actions; -import com.sun.hotspot.igv.view.EditorTopComponent; +import com.oracle.graal.visualizer.editor.EditorTopComponent; +import com.sun.hotspot.igv.view.scene.DiagramScene; +import com.sun.hotspot.igv.view.scene.GraphCompilationViewer; import java.awt.Event; import java.awt.event.KeyEvent; import javax.swing.Action; import javax.swing.KeyStroke; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionRegistration; import org.openide.util.HelpCtx; import org.openide.util.actions.CallableSystemAction; @@ -36,17 +41,15 @@ * @author Thomas Wuerthinger */ public final class ZoomOutAction extends CallableSystemAction { + private final DiagramScene scene; @Override public void performAction() { - EditorTopComponent editor = EditorTopComponent.getActive(); - if (editor != null) { - editor.zoomOut(); - } + scene.zoomOut(); } - public ZoomOutAction() { - + public ZoomOutAction(DiagramScene scene) { + this.scene = scene; putValue(Action.SHORT_DESCRIPTION, "Zoom out"); putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, Event.CTRL_MASK, false)); } diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/next_diagram.png Binary file src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/next_diagram.png has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/prev_diagram.png Binary file src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/prev_diagram.png has changed diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/layer.xml --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/layer.xml Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/layer.xml Tue Feb 07 21:09:31 2012 +0100 @@ -1,80 +1,4 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/scene/CustomizablePanWidgetAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/scene/CustomizablePanWidgetAction.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,146 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package com.sun.hotspot.igv.view.scene; + +import java.awt.Container; +import java.awt.Point; +import java.awt.Rectangle; +import javax.swing.JComponent; +import javax.swing.JScrollPane; +import javax.swing.SwingUtilities; +import org.netbeans.api.visual.action.WidgetAction; +import org.netbeans.api.visual.action.WidgetAction.State; +import org.netbeans.api.visual.action.WidgetAction.WidgetMouseEvent; +import org.netbeans.api.visual.widget.Scene; +import org.netbeans.api.visual.widget.Widget; + +/** + * @author David Kaspar + * @author Peter Hofer + */ +public class CustomizablePanWidgetAction extends WidgetAction.LockedAdapter { + private boolean enabled = true; + + private Scene scene; + private JScrollPane scrollPane; + private Point lastLocation; + + private final int modifiersExMask; + private final int modifiersEx; + + public CustomizablePanWidgetAction(int modifiersExMask, int modifiersEx) { + this.modifiersExMask = modifiersExMask; + this.modifiersEx = modifiersEx; + } + + @Override + protected boolean isLocked() { + return scrollPane != null; + } + + public void setEnabled(boolean enabled) { + if (this.enabled != enabled) { + if (isLocked()) + throw new IllegalStateException(); + + this.enabled = enabled; + } + } + + @Override + public State mousePressed (Widget widget, WidgetMouseEvent event) { + if (isLocked ()) + return State.createLocked (widget, this); + if (enabled && (event.getModifiersEx() & modifiersExMask) == modifiersEx) { + scene = widget.getScene (); + scrollPane = findScrollPane (scene.getView ()); + if (scrollPane != null) { + lastLocation = scene.convertSceneToView (widget.convertLocalToScene (event.getPoint ())); + SwingUtilities.convertPointToScreen (lastLocation, scene.getView ()); + return State.createLocked (widget, this); + } + } + return State.REJECTED; + } + + private JScrollPane findScrollPane (JComponent component) { + for (;;) { + if (component == null) + return null; + if (component instanceof JScrollPane) + return ((JScrollPane) component); + Container parent = component.getParent (); + if (! (parent instanceof JComponent)) + return null; + component = (JComponent) parent; + } + } + + @Override + public State mouseReleased (Widget widget, WidgetMouseEvent event) { + boolean state = pan (widget, event.getPoint ()); + if (state) + scrollPane = null; + return state ? State.createLocked (widget, this) : State.REJECTED; + } + + @Override + public State mouseDragged (Widget widget, WidgetMouseEvent event) { + return pan (widget, event.getPoint ()) ? State.createLocked (widget, this) : State.REJECTED; + } + + private boolean pan (Widget widget, Point newLocation) { + if (scrollPane == null || scene != widget.getScene ()) + return false; + newLocation = scene.convertSceneToView (widget.convertLocalToScene (newLocation)); + SwingUtilities.convertPointToScreen (newLocation, scene.getView ()); + JComponent view = scene.getView (); + Rectangle rectangle = view.getVisibleRect (); + rectangle.x += lastLocation.x - newLocation.x; + rectangle.y += lastLocation.y - newLocation.y; + view.scrollRectToVisible (rectangle); + lastLocation = newLocation; + return true; + } +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/scene/DiagramScene.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/scene/DiagramScene.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,986 @@ +/* + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ +package com.sun.hotspot.igv.view.scene; + +import com.oracle.graal.visualizer.editor.DiagramViewModel; +import com.sun.hotspot.igv.data.ChangedListener; +import com.sun.hotspot.igv.data.ControllableChangedListener; +import com.sun.hotspot.igv.data.Pair; +import com.sun.hotspot.igv.data.Properties; +import com.sun.hotspot.igv.graph.*; +import com.sun.hotspot.igv.hierarchicallayout.HierarchicalLayoutManager; +import com.sun.hotspot.igv.layout.LayoutGraph; +import com.sun.hotspot.igv.util.ColorIcon; +import com.sun.hotspot.igv.util.DoubleClickAction; +import com.sun.hotspot.igv.util.PropertiesSheet; +import com.sun.hotspot.igv.view.widgets.*; +import java.awt.*; +import java.awt.event.*; +import java.util.List; +import java.util.*; +import javax.swing.*; +import org.netbeans.api.visual.action.*; +import org.netbeans.api.visual.animator.SceneAnimator; +import org.netbeans.api.visual.layout.LayoutFactory; +import org.netbeans.api.visual.model.*; +import org.netbeans.api.visual.widget.LayerWidget; +import org.netbeans.api.visual.widget.Widget; +import org.openide.awt.UndoRedo; +import org.openide.nodes.AbstractNode; +import org.openide.nodes.Children; +import org.openide.nodes.Sheet; +import org.openide.util.Lookup; +import org.openide.util.lookup.AbstractLookup; +import org.openide.util.lookup.InstanceContent; + +/** + * + * @author Thomas Wuerthinger + */ +public class DiagramScene extends ObjectScene { + + private CustomizablePanWidgetAction panAction; + private WidgetAction hoverAction; + private WidgetAction selectAction; + private Lookup lookup; + private InstanceContent content; + private Action[] actions; + private LayerWidget connectionLayer; + private JScrollPane scrollPane; + private LayerWidget mainLayer; + private LayerWidget blockLayer; + private Widget topLeft; + private Widget bottomRight; + private DiagramViewModel model; + private WidgetAction zoomAction; + private boolean rebuilding; + /** + * The alpha level of partially visible figures. + */ + public static final float ALPHA = 0.4f; + /** + * The offset of the graph to the border of the window showing it. + */ + public static final int BORDER_SIZE = 20; + public static final int UNDOREDO_LIMIT = 100; + public static final int SCROLL_UNIT_INCREMENT = 80; + public static final int SCROLL_BLOCK_INCREMENT = 400; + public static final float ZOOM_MAX_FACTOR = 3.0f; + public static final float ZOOM_MIN_FACTOR = 0.0f;//0.15f; + public static final float ZOOM_INCREMENT = 1.5f; + public static final int SLOT_OFFSET = 6; + public static final int ANIMATION_LIMIT = 40; + private PopupMenuProvider popupMenuProvider = new PopupMenuProvider() { + + @Override + public JPopupMenu getPopupMenu(Widget widget, Point localLocation) { + return DiagramScene.this.createPopupMenu(); + } + }; + private RectangularSelectDecorator rectangularSelectDecorator = new RectangularSelectDecorator() { + + @Override + public Widget createSelectionWidget() { + Widget widget = new Widget(DiagramScene.this); + widget.setBorder(BorderFactory.createLineBorder(Color.black, 2)); + widget.setForeground(Color.red); + return widget; + } + }; + + @SuppressWarnings("unchecked") + public T getWidget(Object o) { + Widget w = this.findWidget(o); + return (T) w; + } + + @SuppressWarnings("unchecked") + public T getWidget(Object o, Class klass) { + Widget w = this.findWidget(o); + return (T) w; + } + + private static boolean intersects(Set s1, Set s2) { + for (Object o : s1) { + if (s2.contains(o)) { + return true; + } + } + return false; + } + + public void zoomOut() { + double zoom = getZoomFactor(); + Point viewPosition = getScrollPane().getViewport().getViewPosition(); + double newZoom = zoom / DiagramScene.ZOOM_INCREMENT; + if (newZoom > DiagramScene.ZOOM_MIN_FACTOR) { + setZoomFactor(newZoom); + validate(); + getScrollPane().getViewport().setViewPosition(new Point((int) (viewPosition.x / DiagramScene.ZOOM_INCREMENT), (int) (viewPosition.y / DiagramScene.ZOOM_INCREMENT))); + } + } + + public void zoomIn() { + + double zoom = getZoomFactor(); + Point viewPosition = getScrollPane().getViewport().getViewPosition(); + double newZoom = zoom * DiagramScene.ZOOM_INCREMENT; + if (newZoom < DiagramScene.ZOOM_MAX_FACTOR) { + setZoomFactor(newZoom); + validate(); + getScrollPane().getViewport().setViewPosition(new Point((int) (viewPosition.x * DiagramScene.ZOOM_INCREMENT), (int) (viewPosition.y * DiagramScene.ZOOM_INCREMENT))); + } + } + + private void centerFigures(Collection
list) { + gotoFigures(list); + } + + private Set getObjectsFromIdSet(Set set) { + Set selectedObjects = new HashSet<>(); + for (Figure f : getModel().getDiagramToView().getFigures()) { + if (intersects(f.getSource().getSourceNodesAsSet(), set)) { + selectedObjects.add(f); + } + + for (Slot s : f.getSlots()) { + if (intersects(s.getSource().getSourceNodesAsSet(), set)) { + selectedObjects.add(s); + } + } + } + return selectedObjects; + } + private RectangularSelectProvider rectangularSelectProvider = new RectangularSelectProvider() { + + @Override + public void performSelection(Rectangle rectangle) { + if (rectangle.width < 0) { + rectangle.x += rectangle.width; + rectangle.width *= -1; + } + + if (rectangle.height < 0) { + rectangle.y += rectangle.height; + rectangle.height *= -1; + } + + Set selectedObjects = new HashSet<>(); + for (Figure f : getModel().getDiagramToView().getFigures()) { + FigureWidget w = getWidget(f); + if (w != null) { + Rectangle r = new Rectangle(w.getBounds()); + r.setLocation(w.getLocation()); + + if (r.intersects(rectangle)) { + selectedObjects.add(f); + } + + for (Slot s : f.getSlots()) { + SlotWidget sw = getWidget(s); + Rectangle r2 = new Rectangle(sw.getBounds()); + r2.setLocation(sw.convertLocalToScene(new Point(0, 0))); + + if (r2.intersects(rectangle)) { + selectedObjects.add(s); + } + } + } else { + assert false : "w should not be null here!"; + } + } + + setSelectedObjects(selectedObjects); + } + }; + private MouseWheelListener mouseWheelListener = new MouseWheelListener() { + + @Override + public void mouseWheelMoved(MouseWheelEvent e) { + if (e.isControlDown()) { + DiagramScene.this.relayoutWithoutLayout(null); + } + } + }; + + public Point getScrollPosition() { + return getScrollPane().getViewport().getViewPosition(); + } + + public void setScrollPosition(Point p) { + getScrollPane().getViewport().setViewPosition(p); + } + + private JScrollPane createScrollPane() { + JComponent comp = this.createView(); + comp.setDoubleBuffered(true); + comp.setBackground(Color.WHITE); + comp.setOpaque(true); + this.setBackground(Color.WHITE); + this.setOpaque(true); + JScrollPane result = new JScrollPane(comp); + result.setBackground(Color.WHITE); + result.getVerticalScrollBar().setUnitIncrement(SCROLL_UNIT_INCREMENT); + result.getVerticalScrollBar().setBlockIncrement(SCROLL_BLOCK_INCREMENT); + result.getHorizontalScrollBar().setUnitIncrement(SCROLL_UNIT_INCREMENT); + result.getHorizontalScrollBar().setBlockIncrement(SCROLL_BLOCK_INCREMENT); + return result; + } + private ObjectSceneListener selectionChangedListener = new ObjectSceneListener() { + + @Override + public void objectAdded(ObjectSceneEvent arg0, Object arg1) { + } + + @Override + public void objectRemoved(ObjectSceneEvent arg0, Object arg1) { + } + + @Override + public void objectStateChanged(ObjectSceneEvent e, Object o, ObjectState oldState, ObjectState newState) { + } + + @Override + public void selectionChanged(ObjectSceneEvent e, Set oldSet, Set newSet) { + DiagramScene scene = (DiagramScene) e.getObjectScene(); + if (scene.isRebuilding()) { + return; + } + + content.set(newSet, null); + + Set nodeSelection = new HashSet<>(); + for (Object o : newSet) { + if (o instanceof Properties.Provider) { + final Properties.Provider provider = (Properties.Provider) o; + AbstractNode node = new AbstractNode(Children.LEAF) { + + @Override + protected Sheet createSheet() { + Sheet s = super.createSheet(); + PropertiesSheet.initializeSheet(provider.getProperties(), s); + return s; + } + }; + node.setDisplayName(provider.getProperties().get("name")); + content.add(node); + } + + + if (o instanceof Figure) { + nodeSelection.addAll(((Figure) o).getSource().getSourceNodesAsSet()); + } else if (o instanceof Slot) { + nodeSelection.addAll(((Slot) o).getSource().getSourceNodesAsSet()); + } + } + getModel().setSelectedNodes(nodeSelection); + } + + @Override + public void highlightingChanged(ObjectSceneEvent e, Set oldSet, Set newSet) { + Set nodeHighlighting = new HashSet<>(); + for (Object o : newSet) { + if (o instanceof Figure) { + nodeHighlighting.addAll(((Figure) o).getSource().getSourceNodesAsSet()); + } else if (o instanceof Slot) { + nodeHighlighting.addAll(((Slot) o).getSource().getSourceNodesAsSet()); + } + } +// boolean b = highlightedCoordinatorListener.isEnabled(); +// highlightedCoordinatorListener.setEnabled(false); +// SelectionCoordinator.getInstance().setHighlightedObjects(nodeHighlighting); +// highlightedCoordinatorListener.setEnabled(b); + validate(); + } + + @Override + public void hoverChanged(ObjectSceneEvent e, Object oldObject, Object newObject) { + Set newHighlightedObjects = new HashSet<>(DiagramScene.this.getHighlightedObjects()); + if (oldObject != null) { + newHighlightedObjects.remove(oldObject); + } + if (newObject != null) { + newHighlightedObjects.add(newObject); + } + DiagramScene.this.setHighlightedObjects(newHighlightedObjects); + } + + @Override + public void focusChanged(ObjectSceneEvent arg0, Object arg1, Object arg2) { + } + }; + + public void setActions(Action[] actions) { + this.actions = actions; + } + + + + public DiagramScene(DiagramViewModel model) { + + this.model = model; + content = new InstanceContent(); + lookup = new AbstractLookup(content); + + this.setCheckClipping(true); + + scrollPane = createScrollPane(); + + hoverAction = createObjectHoverAction(); + + // This panAction handles the event only when the left mouse button is + // pressed without any modifier keys, otherwise it will not consume it + // and the selection action (below) will handle the event + panAction = new CustomizablePanWidgetAction(~0, MouseEvent.BUTTON1_DOWN_MASK); + this.getActions().addAction(panAction); + + selectAction = createSelectAction(); + this.getActions().addAction(selectAction); + + blockLayer = new LayerWidget(this); + this.addChild(blockLayer); + + mainLayer = new LayerWidget(this); + this.addChild(mainLayer); + + topLeft = new Widget(this); + topLeft.setPreferredLocation(new Point(-BORDER_SIZE, -BORDER_SIZE)); + this.addChild(topLeft); + + bottomRight = new Widget(this); + bottomRight.setPreferredLocation(new Point(-BORDER_SIZE, -BORDER_SIZE)); + this.addChild(bottomRight); + + connectionLayer = new LayerWidget(this); + this.addChild(connectionLayer); + + LayerWidget selectionLayer = new LayerWidget(this); + this.addChild(selectionLayer); + + this.setLayout(LayoutFactory.createAbsoluteLayout()); + + this.getInputBindings().setZoomActionModifiers(KeyEvent.CTRL_MASK); + zoomAction = ActionFactory.createMouseCenteredZoomAction(1.2); + this.getActions().addAction(zoomAction); + this.getView().addMouseWheelListener(mouseWheelListener); + this.getActions().addAction(ActionFactory.createPopupMenuAction(popupMenuProvider)); + + this.getActions().addAction(ActionFactory.createWheelPanAction()); + + LayerWidget selectLayer = new LayerWidget(this); + this.addChild(selectLayer); + this.getActions().addAction(ActionFactory.createRectangularSelectAction(rectangularSelectDecorator, selectLayer, rectangularSelectProvider)); + + this.addObjectSceneListener(selectionChangedListener, ObjectSceneEventType.OBJECT_SELECTION_CHANGED, ObjectSceneEventType.OBJECT_HIGHLIGHTING_CHANGED, ObjectSceneEventType.OBJECT_HOVER_CHANGED); + + update(); + } + + public DiagramViewModel getModel() { + return model; + } + + public JScrollPane getScrollPane() { + return scrollPane; + } + + Component getComponent() { + return scrollPane; + } + + public boolean isAllVisible() { + return getModel().getHiddenNodes().isEmpty(); + } + + public Action createGotoAction(final Figure f) { + final DiagramScene diagramScene = this; + Action a = new AbstractAction() { + + @Override + public void actionPerformed(ActionEvent e) { + diagramScene.gotoFigure(f); + } + }; + + a.setEnabled(true); + a.putValue(Action.SMALL_ICON, new ColorIcon(f.getColor())); + String name = f.getLines()[0]; + + name += " ("; + + if (!this.getWidget(f, FigureWidget.class).isVisible()) { + name += "hidden"; + } + name += ")"; + a.putValue(Action.NAME, name); + return a; + } + + private void update() { + mainLayer.removeChildren(); + blockLayer.removeChildren(); + + rebuilding = true; + + Collection objects = new ArrayList<>(this.getObjects()); + for (Object o : objects) { + this.removeObject(o); + } + + Diagram d = getModel().getDiagramToView(); + + for (Figure f : d.getFigures()) { + FigureWidget w = new FigureWidget(f, hoverAction, selectAction, this, mainLayer); + w.getActions().addAction(ActionFactory.createPopupMenuAction(w)); + w.getActions().addAction(selectAction); + w.getActions().addAction(hoverAction); + w.setVisible(false); + + this.addObject(f, w); + + for (InputSlot s : f.getInputSlots()) { + SlotWidget sw = new InputSlotWidget(s, this, w, w); + addObject(s, sw); + sw.getActions().addAction(new DoubleClickAction(sw)); + sw.getActions().addAction(hoverAction); + sw.getActions().addAction(selectAction); + } + + for (OutputSlot s : f.getOutputSlots()) { + SlotWidget sw = new OutputSlotWidget(s, this, w, w); + addObject(s, sw); + sw.getActions().addAction(new DoubleClickAction(sw)); + sw.getActions().addAction(hoverAction); + sw.getActions().addAction(selectAction); + } + } + + rebuilding = false; + this.smallUpdate(true); + } + + public boolean isRebuilding() { + return rebuilding; + } + + private void smallUpdate(boolean relayout) { + + this.updateHiddenNodes(model.getHiddenNodes(), relayout); + this.validate(); + } + + private boolean isVisible(Connection c) { + FigureWidget w1 = getWidget(c.getInputSlot().getFigure()); + FigureWidget w2 = getWidget(c.getOutputSlot().getFigure()); + + if (w1.isVisible() && w2.isVisible()) { + return true; + } + + return false; + } + + private void relayout(Set oldVisibleWidgets) { + System.out.println("relayout called with old visible widgets: " + oldVisibleWidgets); + + Diagram diagram = getModel().getDiagramToView(); + + HashSet
figures = new HashSet<>(); + + for (Figure f : diagram.getFigures()) { + FigureWidget w = getWidget(f); + if (w.isVisible()) { + figures.add(f); + } + } + + HashSet edges = new HashSet<>(); + + for (Connection c : diagram.getConnections()) { + if (isVisible(c)) { + edges.add(c); + } + } + + HierarchicalLayoutManager manager = new HierarchicalLayoutManager(HierarchicalLayoutManager.Combine.SAME_OUTPUTS); + manager.setMaxLayerLength(10); + manager.doLayout(new LayoutGraph(edges, figures)); + relayoutWithoutLayout(oldVisibleWidgets); + } + private Set> lineCache = new HashSet<>(); + + private void relayoutWithoutLayout(Set oldVisibleWidgets) { + + System.out.println("relayout without layout with visible widgets: " + oldVisibleWidgets); + + Diagram diagram = getModel().getDiagramToView(); + + int maxX = -BORDER_SIZE; + int maxY = -BORDER_SIZE; + for (Figure f : diagram.getFigures()) { + FigureWidget w = getWidget(f); + if (w.isVisible()) { + Point p = f.getPosition(); + Dimension d = f.getSize(); + maxX = Math.max(maxX, p.x + d.width); + maxY = Math.max(maxY, p.y + d.height); + } + } + + for (Connection c : diagram.getConnections()) { + List points = c.getControlPoints(); + FigureWidget w1 = getWidget((Figure) c.getTo().getVertex()); + FigureWidget w2 = getWidget((Figure) c.getFrom().getVertex()); + if (w1.isVisible() && w2.isVisible()) { + for (Point p : points) { + if (p != null) { + maxX = Math.max(maxX, p.x); + maxY = Math.max(maxY, p.y); + } + } + } + } + + bottomRight.setPreferredLocation(new Point(maxX + BORDER_SIZE, maxY + BORDER_SIZE)); + int offx = 0; + int offy = 0; + int curWidth = maxX + 2 * BORDER_SIZE; + int curHeight = maxY + 2 * BORDER_SIZE; + + Rectangle bounds = this.getScrollPane().getBounds(); + bounds.width /= getZoomFactor(); + bounds.height /= getZoomFactor(); + if (curWidth < bounds.width) { + offx = (bounds.width - curWidth) / 2; + } + + if (curHeight < bounds.height) { + offy = (bounds.height - curHeight) / 2; + } + + final int offx2 = offx; + final int offy2 = offy; + + SceneAnimator animator = this.getSceneAnimator(); + connectionLayer.removeChildren(); + int visibleFigureCount = 0; + for (Figure f : diagram.getFigures()) { + if (getWidget(f, FigureWidget.class).isVisible()) { + visibleFigureCount++; + } + } + + + Set> lastLineCache = lineCache; + lineCache = new HashSet<>(); + for (Figure f : diagram.getFigures()) { + for (OutputSlot s : f.getOutputSlots()) { + SceneAnimator anim = animator; + if (visibleFigureCount > ANIMATION_LIMIT || oldVisibleWidgets == null) { + anim = null; + } + processOutputSlot(lastLineCache, s, s.getConnections(), 0, null, null, offx2, offy2, anim); + } + } + + for (Figure f : diagram.getFigures()) { + FigureWidget w = getWidget(f); + if (w.isVisible()) { + Point p = f.getPosition(); + Point p2 = new Point(p.x + offx2, p.y + offy2); + if ((visibleFigureCount <= ANIMATION_LIMIT && oldVisibleWidgets != null && oldVisibleWidgets.contains(w))) { + animator.animatePreferredLocation(w, p2); + } else { + w.setPreferredLocation(p2); + animator.animatePreferredLocation(w, p2); + } + } + } + + this.validate(); + } + private final Point specialNullPoint = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE); + + private void processOutputSlot(Set> lastLineCache, OutputSlot s, List connections, int controlPointIndex, Point lastPoint, LineWidget predecessor, int offx, int offy, SceneAnimator animator) { + Map> pointMap = new HashMap<>(connections.size()); + + for (Connection c : connections) { + + if (!isVisible(c)) { + continue; + } + + List controlPoints = c.getControlPoints(); + if (controlPointIndex >= controlPoints.size()) { + continue; + } + + Point cur = controlPoints.get(controlPointIndex); + if (cur == null) { + cur = specialNullPoint; + } else if (controlPointIndex == 0 && !s.shouldShowName()) { + cur = new Point(cur.x, cur.y - SLOT_OFFSET); + } else if (controlPointIndex == controlPoints.size() - 1 && !c.getInputSlot().shouldShowName()) { + cur = new Point(cur.x, cur.y + SLOT_OFFSET); + } + + if (pointMap.containsKey(cur)) { + pointMap.get(cur).add(c); + } else { + List newList = new ArrayList<>(2); + newList.add(c); + pointMap.put(cur, newList); + } + + } + + for (Point p : pointMap.keySet()) { + List connectionList = pointMap.get(p); + + boolean isBold = false; + boolean isDashed = true; + + for (Connection c : connectionList) { + + if (c.getStyle() == Connection.ConnectionStyle.BOLD) { + isBold = true; + } + + if (c.getStyle() != Connection.ConnectionStyle.DASHED) { + isDashed = false; + } + } + + LineWidget newPredecessor = predecessor; + if (p == specialNullPoint) { + } else if (lastPoint == specialNullPoint) { + } else if (lastPoint != null) { + Point p1 = new Point(lastPoint.x + offx, lastPoint.y + offy); + Point p2 = new Point(p.x + offx, p.y + offy); + + Pair curPair = new Pair<>(p1, p2); + SceneAnimator curAnimator = animator; + if (lastLineCache.contains(curPair)) { + curAnimator = null; + } + LineWidget w = new LineWidget(this, s, connectionList, p1, p2, predecessor, curAnimator, isBold, isDashed); + lineCache.add(curPair); + + newPredecessor = w; + connectionLayer.addChild(w); + w.getActions().addAction(hoverAction); + } + + processOutputSlot(lastLineCache, s, connectionList, controlPointIndex + 1, p, newPredecessor, offx, offy, animator); + } + } + + @Override + public Lookup getLookup() { + return lookup; + } + + private void gotoFigures(final Collection
figures) { + Rectangle overall = null; + getModel().showFigures(figures); + for (Figure f : figures) { + + FigureWidget fw = getWidget(f); + if (fw != null) { + Rectangle r = fw.getBounds(); + Point p = fw.getLocation(); + Rectangle r2 = new Rectangle(p.x, p.y, r.width, r.height); + + if (overall == null) { + overall = r2; + } else { + overall = overall.union(r2); + } + } + } + if (overall != null) { + centerRectangle(overall); + } + } + + private Set idSetToObjectSet(Set ids) { + + Set result = new HashSet<>(); + for (Figure f : getModel().getDiagramToView().getFigures()) { + if (DiagramScene.doesIntersect(f.getSource().getSourceNodesAsSet(), ids)) { + result.add(f); + } + + for (Slot s : f.getSlots()) { + if (DiagramScene.doesIntersect(s.getSource().getSourceNodesAsSet(), ids)) { + result.add(s); + } + } + } + return result; + } + + public void gotoSelection(Set ids) { + + Rectangle overall = null; + Set hiddenNodes = new HashSet<>(this.getModel().getHiddenNodes()); + hiddenNodes.removeAll(ids); + this.getModel().showNot(hiddenNodes); + + Set objects = idSetToObjectSet(ids); + for (Object o : objects) { + + Widget w = getWidget(o); + if (w != null) { + Rectangle r = w.getBounds(); + Point p = w.convertLocalToScene(new Point(0, 0)); + + Rectangle r2 = new Rectangle(p.x, p.y, r.width, r.height); + + if (overall == null) { + overall = r2; + } else { + overall = overall.union(r2); + } + } + } + if (overall != null) { + centerRectangle(overall); + } + + setSelectedObjects(objects); + } + + private Point calcCenter(Rectangle r) { + + Point center = new Point((int) r.getCenterX(), (int) r.getCenterY()); + center.x -= getScrollPane().getViewport().getViewRect().width / 2; + center.y -= getScrollPane().getViewport().getViewRect().height / 2; + + // Ensure to be within area + center.x = Math.max(0, center.x); + center.x = Math.min(getScrollPane().getViewport().getViewSize().width - getScrollPane().getViewport().getViewRect().width, center.x); + center.y = Math.max(0, center.y); + center.y = Math.min(getScrollPane().getViewport().getViewSize().height - getScrollPane().getViewport().getViewRect().height, center.y); + + return center; + } + + private void centerRectangle(Rectangle r) { + + if (getScrollPane().getViewport().getViewRect().width == 0 || getScrollPane().getViewport().getViewRect().height == 0) { + return; + } + + Rectangle r2 = new Rectangle(r.x, r.y, r.width, r.height); + r2 = convertSceneToView(r2); + + double factorX = (double) r2.width / (double) getScrollPane().getViewport().getViewRect().width; + double factorY = (double) r2.height / (double) getScrollPane().getViewport().getViewRect().height; + double factor = Math.max(factorX, factorY); + if (factor >= 1.0) { + Point p = getScrollPane().getViewport().getViewPosition(); + setZoomFactor(getZoomFactor() / factor); + r2.x /= factor; + r2.y /= factor; + r2.width /= factor; + r2.height /= factor; + getScrollPane().getViewport().setViewPosition(calcCenter(r2)); + } else { + getScrollPane().getViewport().setViewPosition(calcCenter(r2)); + } + } + + void setSelection(Collection
list) { + super.setSelectedObjects(new HashSet<>(list)); + centerFigures(list); + } + + private boolean isVisible(Figure f) { + for (Integer n : f.getSource().getSourceNodesAsSet()) { + if (getModel().getHiddenNodes().contains(n)) { + return false; + } + } + return true; + } + + public static boolean doesIntersect(Set s1, Set s2) { + if (s1.size() > s2.size()) { + Set tmp = s1; + s1 = s2; + s2 = tmp; + } + + for (Object o : s1) { + if (s2.contains(o)) { + return true; + } + } + + return false; + } + + private void updateHiddenNodes(Set newHiddenNodes, boolean doRelayout) { + + System.out.println("newHiddenNodes: " + newHiddenNodes); + + Diagram diagram = getModel().getDiagramToView(); + assert diagram != null; + + Set oldVisibleWidgets = new HashSet<>(); + + for (Figure f : diagram.getFigures()) { + FigureWidget w = getWidget(f); + if (w != null && w.isVisible()) { + oldVisibleWidgets.add(w); + } + } + + for (Figure f : diagram.getFigures()) { + boolean hiddenAfter = doesIntersect(f.getSource().getSourceNodesAsSet(), newHiddenNodes); + + FigureWidget w = getWidget(f); + w.setBoundary(false); + if (!hiddenAfter) { + // Figure is shown + w.setVisible(true); + } else { + // Figure is hidden + w.setVisible(false); + } + } + + if (getModel().getShowNodeHull()) { + List boundaries = new ArrayList<>(); + for (Figure f : diagram.getFigures()) { + FigureWidget w = getWidget(f); + if (!w.isVisible()) { + Set
set = new HashSet<>(f.getPredecessorSet()); + set.addAll(f.getSuccessorSet()); + + boolean b = false; + for (Figure neighbor : set) { + FigureWidget neighborWidget = getWidget(neighbor); + if (neighborWidget.isVisible()) { + b = true; + break; + } + } + + if (b) { + w.setBoundary(true); + boundaries.add(w); + } + } + } + + for (FigureWidget w : boundaries) { + if (w.isBoundary()) { + w.setVisible(true); + } + } + } + + if (doRelayout) { + relayout(oldVisibleWidgets); + } + this.validate(); + } + + private void showFigure(Figure f) { + HashSet newHiddenNodes = new HashSet<>(getModel().getHiddenNodes()); + newHiddenNodes.removeAll(f.getSource().getSourceNodesAsSet()); + updateHiddenNodes(newHiddenNodes, true); + } + + public void show(final Figure f) { + showFigure(f); + } + + public void setSelectedObjects(Object... args) { + Set set = new HashSet<>(); + for (Object o : args) { + set.add(o); + } + super.setSelectedObjects(set); + } + + private void centerWidget(Widget w) { + Rectangle r = w.getBounds(); + Point p = w.getLocation(); + centerRectangle(new Rectangle(p.x, p.y, r.width, r.height)); + } + + public void gotoFigure(final Figure f) { + if (!isVisible(f)) { + showFigure(f); + } + + FigureWidget fw = getWidget(f); + if (fw != null) { + setSelection(new HashSet<>(Arrays.asList(f))); + } + } + + public JPopupMenu createPopupMenu() { + JPopupMenu menu = new JPopupMenu(); + for (Action a : actions) { + if (a == null) { + menu.addSeparator(); + } else { + menu.add(a); + } + } + return menu; + } + + private final ChangedListener fullChange = new ChangedListener() { + + @Override + public void changed(DiagramViewModel source) { + assert source == model : "Receive only changed event from current model!"; + assert source != null; + update(); + } + }; + private final ChangedListener hiddenNodesChange = new ChangedListener() { + + @Override + public void changed(DiagramViewModel source) { + assert source == model : "Receive only changed event from current model!"; + assert source != null; + smallUpdate(true); + } + }; + private final ChangedListener selectionChange = new ChangedListener() { + + @Override + public void changed(DiagramViewModel source) { + assert source == model : "Receive only changed event from current model!"; + assert source != null; + smallUpdate(false); + } + }; +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/scene/GraphCompilationViewer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/scene/GraphCompilationViewer.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +package com.sun.hotspot.igv.view.scene; + +import com.sun.hotspot.igv.svg.BatikSVG; +import com.oracle.graal.visualizer.editor.CompilationViewer; +import com.oracle.graal.visualizer.editor.DiagramViewModel; +import com.oracle.graal.visualizer.editor.ExportCookie; +import com.sun.hotspot.igv.graph.Figure; +import com.sun.hotspot.igv.view.actions.*; +import java.awt.Component; +import java.awt.Graphics2D; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.*; +import java.util.Collection; +import javax.swing.Action; +import javax.swing.JToggleButton; +import javax.swing.JToolBar; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.util.Lookup; +import org.openide.util.lookup.Lookups; +import org.openide.util.lookup.ProxyLookup; + +public class GraphCompilationViewer implements CompilationViewer, PropertyChangeListener { + + private DiagramScene scene; + private JToolBar toolBar; + private PredSuccAction predSuccAction; + + private ExportCookie exportCookie = new ExportCookie() { + + @Override + public void export(File f) { + + Graphics2D svgGenerator = BatikSVG.createGraphicsObject(); + + if (svgGenerator == null) { + NotifyDescriptor message = new NotifyDescriptor.Message("For export to SVG files the Batik SVG Toolkit must be intalled.", NotifyDescriptor.ERROR_MESSAGE); + DialogDisplayer.getDefault().notifyLater(message); + } else { + scene.paint(svgGenerator); + FileOutputStream os = null; + try { + os = new FileOutputStream(f); + Writer out = new OutputStreamWriter(os, "UTF-8"); + BatikSVG.printToStream(svgGenerator, out, true); + } catch (FileNotFoundException e) { + NotifyDescriptor message = new NotifyDescriptor.Message("For export to SVG files the Batik SVG Toolkit must be intalled.", NotifyDescriptor.ERROR_MESSAGE); + DialogDisplayer.getDefault().notifyLater(message); + + } catch (UnsupportedEncodingException e) { + } finally { + if (os != null) { + try { + os.close(); + } catch (IOException e) { + } + } + } + + } + } + }; + private Lookup lookup; + + GraphCompilationViewer(DiagramViewModel model) { + + scene = new DiagramScene(model); + + Action[] actions = new Action[]{ + }; + + scene.setActions(actions); +// predSuccAction = new PredSuccAction(); +// JToggleButton button = new JToggleButton(predSuccAction); +// button.setSelected(true); +// toolBar.add(button); +// predSuccAction.addPropertyChangeListener(this); + + lookup = new ProxyLookup(scene.getLookup(), Lookups.singleton(exportCookie)); + } + + @Override + public Lookup getLookup() { + return lookup; + } + + @Override + public Component getComponent() { + return scene.getComponent(); + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (evt.getSource() == this.predSuccAction) { + boolean b = (Boolean) predSuccAction.getValue(PredSuccAction.STATE); + scene.getModel().setShowNodeHull(b); + } else { + assert false : "Unknown event source"; + } + } + +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/scene/GraphCompilationViewerFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/scene/GraphCompilationViewerFactory.java Tue Feb 07 21:09:31 2012 +0100 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +package com.sun.hotspot.igv.view.scene; + +import com.oracle.graal.visualizer.editor.CompilationViewer; +import com.oracle.graal.visualizer.editor.CompilationViewerFactory; +import com.oracle.graal.visualizer.editor.DiagramViewModel; +import com.sun.hotspot.igv.data.InputGraph; +import com.sun.hotspot.igv.filter.FilterChain; +import com.sun.hotspot.igv.filter.FilterChainProvider; +import org.openide.util.Lookup; + +public class GraphCompilationViewerFactory implements CompilationViewerFactory{ + + @Override + public CompilationViewer createViewer(InputGraph firstGraph, InputGraph secondGraph) { + FilterChain filterChain; + FilterChain sequence; + FilterChainProvider provider = Lookup.getDefault().lookup(FilterChainProvider.class); + if (provider == null) { + filterChain = new FilterChain(); + sequence = new FilterChain(); + } else { + filterChain = provider.getFilterChain(); + sequence = provider.getSequence(); + } + DiagramViewModel model = new DiagramViewModel(firstGraph, secondGraph, firstGraph.getGroup(), filterChain, filterChain); + return new GraphCompilationViewer(model); + } + + @Override + public String getName() { + return "Graph"; + } + +} diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/FigureWidget.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/FigureWidget.java Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/FigureWidget.java Tue Feb 07 21:09:31 2012 +0100 @@ -28,7 +28,7 @@ import com.sun.hotspot.igv.util.DoubleClickAction; import com.sun.hotspot.igv.util.DoubleClickHandler; import com.sun.hotspot.igv.util.PropertiesSheet; -import com.sun.hotspot.igv.view.DiagramScene; +import com.sun.hotspot.igv.view.scene.DiagramScene; import java.awt.*; import java.util.ArrayList; import java.util.HashSet; diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/InputSlotWidget.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/InputSlotWidget.java Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/InputSlotWidget.java Tue Feb 07 21:09:31 2012 +0100 @@ -25,7 +25,7 @@ import com.sun.hotspot.igv.graph.Figure; import com.sun.hotspot.igv.graph.InputSlot; -import com.sun.hotspot.igv.view.DiagramScene; +import com.sun.hotspot.igv.view.scene.DiagramScene; import java.awt.Point; import java.util.List; import org.netbeans.api.visual.widget.Widget; diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/LineWidget.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/LineWidget.java Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/LineWidget.java Tue Feb 07 21:09:31 2012 +0100 @@ -27,7 +27,7 @@ import com.sun.hotspot.igv.graph.Figure; import com.sun.hotspot.igv.graph.InputSlot; import com.sun.hotspot.igv.graph.OutputSlot; -import com.sun.hotspot.igv.view.DiagramScene; +import com.sun.hotspot.igv.view.scene.DiagramScene; import java.awt.*; import java.awt.geom.Line2D; import java.util.ArrayList; diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/OutputSlotWidget.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/OutputSlotWidget.java Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/OutputSlotWidget.java Tue Feb 07 21:09:31 2012 +0100 @@ -25,7 +25,7 @@ import com.sun.hotspot.igv.graph.Figure; import com.sun.hotspot.igv.graph.OutputSlot; -import com.sun.hotspot.igv.view.DiagramScene; +import com.sun.hotspot.igv.view.scene.DiagramScene; import java.awt.Point; import java.util.List; import org.netbeans.api.visual.widget.Widget; diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/SlotWidget.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/SlotWidget.java Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/SlotWidget.java Tue Feb 07 21:09:31 2012 +0100 @@ -27,7 +27,7 @@ import com.sun.hotspot.igv.graph.OutputSlot; import com.sun.hotspot.igv.graph.Slot; import com.sun.hotspot.igv.util.DoubleClickHandler; -import com.sun.hotspot.igv.view.DiagramScene; +import com.sun.hotspot.igv.view.scene.DiagramScene; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; diff -r 58ecb156a3e8 -r 9d640941c9c7 src/share/tools/IdealGraphVisualizer/nbproject/project.properties --- a/src/share/tools/IdealGraphVisualizer/nbproject/project.properties Tue Feb 07 19:41:28 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/nbproject/project.properties Tue Feb 07 21:09:31 2012 +0100 @@ -4,7 +4,6 @@ branding.token=${app.name} modules=\ ${project.com.sun.hotspot.igv.graph}:\ - ${project.com.sun.hotspot.igv.coordinator}:\ ${project.com.sun.hotspot.igv.filter}:\ ${project.com.sun.hotspot.igv.hierarchicallayout}:\ ${project.com.sun.hotspot.igv.layout}:\ @@ -15,14 +14,18 @@ ${project.com.sun.hotspot.igv.settings}:\ ${project.com.sun.hotspot.igv.util}:\ ${project.com.sun.hotspot.igv.svg}:\ - ${project.com.sun.hotspot.connection}:\ - ${project.com.sun.hotspot.igv.servercompilerscheduler}:\ ${project.com.sun.hotspot.igv.filterwindow}:\ - ${project.com.sun.hotspot.igv.selectioncoordinator}:\ - ${project.com.sun.hotspot.igv.graal} -project.com.sun.hotspot.connection=NetworkConnection + ${project.com.sun.hotspot.igv.graal}:\ + ${project.at.ssw.visualizer.cfg}:\ + ${project.org.eclipse.draw2d}:\ + ${project.com.oracle.graal.visualizer.editor}:\ + ${project.com.oracle.graal.visualizer.outline}:\ + ${project.com.oracle.graal.visualizer.snapshots} +project.at.ssw.visualizer.cfg=ControlFlowEditor +project.com.oracle.graal.visualizer.editor=Editor +project.com.oracle.graal.visualizer.outline=OutlineView +project.com.oracle.graal.visualizer.snapshots=SnapshotsView project.com.sun.hotspot.igv.bytecodes=Bytecodes -project.com.sun.hotspot.igv.coordinator=Coordinator project.com.sun.hotspot.igv.data=Data project.com.sun.hotspot.igv.difference=Difference project.com.sun.hotspot.igv.filter=Filter @@ -31,13 +34,12 @@ project.com.sun.hotspot.igv.graph=Graph project.com.sun.hotspot.igv.hierarchicallayout=HierarchicalLayout project.com.sun.hotspot.igv.layout=Layout -project.com.sun.hotspot.igv.selectioncoordinator=SelectionCoordinator -project.com.sun.hotspot.igv.servercompilerscheduler=ServerCompiler project.com.sun.hotspot.igv.settings=Settings project.com.sun.hotspot.igv.svg=BatikSVGProxy project.com.sun.hotspot.igv.view=View project.com.sun.hotspot.igv.util=Util +project.org.eclipse.draw2d=Draw2DLibrary # Disable assertions for RequestProcessor to prevent annoying messages in case # of multiple SceneAnimator update tasks in the default RequestProcessor. run.args.extra = -J-client -J-da:org.openide.util.RequestProcessor