Mercurial > hg > graal-compiler
changeset 4506:ab7c258e1cef
Merge.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sun, 05 Feb 2012 05:40:36 +0100 |
parents | 5d9c4796912d (diff) 0312460af9fc (current diff) |
children | 9d640941c9c7 |
files | graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/lir/LIRBlock.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/loop/Loop.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/loop/LoopInfo.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/loop/LoopUtil.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/RemovePlaceholderPhase.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/schedule/Block.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/schedule/IdentifyBlocksPhase.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/NodeIterators.java graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/TypePredicate.java graal/com.oracle.max.graal.java/src/com/oracle/max/graal/java/BlockMap.java graal/com.oracle.max.graal.snippets/src/com/oracle/max/graal/snippets/ArrayCopySnippets.java graal/com.oracle.max.graal.snippets/src/com/oracle/max/graal/snippets/IntrinsifyArrayCopyPhase.java graal/com.oracle.max.graal.snippets/src/com/oracle/max/graal/snippets/SystemSnippets.java graal/com.oracle.max.graal.snippets/src/com/oracle/max/graal/snippets/UnsafeSnippets.java |
diffstat | 289 files changed, 12113 insertions(+), 7491 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/tools/IdealGraphVisualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/BytecodeViewTopComponent.java Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/BytecodeViewTopComponent.java Sun Feb 05 05:40:36 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
--- a/src/share/tools/IdealGraphVisualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/SelectBytecodesAction.java Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/SelectBytecodesAction.java Sun Feb 05 05:40:36 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()); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/manifest.mf Sun Feb 05 05:40:36 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 +
--- /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 Sun Feb 05 05:40:36 2012 +0100 @@ -0,0 +1,1 @@ +at.ssw.visualizer.cfg.CfgCompilationViewerFactory \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/Bundle.properties Sun Feb 05 05:40:36 2012 +0100 @@ -0,0 +1,1 @@ +OpenIDE-Module-Name=ControlFlowEditor
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/CfgCompilationViewer.java Sun Feb 05 05:40:36 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; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/CfgCompilationViewerFactory.java Sun Feb 05 05:40:36 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); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/CfgEditorContext.java Sun Feb 05 05:40:36 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; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/AbstractCfgEditorAction.java Sun Feb 05 05:40:36 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; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/Bundle.properties Sun Feb 05 05:40:36 2012 +0100 @@ -0,0 +1,2 @@ +CTL_SomeAction=test +CTL_SomeAction2=test
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/ExportAction.java Sun Feb 05 05:40:36 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"; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/HideEdgesAction.java Sun Feb 05 05:40:36 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; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/HierarchicalCompoundLayoutAction.java Sun Feb 05 05:40:36 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<CfgScene> scenes; + + public HierarchicalCompoundLayoutAction(List<CfgScene> scenes) { + this.scenes = scenes; + } + + @Override + public void actionPerformed(ActionEvent e) { + for (CfgScene s : scenes) { + s.setSceneLayout(CfgEditorContext.LAYOUT_HIERARCHICALCOMPOUNDLAYOUT); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/HierarchicalNodeLayoutAction.java Sun Feb 05 05:40:36 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<CfgScene> scenes; + + public HierarchicalNodeLayoutAction(List<CfgScene> scenes) { + this.scenes = scenes; + } + + @Override + public void actionPerformed(ActionEvent e) { + for (CfgScene s : scenes) { + s.setSceneLayout(CfgEditorContext.LAYOUT_HIERARCHICALNODELAYOUT); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/ShowAllAction.java Sun Feb 05 05:40:36 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"; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/ShowEdgesAction.java Sun Feb 05 05:40:36 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; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/SwitchLoopClustersAction.java Sun Feb 05 05:40:36 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); + } + } + }); + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/ZoominAction.java Sun Feb 05 05:40:36 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; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/ZoomoutAction.java Sun Feb 05 05:40:36 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; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/CfgEventListener.java Sun Feb 05 05:40:36 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); + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/CfgScene.java Sun Feb 05 05:40:36 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<CfgNode, CfgEdge> 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<CfgNode> selectedNodes = Collections.<CfgNode>emptySet(); + private Map<Integer, LoopClusterWidget> loopidx2clusterwidget = new HashMap<>(); + private Map<CfgNode, EdgeSwitchWidget> inputSwitches = new HashMap<>(); + private Map<CfgNode, EdgeSwitchWidget> 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<NodeWidget> 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<CfgNode, LoopInfo> map) { + this.clusterLayer.removeChildren(); + + Set<LoopInfo> 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<CfgNode> getSelectedNodes() { + return Collections.<CfgNode>unmodifiableSet(selectedNodes); + } + + public Map<Integer, LoopClusterWidget> 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<Widget> 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<NodeWidget> getNodeWidgets() { + if (nodeWidgets != null && nodeWidgets.size() == this.getNodes().size()) { + return nodeWidgets; + } + + List<NodeWidget> 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<CfgNode, CfgEdge> 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<Widget> 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.<CfgNode>emptySet(), false); + this.selectedNodes = Collections.<CfgNode>emptySet(); + this.fireSelectionChanged(); + this.validate(); + } + } + + //sets the scene & global node selection + public void setNodeSelection(Set<CfgNode> newSelection) { + this.setSceneSelection(newSelection); + this.updateGlobalSelection(); + } + + //sets the scene selection + private void setSceneSelection(Set<CfgNode> newSelection) { + if (newSelection.equals(selectedNodes)) { + return; + } + + this.selectedNodes = newSelection; + + Set<Object> 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<BasicBlock> newBlocks = new ArrayList<BasicBlock>(); +// 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<CfgNode> newSelection = new HashSet<CfgNode>(); +// 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<CfgNode> 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<CfgNode> 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<Widget, Point> 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<CfgNode> 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<CfgNode> 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<Widget, Point> 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<CfgNode> 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<CfgNode> successors = new ArrayList<>(); + ArrayList<CfgNode> 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<CfgNode> { + + 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<CfgNode> 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(); + } + } + }; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/EdgeSwitchWidget.java Sun Feb 05 05:40:36 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<CfgEdge> getEdges(){ + Collection<CfgEdge> 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<CfgEdge> 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<CfgEdge> 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<CfgEdge> edges = this.getEdges(); + ArrayList<CfgEdge> 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(); + } + } + }; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/EdgeWidget.java Sun Feb 05 05:40:36 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() + "]"; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/LoopClusterWidget.java Sun Feb 05 05:40:36 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<LoopClusterWidget> { + 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<NodeWidget> 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<NodeWidget> 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+"]"; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/NodeWidget.java Sun Feb 05 05:40:36 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("<html>" + nodeModel.getDescription().replaceAll("\n", "<br>") + "</html>"); + 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() + "]"; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/SelectionWidget.java Sun Feb 05 05:40:36 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()); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/SymmetricAnchor.java Sun Feb 05 05:40:36 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); + } +}
--- /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 Sun Feb 05 05:40:36 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<CfgNode, CfgEdge> { + + 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<CfgNode, CfgEdge> ug) { + CompoundDirectedGraph dg = new CompoundDirectedGraph(); + CompoundDirectedGraphLayout layout = new CompoundDirectedGraphLayout(); + NodeList nodeList = dg.nodes; + EdgeList edgeList = dg.edges; + + Map<Integer, Subgraph> 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<CfgNode, CfgEdge> ug, Collection<CfgNode> collection) { + } + + private Insets getInsets(){ + return new Insets(INSET, INSET, INSET, INSET); + } + +}
--- /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 Sun Feb 05 05:40:36 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<CfgNode, CfgEdge> { + + 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<CfgNode, CfgEdge> 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<CfgNode, CfgEdge> ug, Collection<CfgNode> collection) { + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/Icons.java Sun Feb 05 05:40:36 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() { + } +}
Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/arrangebfs.gif has changed
Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/arrangehier.gif has changed
Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/arrangeloop.gif has changed
Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/autosize.gif has changed
Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/autosize_selection.gif has changed
Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/bezierrouter.gif has changed
Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/cfg.gif has changed
Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/cfg32.gif has changed
Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/cluster.gif has changed
Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/color.gif has changed
Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/combine.gif has changed
Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/combine_disabled.gif has changed
Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/disk.gif has changed
Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/fanrouter.gif has changed
Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/hideedges.gif has changed
Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/hideedges_disabled.gif has changed
Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/manhattanrouter.gif has changed
Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/showedges.gif has changed
Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/showedges_disabled.gif has changed
Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/split.gif has changed
Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/split_disabled.gif has changed
Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/zoomin.gif has changed
Binary file src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/zoomout.gif has changed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/layer.xml Sun Feb 05 05:40:36 2012 +0100 @@ -0,0 +1,72 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.1//EN" "http://www.netbeans.org/dtds/filesystem-1_1.dtd"> +<filesystem> + <folder name="OptionsDialog"> + <file name="CFGOptions.instance"> + <attr name="instanceClass" stringvalue="at.ssw.visualizer.cfg.preferences.CFGOptionsCategory"/> + <attr name="position" intvalue="1"/> + </file> + </folder> + <folder name="CompilationViewer"> + <folder name="CFG"> + <folder name="Actions"> + <file name="com-oracle-graal-visualizer-cfg-RouterAction.instance"> + <attr name="displayName" stringvalue="Bezier routing"/> + <attr methodvalue="org.openide.awt.Actions.checkbox" name="instanceCreate"/> + <attr name="iconBase" stringvalue="at/ssw/visualizer/cfg/icons/bezierrouter.gif"/> + <attr name="preferencesNode" methodvalue="at.ssw.visualizer.cfg.graph.CfgScene.getPreferences"/> + <attr name="preferencesKey" stringvalue="router"/> + </file> + </folder> + </folder> + </folder> + <folder name="Actions"> + <folder name="Window"> + <file name="ShowCFGEditor.instance"> + <attr name="instanceClass" stringvalue="at.ssw.visualizer.cfg.action.ShowCFGEditorAction"/> + </file> + </folder> + <folder name="View"> + <file name="ShowEdges.instance"> + <attr name="instanceClass" stringvalue="at.ssw.visualizer.cfg.action.ShowEdgesAction"/> + </file> + <file name="HideEdges.instance"> + <attr name="instanceClass" stringvalue="at.ssw.visualizer.cfg.action.HideEdgesAction"/> + </file> + <file name="Export.instance"> + <attr name="instanceClass" stringvalue="at.ssw.visualizer.cfg.action.ExportAction"/> + </file> + <file name="Zoomin.instance"> + <attr name="instanceClass" stringvalue="at.ssw.visualizer.cfg.action.ZoominAction"/> + </file> + <file name="Zoomout.instance"> + <attr name="instanceClass" stringvalue="at.ssw.visualizer.cfg.action.ZoomoutAction"/> + </file> + <file name="ShowAll.instance"> + <attr name="instanceClass" stringvalue="at.ssw.visualizer.cfg.action.ShowAllAction"/> + </file> + </folder> + </folder> + + <folder name="Menu"> + <folder name="BuildProject_hidden"> + <file name="at-ssw-visualizer-cfg-action-SomeAction.shadow"> + <attr name="originalFile" stringvalue="Actions/Build/at-ssw-visualizer-cfg-action-SomeAction.instance"/> + </file> + </folder> + <folder name="Window"> + <file name="ShowCFGEditor.shadow"> + <attr name="originalFile" stringvalue="Actions/Window/ShowCFGEditor.instance"/> + <attr name="position" intvalue="1300"/> + </file> + </folder> + </folder> + + <folder name="at-ssw-visualizer-actions-cfg"> + <file name="ShowCFGEditor.shadow"> + <attr name="originalFile" stringvalue="Actions/Window/ShowCFGEditor.instance"/> + <attr name="position" intvalue="300"/> + </file> + </folder> + +</filesystem>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/CfgEdge.java Sun Feb 05 05:40:36 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(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/CfgEdgeImpl.java Sun Feb 05 05:40:36 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(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/CfgEnv.java Sun Feb 05 05:40:36 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<CfgNode, LoopInfo> 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<BasicBlock, CfgNodeImpl> block2nodeMap = new HashMap<>(); + Map<CfgNodeImpl, Set<CfgEdgeImpl>> inputMap = new HashMap<>(); + ArrayList<CfgEdgeImpl> allEdges = new ArrayList<>(); + List<BasicBlock> 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<String> 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<CfgEdgeImpl> outputEdges = new ArrayList<>(); + + Set<BasicBlock> 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<CfgEdgeImpl> 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<CfgEdgeImpl> 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<? extends BasicBlock> 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<CfgNode, LoopInfo> getLoopMap() { + return loopMap; + } + + public void setLoopMap(Map<CfgNode, LoopInfo> 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<CfgNode> 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<CfgNodeImpl> allNodes; + Set<CfgNodeImpl> activeNodes; + Set<CfgNodeImpl> visitedNodes; + Map<CfgNode, LoopInfo> loopMap; + private int loopIndex=0; + + public LoopEnv(Collection<CfgNodeImpl> 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<CfgNode> 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<CfgNode> cache = new HashSet<>(); + Queue<CfgNode> 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; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/CfgNode.java Sun Feb 05 05:40:36 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(); + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/CfgNodeImpl.java Sun Feb 05 05:40:36 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; + } + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/LoopInfo.java Sun Feb 05 05:40:36 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<CfgNode> members; + private List<CfgEdge> 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<CfgNode> getMembers() { + return members; + } + + protected void setMembers(Set<CfgNode> members) { + this.members = members; + } + + public int getLoopIndex() { + return loopIndex; + } + + protected void setParent(LoopInfo parent) { + this.parent = parent; + } + + public LoopInfo getParent(){ + return parent; + } + + public List<CfgEdge> 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(); + } + + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/CFGOptionsCategory.java Sun Feb 05 05:40:36 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"; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/CFGOptionsPanel.java Sun Feb 05 05:40:36 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<ConfigurationElement> 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(); + } + + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/CFGOptionsPanelController.java Sun Feb 05 05:40:36 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; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/CfgPreferences.java Sun Feb 05 05:40:36 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()); + } + + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/CfgPreferencesDefaults.java Sun Feb 05 05:40:36 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); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/ColorChooserButton.java Sun Feb 05 05:40:36 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); + } + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/FlagsEditorPanel.java Sun Feb 05 05:40:36 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<buttonContainer.getComponentCount(); i++) { + Component c = buttonContainer.getComponent(i); + if (c instanceof JButton) { + JButton b = (JButton)c; + if (width < b.getPreferredSize().width) { + width = b.getPreferredSize().width; + } + if (height < b.getPreferredSize().height) { + height = b.getPreferredSize().height; + } + } + } + + Dimension commonButtonSize = new Dimension(width, height); + + for (int i=0; i<buttonContainer.getComponentCount(); i++) { + Component c = buttonContainer.getComponent(i); + if (c instanceof JButton) { + JButton b = (JButton)c; + b.setMinimumSize(commonButtonSize); + b.setPreferredSize(commonButtonSize); + b.setMaximumSize(commonButtonSize); + } + } + + } + + public String getFlagString() { + return listModel.getFlagString(); + } + + public void setFlagString(String flagString) { + listModel.setFlagString(flagString); + } + + public void actionPerformed(ActionEvent e) { + Object source = e.getSource(); + if (source == colorButton) { + changeColor(); + } else if (source == newButton) { + String s = JOptionPane.showInputDialog(this, + "Type in the flag which should fill the block with a specific color"); + if (s == null) { + return; + } + s = s.replace('(', ' '); + s = s.replace(';', ' '); + int index = list.getSelectedIndex()+1; + listModel.insertElementAt(new FlagListItem(s, Color.WHITE), index); + } else if (source == removeButton) { + listModel.removeElementAt(list.getSelectedIndex()); + } else if (source == upButton) { + int index = list.getSelectedIndex(); + if (index == 0) { + return; + } + Object o = listModel.getElementAt(index); + listModel.removeElementAt(index); + listModel.insertElementAt(o, index-1); + } else if (source == downButton) { + int index = list.getSelectedIndex(); + if (index >= 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; + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/FlagsSetting.java Sun Feb 05 05:40:36 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<String, Color> flag2color; + private Hashtable<String, Integer> 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<String> 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 + "]"; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/FontChooserDialog.java Sun Feb 05 05:40:36 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; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/visual/BezierWidget.java Sun Feb 05 05:40:36 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<Point> 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)); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/visual/PolylineRouter.java Sun Feb 05 05:40:36 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<Point> routeConnection(final ConnectionWidget widget) { + if(!widget.isVisible()) return Collections.<Point>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.<Point>emptyList(); + } + + List<Widget> 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<Point> 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<Point> simplify(Collection<Widget> nodeWidgets, List<Point> list) { + List<Point> 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<Point> optimize(Collection<Widget> nodeWidgets, ConnectionWidget connWidget, Point start, Point end) { + + List<Point> 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<Point> 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<Point> 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<Point> 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<Point> optimizeLine(Collection<Widget> 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<Point> 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<Point> 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<Point> 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<Widget> 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<Widget> nodeWidgets, Point start, Point end) { + List<Point> 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<Point> list) { + Rectangle r = w.convertLocalToScene(w.getBounds()); + r.grow(HEXPAND, VEXPAND); + return intersects(list, r); + } + + + private boolean intersects(List<Point> 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); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/visual/PolylineRouterV2.java Sun Feb 05 05:40:36 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<Point> routeConnection(final ConnectionWidget widget) { + if(!widget.isVisible()) return Collections.<Point>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.<Point>emptyList(); + } + + + Point srcCenter = this.getSceneLocation(sourceWidget); + Point tarCenter = this.getSceneLocation(targetWidget); + + List<Widget> widgetObstacles = new ArrayList<>(); + + if(collector != null){ + collector.collectCollisions(widgetObstacles); + } + + List<Rectangle> obstacles = new ArrayList<>(widgetObstacles.size()); + this.collectObstacles(obstacles, widgetObstacles, widget); + + + List<Point> 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<Rectangle> colrects, List<Widget> 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<Point> simplify(List<Rectangle> obstacles, List<Point> list) { + List<Point> 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<Point> optimize(List<Rectangle> nodeWidgets, Point start, Point end) { + + List<Point> 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<Point> 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<Point> 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<Point> optimizeLine(List<Rectangle> obstacles, Point p1, Point p2) { + Line2D line = new Line2D.Double(p1, p2); + boolean inbounds=false; + Rectangle ibr=null; + ArrayList<Point> 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<Rectangle> 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; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/visual/SplineConnectionWidget.java Sun Feb 05 05:40:36 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<Point> 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<Point> 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<Point> 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; + } + + +} + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/visual/WidgetCollisionCollector.java Sun Feb 05 05:40:36 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<Widget> collisions); + +}
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/build.xml Sat Feb 04 15:43:40 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- You may freely edit this file. See harness/README in the NetBeans platform --> -<!-- for some information on what you could do (e.g. targets to override). --> -<!-- If you delete this file and reopen the project it will be recreated. --> -<project name="com.sun.hotspot.igv.coordinator" default="netbeans" basedir="."> - <description>Builds, tests, and runs the project com.sun.hotspot.igv.coordinator.</description> - <import file="nbproject/build-impl.xml"/> -</project>
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/manifest.mf Sat Feb 04 15:43:40 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 -
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/nbproject/build-impl.xml Sat Feb 04 15:43:40 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- -*** GENERATED FROM project.xml - DO NOT EDIT *** -*** EDIT ../build.xml INSTEAD *** ---> -<project name="com.sun.hotspot.igv.coordinator-impl" basedir=".."> - <property file="nbproject/private/suite-private.properties"/> - <property file="nbproject/suite.properties"/> - <fail unless="suite.dir">You must set 'suite.dir' to point to your containing module suite</fail> - <property file="${suite.dir}/nbproject/private/platform-private.properties"/> - <property file="${suite.dir}/nbproject/platform.properties"/> - <macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-project/2"> - <attribute name="name"/> - <attribute name="value"/> - <sequential> - <property name="@{name}" value="${@{value}}"/> - </sequential> - </macrodef> - <property file="${user.properties.file}"/> - <nbmproject2:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/> - <nbmproject2:property name="netbeans.dest.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/> - <fail message="You must define 'nbplatform.${nbplatform.active}.harness.dir'"> - <condition> - <not> - <available file="${harness.dir}" type="dir"/> - </not> - </condition> - </fail> - <import file="${harness.dir}/build.xml"/> -</project>
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/nbproject/genfiles.properties Sat Feb 04 15:43:40 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
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/nbproject/platform.properties Sat Feb 04 15:43:40 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
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/nbproject/project.properties Sat Feb 04 15:43:40 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
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/nbproject/project.xml Sat Feb 04 15:43:40 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,142 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://www.netbeans.org/ns/project/1"> - <type>org.netbeans.modules.apisupport.project</type> - <configuration> - <data xmlns="http://www.netbeans.org/ns/nb-module-project/3"> - <code-name-base>com.sun.hotspot.igv.coordinator</code-name-base> - <suite-component/> - <module-dependencies> - <dependency> - <code-name-base>com.sun.hotspot.igv.connection</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>1.0</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>com.sun.hotspot.igv.data</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>1.0</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>com.sun.hotspot.igv.difference</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>1.0</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>com.sun.hotspot.igv.settings</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>1.0</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>com.sun.hotspot.igv.util</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>1.0</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>org.netbeans.api.progress</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <release-version>1</release-version> - <specification-version>1.23.1</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>org.openide.actions</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>6.21.1</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>org.openide.awt</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>7.30.1</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>org.openide.dialogs</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>7.18.1</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>org.openide.explorer</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>6.34.1</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>org.openide.filesystems</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>7.46.1</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>org.openide.loaders</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>7.20.1</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>org.openide.nodes</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>7.20.1</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>org.openide.util</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>8.14.1</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>org.openide.util.lookup</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>8.6.1</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>org.openide.windows</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>6.39.1</specification-version> - </run-dependency> - </dependency> - </module-dependencies> - <public-packages/> - </data> - </configuration> -</project>
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/nbproject/suite.properties Sat Feb 04 15:43:40 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -suite.dir=${basedir}/..
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/Bundle.properties Sat Feb 04 15:43:40 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
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/FolderNode.java Sat Feb 04 15:43:40 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<FolderElement> 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<Group> groups) { - this.setDisplayName(name); - children.addNotify(); - - for (Group g : groups) { - content.add(g); - } - } - - @Override - public Image getOpenedIcon(int i) { - return getIcon(i); - } -}
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/GraphNode.java Sat Feb 04 15:43:40 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(); - } -}
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/OutlineTopComponent.form Sat Feb 04 15:43:40 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> - -<Form version="1.2" maxVersion="1.2" type="org.netbeans.modules.form.forminfo.JPanelFormInfo"> - <AuxValues> - <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/> - <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/> - <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/> - <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/> - <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/> - <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/> - <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> - <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> - <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> - <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/> - </AuxValues> - - <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/> - <SubComponents> - <Container class="javax.swing.JScrollPane" name="treeView"> - <AuxValues> - <AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new BeanTreeView();"/> - </AuxValues> - <Constraints> - <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription"> - <BorderConstraints direction="Center"/> - </Constraint> - </Constraints> - - <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/> - </Container> - </SubComponents> -</Form>
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/OutlineTopComponent.java Sat Feb 04 15:43:40 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. - */ - // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents - private void initComponents() { - - treeView = new BeanTreeView(); - - setLayout(new java.awt.BorderLayout()); - add(treeView, java.awt.BorderLayout.CENTER); - }// </editor-fold>//GEN-END:initComponents - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JScrollPane treeView; - // End of variables declaration//GEN-END:variables -}
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/OutlineTopComponentSettings.xml Sat Feb 04 15:43:40 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE settings PUBLIC "-//NetBeans//DTD Session settings 1.0//EN" "http://www.netbeans.org/dtds/sessionsettings-1_0.dtd"> -<settings version="1.0"> - <module name="com.sun.hotspot.igv.coordinator" spec="1.0"/> - <instanceof class="at.openide.windows.TopComponent"/> - <instanceof class="com.sun.hotspot.igv.coordinator.OutlineTopComponent"/> - <instance class="com.sun.hotspot.igv.coordinator.OutlineTopComponent" method="getDefault"/> -</settings>
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/OutlineTopComponentWstcref.xml Sat Feb 04 15:43:40 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE tc-ref PUBLIC "-//NetBeans//DTD Top Component in Mode Properties 2.0//EN" "http://www.netbeans.org/dtds/tc-ref2_0.dtd"> -<tc-ref version="2.0" > - <module name="com.sun.hotspot.igv.coordinator" spec="1.0"/> - <tc-id id="OutlineTopComponent"/> - <state opened="true"/> -</tc-ref>
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/StandardConfiguration.xml Sat Feb 04 15:43:40 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -<?xml version="1.0"?> -<!DOCTYPE Configuration PUBLIC "-//NetBeans IDE//DTD toolbar//EN" "http://www.netbeans.org/dtds/toolbar.dtd"> -<Configuration> - <Row> - <Toolbar name="Edit" position="1" visible="false"/> - <Toolbar name="File" position="1" visible="false" /> - <Toolbar name="Memory" position="1" visible="true" /> - </Row> - <Row> - <Toolbar name="WorkspaceSwitcher" /> - <Toolbar name="StatusLine" /> - </Row> -</Configuration>
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/Bundle.properties Sat Feb 04 15:43:40 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...
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/DiffGraphAction.java Sat Feb 04 15:43:40 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; - } -} -
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/DiffGraphCookie.java Sat Feb 04 15:43:40 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); - } - } -}
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/GraphOpenCookie.java Sat Feb 04 15:43:40 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); - } -}
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/GraphRemoveCookie.java Sat Feb 04 15:43:40 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); - } -}
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/ImportAction.java Sat Feb 04 15:43:40 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; - } -}
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/OutlineAction.java Sat Feb 04 15:43:40 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(); - } -}
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/RemoveAction.java Sat Feb 04 15:43:40 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; - } -}
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/RemoveAllAction.java Sat Feb 04 15:43:40 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(); - } -}
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/RemoveCookie.java Sat Feb 04 15:43:40 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(); -}
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/SaveAllAction.java Sat Feb 04 15:43:40 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; - } -}
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/SaveAsAction.java Sat Feb 04 15:43:40 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; - } -}
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/customLeftWsmode.xml Sat Feb 04 15:43:40 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<mode version="2.1"> - <name unique="customLeft" /> - <kind type="view" /> - <state type="joined" /> - <constraints> - <path orientation="horizontal" number="0" weight="0.2"/> - <path orientation="vertical" number="0" weight="0.75"/> - </constraints> - <bounds x="0" y="0" width="0" height="0" /> - <frame state="0"/> - <active-tc id="OutlineTopComponent"/> - <empty-behavior permanent="false"/> -</mode>
Binary file src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/diff.png has changed
Binary file src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/folder.png has changed
Binary file src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/graph.png has changed
Binary file src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/import.png has changed
Binary file src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/remove.png has changed
Binary file src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/removeall.png has changed
Binary file src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/save.png has changed
Binary file src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/saveall.gif has changed
Binary file src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/structure.png has changed
Binary file src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/structured.gif has changed
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/layer.xml Sat Feb 04 15:43:40 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,198 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.2//EN" "http://www.netbeans.org/dtds/filesystem-1_2.dtd"> -<filesystem> - <folder name="Actions"> - <folder name="File"> - <file name="com-sun-hotspot-igv-coordinator-actions-SaveAsAction.instance"/> - <file name="com-sun-hotspot-igv-coordinator-actions-SaveAllAction.instance"/> - <file name="com-sun-hotspot-igv-coordinator-actions-ImportAction.instance"/> - </folder> - <folder name="Edit"> - <file name="com-sun-hotspot-igv-coordinator-actions-RemoveAction.instance"/> - <file name="com-sun-hotspot-igv-coordinator-actions-RemoveAllAction.instance"/> - </folder> - <folder name="Window"> - <file name="com-sun-hotspot-igv-coordinator-actions-OutlineAction.instance"/> - </folder> - </folder> - - <folder name="Menu"> - <folder name="File"> - <file name="Separator2.instance_hidden"/> - <file name="Separator3.instance_hidden"/> - <file name="SeparatorOpen.instance_hidden"/> - <file name="com-sun-hotspot-igv-coordinator-actions-ImportAction.shadow"> - <attr name="originalFile" stringvalue="Actions/File/com-sun-hotspot-igv-coordinator-actions-ImportAction.instance"/> - <attr name="position" intvalue="100"/> - </file> - <file name="SeparatorSave.instance"> - <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/> - <attr name="position" intvalue="150"/> - </file> - <file name="com-sun-hotspot-igv-coordinator-actions-SaveAsAction.shadow"> - <attr name="originalFile" stringvalue="Actions/File/com-sun-hotspot-igv-coordinator-actions-SaveAsAction.instance"/> - <attr name="position" intvalue="200"/> - </file> - <file name="com-sun-hotspot-igv-coordinator-actions-SaveAllAction.shadow"> - <attr name="originalFile" stringvalue="Actions/File/com-sun-hotspot-igv-coordinator-actions-SaveAllAction.instance"/> - <attr name="position" intvalue="300"/> - </file> - <file name="SeparatorRemove.instance"> - <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/> - <attr name="position" intvalue="350"/> - </file> - <file name="com-sun-hotspot-igv-coordinator-actions-RemoveAction.shadow"> - <attr name="originalFile" stringvalue="Actions/Edit/com-sun-hotspot-igv-coordinator-actions-RemoveAction.instance"/> - <attr name="position" intvalue="400" /> - </file> - <file name="com-sun-hotspot-igv-coordinator-actions-RemoveAllAction.shadow"> - <attr name="originalFile" stringvalue="Actions/Edit/com-sun-hotspot-igv-coordinator-actions-RemoveAllAction.instance"/> - <attr name="position" intvalue="500" /> - </file> - - <!-- Hidden menu entries from other modules --> - <file name="org-netbeans-modules-editor-ExportHtmlAction.shadow_hidden"/> - <file name="org-netbeans-modules-openfile-OpenFileAction.shadow_hidden"/> - <file name="org-netbeans-modules-openfile-RecentFileAction.shadow_hidden"/> - <file name="org-netbeans-modules-print-action-PageSetupAction.shadow_hidden"/> - <file name="org-netbeans-modules-print-action-PrintAction.shadow_hidden"/> - <file name="org-netbeans-modules-project-ui-CloseProject.shadow_hidden"/> - <file name="org-netbeans-modules-project-ui-CustomizeProject.shadow_hidden"/> - <file name="org-netbeans-modules-project-ui-NewFile.shadow_hidden"/> - <file name="org-netbeans-modules-project-ui-NewProject.shadow_hidden"/> - <file name="org-netbeans-modules-project-ui-OpenProject.shadow_hidden"/> - <file name="org-netbeans-modules-project-ui-RecentProjects.shadow_hidden"/> - <file name="org-netbeans-modules-project-ui-groups-GroupsMenu.shadow_hidden"/> - <file name="org-openide-actions-SaveAction.shadow_hidden"/> - <file name="org-openide-actions-SaveAllAction.shadow_hidden"/> - <file name="org-openide-actions-SaveAsAction.shadow_hidden"/> - </folder> - - <folder name="Edit"> - <!-- Hidden menu entries from other modules --> - <file name="Separator1.instance_hidden"/> - <file name="Separator2.instance_hidden"/> - <file name="SeparatorAfterFindPrevious.instance_hidden"/> - <file name="SeparatorAfterProjectsSearch.instance_hidden"/> - <file name="WhereUsedAction.shadow_hidden"/> - <file name="org-netbeans-modules-editor-MainMenuAction$FindNextAction.instance_hidden"/> - <file name="org-netbeans-modules-editor-MainMenuAction$FindPreviousAction.instance_hidden"/> - <file name="org-netbeans-modules-editor-MainMenuAction$FindSelectionAction.instance_hidden"/> - <file name="org-netbeans-modules-editor-MainMenuAction$PasteFormattedAction.instance_hidden"/> - <file name="org-netbeans-modules-editor-MainMenuAction$SelectAllAction.instance_hidden"/> - <file name="org-netbeans-modules-editor-MainMenuAction$SelectIdentifierAction.instance_hidden"/> - <file name="org-netbeans-modules-editor-MainMenuAction$StartMacroRecordingAction.instance_hidden"/> - <file name="org-netbeans-modules-editor-MainMenuAction$StopMacroRecordingAction.instance_hidden"/> - <file name="org-netbeans-modules-search-FindInFilesAction.shadow_hidden"/> - <file name="org-netbeans-modules-search-ReplaceInFilesAction.shadow_hidden"/> - <file name="org-openide-actions-CopyAction.shadow_hidden"/> - <file name="org-openide-actions-CutAction.shadow_hidden"/> - <file name="org-openide-actions-DeleteAction.shadow_hidden"/> - <file name="org-openide-actions-FindAction.shadow_hidden"/> - <file name="org-openide-actions-PasteAction.shadow_hidden"/> - <file name="org-openide-actions-ReplaceAction.shadow_hidden"/> - <file name="sep-before-reposearch.instance_hidden"/> - </folder> - - <folder name="View"> - <!-- Hidden menu entries from other modules --> - <file name="Separator1.instance_hidden"/> - <file name="Separator2.instance_hidden"/> - <file name="org-netbeans-core-actions-HTMLViewAction.shadow_hidden"/> - <file name="org-netbeans-core-actions-LogAction.shadow_hidden"/> - <file name="org-netbeans-core-multiview-EditorsAction.instance_hidden"/> - <file name="org-netbeans-core-windows-actions-ToolbarsListAction.instance_hidden"/> - <file name="org-netbeans-modules-editor-NbCodeFoldingAction.instance_hidden"/> - <file name="org-netbeans-modules-project-ui-SyncEditorWithViewsAction.shadow_hidden"/> - <file name="org-netbeans-modules-versioning-ShowTextAnnotationsAction.shadow_hidden"/> - <file name="org-netbeans-modules-versioning-diff-ShowDiffSidebarAction.shadow_hidden"/> - <file name="toggle-line-numbers.shadow_hidden"/> - <file name="toggle-non-printable-characters.shadow_hidden"/> - <file name="toggle-toolbar.shadow_hidden"/> - </folder> - - <!-- Hidden menus --> - <folder name="GoTo_hidden"/> - <folder name="Source_hidden"/> - <folder name="Refactoring_hidden"/> - <folder name="BuildProject_hidden"/> - <folder name="RunProject_hidden"/> - <folder name="Versioning_hidden"/> - - <folder name="Tools"> - <!-- Hidden menu entries from other modules --> - <file name="LibrariesCustomizerAction.shadow_hidden"/> - <file name="PaletteManager_hidden"/> - <file name="Separator1.instance_hidden"/> - <file name="Separator2.instance_hidden"/> - <file name="ServerManagerAction3.shadow_hidden"/> - <file name="VariablesCustomizerAction.shadow_hidden"/> - <file name="org-netbeans-modules-autoupdate-ui-actions-PluginManagerAction.shadow_hidden"/> - <file name="org-netbeans-modules-favorites-templates-TemplatesAction.shadow_hidden"/> - <file name="org-netbeans-modules-options-OptionsWindowAction-separatorBefore.instance_hidden"/> - <file name="org-netbeans-modules-xml-catalog-CatalogAction.shadow_hidden"/> - <file name="org-openide-actions-ToolsAction.shadow_hidden"/> - </folder> - - <folder name="Window"> - <file name="OutlineAction.shadow"> - <attr name="originalFile" stringvalue="Actions/Window/com-sun-hotspot-igv-coordinator-actions-OutlineAction.instance"/> - </file> - - <!-- Hidden menu entries from other modules --> - <file name="Debug_hidden"/> - <file name="Navigator_hidden"/> - <file name="Other_hidden"/> - <file name="Output_hidden"/> - <file name="ProgressListAction.shadow_hidden"/> - <file name="ShowPaletteAction.shadow_hidden"/> - <file name="SwitchToRecentDocumentAction.shadow_hidden"/> - <file name="Versioning_hidden"/> - <file name="org-netbeans-core-ide-ServicesTabAction.shadow_hidden"/> - <file name="org-netbeans-modules-favorites-View.shadow_hidden"/> - <file name="org-netbeans-modules-project-ui-logical-tab-action.shadow_hidden"/> - <file name="org-netbeans-modules-project-ui-physical-tab-action.shadow_hidden"/> - <file name="org-netbeans-modules-tasklist-ui-TaskListAction.shadow_hidden"/> - <file name="CloneDocumentAction.shadow_hidden"/> - </folder> - - <folder name="Help"> - <!-- Hidden menu entries from other modules --> - <file name="Separator1.instance_hidden"/> - <file name="netbeans-kb.url_hidden"/> - <file name="org-netbeans-modules-autoupdate-ui-actions-CheckForUpdatesAction.shadow_hidden"/> - <file name="org-netbeans-modules-bugzilla-ReportNBIssueAction.shadow_hidden"/> - <file name="org-netbeans-modules-usersguide-master.xml_hidden"/> - <file name="shortcuts.xml_hidden"/> - </folder> - </folder> - - <folder name="OptionsDialog"> - <!-- Hidden option tabs from other modules --> - <file name="Editor.instance_hidden"/> - <file name="FontsAndColors.instance_hidden"/> - <file name="General.instance_hidden"/> - <file name="Keymaps.instance_hidden"/> - <folder name="Advanced"> - <file name="Files.instance_hidden"/> - <file name="IssueTracking.instance_hidden"/> - <file name="JavaScript.instance_hidden"/> - <file name="Spellchecker.instance_hidden"/> - <file name="TermAdvancedOption.instance_hidden"/> - <file name="ToDo.instance_hidden"/> - <file name="Versioning.instance_hidden"/> - </folder> - </folder> - - <folder name="Windows2"> - <folder name="Components"> - <file name="OutlineTopComponent.settings" url="OutlineTopComponentSettings.xml"/> - </folder> - <folder name="Modes"> - <file name="customLeft.wsmode" url="customLeftWsmode.xml"/> - <folder name="customLeft"> - <file name="OutlineTopComponent.wstcref" url="OutlineTopComponentWstcref.xml"/> - </folder> - </folder> - </folder> -</filesystem>
--- a/src/share/tools/IdealGraphVisualizer/Data/manifest.mf Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Data/manifest.mf Sun Feb 05 05:40:36 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 +
--- a/src/share/tools/IdealGraphVisualizer/Data/nbproject/project.xml Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Data/nbproject/project.xml Sun Feb 05 05:40:36 2012 +0100 @@ -1,29 +1,33 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://www.netbeans.org/ns/project/1"> - <type>org.netbeans.modules.apisupport.project</type> - <configuration> - <data xmlns="http://www.netbeans.org/ns/nb-module-project/3"> - <code-name-base>com.sun.hotspot.igv.data</code-name-base> - <suite-component/> - <module-dependencies/> - <test-dependencies> - <test-type> - <name>unit</name> - <test-dependency> - <code-name-base>org.netbeans.libs.junit4</code-name-base> - <compile-dependency/> - </test-dependency> - <test-dependency> - <code-name-base>org.openide.util</code-name-base> - <compile-dependency/> - </test-dependency> - </test-type> - </test-dependencies> - <public-packages> - <package>com.sun.hotspot.igv.data</package> - <package>com.sun.hotspot.igv.data.serialization</package> - <package>com.sun.hotspot.igv.data.services</package> - </public-packages> - </data> - </configuration> -</project> +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://www.netbeans.org/ns/project/1"> + <type>org.netbeans.modules.apisupport.project</type> + <configuration> + <data xmlns="http://www.netbeans.org/ns/nb-module-project/3"> + <code-name-base>com.sun.hotspot.igv.data</code-name-base> + <suite-component/> + <module-dependencies/> + <test-dependencies> + <test-type> + <name>unit</name> + <test-dependency> + <code-name-base>org.netbeans.libs.junit4</code-name-base> + <compile-dependency/> + </test-dependency> + <test-dependency> + <code-name-base>org.openide.util</code-name-base> + <compile-dependency/> + </test-dependency> + </test-type> + </test-dependencies> + <public-packages> + <package>at.ssw.visualizer.model.bc</package> + <package>at.ssw.visualizer.model.cfg</package> + <package>at.ssw.visualizer.model.interval</package> + <package>at.ssw.visualizer.model.nc</package> + <package>com.sun.hotspot.igv.data</package> + <package>com.sun.hotspot.igv.data.serialization</package> + <package>com.sun.hotspot.igv.data.services</package> + </public-packages> + </data> + </configuration> +</project>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/bc/Bytecodes.java Sun Feb 05 05:40:36 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(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/cfg/BasicBlock.java Sun Feb 05 05:40:36 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<? extends BasicBlock> getPredecessors(); + + public List<? extends BasicBlock> getSuccessors(); + + public List<? extends BasicBlock> getXhandlers(); + + public List<String> getFlags(); + + public BasicBlock getDominator(); + + public int getLoopIndex(); + + public int getLoopDepth(); + + public boolean hasState(); + + public List<State> getStates(); + + public boolean hasHir(); + + public List<IRInstruction> getHirInstructions(); + + public boolean hasLir(); + + public List<IRInstruction> getLirOperations(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/cfg/ControlFlowGraph.java Sun Feb 05 05:40:36 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<BasicBlock> getBasicBlocks(); + + public BasicBlock getBasicBlockByName(String name); + + public Bytecodes getBytecodes(); + + public NativeMethod getNativeMethod(); + + public boolean hasState(); + + public boolean hasHir(); + + public boolean hasLir(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/cfg/IRInstruction.java Sun Feb 05 05:40:36 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<String> getNames(); + public String getValue(String name); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/cfg/State.java Sun Feb 05 05:40:36 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<StateEntry> getEntries(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/cfg/StateEntry.java Sun Feb 05 05:40:36 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<String> getPhiOperands(); + + public String getOperand(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/interval/ChildInterval.java Sun Feb 05 05:40:36 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<Range> getRanges(); + + public List<UsePosition> getUsePositions(); + + public int getFrom(); + + public int getTo(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/interval/Interval.java Sun Feb 05 05:40:36 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<ChildInterval> getChildren(); + + public String getRegNum(); + + public int getFrom(); + + public int getTo(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/interval/IntervalList.java Sun Feb 05 05:40:36 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<Interval> getIntervals(); + + public ControlFlowGraph getControlFlowGraph(); + + public int getNumLIROperations(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/interval/Range.java Sun Feb 05 05:40:36 2012 +0100 @@ -0,0 +1,11 @@ +package at.ssw.visualizer.model.interval; + +/** + * + * @author Christian Wimmer + */ +public interface Range { + public int getFrom(); + + public int getTo(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/interval/UsePosition.java Sun Feb 05 05:40:36 2012 +0100 @@ -0,0 +1,11 @@ +package at.ssw.visualizer.model.interval; + +/** + * + * @author Christian Wimmer + */ +public interface UsePosition { + public char getKind(); + + public int getPosition(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/model/nc/NativeMethod.java Sun Feb 05 05:40:36 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(); + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/bc/BytecodesImpl.java Sun Feb 05 05:40:36 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(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/cfg/BasicBlockImpl.java Sun Feb 05 05:40:36 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<BasicBlock> getPredecessors() { + return Collections.unmodifiableList(Arrays.asList(predecessors)); + } + + public List<BasicBlock> getSuccessors() { + return Collections.unmodifiableList(Arrays.asList(successors)); + } + + public List<BasicBlock> getXhandlers() { + return Collections.unmodifiableList(Arrays.asList(xhandlers)); + } + + public List<String> 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<State> getStates() { + return Collections.unmodifiableList(Arrays.asList(states)); + } + + public boolean hasHir() { + return hirInstructions != null; + } + + public List<IRInstruction> getHirInstructions() { + return Collections.unmodifiableList(Arrays.asList(hirInstructions)); + } + + public boolean hasLir() { + return lirOperations != null; + } + + public List<IRInstruction> getLirOperations() { + return Collections.unmodifiableList(Arrays.asList(lirOperations)); + } + + @Override + public String toString() { + return name; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/cfg/IRInstructionImpl.java Sun Feb 05 05:40:36 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<String, String> data; + + public IRInstructionImpl(LinkedHashMap<String, String> data) { + this.data = data; + } + + public IRInstructionImpl(String pinned, int bci, int useCount, String name, String text, String operand) { + data = new LinkedHashMap<String, String>(); + 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<String, String>(); + data.put(LIR_NUMBER, Integer.toString(number)); + data.put(LIR_TEXT, text); + } + + public Collection<String> getNames() { + return Collections.unmodifiableSet(data.keySet()); + } + + public String getValue(String name) { + return data.get(name); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/cfg/StateEntryImpl.java Sun Feb 05 05:40:36 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<String> getPhiOperands() { + return Collections.unmodifiableList(Arrays.asList(phiOperands)); + } + + public String getOperand() { + return operand; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/cfg/StateImpl.java Sun Feb 05 05:40:36 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<StateEntry> getEntries() { + return Collections.unmodifiableList(Arrays.asList(entries)); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/interval/ChildIntervalImpl.java Sun Feb 05 05:40:36 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<ChildIntervalImpl> { + 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<Range> getRanges() { + return Collections.unmodifiableList(Arrays.asList(ranges)); + } + + public List<UsePosition> 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(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/interval/IntervalImpl.java Sun Feb 05 05:40:36 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<ChildInterval> 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(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/interval/IntervalListImpl.java Sun Feb 05 05:40:36 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<Interval> 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"; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/interval/RangeImpl.java Sun Feb 05 05:40:36 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<RangeImpl> { + 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 + "]"; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/interval/UsePositionImpl.java Sun Feb 05 05:40:36 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<UsePositionImpl> { + 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 + ")"; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/at/ssw/visualizer/modelimpl/nc/NativeMethodImpl.java Sun Feb 05 05:40:36 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; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/AbstractFolderElement.java Sun Feb 05 05:40:36 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; + } +}
--- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Bundle.properties Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Bundle.properties Sun Feb 05 05:40:36 2012 +0100 @@ -1,1 +1,1 @@ -OpenIDE-Module-Name=Data +OpenIDE-Module-Name=Data
--- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/ChangedEvent.java Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/ChangedEvent.java Sun Feb 05 05:40:36 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 <T> - */ public class ChangedEvent<T> extends Event<ChangedListener<T>> { 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<T> l) { l.changed(object); } + + public void changeObject(T newObject) { + if (object != newObject) { + this.object = newObject; + fire(); + } + } }
--- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Event.java Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Event.java Sun Feb 05 05:40:36 2012 +0100 @@ -45,6 +45,11 @@ listener.add(l); } + public void addListenerAndFire(L l) { + addListener(l); + fire(l); + } + /** * Remove listener * @param l
--- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Folder.java Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Folder.java Sun Feb 05 05:40:36 2012 +0100 @@ -26,6 +26,7 @@ import java.util.List; public interface Folder { + String getName(); List<? extends FolderElement> getElements(); void removeElement(FolderElement element); void addElement(FolderElement group);
--- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/GraphDocument.java Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/GraphDocument.java Sun Feb 05 05:40:36 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"; + } }
--- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputBlock.java Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputBlock.java Sun Feb 05 05:40:36 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<InputNode> nodes; private String name; private InputGraph graph; - private Set<InputBlock> successors; + private List<InputBlock> successors; + private List<InputBlock> 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<InputBlock> getSuccessors() { - return Collections.unmodifiableSet(successors); + @Override + public List<InputBlock> 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<InputBlock> getPredecessors() { + return Collections.unmodifiableList(predecessors); + } + + @Override + public List<BasicBlock> getXhandlers() { + // TODO(tw): Implement. + return Collections.emptyList(); + } + + @Override + public List<String> 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<State> getStates() { + // TODO(tw): Implement. + return Collections.emptyList(); + } + + @Override + public boolean hasHir() { + // TODO(tw): Implement. + return false; + } + + @Override + public List<IRInstruction> getHirInstructions() { + // TODO(tw): Implement. + return Collections.emptyList(); + } + + @Override + public boolean hasLir() { + // TODO(tw): Implement. + return false; + } + + @Override + public List<IRInstruction> getLirOperations() { + // TODO(tw): Implement. + return Collections.emptyList(); + } }
--- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputGraph.java Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputGraph.java Sun Feb 05 05:40:36 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<Integer, InputNode> nodes; private Set<InputEdge> edges; @@ -293,4 +297,44 @@ public Folder getParent() { return parent; } + + @Override + public List<BasicBlock> getBasicBlocks() { + return new ArrayList<BasicBlock>(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; + } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Draw2DLibrary/manifest.mf Sun Feb 05 05:40:36 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 +
Binary file src/share/tools/IdealGraphVisualizer/Draw2DLibrary/release/modules/ext/org.eclipse.draw2d_3.1.0.jar has changed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Draw2DLibrary/src/org/eclipse/draw2d/Bundle.properties Sun Feb 05 05:40:36 2012 +0100 @@ -0,0 +1,1 @@ +OpenIDE-Module-Name=Draw2DLibrary
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Editor/manifest.mf Sun Feb 05 05:40:36 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 +
--- /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 Sun Feb 05 05:40:36 2012 +0100 @@ -0,0 +1,1 @@ +com.oracle.graal.visualizer.editor.GraphViewerImplementation
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/Bundle.properties Sun Feb 05 05:40:36 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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/CompilationViewer.java Sun Feb 05 05:40:36 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(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/CompilationViewerFactory.java Sun Feb 05 05:40:36 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(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/DiagramViewModel.java Sun Feb 05 05:40:36 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<Integer> hiddenNodes; + private Set<Integer> onScreenNodes; + private Set<Integer> selectedNodes; + private FilterChain filterChain; + private FilterChain sequenceFilterChain; + private Diagram diagram; + private InputGraph inputGraph; + private ChangedEvent<DiagramViewModel> diagramChangedEvent; + private ChangedEvent<DiagramViewModel> viewChangedEvent; + private ChangedEvent<DiagramViewModel> hiddenNodesChangedEvent; + private ChangedEvent<DiagramViewModel> viewPropertiesChangedEvent; + private boolean showNodeHull; + private final InputGraph secondGraph; + private final InputGraph firstGraph; + private ChangedListener<FilterChain> filterChainChangedListener = new ChangedListener<FilterChain>() { + + @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<DiagramViewModel> getDiagramChangedEvent() { + return diagramChangedEvent; + } + + public ChangedEvent<DiagramViewModel> getViewChangedEvent() { + return viewChangedEvent; + } + + public ChangedEvent<DiagramViewModel> getHiddenNodesChangedEvent() { + return hiddenNodesChangedEvent; + } + + public ChangedEvent<DiagramViewModel> getViewPropertiesChangedEvent() { + return viewPropertiesChangedEvent; + } + + public Set<Integer> getSelectedNodes() { + return selectedNodes; + } + + public Set<Integer> getHiddenNodes() { + return hiddenNodes; + } + + public Set<Integer> getOnScreenNodes() { + return onScreenNodes; + } + + public void setSelectedNodes(Set<Integer> nodes) { + this.selectedNodes = nodes; + /* List<Color> 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<Integer> nodes) { + System.out.println("Shownot called with " + nodes); + setHiddenNodes(nodes); + } + + public void showFigures(Collection<Figure> f) { + HashSet<Integer> newHiddenNodes = new HashSet<>(getHiddenNodes()); + for (Figure fig : f) { + newHiddenNodes.removeAll(fig.getSource().getSourceNodesAsSet()); + } + setHiddenNodes(newHiddenNodes); + } + + public Set<Figure> getSelectedFigures() { + Set<Figure> 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<Figure> f) { + showFigures(f); + } + + public void showOnly(final Set<Integer> nodes) { + final HashSet<Integer> allNodes = new HashSet<>(getGraphToView().getGroup().getAllNodes()); + allNodes.removeAll(nodes); + setHiddenNodes(allNodes); + } + + public void setHiddenNodes(Set<Integer> nodes) { + this.hiddenNodes = nodes; + hiddenNodesChangedEvent.fire(); + } + + public void setOnScreenNodes(Set<Integer> 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<String> calculateStringList(Group g) { + List<String> 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<Figure> list) { + Set<Integer> newSelectedNodes = new HashSet<>(); + for (Figure f : list) { + newSelectedNodes.addAll(f.getSource().getSourceNodesAsSet()); + } + this.setSelectedNodes(newSelectedNodes); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/EditorTopComponent.form Sun Feb 05 05:40:36 2012 +0100 @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8" ?> + +<Form version="1.2" maxVersion="1.2" type="org.netbeans.modules.form.forminfo.JPanelFormInfo"> + <NonVisualComponents> + <Component class="javax.swing.JCheckBox" name="jCheckBox1"> + <Properties> + <Property name="text" type="java.lang.String" value="jCheckBox1"/> + <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor"> + <Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo"> + <EmptyBorder bottom="0" left="0" right="0" top="0"/> + </Border> + </Property> + <Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor"> + <Insets value="[0, 0, 0, 0]"/> + </Property> + </Properties> + </Component> + </NonVisualComponents> + <AuxValues> + <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/> + <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/> + <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/> + <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/> + <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> + <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> + <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/> + </AuxValues> + + <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/> +</Form>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/EditorTopComponent.java Sun Feb 05 05:40:36 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<String, CompilationViewer> 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<? extends CompilationViewerFactory> 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<AbstractButton> 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<String> calculateStringList(Group g) { + List<String> result = new ArrayList<>(); + for (InputGraph graph : g.getGraphs()) { + result.add(graph.getName()); + } + return result; + } + + private RangeSliderModel getModel() { + return rangeSliderModel; + } + + public static EditorTopComponent getActive() { + Set<? extends Mode> 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. + */ + // <editor-fold defaultstate="collapsed" desc="Generated Code">//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()); + }// </editor-fold>//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<RangeSliderModel> rangeSliderListener = new ChangedListener<RangeSliderModel>() { + + @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(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/ExportCookie.java Sun Feb 05 05:40:36 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); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/GraphViewerImplementation.java Sun Feb 05 05:40:36 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(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/NodeQuickSearch.java Sun Feb 05 05:40:36 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<InputNode> matches = null; + try { + RegexpPropertyMatcher matcher = new RegexpPropertyMatcher(name, value, Pattern.CASE_INSENSITIVE); + Properties.PropertySelector<InputNode> 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<InputNode> 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<InputNode> 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!"); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/SplitCompilationViewer.java Sun Feb 05 05:40:36 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(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/SplitCompilationViewerFactory.java Sun Feb 05 05:40:36 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); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Editor/src/com/oracle/graal/visualizer/editor/layer.xml Sun Feb 05 05:40:36 2012 +0100 @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.1//EN" "http://www.netbeans.org/dtds/filesystem-1_1.dtd"> +<filesystem> + <folder name="QuickSearch"> + <folder name="Nodes"> + <attr name="command" stringvalue="n"/> + <attr name="position" intvalue="0"/> + <file name="com-oracle-graal-visualizer-editor-NodeQuickSearch.instance"/> + </folder> + </folder> + + <folder name="QuickSearchShadow"> + <file name="org-netbeans-modules-quicksearch-QuickSearchAction.shadow"> + <attr name="originalFile" stringvalue="Actions/Edit/org-netbeans-modules-quicksearch-QuickSearchAction.instance"/> + </file> + </folder> +</filesystem>
--- a/src/share/tools/IdealGraphVisualizer/Graal/src/com/sun/hotspot/igv/graal/Bundle.properties Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Graal/src/com/sun/hotspot/igv/graal/Bundle.properties Sun Feb 05 05:40:36 2012 +0100 @@ -1,1 +1,1 @@ -OpenIDE-Module-Name=Graal Compiler Support +OpenIDE-Module-Name=GraalCompilerSupport
--- a/src/share/tools/IdealGraphVisualizer/NetworkConnection/build.xml Sat Feb 04 15:43:40 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- You may freely edit this file. See harness/README in the NetBeans platform --> -<!-- for some information on what you could do (e.g. targets to override). --> -<!-- If you delete this file and reopen the project it will be recreated. --> -<project name="com.sun.hotspot.igv.connection" default="netbeans" basedir="."> - <description>Builds, tests, and runs the project com.sun.hotspot.igv.connection.</description> - <import file="nbproject/build-impl.xml"/> -</project>
--- a/src/share/tools/IdealGraphVisualizer/NetworkConnection/manifest.mf Sat Feb 04 15:43:40 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 -
--- a/src/share/tools/IdealGraphVisualizer/NetworkConnection/nbproject/build-impl.xml Sat Feb 04 15:43:40 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- -*** GENERATED FROM project.xml - DO NOT EDIT *** -*** EDIT ../build.xml INSTEAD *** ---> -<project name="com.sun.hotspot.igv.connection-impl" basedir=".."> - <fail message="Please build using Ant 1.7.1 or higher."> - <condition> - <not> - <antversion atleast="1.7.1"/> - </not> - </condition> - </fail> - <property file="nbproject/private/suite-private.properties"/> - <property file="nbproject/suite.properties"/> - <fail unless="suite.dir">You must set 'suite.dir' to point to your containing module suite</fail> - <property file="${suite.dir}/nbproject/private/platform-private.properties"/> - <property file="${suite.dir}/nbproject/platform.properties"/> - <macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-project/2"> - <attribute name="name"/> - <attribute name="value"/> - <sequential> - <property name="@{name}" value="${@{value}}"/> - </sequential> - </macrodef> - <macrodef name="evalprops" uri="http://www.netbeans.org/ns/nb-module-project/2"> - <attribute name="property"/> - <attribute name="value"/> - <sequential> - <property name="@{property}" value="@{value}"/> - </sequential> - </macrodef> - <property file="${user.properties.file}"/> - <nbmproject2:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/> - <nbmproject2:property name="nbplatform.active.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/> - <nbmproject2:evalprops property="cluster.path.evaluated" value="${cluster.path}" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/> - <fail message="Path to 'platform' cluster missing in $${cluster.path} property or using corrupt Netbeans Platform (missing harness)."> - <condition> - <not> - <contains string="${cluster.path.evaluated}" substring="platform"/> - </not> - </condition> - </fail> - <import file="${harness.dir}/build.xml"/> -</project>
--- a/src/share/tools/IdealGraphVisualizer/NetworkConnection/nbproject/genfiles.properties Sat Feb 04 15:43:40 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
--- a/src/share/tools/IdealGraphVisualizer/NetworkConnection/nbproject/project.properties Sat Feb 04 15:43:40 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
--- a/src/share/tools/IdealGraphVisualizer/NetworkConnection/nbproject/project.xml Sat Feb 04 15:43:40 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://www.netbeans.org/ns/project/1"> - <type>org.netbeans.modules.apisupport.project</type> - <configuration> - <data xmlns="http://www.netbeans.org/ns/nb-module-project/3"> - <code-name-base>com.sun.hotspot.igv.connection</code-name-base> - <suite-component/> - <module-dependencies> - <dependency> - <code-name-base>com.sun.hotspot.igv.data</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>1.0</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>com.sun.hotspot.igv.settings</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>1.0</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>org.openide.awt</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>7.30.1</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>org.openide.dialogs</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>7.18.1</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>org.openide.util</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>8.14.1</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>org.openide.util.lookup</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>8.6.1</specification-version> - </run-dependency> - </dependency> - </module-dependencies> - <public-packages> - <package>com.sun.hotspot.igv.connection</package> - </public-packages> - </data> - </configuration> -</project>
--- a/src/share/tools/IdealGraphVisualizer/NetworkConnection/nbproject/suite.properties Sat Feb 04 15:43:40 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -suite.dir=${basedir}/..
--- a/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Bundle.properties Sat Feb 04 15:43:40 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -OpenIDE-Module-Name=NetworkConnection
--- a/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Client.java Sat Feb 04 15:43:40 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
--- a/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Server.java Sat Feb 04 15:43:40 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); - } -}
--- a/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/layer.xml Sat Feb 04 15:43:40 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.1//EN" "http://www.netbeans.org/dtds/filesystem-1_1.dtd"> -<filesystem> -</filesystem>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/OutlineView/manifest.mf Sun Feb 05 05:40:36 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 +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/Bundle.properties Sun Feb 05 05:40:36 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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/CompilationNode.java Sun Feb 05 05:40:36 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<InputGraph> 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<Folder> { + + 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<Folder> 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<Action> 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); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/OutlineTopComponent.form Sun Feb 05 05:40:36 2012 +0100 @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8" ?> + +<Form version="1.2" maxVersion="1.2" type="org.netbeans.modules.form.forminfo.JPanelFormInfo"> + <AuxValues> + <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/> + <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/> + <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/> + <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/> + <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> + <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> + <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/> + </AuxValues> + + <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/> + <SubComponents> + <Container class="javax.swing.JScrollPane" name="treeView"> + <AuxValues> + <AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new BeanTreeView();"/> + </AuxValues> + <Constraints> + <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription"> + <BorderConstraints direction="Center"/> + </Constraint> + </Constraints> + + <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/> + </Container> + </SubComponents> +</Form>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/OutlineTopComponent.java Sun Feb 05 05:40:36 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. + */ + // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents + private void initComponents() { + + treeView = new BeanTreeView(); + + setLayout(new java.awt.BorderLayout()); + add(treeView, java.awt.BorderLayout.CENTER); + }// </editor-fold>//GEN-END:initComponents + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JScrollPane treeView; + // End of variables declaration//GEN-END:variables +}
--- /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 Sun Feb 05 05:40:36 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)); + } + } + } +}
--- /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 Sun Feb 05 05:40:36 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<FolderElement> elements; + + public RemoveAction(List<FolderElement> elements) { + this.elements = elements; + } + + @Override + public void actionPerformed(ActionEvent e) { + for (FolderElement element : elements) { + element.getParent().removeElement(element); + } + } +}
--- /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 Sun Feb 05 05:40:36 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(); + } +}
--- /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 Sun Feb 05 05:40:36 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()); + } +}
--- /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 Sun Feb 05 05:40:36 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<FolderElement> elements; + + public SaveAsAction(List<FolderElement> 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()); + } + } + } +}
Binary file src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/import.png has changed
Binary file src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/leaf_node.gif has changed
Binary file src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/node.gif has changed
Binary file src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/remove.png has changed
Binary file src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/removeall.png has changed
Binary file src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/save.png has changed
Binary file src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/saveall.gif has changed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/OutlineView/src/com/oracle/graal/visualizer/outline/layer.xml Sun Feb 05 05:40:36 2012 +0100 @@ -0,0 +1,161 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.2//EN" "http://www.netbeans.org/dtds/filesystem-1_2.dtd"> +<filesystem> + <folder name="Actions"/> + + <folder name="Menu"> + <folder name="File"> + <file name="Separator2.instance_hidden"/> + <file name="Separator3.instance_hidden"/> + <file name="SeparatorOpen.instance_hidden"/> + <file name="SeparatorSave.instance"> + <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/> + <attr name="position" intvalue="150"/> + </file> + <file name="SeparatorRemove.instance"> + <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/> + <attr name="position" intvalue="350"/> + </file> + + <!-- Hidden menu entries from other modules --> + <file name="org-netbeans-modules-editor-ExportHtmlAction.shadow_hidden"/> + <file name="org-netbeans-modules-openfile-OpenFileAction.shadow_hidden"/> + <file name="org-netbeans-modules-openfile-RecentFileAction.shadow_hidden"/> + <file name="org-netbeans-modules-print-action-PageSetupAction.shadow_hidden"/> + <file name="org-netbeans-modules-print-action-PrintAction.shadow_hidden"/> + <file name="org-netbeans-modules-project-ui-CloseProject.shadow_hidden"/> + <file name="org-netbeans-modules-project-ui-CustomizeProject.shadow_hidden"/> + <file name="org-netbeans-modules-project-ui-NewFile.shadow_hidden"/> + <file name="org-netbeans-modules-project-ui-NewProject.shadow_hidden"/> + <file name="org-netbeans-modules-project-ui-OpenProject.shadow_hidden"/> + <file name="org-netbeans-modules-project-ui-RecentProjects.shadow_hidden"/> + <file name="org-netbeans-modules-project-ui-groups-GroupsMenu.shadow_hidden"/> + <file name="org-openide-actions-SaveAction.shadow_hidden"/> + <file name="org-openide-actions-SaveAllAction.shadow_hidden"/> + <file name="org-openide-actions-SaveAsAction.shadow_hidden"/> + </folder> + + <folder name="Edit"> + <!-- Hidden menu entries from other modules --> + <file name="Separator1.instance_hidden"/> + <file name="Separator2.instance_hidden"/> + <file name="SeparatorAfterFindPrevious.instance_hidden"/> + <file name="SeparatorAfterProjectsSearch.instance_hidden"/> + <file name="WhereUsedAction.shadow_hidden"/> + <file name="org-netbeans-modules-editor-MainMenuAction$FindNextAction.instance_hidden"/> + <file name="org-netbeans-modules-editor-MainMenuAction$FindPreviousAction.instance_hidden"/> + <file name="org-netbeans-modules-editor-MainMenuAction$FindSelectionAction.instance_hidden"/> + <file name="org-netbeans-modules-editor-MainMenuAction$PasteFormattedAction.instance_hidden"/> + <file name="org-netbeans-modules-editor-MainMenuAction$SelectAllAction.instance_hidden"/> + <file name="org-netbeans-modules-editor-MainMenuAction$SelectIdentifierAction.instance_hidden"/> + <file name="org-netbeans-modules-editor-MainMenuAction$StartMacroRecordingAction.instance_hidden"/> + <file name="org-netbeans-modules-editor-MainMenuAction$StopMacroRecordingAction.instance_hidden"/> + <file name="org-netbeans-modules-search-FindInFilesAction.shadow_hidden"/> + <file name="org-netbeans-modules-search-ReplaceInFilesAction.shadow_hidden"/> + <file name="org-openide-actions-CopyAction.shadow_hidden"/> + <file name="org-openide-actions-CutAction.shadow_hidden"/> + <file name="org-openide-actions-DeleteAction.shadow_hidden"/> + <file name="org-openide-actions-FindAction.shadow_hidden"/> + <file name="org-openide-actions-PasteAction.shadow_hidden"/> + <file name="org-openide-actions-ReplaceAction.shadow_hidden"/> + <file name="sep-before-reposearch.instance_hidden"/> + </folder> + + <folder name="View"> + <!-- Hidden menu entries from other modules --> + <file name="Separator1.instance_hidden"/> + <file name="Separator2.instance_hidden"/> + <file name="org-netbeans-core-actions-HTMLViewAction.shadow_hidden"/> + <file name="org-netbeans-core-actions-LogAction.shadow_hidden"/> + <file name="org-netbeans-core-multiview-EditorsAction.instance_hidden"/> + <file name="org-netbeans-core-windows-actions-ToolbarsListAction.instance_hidden"/> + <file name="org-netbeans-modules-editor-NbCodeFoldingAction.instance_hidden"/> + <file name="org-netbeans-modules-project-ui-SyncEditorWithViewsAction.shadow_hidden"/> + <file name="org-netbeans-modules-versioning-ShowTextAnnotationsAction.shadow_hidden"/> + <file name="org-netbeans-modules-versioning-diff-ShowDiffSidebarAction.shadow_hidden"/> + <file name="toggle-line-numbers.shadow_hidden"/> + <file name="toggle-non-printable-characters.shadow_hidden"/> + <file name="toggle-toolbar.shadow_hidden"/> + </folder> + + <!-- Hidden menus --> + <folder name="GoTo_hidden"/> + <folder name="Source_hidden"/> + <folder name="Refactoring_hidden"/> + <folder name="BuildProject_hidden"/> + <folder name="RunProject_hidden"/> + <folder name="Versioning_hidden"/> + + <folder name="Tools"> + <!-- Hidden menu entries from other modules --> + <file name="LibrariesCustomizerAction.shadow_hidden"/> + <file name="PaletteManager_hidden"/> + <file name="Separator1.instance_hidden"/> + <file name="Separator2.instance_hidden"/> + <file name="ServerManagerAction3.shadow_hidden"/> + <file name="VariablesCustomizerAction.shadow_hidden"/> + <file name="org-netbeans-modules-autoupdate-ui-actions-PluginManagerAction.shadow_hidden"/> + <file name="org-netbeans-modules-favorites-templates-TemplatesAction.shadow_hidden"/> + <file name="org-netbeans-modules-options-OptionsWindowAction-separatorBefore.instance_hidden"/> + <file name="org-netbeans-modules-xml-catalog-CatalogAction.shadow_hidden"/> + <file name="org-openide-actions-ToolsAction.shadow_hidden"/> + </folder> + + <folder name="Window"> + + <!-- Hidden menu entries from other modules --> + <file name="Debug_hidden"/> + <file name="Navigator_hidden"/> + <file name="Other_hidden"/> + <file name="Output_hidden"/> + <file name="ProgressListAction.shadow_hidden"/> + <file name="ShowPaletteAction.shadow_hidden"/> + <file name="SwitchToRecentDocumentAction.shadow_hidden"/> + <file name="Versioning_hidden"/> + <file name="org-netbeans-core-ide-ServicesTabAction.shadow_hidden"/> + <file name="org-netbeans-modules-favorites-View.shadow_hidden"/> + <file name="org-netbeans-modules-project-ui-logical-tab-action.shadow_hidden"/> + <file name="org-netbeans-modules-project-ui-physical-tab-action.shadow_hidden"/> + <file name="org-netbeans-modules-tasklist-ui-TaskListAction.shadow_hidden"/> + <file name="CloneDocumentAction.shadow_hidden"/> + </folder> + + <folder name="Help"> + <!-- Hidden menu entries from other modules --> + <file name="Separator1.instance_hidden"/> + <file name="netbeans-kb.url_hidden"/> + <file name="org-netbeans-modules-autoupdate-ui-actions-CheckForUpdatesAction.shadow_hidden"/> + <file name="org-netbeans-modules-bugzilla-ReportNBIssueAction.shadow_hidden"/> + <file name="org-netbeans-modules-usersguide-master.xml_hidden"/> + <file name="shortcuts.xml_hidden"/> + </folder> + </folder> + + <folder name="OptionsDialog"> + <!-- Hidden option tabs from other modules --> + <file name="Editor.instance_hidden"/> + <file name="FontsAndColors.instance_hidden"/> + <file name="General.instance_hidden"/> + <file name="Keymaps.instance_hidden"/> + <folder name="Advanced"> + <file name="Files.instance_hidden"/> + <file name="IssueTracking.instance_hidden"/> + <file name="JavaScript.instance_hidden"/> + <file name="Spellchecker.instance_hidden"/> + <file name="TermAdvancedOption.instance_hidden"/> + <file name="ToDo.instance_hidden"/> + <file name="Versioning.instance_hidden"/> + </folder> + </folder> + + <folder name="Toolbars"> + <file name="Build_hidden"/> + <file name="Clipboard_hidden"/> + <file name="Debug_hidden"/> + <file name="Debugging.xml_hidden"/> + <file name="File_hidden"/> + <file name="Memory_hidden"/> + <file name="Standard.xml_hidden"/> + <file name="UndoRedo_hidden"/> + </folder> +</filesystem>
--- /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 Sun Feb 05 05:40:36 2012 +0100 @@ -0,0 +1,1 @@ +OpenIDE-Module-Name=NetworkConnection
--- /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 Sun Feb 05 05:40:36 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
--- /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 Sun Feb 05 05:40:36 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; + } +}
--- /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 Sun Feb 05 05:40:36 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(); + +}
--- /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 Sun Feb 05 05:40:36 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; + } +}
--- a/src/share/tools/IdealGraphVisualizer/SelectionCoordinator/build.xml Sat Feb 04 15:43:40 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- You may freely edit this file. See harness/README in the NetBeans platform --> -<!-- for some information on what you could do (e.g. targets to override). --> -<!-- If you delete this file and reopen the project it will be recreated. --> -<project name="com.sun.hotspot.igv.selectioncoordinator" default="netbeans" basedir="."> - <description>Builds, tests, and runs the project com.sun.hotspot.igv.selectioncoordinator.</description> - <import file="nbproject/build-impl.xml"/> -</project>
--- a/src/share/tools/IdealGraphVisualizer/SelectionCoordinator/manifest.mf Sat Feb 04 15:43:40 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 -
--- a/src/share/tools/IdealGraphVisualizer/SelectionCoordinator/nbproject/build-impl.xml Sat Feb 04 15:43:40 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- -*** GENERATED FROM project.xml - DO NOT EDIT *** -*** EDIT ../build.xml INSTEAD *** ---> -<project name="com.sun.hotspot.igv.selectioncoordinator-impl" basedir=".."> - <fail message="Please build using Ant 1.7.1 or higher."> - <condition> - <not> - <antversion atleast="1.7.1"/> - </not> - </condition> - </fail> - <property file="nbproject/private/suite-private.properties"/> - <property file="nbproject/suite.properties"/> - <fail unless="suite.dir">You must set 'suite.dir' to point to your containing module suite</fail> - <property file="${suite.dir}/nbproject/private/platform-private.properties"/> - <property file="${suite.dir}/nbproject/platform.properties"/> - <macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-project/2"> - <attribute name="name"/> - <attribute name="value"/> - <sequential> - <property name="@{name}" value="${@{value}}"/> - </sequential> - </macrodef> - <macrodef name="evalprops" uri="http://www.netbeans.org/ns/nb-module-project/2"> - <attribute name="property"/> - <attribute name="value"/> - <sequential> - <property name="@{property}" value="@{value}"/> - </sequential> - </macrodef> - <property file="${user.properties.file}"/> - <nbmproject2:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/> - <nbmproject2:property name="nbplatform.active.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/> - <nbmproject2:evalprops property="cluster.path.evaluated" value="${cluster.path}" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/> - <fail message="Path to 'platform' cluster missing in $${cluster.path} property or using corrupt Netbeans Platform (missing harness)."> - <condition> - <not> - <contains string="${cluster.path.evaluated}" substring="platform"/> - </not> - </condition> - </fail> - <import file="${harness.dir}/build.xml"/> -</project>
--- a/src/share/tools/IdealGraphVisualizer/SelectionCoordinator/nbproject/genfiles.properties Sat Feb 04 15:43:40 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
--- a/src/share/tools/IdealGraphVisualizer/SelectionCoordinator/nbproject/platform.properties Sat Feb 04 15:43:40 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
--- a/src/share/tools/IdealGraphVisualizer/SelectionCoordinator/nbproject/project.properties Sat Feb 04 15:43:40 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
--- a/src/share/tools/IdealGraphVisualizer/SelectionCoordinator/nbproject/project.xml Sat Feb 04 15:43:40 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://www.netbeans.org/ns/project/1"> - <type>org.netbeans.modules.apisupport.project</type> - <configuration> - <data xmlns="http://www.netbeans.org/ns/nb-module-project/3"> - <code-name-base>com.sun.hotspot.igv.selectioncoordinator</code-name-base> - <suite-component/> - <module-dependencies> - <dependency> - <code-name-base>com.sun.hotspot.igv.data</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>1.0</specification-version> - </run-dependency> - </dependency> - </module-dependencies> - <public-packages> - <package>com.sun.hotspot.igv.selectioncoordinator</package> - </public-packages> - </data> - </configuration> -</project>
--- a/src/share/tools/IdealGraphVisualizer/SelectionCoordinator/nbproject/suite.properties Sat Feb 04 15:43:40 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -suite.dir=${basedir}/..
--- a/src/share/tools/IdealGraphVisualizer/SelectionCoordinator/src/com/sun/hotspot/igv/selectioncoordinator/SelectionCoordinator.java Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/SelectionCoordinator/src/com/sun/hotspot/igv/selectioncoordinator/SelectionCoordinator.java Sun Feb 05 05:40:36 2012 +0100 @@ -100,7 +100,6 @@ private void highlightedObjectsChanged() { highlightedChangedEvent.fire(); - } public void addAllSelected(Set<? extends Object> s) {
--- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/build.xml Sat Feb 04 15:43:40 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- You may freely edit this file. See harness/README in the NetBeans platform --> -<!-- for some information on what you could do (e.g. targets to override). --> -<!-- If you delete this file and reopen the project it will be recreated. --> -<project name="com.sun.hotspot.igv.servercompilerscheduler" default="netbeans" basedir="."> - <description>Builds, tests, and runs the project com.sun.hotspot.igv.servercompilerscheduler.</description> - <import file="nbproject/build-impl.xml"/> -</project>
--- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/manifest.mf Sat Feb 04 15:43:40 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 -
--- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/build-impl.xml Sat Feb 04 15:43:40 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- -*** GENERATED FROM project.xml - DO NOT EDIT *** -*** EDIT ../build.xml INSTEAD *** ---> -<project name="com.sun.hotspot.igv.servercompilerscheduler-impl" basedir=".."> - <property file="nbproject/private/suite-private.properties"/> - <property file="nbproject/suite.properties"/> - <fail unless="suite.dir">You must set 'suite.dir' to point to your containing module suite</fail> - <property file="${suite.dir}/nbproject/private/platform-private.properties"/> - <property file="${suite.dir}/nbproject/platform.properties"/> - <macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-project/2"> - <attribute name="name"/> - <attribute name="value"/> - <sequential> - <property name="@{name}" value="${@{value}}"/> - </sequential> - </macrodef> - <property file="${user.properties.file}"/> - <nbmproject2:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/> - <nbmproject2:property name="netbeans.dest.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/> - <fail message="You must define 'nbplatform.${nbplatform.active}.harness.dir'"> - <condition> - <not> - <available file="${harness.dir}" type="dir"/> - </not> - </condition> - </fail> - <import file="${harness.dir}/build.xml"/> -</project>
--- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/genfiles.properties Sat Feb 04 15:43:40 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
--- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/platform.properties Sat Feb 04 15:43:40 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
--- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/project.properties Sat Feb 04 15:43:40 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
--- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/project.xml Sat Feb 04 15:43:40 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://www.netbeans.org/ns/project/1"> - <type>org.netbeans.modules.apisupport.project</type> - <configuration> - <data xmlns="http://www.netbeans.org/ns/nb-module-project/3"> - <code-name-base>com.sun.hotspot.igv.servercompiler</code-name-base> - <suite-component/> - <module-dependencies> - <dependency> - <code-name-base>com.sun.hotspot.igv.data</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>1.0</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>com.sun.hotspot.igv.graph</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>1.0</specification-version> - </run-dependency> - </dependency> - </module-dependencies> - <public-packages/> - </data> - </configuration> -</project>
--- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/suite.properties Sat Feb 04 15:43:40 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -suite.dir=${basedir}/..
--- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/META-INF/services/com.sun.hotspot.igv.data.services.Scheduler Sat Feb 04 15:43:40 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -com.sun.hotspot.igv.servercompiler.ServerCompilerScheduler
--- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/Bundle.properties Sat Feb 04 15:43:40 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -OpenIDE-Module-Name=ServerCompiler
--- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/ServerCompilerScheduler.java Sat Feb 04 15:43:40 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<Node> succs = new HashSet<>(); - public List<Node> preds = new ArrayList<>(); - public InputBlock block; - public boolean isBlockProjection; - public boolean isBlockStart; - } - private InputGraph graph; - private Collection<Node> nodes; - private Map<InputNode, Node> inputNodeToNode; - private Vector<InputBlock> blocks; - private Map<InputBlock, InputBlock> dominatorMap; - private Map<InputBlock, Integer> blockIndex; - private InputBlock[][] commonDominator; - private static final Comparator<InputEdge> edgeComparator = new Comparator<InputEdge>() { - - @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<Node> stack = new Stack<>(); - Set<Node> 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<InputBlock> schedule(InputGraph graph) { - if (graph.getNodes().isEmpty()) { - return Collections.emptyList(); - } - - if (graph.getBlocks().size() > 0) { - Collection<InputNode> 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<Node> reachable = new HashSet<>(); - reachable.add(root); - Stack<Node> 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<Node> 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<Node> 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<Node> 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<Node> reachable) { - assert !reachable.contains(n); - Stack<Node> 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<Integer> pred; - List<Integer> 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<InputBlock> 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<BlockIntermediate> intermediate = new Vector<>(graph.getBlocks().size()); - Map<InputBlock, BlockIntermediate> 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<Integer> stack = new Stack<>(); - stack.add(0); - - Vector<BlockIntermediate> 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<BlockIntermediate> 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<BlockIntermediate> 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<BlockIntermediate> 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<Integer, List<InputEdge>> edgeMap = new HashMap<>(graph.getEdges().size()); - for (InputEdge e : graph.getEdges()) { - - int to = e.getTo(); - if (!edgeMap.containsKey(to)) { - edgeMap.put(to, new ArrayList<InputEdge>()); - } - - - List<InputEdge> list = edgeMap.get(to); - list.add(e); - } - - - for (Integer i : edgeMap.keySet()) { - - List<InputEdge> 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); - } - } - } -}
--- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/color.filter Sat Feb 04 15:43:40 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
--- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/difference.filter Sat Feb 04 15:43:40 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);
--- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/matchingFlags.filter Sat Feb 04 15:43:40 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);
--- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/onlyControlFlow.filter Sat Feb 04 15:43:40 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
--- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/register.filter Sat Feb 04 15:43:40 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
--- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/remove.filter Sat Feb 04 15:43:40 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
--- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/structural.filter Sat Feb 04 15:43:40 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
--- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/layer.xml Sat Feb 04 15:43:40 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.1//EN" "http://www.netbeans.org/dtds/filesystem-1_1.dtd"> -<filesystem> - <folder name="Filters"> - <file name="C2 Basic Coloring" url="filters/color.filter"> - <attr name="enabled" boolvalue="false"/> - </file> - <file name="C2 Matcher Flags Coloring" url="filters/matchingFlags.filter"> - <attr name="enabled" boolvalue="false"/> - <attr name="after" stringvalue="C2 Basic Coloring"/> - </file> - <file name="C2 Register Coloring" url="filters/register.filter"> - <attr name="enabled" boolvalue="false"/> - <attr name="after" stringvalue="C2 Matcher Flags Coloring"/> - </file> - <file name="C2 Only Control Flow" url="filters/onlyControlFlow.filter"> - <attr name="enabled" boolvalue="false"/> - <attr name="after" stringvalue="C2 Register Coloring"/> - </file> - <file name="C2 Remove Filter" url="filters/remove.filter"> - <attr name="enabled" boolvalue="false"/> - <attr name="after" stringvalue="C2 Only Control Flow"/> - </file> - <file name="C2 Structural" url="filters/structural.filter"> - <attr name="enabled" boolvalue="false"/> - <attr name="after" stringvalue="C2 Remove Filter"/> - </file> - </folder> -</filesystem>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/SnapshotsView/manifest.mf Sun Feb 05 05:40:36 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 +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/Bundle.properties Sun Feb 05 05:40:36 2012 +0100 @@ -0,0 +1,1 @@ +OpenIDE-Module-Name=SnapshotsView
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/SnapshotTopComponent.form Sun Feb 05 05:40:36 2012 +0100 @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8" ?> + +<Form version="1.3" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JPanelFormInfo"> + <AuxValues> + <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/> + <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/> + <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/> + <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/> + <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/> + <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> + <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> + </AuxValues> + + <Layout> + <DimensionLayout dim="0"> + <Group type="103" groupAlignment="0" attributes="0"> + <EmptySpace min="0" pref="400" max="32767" attributes="0"/> + </Group> + </DimensionLayout> + <DimensionLayout dim="1"> + <Group type="103" groupAlignment="0" attributes="0"> + <EmptySpace min="0" pref="300" max="32767" attributes="0"/> + </Group> + </DimensionLayout> + </Layout> +</Form>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/SnapshotTopComponent.java Sun Feb 05 05:40:36 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<RangeSliderModel> result; + private final RangeSlider rangeSlider; + private final ChangedEvent<RangeSliderModel> rangeSliderChangedEvent = new ChangedEvent<RangeSliderModel>(null); + private final LookupListener lookupListener = new LookupListener() { + + @Override + public void resultChanged(LookupEvent le) { + update(); + } + }; + + private final ChangedListener<RangeSliderModel> rangeSliderChangedListener = new ChangedListener<RangeSliderModel>(){ + + @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<RangeSliderModel> 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. + */ + // <editor-fold defaultstate="collapsed" desc="Generated Code">//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) + ); + }// </editor-fold>//GEN-END:initComponents + // Variables declaration - do not modify//GEN-BEGIN:variables + // End of variables declaration//GEN-END:variables + +}
--- /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 Sun Feb 05 05:40:36 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<RangeSliderModel> changeListener = new ChangedListener<RangeSliderModel>() { + + @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); + } + } + } +}
--- /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 Sun Feb 05 05:40:36 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<RangeSliderModel> changeListener = new ChangedListener<RangeSliderModel>() { + + @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); + } + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/belowExplorerWsmode.xml Sun Feb 05 05:40:36 2012 +0100 @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<mode version="2.4"> + <name unique="belowExplorer"/> + <kind type="view"/> + <state type="joined"/> + <constraints> + <path orientation="horizontal" number="20" weight="0.3"/> + <path orientation="vertical" number="21" weight="0.548"/> + </constraints> + <bounds x="0" y="0" width="0" height="0"/> + <frame state="0"/> + + <empty-behavior permanent="false"/> +</mode>
Binary file src/share/tools/IdealGraphVisualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/images/next_snapshot.png has changed
Binary file src/share/tools/IdealGraphVisualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/images/prev_snapshot.png has changed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/layer.xml Sun Feb 05 05:40:36 2012 +0100 @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.2//EN" "http://www.netbeans.org/dtds/filesystem-1_2.dtd"> +<filesystem> + <folder name="Windows2"> + <folder name="Modes"> + <file name="belowExplorer.wsmode" url="belowExplorerWsmode.xml"/> + </folder> + </folder> +</filesystem>
--- a/src/share/tools/IdealGraphVisualizer/Util/nbproject/project.xml Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Util/nbproject/project.xml Sun Feb 05 05:40:36 2012 +0100 @@ -1,55 +1,64 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://www.netbeans.org/ns/project/1"> - <type>org.netbeans.modules.apisupport.project</type> - <configuration> - <data xmlns="http://www.netbeans.org/ns/nb-module-project/3"> - <code-name-base>com.sun.hotspot.igv.util</code-name-base> - <suite-component/> - <module-dependencies> - <dependency> - <code-name-base>com.sun.hotspot.igv.data</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>1.0</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>org.netbeans.api.visual</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>2.27.1</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>org.openide.nodes</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>7.20.1</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>org.openide.util</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>8.14.1</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>org.openide.util.lookup</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>8.6.1</specification-version> - </run-dependency> - </dependency> - </module-dependencies> - <public-packages> - <package>com.sun.hotspot.igv.util</package> - </public-packages> - </data> - </configuration> -</project> +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://www.netbeans.org/ns/project/1"> + <type>org.netbeans.modules.apisupport.project</type> + <configuration> + <data xmlns="http://www.netbeans.org/ns/nb-module-project/3"> + <code-name-base>com.sun.hotspot.igv.util</code-name-base> + <suite-component/> + <module-dependencies> + <dependency> + <code-name-base>com.sun.hotspot.igv.data</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>1.0</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.netbeans.api.visual</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>2.27.1</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.openide.nodes</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>7.20.1</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.openide.util</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>8.14.1</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.openide.util.lookup</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>8.6.1</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.openide.windows</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>6.48.1</specification-version> + </run-dependency> + </dependency> + </module-dependencies> + <public-packages> + <package>com.oracle.graal.visualizer.util</package> + <package>com.sun.hotspot.igv.util</package> + </public-packages> + </data> + </configuration> +</project>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Util/src/com/oracle/graal/visualizer/util/LookupUtils.java Sun Feb 05 05:40:36 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<Action> lookupActions(String path) { + return lookupActions(path, null); + } + + public static Iterable<Action> lookupActions(String path, Lookup context) { + List<Action> 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); + } + }; +}
--- a/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/BoundedZoomAction.java Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/BoundedZoomAction.java Sun Feb 05 05:40:36 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;
--- a/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/Bundle.properties Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/Bundle.properties Sun Feb 05 05:40:36 2012 +0100 @@ -1,1 +1,1 @@ -OpenIDE-Module-Name=Util +OpenIDE-Module-Name=Util
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/CompilationViewModel.java Sun Feb 05 05:40:36 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<CompilationViewModel> { + + private final ChangedEvent<CompilationViewModel> changedEvent = new ChangedEvent<>(this); + private final RangeSliderModel model; + private final Group group; + + @Override + public ChangedEvent<CompilationViewModel> getChangedEvent() { + return changedEvent; + } + + public CompilationViewModel(RangeSliderModel model, Group group) { + this.model = model; + this.group = group; + model.getChangedEvent().addListener(rangeSliderChangedListener); + } + + private final ChangedListener<RangeSliderModel> rangeSliderChangedListener = new ChangedListener<RangeSliderModel>() { + @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<Color> colors) { + model.setColors(colors); + } +}
--- a/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/ContextAction.java Sat Feb 04 15:43:40 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<T> extends CallableSystemAction implements LookupListener, ContextAwareAction { - - private Lookup context = null; - private Lookup.Result<T> 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<T> contextClass(); - - public abstract void performAction(T context); -}
--- a/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/LookupHistory.java Sat Feb 04 15:43:40 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<Class, LookupHistoryImpl> cache = new HashMap<>(); - - private static class LookupHistoryImpl<T> implements LookupListener { - - private Class<T> klass; - private Result<T> result; - private T last; - - public LookupHistoryImpl(Class<T> 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 <T> void init(Class<T> klass) { - if (!cache.containsKey(klass)) { - cache.put(klass, new LookupHistoryImpl<>(klass)); - } - } - - @SuppressWarnings("unchecked") - public static <T> T getLast(Class<T> klass) { - init(klass); - assert cache.containsKey(klass); - return (T) cache.get(klass).getLast(); - } -}
--- a/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/RangeSlider.java Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/RangeSlider.java Sun Feb 05 05:40:36 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<RangeSliderModel>, 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<String> 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<RangeSliderModel> modelChangedListener = new ChangedListener<RangeSliderModel>() { - @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<String> 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<String> 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(); } }
--- a/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/RangeSliderModel.java Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/RangeSliderModel.java Sun Feb 05 05:40:36 2012 +0100 @@ -39,7 +39,6 @@ // Warning: Update setData method if fields are added private ChangedEvent<RangeSliderModel> changedEvent; - private ChangedEvent<RangeSliderModel> colorChangedEvent; private List<String> 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<String> positions) { assert positions.size() > 0; this.changedEvent = new ChangedEvent<>(this); - this.colorChangedEvent = new ChangedEvent<>(this); setPositions(positions); } - protected void setPositions(List<String> positions) { + protected final void setPositions(List<String> 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<Color> colors) { this.colors = colors; - colorChangedEvent.fire(); + changedEvent.fire(); } public List<Color> getColors() { @@ -126,10 +120,6 @@ } } - public ChangedEvent<RangeSliderModel> getColorChangedEvent() { - return colorChangedEvent; - } - @Override public ChangedEvent<RangeSliderModel> getChangedEvent() { return changedEvent;
--- a/src/share/tools/IdealGraphVisualizer/View/nbproject/project.xml Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/nbproject/project.xml Sun Feb 05 05:40:36 2012 +0100 @@ -1,175 +1,175 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://www.netbeans.org/ns/project/1"> - <type>org.netbeans.modules.apisupport.project</type> - <configuration> - <data xmlns="http://www.netbeans.org/ns/nb-module-project/3"> - <code-name-base>com.sun.hotspot.igv.view</code-name-base> - <suite-component/> - <module-dependencies> - <dependency> - <code-name-base>com.sun.hotspot.igv.data</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>1.0</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>com.sun.hotspot.igv.difference</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>1.0</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>com.sun.hotspot.igv.filter</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>1.0</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>com.sun.hotspot.igv.graph</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>1.0</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>com.sun.hotspot.igv.hierarchicallayout</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>1.0</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>com.sun.hotspot.igv.layout</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>1.0</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>com.sun.hotspot.igv.selectioncoordinator</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>1.0</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>com.sun.hotspot.igv.settings</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>1.0</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>com.sun.hotspot.igv.svg</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>1.0</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>com.sun.hotspot.igv.util</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>1.0</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>org.netbeans.api.visual</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>2.27.1</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>org.netbeans.spi.quicksearch</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>1.0</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>org.openide.actions</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>6.21.1</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>org.openide.awt</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>7.30.1</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>org.openide.dialogs</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>7.18.1</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>org.openide.loaders</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>7.20.1</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>org.openide.nodes</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>7.20.1</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>org.openide.util</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>8.14.1</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>org.openide.util.lookup</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>8.6.1</specification-version> - </run-dependency> - </dependency> - <dependency> - <code-name-base>org.openide.windows</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <specification-version>6.39.1</specification-version> - </run-dependency> - </dependency> - </module-dependencies> - <public-packages> - <package>com.sun.hotspot.igv.view</package> - </public-packages> - </data> - </configuration> -</project> +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://www.netbeans.org/ns/project/1"> + <type>org.netbeans.modules.apisupport.project</type> + <configuration> + <data xmlns="http://www.netbeans.org/ns/nb-module-project/3"> + <code-name-base>com.sun.hotspot.igv.view</code-name-base> + <suite-component/> + <module-dependencies> + <dependency> + <code-name-base>com.oracle.graal.visualizer.editor</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>1.0</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>com.sun.hotspot.igv.data</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>1.0</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>com.sun.hotspot.igv.difference</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>1.0</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>com.sun.hotspot.igv.filter</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>1.0</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>com.sun.hotspot.igv.graph</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>1.0</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>com.sun.hotspot.igv.hierarchicallayout</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>1.0</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>com.sun.hotspot.igv.layout</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>1.0</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>com.sun.hotspot.igv.settings</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>1.0</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>com.sun.hotspot.igv.svg</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>1.0</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>com.sun.hotspot.igv.util</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>1.0</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.netbeans.api.visual</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>2.27.1</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.netbeans.spi.quicksearch</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>1.0</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.openide.actions</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>6.21.1</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.openide.awt</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>7.30.1</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.openide.dialogs</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>7.18.1</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.openide.loaders</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>7.20.1</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.openide.nodes</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>7.20.1</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.openide.util</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>8.14.1</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.openide.util.lookup</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>8.6.1</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.openide.windows</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>6.39.1</specification-version> + </run-dependency> + </dependency> + </module-dependencies> + <public-packages> + <package>com.sun.hotspot.igv.view</package> + </public-packages> + </data> + </configuration> +</project>
--- /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 Sun Feb 05 05:40:36 2012 +0100 @@ -0,0 +1,1 @@ +com.sun.hotspot.igv.view.scene.GraphCompilationViewerFactory
--- a/src/share/tools/IdealGraphVisualizer/View/src/META-INF/services/com.sun.hotspot.igv.data.services.GraphViewer Sat Feb 04 15:43:40 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -com.sun.hotspot.igv.view.GraphViewerImplementation
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/BoundedZoomAction.java Sat Feb 04 15:43:40 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; - } -}
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/Bundle.properties Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/Bundle.properties Sun Feb 05 05:40:36 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
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/DiagramScene.java Sat Feb 04 15:43:40 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> T getWidget(Object o) { - Widget w = this.findWidget(o); - return (T) w; - } - - @SuppressWarnings("unchecked") - public <T> T getWidget(Object o, Class<T> klass) { - Widget w = this.findWidget(o); - return (T) w; - } - - private static boolean intersects(Set<? extends Object> s1, Set<? extends Object> 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<Figure> list) { - - boolean b = getUndoRedoEnabled(); - setUndoRedoEnabled(false); - gotoFigures(list); - setUndoRedoEnabled(b); - } - - private Set<Object> getObjectsFromIdSet(Set<Object> set) { - Set<Object> 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<SelectionCoordinator> highlightedCoordinatorListener = new ControllableChangedListener<SelectionCoordinator>() { - - @Override - public void filteredChanged(SelectionCoordinator source) { - DiagramScene.this.setHighlightedObjects(getObjectsFromIdSet(source.getHighlightedObjects())); - DiagramScene.this.validate(); - } - }; - private ControllableChangedListener<SelectionCoordinator> selectedCoordinatorListener = new ControllableChangedListener<SelectionCoordinator>() { - - @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<Object> 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<Object> oldSet, Set<Object> newSet) { - DiagramScene scene = (DiagramScene) e.getObjectScene(); - if (scene.isRebuilding()) { - return; - } - - content.set(newSet, null); - - Set<Integer> 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<Object> oldSet, Set<Object> newSet) { - Set<Integer> 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<Object> 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<Object> 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<Widget> oldVisibleWidgets) { - System.out.println("relayout called with old visible widgets: " + oldVisibleWidgets); - - Diagram diagram = getModel().getDiagramToView(); - - HashSet<Figure> figures = new HashSet<>(); - - for (Figure f : diagram.getFigures()) { - FigureWidget w = getWidget(f); - if (w.isVisible()) { - figures.add(f); - } - } - - HashSet<Connection> 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<Pair<Point, Point>> lineCache = new HashSet<>(); - - private void relayoutWithoutLayout(Set<Widget> 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<Point> 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<Pair<Point, Point>> 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<Pair<Point, Point>> lastLineCache, OutputSlot s, List<Connection> connections, int controlPointIndex, Point lastPoint, LineWidget predecessor, int offx, int offy, SceneAnimator animator) { - Map<Point, List<Connection>> pointMap = new HashMap<>(connections.size()); - - for (Connection c : connections) { - - if (!isVisible(c)) { - continue; - } - - List<Point> 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<Connection> newList = new ArrayList<>(2); - newList.add(c); - pointMap.put(cur, newList); - } - - } - - for (Point p : pointMap.keySet()) { - List<Connection> 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<Point, Point> 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<Connection> connections; - - public ConnectionSet(Collection<Connection> connections) { - connections = new HashSet<>(connections); - } - - public Set<Connection> 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<Figure> 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<Object> idSetToObjectSet(Set<Object> ids) { - - Set<Object> 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<Object> ids) { - - Rectangle overall = null; - Set<Integer> hiddenNodes = new HashSet<>(this.getModel().getHiddenNodes()); - hiddenNodes.removeAll(ids); - this.getModel().showNot(hiddenNodes); - - Set<Object> 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<Figure> 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<Integer> newHiddenNodes, boolean doRelayout) { - - System.out.println("newHiddenNodes: " + newHiddenNodes); - - Diagram diagram = getModel().getDiagramToView(); - assert diagram != null; - - Set<Widget> 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<FigureWidget> boundaries = new ArrayList<>(); - for (Figure f : diagram.getFigures()) { - FigureWidget w = getWidget(f); - if (!w.isVisible()) { - Set<Figure> 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<Integer> 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<Object> 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<DiagramViewModel> { - - 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<DiagramViewModel> fullChange = new ChangedListener<DiagramViewModel>() { - @Override - public void changed(DiagramViewModel source) { - assert source == model : "Receive only changed event from current model!"; - assert source != null; - update(); - } - }; - - private final ChangedListener<DiagramViewModel> hiddenNodesChange = new ChangedListener<DiagramViewModel>() { - @Override - public void changed(DiagramViewModel source) { - assert source == model : "Receive only changed event from current model!"; - assert source != null; - smallUpdate(true); - } - }; - - private final ChangedListener<DiagramViewModel> selectionChange = new ChangedListener<DiagramViewModel>() { - @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; - } -}
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/DiagramViewModel.java Sat Feb 04 15:43:40 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<RangeSliderModel> { - - // Warning: Update setData method if fields are added - private Group group; - private Set<Integer> hiddenNodes; - private Set<Integer> onScreenNodes; - private Set<Integer> selectedNodes; - private FilterChain filterChain; - private FilterChain sequenceFilterChain; - private Diagram diagram; - private InputGraph inputGraph; - private ChangedEvent<DiagramViewModel> groupChangedEvent; - private ChangedEvent<DiagramViewModel> diagramChangedEvent; - private ChangedEvent<DiagramViewModel> viewChangedEvent; - private ChangedEvent<DiagramViewModel> hiddenNodesChangedEvent; - private ChangedEvent<DiagramViewModel> viewPropertiesChangedEvent; - private boolean showNodeHull; - private ChangedListener<FilterChain> filterChainChangedListener = new ChangedListener<FilterChain>() { - - @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<DiagramViewModel> groupChangedListener = new ChangedListener<DiagramViewModel>() { - - 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<Group> groupContentChangedListener = new ChangedListener<Group>() { - - @Override - public void changed(Group source) { - assert source == group; - setPositions(calculateStringList(source)); - setSelectedNodes(selectedNodes); - } - }; - - public ChangedEvent<DiagramViewModel> getDiagramChangedEvent() { - return diagramChangedEvent; - } - - public ChangedEvent<DiagramViewModel> getViewChangedEvent() { - return viewChangedEvent; - } - - public ChangedEvent<DiagramViewModel> getHiddenNodesChangedEvent() { - return hiddenNodesChangedEvent; - } - - public ChangedEvent<DiagramViewModel> getViewPropertiesChangedEvent() { - return viewPropertiesChangedEvent; - } - - public Set<Integer> getSelectedNodes() { - return selectedNodes; - } - - public Set<Integer> getHiddenNodes() { - return hiddenNodes; - } - - public Set<Integer> getOnScreenNodes() { - return onScreenNodes; - } - - public void setSelectedNodes(Set<Integer> nodes) { - this.selectedNodes = nodes; - List<Color> 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<Integer> nodes) { - System.out.println("Shownot called with " + nodes); - setHiddenNodes(nodes); - } - - public void showFigures(Collection<Figure> f) { - HashSet<Integer> newHiddenNodes = new HashSet<>(getHiddenNodes()); - for (Figure fig : f) { - newHiddenNodes.removeAll(fig.getSource().getSourceNodesAsSet()); - } - setHiddenNodes(newHiddenNodes); - } - - - public Set<Figure> getSelectedFigures() { - Set<Figure> 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<Figure> f) { - showFigures(f); - } - - public void showOnly(final Set<Integer> nodes) { - final HashSet<Integer> allNodes = new HashSet<>(getGraphToView().getGroup().getAllNodes()); - allNodes.removeAll(nodes); - setHiddenNodes(allNodes); - } - - public void setHiddenNodes(Set<Integer> nodes) { - this.hiddenNodes = nodes; - hiddenNodesChangedEvent.fire(); - } - - public void setOnScreenNodes(Set<Integer> 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<String> calculateStringList(Group g) { - List<String> result = new ArrayList<>(); - for (InputGraph graph : g.getGraphs()) { - result.add(graph.getName()); - } - return result; - } - - public InputGraph getFirstGraph() { - List<InputGraph> graphs = group.getGraphs(); - if (getFirstPosition() < graphs.size()) { - return graphs.get(getFirstPosition()); - } - return graphs.get(graphs.size() - 1); - } - - public InputGraph getSecondGraph() { - List<InputGraph> 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<Figure> list) { - Set<Integer> newSelectedNodes = new HashSet<>(); - for (Figure f : list) { - newSelectedNodes.addAll(f.getSource().getSourceNodesAsSet()); - } - this.setSelectedNodes(newSelectedNodes); - } -}
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/DiagramViewer.java Sat Feb 04 15:43:40 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<Figure> list); - - public void centerFigures(List<Figure> list); - - public void setInteractionMode(InteractionMode mode); - -}
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorInputGraphProvider.java Sat Feb 04 15:43:40 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<InputNode> nodes) { - editor.setSelectedNodes(nodes); - } -}
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorTopComponent.form Sat Feb 04 15:43:40 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> - -<Form version="1.2" maxVersion="1.2" type="org.netbeans.modules.form.forminfo.JPanelFormInfo"> - <NonVisualComponents> - <Component class="javax.swing.JCheckBox" name="jCheckBox1"> - <Properties> - <Property name="text" type="java.lang.String" value="jCheckBox1"/> - <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor"> - <Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo"> - <EmptyBorder bottom="0" left="0" right="0" top="0"/> - </Border> - </Property> - <Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor"> - <Insets value="[0, 0, 0, 0]"/> - </Property> - </Properties> - </Component> - </NonVisualComponents> - <AuxValues> - <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/> - <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/> - <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/> - <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/> - <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/> - <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/> - <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> - <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> - <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> - <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/> - </AuxValues> - - <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/> -</Form>
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorTopComponent.java Sat Feb 04 15:43:40 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<DiagramProvider> getChangedEvent() { - return diagramChangedEvent; - } - }; - - private ChangedEvent<DiagramProvider> 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<? extends Mode> 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. - */ - // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//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()); - - }// </editor-fold>//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<DiagramViewModel> diagramChangedListener = new ChangedListener<DiagramViewModel>() { - - @Override - public void changed(DiagramViewModel source) { - updateDisplayName(); - Collection<Object> 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<Figure> selector = new Properties.PropertySelector<>(getModel().getDiagramToView().getFigures()); - List<Figure> list = selector.selectMultiple(matcher); - setSelectedFigures(list); - } - - public void setSelectedFigures(List<Figure> list) { - scene.setSelection(list); - scene.centerFigures(list); - } - - public void setSelectedNodes(Set<InputNode> nodes) { - - List<Figure> list = new ArrayList<>(); - Set<Integer> 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<Integer> selectedNodes = this.getModel().getSelectedNodes(); - HashSet<Integer> nodes = new HashSet<>(getModel().getHiddenNodes()); - nodes.addAll(selectedNodes); - this.getModel().showNot(nodes); - } - - public void expandPredecessors() { - Set<Figure> oldSelection = getModel().getSelectedFigures(); - Set<Figure> 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<Figure> oldSelection = getModel().getSelectedFigures(); - Set<Figure> 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<Integer>()); - } - - 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(); - } - -}
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/ExportCookie.java Sat Feb 04 15:43:40 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); -}
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/ExtendedSatelliteComponent.java Sat Feb 04 15:43:40 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) { - } -}
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/GraphViewerImplementation.java Sat Feb 04 15:43:40 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(); - } -}
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/NodeQuickSearch.java Sat Feb 04 15:43:40 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<InputNode> matches = null; - try { - RegexpPropertyMatcher matcher = new RegexpPropertyMatcher(name, value, Pattern.CASE_INSENSITIVE); - Properties.PropertySelector<InputNode> 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<InputNode> 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<InputNode> 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!"); - } - } -}
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/Bundle.properties Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/Bundle.properties Sun Feb 05 05:40:36 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...
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/CustomizablePanAction.java Sat Feb 04 15:43:40 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; - } -}
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExpandPredecessorsAction.java Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExpandPredecessorsAction.java Sun Feb 05 05:40:36 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(); } }
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExpandSuccessorsAction.java Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExpandSuccessorsAction.java Sun Feb 05 05:40:36 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(); } }
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExportAction.java Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExportAction.java Sun Feb 05 05:40:36 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;
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExtractAction.java Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExtractAction.java Sun Feb 05 05:40:36 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(); } }
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/HideAction.java Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/HideAction.java Sun Feb 05 05:40:36 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(); } }
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/NextDiagramAction.java Sat Feb 04 15:43:40 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<DiagramViewModel> implements ChangedListener<DiagramViewModel> { - - 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<DiagramViewModel> 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); - } -}
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/OverviewAction.java Sat Feb 04 15:43:40 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"; - } -}
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/PanModeAction.java Sat Feb 04 15:43:40 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) { - } -}
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/PrevDiagramAction.java Sat Feb 04 15:43:40 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<DiagramViewModel> implements ChangedListener<DiagramViewModel> { - - 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<DiagramViewModel> 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); - } -}
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/SelectionModeAction.java Sat Feb 04 15:43:40 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) { - } -}
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ShowAllAction.java Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ShowAllAction.java Sun Feb 05 05:40:36 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(); } }
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ZoomInAction.java Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ZoomInAction.java Sun Feb 05 05:40:36 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"); }
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ZoomOutAction.java Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ZoomOutAction.java Sun Feb 05 05:40:36 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)); }
Binary file src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/next_diagram.png has changed
Binary file src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/prev_diagram.png has changed
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/layer.xml Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/layer.xml Sun Feb 05 05:40:36 2012 +0100 @@ -1,80 +1,4 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.1//EN" "http://www.netbeans.org/dtds/filesystem-1_1.dtd"> <filesystem> - <folder name="Actions"> - <folder name="File"> - <file name="com-sun-hotspot-igv-view-actions-ExportAction.instance"> - <attr name="position" intvalue="1100"/> - </file> - </folder> - <folder name="View"> - <file name="com-sun-hotspot-igv-view-actions-NextDiagramAction.instance"><attr name="position" intvalue="2000"/></file> - <file name="com-sun-hotspot-igv-view-actions-PrevDiagramAction.instance"><attr name="position" intvalue="2001"/></file> - <file name="com-sun-hotspot-igv-view-actions-ShowAllAction.instance"><attr name="position" intvalue="2001"/></file> - <file name="com-sun-hotspot-igv-view-actions-ExtractAction.instance"><attr name="position" intvalue="2001"/></file> - <file name="com-sun-hotspot-igv-view-actions-HideAction.instance"><attr name="position" intvalue="2001"/></file> - <file name="com-sun-hotspot-igv-view-actions-ZoomInAction.instance"><attr name="position" intvalue="2001"/></file> - <file name="com-sun-hotspot-igv-view-actions-ZoomOutAction.instance"><attr name="position" intvalue="2001"/></file> - <file name="com-sun-hotspot-igv-view-actions-OverviewAction.instance"><attr name="position" intvalue="2001"/></file> - <file name="com-sun-hotspot-igv-view-actions-PredSuccAction.instance"><attr name="position" intvalue="2001"/></file> - <file name="com-sun-hotspot-igv-view-actions-EnableBlockLayoutAction.instance"><attr name="position" intvalue="2001"/></file> - </folder> - </folder> - <folder name="Menu"> - <folder name="View"> - <file name="com-sun-hotspot-igv-view-actions-PrevDiagramAction.shadow"> - <attr name="originalFile" stringvalue="Actions/View/com-sun-hotspot-igv-view-actions-PrevDiagramAction.instance"/> - <attr name="position" intvalue="100"/> - </file> - <file name="com-sun-hotspot-igv-view-actions-NextDiagramAction.shadow"> - <attr name="originalFile" stringvalue="Actions/View/com-sun-hotspot-igv-view-actions-NextDiagramAction.instance"/> - <attr name="position" intvalue="150"/> - </file> - <file name="com-sun-hotspot-igv-view-actions-ShowAllAction.shadow"> - <attr name="originalFile" stringvalue="Actions/View/com-sun-hotspot-igv-view-actions-ShowAllAction.instance"/> - <attr name="position" intvalue="200"/> - </file> - <file name="com-sun-hotspot-igv-view-actions-ExtractAction.shadow"> - <attr name="originalFile" stringvalue="Actions/View/com-sun-hotspot-igv-view-actions-ExtractAction.instance"/> - <attr name="position" intvalue="300"/> - </file> - <file name="com-sun-hotspot-igv-view-actions-HideAction.shadow"> - <attr name="originalFile" stringvalue="Actions/View/com-sun-hotspot-igv-view-actions-HideAction.instance"/> - <attr name="position" intvalue="400"/> - </file> - <file name="com-sun-hotspot-igv-view-actions-ZoomInAction.shadow"> - <attr name="originalFile" stringvalue="Actions/View/com-sun-hotspot-igv-view-actions-ZoomInAction.instance"/> - <attr name="position" intvalue="500"/> - </file> - <file name="com-sun-hotspot-igv-view-actions-ZoomOutAction.shadow"> - <attr name="originalFile" stringvalue="Actions/View/com-sun-hotspot-igv-view-actions-ZoomOutAction.instance"/> - <attr name="position" intvalue="550"/> - </file> - </folder> - <folder name="File"> - <file name="ExportActionSeparator.instance"> - <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/> - <attr name="position" intvalue="700"/> - </file> - <file name="com-sun-hotspot-igv-view-actions-ExportAction.shadow"> - <attr name="originalFile" stringvalue="Actions/File/com-sun-hotspot-igv-view-actions-ExportAction.instance"/> - <attr name="position" intvalue="710"/> - </file> - </folder> - </folder> - - <folder name="QuickSearch"> - <folder name="Nodes"> - <attr name="command" stringvalue="n"/> - <attr name="position" intvalue="0"/> - <file name="com-sun-hotspot-igv-view-NodeQuickSearch.instance" /> - </folder> - </folder> - - <folder name="QuickSearchShadow"> - <file name="org-netbeans-modules-quicksearch-QuickSearchAction.shadow"> - <attr name="originalFile" stringvalue="Actions/Edit/org-netbeans-modules-quicksearch-QuickSearchAction.instance"/> - - </file> - </folder> </filesystem>
--- /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 Sun Feb 05 05:40:36 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; + } +}
--- /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 Sun Feb 05 05:40:36 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> T getWidget(Object o) { + Widget w = this.findWidget(o); + return (T) w; + } + + @SuppressWarnings("unchecked") + public <T> T getWidget(Object o, Class<T> klass) { + Widget w = this.findWidget(o); + return (T) w; + } + + private static boolean intersects(Set<? extends Object> s1, Set<? extends Object> 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<Figure> list) { + gotoFigures(list); + } + + private Set<Object> getObjectsFromIdSet(Set<Object> set) { + Set<Object> 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<Object> 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<Object> oldSet, Set<Object> newSet) { + DiagramScene scene = (DiagramScene) e.getObjectScene(); + if (scene.isRebuilding()) { + return; + } + + content.set(newSet, null); + + Set<Integer> 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<Object> oldSet, Set<Object> newSet) { + Set<Integer> 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<Object> 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<Object> 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<Widget> oldVisibleWidgets) { + System.out.println("relayout called with old visible widgets: " + oldVisibleWidgets); + + Diagram diagram = getModel().getDiagramToView(); + + HashSet<Figure> figures = new HashSet<>(); + + for (Figure f : diagram.getFigures()) { + FigureWidget w = getWidget(f); + if (w.isVisible()) { + figures.add(f); + } + } + + HashSet<Connection> 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<Pair<Point, Point>> lineCache = new HashSet<>(); + + private void relayoutWithoutLayout(Set<Widget> 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<Point> 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<Pair<Point, Point>> 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<Pair<Point, Point>> lastLineCache, OutputSlot s, List<Connection> connections, int controlPointIndex, Point lastPoint, LineWidget predecessor, int offx, int offy, SceneAnimator animator) { + Map<Point, List<Connection>> pointMap = new HashMap<>(connections.size()); + + for (Connection c : connections) { + + if (!isVisible(c)) { + continue; + } + + List<Point> 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<Connection> newList = new ArrayList<>(2); + newList.add(c); + pointMap.put(cur, newList); + } + + } + + for (Point p : pointMap.keySet()) { + List<Connection> 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<Point, Point> 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<Figure> 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<Object> idSetToObjectSet(Set<Object> ids) { + + Set<Object> 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<Object> ids) { + + Rectangle overall = null; + Set<Integer> hiddenNodes = new HashSet<>(this.getModel().getHiddenNodes()); + hiddenNodes.removeAll(ids); + this.getModel().showNot(hiddenNodes); + + Set<Object> 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<Figure> 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<Integer> newHiddenNodes, boolean doRelayout) { + + System.out.println("newHiddenNodes: " + newHiddenNodes); + + Diagram diagram = getModel().getDiagramToView(); + assert diagram != null; + + Set<Widget> 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<FigureWidget> boundaries = new ArrayList<>(); + for (Figure f : diagram.getFigures()) { + FigureWidget w = getWidget(f); + if (!w.isVisible()) { + Set<Figure> 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<Integer> 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<Object> 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<DiagramViewModel> fullChange = new ChangedListener<DiagramViewModel>() { + + @Override + public void changed(DiagramViewModel source) { + assert source == model : "Receive only changed event from current model!"; + assert source != null; + update(); + } + }; + private final ChangedListener<DiagramViewModel> hiddenNodesChange = new ChangedListener<DiagramViewModel>() { + + @Override + public void changed(DiagramViewModel source) { + assert source == model : "Receive only changed event from current model!"; + assert source != null; + smallUpdate(true); + } + }; + private final ChangedListener<DiagramViewModel> selectionChange = new ChangedListener<DiagramViewModel>() { + + @Override + public void changed(DiagramViewModel source) { + assert source == model : "Receive only changed event from current model!"; + assert source != null; + smallUpdate(false); + } + }; +}
--- /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 Sun Feb 05 05:40:36 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"; + } + } + +}
--- /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 Sun Feb 05 05:40:36 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"; + } + +}
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/FigureWidget.java Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/FigureWidget.java Sun Feb 05 05:40:36 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;
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/InputSlotWidget.java Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/InputSlotWidget.java Sun Feb 05 05:40:36 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;
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/LineWidget.java Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/LineWidget.java Sun Feb 05 05:40:36 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;
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/OutputSlotWidget.java Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/OutputSlotWidget.java Sun Feb 05 05:40:36 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;
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/SlotWidget.java Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/SlotWidget.java Sun Feb 05 05:40:36 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;
--- a/src/share/tools/IdealGraphVisualizer/nbproject/project.properties Sat Feb 04 15:43:40 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/nbproject/project.properties Sun Feb 05 05:40:36 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