# HG changeset patch # User Thomas Wuerthinger # Date 1328650869 -3600 # Node ID 015fb895586b9f3579d0baed9627486b276dc101 # Parent 6cb549627941bf1a8980415c4fadde1de586a08a Moved visualizer to new directory. diff -r 6cb549627941 -r 015fb895586b .hgignore --- a/.hgignore Tue Feb 07 22:31:33 2012 +0100 +++ b/.hgignore Tue Feb 07 22:41:09 2012 +0100 @@ -44,5 +44,8 @@ ^src/share/tools/IdealGraphVisualizer/[a-zA-Z0-9]*/build/ ^src/share/tools/IdealGraphVisualizer/build/ ^src/share/tools/IdealGraphVisualizer/dist/ +^visualizer/[a-zA-Z0-9]*/build/ +^visualizer/build/ +^visualizer/dist/ ^.hgtip .DS_Store diff -r 6cb549627941 -r 015fb895586b visualizer/BatikSVGProxy/manifest.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/BatikSVGProxy/manifest.mf Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,6 @@ +Manifest-Version: 1.0 +OpenIDE-Module: com.sun.hotspot.igv.svg +OpenIDE-Module-Layer: com/sun/hotspot/igv/svg/layer.xml +OpenIDE-Module-Localizing-Bundle: com/sun/hotspot/igv/svg/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff -r 6cb549627941 -r 015fb895586b visualizer/BatikSVGProxy/src/com/sun/hotspot/igv/svg/BatikSVG.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/BatikSVGProxy/src/com/sun/hotspot/igv/svg/BatikSVG.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,102 @@ +/* + * 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.svg; + +import java.awt.Graphics2D; +import java.io.Writer; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import org.w3c.dom.DOMImplementation; + +/** + * Utility class + * @author Thomas Wuerthinger + */ +public class BatikSVG { + + private BatikSVG() { + } + + private static Constructor SVGGraphics2DConstructor; + private static Method streamMethod; + private static Method createDefaultMethod; + private static Method getDOMImplementationMethod; + private static Method setEmbeddedFontsOnMethod; + private static Class classSVGGraphics2D; + + /** + * Creates a graphics object that allows to be exported to SVG data using the {@link #printToStream(Graphics2D, Writer, boolean) printToStream} method. + * @return the newly created Graphics2D object or null if the library does not exist + */ + public static Graphics2D createGraphicsObject() { + try { + if (SVGGraphics2DConstructor == null) { + ClassLoader cl = BatikSVG.class.getClassLoader(); + Class classGenericDOMImplementation = cl.loadClass("org.apache.batik.dom.GenericDOMImplementation"); + Class classSVGGeneratorContext = cl.loadClass("org.apache.batik.svggen.SVGGeneratorContext"); + classSVGGraphics2D = cl.loadClass("org.apache.batik.svggen.SVGGraphics2D"); + getDOMImplementationMethod = classGenericDOMImplementation.getDeclaredMethod("getDOMImplementation", new Class[0]); + createDefaultMethod = classSVGGeneratorContext.getDeclaredMethod("createDefault", new Class[]{org.w3c.dom.Document.class}); + setEmbeddedFontsOnMethod = classSVGGeneratorContext.getDeclaredMethod("setEmbeddedFontsOn", new Class[]{boolean.class}); + streamMethod = classSVGGraphics2D.getDeclaredMethod("stream", Writer.class, boolean.class); + SVGGraphics2DConstructor = classSVGGraphics2D.getConstructor(classSVGGeneratorContext, boolean.class); + } + DOMImplementation dom = (DOMImplementation) getDOMImplementationMethod.invoke(null); + org.w3c.dom.Document document = dom.createDocument("http://www.w3.org/2000/svg", "svg", null); + Object ctx = createDefaultMethod.invoke(null, document); + setEmbeddedFontsOnMethod.invoke(ctx, true); + Graphics2D svgGenerator = (Graphics2D) SVGGraphics2DConstructor.newInstance(ctx, true); + return svgGenerator; + } catch (ClassNotFoundException e) { + return null; + } catch (NoSuchMethodException e) { + return null; + } catch (IllegalAccessException e) { + return null; + } catch (InvocationTargetException e) { + return null; + } catch (InstantiationException e) { + return null; + } + } + + /** + * Serializes a graphics object to a stream in SVG format. + * @param svgGenerator the graphics object. Only graphics objects created by the {@link #createGraphicsObject() createGraphicsObject} method are valid. + * @param stream the stream to which the data is written + * @param useCSS whether to use CSS styles in the SVG output + */ + public static void printToStream(Graphics2D svgGenerator, Writer stream, boolean useCSS) { + assert classSVGGraphics2D != null; + assert classSVGGraphics2D.isInstance(svgGenerator); + try { + streamMethod.invoke(svgGenerator, stream, useCSS); + } catch (IllegalAccessException e) { + assert false; + } catch (InvocationTargetException e) { + assert false; + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/BatikSVGProxy/src/com/sun/hotspot/igv/svg/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/BatikSVGProxy/src/com/sun/hotspot/igv/svg/Bundle.properties Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,1 @@ +OpenIDE-Module-Name=BatikSVGProxy diff -r 6cb549627941 -r 015fb895586b visualizer/BatikSVGProxy/src/com/sun/hotspot/igv/svg/layer.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/BatikSVGProxy/src/com/sun/hotspot/igv/svg/layer.xml Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,4 @@ + + + + diff -r 6cb549627941 -r 015fb895586b visualizer/BatikSVGProxy/src/com/sun/hotspot/igv/svg/package-info.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/BatikSVGProxy/src/com/sun/hotspot/igv/svg/package-info.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,29 @@ +/* + * 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. + * + */ +/** + * This package is used to proxy the SVG export functionality of the BatikSVG library. Reflection is used such that the + * library is optional and need not be present at build time. + */ +package com.sun.hotspot.igv.svg; + diff -r 6cb549627941 -r 015fb895586b visualizer/Bytecodes/manifest.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Bytecodes/manifest.mf Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,6 @@ +Manifest-Version: 1.0 +OpenIDE-Module: com.sun.hotspot.igv.bytecodes +OpenIDE-Module-Layer: com/sun/hotspot/igv/bytecodes/layer.xml +OpenIDE-Module-Localizing-Bundle: com/sun/hotspot/igv/bytecodes/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff -r 6cb549627941 -r 015fb895586b visualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/Bundle.properties Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,5 @@ +CTL_BytecodeViewAction=Bytecode +CTL_BytecodeViewTopComponent=Bytecode +CTL_SelectBytecodesAction=Select nodes +HINT_BytecodeViewTopComponent=Shows the bytecode associated with the displayed graph. +OpenIDE-Module-Name=Bytecodes diff -r 6cb549627941 -r 015fb895586b visualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/BytecodeNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/BytecodeNode.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,101 @@ +/* + * 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.bytecodes; + +import com.sun.hotspot.igv.data.InputBytecode; +import com.sun.hotspot.igv.data.InputGraph; +import com.sun.hotspot.igv.data.InputNode; +import com.sun.hotspot.igv.data.Properties; +import com.sun.hotspot.igv.data.Properties.StringPropertyMatcher; +import java.awt.Image; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import javax.swing.Action; +import org.openide.nodes.AbstractNode; +import org.openide.nodes.Children; +import org.openide.nodes.Node; +import org.openide.util.ImageUtilities; + +/** + * + * @author Thomas Wuerthinger + */ +public class BytecodeNode extends AbstractNode { + + private Set nodes; + + public BytecodeNode(InputBytecode bytecode, InputGraph graph, String bciValue) { + + super(Children.LEAF); + this.setDisplayName(bytecode.getBci() + " " + bytecode.getName()); + + bciValue = bytecode.getBci() + " " + bciValue; + bciValue = bciValue.trim(); + + Properties.PropertySelector selector = new Properties.PropertySelector<>(graph.getNodes()); + StringPropertyMatcher matcher = new StringPropertyMatcher("bci", bciValue); + List nodeList = selector.selectMultiple(matcher); + if (nodeList.size() > 0) { + nodes = new LinkedHashSet<>(); + for (InputNode n : nodeList) { + nodes.add(n); + } + this.setDisplayName(this.getDisplayName() + " (" + nodes.size() + " nodes)"); + } + } + + @Override + public Image getIcon(int i) { + if (nodes != null) { + return ImageUtilities.loadImage("com/sun/hotspot/igv/bytecodes/images/link.png"); + } else { + return ImageUtilities.loadImage("com/sun/hotspot/igv/bytecodes/images/bytecode.png"); + } + } + + @Override + public Image getOpenedIcon(int i) { + return getIcon(i); + } + + @Override + public Action[] getActions(boolean b) { + return new Action[]{(Action) SelectBytecodesAction.findObject(SelectBytecodesAction.class, true)}; + } + + @Override + public Action getPreferredAction() { + return (Action) SelectBytecodesAction.findObject(SelectBytecodesAction.class, true); + } + + @Override + @SuppressWarnings("unchecked") + public T getCookie(Class aClass) { + if (aClass == SelectBytecodesCookie.class && nodes != null) { + return (T) (new SelectBytecodesCookie(nodes)); + } + return super.getCookie(aClass); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/BytecodeViewAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/BytecodeViewAction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,46 @@ +/* + * 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.bytecodes; + +import java.awt.event.ActionEvent; +import javax.swing.AbstractAction; +import org.openide.util.NbBundle; +import org.openide.windows.TopComponent; + +/** + * @author Thomas Wuerthinger + */ +public class BytecodeViewAction extends AbstractAction { + + public BytecodeViewAction() { + super(NbBundle.getMessage(BytecodeViewAction.class, "CTL_BytecodeViewAction")); + } + + @Override + public void actionPerformed(ActionEvent evt) { + TopComponent win = BytecodeViewTopComponent.findInstance(); + win.open(); + win.requestActive(); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/BytecodeViewTopComponent.form --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/BytecodeViewTopComponent.form Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,28 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
diff -r 6cb549627941 -r 015fb895586b visualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/BytecodeViewTopComponent.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/BytecodeViewTopComponent.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,195 @@ +/* + * 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.bytecodes; + +import com.sun.hotspot.igv.data.Group; +import com.sun.hotspot.igv.data.InputGraph; +import com.sun.hotspot.igv.data.services.InputGraphProvider; +import java.awt.BorderLayout; +import java.io.Serializable; +import javax.swing.SwingUtilities; +import org.openide.ErrorManager; +import org.openide.explorer.ExplorerManager; +import org.openide.explorer.ExplorerUtils; +import org.openide.explorer.view.BeanTreeView; +import org.openide.util.*; +import org.openide.windows.TopComponent; +import org.openide.windows.WindowManager; + +/** + * @author Thomas Wuerthinger + */ +final class BytecodeViewTopComponent extends TopComponent implements ExplorerManager.Provider, LookupListener { + + private static BytecodeViewTopComponent instance; + private static final String PREFERRED_ID = "BytecodeViewTopComponent"; + private ExplorerManager manager; + private BeanTreeView treeView; + private Lookup.Result result = null; + private MethodNode rootNode; + + private BytecodeViewTopComponent() { + initComponents(); + setName(NbBundle.getMessage(BytecodeViewTopComponent.class, "CTL_BytecodeViewTopComponent")); + setToolTipText(NbBundle.getMessage(BytecodeViewTopComponent.class, "HINT_BytecodeViewTopComponent")); + + manager = new ExplorerManager(); + rootNode = new MethodNode(null, null, ""); + manager.setRootContext(rootNode); + + setLayout(new BorderLayout()); + + treeView = new BeanTreeView(); + treeView.setRootVisible(false); + this.add(BorderLayout.CENTER, treeView); + associateLookup(ExplorerUtils.createLookup(manager, getActionMap())); + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(0, 400, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(0, 300, Short.MAX_VALUE) + ); + }// //GEN-END:initComponents + // Variables declaration - do not modify//GEN-BEGIN:variables + // End of variables declaration//GEN-END:variables + + /** + * 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 BytecodeViewTopComponent getDefault() { + if (instance == null) { + instance = new BytecodeViewTopComponent(); + } + return instance; + } + + /** + * Obtain the BytecodeViewTopComponent instance. Never call {@link #getDefault} directly! + */ + public static synchronized BytecodeViewTopComponent findInstance() { + TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID); + if (win == null) { + ErrorManager.getDefault().log(ErrorManager.WARNING, "Cannot find BytecodeView component. It will not be located properly in the window system."); + return getDefault(); + } + if (win instanceof BytecodeViewTopComponent) { + return (BytecodeViewTopComponent) 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() { + Lookup.Template tpl = new Lookup.Template<>(InputGraphProvider.class); + result = Utilities.actionsGlobalContext().lookup(tpl); + result.addLookupListener(this); + } + + @Override + public void componentClosed() { + result.removeLookupListener(this); + result = null; + } + + @Override + public Object writeReplace() { + return new ResolvableHelper(); + } + + @Override + protected String preferredID() { + return PREFERRED_ID; + } + + @Override + public ExplorerManager getExplorerManager() { + return manager; + } + + @Override + public void requestActive() { + super.requestActive(); + this.treeView.requestFocus(); + } + + @Override + public boolean requestFocus(boolean temporary) { + this.treeView.requestFocus(); + return super.requestFocus(temporary); + } + + @Override + protected boolean requestFocusInWindow(boolean temporary) { + this.treeView.requestFocus(); + return super.requestFocusInWindow(temporary); + } + + @Override + public void resultChanged(LookupEvent lookupEvent) { + final InputGraphProvider p = null; // TODO(tw): FIXME //.getLast(InputGraphProvider.class);//)Utilities.actionsGlobalContext().lookup(InputGraphProvider.class); + if (p != null) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + InputGraph graph = p.getGraph(); + if (graph != null) { + Group g = graph.getGroup(); + rootNode.update(graph, g.getMethod()); + } + } + }); + } + } + + final static class ResolvableHelper implements Serializable { + + private static final long serialVersionUID = 1L; + + public Object readResolve() { + return BytecodeViewTopComponent.getDefault(); + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/BytecodeViewTopComponentSettings.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/BytecodeViewTopComponentSettings.xml Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,8 @@ + + + + + + + + diff -r 6cb549627941 -r 015fb895586b visualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/BytecodeViewTopComponentWstcref.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/BytecodeViewTopComponentWstcref.xml Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,7 @@ + + + + + + + diff -r 6cb549627941 -r 015fb895586b visualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/MethodNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/MethodNode.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,101 @@ +/* + * 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.bytecodes; + +import com.sun.hotspot.igv.data.InputBytecode; +import com.sun.hotspot.igv.data.InputGraph; +import com.sun.hotspot.igv.data.InputMethod; +import java.awt.Image; +import org.openide.nodes.AbstractNode; +import org.openide.nodes.Children; +import org.openide.nodes.Node; +import org.openide.util.ImageUtilities; + +/** + * + * @author Thomas Wuerthinger + */ +public class MethodNode extends AbstractNode { + + private static class MethodNodeChildren extends Children.Keys { + + private InputMethod method; + private InputGraph graph; + private String bciString; + + public MethodNodeChildren(InputMethod method, InputGraph graph, String bciString) { + this.method = method; + this.bciString = bciString; + this.graph = graph; + } + + @Override + protected Node[] createNodes(InputBytecode bc) { + if (bc.getInlined() == null) { + return new Node[]{new BytecodeNode(bc, graph, bciString)}; + } else { + return new Node[]{new BytecodeNode(bc, graph, bciString), new MethodNode(bc.getInlined(), graph, bc.getBci() + " " + bciString)}; + } + } + + @Override + public void addNotify() { + if (method != null) { + setKeys(method.getBytecodes()); + } + } + + public void setMethod(InputMethod method, InputGraph graph) { + this.method = method; + this.graph = graph; + addNotify(); + } + } + + /** Creates a new instance of MethodNode */ + public MethodNode(InputMethod method, InputGraph graph, String bciString) { + super((method != null && method.getBytecodes().size() == 0) ? Children.LEAF : new MethodNodeChildren(method, graph, bciString)); + if (method != null) { + this.setDisplayName(method.getName()); + } + } + + @Override + public Image getIcon(int i) { + return ImageUtilities.loadImage("com/sun/hotspot/igv/bytecodes/images/method.png"); + } + + @Override + public Image getOpenedIcon(int i) { + return getIcon(i); + } + + public void update(InputGraph graph, InputMethod method) { + ((MethodNodeChildren) this.getChildren()).setMethod(method, graph); + if (method != null) { + this.setDisplayName(method.getName()); + } + + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/SelectBytecodesAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/SelectBytecodesAction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,80 @@ +/* + * 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.bytecodes; + +import com.sun.hotspot.igv.data.services.InputGraphProvider; +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 SelectBytecodesAction extends CookieAction { + + @Override + protected void performAction(Node[] activatedNodes) { + SelectBytecodesCookie c = activatedNodes[0].getCookie(SelectBytecodesCookie.class); + InputGraphProvider p = null; // TODO: fixme LookupHistory.getLast(InputGraphProvider.class);//Utilities.actionsGlobalContext().lookup(InputGraphProvider.class); + if (p != null) { + p.setSelectedNodes(c.getNodes()); + } + } + + @Override + protected int mode() { + return CookieAction.MODE_EXACTLY_ONE; + } + + @Override + public String getName() { + return NbBundle.getMessage(SelectBytecodesAction.class, "CTL_SelectBytecodesAction"); + } + + @Override + protected Class[] cookieClasses() { + return new Class[]{ + SelectBytecodesCookie.class + }; + } + + @Override + protected void initialize() { + super.initialize(); + putValue("noIconInMenu", Boolean.TRUE); + } + + @Override + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + @Override + protected boolean asynchronous() { + return false; + } +} + diff -r 6cb549627941 -r 015fb895586b visualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/SelectBytecodesCookie.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/SelectBytecodesCookie.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,47 @@ +/* + * 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.bytecodes; + +import com.sun.hotspot.igv.data.InputNode; +import java.util.Collections; +import java.util.Set; +import org.openide.nodes.Node; + +/** + * + * @author Thomas Wuerthinger + */ +public class SelectBytecodesCookie implements Node.Cookie { + + private Set nodes; + + /** Creates a new instance of SelectBytecodesCookie */ + public SelectBytecodesCookie(Set nodes) { + this.nodes = nodes; + } + + public Set getNodes() { + return Collections.unmodifiableSet(nodes); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/images/bytecode.png Binary file visualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/images/bytecode.png has changed diff -r 6cb549627941 -r 015fb895586b visualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/images/link.png Binary file visualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/images/link.png has changed diff -r 6cb549627941 -r 015fb895586b visualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/images/method.png Binary file visualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/images/method.png has changed diff -r 6cb549627941 -r 015fb895586b visualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/layer.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/layer.xml Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/manifest.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/manifest.mf Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,6 @@ +Manifest-Version: 1.0 +OpenIDE-Module: at.ssw.visualizer.cfg +OpenIDE-Module-Layer: at/ssw/visualizer/cfg/layer.xml +OpenIDE-Module-Localizing-Bundle: at/ssw/visualizer/cfg/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/META-INF/services/com.oracle.graal.visualizer.editor.CompilationViewerFactory --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/META-INF/services/com.oracle.graal.visualizer.editor.CompilationViewerFactory Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,1 @@ +at.ssw.visualizer.cfg.CfgCompilationViewerFactory \ No newline at end of file diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/Bundle.properties Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,1 @@ +OpenIDE-Module-Name=ControlFlowEditor diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/CfgCompilationViewer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/CfgCompilationViewer.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,235 @@ +/* + * 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.CfgScene; +import at.ssw.visualizer.cfg.graph.EdgeWidget; +import at.ssw.visualizer.cfg.graph.NodeWidget; +import at.ssw.visualizer.cfg.model.CfgEdge; +import at.ssw.visualizer.cfg.model.CfgNode; +import at.ssw.visualizer.cfg.preferences.CfgPreferences; +import at.ssw.visualizer.cfg.preferences.FlagsSetting; +import at.ssw.visualizer.model.cfg.ControlFlowGraph; +import com.oracle.graal.visualizer.editor.CompilationViewer; +import com.sun.hotspot.igv.data.InputGraph; +import java.awt.Color; +import java.awt.Component; +import java.beans.PropertyChangeEvent; +import javax.swing.*; +import javax.swing.border.Border; +import org.netbeans.api.visual.widget.Widget; +import org.openide.awt.Toolbar; +import org.openide.util.Lookup; +import org.openide.util.actions.SystemAction; +import org.openide.util.lookup.Lookups; + +class CfgCompilationViewer implements CompilationViewer { + + private CfgScene scene; + private JScrollPane jScrollPane; + private ControlFlowGraph cfg; + private JComponent myView; + + public CfgCompilationViewer(InputGraph cfg) { + this.cfg = cfg; + + // setIcon(ImageUtilities.loadImage("at/ssw/visualizer/cfg/icons/cfg.gif")); +// setName(cfg.getParent().getShortName()); +// setToolTipText(cfg.getCompilation().getMethod() + " - " + cfg.getName()); + // TODO(tw): Add title. + + //panel setup + this.jScrollPane = new JScrollPane(); + this.jScrollPane.setOpaque(true); + this.jScrollPane.setBorder(BorderFactory.createEmptyBorder()); + this.jScrollPane.setViewportBorder(BorderFactory.createEmptyBorder()); + this.scene = new CfgScene(jScrollPane, cfg); + this.myView = scene.createView(); + this.jScrollPane.setViewportView(myView); + jScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); + jScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); + jScrollPane.getVerticalScrollBar().setEnabled(true); + jScrollPane.getHorizontalScrollBar().setEnabled(true); + + //setup enviroment,register listeners + // TODO(tw): Add to lookup. +// selection = new Selection(); +// selection.put(cfg); +// selection.put(scene); +// selection.addChangeListener(scene); + + scene.validate(); + scene.applyLayout(); + } + + public void propertyChange(PropertyChangeEvent evt) { + if (this.scene != null) { + + String propName = evt.getPropertyName(); + CfgPreferences prefs = CfgPreferences.getInstance(); + switch (propName) { + case CfgPreferences.PROP_BACKGROUND_COLOR: + scene.setBackground(prefs.getBackgroundColor()); + scene.revalidate(); + break; + case CfgPreferences.PROP_NODE_COLOR: + for (NodeWidget nw : scene.getNodeWidgets()) { + //only change the node color if its not a custom color + if (!nw.isNodeColorCustomized()) { + nw.setNodeColor(prefs.getNodeColor(), false); + } + } + break; + case CfgPreferences.PROP_EDGE_COLOR: + for (CfgEdge e : scene.getEdges()) { + if (!e.isBackEdge() && !e.isXhandler()) { + EdgeWidget w = (EdgeWidget) scene.findWidget(e); + w.setLineColor(prefs.getEdgeColor()); + } + } + break; + case CfgPreferences.PROP_BACK_EDGE_COLOR: + for (CfgEdge e : scene.getEdges()) { + if (e.isBackEdge()) { + EdgeWidget w = (EdgeWidget) scene.findWidget(e); + w.setLineColor(prefs.getBackedgeColor()); + } + } + break; + case CfgPreferences.PROP_EXCEPTION_EDGE_COLOR: + for (CfgEdge e : scene.getEdges()) { + if (e.isXhandler()) { + EdgeWidget w = (EdgeWidget) scene.findWidget(e); + w.setLineColor(prefs.getExceptionEdgeColor()); + } + } + break; + case CfgPreferences.PROP_BORDER_COLOR: + for (CfgNode n : scene.getNodes()) { + NodeWidget nw = (NodeWidget) scene.findWidget(n); + nw.setBorderColor(prefs.getBorderColor()); + } + break; + case CfgPreferences.PROP_TEXT_FONT: + for (CfgNode n : scene.getNodes()) { + NodeWidget nw = (NodeWidget) scene.findWidget(n); + nw.adjustFont(prefs.getTextFont()); + } + break; + case CfgPreferences.PROP_TEXT_COLOR: + for (CfgNode n : scene.getNodes()) { + NodeWidget nw = (NodeWidget) scene.findWidget(n); + nw.setForeground(prefs.getTextColor()); + } + break; + case CfgPreferences.PROP_FLAGS: + FlagsSetting fs = CfgPreferences.getInstance().getFlagsSetting(); + for (CfgNode n : scene.getNodes()) { + NodeWidget nw = (NodeWidget) scene.findWidget(n); + Color nodeColor = fs.getColor(n.getBasicBlock().getFlags()); + if (nodeColor != null) { + nw.setNodeColor(nodeColor, true); + } else { + nw.setNodeColor(CfgPreferences.getInstance().getNodeColor(), false); + } + } + break; + case CfgPreferences.PROP_SELECTION_COLOR_BG: + case CfgPreferences.PROP_SELECTION_COLOR_FG: + for (CfgNode n : scene.getNodes()) { + Widget w = scene.findWidget(n); + w.revalidate(); + } + break; + } + scene.validate(); + } + + } + + /*@Override + public Component getToolBarComponent() { + Toolbar tb = new Toolbar("CfgToolbar"); + + tb.setBorder((Border) UIManager.get("Nb.Editor.Toolbar.border")); + + //zoomin/zoomout buttons + tb.add(SystemAction.get(ZoominAction.class).getToolbarPresenter()); + tb.add(SystemAction.get(ZoomoutAction.class).getToolbarPresenter()); + tb.addSeparator(); + + //router buttons + ButtonGroup routerButtons = new ButtonGroup(); + UseDirectLineRouterAction direct = SystemAction.get(UseDirectLineRouterAction.class); + UseBezierRouterAction bezier = SystemAction.get(UseBezierRouterAction.class); + JToggleButton button = (JToggleButton) direct.getToolbarPresenter(); + button.getModel().setGroup(routerButtons); + button.setSelected(true); + tb.add(button); + button = (JToggleButton) bezier.getToolbarPresenter(); + button.getModel().setGroup(routerButtons); + tb.add(button); + tb.addSeparator(); + + //layout buttons + tb.add(SystemAction.get(HierarchicalNodeLayoutAction.class).getToolbarPresenter()); + tb.add(SystemAction.get(HierarchicalCompoundLayoutAction.class).getToolbarPresenter()); + + tb.addSeparator(); + tb.add(SystemAction.get(ShowAllAction.class).getToolbarPresenter()); + tb.addSeparator(); + + //cluster button + tb.add(SystemAction.get(SwitchLoopClustersAction.class).getToolbarPresenter()); + tb.addSeparator(); + + //show/hide edge button + tb.add(SystemAction.get(ShowEdgesAction.class).getToolbarPresenter()); + tb.add(SystemAction.get(HideEdgesAction.class).getToolbarPresenter()); + tb.addSeparator(); + + //color button + JComponent colorButton = SystemAction.get(ColorAction.class).getToolbarPresenter(); + scene.addCfgEventListener((CfgEventListener) colorButton); + tb.add(colorButton); + + //export button + tb.add(SystemAction.get(ExportAction.class).getToolbarPresenter()); + tb.doLayout(); + + return tb; + }*/ + + @Override + public Lookup getLookup() { + return Lookups.fixed(scene); + } + + @Override + public Component getComponent() { + return jScrollPane; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/CfgCompilationViewerFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/CfgCompilationViewerFactory.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,26 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package at.ssw.visualizer.cfg; + +import com.oracle.graal.visualizer.editor.CompilationViewer; +import com.oracle.graal.visualizer.editor.CompilationViewerFactory; +import com.oracle.graal.visualizer.editor.DiagramViewModel; +import com.oracle.graal.visualizer.editor.SplitCompilationViewerFactory; +import com.sun.hotspot.igv.data.InputGraph; + +public class CfgCompilationViewerFactory extends SplitCompilationViewerFactory { + + @Override + public String getName() { + return "CFG"; + } + + @Override + protected CompilationViewer createViewer(InputGraph graph) { + return new CfgCompilationViewer(graph); + } + +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/CfgEditorContext.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/CfgEditorContext.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,10 @@ + +package at.ssw.visualizer.cfg; + +public abstract class CfgEditorContext { + + public static final int LAYOUT_HIERARCHICALNODELAYOUT = 1; + public static final int LAYOUT_HIERARCHICALCOMPOUNDLAYOUT = 2; + + public static final int MAX_AUTOEDGESVISIBLE = 8; +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/AbstractCfgEditorAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/AbstractCfgEditorAction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,57 @@ +package at.ssw.visualizer.cfg.action; + + +import at.ssw.visualizer.cfg.graph.CfgScene; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JMenuItem; +import org.openide.util.Utilities; +import org.openide.util.actions.CallableSystemAction; + +/** + * The common superclass of all concrete actions related to the CFG visualizer. + * + * @author Bernhard Stiftner + * @author Rumpfhuber Stefan + */ +public abstract class AbstractCfgEditorAction extends CallableSystemAction { + + CfgScene topComponent = null; + + public AbstractCfgEditorAction() { + setEnabled(false); + + } + + protected CfgScene getEditor() { + return Utilities.actionsGlobalContext().lookup(CfgScene.class); + } + + @Override + public JMenuItem getMenuPresenter() { + return new JMenuItem(this); + } + + + @Override + public JComponent getToolbarPresenter() { + JButton b = new JButton(this); + if (getIcon() != null) { + b.setText(null); + b.setToolTipText(getName()); + } + return b; + } + + + @Override + public JMenuItem getPopupPresenter() { + return new JMenuItem(this); + } + + + @Override + protected boolean asynchronous() { + return false; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/Bundle.properties Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,2 @@ +CTL_SomeAction=test +CTL_SomeAction2=test diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/HideEdgesAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/HideEdgesAction.java Tue Feb 07 22:41:09 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.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 = "at.ssw.visualizer.cfg.action.HideEdges", category = "View") +@ActionRegistration(displayName = "Hide Edges", iconBase="at/ssw/visualizer/cfg/icons/hideedges.gif") +@ActionReference(path = "CompilationViewer/CFG/Actions", position = 180) +public class HideEdgesAction implements ActionListener { + + private List scenes; + + public HideEdgesAction(List scenes) { + this.scenes = scenes; + } + + @Override + public void actionPerformed(ActionEvent e) { + for (CfgScene scene : scenes) { + scene.setSelectedEdgesVisibility(false); + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/HierarchicalCompoundLayoutAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/HierarchicalCompoundLayoutAction.java Tue Feb 07 22:41:09 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 = "at.ssw.visualizer.cfg.action.HierarchicalCompoundLayout", category = "View") +@ActionRegistration(displayName = "Compound Layout", iconBase="at/ssw/visualizer/cfg/icons/arrangeloop.gif") +@ActionReference(path = "CompilationViewer/CFG/Actions", position = 150) +public class HierarchicalCompoundLayoutAction implements ActionListener { + List scenes; + + public HierarchicalCompoundLayoutAction(List scenes) { + this.scenes = scenes; + } + + @Override + public void actionPerformed(ActionEvent e) { + for (CfgScene s : scenes) { + s.setSceneLayout(CfgEditorContext.LAYOUT_HIERARCHICALCOMPOUNDLAYOUT); + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/HierarchicalNodeLayoutAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/HierarchicalNodeLayoutAction.java Tue Feb 07 22:41:09 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 = "at.ssw.visualizer.cfg.action.HierarchicalNodeLayout", category = "View") +@ActionRegistration(displayName = "Layout", iconBase="at/ssw/visualizer/cfg/icons/arrangehier.gif") +@ActionReference(path = "CompilationViewer/CFG/Actions", position = 160) +public class HierarchicalNodeLayoutAction implements ActionListener { + List scenes; + + public HierarchicalNodeLayoutAction(List scenes) { + this.scenes = scenes; + } + + @Override + public void actionPerformed(ActionEvent e) { + for (CfgScene s : scenes) { + s.setSceneLayout(CfgEditorContext.LAYOUT_HIERARCHICALNODELAYOUT); + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/ShowEdgesAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/action/ShowEdgesAction.java Tue Feb 07 22:41:09 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.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 = "ShowEdges", category = "View") +@ActionRegistration(displayName = "Show Edges", iconBase="at/ssw/visualizer/cfg/icons/showedges.gif") +@ActionReference(path = "CompilationViewer/CFG/Actions", position = 170) +public class ShowEdgesAction implements ActionListener { + + private List scenes; + + public ShowEdgesAction(List scenes) { + this.scenes = scenes; + } + + @Override + public void actionPerformed(ActionEvent e) { + for (CfgScene scene : scenes) { + scene.setSelectedEdgesVisibility(true); + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/CfgScene.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/CfgScene.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,836 @@ +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 com.oracle.graal.visualizer.sharedactions.ZoomCookie; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.RenderingHints; +import java.awt.event.ActionEvent; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.prefs.PreferenceChangeEvent; +import java.util.prefs.PreferenceChangeListener; +import java.util.prefs.Preferences; +import javax.swing.AbstractAction; +import javax.swing.JComponent; +import javax.swing.JMenu; +import javax.swing.JPopupMenu; +import javax.swing.JScrollPane; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.event.EventListenerList; +import org.netbeans.api.visual.action.ActionFactory; +import org.netbeans.api.visual.action.MoveProvider; +import org.netbeans.api.visual.action.PopupMenuProvider; +import org.netbeans.api.visual.action.RectangularSelectDecorator; +import org.netbeans.api.visual.action.RectangularSelectProvider; +import org.netbeans.api.visual.action.WidgetAction; +import org.netbeans.api.visual.anchor.Anchor; +import org.netbeans.api.visual.anchor.AnchorFactory; +import org.netbeans.api.visual.graph.GraphScene; +import org.netbeans.api.visual.graph.layout.GraphLayout; +import org.netbeans.api.visual.layout.LayoutFactory; +import org.netbeans.api.visual.layout.SceneLayout; +import org.netbeans.api.visual.router.Router; +import org.netbeans.api.visual.router.Router.*; +import org.netbeans.api.visual.router.RouterFactory; +import org.netbeans.api.visual.widget.ConnectionWidget; +import org.netbeans.api.visual.widget.LayerWidget; +import org.netbeans.api.visual.widget.Widget; +import org.openide.util.NbPreferences; +import org.openide.util.actions.SystemAction; + +public final class CfgScene extends GraphScene implements ChangeListener, ZoomCookie { + + private LayerWidget mainLayer = new LayerWidget(this); + private LayerWidget connectionLayer = new LayerWidget(this); + private LayerWidget interractionLayer = new LayerWidget(this); + private LayerWidget clusterLayer = new LayerWidget(this); + private Set selectedNodes = Collections.emptySet(); + private Map loopidx2clusterwidget = new HashMap<>(); + private Map inputSwitches = new HashMap<>(); + private Map outputSwitches = new HashMap<>(); + private WidgetAction moveAction = ActionFactory.createMoveAction(ActionFactory.createFreeMoveStrategy(), this.createMoveProvider()); + private SceneLayout sceneLayout; + private CfgEnv env; + private int currentLayout = -1; + private JScrollPane scrollPane; + private WidgetAction contextPopupAction = this.createContextMenuAction(this); + private List nodeWidgets = null; + private boolean loopClustersVisible = true; + private static String PREFERENCE_LOOP_CLUSTER = "loopClusters"; + 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())); + } else if (evt.getKey().equals(PREFERENCE_LOOP_CLUSTER)) { + setLoopWidgets(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)); + setLoopWidgets(getPreferences().getBoolean(PREFERENCE_LOOP_CLUSTER, true)); + setSceneLayout(getPreferences().getInt(PREFERENCE_LAYOUT, CfgEditorContext.LAYOUT_HIERARCHICALNODELAYOUT)); + } + + //sets the parent Widget of all LoopClusterWidgets + private void stackLoops(Map map) { + this.clusterLayer.removeChildren(); + + Set cache = new HashSet<>(); + for (LoopInfo info : map.values()) { + if (cache.contains(info)) { + continue; + } + LoopClusterWidget widget = this.loopidx2clusterwidget.get(info.getLoopIndex()); + LoopInfo parent = info.getParent(); + while (parent != null) { + LoopClusterWidget parentWidget = this.loopidx2clusterwidget.get(parent.getLoopIndex()); + assert parentWidget != null; + if (widget.getParentWidget() != null) { + widget.removeFromParent(); + } + parentWidget.addChild(widget); + widget = parentWidget; + parent = parent.getParent(); + } + widget.removeFromParent(); + this.clusterLayer.addChild(widget);//parent == null => parent is clusterlayer + } + } + + //hide in|output edges + private void autoHideEdges() { + for (CfgNode n : this.getNodes()) { + int fanin = n.getInputEdges().length; + int fanout = n.getOutputEdges().length; + if (fanin > CfgEditorContext.MAX_AUTOEDGESVISIBLE) { + assert (inputSwitches.containsKey(n)); + if (this.inputSwitches.containsKey(n)) { + EdgeSwitchWidget esw = this.inputSwitches.get(n); + esw.changeEdgeVisibility(false); + } + } + if (fanout > CfgEditorContext.MAX_AUTOEDGESVISIBLE) { + if (this.outputSwitches.containsKey(n)) { + EdgeSwitchWidget esw = this.outputSwitches.get(n); + esw.changeEdgeVisibility(false); + } + } + } + + } + + //apply current cfggraphscene layout + public void applyLayout() { + this.sceneLayout.invokeLayoutImmediately(); + } + + //returns a Set with the currently selected Nodes + public Set getSelectedNodes() { + return Collections.unmodifiableSet(selectedNodes); + } + + public Map getLoopidx2clusterwidget() { + return loopidx2clusterwidget; + } + + /** + * Sets the color of the currently selected Nodes If the supplied color is null the default color will be used + */ + public void setSelectedNodesColor(Color color) { + if (color == null) { //set default color + CfgPreferences prefs = CfgPreferences.getInstance(); + boolean customized = false; + for (CfgNode n : this.selectedNodes) { + color = null; + color = prefs.getFlagsSetting().getColor(n.getBasicBlock().getFlags()); + customized = (color != null); + NodeWidget nw = (NodeWidget) this.findWidget(n); + nw.setNodeColor((customized) ? color : prefs.getNodeColor(), customized); + } + } else { + for (CfgNode n : this.selectedNodes) { + NodeWidget nw = (NodeWidget) this.findWidget(n); + nw.setNodeColor(color, true); + } + } + this.validate(); + } + + public void setSelectedEdgesVisibility(boolean visible) { + for (CfgNode n : this.selectedNodes) { + EdgeSwitchWidget in = this.inputSwitches.get(n); + EdgeSwitchWidget out = this.outputSwitches.get(n); + if (in != null) { + in.changeEdgeVisibility(visible); + } + if (out != null) { + out.changeEdgeVisibility(visible); + } + } + this.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(); + getPreferences().putBoolean(PREFERENCE_LOOP_CLUSTER, visible); + } + + private void setUseBezierRouter(boolean value) { + Router router; + if (value) { + router = new PolylineRouterV2(new WidgetCollisionCollector() { + @Override + public void collectCollisions(List collisions) { + collisions.addAll(getNodeWidgets()); + } + }); + } else { + router = RouterFactory.createDirectRouter(); + } + + for (CfgEdge e : this.getEdges()) { + EdgeWidget ew = (EdgeWidget) this.findWidget(e); + ew.setRouter(router); + } + this.validate(); + getPreferences().putBoolean(PREFERENCE_ROUTER, value); + } + + public Collection getNodeWidgets() { + if (nodeWidgets != null && nodeWidgets.size() == this.getNodes().size()) { + return nodeWidgets; + } + + List widgets = new ArrayList<>(); + for (CfgNode n : this.getNodes()) { + NodeWidget w = (NodeWidget) this.findWidget(n); + widgets.add(w); + } + + nodeWidgets = Collections.unmodifiableList(widgets); + return widgets; + } + + public void setSceneLayout(int newLayout) { + + GraphLayout graphLayout = null; + + switch (newLayout) { + case CfgEditorContext.LAYOUT_HIERARCHICALNODELAYOUT: + graphLayout = new HierarchicalNodeLayout(this); + break; + + case CfgEditorContext.LAYOUT_HIERARCHICALCOMPOUNDLAYOUT: + graphLayout = new HierarchicalCompoundLayout(this); + break; + } + + this.currentLayout = newLayout; + if (graphLayout != null) { + this.sceneLayout = LayoutFactory.createSceneGraphLayout(this, graphLayout); + } + + getPreferences().putInt(PREFERENCE_LAYOUT, newLayout); + sceneLayout.invokeLayoutImmediately(); + } + + @Override + protected void attachEdgeSourceAnchor(CfgEdge edge, CfgNode oldSourceNode, CfgNode sourceNode) { + Anchor sourceAnchor; + EdgeWidget edgeWidget = (EdgeWidget) findWidget(edge); + Widget sourceWidget = findWidget(sourceNode); + + if (edge.isSymmetric()) { + sourceAnchor = new SymmetricAnchor(sourceWidget, true, true); + } else { + sourceAnchor = AnchorFactory.createRectangularAnchor(sourceWidget); + } + edgeWidget.setSourceAnchor(sourceAnchor); + } + + @Override + protected void attachEdgeTargetAnchor(CfgEdge edge, CfgNode oldtarget, CfgNode targetNode) { + Anchor targetAnchor; + ConnectionWidget edgeWidget = (ConnectionWidget) findWidget(edge); + Widget targetWidget = findWidget(targetNode); + + if (edge.isSymmetric()) { + targetAnchor = new SymmetricAnchor(targetWidget, true, false); + } else { + targetAnchor = AnchorFactory.createRectangularAnchor(targetWidget); + } + edgeWidget.setTargetAnchor(targetAnchor); + } + + @Override + protected Widget attachEdgeWidget(CfgEdge edge) { + EdgeWidget widget = new EdgeWidget(this, edge); + connectionLayer.addChild(widget); + attachSourceSwitchWidget(edge); + attachTargetSwitchWidget(edge); + return widget; + } + + @Override + protected Widget attachNodeWidget(CfgNode node) { + this.nodeWidgets = null; + + NodeWidget nw = new NodeWidget(this, node); + WidgetAction.Chain actions = nw.getActions(); + actions.addAction(this.contextPopupAction); + actions.addAction(this.moveAction); + actions.addAction(this.createObjectHoverAction()); + + if (node.isLoopMember()) { + LoopClusterWidget loopWidget = this.attachLoopMember(node); + loopWidget.addMember(nw); + } + mainLayer.addChild(nw); + return nw; + } + + private LoopClusterWidget attachLoopMember(CfgNode node) { + LoopClusterWidget lw = this.loopidx2clusterwidget.get(node.getLoopIndex()); + if (lw == null) { + lw = new LoopClusterWidget(this, node.getLoopDepth(), node.getLoopIndex()); + this.loopidx2clusterwidget.put(node.getLoopIndex(), lw); + this.clusterLayer.addChild(lw); + } + return lw; + } + + private boolean detachLoopMember(CfgNode node, NodeWidget nodeWidget) { + LoopClusterWidget rm = this.loopidx2clusterwidget.get(node.getLoopIndex()); + if (rm == null) { + return false;//not added + } + if (rm.removeMember(nodeWidget)) { + if (rm.getMembers().isEmpty()) { + this.loopidx2clusterwidget.remove(rm.getLoopIndex()); + List childs = new ArrayList<>(rm.getChildren()); + for (Widget w : childs) {//append stacked loopwidgets + w.removeFromParent(); + rm.getParentWidget().addChild(w); + } + rm.removeFromParent(); + } + return true; + } + return false; + } + + //this function is not invoked by any class of the module + //however to ensure that the edge switches are treatet corretly + //when a future version removes nodes it was implemented too. + @Override + protected void detachNodeWidget(CfgNode node, Widget nodeWidget) { + if (node.isLoopMember() && nodeWidget instanceof NodeWidget) { + this.detachLoopMember(node, (NodeWidget) nodeWidget); + } + super.detachNodeWidget(node, nodeWidget); + assert nodeWidget.getParentWidget() == null; + if (this.inputSwitches.containsKey(node)) { + EdgeSwitchWidget esw = this.inputSwitches.remove(node); + this.connectionLayer.removeChild(esw); + } + if (this.outputSwitches.containsKey(node)) { + EdgeSwitchWidget esw = this.outputSwitches.remove(node); + this.connectionLayer.removeChild(esw); + } + } + + protected EdgeSwitchWidget attachSourceSwitchWidget(CfgEdge e) { + CfgNode sourceNode = e.getSourceNode(); + NodeWidget sourceWidget = (NodeWidget) this.findWidget(sourceNode); + EdgeSwitchWidget out = outputSwitches.get(sourceNode); + if (out == null) { + out = new EdgeSwitchWidget(this, sourceWidget, true); + this.connectionLayer.addChild(out); + outputSwitches.put(sourceNode, out); + } + return out; + } + + protected EdgeSwitchWidget attachTargetSwitchWidget(CfgEdge e) { + CfgNode targetNode = e.getTargetNode(); + NodeWidget targetWidget = (NodeWidget) this.findWidget(targetNode); + EdgeSwitchWidget in = inputSwitches.get(targetNode); + if (in == null) { + in = new EdgeSwitchWidget(this, targetWidget, false); + this.connectionLayer.addChild(in); + inputSwitches.put(targetNode, in); + } + return in; + } + + //resets the selection state of all NodeWidgets + private void cleanNodeSelection() { + if (!this.selectedNodes.isEmpty()) { + this.userSelectionSuggested(Collections.emptySet(), false); + this.selectedNodes = Collections.emptySet(); + this.validate(); + } + } + + //sets the scene & global node selection + public void setNodeSelection(Set newSelection) { + this.setSceneSelection(newSelection); + this.updateGlobalSelection(); + } + + //sets the scene selection + private void setSceneSelection(Set newSelection) { + if (newSelection.equals(selectedNodes)) { + return; + } + + this.selectedNodes = newSelection; + + Set selectedObjects = new HashSet<>(); + + for (CfgNode n : newSelection) { + selectedObjects.addAll(this.findNodeEdges(n, true, true)); + } + selectedObjects.addAll(newSelection); + + //if the selection gets updated from a change in the block view + //the scene will be centered + if (selectionUpdating) { + this.centerSelection(); + } + + this.userSelectionSuggested(selectedObjects, false); + this.validate(); + } + + //updates selection of Block View + public void updateGlobalSelection() { + // TODO(tw): Add selection management. +// Selection selection = SelectionManager.getDefault().getCurSelection(); +// ArrayList newBlocks = new ArrayList(); +// for (CfgNode n : this.selectedNodes) { +// newBlocks.add(n.getBasicBlock()); +// } +// BasicBlock[] curBlocks = newBlocks.toArray(new BasicBlock[newBlocks.size()]); +// selection.put(curBlocks); + } + private boolean selectionUpdating = false; + + //change of blockview selection + public void stateChanged(ChangeEvent event) { + if (selectionUpdating) { + return; + } + + selectionUpdating = true; + + Object source = event.getSource(); +// if(source instanceof Selection){ +// Selection selection=(Selection) source; +// Set newSelection = new HashSet(); +// BasicBlock[] newBlocks = selection.get(BasicBlock[].class); +// if (newBlocks != null) { +// for(BasicBlock b : newBlocks){ +// for(CfgNode n : this.getNodes()){ +// if(n.getBasicBlock() == b) newSelection.add(n); +// } +// } +// this.setSceneSelection(newSelection); +// } +// } + selectionUpdating = false; + // TODO(tw): Add selection management. + } + + //centers the viewport on the currently selected nodewidgets + private void centerSelection() { + Point sceneCenter = null; + Collection nodes = this.selectedNodes; + if (nodes.size() == 0) { + nodes = this.getNodes(); + } + + for (CfgNode n : nodes) { + if (sceneCenter == null) { + sceneCenter = this.findWidget(n).getLocation(); + continue; + } + Point location = this.findWidget(n).getLocation(); + sceneCenter.x = (location.x + sceneCenter.x) / 2; + sceneCenter.y = (location.y + sceneCenter.y) / 2; + } + + JComponent view = this.getView(); + if (view != null) { + Rectangle viewBounds = view.getVisibleRect(); + + Point viewCenter = this.convertSceneToView(sceneCenter); + + view.scrollRectToVisible(new Rectangle( + viewCenter.x - viewBounds.width / 2, + viewCenter.y - viewBounds.height / 2, + viewBounds.width, + viewBounds.height)); + } + } + + public void zoomScene() { + JScrollPane pane = scrollPane; + Rectangle prefBounds = this.getPreferredBounds(); + Dimension viewDim = pane.getViewportBorderBounds().getSize(); + + double realwidth = (double) prefBounds.width * this.getZoomFactor(); + double realheight = (double) prefBounds.height * this.getZoomFactor(); + + double zoomX = (double) viewDim.width / realwidth; + double zoomY = (double) viewDim.height / realheight; + double zoomFactor = Math.min(zoomX, zoomY); + this.setZoomFactor(zoomFactor * 0.9); + } + + //Enables Antialiasing + @Override + public void paintChildren() { + Object anti = getGraphics().getRenderingHint(RenderingHints.KEY_ANTIALIASING); + Object textAnti = getGraphics().getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING); + + getGraphics().setRenderingHint( + RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + getGraphics().setRenderingHint( + RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + + super.paintChildren(); + + getGraphics().setRenderingHint(RenderingHints.KEY_ANTIALIASING, anti); + getGraphics().setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, textAnti); + } + + //select provider for node selection + private RectangularSelectProvider createRectangularSelectProvider() { + return new RectangularSelectProvider() { + + public void performSelection(Rectangle rectangle) { + HashSet set = new HashSet<>(); + + //change to a rectangle with (x,offsetY) at the top left + if (rectangle.width < 0) { + rectangle.x = rectangle.x + rectangle.width; + rectangle.width *= -1; + } + if (rectangle.height < 0) { + rectangle.y = rectangle.y + rectangle.height; + rectangle.height *= -1; + } + + for (NodeWidget n : getNodeWidgets()) { + Point p = n.getLocation(); + if (p != null && rectangle.contains(p)) { + set.add(n.getNodeModel()); + } + } + setNodeSelection(set); + } + }; + } + + //select decorator for node selection + private RectangularSelectDecorator createSelectDecorator(final CfgScene scene) { + return new RectangularSelectDecorator() { + + public Widget createSelectionWidget() { + scene.cleanNodeSelection();//unselected all nodes + scene.revalidate(); + return new SelectionWidget(getScene()); + } + }; + } + + private MoveProvider createMoveProvider() { + return new MoveProvider() { + + private HashMap originals = new HashMap<>(); + private Point original = null; + + public void movementStarted(Widget widget) { + originals.clear(); + NodeWidget nw = (NodeWidget) widget; + if (selectedNodes.contains(nw.getNodeModel())) {//move current selection + for (CfgNode n : selectedNodes) { + Widget w = findWidget(n); + originals.put(w, w.getLocation()); + } + } else {//a newly-selected node will be moved + CfgNode n = nw.getNodeModel(); + HashSet selectedNode = new HashSet<>(1); + selectedNode.add(n); + setNodeSelection(selectedNode); + originals.put(widget, widget.getPreferredLocation()); + widget.revalidate(); + validate(); + + } + } + + public void movementFinished(Widget widget) { + NodeWidget nw = (NodeWidget) widget; + if (selectedNodes.contains(nw.getNodeModel())) { + return;//to be able to move the current selection + } + + HashSet selectedNode = new HashSet<>(1); + selectedNode.add(nw.getNodeModel()); + setNodeSelection(selectedNode); + originals.clear(); + original = null; + + } + + public Point getOriginalLocation(Widget widget) { + if (original == null) { + original = widget.getLocation(); + } + + return original; + } + //todo : find a cache algorithm which only routes edges + //which are intersected by bounds of the moved rectangle + + public void setNewLocation(Widget widget, Point location) { + Point org = getOriginalLocation(widget); + int dx = location.x - org.x; + int dy = location.y - org.y; + for (Map.Entry entry : originals.entrySet()) { + Point point = entry.getValue(); + entry.getKey().setPreferredLocation(new Point(point.x + dx, point.y + dy)); + } + for (CfgEdge e : getEdges()) { + EdgeWidget ew = (EdgeWidget) findWidget(e); + if (ew.isVisible()) { + ew.reroute(); + } + } + } + }; + } + + private WidgetAction createContextMenuAction(final CfgScene scene) { + return ActionFactory.createPopupMenuAction(new PopupMenuProvider() { + + public JPopupMenu getPopupMenu(Widget widget, Point point) { + JPopupMenu menu = new JPopupMenu(); + NodeWidget nw = null; + if (widget instanceof NodeWidget) { + nw = (NodeWidget) widget; + if (!selectedNodes.contains(nw.getNodeModel())) { + HashSet selectedNode = new HashSet<>(1); + selectedNode.add(nw.getNodeModel()); + setNodeSelection(selectedNode); + } + } else if (scene.getSelectedNodes().size() == 1) { + nw = (NodeWidget) scene.findWidget(scene.getSelectedNodes().iterator().next()); + } + + if (nw != null) { + CfgNode node = nw.getNodeModel(); + ArrayList successors = new ArrayList<>(); + ArrayList predecessors = new ArrayList<>(); + for (CfgEdge e : node.getOutputEdges()) { + successors.add(e.getTargetNode()); + } + for (CfgEdge e : node.getInputEdges()) { + predecessors.add(e.getSourceNode()); + } + + if (predecessors.size() > 0) { + Collections.sort(predecessors, new NodeNameComparator()); + JMenu predmenu = new JMenu("Go to predecessor"); + for (CfgNode n : predecessors) { + GotoNodeAction action = new GotoNodeAction(n); + predmenu.add(action); + } + menu.add(predmenu); + } + if (successors.size() > 0) { + Collections.sort(successors, new NodeNameComparator()); + JMenu succmenu = new JMenu("Go to successor"); + for (CfgNode n : successors) { + GotoNodeAction action = new GotoNodeAction(n); + succmenu.add(action); + } + menu.add(succmenu); + } + if (successors.size() > 0 || predecessors.size() > 0) { + menu.addSeparator(); + } + } + + return menu; + } + }); + } + + @Override + public void zoomIn() { + this.setZoomFactor(this.getZoomFactor() * 1.1); + this.validate(); + } + + @Override + public void zoomOut() { + this.setZoomFactor(this.getZoomFactor() * 0.9); + this.validate(); + } + + @Override + public void showAll() { + this.zoomScene(); + this.validate(); + } + + private class NodeNameComparator implements Comparator { + + public int compare(CfgNode node1, CfgNode node2) { + String name1 = node1.getBasicBlock().getName().substring(1); + String name2 = node2.getBasicBlock().getName().substring(1); + Integer blocknum1 = Integer.parseInt(name1); + Integer blocknum2 = Integer.parseInt(name2); + return blocknum1.compareTo(blocknum2); + } + } + + private class GotoNodeAction extends AbstractAction { + + CfgNode node; + + GotoNodeAction(CfgNode node) { + super(node.getBasicBlock().getName()); + this.node = node; + } + + public void actionPerformed(ActionEvent e) { + Set nodes = new HashSet<>(1); + nodes.add(node); + setNodeSelection(nodes); + centerSelection(); + } + } + + private SceneListener createSceneListener(final CfgScene scene) { + return new SceneListener() { + + public void sceneRepaint() { + } + + public void sceneValidating() { + } + + public void sceneValidated() { + if (scene.isLoopClusterVisible()) { //update only if visible + for (LoopClusterWidget cw : getLoopidx2clusterwidget().values()) { + cw.updateClusterBounds(); + } + } + for (EdgeSwitchWidget esw : inputSwitches.values()) { + esw.updatePosition(); + } + + for (EdgeSwitchWidget esw : outputSwitches.values()) { + esw.updatePosition(); + } + } + }; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/EdgeSwitchWidget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/EdgeSwitchWidget.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,290 @@ +package at.ssw.visualizer.cfg.graph; + +import at.ssw.visualizer.cfg.model.CfgEdge; +import at.ssw.visualizer.cfg.model.CfgNode; +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.Polygon; +import java.awt.Rectangle; +import java.awt.geom.AffineTransform; +import java.util.ArrayList; +import java.util.Collection; +import org.netbeans.api.visual.action.ActionFactory; +import org.netbeans.api.visual.action.SelectProvider; +import org.netbeans.api.visual.action.TwoStateHoverProvider; +import org.netbeans.api.visual.action.WidgetAction; +import org.netbeans.api.visual.model.ObjectState; +import org.netbeans.api.visual.widget.Widget; + + +public class EdgeSwitchWidget extends Widget { + private final static Color color_enabled = Color.gray; + private final static Color color_hover = Color.lightGray; + private float width=1; + private float height=1; + private CfgScene scene; + private NodeWidget nodeWidget; + private boolean output; + private WidgetAction hoverAction; + private static final String TT_HIDE_EDGES = "Hide Edges"; + private static final String TT_SHOW_EDGES = "Show Edges"; + private static SelectProvider selectProvider = createSelectProvider(); + + + public EdgeSwitchWidget(final CfgScene scene, NodeWidget nodeWidget, boolean output) { + super(scene); + this.scene = scene; + this.output = output; + this.nodeWidget = nodeWidget; + + this.getActions().addAction(ActionFactory.createSelectAction(selectProvider)); + TwoStateHoverProvider ts = new TsHover(this); + WidgetAction wa = ActionFactory.createHoverAction(ts); + this.hoverAction = wa; + this.getActions().addAction(wa); + scene.getActions().addAction(wa); + this.setToolTipText(TT_HIDE_EDGES); + this.setForeground(color_enabled); + this.setState(ObjectState.createNormal()); + } + + + @Override + protected Rectangle calculateClientArea() { + if (this.nodeWidget.getBounds() == null) return new Rectangle(0, 0, 1, 1); + int hw = (int) (this.width / 2); + int hh = (int) (this.height /2); + + return new Rectangle(-hw, -hh, 2*hw, 2*hh); + } + + + public void updatePosition() { + if (this.nodeWidget.getBounds() != null) { + this.width = nodeWidget.getBounds().width*9; + this.width /=10; + this.height = nodeWidget.getBounds().height/4; + int offset=(int)(2 * (height / 3)); + + Rectangle bounds = nodeWidget.getBounds(); + Point location = nodeWidget.getLocation(); + + Point newLoc = new Point(); + newLoc.x = location.x; + + if(output) { + newLoc.y = +location.y + bounds.height/2+offset; + }else { + newLoc.y = location.y - bounds.height/2-offset; + } + this.setPreferredLocation(newLoc); + } + } + + private Collection getEdges(){ + Collection edges; + CfgNode node = nodeWidget.getNodeModel(); + if (output) { + edges = scene.findNodeEdges(node, true, false); + } else { + edges = scene.findNodeEdges(node, false, true); + } + return edges; + } + + //change visibility for all Edges + public void changeEdgeVisibility(boolean visible){ + Collection edges = this.getEdges(); + + for(CfgEdge e: edges) { + EdgeWidget ew = (EdgeWidget) scene.findWidget(e); + if(visible != ew.isEdgeVisible()){ + ew.setEdgeVisible(visible); + if(output){ + scene.getInputSwitch(e.getTargetNode()).updateStatus(); + } else { + scene.getOutputSwitch(e.getSourceNode()).updateStatus(); + } + } + } + if(visible) + this.setToolTipText(TT_HIDE_EDGES); + else + this.setToolTipText(TT_SHOW_EDGES); + + this.setForeground(color_enabled); + this.bringToBack(); + ObjectState os = this.getState(); + this.setState(os.deriveSelected(!visible)); + } + + /** + * Update the status of the switch to the current state of the edges + * usually needed when the opposit switch changes the state + */ + private void updateStatus(){ + Collection edges = this.getEdges(); + boolean hiddenFound=false; + for(CfgEdge e: edges) { + EdgeWidget ew = (EdgeWidget) scene.findWidget(e); + if(!ew.isVisible()) { + hiddenFound=true; + break; + } + } + ObjectState os = this.getState(); + if(os.isSelected() && !hiddenFound) { + this.setState(os.deriveSelected(false)); + setToolTipText(TT_HIDE_EDGES); + } else if (!os.isSelected() && hiddenFound) { + this.setState(os.deriveSelected(true)); + setToolTipText(TT_SHOW_EDGES); + } + this.revalidate(); + } + + + public void startPreview() { + ObjectState os = this.getState(); + + for(CfgEdge e : getEdges()) { + EdgeWidget ew = (EdgeWidget) scene.findWidget(e); + if(!os.isSelected() || !ew.isVisible()){ + ObjectState edgeState = ew.getState(); + ew.setState(edgeState.deriveHighlighted(true)); + } + } + } + + public void endPreview(){ + for(CfgEdge e : getEdges()) { + EdgeWidget ew = (EdgeWidget) scene.findWidget(e); + ObjectState os = ew.getState(); + ew.setState(os.deriveHighlighted(false)); + } + } + + /** + * shows or hides the edges of the switch + */ + public void switchEdges() { + endPreview(); + ObjectState os = this.getState(); + Collection edges = this.getEdges(); + ArrayList updates = new ArrayList<>(); + boolean visible=os.isSelected(); + this.setState(os.deriveSelected(!visible)); + for(CfgEdge e: edges) { + EdgeWidget ew = (EdgeWidget) scene.findWidget(e); + if(ew.isEdgeVisible() != visible){ + updates.add(e); + ew.setEdgeVisible(visible); + if(output){ + scene.getInputSwitch(e.getTargetNode()).updateStatus(); + } else { + scene.getOutputSwitch(e.getSourceNode()).updateStatus(); + } + } + } + if(visible) + this.setToolTipText(TT_HIDE_EDGES); + else + this.setToolTipText(TT_SHOW_EDGES); + + revalidate(); + } + + + + + private class TsHover implements TwoStateHoverProvider { + EdgeSwitchWidget tw; + + TsHover(EdgeSwitchWidget tw) { + this.tw = tw; + } + + public void unsetHovering(Widget w) { + w.setForeground(color_enabled); + ObjectState state = w.getState(); + w.setState(state.deriveWidgetHovered(false)); + w.bringToBack(); + endPreview(); + } + + public void setHovering(Widget w) { + ObjectState state = w.getState(); + w.setState(state.deriveWidgetHovered(true)); + w.setForeground(color_hover); + w.bringToFront(); + nodeWidget.bringToFront(); + startPreview(); + } + } + + @Override + public void paintWidget() { + ObjectState os = this.getState(); + if(!os.isHovered() && !os.isSelected()) return; //all previewEdges visible and not hovering, + //no need to paint the switch + float hw = width/2; + Polygon pol = new Polygon(); + pol.addPoint(0,(int) -height/2); + pol.addPoint((int)hw,(int) height/2); + pol.addPoint((int)-hw,(int) height/2); + Graphics2D gr = getGraphics(); + gr.setColor(this.getForeground()); + BasicStroke bs = new BasicStroke(2.0f, BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND); + gr.setStroke(bs); + AffineTransform previousTransform; + previousTransform = gr.getTransform (); + if(output) { + if(os.isSelected() ){//hidden + gr.scale(1.0, -1.0); + } + } else { //input switch + if(os.isHovered() && !os.isSelected()){ + gr.scale(1.0, -1.0); + } + } + gr.fillPolygon(pol); + gr.setTransform(previousTransform); + + } + + + + //the constructor adds the hover WidgetAction to the scene + //the action is removed from the scene when the object gets destroyed + @Override + protected void finalize() throws Throwable { + this.getScene().getActions().removeAction(hoverAction); + this.getActions().removeAction(hoverAction); + } + + @Override + public String toString(){ + return "EDGESWITCH("+this.nodeWidget.getNodeModel().toString()+")"; + } + + private static SelectProvider createSelectProvider() { + return new SelectProvider(){ + public boolean isAimingAllowed(Widget arg0, Point arg1, boolean arg2) { + return false; + } + + public boolean isSelectionAllowed(Widget arg0, Point arg1, boolean arg2) { + return true; + } + + public void select(Widget w, Point arg1, boolean arg2) { + if(w instanceof EdgeSwitchWidget){ + EdgeSwitchWidget tw = (EdgeSwitchWidget) w; + tw.switchEdges(); + } + } + }; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/EdgeWidget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/EdgeWidget.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,97 @@ +package at.ssw.visualizer.cfg.graph; + +import at.ssw.visualizer.cfg.model.CfgEdge; +import at.ssw.visualizer.cfg.preferences.CfgPreferences; +import at.ssw.visualizer.cfg.visual.BezierWidget; +import at.ssw.visualizer.cfg.visual.SplineConnectionWidget; +import org.netbeans.api.visual.anchor.AnchorShapeFactory; +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Stroke; +import org.netbeans.api.visual.anchor.AnchorShape; +import org.netbeans.api.visual.model.ObjectState; + +//public class EdgeWidget extends BezierWidget { +public class EdgeWidget extends SplineConnectionWidget { + + private boolean visible=true;//to store the visible state when entering the preview + protected static final Stroke selectedStroke = new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); + protected static final Stroke defaultStroke = new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); + protected static final Stroke previewStroke = new BasicStroke( + 0.5f, // Width + BasicStroke.CAP_SQUARE, // End cap + BasicStroke.JOIN_MITER, // Join style + 10.0f, // Miter limit + new float[] {5.0f, 5.0f}, // Dash pattern + 0.0f); + + + + public EdgeWidget(CfgScene scene, CfgEdge edge) { + super(scene); + Color lineColor; + CfgPreferences prefs = CfgPreferences.getInstance(); + + if(edge.isBackEdge()) + lineColor = prefs.getBackedgeColor(); + else if (edge.isXhandler()) + lineColor = prefs.getExceptionEdgeColor(); + else + lineColor = prefs.getEdgeColor(); + + setLineColor(lineColor); + AnchorShape as; + if(edge.isReflexive())//small Arrow + as = AnchorShapeFactory.createTriangleAnchorShape(6, true, false, 5); + else + as =AnchorShapeFactory.createTriangleAnchorShape(10, true, false, 9); + + setTargetAnchorShape(as); + setToolTipText(edge.toString()); + } + + public CfgEdge getEdgeModel() { + CfgScene scene = (CfgScene) this.getScene(); + return (CfgEdge) scene.findObject(this); + } + + public void setEdgeVisible(boolean visible) { + this.visible=visible; + this.setVisible(visible); + this.reroute(); + this.revalidate(); + } + + + public boolean isEdgeVisible(){ + return visible; + } + + + @Override + public void notifyStateChanged(ObjectState oldState, ObjectState newState) { + setForeground (getLineColor()); + + if(newState.isHighlighted() && !oldState.isHighlighted()){ + this.setStroke(previewStroke); + this.setVisible(true); + } else { + if(newState.isSelected()){ + this.setStroke(selectedStroke); + } else { + this.setStroke(defaultStroke); + } + if(this.isEdgeVisible()){ + this.setVisible(true); + } else { + this.setVisible(false); + } + } + } + + + @Override + public String toString(){ + return "EdgeWidget[" + getEdgeModel().toString() + "]"; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/LoopClusterWidget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/LoopClusterWidget.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,107 @@ +package at.ssw.visualizer.cfg.graph; + +import at.ssw.visualizer.cfg.model.LoopInfo; +import java.awt.Color; +import java.awt.Rectangle; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import org.netbeans.api.visual.action.ActionFactory; +import org.netbeans.api.visual.action.EditProvider; +import org.netbeans.api.visual.border.BorderFactory; +import org.netbeans.api.visual.widget.Widget; + +public class LoopClusterWidget extends Widget implements Comparable { + private static final int INSET = 10;//min space between node members and cluster border + private static final int DASHSIZE = 10; + private Color color = Color.BLUE; + private int loopIndex; + private int loopDepth; + private CfgScene cfgscene; + private ArrayList members = new ArrayList<>(); + + public LoopClusterWidget(CfgScene scene, int loopdepth, final int loopindex) { + super(scene); + this.cfgscene = scene; + this.loopIndex = loopindex; + this.loopDepth = loopdepth; + this.setBorder(BorderFactory.createDashedBorder(color, DASHSIZE, DASHSIZE/2, true)); + this.getActions().addAction(ActionFactory.createEditAction( new EditProvider() { //double click action + public void edit(Widget w) { + if(w instanceof LoopClusterWidget){ + for(LoopInfo info : cfgscene.getCfgEnv().getLoopMap().values()){ + if(info.getLoopIndex() == loopindex){ + cfgscene.setNodeSelection(info.getMembers()); + break; + } + } + } + } + })); + + } + + public List getMembers() { + return members; + } + + public int getLoopIndex() { + return loopIndex; + } + + public void addMember(NodeWidget nw) { + assert(!this.members.contains(nw)); + members.add(nw); + } + + public boolean removeMember(NodeWidget nw) { + if(this.members.contains(nw)){ + members.remove(nw); + return true; + } + return false; + } + + public void setrandomColor(){ + if(this.loopDepth == 0 ) return; + Random rand = new Random(); + Color randColor = Color.getHSBColor(rand.nextFloat()%360,0.1f,1.0f); + this.setBackground(randColor); + } + + //updates the bounds of the widget, + //and revalidates the widget if a membernode changed the scene position + public void updateClusterBounds(){ + Rectangle boundRect=null; + + for(NodeWidget nw : this.members){ + if(boundRect==null){ + boundRect = nw.convertLocalToScene(nw.getBounds()); + } else { + boundRect = boundRect.union(nw.convertLocalToScene(nw.getBounds())); + } + } + if(boundRect==null) return; + for(Widget w : this.getChildren()) { + if(w instanceof LoopClusterWidget) { + LoopClusterWidget lc = (LoopClusterWidget)w; + lc.updateClusterBounds(); + boundRect = boundRect.union(w.convertLocalToScene(w.getBounds())); + } + } + + boundRect.grow(INSET, INSET); + this.setPreferredBounds(boundRect); + } + + + public int compareTo(LoopClusterWidget o) { + return new Integer(this.loopDepth).compareTo(o.loopDepth); + } + + + @Override + public String toString(){ + return "LoopCluster: [DEPTH "+this.loopDepth+ "] [INDEX "+this.loopIndex+"]"; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/NodeWidget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/NodeWidget.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,153 @@ +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 nodeColorCustomized; + private String text; + private Rectangle2D fontRect; + private Color nodeColor; + + protected static final Color HOVER_BACKGROUND = new Color(0xEEEEEE); + protected static final Color HOVER_FOREGROUND = new Color(0xCDCDCD); + + public NodeWidget(CfgScene scene, CfgNode nodeModel ){ + super(scene); + this.setToolTipText("" + nodeModel.getDescription().replaceAll("\n", "
") + ""); + this.text = nodeModel.getBasicBlock().getName(); + this.borderWidth = nodeModel.getLoopDepth()+1; + this.setBorder(BorderFactory.createRoundedBorder(arcWidth+borderWidth, arcHeight+borderWidth, borderWidth, borderWidth, Color.BLACK, Color.BLACK)); + CfgPreferences prefs = CfgPreferences.getInstance(); + Color color = prefs.getFlagsSetting().getColor(nodeModel.getBasicBlock().getFlags()); + this.nodeColorCustomized = (color!=null); + this.nodeColor = (nodeColorCustomized) ? color : prefs.getNodeColor(); + this.adjustFont(null); + } + + public void setBorderColor(Color color){ + this.setBorder(BorderFactory.createRoundedBorder(arcWidth+borderWidth, arcHeight+borderWidth, borderWidth, borderWidth, color, color)); + } + + public boolean isNodeColorCustomized() { + return nodeColorCustomized; + } + + //sets a customColor node color + public void setNodeColor(Color color, boolean customColor) { + this.nodeColorCustomized=customColor; + this.nodeColor=color; + this.revalidate(); + } + + public Color getNodeColor() { + return this.nodeColor; + } + + public CfgNode getNodeModel() { + CfgScene scene = (CfgScene) this.getScene(); + return (CfgNode) scene.findObject(this); + } + + + @Override + public void notifyStateChanged(ObjectState oldState, ObjectState newState) { + if(!oldState.equals(newState)) + this.revalidate(); + if(!oldState.isSelected() && newState.isSelected()) + this.bringToFront(); + } + + @Override + protected Rectangle calculateClientArea() { + return new Rectangle(-(halfwidth+1), -(1+halfheight), width+1, height+1);//add border + } + + public void adjustFont(Font font){ + if(font==null) + font = CfgPreferences.getInstance().getTextFont(); + if(font.getSize()>FONT_MAXSIZE){ + font = new Font(font.getFamily(), font.getStyle(), FONT_MAXSIZE); + } + int size=font.getSize(); + int fontStyle = font.getStyle(); + String fontName = font.getFamily(); + FontRenderContext frc = new FontRenderContext(new AffineTransform(), false, false); + Rectangle2D bounds = font.getStringBounds(text, frc); + while(size > 1 && bounds.getWidth() > width) { + font = new Font(fontName, fontStyle, --size); + bounds = font.getStringBounds(text, frc); + } + this.fontRect=bounds; + this.setFont(font); + } + + @Override + protected void paintWidget() { + Graphics2D gr = getGraphics(); + gr.setColor(nodeColor); + Insets borderInsets = this.getBorder().getInsets(); + RoundRectangle2D.Float innerRect = new RoundRectangle2D.Float(-(halfwidth+1), -(halfheight+1), width+1, height+1,arcWidth-1, arcHeight-1); + gr.fill(innerRect); + gr.setColor(getForeground()); + gr.setFont(getFont()); + float textX = (float)( - fontRect.getCenterX()); + float textY = (float)( - fontRect.getCenterY()); + gr.drawString(text, textX, textY); + + RoundRectangle2D.Float outerRect = new RoundRectangle2D.Float(-(halfwidth+borderInsets.left + 1), -(halfheight+borderInsets.top + 1), + width+borderInsets.left + borderInsets.right + 1, height + borderInsets.top + borderInsets.bottom + 1, + arcWidth + borderWidth, arcHeight + borderWidth); + + ObjectState os =this.getState(); + if(os.isSelected()){ + Composite composite = gr.getComposite(); + gr.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.5f)); + gr.setColor(CfgPreferences.getInstance().getSelectionColorForeground()); + gr.fill(outerRect); + gr.setColor(CfgPreferences.getInstance().getSelectionColorBackground()); + gr.setComposite(composite); + } + if(os.isHovered()){ + Composite composite = gr.getComposite(); + gr.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.5f)); + gr.setColor(HOVER_FOREGROUND); + gr.fill(outerRect); + gr.setColor(HOVER_BACKGROUND); + gr.setComposite(composite); + } + } + + @Override + public String toString() { + return "NodeWidget[" + getNodeModel().getBasicBlock().getName() + "]"; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/SelectionWidget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/SelectionWidget.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,39 @@ +package at.ssw.visualizer.cfg.graph; + +import at.ssw.visualizer.cfg.preferences.CfgPreferences; +import java.awt.AlphaComposite; +import java.awt.Composite; +import java.awt.Graphics2D; +import java.awt.Rectangle; +import org.netbeans.api.visual.widget.Scene; +import org.netbeans.api.visual.widget.Widget; + + +public class SelectionWidget extends Widget { + public SelectionWidget(Scene scene) { + super(scene); + } + + public static void renderSelectedRect(Graphics2D gr, Rectangle rect) { + if (rect == null) { + return; + } + gr.setColor(CfgPreferences.getInstance().getSelectionColorBackground()); + gr.fillRect(rect.x, rect.y, rect.width, rect.height); + gr.setColor(CfgPreferences.getInstance().getSelectionColorForeground()); + } + + public void renderSelectionRectangle(Graphics2D gr, Rectangle selectionRectangle) { + Composite composite = gr.getComposite(); + gr.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.5f)); + + renderSelectedRect(gr, selectionRectangle); + gr.setComposite(composite); + } + + @Override + public void paintWidget(){ + this.renderSelectionRectangle(this.getGraphics(), this.getBounds()); + } + +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/SymmetricAnchor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/SymmetricAnchor.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,157 @@ +package at.ssw.visualizer.cfg.graph; + +import org.netbeans.api.visual.widget.Widget; +import org.netbeans.api.visual.anchor.Anchor; +import java.awt.*; + + +/** + * This Anchor can be used with symmetric edges to create parallel Edges. + * Two Directed Edges are symmetric if they are connecting the same Nodes in different directions. + * e.g. Nodes (1, 2) Edges(a , b) with (1)-a->(2) , (2)-b->(1) + * Start-/End positions are calculated with a fixed offset to prevent edges from overlapping. + * If the edges are drawn as straight lines they will appear as parallel edges. + */ + +public final class SymmetricAnchor extends Anchor { + + private final static int OFFSET = 10; + private boolean includeBorders; + private int offx; + private int offy; + + public SymmetricAnchor (Widget widget, boolean includeBorders, boolean source) { + super (widget); + this.includeBorders = includeBorders; + if (source) { + offx = OFFSET; + offy = OFFSET; + } + else { + offx = -OFFSET; + offy = -OFFSET; + } + } + + public Result compute (Entry entry) { + Point relatedLocation = //center of the widget + getRelatedSceneLocation (); + Point oppositeLocation = //center of the widget + getOppositeSceneLocation (entry); + + Widget widget = getRelatedWidget (); + Rectangle bounds = widget.getBounds (); + if (! includeBorders) { + Insets insets = widget.getBorder ().getInsets (); + bounds.x += insets.left; + bounds.y += insets.top; + bounds.width -= insets.left + insets.right; + bounds.height -= insets.top + insets.bottom; + } + + bounds = widget.convertLocalToScene (bounds); + + if (bounds.isEmpty () || relatedLocation.equals (oppositeLocation)) + return new Anchor.Result (relatedLocation, Anchor.DIRECTION_ANY); + + float dx //distance x-axis + = oppositeLocation.x - relatedLocation.x; + float dy //distance y-axis + = oppositeLocation.y - relatedLocation.y; + + + float ddx + = Math.abs (dx) / (float) bounds.width; + float ddy = + Math.abs (dy) / (float) bounds.height; + + Anchor.Direction direction; + + + if (ddx >= ddy) { + if(dx >= 0.0f){ + direction = Direction.RIGHT; + relatedLocation.y -= offy; + } else { + direction = Direction.LEFT; + relatedLocation.y += offy; + } + } else { + if(dy >= 0.0f){ + direction = Direction.BOTTOM; + relatedLocation.x += offx; + } else { + direction = Direction.TOP; + relatedLocation.x -= offx; + } + } + + + float scale = 0.5f / Math.max (ddx, ddy); + + float ex = scale * dx; + float ey = scale * dy; + + Point point = new Point (Math.round (relatedLocation.x + ex), Math.round (relatedLocation.y + ey)); + + if(direction == Direction.RIGHT) { + int top = bounds.y;//-bounds.height;// left y of the widget + int bottom = bounds.y + bounds.height;// right y of the widget + if(point.y < top) {//above the widget + int cor = top-point.y; + point.x -= cor; + point.y += cor; + } else if ( point.y > bottom) { + int cor = point.y-bottom; + point.x -= cor; + point.y -= cor; + } + + } else if (direction == Direction.LEFT) { + int top = bounds.y;//-bounds.height;// left y of the widget + int bottom = bounds.y + bounds.height;// right y of the widget + + + + if(point.y < top) {//above the widget + int cor = top-point.y; + point.x += cor; + point.y += cor; + } else if ( point.y > bottom) { + int cor = bottom-point.y; + point.x -= cor; + point.y += cor; + } + + + } else if (direction == Direction.BOTTOM) { + int left = bounds.x;//-bounds.height;// left y of the widget + int right = bounds.x + bounds.width;// right y of the widget + if(point.x < left) {//above the widget + int cor = left-point.x; + point.x += cor; + point.y -= cor; + } else if ( point.x > right) { + int cor = point.x- right; + point.x -= cor; + point.y -= cor; + } + + } else if (direction == Direction.TOP) { + int left = bounds.x;//-bounds.height;// left y of the widget + int right = bounds.x + bounds.width;// right y of the widget + if(point.x < left) {//above the widget + int cor = left-point.x; + point.x += cor; + point.y += cor; + } else if ( point.x > right) { + int cor = point.x - right; + point.x -= cor; + point.y += cor; + } + + } + + return new Anchor.Result (point, direction); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/layout/HierarchicalCompoundLayout.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/layout/HierarchicalCompoundLayout.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,102 @@ +package at.ssw.visualizer.cfg.graph.layout; + +import at.ssw.visualizer.cfg.graph.CfgScene; +import at.ssw.visualizer.cfg.model.CfgEdge; +import at.ssw.visualizer.cfg.model.CfgNode; +import at.ssw.visualizer.cfg.model.LoopInfo; +import java.awt.Point; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import org.eclipse.draw2d.geometry.Insets; +import org.netbeans.api.visual.graph.layout.GraphLayout; +import org.netbeans.api.visual.graph.layout.UniversalGraph; +import org.eclipse.draw2d.graph.CompoundDirectedGraph; +import org.eclipse.draw2d.graph.CompoundDirectedGraphLayout; +import org.eclipse.draw2d.graph.Edge; +import org.eclipse.draw2d.graph.EdgeList; +import org.eclipse.draw2d.graph.Node; +import org.eclipse.draw2d.graph.NodeList; +import org.eclipse.draw2d.graph.Subgraph; +import org.netbeans.api.visual.widget.Widget; + +public class HierarchicalCompoundLayout extends GraphLayout { + + private static final int TOP_BORDER = 20; + private static final int LEFT_BORDER = 20; + private int PADDING = 20; + private static final int INSET = 20; + private CfgScene scene; + + public HierarchicalCompoundLayout(CfgScene scene){ + this.scene = scene; + } + + @Override + protected void performGraphLayout(UniversalGraph ug) { + CompoundDirectedGraph dg = new CompoundDirectedGraph(); + CompoundDirectedGraphLayout layout = new CompoundDirectedGraphLayout(); + NodeList nodeList = dg.nodes; + EdgeList edgeList = dg.edges; + + Map idx2graph = new HashMap<>(); + Subgraph base = new Subgraph(0); + idx2graph.put(0, base); + base.insets=getInsets(); + for(LoopInfo info : scene.getCfgEnv().getLoopMap().values()){ + Subgraph subg = new Subgraph(info.getLoopIndex()); + subg.insets=getInsets(); + idx2graph.put(info.getLoopIndex(), subg); + } + + for(CfgNode n : scene.getCfgEnv().getNodes() ) { + Widget nodeWidget = scene.findWidget(n); + Node node = new Node(n); + node.width=nodeWidget.getBounds().width; + node.height = nodeWidget.getBounds().height; + node.setPadding(new Insets(PADDING, PADDING, PADDING, PADDING)); + Subgraph subg = idx2graph.get(n.getLoopIndex()); + assert(subg != null); + node.setParent(subg); + subg.addMember(node); + nodeList.add(node); + + } + nodeList.addAll(idx2graph.values()); + for(LoopInfo info : scene.getCfgEnv().getLoopMap().values()){ + Subgraph subg = idx2graph.get(info.getLoopIndex()); + if(info.getParent() != null){ + Subgraph parentsubg = idx2graph.get(info.getParent().getLoopIndex()); + Edge edge = new Edge(parentsubg, subg); + parentsubg.addMember(subg); + subg.setParent(parentsubg); + edgeList.add(edge); + } + } + for(CfgEdge e : scene.getCfgEnv().getEdges() ) { + if(e.isBackEdge()) continue; + Edge edge = new Edge(e, nodeList.getNode(e.getSourceNode().getNodeIndex()), nodeList.getNode(e.getTargetNode().getNodeIndex())); + edgeList.add(edge); + } + layout.visit(dg); + + for(Object obj : dg.nodes){ + Node n = (Node) obj; + if(n.data instanceof CfgNode){ + CfgNode cfgNode = (CfgNode) n.data; + Point pos = new Point(n.x + LEFT_BORDER, n.y + TOP_BORDER); + Point scenepos = scene.convertLocalToScene(pos); + this.setResolvedNodeLocation(ug, cfgNode, scenepos); + } + } + } + + @Override + protected void performNodesLayout(UniversalGraph ug, Collection collection) { + } + + private Insets getInsets(){ + return new Insets(INSET, INSET, INSET, INSET); + } + +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/layout/HierarchicalNodeLayout.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/graph/layout/HierarchicalNodeLayout.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,69 @@ +package at.ssw.visualizer.cfg.graph.layout; + +import at.ssw.visualizer.cfg.graph.CfgScene; +import at.ssw.visualizer.cfg.model.CfgEdge; +import at.ssw.visualizer.cfg.model.CfgNode; +import java.awt.Point; +import java.util.Collection; +import org.netbeans.api.visual.graph.layout.GraphLayout; +import org.netbeans.api.visual.graph.layout.UniversalGraph; +import org.eclipse.draw2d.graph.DirectedGraph; +import org.eclipse.draw2d.graph.DirectedGraphLayout; +import org.eclipse.draw2d.graph.Edge; +import org.eclipse.draw2d.graph.EdgeList; +import org.eclipse.draw2d.graph.Node; +import org.eclipse.draw2d.graph.NodeList; +import org.netbeans.api.visual.widget.Widget; + + +public class HierarchicalNodeLayout extends GraphLayout { + + private static final int TOP_BORDER = 20; + private static final int LEFT_BORDER = 40; + + private CfgScene scene; + + public HierarchicalNodeLayout(CfgScene scene){ + this.scene = scene; + } + + @Override + protected void performGraphLayout(UniversalGraph ug) { + DirectedGraph dg = new DirectedGraph(); + DirectedGraphLayout layout = new DirectedGraphLayout(); + + NodeList nodeList = dg.nodes; + EdgeList edgeList = dg.edges; + + for(CfgNode n : scene.getCfgEnv().getNodes() ) { + Widget nodeWidget = scene.findWidget(n); + Node node = new Node(n); + node.width=nodeWidget.getBounds().width; + node.height = nodeWidget.getBounds().height; + nodeList.add(node); + } + + for(CfgEdge e : scene.getCfgEnv().getEdges() ) { + if(e.isBackEdge()) continue; + Edge edge = new Edge(e, nodeList.getNode(e.getSourceNode().getNodeIndex()), + nodeList.getNode(e.getTargetNode().getNodeIndex())); + edgeList.add(edge); + } + + layout.visit(dg); + + for(Object obj : dg.nodes){ + Node n = (Node) obj; + CfgNode cfgNode = (CfgNode) n.data; + Point pos = new Point(n.x + LEFT_BORDER , n.y + TOP_BORDER); + Point scenepos = scene.convertLocalToScene(pos); + setResolvedNodeLocation(ug, cfgNode, scenepos); + } + + } + + @Override + protected void performNodesLayout(UniversalGraph ug, Collection collection) { + } + +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/Icons.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/Icons.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,18 @@ +package at.ssw.visualizer.cfg.icons; + +/** + * + * @author Christian Wimmer + */ +public class Icons { + private static final String PATH = "at/ssw/visualizer/cfg/icons/"; + + public static final String CFG = PATH + "cfg.gif"; + + public static final String ICON_ZOOMIN = PATH + "zoomin.gif"; + public static final String ICON_ZOOMOUT = PATH + "zoomout.gif"; + public static final String ICON_DEFAULT = PATH + "arrangebfs.gif"; + + private Icons() { + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/arrangebfs.gif Binary file visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/arrangebfs.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/arrangehier.gif Binary file visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/arrangehier.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/arrangeloop.gif Binary file visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/arrangeloop.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/autosize_selection.gif Binary file visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/autosize_selection.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/bezierrouter.gif Binary file visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/bezierrouter.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/cfg.gif Binary file visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/cfg.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/cfg32.gif Binary file visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/cfg32.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/cluster.gif Binary file visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/cluster.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/color.gif Binary file visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/color.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/combine.gif Binary file visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/combine.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/combine_disabled.gif Binary file visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/combine_disabled.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/disk.gif Binary file visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/disk.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/fanrouter.gif Binary file visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/fanrouter.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/hideedges.gif Binary file visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/hideedges.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/hideedges_disabled.gif Binary file visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/hideedges_disabled.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/manhattanrouter.gif Binary file visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/manhattanrouter.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/showedges.gif Binary file visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/showedges.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/showedges_disabled.gif Binary file visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/showedges_disabled.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/split.gif Binary file visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/split.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/split_disabled.gif Binary file visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/icons/split_disabled.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/layer.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/layer.xml Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/CfgEdge.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/CfgEdge.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,10 @@ +package at.ssw.visualizer.cfg.model; + +public interface CfgEdge { + public CfgNode getSourceNode(); + public CfgNode getTargetNode(); + public boolean isXhandler(); + public boolean isBackEdge(); + public boolean isSymmetric(); + public boolean isReflexive(); +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/CfgEdgeImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/CfgEdgeImpl.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,50 @@ +package at.ssw.visualizer.cfg.model; + +public class CfgEdgeImpl implements CfgEdge { + private CfgNodeImpl sourceNode; + private CfgNodeImpl targetNode; + private boolean symmetric; + private boolean backedge; + + public CfgEdgeImpl(CfgNodeImpl sourceNode, CfgNodeImpl targetNode) { + this.sourceNode = sourceNode; + this.targetNode = targetNode; + } + + public void setSymmetric(boolean symmetric){ + this.symmetric = symmetric; + } + + public void setBackEdge(boolean isBackedge){ + this.backedge = isBackedge; + } + + public CfgNode getSourceNode() { + return sourceNode; + } + + public CfgNode getTargetNode() { + return targetNode; + } + + public boolean isBackEdge() { + return this.backedge; + } + + public boolean isSymmetric() { + return symmetric; + } + + public boolean isReflexive() { + return sourceNode==targetNode; + } + + public boolean isXhandler() { + return sourceNode.getBasicBlock().getXhandlers().contains(targetNode.getBasicBlock()); + } + + @Override + public String toString(){ + return this.sourceNode.getBasicBlock().getName() + "->" + targetNode.getBasicBlock().getName(); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/CfgEnv.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/CfgEnv.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,297 @@ +package at.ssw.visualizer.cfg.model; + +import at.ssw.visualizer.model.cfg.BasicBlock; +import at.ssw.visualizer.model.cfg.ControlFlowGraph; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Queue; +import java.util.Set; + + +/** + * This is the container class for the data model, + * it prepares creates nodes and edges for the CfgScene + * from a ControlFlowGraph of the Compilation Model + */ +public class CfgEnv { + private ControlFlowGraph cfg; + private Map loopMap;//maps: LoopHeader --> LoopInfo + private CfgNodeImpl[] nodeArr; + private CfgEdgeImpl[] edgeArr; + + public CfgEnv(ControlFlowGraph cfg) { + this.cfg = cfg; + int blockCount = cfg.getBasicBlocks().size(); + CfgNodeImpl[] nodes = new CfgNodeImpl[blockCount]; + Map block2nodeMap = new HashMap<>(); + Map> inputMap = new HashMap<>(); + ArrayList allEdges = new ArrayList<>(); + List blocks = cfg.getBasicBlocks(); + //create nodes + for(int idx=0 ; idx < blockCount ; idx++) { + BasicBlock b = blocks.get(idx); + + String description = "Name: " + b.getName() + "\n"; + description += "BCI: [" + b.getFromBci() + "," + b.getToBci() + "]\n"; + if (b.getLoopDepth() > 0) { + description += "Loop " + b.getLoopIndex() + " Depth " + b.getLoopDepth() + "\n"; + } + description += "Predecessors: " + getBlockList(b.getPredecessors()) + "\n"; + description += "Successors: " + getBlockList(b.getSuccessors()) + "\n"; + description += "XHandlers: " + getBlockList(b.getXhandlers()); + if (b.getDominator() != null) { + description += "\nDominator: " + b.getDominator().getName(); + } + nodes[idx] = new CfgNodeImpl(b, idx, description); + block2nodeMap.put(b, nodes[idx]); + } + + + //create edges + Set cache = new HashSet<>();//avoids identical edges with same source and same target + for(int i = 0 ; i < blockCount ; i++) { + BasicBlock b = blocks.get(i); + List outputEdges = new ArrayList<>(); + + Set successors = new HashSet<>(); + successors.addAll(b.getSuccessors()); + successors.addAll(b.getXhandlers()); + for(BasicBlock sb : successors) { + CfgNodeImpl succNode = block2nodeMap.get(sb); + CfgEdgeImpl edge = new CfgEdgeImpl(nodes[i], succNode); + if(cache.contains(edge.toString())) + continue; + cache.add(edge.toString()); + //check for symtric edges + if(sb.getXhandlers().contains(b) || sb.getSuccessors().contains(b)) + edge.setSymmetric(true); + outputEdges.add(edge); + } + allEdges.addAll(outputEdges); + nodes[i].setOutputEdges(outputEdges.toArray(new CfgEdgeImpl[outputEdges.size()])); + } + + for(CfgEdgeImpl e: allEdges) { + //CfgNodeImpl src = (CfgNodeImpl) e.getSourceNode(); + CfgNodeImpl tar = (CfgNodeImpl) e.getTargetNode(); + Set set = inputMap.get(tar); + if( set == null) { + set = new HashSet<>(); + set.add(e); + inputMap.put(tar, set); + } + set.add(e); + } + for(CfgNodeImpl n : nodes){ + Set inputEdges = inputMap.get(n); + if(inputEdges == null) continue; + n.setInputEdges(inputEdges.toArray(new CfgEdgeImpl[inputEdges.size()])); + } + CfgEdgeImpl[] edges = allEdges.toArray(new CfgEdgeImpl[allEdges.size()]); + this.edgeArr=edges; + this.nodeArr=nodes; + CfgNodeImpl rootNode = nodeArr[0]; + setNodeLevels(rootNode); + indexLoops(rootNode); + + } + + + private String getBlockList(List blocks) { + if (blocks.size() == 0) { + return "None"; + } + StringBuilder sb = new StringBuilder(); + String prefix = ""; + for (BasicBlock b : blocks) { + sb.append(prefix).append(b.getName()); + prefix = ", "; + } + return sb.toString(); + } + + + public CfgNode[] getNodes(){ + return this.nodeArr; + } + + public CfgEdge[] getEdges(){ + return this.edgeArr; + } + + public Map getLoopMap() { + return loopMap; + } + + public void setLoopMap(Map loopMap) { + this.loopMap = loopMap; + } + + private void indexLoops(CfgNodeImpl rootNode){ + LoopEnv env = new LoopEnv(Arrays.asList(nodeArr)); + loopDetection(env, rootNode); + calcLoopDepth(env); + + int loopIndex=1; + + for(LoopInfo info : env.loopMap.values()) { + info.setLoopIndex(loopIndex++); + info.setLoopDepth(info.getHeader().getLoopDepth()); + for(CfgNode n : info.getMembers()){ + if(n.getLoopDepth()>info.getLoopDepth()) continue; + CfgNodeImpl ni = (CfgNodeImpl) n; + ni.setLoopDepth(info.getLoopDepth()); + ni.setLoopIndex(info.getLoopIndex()); + } + } + + for(LoopInfo info : env.loopMap.values()) { + HashSet members = new HashSet<>(info.getMembers()); + members.remove(info.getHeader());//remove own header + for(CfgNode n: members){ + if(n.isLoopHeader()) { + LoopInfo memberInfo = env.loopMap.get(n); + if (info.getLoopDepth() == memberInfo.getLoopDepth()-1) + memberInfo.setParent(info); + } + } + } + this.loopMap = env.loopMap; + } + + + private class LoopEnv { + Set allNodes; + Set activeNodes; + Set visitedNodes; + Map loopMap; + private int loopIndex=0; + + public LoopEnv(Collection nodes){ + allNodes = new HashSet<>(nodes); + activeNodes = new HashSet<>(2 * allNodes.size()); + visitedNodes = new HashSet<>(2 * allNodes.size()); + loopMap = new HashMap<>(); + } + + public int getLoopIndex(){ + return ++loopIndex; + } + } + + + private void loopDetection(LoopEnv env, CfgNodeImpl root) { + for (CfgNodeImpl n : env.allNodes) { + n.setLoopHeader(false); + for (CfgEdge e : n.getInputEdges()) { + CfgEdgeImpl ei = (CfgEdgeImpl) e; + ei.setBackEdge(false); + } + } + visit(env, root, null); + } + + + + private void visit(LoopEnv env, CfgNodeImpl n, CfgEdgeImpl e) { + if (env.activeNodes.contains(n)) { + // This node is b loop header! + n.setLoopHeader(true); + e.setBackEdge(true); + } else if (!env.visitedNodes.contains(n)) { + env.visitedNodes.add(n); + env.activeNodes.add(n); + + for (CfgEdge edge : n.getOutputEdges()) { + if(!edge.getTargetNode().isOSR()) { + CfgEdgeImpl ei = (CfgEdgeImpl) edge; + CfgNodeImpl ni = (CfgNodeImpl) edge.getTargetNode(); + visit(env, ni, ei); + } + } + env.activeNodes.remove(n); + } + } + + + + private void calcLoopDepth(LoopEnv env) { + for (CfgNodeImpl n : env.allNodes) { + env.visitedNodes.clear(); + + if (n.isLoopHeader()) { + LoopInfo loop = new LoopInfo(); + loop.setHeader(n); + n.setLoopIndex(env.getLoopIndex()); + HashSet members = new HashSet<>(); + loop.setMembers(members); + members.add(n); + env.loopMap.put(loop.getHeader(), loop); + int loopDepth = n.getLoopDepth() + 1; + loop.setLoopDepth(loopDepth); + n.setLoopDepth(loopDepth); + for (CfgEdge e : n.getInputEdges()) { + if (e.isBackEdge() && !e.getSourceNode().isOSR()) { + CfgNodeImpl src = (CfgNodeImpl) e.getSourceNode(); + backwardIteration(env, n, src, loop); + loop.getBackEdges().add(e); + } + } + } + } + } + + + private void backwardIteration(LoopEnv env, CfgNodeImpl endNode, CfgNodeImpl n, LoopInfo loop) { + if (endNode != n && !env.visitedNodes.contains(n)) { + env.visitedNodes.add(n); + + for (CfgEdge e : n.getInputEdges()) { + if (!e.getSourceNode().isOSR()) { + CfgNodeImpl src = (CfgNodeImpl) e.getSourceNode(); + backwardIteration(env, endNode, src, loop); + } + } + loop.getMembers().add(n); + n.setLoopDepth(n.getLoopDepth() + 1); + } + } + + private void setNodeLevels(CfgNode rootNode){ + Set cache = new HashSet<>(); + Queue queue = new LinkedList<>(); + queue.add(rootNode); + cache.add(rootNode); + int level=0; + int[] nodeCount = new int[2]; + nodeCount[0]=1; + while(!queue.isEmpty()){ + CfgNodeImpl curNode = (CfgNodeImpl) queue.poll(); + curNode.setLevel(level); + nodeCount[0]--; + for(CfgEdge outEdge : curNode.getOutputEdges()) { + CfgNode succNode = outEdge.getTargetNode(); + if(cache.contains(succNode)) continue; + cache.add(succNode); + queue.add(succNode); + nodeCount[1]++; + } + if(nodeCount[0]==0){ + nodeCount[0]=nodeCount[1]; + nodeCount[1]=0; + level++; + } + } + } + + public ControlFlowGraph getCfg() { + return cfg; + } + +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/CfgNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/CfgNode.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,23 @@ +package at.ssw.visualizer.cfg.model; + +import at.ssw.visualizer.model.cfg.BasicBlock; + + +public interface CfgNode { + //testers + public boolean isOSR(); + public boolean isRoot(); + public boolean isLoopHeader(); + public boolean isLoopMember(); + + //getters + public int getLevel(); + public int getLoopDepth(); + public int getLoopIndex(); + public int getNodeIndex(); + public CfgEdge[] getInputEdges(); + public CfgEdge[] getOutputEdges(); + public BasicBlock getBasicBlock(); + public String getDescription(); + +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/CfgNodeImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/CfgNodeImpl.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,133 @@ +package at.ssw.visualizer.cfg.model; + +import at.ssw.visualizer.model.cfg.BasicBlock; +import java.awt.Color; + + + +public class CfgNodeImpl implements CfgNode { + private int nodeIndex; + private BasicBlock basicBlock; + private int level; + private int loopDepth=0; + private int loopIndex=0; + private boolean osr=false; + private CfgNodeImpl dominator=null; + private CfgEdgeImpl[] inputEdges = new CfgEdgeImpl[0]; + private CfgEdgeImpl[] outputEdges = new CfgEdgeImpl[0]; + private String description; + private Color customColor=null; + private boolean loopHeader; + + public CfgNodeImpl(BasicBlock bb, int nodeIndex, String description) { + this.basicBlock = bb; + this.nodeIndex = nodeIndex; + this.description = description; + + if (bb.getPredecessors().size() == 1) { + BasicBlock pred = bb.getPredecessors().get(0); + boolean isStd = pred.getPredecessors().size() == 0; + if (isStd) { + for (String s : bb.getFlags()) { + if (s.equals("osr")) { + osr = true; + break; + } + } + } + } + } + + public int getNodeIndex() { + return nodeIndex; + } + + + public void setDominator(CfgNodeImpl dominator) { + this.dominator = dominator; + } + + public void setLevel(int level) { + this.level = level; + } + + public void setLoopDepth(int loopDepth) { + this.loopDepth = loopDepth; + } + + public void setLoopHeader(boolean loopHeader) { + this.loopHeader = loopHeader; + } + + public void setLoopIndex(int loopIndex) { + this.loopIndex = loopIndex; + } + + public void setNodeIndex(int nodeIndex) { + this.nodeIndex = nodeIndex; + } + + public boolean isRoot() { + return nodeIndex==0; + } + + public boolean isLoopHeader() { + return loopHeader; + } + + public boolean isLoopMember() { + return loopIndex > 0; + } + + public int getLevel() { + return level; + } + + public BasicBlock getBasicBlock() { + return basicBlock; + } + + public int getLoopDepth() { + return loopDepth; + } + + public int getLoopIndex() { + return loopIndex; + } + + public boolean isOSR() { + return osr; + } + + @Override + public String toString(){ + return basicBlock.getName(); + } + + public void setInputEdges(CfgEdgeImpl[] inputEdges){ + this.inputEdges = inputEdges; + } + + + public void setOutputEdges(CfgEdgeImpl[] outputEdges){ + this.outputEdges = outputEdges; + } + + public CfgEdge[] getInputEdges() { + return this.inputEdges; + } + + public CfgEdge[] getOutputEdges() { + return outputEdges; + } + + public String getDescription() { + return description; + } + + public void setColor(Color color) { + this.customColor=color; + } + + +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/LoopInfo.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/model/LoopInfo.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,67 @@ +package at.ssw.visualizer.cfg.model; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + + +public class LoopInfo { + private CfgNode header;//the target node of the backedge + private int loopIndex; //index of the min cycleSet + private int loopDepth; //nested depth >=1 + private LoopInfo parent=null; + private Set members; + private List backEdges = new ArrayList<>();//dfs backEdge + + protected void setLoopDepth(int depth) { + this.loopDepth=depth; + } + + protected void setLoopIndex(int loopIndex) { + this.loopIndex = loopIndex; + } + + public int getLoopDepth() { + return loopDepth; + } + + public Set getMembers() { + return members; + } + + protected void setMembers(Set members) { + this.members = members; + } + + public int getLoopIndex() { + return loopIndex; + } + + protected void setParent(LoopInfo parent) { + this.parent = parent; + } + + public LoopInfo getParent(){ + return parent; + } + + public List getBackEdges() { + return backEdges; + } + + public CfgNode getHeader() { + return header; + } + + protected void setHeader(CfgNode header) { + this.header = header; + } + + @Override + public String toString(){ + return "Loop(" + header.toString()+ ")-->" + members.toString(); + } + + + +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/CFGOptionsCategory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/CFGOptionsCategory.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,32 @@ +package at.ssw.visualizer.cfg.preferences; + +import javax.swing.Icon; +import javax.swing.ImageIcon; +import org.netbeans.spi.options.OptionsCategory; +import org.netbeans.spi.options.OptionsPanelController; +import org.openide.util.ImageUtilities; + +/** + * Descriptor for the settings page displayed in the options dialog. + * + * @author Bernhard Stiftner + */ +public class CFGOptionsCategory extends OptionsCategory { + + public OptionsPanelController create() { + return new CFGOptionsPanelController(); + } + + public String getCategoryName() { + return "Control Flow Graph"; + } + + @Override + public Icon getIcon() { + return new ImageIcon(ImageUtilities.loadImage("at/ssw/visualizer/cfg/icons/cfg32.gif")); + } + + public String getTitle() { + return "CFG Visualizer"; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/CFGOptionsPanel.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/CFGOptionsPanel.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,482 @@ +package at.ssw.visualizer.cfg.preferences; + +import java.awt.Color; +import java.awt.Font; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.List; +import javax.swing.AbstractAction; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.SwingConstants; + +/** + * The actual component for changing the CFG visualizer settings. + * + * @author Bernhard Stiftner + * @author Rumpfhuber Stefan + */ +public class CFGOptionsPanel extends JPanel { + + List elements = new ArrayList<>(); + + /** Creates a new instance of CFGOptionsPanel */ + public CFGOptionsPanel() { + setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + JPanel cfgPanel = new JPanel(new GridBagLayout()); + + // color/font settings + addColorChooser(cfgPanel, "Background color: ", new ColorChooser(CfgPreferences.PROP_BACKGROUND_COLOR){ + @Override + public void apply() { + CfgPreferences.getInstance().setBackgroundColor(getColor()); + } + + @Override + public void update() { + this.originalColor = CfgPreferences.getInstance().getBackgroundColor(); + setColor(this.originalColor); + } + + public void reset() { + this.setColor(CfgPreferencesDefaults.DEFAULT_BACKGROUND_COLOR); + } + + + + }); + addColorChooser(cfgPanel, "Back edge color: ", new ColorChooser(CfgPreferences.PROP_BACK_EDGE_COLOR){ + + @Override + public void apply() { + CfgPreferences.getInstance().setBackedgeColor(getColor()); + } + + @Override + public void update() { + this.originalColor = CfgPreferences.getInstance().getBackedgeColor(); + this.setColor(this.originalColor); + + } + + public void reset() { + this.setColor(CfgPreferencesDefaults.DEFAULT_BACKEDGE_COLOR); + } + }); + addColorChooser(cfgPanel, "Edge color: ", new ColorChooser(CfgPreferences.PROP_EDGE_COLOR){ + + @Override + public void apply() { + CfgPreferences.getInstance().setEdgeColor(getColor()); + } + + @Override + public void update() { + this.originalColor = CfgPreferences.getInstance().getEdgeColor(); + setColor(this.originalColor); + } + + public void reset() { + this.setColor(CfgPreferencesDefaults.DEFAULT_EDGE_COLOR); + } + + }); + addColorChooser(cfgPanel, "Exception edge color: ", new ColorChooser(CfgPreferences.PROP_EXCEPTION_EDGE_COLOR){ + + @Override + public void apply() { + CfgPreferences.getInstance().setExceptionEdgeColor(getColor()); + } + + @Override + public void update() { + this.originalColor = CfgPreferences.getInstance().getExceptionEdgeColor(); + setColor(this.originalColor); + + } + + public void reset() { + this.setColor(CfgPreferencesDefaults.DEFAULT_EXCEPTIONEDGE_COLOR); + } + }); + addColorChooser(cfgPanel, "Node color: ", new ColorChooser(CfgPreferences.PROP_NODE_COLOR){ + + @Override + public void apply() { + CfgPreferences.getInstance().setNodeColor(getColor()); + } + + @Override + public void update() { + this.originalColor = CfgPreferences.getInstance().getNodeColor(); + setColor(this.originalColor); + + } + + public void reset() { + this.setColor(CfgPreferencesDefaults.DEFAUT_NODE_COLOR); + } + }); + addColorChooser(cfgPanel, "Text color: ", new ColorChooser(CfgPreferences.PROP_TEXT_COLOR){ + + @Override + public void apply() { + CfgPreferences.getInstance().setTextColor(getColor()); + } + + @Override + public void update() { + this.originalColor = CfgPreferences.getInstance().getTextColor(); + + } + + public void reset() { + this.setColor(CfgPreferencesDefaults.DEFAULT_TEXT_COLOR); + } + }); + addColorChooser(cfgPanel, "Border color: ", new ColorChooser(CfgPreferences.PROP_BORDER_COLOR){ + + @Override + public void apply() { + CfgPreferences.getInstance().setBorderColor(getColor()); + } + + @Override + public void update() { + this.originalColor = CfgPreferences.getInstance().getBorderColor(); + setColor(this.originalColor); + + } + public void reset() { + this.setColor(CfgPreferencesDefaults.DEFAULT_BORDER_COLOR); + } + }); + addColorChooser(cfgPanel, "Selected Nodes color: ", new ColorChooser(CfgPreferences.PROP_SELECTION_COLOR_FG){ + + @Override + public void apply() { + CfgPreferences.getInstance().setSelectionColorForeground(getColor()); + } + + @Override + public void update() { + this.originalColor = CfgPreferences.getInstance().getSelectionColorForeground(); + setColor(this.originalColor); + } + + public void reset() { + this.setColor(CfgPreferencesDefaults.DEFAULT_SELECTION_COLOR_FOREGROUND); + } + }); + addColorChooser(cfgPanel, "Selection Rect color: ", new ColorChooser(CfgPreferences.PROP_SELECTION_COLOR_BG){ + + @Override + public void apply() { + CfgPreferences.getInstance().setSelectionColorBackground(getColor()); + } + + @Override + public void update() { + this.originalColor = CfgPreferences.getInstance().getSelectionColorBackground(); + setColor(this.originalColor); + } + + public void reset() { + this.setColor(CfgPreferencesDefaults.DEFAULT_SELECTION_COLOR_BACKGROUND); + } + }); + addFontChooser(cfgPanel, "Text font: ", new FontChooser(CfgPreferences.PROP_TEXT_FONT){ + + @Override + public void apply() { + CfgPreferences.getInstance().setTextFont(getSelectedFont()); + } + + @Override + public void update() { + this.originalFont = CfgPreferences.getInstance().getTextFont(); + this.setSelectedFont(originalFont); + + } + + public void reset() { + this.setSelectedFont(CfgPreferencesDefaults.DEFAULT_TEXT_FONT); + } + }); + + // flags editor + addFlagsEditor(cfgPanel, "Flags: "); + add(cfgPanel); + + // add update button + Box hBox = new Box(BoxLayout.X_AXIS); + hBox.add(new JButton(new ResetAction())); + hBox.add(Box.createHorizontalGlue()); + add(hBox); + + add(Box.createVerticalGlue()); + } + + public void update() { + for (ConfigurationElement e : elements) { + e.update(); + } + } + + public void cancel() { + for (ConfigurationElement e : elements) { + e.update(); + } + } + + public void applyChanges() { + for (ConfigurationElement e : elements) { + if(e.isChanged()) + e.apply(); + } + } + + public boolean isDataValid() { + return true; + } + + public boolean isChanged() { + for (ConfigurationElement e : elements) { + if (e.isChanged()) { + return true; + } + } + return false; + } + + public void loadDefault() { + for (ConfigurationElement e : elements) { + e.reset(); + } + } + + private void addColorChooser(JComponent c, String displayName, ColorChooser chooser) { + GridBagLayout layout = (GridBagLayout)c.getLayout(); + GridBagConstraints constraints = new GridBagConstraints(); + constraints.insets = new Insets(3, 3, 3, 3); + constraints.weightx = 0.0; + constraints.fill = GridBagConstraints.NONE; + constraints.anchor = GridBagConstraints.EAST; + JLabel label = new JLabel(displayName, JLabel.TRAILING); + layout.setConstraints(label, constraints); + c.add(label); + constraints.anchor = GridBagConstraints.WEST; + constraints.gridwidth = GridBagConstraints.REMAINDER; + layout.setConstraints(chooser, constraints); + c.add(chooser); + elements.add(chooser); + label.setLabelFor(chooser); + } + + + + private void addFontChooser(JComponent c, String displayName, FontChooser chooser) { + GridBagLayout layout = (GridBagLayout)c.getLayout(); + GridBagConstraints constraints = new GridBagConstraints(); + constraints.insets = new Insets(3, 3, 3, 3); + constraints.weightx = 0.0; + constraints.fill = GridBagConstraints.NONE; + constraints.anchor = GridBagConstraints.EAST; + JLabel label = new JLabel(displayName, JLabel.TRAILING); + layout.setConstraints(label, constraints); + c.add(label); + constraints.insets = new Insets(3, 3, 3, 1); + constraints.weightx = 1.0; + constraints.fill = GridBagConstraints.HORIZONTAL; + constraints.anchor = GridBagConstraints.CENTER; + layout.setConstraints(chooser.getPreview(), constraints); + c.add(chooser.getPreview()); + constraints.insets = new Insets(3, 1, 3, 3); + constraints.weightx = 0.0; + constraints.fill = GridBagConstraints.NONE; + constraints.anchor = GridBagConstraints.EAST; + constraints.gridwidth = GridBagConstraints.REMAINDER; + layout.setConstraints(chooser.getButton(), constraints); + c.add(chooser.getButton()); + elements.add(chooser); + label.setLabelFor(chooser.getButton()); + } + + private void addFlagsEditor(JComponent c, String displayName) { + GridBagLayout layout = (GridBagLayout)c.getLayout(); + GridBagConstraints constraints = new GridBagConstraints(); + constraints.insets = new Insets(3, 3, 3, 3); + constraints.weightx = 0.0; + constraints.fill = GridBagConstraints.NONE; + constraints.anchor = GridBagConstraints.NORTHEAST; + FlagsEditor flagsEditor = new FlagsEditor(); + JLabel flagsLabel = new JLabel(displayName, JLabel.TRAILING); + flagsLabel.setVerticalAlignment(SwingConstants.TOP); + layout.setConstraints(flagsLabel, constraints); + c.add(flagsLabel); + constraints.weightx = 1.0; + constraints.weighty = 1.0; + constraints.fill = GridBagConstraints.BOTH; + constraints.anchor = GridBagConstraints.CENTER; + constraints.gridwidth = GridBagConstraints.REMAINDER; + layout.setConstraints(flagsEditor, constraints); + c.add(flagsEditor); + elements.add(flagsEditor); + flagsLabel.setLabelFor(flagsEditor); + } + + + + + interface ConfigurationElement { + + public boolean isChanged(); + + //apply changes to preferences + public void apply(); + + //optain current value from preferences + public void update(); + + //reset to default value + public void reset(); + + } + + abstract class ColorChooser extends ColorChooserButton implements ConfigurationElement { + + Color originalColor;//the color before any change + String propertyName; + + public ColorChooser(String propertyName) { + this.propertyName = propertyName; + } + + public boolean isChanged() { + return !originalColor.equals(getColor()); + } + + + public abstract void apply(); + public abstract void update(); + + } + + + abstract class FontChooser implements ConfigurationElement, ActionListener { + + Font originalFont; + Font selectedFont; + String propertyName; + JTextField preview; + JButton button; + + public FontChooser(String propertyName) { + this.propertyName = propertyName; + preview = new JTextField(""); + preview.setEditable(false); + button = new JButton("..."); + button.setMargin(new Insets(0, 0, 0, 0)); + button.addActionListener(this); + } + + public boolean isChanged() { + return !originalFont.equals(selectedFont); + } + + public abstract void apply(); + + public abstract void update(); + + public abstract void reset(); + + public JTextField getPreview() { + return preview; + } + + public JButton getButton() { + return button; + }; + + public Font getSelectedFont() { + return selectedFont; + } + + public void setSelectedFont(Font f) { + selectedFont = f; + preview.setText(fontToString(f)); + preview.revalidate(); + } + + public void actionPerformed(ActionEvent e) { + setSelectedFont(FontChooserDialog.show(selectedFont)); + } + + public String fontToString(Font font) { + StringBuffer sb = new StringBuffer(); + sb.append(font.getName()); + sb.append(" "); + sb.append(font.getSize()); + if (font.isBold()) { + sb.append(" bold"); + } + if (font.isItalic()) { + sb.append(" italic"); + } + return sb.toString(); + } + + } + + class FlagsEditor extends FlagsEditorPanel implements ConfigurationElement { + + FlagsSetting originalFlags; + + public FlagsEditor() { + super(null); + } + + public boolean isChanged() { + return !originalFlags.getFlagString().equals(getFlagString()); + } + + public void apply() { + CfgPreferences.getInstance().setFlagsSetting(new FlagsSetting(getFlagString())); + update(); + } + + public void update() { + originalFlags = CfgPreferences.getInstance().getFlagsSetting(); + setFlagString(originalFlags.getFlagString()); + } + + public void reset() { + FlagsSetting defaultFlags = new FlagsSetting(CfgPreferencesDefaults.DEFAULT_FLAGSTRING); + setFlagString(defaultFlags.getFlagString()); + colorButton.setColor(getParent().getBackground()); + } + + } + + class ResetAction extends AbstractAction { + + public ResetAction() { + super("Reset"); + } + + public void actionPerformed(ActionEvent e) { + CFGOptionsPanel.this.loadDefault(); + } + + } + +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/CFGOptionsPanelController.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/CFGOptionsPanelController.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,63 @@ +package at.ssw.visualizer.cfg.preferences; + +import java.beans.PropertyChangeListener; +import javax.swing.JComponent; +import org.netbeans.spi.options.OptionsPanelController; +import org.openide.util.HelpCtx; +import org.openide.util.Lookup; + +/** + * Controller for the settings page displayed in the options dialog. + * + * @author Bernhard Stiftner + */ +public class CFGOptionsPanelController extends OptionsPanelController { + + CFGOptionsPanel optionsPanel; + + + public void update() { + getOptionsPanel().update(); + } + + public void applyChanges() { + getOptionsPanel().applyChanges(); + } + + public void cancel() { + getOptionsPanel().cancel(); + } + + public boolean isValid() { + return getOptionsPanel().isDataValid(); + } + + public boolean isChanged() { + return getOptionsPanel().isChanged(); + } + + public JComponent getComponent(Lookup masterLookup) { + return getOptionsPanel(); + } + + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + public void addPropertyChangeListener(PropertyChangeListener l) { + getOptionsPanel().addPropertyChangeListener(l); + } + + //todo: investigate - who removes the changelistener ? + public void removePropertyChangeListener(PropertyChangeListener l) { + getOptionsPanel().removePropertyChangeListener(l); + } + + private CFGOptionsPanel getOptionsPanel() { + if (optionsPanel == null) { + optionsPanel = new CFGOptionsPanel(); + } + return optionsPanel; + } + +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/CfgPreferences.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/CfgPreferences.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,239 @@ +package at.ssw.visualizer.cfg.preferences; + +import java.awt.Color; +import java.awt.Font; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.prefs.Preferences; +import javax.swing.event.EventListenerList; +import org.openide.util.NbPreferences; + +/** + * Replacement for old CFGSettings to remove dependency on deprecated SystemOption package + * + * @author Rumpfhuber Stefan + */ +public class CfgPreferences { + public static final String PROP_FLAGS = "flagsPreference"; + public static final String PROP_TEXT_FONT = "textFontPreference"; + public static final String PROP_TEXT_COLOR = "textColorPreference"; + public static final String PROP_NODE_COLOR = "nodeColorPreference"; + public static final String PROP_EDGE_COLOR = "edgeColorPreference"; + public static final String PROP_BORDER_COLOR = "borderColorPreference"; + public static final String PROP_BACK_EDGE_COLOR = "backEdgeColorPreference"; + public static final String PROP_BACKGROUND_COLOR = "backgroundColorPreference"; + public static final String PROP_SELECTION_COLOR_FG = "selectionColorFgPreference"; + public static final String PROP_SELECTION_COLOR_BG = "selectionColorBgPreference"; + public static final String PROP_EXCEPTION_EDGE_COLOR = "exceptionEdgeColorPreference"; + + private static final String PROP_FONTNAME = "_FontFamily"; + private static final String PROP_FONTSIZE = "_FontSize"; + private static final String PROP_FONTSTYLE = "_FontStyle"; + + protected static final String nodeName = "CfgPreferences"; + + private static CfgPreferences instance = new CfgPreferences(); + private EventListenerList listenerList; + + private FlagsSetting flagsSetting; + private Color node_color; + private Color background_color; + private Color backedge_color; + private Color edge_color; + private Color border_color; + private Color exceptionEdgeColor; + private Color text_color; + private Font text_font; + private Color selection_color_fg; + private Color selection_color_bg; + + + private CfgPreferences(){ + listenerList = new EventListenerList(); + init(); + } + + public static CfgPreferences getInstance(){ + return instance; + } + + protected final Preferences getPreferences() { + return NbPreferences.forModule(this.getClass()).node("options").node(nodeName); + } + + + protected void init(){ + Preferences prefs = this.getPreferences(); + String flagString = prefs.get(PROP_FLAGS, CfgPreferencesDefaults.DEFAULT_FLAGSTRING); + flagsSetting = new FlagsSetting(flagString); + node_color = this.getColorProperty(PROP_NODE_COLOR, CfgPreferencesDefaults.DEFAUT_NODE_COLOR); + background_color = this.getColorProperty(PROP_BACKGROUND_COLOR, CfgPreferencesDefaults.DEFAULT_BACKGROUND_COLOR); + backedge_color = this.getColorProperty(PROP_BACK_EDGE_COLOR, CfgPreferencesDefaults.DEFAULT_BACKEDGE_COLOR); + edge_color = this.getColorProperty(PROP_EDGE_COLOR, CfgPreferencesDefaults.DEFAULT_EDGE_COLOR); + selection_color_fg= this.getColorProperty(PROP_SELECTION_COLOR_FG, CfgPreferencesDefaults.DEFAULT_SELECTION_COLOR_FOREGROUND); + border_color = this.getColorProperty(PROP_BORDER_COLOR, CfgPreferencesDefaults.DEFAULT_BORDER_COLOR); + exceptionEdgeColor = this.getColorProperty(PROP_EXCEPTION_EDGE_COLOR, CfgPreferencesDefaults.DEFAULT_EXCEPTIONEDGE_COLOR); + text_color= this.getColorProperty(PROP_TEXT_COLOR, CfgPreferencesDefaults.DEFAULT_TEXT_COLOR); + selection_color_bg = this.getColorProperty(PROP_SELECTION_COLOR_BG, CfgPreferencesDefaults.DEFAULT_SELECTION_COLOR_BACKGROUND); + selection_color_fg = this.getColorProperty(PROP_SELECTION_COLOR_FG, CfgPreferencesDefaults.DEFAULT_SELECTION_COLOR_FOREGROUND); + text_font = this.getFontProperty(PROP_TEXT_FONT, CfgPreferencesDefaults.DEFAULT_TEXT_FONT); + } + + private void firePropertyChange(String propertyName, Object oldValue, Object newValue) { + Object[] listeners = listenerList.getListenerList(); + + PropertyChangeEvent event = new PropertyChangeEvent(this, propertyName, oldValue, newValue); + for (int i = listeners.length - 2; i >= 0; i -= 2) { + if (listeners[i] == PropertyChangeListener.class) { + ((PropertyChangeListener) listeners[i+1]).propertyChange(event); + } + } + } + + private Font getFontProperty(String propName, Font defaultFont){ + Preferences prefs = this.getPreferences(); + String fontName = prefs.get(propName+PROP_FONTNAME, defaultFont.getFamily()); + int fontSize = prefs.getInt(propName+PROP_FONTSIZE, defaultFont.getSize()); + int fontStyle = prefs.getInt(propName+PROP_FONTSTYLE, defaultFont.getStyle()); + return new Font(fontName, fontStyle, fontSize); + } + + private Color getColorProperty(String propName, Color defaultColor){ + Preferences prefs = this.getPreferences(); + int srgb = prefs.getInt(propName, defaultColor.getRGB()); + if(srgb == defaultColor.getRGB()) + return defaultColor; + return new Color(srgb); + } + + public Color getBackedgeColor() { + return backedge_color; + } + + public Color getBackgroundColor() { + return background_color; + } + + public Color getBorderColor() { + return border_color; + } + + public Color getEdgeColor() { + return edge_color; + } + + public Color getExceptionEdgeColor() { + return exceptionEdgeColor; + } + + public Color getNodeColor() { + return node_color; + } + + public Color getSelectionColorForeground() { + return selection_color_fg; + } + + public Color getSelectionColorBackground() { + return selection_color_bg; + } + + public Color getTextColor() { + return text_color; + } + + public Font getTextFont() { + return text_font; + } + + public FlagsSetting getFlagsSetting() { + return flagsSetting; + } + + + public void setFlagsSetting(FlagsSetting flagsSetting) { + FlagsSetting old = this.getFlagsSetting(); + this.flagsSetting = flagsSetting; + Preferences prefs = getPreferences(); + firePropertyChange(PROP_FLAGS, old, flagsSetting); + prefs.put(PROP_FLAGS, flagsSetting.getFlagString()); + } + + + public void setTextFont(Font text_font) { + Font old = this.getTextFont(); + Preferences prefs = getPreferences(); + this.text_font = text_font; + firePropertyChange(PROP_TEXT_FONT, old, text_font); + prefs.put(PROP_TEXT_FONT + PROP_FONTNAME , text_font.getFamily()); + prefs.putInt(PROP_TEXT_FONT + PROP_FONTSIZE, text_font.getSize()); + prefs.putInt(PROP_TEXT_FONT + PROP_FONTSTYLE, text_font.getStyle()); + } + + public void setBackedgeColor(Color backedge_color) { + Color old = this.getBackedgeColor(); + this.backedge_color = backedge_color; + firePropertyChange(PROP_BACK_EDGE_COLOR, old, backedge_color); + getPreferences().putInt(PROP_BACK_EDGE_COLOR, backedge_color.getRGB()); + } + + public void setBackgroundColor(Color bg_color) { + Color old = this.getBackgroundColor(); + background_color = bg_color; + firePropertyChange(PROP_BACKGROUND_COLOR, old, bg_color ); + getPreferences().putInt(PROP_BACKGROUND_COLOR, bg_color.getRGB()); + } + + public void setBorderColor(Color border_color) { + Color old = getBorderColor(); + this.border_color = border_color; + firePropertyChange(PROP_BORDER_COLOR, old, border_color ); + getPreferences().putInt(PROP_BORDER_COLOR, border_color.getRGB()); + } + + public void setEdgeColor(Color edge_color) { + Color old = getEdgeColor(); + this.edge_color = edge_color; + firePropertyChange(PROP_EDGE_COLOR, old, edge_color); + getPreferences().putInt(PROP_EDGE_COLOR, edge_color.getRGB()); + } + + public void setNodeColor(Color node_color) { + Color old = getNodeColor(); + this.node_color = node_color; + firePropertyChange(PROP_NODE_COLOR, old, node_color); + getPreferences().putInt(PROP_NODE_COLOR, node_color.getRGB()); + + } + + public void setSelectionColorForeground(Color selection_color) { + Color old = this.getSelectionColorForeground(); + this.selection_color_fg = selection_color; + firePropertyChange(PROP_SELECTION_COLOR_FG, old, selection_color); + getPreferences().putInt(PROP_SELECTION_COLOR_FG, selection_color.getRGB()); + } + + public void setSelectionColorBackground(Color selection_color) { + Color old = this.getSelectionColorBackground(); + this.selection_color_bg = selection_color; + firePropertyChange(PROP_SELECTION_COLOR_BG, old, selection_color); + getPreferences().putInt(PROP_SELECTION_COLOR_BG, selection_color.getRGB()); + } + + public void setTextColor(Color text_color) { + Color old = this.getTextColor(); + this.text_color = text_color; + firePropertyChange(PROP_TEXT_COLOR, old, text_color); + getPreferences().putInt(PROP_TEXT_COLOR, text_color.getRGB()); + } + + public void setExceptionEdgeColor(Color exceptionEdgeColor) { + Color old = this.getExceptionEdgeColor(); + this.exceptionEdgeColor = exceptionEdgeColor; + firePropertyChange(PROP_EXCEPTION_EDGE_COLOR, old, exceptionEdgeColor); + getPreferences().putInt(PROP_EXCEPTION_EDGE_COLOR, exceptionEdgeColor.getRGB()); + } + + + +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/CfgPreferencesDefaults.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/CfgPreferencesDefaults.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,23 @@ +package at.ssw.visualizer.cfg.preferences; + +import java.awt.Color; +import java.awt.Font; + +/** + * Default Configuration for options panel + * + * @author Rumpfhuber Stefan + */ +public final class CfgPreferencesDefaults { + public static final String DEFAULT_FLAGSTRING = "std(224,224,128);osr(224,224,0);ex(128,128,224);sr(128,224,128);llh(224,128,128);lle(224,192,192);plh(128,224,128);bb(160,0,0);ces(192,192,192)"; + public static final Color DEFAUT_NODE_COLOR = new Color(208, 208, 208); + public static final Color DEFAULT_BACKGROUND_COLOR = new Color(255, 255, 255); + public static final Color DEFAULT_BACKEDGE_COLOR = new Color(160, 0, 0); + public static final Color DEFAULT_EDGE_COLOR = new Color(0, 0, 0); + public static final Color DEFAULT_SELECTION_COLOR_FOREGROUND = Color.BLUE; + public static final Color DEFAULT_SELECTION_COLOR_BACKGROUND = Color.BLUE; + public static final Color DEFAULT_BORDER_COLOR = new Color(0, 0, 0); + public static final Color DEFAULT_EXCEPTIONEDGE_COLOR = new Color(0, 0, 160); + public static final Color DEFAULT_TEXT_COLOR = new Color(0, 0, 0); + public static final Font DEFAULT_TEXT_FONT = new Font("Dialog", Font.PLAIN, 18); +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/ColorChooserButton.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/ColorChooserButton.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,94 @@ +package at.ssw.visualizer.cfg.preferences; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.Icon; +import javax.swing.JButton; +import javax.swing.JColorChooser; + +/** + * A color selection button. It will preview the currently selected color as + * an icon. Clicking the button will bring up the JColorChooser dialog. + * + * @author Bernhard Stiftner + */ +public class ColorChooserButton extends JButton implements ActionListener { + + public static final Dimension ICON_SIZE = new Dimension(24, 8); + + Color color; + boolean colorChooserEnabled = true; // bring up dialog when clicked? + + + public ColorChooserButton() { + this(Color.black); + } + + public ColorChooserButton(Color defaultColor) { + setIcon(new ColorBoxIcon()); + addActionListener(this); + color = defaultColor; + Dimension size = new Dimension(ICON_SIZE); + size.width += getInsets().left + getInsets().right; + size.height += getInsets().top + getInsets().bottom; + setPreferredSize(size); + } + + public void setColor(Color newColor) { + color = newColor; + repaint(); + } + + public Color getColor() { + return color; + } + + public boolean isColorChooserEnabled() { + return colorChooserEnabled; + } + + public void setColorChooserEnabled(boolean enabled) { + this.colorChooserEnabled = enabled; + } + + public void actionPerformed(ActionEvent e) { + if (!colorChooserEnabled) { + return; + } + + Color c = JColorChooser.showDialog(this, "Choose color", color); + if (c != null) { + setColor(c); + } + } + + class ColorBoxIcon implements Icon { + + public int getIconWidth() { + return ICON_SIZE.width; + } + + public int getIconHeight() { + return ICON_SIZE.height; + } + + public void paintIcon(Component c, Graphics g, int x, int y) { + Color oldColor = g.getColor(); + g.translate(x, y); + + g.setColor(color); + g.fillRect(0, 0, ICON_SIZE.width, ICON_SIZE.height); + + g.setColor(Color.black); + g.drawRect(0, 0, ICON_SIZE.width, ICON_SIZE.height); + + g.translate(-x, -y); + g.setColor(oldColor); + } + } +} + diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/FlagsEditorPanel.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/FlagsEditorPanel.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,247 @@ +package at.ssw.visualizer.cfg.preferences; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Enumeration; +import java.util.StringTokenizer; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.DefaultListModel; +import javax.swing.JButton; +import javax.swing.JColorChooser; +import javax.swing.JComponent; +import javax.swing.JList; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.ListSelectionModel; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; + +/** + * + * @author Bernhard Stiftner + * @author Rumpfhuber Stefan + */ +public class FlagsEditorPanel extends JPanel implements ActionListener, + ListSelectionListener { + + FlagListModel listModel; + JList list; + ColorChooserButton colorButton; + JButton newButton; + JButton removeButton; + JButton upButton; + JButton downButton; + + + /** Creates a new instance of FlagsEditorPanel */ + public FlagsEditorPanel(String flagString) { + setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); + + listModel = new FlagListModel(flagString); + list = new JList(listModel); + list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + list.addListSelectionListener(this); + add(new JScrollPane(list)); + + add(Box.createHorizontalStrut(3)); + + Box buttonBox = new Box(BoxLayout.Y_AXIS); + buttonBox.add(colorButton = new ColorChooserButton()); + buttonBox.add(newButton = new JButton("New...")); + buttonBox.add(removeButton = new JButton("Remove")); + buttonBox.add(upButton = new JButton("Up")); + buttonBox.add(downButton = new JButton("Down")); + buttonBox.add(Box.createVerticalGlue()); + add(buttonBox); + layoutButtonContainer(buttonBox); + + colorButton.setColorChooserEnabled(false); + colorButton.addActionListener(this); + newButton.addActionListener(this); + removeButton.addActionListener(this); + upButton.addActionListener(this); + downButton.addActionListener(this); + + selectionChanged(-1); // no selection + } + + /** + * Ugly helper to make a nice layout for vertically aligned buttons. + */ + private static void layoutButtonContainer(JComponent buttonContainer) { + int width = 0; + int height = 0; + + for (int i=0; i= listModel.size()-1) { + return; + } + Object o = listModel.getElementAt(index); + listModel.removeElementAt(index); + listModel.insertElementAt(o, index+1); + } + } + + public void valueChanged(ListSelectionEvent e) { + if (e.getValueIsAdjusting()) { + return; // another event will be fired soon + } + selectionChanged(list.getSelectedIndex()); + } + + protected void selectionChanged(int index) { //index is -1 if there is no selection + colorButton.setEnabled(index >= 0); + removeButton.setEnabled(index >= 0); + upButton.setEnabled(index > 0); + downButton.setEnabled(index >= 0 && index < listModel.getSize()-1); + + if (index >= 0) { + FlagListItem item = (FlagListItem)listModel.elementAt(index); + colorButton.setColor(item.getColor()); + list.setSelectedIndex(index); + } else { + colorButton.setColor(getBackground()); + } + } + + protected void changeColor() { + int selectedIndex = list.getSelectedIndex(); + FlagListItem item = (FlagListItem)listModel.elementAt(selectedIndex); + Color c = JColorChooser.showDialog(this, "Choose color", item.getColor()); + + if (c != null) { + item.setColor(c); + colorButton.setColor(c); + } + } + + class FlagListModel extends DefaultListModel { + + public FlagListModel(String flagString) { + if (flagString != null) { + setFlagString(flagString); + } + } + + public String getFlagString() { + StringBuffer sb = new StringBuffer(); + Enumeration e = elements(); + while (e.hasMoreElements()) { + FlagListItem item = (FlagListItem)e.nextElement(); + sb.append(item.getFlagString()); + Color c = item.getColor(); + sb.append("(").append(c.getRed()).append(",").append(c.getGreen()).append(",").append(c.getBlue()).append(")"); + if (e.hasMoreElements()) { + sb.append(";"); + } + } + return sb.toString(); + } + + public void setFlagString(String flagString) { + clear(); + StringTokenizer st = new StringTokenizer(flagString, ";"); + while (st.hasMoreTokens()) { + String s = st.nextToken(); + String flag = s.split("\\(")[0]; + Color color = FlagsSetting.toColor(s); + addElement(new FlagListItem(flag, color)); + } + } + + } + + class FlagListItem { + + Color color; + String flagString; + + public FlagListItem(String flagString, Color color) { + this.flagString = flagString; + this.color = color; + } + + public Color getColor() { + return color; + } + + public String getFlagString() { + return flagString; + } + + public void setColor(Color c) { + color = c; + } + + @Override + public String toString() { + return flagString; + } + } + +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/FlagsSetting.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/FlagsSetting.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,85 @@ +package at.ssw.visualizer.cfg.preferences; + +import java.awt.Color; +import java.io.Serializable; +import java.util.Hashtable; +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public class FlagsSetting implements Serializable { + + private Hashtable flag2color; + private Hashtable priority; + private String flagString; + + + public FlagsSetting(String flagString) { + this.flagString = flagString; + flag2color = new Hashtable<>(); + priority = new Hashtable<>(); + String[] flags = flagString.split(";"); + + int z = 0; + for(String s : flags) { + String flag = s.split("\\(")[0]; + Color c = toColor(s); + flag2color.put(flag, c); + priority.put(flag, z); + z++; + } + } + + public Color getColor(List strings) { + int minPriority = Integer.MAX_VALUE; + Color result = null; + + for(String s : strings) { + Color curColor = flag2color.get(s); + if(curColor != null) { + int curPriority = priority.get(s); + if(curPriority < minPriority) { + minPriority = curPriority; + result = curColor; + } + } + } + + return result; + } + + public static Color toColor(String s) { + String sArr[] = s.split("\\("); + String Color = sArr[1].substring(0, sArr[1].length() - 1); + String ColorArr[] = Color.split(","); + int r = Integer.parseInt(ColorArr[0]); + int g = Integer.parseInt(ColorArr[1]); + int b = Integer.parseInt(ColorArr[2]); + return new Color(r, g, b); + } + + public String getFlagString() { + return flagString; + } + + @Override + public boolean equals(Object o) { + if(o==null) + return false; + return this.toString().equals(o.toString()); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 19 * hash + (this.flagString != null ? this.flagString.hashCode() : 0); + return hash; + } + + @Override + public String toString(){ + return "FlagSetting[" + flagString + "]"; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/FontChooserDialog.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/preferences/FontChooserDialog.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,37 @@ +package at.ssw.visualizer.cfg.preferences; + +import java.awt.Font; +import java.beans.PropertyEditor; +import java.beans.PropertyEditorManager; +import org.openide.DialogDescriptor; +import org.openide.DialogDisplayer; + +/** + * + * @author Bernhard Stiftner + */ +public class FontChooserDialog { + + /* + * Displays a font selection dialog. + * @return The selected font, or the initial font if the user chose + * to bail out + */ + public static Font show(Font initialFont) { + PropertyEditor pe = PropertyEditorManager.findEditor(Font.class); + if (pe == null) { + throw new RuntimeException("Could not find font editor component."); + } + pe.setValue(initialFont); + DialogDescriptor dd = new DialogDescriptor( + pe.getCustomEditor(), + "Choose Font"); + DialogDisplayer.getDefault().createDialog(dd).setVisible(true); + if (dd.getValue() == DialogDescriptor.OK_OPTION) { + Font f = (Font)pe.getValue(); + return f; + } + return initialFont; + } + +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/visual/BezierWidget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/visual/BezierWidget.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,345 @@ +package at.ssw.visualizer.cfg.visual; + +import org.netbeans.api.visual.widget.ConnectionWidget; +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Shape; +import java.awt.Stroke; +import java.awt.geom.AffineTransform; +import java.awt.geom.CubicCurve2D; +import java.awt.geom.GeneralPath; +import java.awt.geom.Point2D; +import java.util.List; +import org.netbeans.api.visual.anchor.AnchorShape; +import org.netbeans.api.visual.graph.GraphScene; +import org.netbeans.api.visual.widget.Scene; +import org.netbeans.api.visual.widget.Widget; + + +/** + * In comparison to the default ConnectionWidget this class is able to connect + * Widgets with a curve instead of a straight line sequence. Between two control + * points a curve is painted as cubic bezier curve the control points are + * calculated automaticaly they depend on the position of the prior- and the + * following control points. + * In conjunction with a suitable router the connection will be a straight line + * or a curve depending on the amount and the position of the controlpoints. + * Controlpoints supplied by the router, are treated as curve intersection points. + * For Reflexive edges the router doesn`t need to supply controlpoints, they + * get painted by this class automatically. If the router supplys more as 2 + * control points for a recursive edge the edge gets painted with the default + * curve approximation algorithm. + */ +public class BezierWidget extends ConnectionWidget { + private static final double BEZIER_SCALE = 0.3; + private static final double ENDPOINT_DEVIATION = 3;//curve endpoint approximation accuracy + + private GraphScene scene=null; + + public BezierWidget(Scene scene) { + super(scene); + } + + public BezierWidget(GraphScene scene) { + super(scene); + this.scene=scene; + } + + + private boolean isReflexive(){ + return getSourceAnchor().getRelatedWidget() == getTargetAnchor().getRelatedWidget(); + } + + + @Override + protected Rectangle calculateClientArea() { + Rectangle bounds = null; + if(this.getControlPoints().size()>0){ + for(Point p : this.getControlPoints()){ + if(bounds==null) + bounds = new Rectangle(p); + else + bounds.add(p); + } + bounds.grow(5,5); + } + if(isReflexive()){ + Widget related = this.getTargetAnchor().getRelatedWidget(); + bounds = related.convertLocalToScene(related.getBounds()); + bounds.grow(10, 10); + } + if(bounds==null) + bounds = super.calculateClientArea(); + + return bounds; + } + + + + //returns prefered location for an edge -1 for left and 1 for right + private int edgeBalance(Widget nodeWidget) { + if(scene == null) + return 1; + + Point nodeLocation = nodeWidget.getLocation(); + int left = 0, right = 0; + + Object node = scene.findObject(nodeWidget); + + for(Object e : scene.findNodeEdges(node, true, true)) {//inputedges + ConnectionWidget cw = (ConnectionWidget) scene.findWidget(e); + + if(cw != this) { + Widget targetNodeWidget = cw.getTargetAnchor().getRelatedWidget(); + + Point location; + if(targetNodeWidget == nodeWidget) { + Widget sourceNodeWidget = cw.getSourceAnchor().getRelatedWidget(); + location = sourceNodeWidget.getLocation(); + } else { + location = targetNodeWidget.getLocation(); + } + + if(location.x < nodeLocation.x) + left++; + else + right++; + } + } + if(left < right) + return -1; + else + return 1; + } + + + + + /** + * if the edge is reflexive its painted as a cyclic edge + * if there are 2 controlpoints the connection is painted as a straight line from the source to the targetanchor + * if there are more as 2 controlpoints the connection path between 2 control points is painted as bezier curve + */ + + @Override + protected void paintWidget () { + + List contrPoints = this.getControlPoints(); + int listSize = contrPoints.size(); + + Graphics2D gr = getGraphics (); + + if (listSize <= 2) { + if(isReflexive()) { //special case for reflexive connection widgets + Widget related = this.getTargetAnchor().getRelatedWidget(); + int position = this.edgeBalance(related); + Rectangle bounds = related.convertLocalToScene(related.getBounds()); + gr.setColor (getLineColor()); + Point first = new Point(); + Point last = new Point(); + double centerX = bounds.getCenterX(); + first.x = (int) (centerX + bounds.width / 4); + first.y = bounds.y + bounds.height; + last.x = first.x; + last.y = bounds.y; + + gr.setStroke(this.getStroke()); + + double cutDistance = this.getTargetAnchorShape().getCutDistance(); + double anchorAngle = Math.PI/-3.0; + double cutX = Math.abs(Math.cos(anchorAngle)*cutDistance); + double cutY = Math.abs(Math.sin(anchorAngle)*cutDistance); + int ydiff=first.y-last.y; + int endy = -ydiff; + double height=bounds.getHeight(); + double cy = height/4.0; + double cx=bounds.getWidth()/5.0; + double dcx = cx*2; + GeneralPath gp = new GeneralPath(); + gp.moveTo(0, 0); + gp.quadTo(0, cy, cx, cy); + gp.quadTo(dcx, cy, dcx, -height/2.0); + gp.quadTo(dcx, endy - cy, cy, -(cy+ydiff)); + gp.quadTo(cutX*1.5, endy - cy, cutX, endy-cutY); + + AffineTransform af = new AffineTransform(); + AnchorShape anchorShape = this.getTargetAnchorShape(); + + if(position < 0) { + first.x = (int) (centerX - bounds.width / 4); + af.translate(first.x, first.y); + af.scale(-1.0, 1.0); + last.x = first.x; + } else { + af.translate(first.x, first.y); + } + Shape s = gp.createTransformedShape(af); + gr.draw(s); + + if (last != null) { + AffineTransform previousTransform = gr.getTransform (); + gr.translate (last.x, last.y); + + if(position < 0) + gr.rotate(Math.PI - anchorAngle); + else + gr.rotate (anchorAngle); + + anchorShape.paint (gr, false); + gr.setTransform (previousTransform); + } + + } else { + super.paintWidget(); + } + return; + } + + //bezier curve... + GeneralPath curvePath = new GeneralPath(); + Point lastControlPoint = null; + double lastControlPointRotation = 0.0; + + Point prev = null; + for (int i = 0; i < listSize - 1; i++) { + Point cur = contrPoints.get(i); + Point next = contrPoints.get(i + 1); + Point nextnext = null; + if (i < listSize - 2) { + nextnext = contrPoints.get(i + 2); + } + + double len = cur.distance(next); + double scale = len * BEZIER_SCALE; + Point bezierFrom = null;//first ControlPoint + Point bezierTo = null;//second ControlPoint + + if (prev == null) { + //first point + curvePath.moveTo(cur.x, cur.y);//startpoint + bezierFrom = cur; + } else { + bezierFrom = new Point(next.x - prev.x, next.y - prev.y); + bezierFrom = scaleVector(bezierFrom, scale); + bezierFrom.translate(cur.x, cur.y); + } + + if (nextnext == null) {//next== last point (curve to) + lastControlPoint=next; + bezierTo = next;//set 2nd intermediate point to endpoint + GeneralPath lastseg = this.subdivide(cur, bezierFrom, bezierTo, next); + if(lastseg != null) + curvePath.append(lastseg, true); + break; + } else { + bezierTo = new Point(cur.x - nextnext.x, cur.y - nextnext.y); + bezierTo = scaleVector(bezierTo, scale); + bezierTo.translate(next.x, next.y); + } + + curvePath.curveTo( + bezierFrom.x, bezierFrom.y,//controlPoint1 + bezierTo.x, bezierTo.y,//controlPoint2 + next.x,next.y + ); + prev = cur; + } + Point2D cur = curvePath.getCurrentPoint(); + Point next = lastControlPoint; + + lastControlPointRotation = //anchor anchorAngle + Math.atan2 (cur.getY() - next.y, cur.getX() - next.x); + + Color previousColor = gr.getColor(); + gr.setColor (getLineColor()); + Stroke s = this.getStroke(); + gr.setStroke(s); + gr.setColor(this.getLineColor()); + gr.draw(curvePath); + + AffineTransform previousTransform = gr.getTransform (); + gr.translate (lastControlPoint.x, lastControlPoint.y); + gr.rotate (lastControlPointRotation); + AnchorShape targetAnchorShape = this.getTargetAnchorShape(); + targetAnchorShape.paint (gr, false); + gr.setTransform (previousTransform); + + //paint ControlPoints if enabled + if (isPaintControlPoints()) { + int last = listSize - 1; + for (int index = 0; index <= last; index ++) { + Point point = contrPoints.get (index); + previousTransform = gr.getTransform (); + gr.translate (point.x, point.y); + if (index == 0 || index == last) + getEndPointShape().paint (gr); + else + getControlPointShape().paint (gr); + gr.setTransform (previousTransform); + } + + } + gr.setColor(previousColor); + } + + + + private GeneralPath subdivide (Point b0, Point b1, Point b2, Point b3) { + double cutDistance = getTargetAnchorShape().getCutDistance(); + double minDistance = cutDistance - ENDPOINT_DEVIATION; + /** + * if the cutDistance is valid the last segment of the curve + * gets reduced by subdivision until the distance of the endpoint(epDistance) + * satisfys the condition (cutDistance > epDistance > (cutDistance - ENDPOINT-DEVIATION) + */ + if(cutDistance > minDistance && minDistance > 0 ) { + GeneralPath path = new GeneralPath(); + + path.moveTo(b0.x, b0.y); + + CubicCurve2D.Double left = new CubicCurve2D.Double( + b0.x, b0.y, + b1.x, b1.y, + b2.x, b2.y, + b3.x, b3.y); + + CubicCurve2D right=new CubicCurve2D.Double(); + left.subdivide(left, right); + double distance = b3.distance(left.getP2()); + //if the distance is bigger as the cutDistance the left segment is added + //and the right segment is divided again + while(distance>cutDistance){ + path.append(left, true); + right.subdivide(left, right); + distance = b3.distance(left.getP2()); + //if the devision removed to much the left segment is divided + while(distance < minDistance) { + //changes the distance to ~ (distance+distance/2) + left.subdivide(left, right); + distance = b3.distance(left.getP2()); + } + } + //append the last segment with (minDistance < distance < cutDistance) + //actually we should check if the a division happend, but this is very unlikly + path.append(left, true); + return path; + } + return null; + } + + + + + + private static Point scaleVector(Point vector, double len) { + double scale = Math.sqrt(vector.x * vector.x + vector.y * vector.y); + if(scale==0.0) return vector; + scale = len / scale; + return new Point( + Math.round(vector.x * (float)scale), + Math.round(vector.y * (float)scale)); + } + +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/visual/PolylineRouter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/visual/PolylineRouter.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,360 @@ +package at.ssw.visualizer.cfg.visual; + +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.geom.Line2D; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import org.netbeans.api.visual.anchor.Anchor; +import org.netbeans.api.visual.router.Router; +import org.netbeans.api.visual.widget.ConnectionWidget; +import org.netbeans.api.visual.widget.Widget; + +/** + * Router Class with Collision Detection + * + * + * The returned path is a straight line there is no node widget between the source and the target node, + * if there are nodewidgets in between it tries to find a path around those abstacles to avoid collisions. + * The algorithm for the search of this path is limited by a fixed number of iterations defined in + * NUMER_OF_ITERATIONS to return a result in reasonable time. If the calculation exceeds this limit the + * path returned contains at least 1 collision with a nodewidget. + */ + +public class PolylineRouter implements Router { + private static final float FACTOR = 0.70f; + + private static final int HEXPAND = 3; + private static final int VEXPAND = 3; + private static final int NUMBER_OF_ITERATIONS = 8; + + WidgetCollisionCollector collector; + + + public PolylineRouter(WidgetCollisionCollector collector){ + this.collector=collector; + } + + + public List routeConnection(final ConnectionWidget widget) { + if(!widget.isVisible()) return Collections.emptyList(); + + Anchor sourceAnchor = widget.getSourceAnchor(); + Anchor targetAnchor = widget.getTargetAnchor(); + + if(sourceAnchor == null || targetAnchor == null) + return null; + + Point start = sourceAnchor.compute(widget.getSourceAnchorEntry()).getAnchorSceneLocation(); + Point end = targetAnchor.compute(widget.getTargetAnchorEntry()).getAnchorSceneLocation(); + + Widget sourceWidget = sourceAnchor.getRelatedWidget(); + Widget targetWidget = targetAnchor.getRelatedWidget(); + + + if(sourceWidget == targetWidget){//reflexive edges doesnt need any path + return Collections.emptyList(); + } + + List nodeWidgets = new ArrayList<>(); + + if(collector != null){ + collector.collectCollisions(nodeWidgets); + //source and target widget are not treatet as obstacle + nodeWidgets.remove(sourceWidget); + nodeWidgets.remove(targetWidget); + } + + List controlPoints = optimize(nodeWidgets, widget, start, end); + + //size==2 => straight line + //size==3 => ensures a collision between cp0 and cp2 therefore its not possible to simplify it + if(controlPoints.size() > 3) + controlPoints = simplify(nodeWidgets, controlPoints); + + return controlPoints; + } + + + private List simplify(Collection nodeWidgets, List list) { + List result = new ArrayList<>(); + result.add( list.get(0) );//add startpoint + for (int i = 1; i < list.size(); i++) { + Point prev = list.get(i - 1); + for (int j = i; j < list.size(); j++) { + Point cur = list.get(j); + if (!intersects(nodeWidgets, prev, cur)) { + i = j; + } + } + result.add(list.get(i)); + } + return result; + } + + /** + * Computates the Anchorposition like the Rectangular anchor for a + * given widget as source/target and a controlpoint as opposit anchorposition + */ + + private Point computateAnchorPosition(Widget relatedWidget, Point controlPoint) { + Rectangle bounds = relatedWidget.getBounds(); + Point relatedLocation = relatedWidget.getLocation();//center of the widget + + if (bounds.isEmpty () || relatedLocation.equals (controlPoint)) + return relatedLocation; + + float dx = controlPoint.x - relatedLocation.x; + float dy = controlPoint.y - relatedLocation.y; + + float ddx = Math.abs (dx) / (float) bounds.width; + float ddy = Math.abs (dy) / (float) bounds.height; + + float scale = 0.5f / Math.max (ddx, ddy); + + Point point = new Point (Math.round (relatedLocation.x + scale * dx), + Math.round (relatedLocation.y + scale * dy)); + return point; + } + + + + private List optimize(Collection nodeWidgets, ConnectionWidget connWidget, Point start, Point end) { + + List list = new ArrayList<>(); + list.add(start); + list.add(end); + + boolean progress = true; + + for (int j = 0; progress && j < NUMBER_OF_ITERATIONS ; j++) { + progress = false; + List newList = new ArrayList<>(); + for (int i = 0; i < list.size() - 1 ; i++) { + Point cur = list.get(i); + Point next = list.get(i + 1); + newList.add(cur); + List intermediate = optimizeLine(nodeWidgets, cur, next); + if (intermediate != null && intermediate.size() > 0) { + progress = true; + newList.addAll(intermediate);//insert new controlpoints between cur and next + } + } + newList.add(list.get(list.size()-1));//add endpoint of the polyline + list = newList; + + } + + if(list.size() > 2) { + Widget sourceNode = connWidget.getSourceAnchor().getRelatedWidget(); + Widget targetNode = connWidget.getTargetAnchor().getRelatedWidget(); + Rectangle sourceBounds = sourceNode.convertLocalToScene(sourceNode.getBounds()); + Rectangle targetBounds = targetNode.convertLocalToScene(targetNode.getBounds()); + sourceBounds.grow(HEXPAND, VEXPAND); + + /** + * add only points which are not intersecting the source and the target + * widget bounds caused by invalid bad anchor positions. The first + * and the last point is ignored cause the anchor is recalculated + * anyway. + */ + ArrayList tmp = new ArrayList<>(); + int listSize=list.size(); + tmp.add(list.get(0)); + int i=0; + while(++i < listSize-1) { + Point p = list.get(i); + if(!sourceBounds.contains(p) || !targetBounds.contains(p)) + tmp.add(p); + } + + tmp.add(list.get(i)); + if(tmp.size() < 3) + return tmp; + + list=tmp; + //calculate a proper anchor position using the second/penultimate controlpoint for start/end + start = this.computateAnchorPosition(connWidget.getSourceAnchor().getRelatedWidget(), list.get(1)); + end = this.computateAnchorPosition(connWidget.getTargetAnchor().getRelatedWidget(), list.get(list.size()-2)); + list.set(0,start); + list.set(list.size()-1, end); + } + return list; + } + + + /** + * trys to optimize a line from p1 to p2 to avoid collisions with node widgets + * returns null if the line doesn`t intersect with any nodewidget + * or a list with immediate points between p1 and p2 to avoid collisions + */ + private List optimizeLine(Collection nodeWidgets, Point p1, Point p2) { + Line2D line = new Line2D.Double(p1, p2); + + for(Widget w : nodeWidgets ) { + if( w.isVisible() ) { + Rectangle r = w.convertLocalToScene(w.getBounds()); + r.grow(HEXPAND, VEXPAND); + + if (!line.intersects(r)) continue; + + Point location = w.getLocation(); + int distx = (int) (r.width * FACTOR); + int disty = (int) (r.height * FACTOR); + + int minIntersects = Integer.MAX_VALUE; + int min = Integer.MAX_VALUE; + List minSol = null; + for (int i = -1; i <= 1; i++) { + for (int j = -1; j <= 1; j++) { + if (i != 0 || j != 0) { + Point cur = new Point(location.x + i * distx, location.y + j * disty); + List list1 = new ArrayList<>(); + list1.add(p1); + list1.add(cur); + list1.add(p2); + int crossProd = Math.abs(crossProduct(p1, cur, p2)); + if (!intersects(w, list1)) { + Line2D line1 = new Line2D.Float(p1, cur); + Line2D line2 = new Line2D.Float(p2, cur); + int curIntersects = this.countNodeIntersections(nodeWidgets, line1, line2); + + if (curIntersects < minIntersects + || (curIntersects == minIntersects && crossProd < min)) { + minIntersects = curIntersects; + min = crossProd; + minSol = new ArrayList<>(); + minSol.add(cur); + } + } + + if (i == 0 || j == 0) { + Point cur1, cur2; + if (i == 0) { + cur1 = new Point(location.x + distx/2, location.y + j * disty); + cur2 = new Point(location.x - distx/2, location.y + j * disty); + } else { // (j == 0) + cur1 = new Point(location.x + i * distx, location.y + disty/2); + cur2 = new Point(location.x + i * distx, location.y - disty/2); + } + + Point vec1 = new Point(p1.x - cur1.x, p1.y - cur1.y); + int offset1 = vec1.x * vec1.x + vec1.y * vec1.y; + + Point vec2 = new Point(p1.x - cur2.x, p1.y - cur2.y); + int offset2 = vec2.x * vec2.x + vec2.y * vec2.y; + + if (offset2 < offset1) { + Point tmp = cur1; + cur1 = cur2; + cur2 = tmp; + } + + List list2 = new ArrayList<>(); + list2.add(p1); + list2.add(cur1); + list2.add(cur2); + list2.add(p2); + + int cross1 = crossProduct(p1, cur1, cur2); + int cross2 = crossProduct(cur1, cur2, p2); + + if (cross1 > 0) { + cross1 = 1; + } else if (cross1 < 0) { + cross1 = -1; + } + + if (cross2 > 0) { + cross2 = 1; + } else if (cross2 < 0) { + cross2 = -1; + } + if ((cross1 == cross2 || cross1 == 0 || cross2 == 0) && !intersects(w, list2)) { + Line2D line1 = new Line2D.Float(p1, cur1); + Line2D line2 = new Line2D.Float(cur1, cur2); + Line2D line3 = new Line2D.Float(p2, cur2); + int curIntersects = this.countNodeIntersections(nodeWidgets, line1, line2, line3); + + // This is a bit better + crossProd--; + + if (curIntersects < minIntersects + || (curIntersects == minIntersects && crossProd < min)) { + minIntersects = curIntersects; + min = crossProd; + minSol = new ArrayList<>(); + minSol.add(cur1); + minSol.add(cur2); + } + } + } + } + } + } + if (minSol != null) { + return minSol; + } + } + } + return null; + } + + + + private int countNodeIntersections(Collection nodeWidgets, Line2D... lines){ + int count=0; + for(Widget nw : nodeWidgets){ + if(nw.isVisible()) { + Rectangle bounds = nw.convertLocalToScene(nw.getBounds()); + for( Line2D line : lines){ + if(line.intersects(bounds)) + count++; + } + } + } + return count; + } + + + private boolean intersects(Collection nodeWidgets, Point start, Point end) { + List pointlist = new ArrayList<>(); + pointlist.add(start); + pointlist.add(end); + + for(Widget w : nodeWidgets){ + if(w.isVisible() && intersects(w, pointlist)) { + return true; + } + } + return false; + } + + + private boolean intersects(Widget w, List list) { + Rectangle r = w.convertLocalToScene(w.getBounds()); + r.grow(HEXPAND, VEXPAND); + return intersects(list, r); + } + + + private boolean intersects(List list, Rectangle rect){ + for(int i=1; i < list.size(); i++) { + Point cur = list.get(i-1); + Point next = list.get(i); + if(rect.intersectsLine(cur.x, cur.y, next.x, next.y)) + return true; + } + return false; + } + + + private int crossProduct(Point p1, Point p2, Point p3) { + Point off1 = new Point(p1.x - p2.x, p1.y - p2.y); + Point off2 = new Point(p3.x - p2.x, p3.y - p2.y); + return (off1.x * off2.y - off1.y * off2.x); + } + +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/visual/PolylineRouterV2.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/visual/PolylineRouterV2.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,393 @@ +package at.ssw.visualizer.cfg.visual; + +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.geom.Line2D; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import org.netbeans.api.visual.anchor.Anchor; +import org.netbeans.api.visual.router.Router; +import org.netbeans.api.visual.widget.ConnectionWidget; +import org.netbeans.api.visual.widget.Widget; + +/** + * Router Class with Collision Detection + * + * + * The returned path is a straight line there is no node widget between the source and the target node, + * if there are nodewidgets in between it tries to find a path around those abstacles to avoid collisions. + * The algorithm for the search of this path is limited by a fixed number of iterations defined in + * NUMER_OF_ITERATIONS to return a result in reasonable time. If the calculation exceeds this limit the + * path returned contains at least 1 collision with a nodewidget. + * + * This class intend to solve the same problem as the class PolyLineRouter but + * uses slightly different methods. + * + uses another algorithm for solving the collision. + * + the obstacle bounds are calulated in advance to avoid a recalculation. + * - there is no heuristic, the shortest path around the widget is choosen asap. + * + * + * + */ + +public class PolylineRouterV2 implements Router { + private static final int HEXPAND = 3; + private static final int VEXPAND = 3; + private static final int NUMBER_OF_ITERATIONS = 8; + + WidgetCollisionCollector collector; + + + public PolylineRouterV2(WidgetCollisionCollector collector){ + this.collector=collector; + } + + + public List routeConnection(final ConnectionWidget widget) { + if(!widget.isVisible()) return Collections.emptyList(); + + Anchor sourceAnchor = widget.getSourceAnchor(); + Anchor targetAnchor = widget.getTargetAnchor(); + + if(sourceAnchor == null || targetAnchor == null) + return null; + + Point start = sourceAnchor.compute(widget.getSourceAnchorEntry()).getAnchorSceneLocation(); + Point end = targetAnchor.compute(widget.getTargetAnchorEntry()).getAnchorSceneLocation(); + + Widget sourceWidget = sourceAnchor.getRelatedWidget(); + Widget targetWidget = targetAnchor.getRelatedWidget(); + + + if(sourceWidget == targetWidget){//reflexive edges doesnt need any path + return Collections.emptyList(); + } + + + Point srcCenter = this.getSceneLocation(sourceWidget); + Point tarCenter = this.getSceneLocation(targetWidget); + + List widgetObstacles = new ArrayList<>(); + + if(collector != null){ + collector.collectCollisions(widgetObstacles); + } + + List obstacles = new ArrayList<>(widgetObstacles.size()); + this.collectObstacles(obstacles, widgetObstacles, widget); + + + List controlPoints = optimize(obstacles, srcCenter, tarCenter); +// size==2 => straight line +// size==3 => ensures a collision between cp0 and cp2 therefore its not possible to simplify it + if(controlPoints.size() > 3){ + Point rstart = this.computateAnchorPosition(sourceWidget, controlPoints.get(1)); + Point rend = this.computateAnchorPosition(targetWidget, controlPoints.get(controlPoints.size()-2)); + controlPoints.set(0, rstart); + controlPoints.set(controlPoints.size()-1, rend); + controlPoints = simplify(obstacles, controlPoints); + } else if (controlPoints.size()>=2){ + //use old points + controlPoints.set(0, start); + controlPoints.set(controlPoints.size()-1, end); + + } + return controlPoints; + } + + + private int collectObstacles(List colrects, List colwidgets , ConnectionWidget cw){ + int count=0; + Anchor sourceAnchor = cw.getSourceAnchor(); + Anchor targetAnchor = cw.getTargetAnchor(); + Widget sourceWidget = sourceAnchor.getRelatedWidget(); + Widget targetWidget = targetAnchor.getRelatedWidget(); + Point start = sourceAnchor.compute(cw.getSourceAnchorEntry()).getAnchorSceneLocation(); + Point end = targetAnchor.compute(cw.getTargetAnchorEntry()).getAnchorSceneLocation(); + + for(Widget w : colwidgets){ + + if(w==sourceWidget || w == targetWidget) continue; + + Rectangle r = w.convertLocalToScene(w.getBounds()); + r.grow(HEXPAND, VEXPAND); + if(r.intersectsLine(start.x,start.y,end.x,end.y)) + count++; + colrects.add(r); + } + return count; + } + + + private Point center (Rectangle bounds) { + return new Point (bounds.x + bounds.width / 2, bounds.y + bounds.height / 2); + } + + /** + * Returns the scene location of a related widget. + * bounds might be null if the widget was not added to the scene + * @return the scene location; null if no related widget is assigned + */ + public Point getSceneLocation (Widget relatedWidget) { + if (relatedWidget != null) { + Rectangle bounds = relatedWidget.getBounds (); + if(bounds != null) + return center(relatedWidget.convertLocalToScene(bounds)); + } + return null; + } + + /** + * Computates the Anchorposition like the Rectangular anchor for a + * given widget as source/target and a controlpoint as opposit anchorposition + */ + + private Point computateAnchorPosition(Widget relatedWidget, Point controlPoint) { + Rectangle bounds = relatedWidget.getBounds(); + + //todo: fix, center of widget must be cacluated trough the bounds + //since there are some wheird widgets where the location is not the center of the widget + Point relatedLocation = relatedWidget.getLocation();//center of the widget + + if (bounds.isEmpty () || relatedLocation.equals (controlPoint)) + return relatedLocation; + + float dx = controlPoint.x - relatedLocation.x; + float dy = controlPoint.y - relatedLocation.y; + + float ddx = Math.abs (dx) / (float) bounds.width; + float ddy = Math.abs (dy) / (float) bounds.height; + + float scale = 0.5f / Math.max (ddx, ddy); + + Point point = new Point (Math.round (relatedLocation.x + scale * dx), + Math.round (relatedLocation.y + scale * dy)); + return point; + } + + private List simplify(List obstacles, List list) { + List result = new ArrayList<>(list.size()); + result.add( list.get(0) );//add startpoint + for (int i = 1; i < list.size(); i++) { + Point prev = list.get(i - 1); + for (int j = i; j < list.size(); j++) { + Point cur = list.get(j); + if (!intersects(obstacles, prev, cur)) { + i = j; + } + } + result.add(list.get(i)); + } + return result; + } + + private List optimize(List nodeWidgets, Point start, Point end) { + + List list = new ArrayList<>(); + list.add(start); + list.add(end); + + boolean progress = true; + + for (int j = 0; progress && j < NUMBER_OF_ITERATIONS ; j++) { + progress = false; + List newList = new ArrayList<>(); + for (int i = 0; i < list.size() - 1 ; i++) { + Point cur = list.get(i); + Point next = list.get(i + 1); + newList.add(cur); + List intermediate = optimizeLine(nodeWidgets, cur, next); + if (intermediate != null && intermediate.size() > 0) { + progress = true; + newList.addAll(intermediate);//insert new controlpoints between cur and next + } + } + newList.add(list.get(list.size()-1));//add endpoint of the polyline + list = newList; + + } + + return list; + } + + + /** + * trys to optimize a line from p1 to p2 to avoid collisions with rectangles + * returns null if the line doesn`t intersect with any nodewidget or + * if the obstacles are overlapping + * ---------------------------------------------------------------------- + * if the collision is solved it returns a list with immediate points + * between p1 and p2. The points are taken from hull points of and grown + * rectangle. + */ + private List optimizeLine(List obstacles, Point p1, Point p2) { + Line2D line = new Line2D.Double(p1, p2); + boolean inbounds=false; + Rectangle ibr=null; + ArrayList sol = new ArrayList<>(); + boolean leftIntersection; + boolean rightIntersection; + boolean bottomIntersection; + boolean topIntersection; + Point interLeft=new Point(); + Point interRight=new Point(); + Point interBot=new Point(); + Point interTop=new Point(); + + + + for(Rectangle r : obstacles ) { + if (!line.intersects(r)) continue; + + int w=r.width+2; + int h=r.height+2; + Point topLeft = r.getLocation(); + topLeft.x-=1; + topLeft.y-=1; + Point topRight = new Point(topLeft.x+w, topLeft.y); + Point bottomLeft = new Point(topLeft.x, topLeft.y+h); + Point bottomRight = new Point(topRight.x, bottomLeft.y); + leftIntersection = findIntersectionPoint(p1, p2, topLeft, bottomLeft, interLeft); + rightIntersection = findIntersectionPoint(p1, p2, topRight, bottomRight, interRight); + bottomIntersection = findIntersectionPoint(p1, p2, bottomLeft, bottomRight, interBot); + topIntersection = findIntersectionPoint(p1, p2, topLeft, topRight, interTop); + + //Intersection points are not used yet. This could be actually a + //good approach to avoid additional collisions because it would be + //still the same vector. + + if(leftIntersection) { + if(topIntersection) {//left and top + sol.add(topLeft); + } + else if(bottomIntersection){//left and bottom + sol.add(bottomLeft); + } + else if(rightIntersection){//left and right + double disttl = topLeft.distance(p1); + double distbl = bottomLeft.distance(p1); + if(disttl > distbl){ + //pass at the bottom + double distbr = bottomRight.distance(p1); + if(distbl < distbr){ + //from the left to the right + sol.add(bottomLeft); + sol.add(bottomRight); + } else { + //from the right to the left + sol.add(bottomRight); + sol.add(bottomLeft); + } + } else { + //pass at the top + double disttr = topRight.distance(p1); + if(disttl < disttr){ + //from the left to the right + sol.add(topLeft); + sol.add(topRight); + } else { + //from the right to the left + sol.add(topRight); + sol.add(topLeft); + } + } + } else {//only left => inside bounds + inbounds=true; + } + } else if (rightIntersection) { + if(topIntersection) {//right and top + sol.add(topRight); + } + else if(bottomIntersection){//right and bottom + sol.add(bottomRight); + } else { //only right => inside the bounds + inbounds=true; + } + } else if (topIntersection && bottomIntersection) {//top and bottom + double disttop = interTop.distance(p1); + double distbot = interBot.distance(p1); + if(disttop < distbot ){ + //from the top to the bottom + double distleft = interTop.distance(topLeft); + double distright = interTop.distance(topRight); + if(distleft < distright){ + //pass left + sol.add(topLeft); + sol.add(bottomLeft); + } else { + //pass right + sol.add(topRight); + sol.add(bottomRight); + } + } else { + //from the bottom to the top + double distleft = interBot.distance(bottomLeft); + double distright = interBot.distance(bottomRight); + if(distleft < distright){ + //pass left + sol.add(bottomLeft); + sol.add(topLeft); + } else { + //pass right + sol.add(bottomRight); + sol.add(topRight); + } + } + } else {//only bottom or only top + inbounds=true; + } /* ENDIF */ + + //breakpoint <-- collision detected + + if(sol.size()>0) {//solution found + assert(!inbounds); + return sol; + } else { //no solution found=> inbounds + assert(inbounds); + assert(sol.size()==0); + //handle collision or just skip it and search for the next collisionj + ibr=r; + //jump out of the loop to able to interate over the obstacles + break; + } + }/* end foreach obstacle */ + + if(inbounds || ibr != null){ + assert(inbounds); + assert(ibr!=null); + } + return null;//no collison found + }/* end optimizeLine */ + + + + //check intersection between line p0->p1 for a given set of obstacles + private static boolean intersects(List obstacles, Point p0, Point p1) { + for(Rectangle r : obstacles){ + if(r.intersectsLine(p0.x, p0.y, p1.x, p1.y)) + return true; + } + return false; + } + + + private boolean findIntersectionPoint( + Point p0, Point p1, Point p2, Point p3, Point pI) { + float q = (p0.y - p2.y)*(p3.x - p2.x) - (p0.x - p2.x)*(p3.y - p2.y); + float d = (p1.x - p0.x)*(p3.y - p2.y) - (p1.y - p0.y)*(p3.x - p2.x); + + //parallel ? + if(d==0) return false; + + float r = q / d; + q = (p0.y - p2.y)*(p1.x - p0.x) - (p0.x - p2.x)*(p1.y - p0.y); + + float s = q / d; + if(r<0 || r>1 || s<0 || s>1) return false; + + pI.x = p0.x + (int) (0.5f + r * (p1.x - p0.x)); + pI.y = p0.y + (int) (0.5f + r * (p1.y - p0.y)); + return true; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/visual/SplineConnectionWidget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/visual/SplineConnectionWidget.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,541 @@ +package at.ssw.visualizer.cfg.visual; + +import org.netbeans.api.visual.widget.ConnectionWidget; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Shape; +import java.awt.geom.AffineTransform; +import java.awt.geom.CubicCurve2D; +import java.awt.geom.GeneralPath; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; +import java.util.List; +import org.netbeans.api.visual.anchor.AnchorShape; +import org.netbeans.api.visual.graph.GraphScene; +import org.netbeans.api.visual.widget.Scene; +import org.netbeans.api.visual.widget.Widget; + + +/** + * In comparison to the default ConnectionWidget this class is able to connect + * widgets with a curve instead of a straight line sequence. + * In conjunction with a suitable router the connection will be a straight line + * or a curve depending on the amount and the position of the controlpoints. + * Controlpoints supplied by the router, are treated as curve intersection points. + * For Reflexive edges the router doesn`t necessarily need to supply + * any controlpoints, they get painted by this automatically, this can be + * excepted if the router supplys more as 2 control points for a self edge, + * then the edge gets painted with the default curve interpolation algorithm. + * The method used for drawing curves uses a piecewise cubic interpolation + * algorithm. Between two control points a curve is painted as cubic bezier + * curve the, inner bezier points are calculated automatically with FMILL + * tangents and a chord parametrization, this interpolant is also known as + * cutmull-rom spline. The resulting spline fullfills c^1 continuity. + * The the end points the interpolation algorithm uses the bessel end condition. + */ + +public class SplineConnectionWidget extends ConnectionWidget { + private static final double ENDPOINT_DEVIATION = 3;//curve endpoint approximation accuracy + private static final double HIT_DISTANCE_SQUARE = 4.0;//distance for intersection test + private GraphScene scene=null; + private Point2D [] bezierPoints = null; + + public SplineConnectionWidget(Scene scene) { + super(scene); + if(scene instanceof GraphScene) + this.scene=(GraphScene) scene; + } + + //check for self - edge + private boolean isReflexive(){ + return getSourceAnchor().getRelatedWidget() == getTargetAnchor().getRelatedWidget(); + } + + + @Override + protected Rectangle calculateClientArea() { + + Rectangle bounds = null; + + if(this.getControlPoints().size()>2){ + bezierPoints = createBezierPoints(getControlPoints()); + } + //minmax method - returns the smallest bounding rectangle + //Curves and surfaces for CAGD (3rd ed.), p.54 + //exact calculation of the bounding min rect + if(bezierPoints != null) { + Rectangle2D bounds2D = null; + for (int i = 0; i < bezierPoints.length; i++) { + Point2D point = bezierPoints[i]; + if(bounds2D==null) + bounds2D = new Rectangle2D.Double(point.getX(),point.getY(),0,0); + else + bounds2D.add(point); + } + bounds = bounds2D.getBounds(); + bounds.grow(2, 2); + + } else if (getControlPoints().size()>0){ + for(Point p : this.getControlPoints()){ + if(bounds==null) + bounds = new Rectangle(p); + else + bounds.add(p); + } + bounds.grow(5,5); + + } else if (isReflexive()) { + Widget related = this.getTargetAnchor().getRelatedWidget(); + bounds = related.convertLocalToScene(related.getBounds()); + bounds.grow(10, 10); + } + + if(bounds==null) + bounds = super.calculateClientArea(); + + return bounds; + } + + + /** + * if the edge is reflexive its painted as a cyclic self edge, if there + * are two controlpoints the connection is painted as a straight line from + * the source to the targetanchor, if there are more as 2 controlpoints the + * connection path between two control points is painted as cutmull rom + * spline with bessel end tangents. + */ + @Override + protected void paintWidget () { + List contrPoints = this.getControlPoints(); + int listSize = contrPoints.size(); + + Graphics2D gr = getGraphics (); + + if (listSize <= 2) { + this.bezierPoints=null;//set bezier Points null for calulateClientArea() + if(isReflexive()) { //special case for reflexive connection widgets + this.drawReflexive(gr); + } else { + super.paintWidget(); + } + return; + } + + //bezier curve... listSize > 2 + GeneralPath curvePath = new GeneralPath(); + double lastControlPointRotation = 0.0; + + + Point2D [] bezPoints = this.createBezierPoints(contrPoints); + curvePath.moveTo(bezPoints[0].getX(), bezPoints[0].getY());//b00 + + //last segment is added by subdivision thats why its -5 + for (int i = 1; i < bezPoints.length-5; i+=3) { + curvePath.curveTo( + bezPoints[i].getX(), bezPoints[i].getY(),//b1i + bezPoints[i+1].getX(), bezPoints[i+1].getY(),//b2i + bezPoints[i+2].getX(), bezPoints[i+2].getY());//b3i + + } + + GeneralPath lastseg = subdivide2D( + bezPoints[bezPoints.length-4], + bezPoints[bezPoints.length-3], + bezPoints[bezPoints.length-2], + bezPoints[bezPoints.length-1]); + + + if(lastseg != null) + curvePath.append(lastseg, true); + + Point2D cur = curvePath.getCurrentPoint(); + Point lastControlPoint = contrPoints.get(listSize-1); + + lastControlPointRotation = //anchor anchorAngle + Math.atan2 (cur.getY() - lastControlPoint.y, cur.getX() - lastControlPoint.x); + + gr.setStroke(getStroke()); + gr.setColor(getLineColor()); + gr.draw(curvePath); + + + AffineTransform previousTransform = gr.getTransform (); + gr.translate (lastControlPoint.x, lastControlPoint.y); + gr.rotate (lastControlPointRotation); + AnchorShape targetAnchorShape = this.getTargetAnchorShape(); + targetAnchorShape.paint (gr, false); + gr.setTransform (previousTransform); + + //paint ControlPoints if enabled + if (isPaintControlPoints()) { + int last = listSize - 1; + for (int index = 0; index <= last; index ++) { + Point point = contrPoints.get (index); + previousTransform = gr.getTransform (); + gr.translate (point.x, point.y); + if (index == 0 || index == last) + getEndPointShape().paint (gr); + else + getControlPointShape().paint (gr); + gr.setTransform (previousTransform); + } + + } + } + + private void drawReflexive(Graphics2D gr){ + Widget related = this.getTargetAnchor().getRelatedWidget(); + int position = this.edgeBalance(related); + Rectangle bounds = related.convertLocalToScene(related.getBounds()); + gr.setColor (getLineColor()); + Point first = new Point(); + Point last = new Point(); + double centerX = bounds.getCenterX(); + first.x = (int) (centerX + bounds.width / 4); + first.y = bounds.y + bounds.height; + last.x = first.x; + last.y = bounds.y; + + gr.setStroke(this.getStroke()); + + double cutDistance = this.getTargetAnchorShape().getCutDistance(); + double anchorAngle = Math.PI/-3.0; + double cutX = Math.abs(Math.cos(anchorAngle)*cutDistance); + double cutY = Math.abs(Math.sin(anchorAngle)*cutDistance); + int ydiff=first.y-last.y; + int endy = -ydiff; + double height=bounds.getHeight(); + double cy = height/4.0; + double cx=bounds.getWidth()/5.0; + double dcx = cx*2; + GeneralPath gp = new GeneralPath(); + gp.moveTo(0, 0); + gp.quadTo(0, cy, cx, cy); + gp.quadTo(dcx, cy, dcx, -height/2.0); + gp.quadTo(dcx, endy - cy, cy, -(cy+ydiff)); + gp.quadTo(cutX*1.5, endy - cy, cutX, endy-cutY); + + AffineTransform af = new AffineTransform(); + AnchorShape anchorShape = this.getTargetAnchorShape(); + + if(position < 0) { + first.x = (int) (centerX - bounds.width / 4); + af.translate(first.x, first.y); + af.scale(-1.0, 1.0); + last.x = first.x; + } else { + af.translate(first.x, first.y); + } + Shape s = gp.createTransformedShape(af); + gr.draw(s); + + if (last != null) { + AffineTransform previousTransform = gr.getTransform (); + gr.translate (last.x, last.y); + + if(position < 0) + gr.rotate(Math.PI - anchorAngle); + else + gr.rotate (anchorAngle); + + anchorShape.paint (gr, false); + gr.setTransform (previousTransform); + } + } + + //returns prefered location for an edge -1 for left and 1 for right + private int edgeBalance(Widget nodeWidget) { + if(scene == null) + return 1; + + Point nodeLocation = nodeWidget.getLocation(); + int left = 0, right = 0; + + Object node = scene.findObject(nodeWidget); + + for(Object e : scene.findNodeEdges(node, true, true)) {//inputedges + ConnectionWidget cw = (ConnectionWidget) scene.findWidget(e); + + if(cw != this) { + Widget targetNodeWidget = cw.getTargetAnchor().getRelatedWidget(); + + Point location; + if(targetNodeWidget == nodeWidget) { + Widget sourceNodeWidget = cw.getSourceAnchor().getRelatedWidget(); + location = sourceNodeWidget.getLocation(); + } else { + location = targetNodeWidget.getLocation(); + } + + if(location.x < nodeLocation.x) + left++; + else + right++; + } + } + if(left < right) + return -1; + else + return 1; + } + + + private Point2D[] createBezierPoints(List list){ + if(list.size()<3) return null ; + + + int lastIdx = list.size()-1; + + + //chord length parametrization + double[] uis = new double[list.size()]; + uis[0]=0; + uis[1] = list.get(1).distance(list.get(0)); + for (int i = 1; i < uis.length; i++) { + Point cur = list.get(i); + Point prev = list.get(i-1); + uis[i]=uis[i-1]+ cur.distance(prev); + } + + + for (int i = 1; i < uis.length; i++) { + uis[i] /= uis[lastIdx]; + + } + double[] delta = new double[uis.length-1]; + for (int i = 0; i < delta.length; i++) { + double ui = uis[i]; + double uin = uis[i+1]; + delta[i] = uin-ui; + } + + + //FMILL tangent directions (chord length) + Point2D[] tangents = new Point2D[list.size()]; + + for (int i = 1; i < list.size()-1; i++) { + Point xBefore = list.get(i-1); + Point xAfter = list.get(i+1); + Point2D.Double tangent = new Point2D.Double (xAfter.x - xBefore.x, xAfter.y - xBefore.y); + tangents[i] = tangent; + } + + + Point2D [] bezPoints = new Point2D[(list.size()-1)*2+list.size()]; + //Catmull-Rom + for (int i = 1; i < list.size()-1; i++) { + Point b3i = list.get(i); + Point2D b3ib = b3iBefore(b3i, delta[i-1], delta[i], tangents[i]); + Point2D b3ia = b3iAfter(b3i, delta[i-1], delta[i], tangents[i]); + bezPoints[3*i] = b3i; + bezPoints[3*i-1] = b3ib; + bezPoints[3*i+1] = b3ia; + } + bezPoints[0] = list.get(0); + bezPoints[bezPoints.length-1] = list.get(list.size()-1); + + Point p0 = list.get(0); + Point p1 = list.get(1); + Point p2 = list.get(2); + Point pL_2 = list.get(lastIdx-2); + Point pL_1 = list.get(lastIdx-1); + Point pL = list.get(lastIdx); + + Point2D m1 = besselTangent(delta[0], delta[1], p0, p1, p2); + Point2D m0 = besselEndTangent(p0, p1, delta[0], m1); + + Point2D mLb = besselTangent(delta[delta.length-2], delta[delta.length-1], + pL_2,pL_1, pL); + Point2D mL = besselEndTangent(pL_1, pL, delta[delta.length-1], mLb); + + Point2D scaleM0 = scale(normalize(m0), p0.distance(p1));//increase distx/distxl to make curve rounder at the end + Point2D scaleML = scale(normalize(mL), pL.distance(pL_1)); + //Catmull-Rom for bessel points + Point2D b30a = b3iAfter(p0, delta[0], delta[0],scaleM0); + Point2D b33b = b3iBefore(pL, delta[delta.length-1], delta[delta.length-1],scaleML); + + bezPoints[1] = b30a; + bezPoints[bezPoints.length-2] = b33b; + + return bezPoints; + } + + + + private static Point2D besselTangent(double delta_ib, double delta_i, Point2D p0, Point2D p1 , Point2D p2){ + double alpha_i = delta_ib/(delta_ib+delta_i); + + double x = (1-alpha_i)/delta_ib * (p1.getX() - p0.getX()) + + alpha_i/delta_i * (p2.getX()-p1.getX()); + double y = (1-alpha_i)/delta_ib * (p1.getY() - p0.getY()) + + alpha_i/delta_i * (p2.getY()-p1.getY()); + + return new Point2D.Double(x,y); + } + + private static Point2D besselEndTangent(Point2D p0, Point2D p1, double delta_u, Point2D m){ + double x = 2*((p1.getX()-p0.getX())/delta_u) - m.getX(); + double y = 2*((p1.getY()-p0.getY())/delta_u) - m.getY(); + return new Point2D.Double(x,y); + } + + private static Point2D b3iBefore(Point2D b3i, double delta_ib, double delta_i, Point2D li){ + double x = b3i.getX() - (delta_ib/(3*(delta_ib+delta_i)))*li.getX(); + double y = b3i.getY() - (delta_ib/(3*(delta_ib+delta_i)))*li.getY(); + return new Point.Double(x,y); + } + + private static Point2D b3iAfter(Point2D b3i, double delta_ib,double delta_i,Point2D li){ + double x = b3i.getX() + (delta_i/(3*(delta_ib+delta_i)))*li.getX(); + double y = b3i.getY() + (delta_i/(3*(delta_ib+delta_i)))*li.getY(); + return new Point.Double(x,y); + } + + + + + //returns length of vector v + private static double norm(Point2D v){ + return Math.sqrt(v.getX()*v.getX()+v.getY()*v.getY()); + } + + //returns unity vector of vector v + private static Point2D normalize(Point2D v){ + double norm = norm(v); + if(norm==0) return new Point2D.Double(v.getX(), v.getY()); + return new Point2D.Double(v.getX()/norm , v.getY()/norm); + } + + //scale vector to size of length + private static Point2D scale(Point2D v, double length){ + Point2D tmp = normalize(v); + return new Point2D.Double(tmp.getX()*length, tmp.getY()*length); + } + + + + private GeneralPath subdivide2D (Point2D b0, Point2D b1, Point2D b2, Point2D b3) { + //set 2nd intermediate point to endpoint + //we could actually use another "better" point if we like to have a smoother curve + + double cutDistance = getTargetAnchorShape().getCutDistance(); + double minDistance = cutDistance - ENDPOINT_DEVIATION; + /** + * if the cutDistance is valid the last segment of the curve + * gets reduced by subdivision until the distance of the endpoint(epDistance) + * satisfys the condition (cutDistance > epDistance > (cutDistance - ENDPOINT-DEVIATION) + */ + if(cutDistance > minDistance && minDistance > 0 ) { + GeneralPath path = new GeneralPath(); + + path.moveTo(b0.getX(), b0.getY()); + + CubicCurve2D.Double curve = new CubicCurve2D.Double( + b0.getX(), b0.getY(), + b1.getX(), b1.getY(), + b2.getX(), b2.getY(), + b3.getX(), b3.getY()); + + + + CubicCurve2D right=new CubicCurve2D.Double(); + CubicCurve2D left=new CubicCurve2D.Double(); + curve.subdivide(left, right); + double distance = b3.distance(left.getP2()); + //if the distance is bigger as the cutDistance the left segment is added + //and the right segment is divided again + while(distance>cutDistance){ + path.append(left, true); + right.subdivide(left, right); + distance = b3.distance(left.getP2()); + //if the devision removed to much the left segment is divided + while(distance < minDistance) { + //changes the distance to ~ (distance+distance/2) + left.subdivide(left, right); + distance = b3.distance(left.getP2()); + } + } + //append the last segment with (minDistance < distance < cutDistance) + path.append(left, true); + return path; + } + return null; + } + + + /** + * Returns whether a specified local point pL is a part of the connection + * widget. + * First it make a rough bounds check + * for Line Segments => use Super call (ConnectionWidget.isHitAt(pL)). + * for self-edges => its sufficent to return getBounds.contains(pL). + * for Splines => Interate over all Partitial segments of the curve and make + * a minmax check with the bezier points. If pL is inside the minmax + * rectangle of one segment the curve is constructed and subdivided until + * the distance d between center point pC (of the bounding rectangle) + * and pL is below HIT_DISTANCE_SQUARE, in this case it returns true. + * If no no minmax check was successful or the subdivision lead to an + * rectangle witch doesn`t contain pL return false. + * @param localLocation the local location + * @return true, if the location is a part of the connection widget + */ + @Override + public boolean isHitAt(Point localLocation) { + if(!isVisible() || !getBounds ().contains (localLocation)) + return false; + + List controlPoints = getControlPoints (); + if(controlPoints.size() <=2){ + if(isReflexive()) return true; + return super.isHitAt(localLocation); + } + + if(bezierPoints != null) { + for (int i = 0; i < bezierPoints.length-1; i+=3) { + Point2D b0 = bezierPoints[i]; + Point2D b1 = bezierPoints[i+1]; + Point2D b2 = bezierPoints[i+2]; + Point2D b3 = bezierPoints[i+3]; + + CubicCurve2D left = new CubicCurve2D.Double( + b0.getX(), b0.getY(), + b1.getX(), b1.getY(), + b2.getX(), b2.getY(), + b3.getX(), b3.getY()); + + + Rectangle2D bounds = left.getBounds2D(); + while(bounds.contains(localLocation)) { + //calculate the center and use HIT_DISTANCE_SQUARE for a range check + Point2D test = new Point2D.Double(bounds.getCenterX(),bounds.getCenterY()); + if(test.distance(localLocation) < HIT_DISTANCE_SQUARE){ + return true; + } + + + CubicCurve2D right = new CubicCurve2D.Double(); + left.subdivide(left, right); + Rectangle2D lb2d = left.getBounds2D(); + Rectangle2D rb2d = right.getBounds2D(); + if( lb2d.contains(localLocation)){ + bounds = lb2d; + } else if (rb2d.contains(localLocation)) { + left = right; + bounds = rb2d; + } else { + return false; + } + + }//end while + }//end for + } + return false; + } + + +} + + + + diff -r 6cb549627941 -r 015fb895586b visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/visual/WidgetCollisionCollector.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/ControlFlowEditor/src/at/ssw/visualizer/cfg/visual/WidgetCollisionCollector.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,12 @@ +package at.ssw.visualizer.cfg.visual; + +import java.util.List; +import org.netbeans.api.visual.widget.Widget; + + +public interface WidgetCollisionCollector { + + //returns a list of widgets which should be handled as obstacles + void collectCollisions(List collisions); + +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/manifest.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/manifest.mf Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +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 + diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/at/ssw/visualizer/model/bc/Bytecodes.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/at/ssw/visualizer/model/bc/Bytecodes.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,33 @@ +package at.ssw.visualizer.model.bc; + +import at.ssw.visualizer.model.cfg.ControlFlowGraph; + +/** + * This class holds the bytecode of a method and provides severel methods + * accessing the details. + * + * @author Alexander Reder + * @author Christian Wimmer + */ +public interface Bytecodes { + /** + * Back-link to the control flow graph where the bytecodes were loaded from. + */ + public ControlFlowGraph getControlFlowGraph(); + + /** + * Called before the first call of getBytecodes() or getEpilogue(). Can be called multiple times. + */ + public void parseBytecodes(); + + /** + * The bytecodes of the method in the given bytecode range. + * + * @param fromBCI starting BCI (including this bci) + * @param toBCI ending BCI (not including this bci) + * @return string representation of the bytecodes + */ + public String getBytecodes(int fromBCI, int toBCI); + + public String getEpilogue(); +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/at/ssw/visualizer/model/cfg/BasicBlock.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/at/ssw/visualizer/model/cfg/BasicBlock.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,41 @@ +package at.ssw.visualizer.model.cfg; + +import java.util.List; + +/** + * + * @author Christian Wimmer + */ +public interface BasicBlock { + public String getName(); + + public int getFromBci(); + + public int getToBci(); + + public List getPredecessors(); + + public List getSuccessors(); + + public List getXhandlers(); + + public List getFlags(); + + public BasicBlock getDominator(); + + public int getLoopIndex(); + + public int getLoopDepth(); + + public boolean hasState(); + + public List getStates(); + + public boolean hasHir(); + + public List getHirInstructions(); + + public boolean hasLir(); + + public List getLirOperations(); +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/at/ssw/visualizer/model/cfg/ControlFlowGraph.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/at/ssw/visualizer/model/cfg/ControlFlowGraph.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,26 @@ +package at.ssw.visualizer.model.cfg; + +import at.ssw.visualizer.model.bc.Bytecodes; +import at.ssw.visualizer.model.nc.NativeMethod; +import com.sun.hotspot.igv.data.FolderElement; +import java.util.List; + +/** + * + * @author Christian Wimmer + */ +public interface ControlFlowGraph extends FolderElement { + public List getBasicBlocks(); + + public BasicBlock getBasicBlockByName(String name); + + public Bytecodes getBytecodes(); + + public NativeMethod getNativeMethod(); + + public boolean hasState(); + + public boolean hasHir(); + + public boolean hasLir(); +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/at/ssw/visualizer/model/cfg/IRInstruction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/at/ssw/visualizer/model/cfg/IRInstruction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,19 @@ +package at.ssw.visualizer.model.cfg; + +import java.util.Collection; + +/** + * + * @author Christian Wimmer + */ +public interface IRInstruction { + public static String HIR_NAME = "tid"; + public static String HIR_TEXT = "instruction"; + public static String HIR_OPERAND = "result"; + + public static String LIR_NUMBER = "nr"; + public static String LIR_TEXT = "instruction"; + + public Collection getNames(); + public String getValue(String name); +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/at/ssw/visualizer/model/cfg/State.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/at/ssw/visualizer/model/cfg/State.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,17 @@ +package at.ssw.visualizer.model.cfg; + +import java.util.List; + +/** + * + * @author Christian Wimmer + */ +public interface State { + public String getKind(); + + public int getSize(); + + public String getMethod(); + + public List getEntries(); +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/at/ssw/visualizer/model/cfg/StateEntry.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/at/ssw/visualizer/model/cfg/StateEntry.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,19 @@ +package at.ssw.visualizer.model.cfg; + +import java.util.List; + +/** + * + * @author Christian Wimmer + */ +public interface StateEntry { + public int getIndex(); + + public String getName(); + + public boolean hasPhiOperands(); + + public List getPhiOperands(); + + public String getOperand(); +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/at/ssw/visualizer/model/interval/ChildInterval.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/at/ssw/visualizer/model/interval/ChildInterval.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,29 @@ +package at.ssw.visualizer.model.interval; + +import java.util.List; + +/** + * + * @author Christian Wimmer + */ +public interface ChildInterval { + public Interval getParent(); + + public String getRegNum(); + + public String getType(); + + public String getOperand(); + + public String getSpillState(); + + public ChildInterval getRegisterHint(); + + public List getRanges(); + + public List getUsePositions(); + + public int getFrom(); + + public int getTo(); +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/at/ssw/visualizer/model/interval/Interval.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/at/ssw/visualizer/model/interval/Interval.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,19 @@ +package at.ssw.visualizer.model.interval; + +import java.util.List; + +/** + * + * @author Christian Wimmer + */ +public interface Interval { + public IntervalList getParent(); + + public List getChildren(); + + public String getRegNum(); + + public int getFrom(); + + public int getTo(); +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/at/ssw/visualizer/model/interval/IntervalList.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/at/ssw/visualizer/model/interval/IntervalList.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,16 @@ +package at.ssw.visualizer.model.interval; + +import at.ssw.visualizer.model.cfg.ControlFlowGraph; +import java.util.List; + +/** + * + * @author Christian Wimmer + */ +public interface IntervalList { + public List getIntervals(); + + public ControlFlowGraph getControlFlowGraph(); + + public int getNumLIROperations(); +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/at/ssw/visualizer/model/interval/Range.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/at/ssw/visualizer/model/interval/Range.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,11 @@ +package at.ssw.visualizer.model.interval; + +/** + * + * @author Christian Wimmer + */ +public interface Range { + public int getFrom(); + + public int getTo(); +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/at/ssw/visualizer/model/interval/UsePosition.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/at/ssw/visualizer/model/interval/UsePosition.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,11 @@ +package at.ssw.visualizer.model.interval; + +/** + * + * @author Christian Wimmer + */ +public interface UsePosition { + public char getKind(); + + public int getPosition(); +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/at/ssw/visualizer/model/nc/NativeMethod.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/at/ssw/visualizer/model/nc/NativeMethod.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,15 @@ +package at.ssw.visualizer.model.nc; + +import at.ssw.visualizer.model.cfg.ControlFlowGraph; + +/** + * + * @author Alexander Reder + */ +public interface NativeMethod { + + public ControlFlowGraph getControlFlowGraph(); + + public String getMethodText(); + +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/at/ssw/visualizer/modelimpl/bc/BytecodesImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/at/ssw/visualizer/modelimpl/bc/BytecodesImpl.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,166 @@ +package at.ssw.visualizer.modelimpl.bc; + +import at.ssw.visualizer.model.bc.Bytecodes; +import at.ssw.visualizer.model.cfg.BasicBlock; +import at.ssw.visualizer.model.cfg.ControlFlowGraph; +import at.ssw.visualizer.modelimpl.cfg.BasicBlockImpl; +import java.util.Arrays; + +/** + * This class holds the bytecode of a method and provides severel methods + * accessing the details. + * + * @author Christian Wimmer + */ +public class BytecodesImpl implements Bytecodes { + private ControlFlowGraph controlFlowGraph; + private String bytecodeString; + + private String[] bytecodes; + private String epilogue; + + + public BytecodesImpl(ControlFlowGraph controlFlowGraph, String bytecodeString) { + this.controlFlowGraph = controlFlowGraph; + this.bytecodeString = bytecodeString; + } + + public void parseBytecodes() { + String[] lines = bytecodeString.split("\n"); + + boolean inPrologue = true; + String[] result = new String[lines.length * 3]; + int lastBci = -1; + int lnr = 0; + for (; lnr < lines.length; lnr++) { + String line = lines[lnr]; + + line = line.trim(); + if (line.startsWith("[")) { + int end = line.indexOf(']'); + if (end != -1) { + line = line.substring(end + 1, line.length()); + } + } + + line = line.trim(); + int space1 = line.indexOf(' '); + if (space1 <= 0) { + if (inPrologue) { + continue; + } else { + break; + } + } + String bciStr = line.substring(0, space1); + if (bciStr.endsWith(":")) { + bciStr = bciStr.substring(0, bciStr.length() - 1); + } + + int bci; + try { + bci = Integer.parseInt(bciStr); + } catch (NumberFormatException ex) { + // Ignore invalid lines. + if (inPrologue) { + continue; + } else { + break; + } + } + + String opcode = line.substring(space1 + 1); + String params = ""; + int space2 = opcode.indexOf(' '); + if (space2 > 0) { + params = opcode.substring(space2 + 1).trim(); + opcode = opcode.substring(0, space2); + } + String tail = ""; + int space3 = params.indexOf('|'); + if (space3 >= 0) { + tail = params.substring(space3); + params = params.substring(0, space3); + } + +// if (!"ldc".equals(opcode) || !params.startsWith("\"")) { +// // Separate packages with "." instead of "/" +// params = params.replace('/', '.'); +// } + + String printLine = bciStr + ":" + " ".substring(Math.min(bciStr.length(), 3)) + + opcode + " ".substring(Math.min(opcode.length(), 13)) + + params + " ".substring(Math.min(params.length(), 8)) + + tail; + + + if (bci >= result.length) { + result = Arrays.copyOf(result, Math.max(bci + 1, result.length * 2)); + } + result[bci] = printLine; + inPrologue = false; + lastBci = Math.max(lastBci, bci); + } + + StringBuilder epilogueBuilder = new StringBuilder(); + for (; lnr < lines.length; lnr++) { + epilogueBuilder.append(lines[lnr]).append("\n"); + } + epilogue = epilogueBuilder.toString(); + bytecodes = Arrays.copyOf(result, lastBci + 1); + + + BasicBlockImpl[] blocks = new BasicBlockImpl[bytecodes.length]; + for (BasicBlock b : controlFlowGraph.getBasicBlocks()) { + if (b instanceof BasicBlockImpl) { + BasicBlockImpl block = (BasicBlockImpl) b; + if (block.getToBci() != -1) { + // Do not override existing values. + return; + } + if (block.getFromBci() >= 0 && block.getFromBci() < blocks.length) { + blocks[block.getFromBci()] = block; + } + } + } + + int curToBci = -1; + for (int i = blocks.length - 1; i >= 0; i--) { + if (bytecodes[i] != null && curToBci == -1) { + curToBci = i; + } + if (blocks[i] != null) { + blocks[i].setToBci(curToBci); + curToBci = -1; + } + } + } + + public ControlFlowGraph getControlFlowGraph() { + return controlFlowGraph; + } + + public String getBytecodes(int fromBCI, int toBCI) { + if (fromBCI < 0) { + return ""; + } + toBCI = Math.min(toBCI, bytecodes.length); + StringBuilder sb = new StringBuilder(); + for (int i = fromBCI; i < toBCI; i++) { + if (bytecodes[i] != null) { + sb.append(bytecodes[i]).append("\n"); + } + } + return sb.toString(); + } + + @Override + public String getEpilogue() { + return epilogue; + } + + @Override + public String toString() { + return "Bytecodes " + getControlFlowGraph().getName(); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/at/ssw/visualizer/modelimpl/cfg/BasicBlockImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/at/ssw/visualizer/modelimpl/cfg/BasicBlockImpl.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,143 @@ +package at.ssw.visualizer.modelimpl.cfg; + +import at.ssw.visualizer.model.cfg.BasicBlock; +import at.ssw.visualizer.model.cfg.ControlFlowGraph; +import at.ssw.visualizer.model.cfg.IRInstruction; +import at.ssw.visualizer.model.cfg.State; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * + * @author Christian Wimmer + */ +public class BasicBlockImpl implements BasicBlock { + + private ControlFlowGraph parent; + private String name; + private int fromBci; + private int toBci; + private BasicBlock[] predecessors; + private BasicBlock[] successors; + private BasicBlock[] xhandlers; + private String[] flags; + private BasicBlock dominator; + private int loopIndex; + private int loopDepth; + private int firstLirId; + private int lastLirId; + private State[] states; + private IRInstruction[] hirInstructions; + private IRInstruction[] lirOperations; + + public void setValues(String name, int fromBci, int toBci, BasicBlock[] predecessors, BasicBlock[] successors, BasicBlock[] xhandlers, String[] flags, BasicBlock dominator, int loopIndex, int loopDepth, int firstLirId, int lastLirId, State[] states, IRInstruction[] hirInstructions, IRInstruction[] lirOperations) { + this.name = name; + this.fromBci = fromBci; + this.toBci = toBci; + + this.predecessors = predecessors; + this.successors = successors; + this.xhandlers = xhandlers; + + this.flags = flags; + this.dominator = dominator; + this.loopIndex = loopIndex; + this.loopDepth = loopDepth; + this.firstLirId = firstLirId; + this.lastLirId = lastLirId; + + this.states = states; + this.hirInstructions = hirInstructions; + this.lirOperations = lirOperations; + } + + public ControlFlowGraph getParent() { + return parent; + } + + protected void setParent(ControlFlowGraph parent) { + this.parent = parent; + } + + public String getName() { + return name; + } + + public int getFromBci() { + return fromBci; + } + + public int getToBci() { + return toBci; + } + + public void setToBci(int toBci) { + this.toBci = toBci; + } + + public List getPredecessors() { + return Collections.unmodifiableList(Arrays.asList(predecessors)); + } + + public List getSuccessors() { + return Collections.unmodifiableList(Arrays.asList(successors)); + } + + public List getXhandlers() { + return Collections.unmodifiableList(Arrays.asList(xhandlers)); + } + + public List getFlags() { + return Collections.unmodifiableList(Arrays.asList(flags)); + } + + public BasicBlock getDominator() { + return dominator; + } + + public int getLoopIndex() { + return loopIndex; + } + + public int getLoopDepth() { + return loopDepth; + } + + public int getFirstLirId() { + return firstLirId; + } + + public int getLastLirId() { + return lastLirId; + } + + public boolean hasState() { + return states != null; + } + + public List getStates() { + return Collections.unmodifiableList(Arrays.asList(states)); + } + + public boolean hasHir() { + return hirInstructions != null; + } + + public List getHirInstructions() { + return Collections.unmodifiableList(Arrays.asList(hirInstructions)); + } + + public boolean hasLir() { + return lirOperations != null; + } + + public List getLirOperations() { + return Collections.unmodifiableList(Arrays.asList(lirOperations)); + } + + @Override + public String toString() { + return name; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/at/ssw/visualizer/modelimpl/cfg/IRInstructionImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/at/ssw/visualizer/modelimpl/cfg/IRInstructionImpl.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,40 @@ +package at.ssw.visualizer.modelimpl.cfg; + +import at.ssw.visualizer.model.cfg.IRInstruction; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashMap; + +public class IRInstructionImpl implements IRInstruction { + private LinkedHashMap data; + + public IRInstructionImpl(LinkedHashMap data) { + this.data = data; + } + + public IRInstructionImpl(String pinned, int bci, int useCount, String name, String text, String operand) { + data = new LinkedHashMap(); + data.put("p", pinned); + data.put("bci", Integer.toString(bci)); + data.put("use", Integer.toString(useCount)); + data.put(HIR_NAME, name); + if (operand != null) { + data.put(HIR_OPERAND, operand); + } + data.put(HIR_TEXT, text); + } + + public IRInstructionImpl(int number, String text) { + data = new LinkedHashMap(); + data.put(LIR_NUMBER, Integer.toString(number)); + data.put(LIR_TEXT, text); + } + + public Collection getNames() { + return Collections.unmodifiableSet(data.keySet()); + } + + public String getValue(String name) { + return data.get(name); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/at/ssw/visualizer/modelimpl/cfg/StateEntryImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/at/ssw/visualizer/modelimpl/cfg/StateEntryImpl.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,44 @@ +package at.ssw.visualizer.modelimpl.cfg; + +import at.ssw.visualizer.model.cfg.StateEntry; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * + * @author Christian Wimmer + */ +public class StateEntryImpl implements StateEntry { + private int index; + private String name; + private String[] phiOperands; + private String operand; + + public StateEntryImpl(int index, String name, String[] phiOperands, String operand) { + this.index = index; + this.name = name; + this.phiOperands = phiOperands; + this.operand = operand; + } + + public int getIndex() { + return index; + } + + public String getName() { + return name; + } + + public boolean hasPhiOperands() { + return phiOperands != null; + } + + public List getPhiOperands() { + return Collections.unmodifiableList(Arrays.asList(phiOperands)); + } + + public String getOperand() { + return operand; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/at/ssw/visualizer/modelimpl/cfg/StateImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/at/ssw/visualizer/modelimpl/cfg/StateImpl.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,41 @@ +package at.ssw.visualizer.modelimpl.cfg; + +import at.ssw.visualizer.model.cfg.State; +import at.ssw.visualizer.model.cfg.StateEntry; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * + * @author Christian Wimmer + */ +public class StateImpl implements State { + private String kind; + private int size; + private String method; + private StateEntry[] entries; + + public StateImpl(String kind, int size, String method, StateEntryImpl[] entries) { + this.kind = kind; + this.size = size; + this.method = method; + this.entries = entries; + } + + public String getKind() { + return kind; + } + + public int getSize() { + return size; + } + + public String getMethod() { + return method; + } + + public List getEntries() { + return Collections.unmodifiableList(Arrays.asList(entries)); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/at/ssw/visualizer/modelimpl/interval/ChildIntervalImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/at/ssw/visualizer/modelimpl/interval/ChildIntervalImpl.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,118 @@ +package at.ssw.visualizer.modelimpl.interval; + +import at.ssw.visualizer.model.interval.ChildInterval; +import at.ssw.visualizer.model.interval.Interval; +import at.ssw.visualizer.model.interval.Range; +import at.ssw.visualizer.model.interval.UsePosition; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * + * @author Christian Wimmer + */ +public class ChildIntervalImpl implements ChildInterval, Comparable { + private Interval parent; + private String regNum; + private String type; + private String operand; + private String spillState; + private ChildInterval registerHint; + private Range[] ranges; + private UsePosition[] usePositions; + + public void setValues(String regNum, String type, String operand, String spillState, ChildInterval registerHint, Range[] ranges, UsePosition[] usePositions) { + this.regNum = regNum; + this.type = type; + this.operand = operand; + this.spillState = spillState; + this.registerHint = registerHint; + this.ranges = ranges; + this.usePositions = usePositions; + } + + public Interval getParent() { + return parent; + } + + protected void setParent(IntervalImpl parent) { + this.parent = parent; + } + + public String getRegNum() { + return regNum; + } + + public String getType() { + return type; + } + + public String getOperand() { + return operand; + } + + public String getSpillState() { + return spillState; + } + + public ChildInterval getRegisterHint() { + return registerHint; + } + + public List getRanges() { + return Collections.unmodifiableList(Arrays.asList(ranges)); + } + + public List getUsePositions() { + return Collections.unmodifiableList(Arrays.asList(usePositions)); + } + + + public int getFrom() { + return ranges[0].getFrom(); + } + + public int getTo() { + return ranges[ranges.length - 1].getTo(); + } + + + public int compareTo(ChildIntervalImpl other) { + return getFrom() - other.getFrom(); + } + + @Override + public String toString() { + StringBuilder result = new StringBuilder(); + result.append(regNum); + result.append(": "); + result.append(getType()); + result.append(", "); + result.append(getOperand()); + result.append(", "); + if (registerHint != null) { + result.append(registerHint.getRegNum()); + } else { + result.append("null"); + } + + result.append(" "); + for (int i = 0; i < ranges.length; i++) { + if (i > 0) { + result.append(", "); + } + result.append(ranges[i]); + } + + result.append(" "); + for (int i = 0; i < usePositions.length; i++) { + if (i > 0) { + result.append(", "); + } + result.append(usePositions[i]); + } + + return result.toString(); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/at/ssw/visualizer/modelimpl/interval/IntervalImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/at/ssw/visualizer/modelimpl/interval/IntervalImpl.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,60 @@ +package at.ssw.visualizer.modelimpl.interval; + +import at.ssw.visualizer.model.interval.ChildInterval; +import at.ssw.visualizer.model.interval.Interval; +import at.ssw.visualizer.model.interval.IntervalList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * + * @author Christian Wimmer + */ +public class IntervalImpl implements Interval { + private IntervalList parent; + private ChildInterval[] children; + + public IntervalImpl(ChildIntervalImpl[] children) { + this.children = children; + for (ChildIntervalImpl child : children) { + child.setParent(this); + } + } + + public IntervalList getParent() { + return parent; + } + + protected void setParent(IntervalListImpl parent) { + this.parent = parent; + } + + public List getChildren() { + return Collections.unmodifiableList(Arrays.asList(children)); + } + + public String getRegNum() { + return children[0].getRegNum(); + } + + public int getFrom() { + return children[0].getFrom(); + } + + public int getTo() { + return children[children.length - 1].getTo(); + } + + @Override + public String toString() { + StringBuilder result = new StringBuilder(); + for (int i = 0; i < children.length; i++) { + if (i > 0) { + result.append("\n "); + } + result.append(children[i]); + } + return result.toString(); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/at/ssw/visualizer/modelimpl/interval/IntervalListImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/at/ssw/visualizer/modelimpl/interval/IntervalListImpl.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,54 @@ +package at.ssw.visualizer.modelimpl.interval; + +import at.ssw.visualizer.model.cfg.BasicBlock; +import at.ssw.visualizer.model.cfg.ControlFlowGraph; +import at.ssw.visualizer.model.interval.Interval; +import at.ssw.visualizer.model.interval.IntervalList; +import com.sun.hotspot.igv.data.AbstractFolderElement; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * + * @author Christian Wimmer + */ +public class IntervalListImpl extends AbstractFolderElement implements IntervalList { + private Interval[] intervals; + private ControlFlowGraph controlFlowGraph; + private int numLIROperations; + + public IntervalListImpl(String shortName, String name, IntervalImpl[] intervals, ControlFlowGraph controlFlowGraph) { + super(shortName, name); + this.intervals = intervals; + this.controlFlowGraph = controlFlowGraph; + + for (IntervalImpl interval : intervals) { + interval.setParent(this); + numLIROperations = Math.max(numLIROperations, interval.getTo()); + } +// for (BasicBlock basicBlock : controlFlowGraph.getBasicBlocks()) { +// numLIROperations = Math.max(numLIROperations, basicBlock.getLastLirId() + 2); +// } + // TODO(tw): Add number of LIR operations to output. + } + + + public List getIntervals() { + return Collections.unmodifiableList(Arrays.asList(intervals)); + } + + public ControlFlowGraph getControlFlowGraph() { + return controlFlowGraph; + } + + public int getNumLIROperations() { + return numLIROperations; + } + + + @Override + public String toString() { + return " Intervals \"" + getName() + "\": " + intervals.length + " intervals\n"; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/at/ssw/visualizer/modelimpl/interval/RangeImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/at/ssw/visualizer/modelimpl/interval/RangeImpl.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,36 @@ +package at.ssw.visualizer.modelimpl.interval; + +import at.ssw.visualizer.model.interval.Range; + +/** + * + * @author Christian Wimmer + */ +public class RangeImpl implements Range, Comparable { + private int from; + private int to; + + public RangeImpl(int from, int to) { + this.from = from; + this.to = to; + } + + + public int getFrom() { + return from; + } + + public int getTo() { + return to; + } + + + public int compareTo(RangeImpl other) { + return getFrom() - other.getFrom(); + } + + @Override + public String toString() { + return "[" + from + ", " + to + "]"; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/at/ssw/visualizer/modelimpl/interval/UsePositionImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/at/ssw/visualizer/modelimpl/interval/UsePositionImpl.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,36 @@ +package at.ssw.visualizer.modelimpl.interval; + +import at.ssw.visualizer.model.interval.UsePosition; + +/** + * + * @author Christian Wimmer + */ +public class UsePositionImpl implements UsePosition, Comparable { + private int position; + private char kind; + + public UsePositionImpl(int position, char kind) { + this.position = position; + this.kind = kind; + } + + + public char getKind() { + return kind; + } + + public int getPosition() { + return position; + } + + + public int compareTo(UsePositionImpl other) { + return getPosition() - other.getPosition(); + } + + @Override + public String toString() { + return position + "(" + kind + ")"; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/at/ssw/visualizer/modelimpl/nc/NativeMethodImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/at/ssw/visualizer/modelimpl/nc/NativeMethodImpl.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,28 @@ +package at.ssw.visualizer.modelimpl.nc; + +import at.ssw.visualizer.model.cfg.ControlFlowGraph; +import at.ssw.visualizer.model.nc.NativeMethod; + +/** + * + * @author Alexander Reder + */ +public class NativeMethodImpl implements NativeMethod { + + private ControlFlowGraph controlFlowGraph; + private String methodText; + + public NativeMethodImpl(ControlFlowGraph controlFlowGraph, String methodText) { + this.controlFlowGraph = controlFlowGraph; + this.methodText = methodText; + } + + public ControlFlowGraph getControlFlowGraph() { + return controlFlowGraph; + } + + public String getMethodText() { + return methodText; + } + +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/com/sun/hotspot/igv/data/AbstractFolderElement.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/com/sun/hotspot/igv/data/AbstractFolderElement.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.sun.hotspot.igv.data; + +public class AbstractFolderElement implements FolderElement { + + private String name; + private String shortName; + private Folder parent; + + public AbstractFolderElement(String name, String shortName) { + this.name = name; + this.shortName = shortName; + } + + public String getShortName() { + return shortName; + } + + @Override + public String getName() { + return name; + } + + @Override + public Folder getParent() { + return parent; + } + + @Override + public void setParent(Folder parent) { + this.parent = parent; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/com/sun/hotspot/igv/data/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/com/sun/hotspot/igv/data/Bundle.properties Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,1 @@ +OpenIDE-Module-Name=Data diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/com/sun/hotspot/igv/data/ChangedEvent.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/com/sun/hotspot/igv/data/ChangedEvent.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,45 @@ +/* + * 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.data; + +public class ChangedEvent extends Event> { + + private T object; + + public ChangedEvent(T object) { + this.object = object; + } + + @Override + protected void fire(ChangedListener l) { + l.changed(object); + } + + public void changeObject(T newObject) { + if (object != newObject) { + this.object = newObject; + fire(); + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/com/sun/hotspot/igv/data/ChangedEventProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/com/sun/hotspot/igv/data/ChangedEventProvider.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,38 @@ +/* + * 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.data; + +/** + * Provides a changed event object. + * @author Thomas Wuerthinger + * @param Class for which the changed event fires. + */ +public interface ChangedEventProvider { + + /** + * Returns the changed event object. Should always return the same instance. + */ + ChangedEvent getChangedEvent(); +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/com/sun/hotspot/igv/data/ChangedListener.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/com/sun/hotspot/igv/data/ChangedListener.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,38 @@ +/* + * 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.data; + +/** + * Listens to changed events. + * @author Thomas Wuerthinger + * @param Class for which the changed event fires. + */ +public interface ChangedListener { + + /** + * This method is called everytime a changed event is fired. + * @param source Object that has changed. + */ + void changed(T source); +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/com/sun/hotspot/igv/data/ControllableChangedListener.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/com/sun/hotspot/igv/data/ControllableChangedListener.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,56 @@ +/* + * 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.data; + +/** + * + * @author Thomas Wuerthinger + */ +public abstract class ControllableChangedListener implements ChangedListener{ + + private boolean enabled; + + + public ControllableChangedListener() { + enabled = true; + } + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean b) { + enabled = b; + } + + @Override + public void changed(T source) { + if(enabled) { + filteredChanged(source); + } + } + + public abstract void filteredChanged(T source); +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/com/sun/hotspot/igv/data/Event.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/com/sun/hotspot/igv/data/Event.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,87 @@ +/* + * 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.data; + +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public abstract class Event { + + private List listener; + private boolean fireEvents; + private boolean eventWasFired; + + public Event() { + listener = new ArrayList<>(); + fireEvents = true; + } + + public void addListener(L l) { + listener.add(l); + } + + public void addListenerAndFire(L l) { + addListener(l); + fire(l); + } + + /** + * Remove listener + * @param l + */ + public void removeListener(final L l) { + listener.remove(l); + } + + public void fire() { + if(fireEvents) { + List tmpList = new ArrayList<>(listener); + for (L l : tmpList) { + fire(l); + } + } else { + eventWasFired = true; + } + } + + public void beginAtomic() { + assert fireEvents : "endAtomic has to be called before another beginAtomic may be called"; + this.fireEvents = false; + this.eventWasFired = false; + } + + public void endAtomic() { + assert !fireEvents : "beginAtomic has to be called first"; + this.fireEvents = true; + if(eventWasFired) { + fire(); + } + } + + protected abstract void fire(L l); +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/com/sun/hotspot/igv/data/Folder.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/com/sun/hotspot/igv/data/Folder.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,34 @@ +/* + * 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.data; + +import java.util.List; + +public interface Folder { + String getName(); + List getElements(); + void removeElement(FolderElement element); + void addElement(FolderElement group); + ChangedEvent getChangedEvent(); +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/com/sun/hotspot/igv/data/FolderElement.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/com/sun/hotspot/igv/data/FolderElement.java Tue Feb 07 22:41:09 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.sun.hotspot.igv.data; + +public interface FolderElement { + + Folder getParent(); + String getName(); + void setParent(Folder parent); +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/com/sun/hotspot/igv/data/GraphDocument.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/com/sun/hotspot/igv/data/GraphDocument.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,98 @@ +/* + * 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.data; + +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public class GraphDocument extends Properties.Entity implements ChangedEventProvider, Folder { + + private List elements; + private ChangedEvent changedEvent; + + public GraphDocument() { + elements = new ArrayList<>(); + changedEvent = new ChangedEvent<>(this); + } + + public void clear() { + elements.clear(); + getChangedEvent().fire(); + } + + @Override + public ChangedEvent getChangedEvent() { + return changedEvent; + } + + public void addGraphDocument(GraphDocument document) { + for (FolderElement e : document.elements) { + e.setParent(this); + this.addElement(e); + } + document.clear(); + getChangedEvent().fire(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + sb.append("GraphDocument: ").append(getProperties().toString()).append(" \n\n"); + for (FolderElement g : getElements()) { + sb.append(g.toString()); + sb.append("\n\n"); + } + + return sb.toString(); + } + + @Override + public List getElements() { + return elements; + } + + @Override + public void removeElement(FolderElement element) { + if (elements.remove(element)) { + getChangedEvent().fire(); + } + } + + @Override + public void addElement(FolderElement element) { + elements.add(element); + element.setParent(this); + getChangedEvent().fire(); + } + + @Override + public String getName() { + return "root"; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/com/sun/hotspot/igv/data/Group.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/com/sun/hotspot/igv/data/Group.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,180 @@ +/* + * 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.data; + +import java.util.*; + +/** + * + * @author Thomas Wuerthinger + */ +public class Group extends Properties.Entity implements ChangedEventProvider, Folder, FolderElement { + + private final List elements; + private final List graphs; + + private InputMethod method; + private transient ChangedEvent changedEvent; + private Folder parent; + + public Group(Folder parent) { + elements = new ArrayList<>(); + graphs = new ArrayList<>(); + changedEvent = new ChangedEvent<>(this); + this.parent = parent; + + // Ensure that name and type are never null + getProperties().setProperty("name", ""); + getProperties().setProperty("type", ""); + } + + public void fireChangedEvent() { + changedEvent.fire(); + } + + public void setMethod(InputMethod method) { + this.method = method; + } + + public InputMethod getMethod() { + return method; + } + + @Override + public ChangedEvent getChangedEvent() { + return changedEvent; + } + + @Override + public List getElements() { + return Collections.unmodifiableList(elements); + } + + public int getGraphsCount() { + return elements.size(); + } + + @Override + public void addElement(FolderElement element) { + elements.add(element); + if (element instanceof InputGraph) { + graphs.add((InputGraph) element); + } else { + + } + element.setParent(this); + changedEvent.fire(); + } + + public Set getAllNodes() { + Set result = new HashSet<>(); + for (FolderElement e : elements) { + if (e instanceof InputGraph) { + InputGraph g = (InputGraph) e; + result.addAll(g.getNodesAsSet()); + } + } + return result; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("Group ").append(getProperties()).append("\n"); + for (FolderElement g : elements) { + sb.append(g.toString()); + sb.append('\n'); + } + return sb.toString(); + } + + @Override + public String getName() { + return getProperties().get("name"); + } + + public String getType() { + return getProperties().get("type"); + + } + + InputGraph getPrev(InputGraph graph) { + InputGraph lastGraph = null; + for (FolderElement e : elements) { + if (e == graph) { + return lastGraph; + } + if (e instanceof InputGraph) { + lastGraph = (InputGraph) e; + } + } + return null; + } + + InputGraph getNext(InputGraph graph) { + boolean found = false; + for (FolderElement e : elements) { + if (e == graph) { + found = true; + } else if (found && e instanceof InputGraph) { + return (InputGraph) e; + } + } + return null; + } + + public InputGraph getLastGraph() { + InputGraph lastGraph = null; + for (FolderElement e : elements) { + if (e instanceof InputGraph) { + lastGraph = (InputGraph) e; + } + } + return lastGraph; + } + + @Override + public Folder getParent() { + return parent; + } + + @Override + public void removeElement(FolderElement element) { + if (elements.remove(element)) { + if (element instanceof InputGraph) { + graphs.remove((InputGraph) element); + } + changedEvent.fire(); + } + } + + public List getGraphs() { + return graphs; + } + + @Override + public void setParent(Folder parent) { + this.parent = parent; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/com/sun/hotspot/igv/data/InputBlock.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/com/sun/hotspot/igv/data/InputBlock.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,205 @@ +/* + * 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.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 implements BasicBlock { + + private List nodes; + private String name; + private InputGraph graph; + private List successors; + private List predecessors; + + @Override + public int hashCode() { + return name.hashCode(); + } + + @Override + public boolean equals(Object o) { + + if (o == this) { + return true; + } + + if (o == null || (!(o instanceof InputBlock))) { + return false; + } + + final InputBlock b = (InputBlock)o; + final boolean result = b.nodes.equals(nodes) && b.name.equals(name) && b.successors.size() == successors.size(); + if (!result) { + return false; + } + + final HashSet s = new HashSet<>(); + for (InputBlock succ : successors) { + s.add(succ.name); + } + + for (InputBlock succ : b.successors) { + if (!s.contains(succ.name)) { + return false; + } + } + + return true; + } + + InputBlock(InputGraph graph, String name) { + this.graph = graph; + this.name = name; + nodes = new ArrayList<>(); + successors = new ArrayList<>(); + predecessors = new ArrayList<>(); + } + + public String getName() { + return name; + } + + public List getNodes() { + return Collections.unmodifiableList(nodes); + } + + public void addNode(int id) { + InputNode n = graph.getNode(id); + assert n != null; + graph.setBlock(n, this); + final InputNode node = graph.getNode(id); + assert node != null; + assert !nodes.contains(node) : "duplicate : " + node; + nodes.add(node); + } + + @Override + public List getSuccessors() { + return Collections.unmodifiableList(successors); + } + + @Override + public String toString() { + return "Block " + this.getName(); + } + + void addSuccessor(InputBlock b) { + if (!successors.contains(b)) { + successors.add(b); + b.predecessors.add(this); + } + } + + @Override + public int getFromBci() { + // TODO(tw): Implement. + return -1; + } + + @Override + public int getToBci() { + // TODO(tw): Implement. + return -1; + } + + @Override + public List getPredecessors() { + return Collections.unmodifiableList(predecessors); + } + + @Override + public List getXhandlers() { + // TODO(tw): Implement. + return Collections.emptyList(); + } + + @Override + public List getFlags() { + // TODO(tw): Implement. + return Collections.emptyList(); + } + + @Override + public BasicBlock getDominator() { + // TODO(tw): Implement. + return null; + } + + @Override + public int getLoopIndex() { + // TODO(tw): Implement. + return -1; + } + + @Override + public int getLoopDepth() { + // TODO(tw): Implement. + return -1; + } + + @Override + public boolean hasState() { + // TODO(tw): Implement. + return false; + } + + @Override + public List getStates() { + // TODO(tw): Implement. + return Collections.emptyList(); + } + + @Override + public boolean hasHir() { + // TODO(tw): Implement. + return false; + } + + @Override + public List getHirInstructions() { + // TODO(tw): Implement. + return Collections.emptyList(); + } + + @Override + public boolean hasLir() { + // TODO(tw): Implement. + return false; + } + + @Override + public List getLirOperations() { + // TODO(tw): Implement. + return Collections.emptyList(); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/com/sun/hotspot/igv/data/InputBlockEdge.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/com/sun/hotspot/igv/data/InputBlockEdge.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,80 @@ +/* + * 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.data; + +/** + * + * @author Thomas Wuerthinger + */ +public class InputBlockEdge { + + public enum State { + SAME, + NEW, + DELETED + } + + private InputBlock from; + private InputBlock to; + private State state = State.SAME; + + public InputBlockEdge(InputBlock from, InputBlock to) { + assert from != null; + assert to != null; + this.from = from; + this.to = to; + } + + public InputBlock getFrom() { + return from; + } + + public InputBlock getTo() { + return to; + } + + public State getState() { + return state; + } + + public void setState(State state) { + this.state = state; + } + + @Override + public boolean equals(Object obj) { + if (obj != null && obj instanceof InputBlockEdge) { + InputBlockEdge e = (InputBlockEdge) obj; + return e.from.equals(from) && e.to.equals(to); + } + return false; + } + + @Override + public int hashCode() { + int hash = from.hashCode(); + hash = 59 * hash + to.hashCode(); + return hash; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/com/sun/hotspot/igv/data/InputBytecode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/com/sun/hotspot/igv/data/InputBytecode.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,56 @@ +/* + * 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.data; + +/** + * + * @author Thomas Wuerthinger + */ +public class InputBytecode { + + private int bci; + private String name; + private InputMethod inlined; + + public InputBytecode(int bci, String name) { + this.bci = bci; + this.name = name; + } + + public InputMethod getInlined() { + return inlined; + } + + public void setInlined(InputMethod inlined) { + this.inlined = inlined; + } + + public int getBci() { + return bci; + } + + public String getName() { + return name; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/com/sun/hotspot/igv/data/InputEdge.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/com/sun/hotspot/igv/data/InputEdge.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,138 @@ +/* + * 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.data; + +import java.util.Comparator; + +/** + * + * @author Thomas Wuerthinger + */ +public class InputEdge { + + public enum State { + + SAME, + NEW, + DELETED + } + + public static final Comparator OUTGOING_COMPARATOR = new Comparator(){ + + @Override + public int compare(InputEdge o1, InputEdge o2) { + if(o1.getFromIndex() == o2.getFromIndex()) { + return o1.getTo() - o2.getTo(); + } + return o1.getFromIndex() - o2.getFromIndex(); + } + }; + + + public static final Comparator INGOING_COMPARATOR = new Comparator(){ + + @Override + public int compare(InputEdge o1, InputEdge o2) { + if(o1.getToIndex() == o2.getToIndex()) { + return o1.getFrom() - o2.getFrom(); + } + return o1.getToIndex() - o2.getToIndex(); + } + }; + + private char toIndex; + private char fromIndex; + private int from; + private int to; + private State state; + private String label; + + public InputEdge(char toIndex, int from, int to) { + this((char) 0, toIndex, from, to, null); + } + + public InputEdge(char fromIndex, char toIndex, int from, int to) { + this(fromIndex, toIndex, from, to, null); + } + + public InputEdge(char fromIndex, char toIndex, int from, int to, String label) { + this.toIndex = toIndex; + this.fromIndex = fromIndex; + this.from = from; + this.to = to; + this.state = State.SAME; + this.label = label; + } + + public State getState() { + return state; + } + + public void setState(State x) { + this.state = x; + } + + public char getToIndex() { + return toIndex; + } + + public char getFromIndex() { + return fromIndex; + } + + public String getName() { + return "in" + toIndex; + } + + public int getFrom() { + return from; + } + + public int getTo() { + return to; + } + + public String getLabel() { + return label; + } + + @Override + public boolean equals(Object o) { + if (o == null || !(o instanceof InputEdge)) { + return false; + } + InputEdge conn2 = (InputEdge) o; + return conn2.fromIndex == fromIndex && conn2.toIndex == toIndex && conn2.from == from && conn2.to == to; + } + + @Override + public String toString() { + return "Edge from " + from + " to " + to + "(" + (int) fromIndex + ", " + (int) toIndex + ") "; + } + + @Override + public int hashCode() { + return (from << 20 | to << 8 | toIndex << 4 | fromIndex); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/com/sun/hotspot/igv/data/InputGraph.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/com/sun/hotspot/igv/data/InputGraph.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,340 @@ +/* + * 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.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, ControlFlowGraph { + + private Map nodes; + private Set edges; + private Folder parent; + private Group parentGroup; + private Map blocks; + private Set blockEdges; + private Map nodeToBlock; + + public InputGraph(String name) { + setName(name); + nodes = new LinkedHashMap<>(); + edges = new LinkedHashSet<>(); + blocks = new LinkedHashMap<>(); + blockEdges = new LinkedHashSet<>(); + nodeToBlock = new LinkedHashMap<>(); + } + + @Override + public void setParent(Folder parent) { + this.parent = parent; + if (parent instanceof Group) { + assert this.parentGroup == null; + this.parentGroup = (Group) parent; + } + } + + public InputBlockEdge addBlockEdge(InputBlock left, InputBlock right) { + InputBlockEdge edge = new InputBlockEdge(left, right); + blockEdges.add(edge); + left.addSuccessor(right); + return edge; + } + + public List findRootNodes() { + List result = new ArrayList<>(); + Set nonRoot = new HashSet<>(); + for(InputEdge curEdges : getEdges()) { + nonRoot.add(curEdges.getTo()); + } + + for(InputNode node : getNodes()) { + if(!nonRoot.contains(node.getId())) { + result.add(node); + } + } + + return result; + } + + public Map> findAllOutgoingEdges() { + + Map> result = new HashMap<>(getNodes().size()); + for(InputNode n : this.getNodes()) { + result.put(n, new ArrayList()); + } + + for(InputEdge e : this.edges) { + int from = e.getFrom(); + InputNode fromNode = this.getNode(from); + List fromList = result.get(fromNode); + assert fromList != null; + fromList.add(e); + } + + for(InputNode n : this.getNodes()) { + List list = result.get(n); + Collections.sort(list, InputEdge.OUTGOING_COMPARATOR); + } + + return result; + } + + public Map> findAllIngoingEdges() { + + Map> result = new HashMap<>(getNodes().size()); + for(InputNode n : this.getNodes()) { + result.put(n, new ArrayList()); + } + + for(InputEdge e : this.edges) { + int to = e.getTo(); + InputNode toNode = this.getNode(to); + List toList = result.get(toNode); + assert toList != null; + toList.add(e); + } + + for(InputNode n : this.getNodes()) { + List list = result.get(n); + Collections.sort(list, InputEdge.INGOING_COMPARATOR); + } + + return result; + } + + public List findOutgoingEdges(InputNode n) { + List result = new ArrayList<>(); + + for(InputEdge e : this.edges) { + if(e.getFrom() == n.getId()) { + result.add(e); + } + } + + Collections.sort(result, InputEdge.OUTGOING_COMPARATOR); + + return result; + } + + public void clearBlocks() { + blocks.clear(); + nodeToBlock.clear(); + } + + public void setEdge(int fromIndex, int toIndex, int from, int to) { + assert fromIndex == ((char)fromIndex) : "Downcast must be safe"; + assert toIndex == ((char)toIndex) : "Downcast must be safe"; + + InputEdge edge = new InputEdge((char)fromIndex, (char)toIndex, from, to); + if(!this.getEdges().contains(edge)) { + this.addEdge(edge); + } + } + + public void ensureNodesInBlocks() { + InputBlock noBlock = null; + Set scheduledNodes = new HashSet<>(); + + for (InputBlock b : getBlocks()) { + for (InputNode n : b.getNodes()) { + assert !scheduledNodes.contains(n); + scheduledNodes.add(n); + } + } + + for (InputNode n : this.getNodes()) { + assert nodes.get(n.getId()) == n; + if (!scheduledNodes.contains(n)) { + if (noBlock == null) { + noBlock = this.addBlock("(no block)"); + } + noBlock.addNode(n.getId()); + } + assert this.getBlock(n) != null; + } + } + + public void setBlock(InputNode node, InputBlock block) { + nodeToBlock.put(node.getId(), block); + } + + public InputBlock getBlock(int nodeId) { + return nodeToBlock.get(nodeId); + } + + public InputBlock getBlock(InputNode node) { + assert nodes.containsKey(node.getId()); + assert nodes.get(node.getId()).equals(node); + return getBlock(node.getId()); + } + + public InputGraph getNext() { + return parentGroup.getNext(this); + } + + public InputGraph getPrev() { + return parentGroup.getPrev(this); + } + + private void setName(String name) { + this.getProperties().setProperty("name", name); + } + + @Override + public String getName() { + return getProperties().get("name"); + } + + public Collection getNodes() { + return Collections.unmodifiableCollection(nodes.values()); + } + + public Set getNodesAsSet() { + return Collections.unmodifiableSet(nodes.keySet()); + } + + public Collection getBlocks() { + return Collections.unmodifiableCollection(blocks.values()); + } + + public void addNode(InputNode node) { + nodes.put(node.getId(), node); + } + + public InputNode getNode(int id) { + return nodes.get(id); + } + + public InputNode removeNode(int index) { + return nodes.remove(index); + } + + public Collection getEdges() { + return Collections.unmodifiableSet(edges); + } + + public void removeEdge(InputEdge c) { + boolean removed = edges.remove(c); + assert removed; + } + + public void addEdge(InputEdge c) { + // Be tolerant with duplicated edges. + if (!edges.contains(c)) { + edges.add(c); + } + } + + public Group getGroup() { + return parentGroup; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("Graph ").append(getName()).append(" ").append(getProperties().toString()).append("\n"); + for (InputNode n : nodes.values()) { + sb.append(n.toString()); + sb.append("\n"); + } + + for (InputEdge c : edges) { + sb.append(c.toString()); + sb.append("\n"); + } + + for (InputBlock b : getBlocks()) { + sb.append(b.toString()); + sb.append("\n"); + } + + return sb.toString(); + } + + public InputBlock addBlock(String name) { + final InputBlock b = new InputBlock(this, name); + blocks.put(b.getName(), b); + return b; + } + + public InputBlock getBlock(String s) { + return blocks.get(s); + } + + public Collection getBlockEdges() { + return Collections.unmodifiableSet(blockEdges); + } + + @Override + public Folder getParent() { + return parent; + } + + @Override + public List getBasicBlocks() { + return new ArrayList(blocks.values()); + } + + @Override + public BasicBlock getBasicBlockByName(String name) { + return blocks.get(name); + } + + @Override + public Bytecodes getBytecodes() { + // TODO(tw): no bytecodes + return null; + } + + @Override + public NativeMethod getNativeMethod() { + // TODO(tw): No native method. + return null; + } + + @Override + public boolean hasState() { + // TODO(tw): implement + return false; + } + + @Override + public boolean hasHir() { + // TODO(tw): Implement + return false; + } + + @Override + public boolean hasLir() { + // TODO(tw): Implement + return false; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/com/sun/hotspot/igv/data/InputMethod.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/com/sun/hotspot/igv/data/InputMethod.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,149 @@ +/* + * 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.data; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public class InputMethod extends Properties.Entity { + + private String name; + private int bci; + private String shortName; + private List inlined; + private InputMethod parentMethod; + private Group group; + private List bytecodes; + + @Override + public int hashCode() { + int result = name.hashCode(); + result = result * 31 + bci; + result = result * 31 + shortName.hashCode(); + result = result * 31 + inlined.hashCode(); + result = result * 31 + bytecodes.hashCode(); + return result; + } + + @Override + public boolean equals(Object o) { + if (o == null || (!(o instanceof InputMethod))) { + return false; + } + + final InputMethod im = (InputMethod)o; + return name.equals(im.name) && bci == im.bci && shortName.equals(im.shortName) && + inlined.equals(im.inlined) && bytecodes.equals(im.bytecodes); + } + + + + /** Creates a new instance of InputMethod */ + public InputMethod(Group parent, String name, String shortName, int bci) { + this.group = parent; + this.name = name; + this.bci = bci; + this.shortName = shortName; + inlined = new ArrayList<>(); + bytecodes = new ArrayList<>(); + } + + public List getBytecodes() { + return Collections.unmodifiableList(bytecodes); + } + + public List getInlined() { + return Collections.unmodifiableList(inlined); + } + + public void addInlined(InputMethod m) { + + // assert bci unique + for (InputMethod m2 : inlined) { + assert m2.getBci() != m.getBci(); + } + + inlined.add(m); + assert m.parentMethod == null; + m.parentMethod = this; + + for (InputBytecode bc : bytecodes) { + if (bc.getBci() == m.getBci()) { + bc.setInlined(m); + } + } + } + + public Group getGroup() { + return group; + } + + public String getShortName() { + return shortName; + } + + public void setBytecodes(String text) { + + String[] strings = text.split("\n"); + int oldNumber = -1; + for (String s : strings) { + + if (s.length() > 0 && Character.isDigit(s.charAt(0))) { + s = s.trim(); + int spaceIndex = s.indexOf(' '); + String numberString = s.substring(0, spaceIndex); + String tmpName = s.substring(spaceIndex + 1, s.length()); + + int number = -1; + number = Integer.parseInt(numberString); + + // assert correct order of bytecodes + assert number > oldNumber; + + InputBytecode bc = new InputBytecode(number, tmpName); + bytecodes.add(bc); + + for (InputMethod m : inlined) { + if (m.getBci() == number) { + bc.setInlined(m); + break; + } + } + } + } + } + + public String getName() { + return name; + } + + public int getBci() { + return bci; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/com/sun/hotspot/igv/data/InputNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/com/sun/hotspot/igv/data/InputNode.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,102 @@ +/* + * 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.data; + +import java.util.Comparator; + +/** + * + * @author Thomas Wuerthinger + */ +public class InputNode extends Properties.Entity { + + private int id; + + public static final Comparator COMPARATOR = new Comparator() { + @Override + public int compare(InputNode o1, InputNode o2) { + return o1.getId() - o2.getId(); + } + }; + + public static Comparator getPropertyComparator(final String propertyName) { + return new Comparator() { + + @Override + public int compare(InputNode o1, InputNode o2) { + + int i1 = 0; + try { + i1 = Integer.parseInt(o1.getProperties().get(propertyName)); + } catch(NumberFormatException e) { + } + + int i2 = 0; + try { + i2 = Integer.parseInt(o2.getProperties().get(propertyName)); + } catch(NumberFormatException e) { + } + + return i1 - i2; + } + }; + } + + public InputNode(InputNode n) { + super(n); + setId(n.id); + } + + public InputNode(int id) { + setId(id); + } + + public void setId(int id) { + this.id = id; + getProperties().setProperty("id", "" + id); + } + + public int getId() { + return id; + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof InputNode)) { + return false; + } + InputNode n = (InputNode) o; + return n.id == id; + } + + @Override + public int hashCode() { + return id * 13; + } + + @Override + public String toString() { + return "Node " + id + " " + getProperties().toString(); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/com/sun/hotspot/igv/data/Pair.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/com/sun/hotspot/igv/data/Pair.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,87 @@ +/* + * 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.data; + +/** + * + * @author Thomas Wuerthinger + */ +public class Pair { + + private L l; + private R r; + + public Pair() { + } + + public Pair(L l, R r) { + this.l = l; + this.r = r; + } + + public L getLeft() { + return l; + } + + public void setLeft(L l) { + this.l = l; + } + + public R getRight() { + return r; + } + + public void setRight(R r) { + this.r = r; + } + + @Override + public boolean equals(Object o) { + if (o == null || !(o instanceof Pair)) { + return false; + } + Pair obj = (Pair) o; + boolean b1 = (l == obj.l); + if (l != null) { + b1 = l.equals(obj.l); + } + + boolean b2 = (r == obj.r); + if (r != null) { + b2 = r.equals(obj.r); + } + + return b1 && b2; + } + + @Override + public int hashCode() { + return ((l == null) ? 0 : l.hashCode()) * 71 + ((r == null) ? 0 : r.hashCode()); + } + + @Override + public String toString() { + return "[" + l + "/" + r + "]"; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/com/sun/hotspot/igv/data/Properties.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/com/sun/hotspot/igv/data/Properties.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,391 @@ +/* + * 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.data; + +import java.io.Serializable; +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +/** + * + * @author Thomas Wuerthinger + */ +public class Properties implements Serializable, Iterable { + + public static final long serialVersionUID = 1L; + private String[] map = new String[4]; + + public Properties() { + } + + @Override + public boolean equals(java.lang.Object o) { + if (!(o instanceof Properties)) { + return false; + } + + Properties p = (Properties) o; + + for (Property prop : this) { + String value = p.get(prop.getName()); + if (value == null || !value.equals(prop.getValue())) { + return false; + } + } + + for (Property prop : p) { + String value = this.get(prop.getName()); + if (value == null || !value.equals(prop.getValue())) { + return false; + } + } + + return true; + } + + @Override + public int hashCode() { + int hash = 5; + + if (map != null) { + for (int i = 0; i < this.map.length; i++) { + if (map[i] == null) { + i++; + } else { + hash = hash * 83 + map[i].hashCode(); + } + } + } + return hash; + } + + public Properties(String name, String value) { + this(); + this.setProperty(name, value); + } + + public Properties(String name, String value, String name1, String value1) { + this(name, value); + this.setProperty(name1, value1); + } + + public Properties(String name, String value, String name1, String value1, String name2, String value2) { + this(name, value, name1, value1); + this.setProperty(name2, value2); + } + + public Properties(Properties p) { + map = new String[p.map.length]; + System.arraycopy(p.map, 0, map, 0, p.map.length); + } + + public static class Entity implements Provider { + + private Properties properties; + + public Entity() { + properties = new Properties(); + } + + public Entity(Properties.Entity object) { + properties = new Properties(object.getProperties()); + } + + @Override + public Properties getProperties() { + return properties; + } + } + + public interface PropertyMatcher { + + String getName(); + + boolean match(String value); + } + + public static class InvertPropertyMatcher implements PropertyMatcher { + + private PropertyMatcher matcher; + + public InvertPropertyMatcher(PropertyMatcher matcher) { + this.matcher = matcher; + } + + @Override + public String getName() { + return matcher.getName(); + } + + @Override + public boolean match(String p) { + if (p == null) { + return false; + } + return !matcher.match(p); + } + } + + public static class StringPropertyMatcher implements PropertyMatcher { + + private String name; + private String value; + + public StringPropertyMatcher(String name, String value) { + if (name == null) { + throw new IllegalArgumentException("Property name must not be null!"); + } + if (value == null) { + throw new IllegalArgumentException("Property value must not be null!"); + } + this.name = name; + this.value = value; + } + + @Override + public String getName() { + return name; + } + + @Override + public boolean match(String p) { + if (p == null) { + throw new IllegalArgumentException("Property value must not be null!"); + } + return p.equals(value); + } + } + + public static class RegexpPropertyMatcher implements PropertyMatcher { + + private String name; + private Pattern valuePattern; + + public RegexpPropertyMatcher(String name, String value) { + this(name, value, 0); + } + + public RegexpPropertyMatcher(String name, String value, int flags) { + + if (name == null) { + throw new IllegalArgumentException("Property name must not be null!"); + } + + if (value == null) { + throw new IllegalArgumentException("Property value pattern must not be null!"); + } + + this.name = name; + + try { + valuePattern = Pattern.compile(value, flags); + } catch (PatternSyntaxException e) { + throw new IllegalArgumentException("Bad pattern: " + value); + } + } + + @Override + public String getName() { + return name; + } + + @Override + public boolean match(String p) { + if (p == null) { + throw new IllegalArgumentException("Property value must not be null!"); + } + Matcher m = valuePattern.matcher(p); + return m.matches(); + } + } + + public Property selectSingle(PropertyMatcher matcher) { + + final String name = matcher.getName(); + String value = null; + for (int i = 0; i < map.length; i += 2) { + if (map[i] != null && name.equals(map[i])) { + value = map[i + 1]; + break; + } + } + if (value != null && matcher.match(value)) { + return new Property(name, value); + } else { + return null; + } + } + + public interface Provider { + + public Properties getProperties(); + } + + @Override + public String toString() { + List pairs = new ArrayList<>(); + for (int i = 0; i < map.length; i += 2) { + if (map[i + 1] != null) { + pairs.add(new String[]{map[i], map[i + 1]}); + } + } + + Collections.sort(pairs, new Comparator() { + @Override + public int compare(String[] o1, String[] o2) { + assert o1.length == 2; + assert o2.length == 2; + return o1[0].compareTo(o2[0]); + } + }); + + StringBuilder sb = new StringBuilder(); + sb.append("["); + boolean first = true; + for (String[] p : pairs) { + if (first) { + first = false; + } else { + sb.append(", "); + } + sb.append(p[0] + "=" + p[1]); + } + return sb.append("]").toString(); + } + + public static class PropertySelector { + + private Collection objects; + + public PropertySelector(Collection objects) { + this.objects = objects; + } + + public T selectSingle(PropertyMatcher matcher) { + + for (T t : objects) { + Property p = t.getProperties().selectSingle(matcher); + if (p != null) { + return t; + } + } + + return null; + } + + public List selectMultiple(PropertyMatcher matcher) { + List result = new ArrayList<>(); + + for (T t : objects) { + Property p = t.getProperties().selectSingle(matcher); + if (p != null) { + result.add(t); + } + } + + return result; + } + } + + public String get(String key) { + for (int i = 0; i < map.length; i += 2) { + if (map[i] != null && map[i].equals(key)) { + return map[i + 1]; + } + } + return null; + } + + public void setProperty(String name, String value) { + + for (int i = 0; i < map.length; i += 2) { + if (map[i] != null && map[i].equals(name)) { + String p = map[i + 1]; + if (value == null) { + // remove this property + map[i] = null; + map[i + 1] = null; + } else { + map[i + 1] = value; + } + return; + } + } + if (value == null) { + return; + } + for (int i = 0; i < map.length; i += 2) { + if (map[i] == null) { + map[i] = name; + map[i + 1] = value; + return; + } + } + String[] newMap = new String[map.length + 4]; + System.arraycopy(map, 0, newMap, 0, map.length); + newMap[map.length] = name; + newMap[map.length + 1] = value; + map = newMap; + } + + public void add(Properties properties) { + for (Property p : properties) { + setProperty(p.getName(), p.getValue()); + } + } + + private class PropertiesIterator implements Iterator { + + int index; + + @Override + public boolean hasNext() { + while (index < map.length && map[index + 1] == null) { + index += 2; + } + return index < map.length; + } + + @Override + public Property next() { + if (index < map.length) { + index += 2; + return new Property(map[index - 2], map[index - 1]); + } + return null; + } + + @Override + public void remove() { + throw new UnsupportedOperationException("Not supported yet."); + } + } + + @Override + public Iterator iterator() { + return new PropertiesIterator(); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/com/sun/hotspot/igv/data/Property.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/com/sun/hotspot/igv/data/Property.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,77 @@ +/* + * 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.data; + +import java.io.Serializable; + +/** + * + * @author Thomas Wuerthinger + */ +public class Property implements Serializable { + + public static final long serialVersionUID = 1L; + private String name; + private String value; + + Property(String name, String value) { + this.name = name; + this.value = value; + + if (value == null) { + throw new IllegalArgumentException("Property value must not be null!"); + } + + if (name == null) { + throw new IllegalArgumentException("Property name must not be null!"); + } + } + + public String getName() { + return name; + } + + public String getValue() { + return value; + } + + @Override + public String toString() { + return name + "=" + value; + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof Property)) { + return false; + } + Property p2 = (Property) o; + return name.equals(p2.name) && value.equals(p2.value); + } + + @Override + public int hashCode() { + return name.hashCode() * 13 + value.hashCode(); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/com/sun/hotspot/igv/data/Source.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/com/sun/hotspot/igv/data/Source.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,67 @@ +/* + * 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.data; + +import java.util.*; + +/** + * + * @author Thomas Wuerthinger + */ +public class Source { + + private List sourceNodes; + private Set set; + + public Source() { + sourceNodes = new ArrayList<>(1); + set = new LinkedHashSet<>(1); + } + + public List getSourceNodes() { + return Collections.unmodifiableList(sourceNodes); + } + + public Set getSourceNodesAsSet() { + return Collections.unmodifiableSet(set); + } + + public void addSourceNode(InputNode n) { + if (!set.contains(n.getId())) { + sourceNodes.add(n); + set.add(n.getId()); + } + } + + public interface Provider { + + public Source getSource(); + } + + public void addSourceNodes(Source s) { + for (InputNode n : s.getSourceNodes()) { + addSourceNode(n); + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/com/sun/hotspot/igv/data/serialization/Parser.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/com/sun/hotspot/igv/data/serialization/Parser.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,542 @@ +/* + * 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.data.serialization; + +import com.sun.hotspot.igv.data.*; +import com.sun.hotspot.igv.data.serialization.XMLParser.ElementHandler; +import com.sun.hotspot.igv.data.serialization.XMLParser.HandoverElementHandler; +import com.sun.hotspot.igv.data.serialization.XMLParser.ParseMonitor; +import com.sun.hotspot.igv.data.serialization.XMLParser.TopElementHandler; +import com.sun.hotspot.igv.data.services.GroupCallback; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import javax.swing.SwingUtilities; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParserFactory; +import javax.xml.transform.Source; +import javax.xml.transform.stream.StreamSource; +import javax.xml.validation.SchemaFactory; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; + +/** + * + * @author Thomas Wuerthinger + */ +public class Parser { + + public static final String INDENT = " "; + public static final String TOP_ELEMENT = "graphDocument"; + public static final String GROUP_ELEMENT = "group"; + public static final String GRAPH_ELEMENT = "graph"; + public static final String ROOT_ELEMENT = "graphDocument"; + public static final String PROPERTIES_ELEMENT = "properties"; + public static final String EDGES_ELEMENT = "edges"; + public static final String PROPERTY_ELEMENT = "p"; + public static final String EDGE_ELEMENT = "edge"; + public static final String NODE_ELEMENT = "node"; + public static final String NODES_ELEMENT = "nodes"; + public static final String REMOVE_EDGE_ELEMENT = "removeEdge"; + public static final String REMOVE_NODE_ELEMENT = "removeNode"; + public static final String METHOD_NAME_PROPERTY = "name"; + public static final String GROUP_NAME_PROPERTY = "name"; + public static final String METHOD_IS_PUBLIC_PROPERTY = "public"; + public static final String METHOD_IS_STATIC_PROPERTY = "static"; + public static final String TRUE_VALUE = "true"; + public static final String NODE_NAME_PROPERTY = "name"; + public static final String EDGE_NAME_PROPERTY = "name"; + public static final String NODE_ID_PROPERTY = "id"; + public static final String FROM_PROPERTY = "from"; + public static final String TO_PROPERTY = "to"; + public static final String PROPERTY_NAME_PROPERTY = "name"; + public static final String GRAPH_NAME_PROPERTY = "name"; + public static final String FROM_INDEX_PROPERTY = "fromIndex"; + public static final String TO_INDEX_PROPERTY = "toIndex"; + public static final String TO_INDEX_ALT_PROPERTY = "index"; + public static final String LABEL_PROPERTY = "label"; + public static final String METHOD_ELEMENT = "method"; + public static final String INLINE_ELEMENT = "inline"; + public static final String BYTECODES_ELEMENT = "bytecodes"; + public static final String METHOD_BCI_PROPERTY = "bci"; + public static final String METHOD_SHORT_NAME_PROPERTY = "shortName"; + public static final String CONTROL_FLOW_ELEMENT = "controlFlow"; + public static final String BLOCK_NAME_PROPERTY = "name"; + public static final String BLOCK_ELEMENT = "block"; + public static final String SUCCESSORS_ELEMENT = "successors"; + public static final String SUCCESSOR_ELEMENT = "successor"; + public static final String ASSEMBLY_ELEMENT = "assembly"; + public static final String DIFFERENCE_PROPERTY = "difference"; + private TopElementHandler xmlDocument = new TopElementHandler<>(); + private Map differenceEncoding = new HashMap<>(); + private Map lastParsedGraph = new HashMap<>(); + private GroupCallback groupCallback; + private HashMap idCache = new HashMap<>(); + private ArrayList> blockConnections = new ArrayList<>(); + private int maxId = 0; + private GraphDocument graphDocument; + + private int lookupID(String i) { + try { + return Integer.parseInt(i); + } catch (NumberFormatException nfe) { + // ignore + } + Integer id = idCache.get(i); + if (id == null) { + id = maxId++; + idCache.put(i, id); + } + return id.intValue(); + } + + // + private ElementHandler topHandler = new ElementHandler(TOP_ELEMENT) { + + @Override + protected GraphDocument start() throws SAXException { + graphDocument = new GraphDocument(); + return graphDocument; + } + }; + // + private ElementHandler groupHandler = new XMLParser.ElementHandler(GROUP_ELEMENT) { + + @Override + protected Group start() throws SAXException { + final Group group = new Group(this.getParentObject()); + + String differenceProperty = this.readAttribute(DIFFERENCE_PROPERTY); + Parser.this.differenceEncoding.put(group, (differenceProperty != null && (differenceProperty.equals("1") || differenceProperty.equals("true")))); + + ParseMonitor monitor = getMonitor(); + if (monitor != null) { + monitor.setState(group.getName()); + } + + final Folder parent = getParentObject(); + if (groupCallback == null || parent instanceof Group) { + SwingUtilities.invokeLater(new Runnable(){ + @Override + public void run() { + parent.addElement(group); + } + }); + } + + return group; + } + + @Override + protected void end(String text) throws SAXException { + } + }; + // + private ElementHandler methodHandler = new XMLParser.ElementHandler(METHOD_ELEMENT) { + + @Override + protected InputMethod start() throws SAXException { + + InputMethod method = parseMethod(this, getParentObject()); + getParentObject().setMethod(method); + return method; + } + }; + + private InputMethod parseMethod(XMLParser.ElementHandler handler, Group group) throws SAXException { + String s = handler.readRequiredAttribute(METHOD_BCI_PROPERTY); + int bci = 0; + try { + bci = Integer.parseInt(s); + } catch (NumberFormatException e) { + throw new SAXException(e); + } + InputMethod method = new InputMethod(group, handler.readRequiredAttribute(METHOD_NAME_PROPERTY), handler.readRequiredAttribute(METHOD_SHORT_NAME_PROPERTY), bci); + return method; + } + // + private HandoverElementHandler bytecodesHandler = new XMLParser.HandoverElementHandler(BYTECODES_ELEMENT, true) { + + @Override + protected void end(String text) throws SAXException { + getParentObject().setBytecodes(text); + } + }; + // + private HandoverElementHandler inlinedHandler = new XMLParser.HandoverElementHandler<>(INLINE_ELEMENT); + // + private ElementHandler inlinedMethodHandler = new XMLParser.ElementHandler(METHOD_ELEMENT) { + + @Override + protected InputMethod start() throws SAXException { + InputMethod method = parseMethod(this, getParentObject().getGroup()); + getParentObject().addInlined(method); + return method; + } + }; + // + private ElementHandler graphHandler = new XMLParser.ElementHandler(GRAPH_ELEMENT) { + + @Override + protected InputGraph start() throws SAXException { + String name = readAttribute(GRAPH_NAME_PROPERTY); + InputGraph curGraph = new InputGraph(name); + if (differenceEncoding.get(getParentObject())) { + InputGraph previous = lastParsedGraph.get(getParentObject()); + lastParsedGraph.put(getParentObject(), curGraph); + if (previous != null) { + for (InputNode n : previous.getNodes()) { + curGraph.addNode(n); + } + for (InputEdge e : previous.getEdges()) { + curGraph.addEdge(e); + } + } + } + return curGraph; + } + + @Override + protected void end(String text) throws SAXException { + // NOTE: Some graphs intentionally don't provide blocks. Instead + // they later generate the blocks from other information such + // as node properties (example: ServerCompilerScheduler). + // Thus, we shouldn't assign nodes that don't belong to any + // block to some artificial block below unless blocks are + // defined and nodes are assigned to them. + + final InputGraph graph = getObject(); + final Group parent = getParentObject(); + if (graph.getBlocks().size() > 0) { + boolean blocksContainNodes = false; + for (InputBlock b : graph.getBlocks()) { + if (b.getNodes().size() > 0) { + blocksContainNodes = true; + break; + } + } + + if (!blocksContainNodes) { + graph.clearBlocks(); + blockConnections.clear(); + } else { + // Blocks and their nodes defined: add other nodes to an + // artificial "no block" block + InputBlock noBlock = null; + for (InputNode n : graph.getNodes()) { + if (graph.getBlock(n) == null) { + if (noBlock == null) { + noBlock = graph.addBlock("(no block)"); + } + + noBlock.addNode(n.getId()); + } + + assert graph.getBlock(n) != null; + } + } + } + + // Resolve block successors + for (Pair p : blockConnections) { + final InputBlock left = graph.getBlock(p.getLeft()); + assert left != null; + final InputBlock right = graph.getBlock(p.getRight()); + assert right != null; + graph.addBlockEdge(left, right); + } + blockConnections.clear(); + + SwingUtilities.invokeLater(new Runnable(){ + + @Override + public void run() { + // Add to group + parent.addElement(graph); + } + }); + } + }; + // + private HandoverElementHandler nodesHandler = new HandoverElementHandler<>(NODES_ELEMENT); + // + private HandoverElementHandler controlFlowHandler = new HandoverElementHandler<>(CONTROL_FLOW_ELEMENT); + // + private ElementHandler blockHandler = new ElementHandler(BLOCK_ELEMENT) { + + @Override + protected InputBlock start() throws SAXException { + InputGraph graph = getParentObject(); + String name = readRequiredAttribute(BLOCK_NAME_PROPERTY); + InputBlock b = graph.addBlock(name); + for (InputNode n : b.getNodes()) { + assert graph.getBlock(n).equals(b); + } + return b; + } + }; + // + private HandoverElementHandler blockNodesHandler = new HandoverElementHandler<>(NODES_ELEMENT); + // + private ElementHandler blockNodeHandler = new ElementHandler(NODE_ELEMENT) { + + @Override + protected InputBlock start() throws SAXException { + String s = readRequiredAttribute(NODE_ID_PROPERTY); + + int id = 0; + try { + id = lookupID(s); + } catch (NumberFormatException e) { + throw new SAXException(e); + } + getParentObject().addNode(id); + return getParentObject(); + } + }; + // + private HandoverElementHandler successorsHandler = new HandoverElementHandler<>(SUCCESSORS_ELEMENT); + // + private ElementHandler successorHandler = new ElementHandler(SUCCESSOR_ELEMENT) { + + @Override + protected InputBlock start() throws SAXException { + String name = readRequiredAttribute(BLOCK_NAME_PROPERTY); + blockConnections.add(new Pair<>(getParentObject().getName(), name)); + return getParentObject(); + } + }; + // + private ElementHandler nodeHandler = new ElementHandler(NODE_ELEMENT) { + + @Override + protected InputNode start() throws SAXException { + String s = readRequiredAttribute(NODE_ID_PROPERTY); + int id = 0; + try { + id = lookupID(s); + } catch (NumberFormatException e) { + throw new SAXException(e); + } + InputNode node = new InputNode(id); + getParentObject().addNode(node); + return node; + } + }; + // + private ElementHandler removeNodeHandler = new ElementHandler(REMOVE_NODE_ELEMENT) { + + @Override + protected InputNode start() throws SAXException { + String s = readRequiredAttribute(NODE_ID_PROPERTY); + int id = 0; + try { + id = lookupID(s); + } catch (NumberFormatException e) { + throw new SAXException(e); + } + return getParentObject().removeNode(id); + } + }; + // + private HandoverElementHandler edgesHandler = new HandoverElementHandler<>(EDGES_ELEMENT); + + // Local class for edge elements + private class EdgeElementHandler extends ElementHandler { + + public EdgeElementHandler(String name) { + super(name); + } + + @Override + protected InputEdge start() throws SAXException { + int fromIndex = 0; + int toIndex = 0; + int from = -1; + int to = -1; + String label = null; + + try { + String fromIndexString = readAttribute(FROM_INDEX_PROPERTY); + if (fromIndexString != null) { + fromIndex = Integer.parseInt(fromIndexString); + } + + String toIndexString = readAttribute(TO_INDEX_PROPERTY); + if (toIndexString == null) { + toIndexString = readAttribute(TO_INDEX_ALT_PROPERTY); + } + if (toIndexString != null) { + toIndex = Integer.parseInt(toIndexString); + } + + label = readAttribute(LABEL_PROPERTY); + + from = lookupID(readRequiredAttribute(FROM_PROPERTY)); + to = lookupID(readRequiredAttribute(TO_PROPERTY)); + } catch (NumberFormatException e) { + throw new SAXException(e); + } + + InputEdge conn = new InputEdge((char) fromIndex, (char) toIndex, from, to, label); + return start(conn); + } + + protected InputEdge start(InputEdge conn) throws SAXException { + return conn; + } + } + // + private EdgeElementHandler edgeHandler = new EdgeElementHandler(EDGE_ELEMENT) { + + @Override + protected InputEdge start(InputEdge conn) throws SAXException { + getParentObject().addEdge(conn); + return conn; + } + }; + // + private EdgeElementHandler removeEdgeHandler = new EdgeElementHandler(REMOVE_EDGE_ELEMENT) { + + @Override + protected InputEdge start(InputEdge conn) throws SAXException { + getParentObject().removeEdge(conn); + return conn; + } + }; + // + private HandoverElementHandler propertiesHandler = new HandoverElementHandler<>(PROPERTIES_ELEMENT); + // + private HandoverElementHandler groupPropertiesHandler = new HandoverElementHandler(PROPERTIES_ELEMENT) { + + @Override + public void end(String text) throws SAXException { + if (groupCallback != null && getParentObject().getParent() instanceof GraphDocument) { + final Group group = getParentObject(); + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + groupCallback.started(group); + } + }); + } + } + }; + // + private ElementHandler propertyHandler = new XMLParser.ElementHandler(PROPERTY_ELEMENT, true) { + + @Override + public String start() throws SAXException { + return readRequiredAttribute(PROPERTY_NAME_PROPERTY); + } + + @Override + public void end(String text) { + getParentObject().getProperties().setProperty(getObject(), text.trim()); + } + }; + + public Parser() { + this(null); + } + + public Parser(GroupCallback groupCallback) { + + this.groupCallback = groupCallback; + + // Initialize dependencies + xmlDocument.addChild(topHandler); + topHandler.addChild(groupHandler); + + groupHandler.addChild(methodHandler); + groupHandler.addChild(graphHandler); + groupHandler.addChild(groupHandler); + + methodHandler.addChild(inlinedHandler); + methodHandler.addChild(bytecodesHandler); + + inlinedHandler.addChild(inlinedMethodHandler); + inlinedMethodHandler.addChild(bytecodesHandler); + inlinedMethodHandler.addChild(inlinedHandler); + + graphHandler.addChild(nodesHandler); + graphHandler.addChild(edgesHandler); + graphHandler.addChild(controlFlowHandler); + + controlFlowHandler.addChild(blockHandler); + + blockHandler.addChild(successorsHandler); + successorsHandler.addChild(successorHandler); + blockHandler.addChild(blockNodesHandler); + blockNodesHandler.addChild(blockNodeHandler); + + nodesHandler.addChild(nodeHandler); + nodesHandler.addChild(removeNodeHandler); + edgesHandler.addChild(edgeHandler); + edgesHandler.addChild(removeEdgeHandler); + + methodHandler.addChild(propertiesHandler); + inlinedMethodHandler.addChild(propertiesHandler); + topHandler.addChild(propertiesHandler); + groupHandler.addChild(groupPropertiesHandler); + graphHandler.addChild(propertiesHandler); + nodeHandler.addChild(propertiesHandler); + propertiesHandler.addChild(propertyHandler); + groupPropertiesHandler.addChild(propertyHandler); + } + + // Returns a new GraphDocument object deserialized from an XML input source. + public GraphDocument parse(InputSource source, XMLParser.ParseMonitor monitor) throws SAXException { + XMLReader reader = createReader(); + + reader.setContentHandler(new XMLParser(xmlDocument, monitor)); + try { + reader.parse(source); + } catch (IOException ex) { + throw new SAXException(ex); + } + + return graphDocument; + } + + private XMLReader createReader() throws SAXException { + try { + SAXParserFactory pfactory = SAXParserFactory.newInstance(); + pfactory.setValidating(false); + pfactory.setNamespaceAware(true); + + // Enable schema validation + SchemaFactory sfactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema"); + InputStream stream = Parser.class.getResourceAsStream("graphdocument.xsd"); + pfactory.setSchema(sfactory.newSchema(new Source[]{new StreamSource(stream)})); + + return pfactory.newSAXParser().getXMLReader(); + } catch (ParserConfigurationException ex) { + throw new SAXException(ex); + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/com/sun/hotspot/igv/data/serialization/Printer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/com/sun/hotspot/igv/data/serialization/Printer.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,245 @@ +/* + * 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.data.serialization; + +import com.sun.hotspot.igv.data.*; +import java.io.IOException; +import java.io.InputStream; +import java.io.Writer; +import java.util.HashSet; +import java.util.Set; + +/** + * + * @author Thomas Wuerthinger + */ +public class Printer { + + private InputStream in; + + public Printer() { + this(null); + } + + public Printer(InputStream inputStream) { + this.in = inputStream; + } + + public void export(Writer writer, GraphDocument document) { + + XMLWriter xmlWriter = new XMLWriter(writer); + + try { + export(xmlWriter, document); + } catch (IOException ex) { + } + } + + private void export(XMLWriter xmlWriter, GraphDocument document) throws IOException { + xmlWriter.startTag(Parser.ROOT_ELEMENT); + xmlWriter.writeProperties(document.getProperties()); + for (FolderElement e : document.getElements()) { + if (e instanceof Group) { + export(xmlWriter, (Group) e); + } else if (e instanceof InputGraph) { + export(xmlWriter, (InputGraph)e, null, false); + } + } + + xmlWriter.endTag(); + xmlWriter.flush(); + } + + private void export(XMLWriter writer, Group g) throws IOException { + Properties attributes = new Properties(); + attributes.setProperty("difference", Boolean.toString(true)); + writer.startTag(Parser.GROUP_ELEMENT, attributes); + writer.writeProperties(g.getProperties()); + + boolean shouldExport = true; + if (in != null) { + char c = (char) in.read(); + if (c != 'y') { + shouldExport = false; + } + } + + if (shouldExport) { + if (g.getMethod() != null) { + export(writer, g.getMethod()); + } + + InputGraph previous = null; + for (FolderElement e : g.getElements()) { + if (e instanceof InputGraph) { + InputGraph graph = (InputGraph) e; + export(writer, graph, previous, true); + previous = graph; + } else if (e instanceof Group) { + export(writer, (Group) e); + } + } + } + + writer.endTag(); + } + + public void export(XMLWriter writer, InputGraph graph, InputGraph previous, boolean difference) throws IOException { + + writer.startTag(Parser.GRAPH_ELEMENT); + writer.writeProperties(graph.getProperties()); + writer.startTag(Parser.NODES_ELEMENT); + + Set removed = new HashSet<>(); + Set equal = new HashSet<>(); + + if (previous != null) { + for (InputNode n : previous.getNodes()) { + int id = n.getId(); + InputNode n2 = graph.getNode(id); + if (n2 == null) { + removed.add(n); + } else if (n.equals(n2)) { + equal.add(n); + } + } + } + + if (difference) { + for (InputNode n : removed) { + writer.simpleTag(Parser.REMOVE_NODE_ELEMENT, new Properties(Parser.NODE_ID_PROPERTY, Integer.toString(n.getId()))); + } + } + + for (InputNode n : graph.getNodes()) { + if (!difference || !equal.contains(n)) { + writer.startTag(Parser.NODE_ELEMENT, new Properties(Parser.NODE_ID_PROPERTY, Integer.toString(n.getId()))); + writer.writeProperties(n.getProperties()); + writer.endTag(); + } + } + + writer.endTag(); + + writer.startTag(Parser.EDGES_ELEMENT); + Set removedEdges = new HashSet<>(); + Set equalEdges = new HashSet<>(); + + if (previous != null) { + for (InputEdge e : previous.getEdges()) { + if (graph.getEdges().contains(e)) { + equalEdges.add(e); + } else { + removedEdges.add(e); + } + } + } + + if (difference) { + for (InputEdge e : removedEdges) { + writer.simpleTag(Parser.REMOVE_EDGE_ELEMENT, createProperties(e)); + } + } + + for (InputEdge e : graph.getEdges()) { + if (!difference || !equalEdges.contains(e)) { + if (!equalEdges.contains(e)) { + writer.simpleTag(Parser.EDGE_ELEMENT, createProperties(e)); + } + } + } + + writer.endTag(); + + writer.startTag(Parser.CONTROL_FLOW_ELEMENT); + for (InputBlock b : graph.getBlocks()) { + writer.startTag(Parser.BLOCK_ELEMENT, new Properties(Parser.BLOCK_NAME_PROPERTY, b.getName())); + + if (b.getSuccessors().size() > 0) { + writer.startTag(Parser.SUCCESSORS_ELEMENT); + for (InputBlock s : b.getSuccessors()) { + writer.simpleTag(Parser.SUCCESSOR_ELEMENT, new Properties(Parser.BLOCK_NAME_PROPERTY, s.getName())); + } + writer.endTag(); + } + + if (b.getNodes().size() > 0) { + writer.startTag(Parser.NODES_ELEMENT); + for (InputNode n : b.getNodes()) { + writer.simpleTag(Parser.NODE_ELEMENT, new Properties(Parser.NODE_ID_PROPERTY, n.getId() + "")); + } + writer.endTag(); + } + + writer.endTag(); + } + + writer.endTag(); + writer.endTag(); + } + + private void export(XMLWriter w, InputMethod method) throws IOException { + + w.startTag(Parser.METHOD_ELEMENT, new Properties(Parser.METHOD_BCI_PROPERTY, method.getBci() + "", Parser.METHOD_NAME_PROPERTY, method.getName(), Parser.METHOD_SHORT_NAME_PROPERTY, method.getShortName())); + + w.writeProperties(method.getProperties()); + + if (method.getInlined().size() > 0) { + w.startTag(Parser.INLINE_ELEMENT); + for (InputMethod m : method.getInlined()) { + export(w, m); + } + w.endTag(); + } + + w.startTag(Parser.BYTECODES_ELEMENT); + + StringBuilder b = new StringBuilder(); + b.append(""); + w.write(b.toString()); + w.endTag(); + w.endTag(); + } + + private Properties createProperties(InputEdge edge) { + Properties p = new Properties(); + if (edge.getToIndex() != 0) { + p.setProperty(Parser.TO_INDEX_PROPERTY, Integer.toString(edge.getToIndex())); + } + if (edge.getFromIndex() != 0) { + p.setProperty(Parser.FROM_INDEX_PROPERTY, Integer.toString(edge.getFromIndex())); + } + p.setProperty(Parser.TO_PROPERTY, Integer.toString(edge.getTo())); + p.setProperty(Parser.FROM_PROPERTY, Integer.toString(edge.getFrom())); + return p; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/com/sun/hotspot/igv/data/serialization/XMLParser.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/com/sun/hotspot/igv/data/serialization/XMLParser.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,270 @@ +/* + * 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.data.serialization; + +import com.sun.hotspot.igv.data.Properties; +import java.util.HashMap; +import java.util.Stack; +import org.xml.sax.Attributes; +import org.xml.sax.ContentHandler; +import org.xml.sax.Locator; +import org.xml.sax.SAXException; + +/** + * + * @author Thomas Wuerthinger + */ +public class XMLParser implements ContentHandler { + + public static interface ParseMonitor { + + public void setProgress(double d); + + public void setState(String state); + } + + public static class MissingAttributeException extends SAXException { + + private String name; + + public MissingAttributeException(String name) { + super("Missing attribute \"" + name + "\""); + this.name = name; + } + + public String getAttributeName() { + return this.getMessage(); + } + } + + public static class HandoverElementHandler

extends ElementHandler { + + @Override + protected P start() throws SAXException { + return getParentObject(); + } + + public HandoverElementHandler(String name) { + super(name); + } + + public HandoverElementHandler(String name, boolean needsText) { + super(name, needsText); + } + } + + public static class TopElementHandler

extends ElementHandler { + + public TopElementHandler() { + super(null); + } + } + + public static class ElementHandler { + + private String name; + private Stack object = new Stack<>(); + private Attributes attr; + private StringBuilder currentText; + private ParseMonitor monitor; + private HashMap> hashtable; + private boolean needsText; + private Stack> parentElement = new Stack<>(); + private Stack

parentObject = new Stack<>(); + + public ElementHandler(String name) { + this(name, false); + } + + public ElementHandler getParentElement() { + return parentElement.peek(); + } + + public P getParentObject() { + return parentObject.peek(); + } + + protected boolean needsText() { + return needsText; + } + + public ElementHandler(String name, boolean needsText) { + this.hashtable = new HashMap<>(); + this.name = name; + this.needsText = needsText; + } + + public ParseMonitor getMonitor() { + return monitor; + } + + public ElementHandler getChild(String name) { + return hashtable.get(name); + } + + public void addChild(ElementHandler handler) { + assert handler != null; + hashtable.put(handler.getName(), handler); + } + + public String getName() { + return name; + } + + public T getObject() { + return object.size() == 0 ? null : object.peek(); + } + + public String readAttribute(String name) { + return attr.getValue(name); + } + + public String readRequiredAttribute(String name) throws SAXException { + String s = readAttribute(name); + if (s == null) { + throw new MissingAttributeException(name); + } + return s; + } + + public void processAttributesAsProperties(Properties p) { + int length = attr.getLength(); + for (int i = 0; i < length; i++) { + String val = attr.getValue(i); + String localName = attr.getLocalName(i); + p.setProperty(val, localName); + } + } + + public void startElement(ElementHandler parentElement, Attributes attr, ParseMonitor monitor) throws SAXException { + this.currentText = new StringBuilder(); + this.attr = attr; + this.monitor = monitor; + this.parentElement.push(parentElement); + parentObject.push(parentElement.getObject()); + object.push(start()); + } + + protected T start() throws SAXException { + return null; + } + + protected void end(String text) throws SAXException { + + } + + public void endElement() throws SAXException { + end(currentText.toString()); + object.pop(); + parentElement.pop(); + parentObject.pop(); + } + + protected void text(char[] c, int start, int length) { + assert currentText != null; + currentText.append(c, start, length); + } + } + private Stack stack; + private ParseMonitor monitor; + + public XMLParser(TopElementHandler rootHandler, ParseMonitor monitor) { + this.stack = new Stack<>(); + this.monitor = monitor; + this.stack.push(rootHandler); + } + + @Override + public void setDocumentLocator(Locator locator) { + if (monitor != null) { + monitor.setState("Starting parsing"); + } + } + + @Override + public void startDocument() throws SAXException { + } + + @Override + public void endDocument() throws SAXException { + } + + @Override + public void startPrefixMapping(String prefix, String uri) throws SAXException { + } + + @Override + public void endPrefixMapping(String prefix) throws SAXException { + } + + @SuppressWarnings("unchecked") + @Override + public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { + assert !stack.isEmpty(); + + ElementHandler parent = stack.peek(); + if (parent != null) { + ElementHandler child = parent.getChild(qName); + if (child != null) { + child.startElement(parent, atts, monitor); + stack.push(child); + return; + } + } + + stack.push(null); + } + + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + ElementHandler handler = stack.pop(); + if (handler != null) { + handler.endElement(); + } + } + + @Override + public void characters(char[] ch, int start, int length) throws SAXException { + + assert !stack.isEmpty(); + + + ElementHandler top = stack.peek(); + if (top != null && top.needsText()) { + top.text(ch, start, length); + } + } + + @Override + public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { + } + + @Override + public void processingInstruction(String target, String data) throws SAXException { + } + + @Override + public void skippedEntity(String name) throws SAXException { + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/com/sun/hotspot/igv/data/serialization/XMLWriter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/com/sun/hotspot/igv/data/serialization/XMLWriter.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,131 @@ +/* + * 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.data.serialization; + +import com.sun.hotspot.igv.data.Properties; +import com.sun.hotspot.igv.data.Property; +import java.io.IOException; +import java.io.Writer; +import java.util.Stack; + +/** + * + * @author Thomas Wuerthinger + */ +public class XMLWriter extends Writer { + + private Writer inner; + private Stack elementStack; + + public XMLWriter(Writer inner) { + this.inner = inner; + elementStack = new Stack<>(); + } + + @Override + public void write(char[] arr) throws IOException { + write(arr, 0, arr.length); + } + + @Override + public void write(char[] cbuf, int off, int len) throws IOException { + for (int i = off; i < off + len; i++) { + char c = cbuf[i]; + if (c == '>') { + inner.write(">"); + } else if (c == '<') { + inner.write("<"); + } else if (c == '&') { + inner.write("&"); + } else { + inner.write(c); + } + } + } + + @Override + public void flush() throws IOException { + inner.flush(); + } + + @Override + public void close() throws IOException { + inner.close(); + } + + public void endTag() throws IOException { + inner.write("\n"); + } + + public void startTag(String name) throws IOException { + inner.write("<" + name + ">\n"); + elementStack.push(name); + } + + public void simpleTag(String name) throws IOException { + inner.write("<" + name + "/>\n"); + } + + public void startTag(String name, Properties attributes) throws IOException { + inner.write("<" + name); + elementStack.push(name); + + for (Property p : attributes) { + inner.write(" " + p.getName() + "=\""); + write(p.getValue().toCharArray()); + inner.write("\""); + } + + inner.write(">\n"); + } + + public void simpleTag(String name, Properties attributes) throws IOException { + inner.write("<" + name); + + for (Property p : attributes) { + inner.write(" " + p.getName() + "=\""); + write(p.getValue().toCharArray()); + inner.write("\""); + } + + inner.write("/>\n"); + } + + public void writeProperties(Properties props) throws IOException { + if (props.iterator().hasNext() == false) { + return; + } + + startTag(Parser.PROPERTIES_ELEMENT); + + for (Property p : props) { + startTag(Parser.PROPERTY_ELEMENT, new Properties(Parser.PROPERTY_NAME_PROPERTY, p.getName())); + this.write(p.getValue().toCharArray()); + endTag(); + } + + endTag(); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/com/sun/hotspot/igv/data/serialization/graphdocument.xsd --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/com/sun/hotspot/igv/data/serialization/graphdocument.xsd Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,146 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/com/sun/hotspot/igv/data/services/GraphViewer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/com/sun/hotspot/igv/data/services/GraphViewer.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,35 @@ +/* + * 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.data.services; + +import com.sun.hotspot.igv.data.InputGraph; + +/** + * + * @author Thomas Wuerthinger + */ +public interface GraphViewer { + + public void view(InputGraph graph); +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/com/sun/hotspot/igv/data/services/GroupCallback.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/com/sun/hotspot/igv/data/services/GroupCallback.java Tue Feb 07 22:41:09 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.sun.hotspot.igv.data.services; + +import com.sun.hotspot.igv.data.Group; + +/** + * + * @author Thomas Wuerthinger + */ +public interface GroupCallback { + + public void started(Group g); +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/com/sun/hotspot/igv/data/services/InputGraphProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/com/sun/hotspot/igv/data/services/InputGraphProvider.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,40 @@ +/* + * 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.data.services; + +import com.sun.hotspot.igv.data.InputGraph; +import com.sun.hotspot.igv.data.InputNode; +import java.util.Set; + +/** + * + * @author Thomas Wuerthinger + */ +public interface InputGraphProvider { + + InputGraph getGraph(); + + void setSelectedNodes(Set nodes); +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/src/com/sun/hotspot/igv/data/services/Scheduler.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/src/com/sun/hotspot/igv/data/services/Scheduler.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,38 @@ +/* + * 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.data.services; + +import com.sun.hotspot.igv.data.InputBlock; +import com.sun.hotspot.igv.data.InputGraph; +import java.util.Collection; + +/** + * + * @author Thomas Wuerthinger + */ +public interface Scheduler { + + public Collection schedule(InputGraph graph); +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/test/unit/src/com/sun/hotspot/igv/data/ChangedEventTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/test/unit/src/com/sun/hotspot/igv/data/ChangedEventTest.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,95 @@ +/* + * 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.data; + +import static org.junit.Assert.assertEquals; +import org.junit.*; + +/** + * + * @author Thomas Wuerthinger + */ +public class ChangedEventTest { + + public ChangedEventTest() { + } + + @BeforeClass + public static void setUpClass() throws Exception { + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of addListener method, of class Event. + */ + @Test + public void testBase() { + + ChangedEvent e = new ChangedEvent<>(5); + final int[] fireCount = new int[1]; + + e.addListener(new ChangedListener() { + @Override + public void changed(Integer s) { + assertEquals(s.intValue(), 5); + fireCount[0]++; + } + }); + + e.fire(); + assertEquals(1, fireCount[0]); + + e.fire(); + assertEquals(2, fireCount[0]); + + e.beginAtomic(); + + e.fire(); + assertEquals(2, fireCount[0]); + + e.fire(); + assertEquals(2, fireCount[0]); + + e.fire(); + assertEquals(2, fireCount[0]); + + e.endAtomic(); + assertEquals(3, fireCount[0]); + + } + + +} \ No newline at end of file diff -r 6cb549627941 -r 015fb895586b visualizer/Data/test/unit/src/com/sun/hotspot/igv/data/ControllableChangedListenerTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/test/unit/src/com/sun/hotspot/igv/data/ControllableChangedListenerTest.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,93 @@ +/* + * 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.data; + +import static org.junit.Assert.*; +import org.junit.*; + +/** + * + * @author Thomas Wuerthinger + */ +public class ControllableChangedListenerTest { + + public ControllableChangedListenerTest() { + } + + @BeforeClass + public static void setUpClass() throws Exception { + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of isEnabled method, of class ControllableChangedListener. + */ + @Test + public void testBase() { + + final boolean[] hasFired = new boolean[1]; + final boolean[] shouldFire = new boolean[1]; + final Integer[] valueToFire = new Integer[1]; + ControllableChangedListener l = new ControllableChangedListener() { + + @Override + public void filteredChanged(Integer value) { + assertTrue(shouldFire[0]); + assertEquals(valueToFire[0], value); + hasFired[0] = true; + } + }; + + shouldFire[0] = true; + valueToFire[0] = 1; + hasFired[0] = false; + l.changed(1); + assertTrue(hasFired[0]); + + shouldFire[0] = false; + hasFired[0] = false; + l.setEnabled(false); + l.changed(1); + assertFalse(hasFired[0]); + + shouldFire[0] = true; + valueToFire[0] = 1; + hasFired[0] = false; + l.setEnabled(true); + l.changed(1); + assertTrue(hasFired[0]); + } +} \ No newline at end of file diff -r 6cb549627941 -r 015fb895586b visualizer/Data/test/unit/src/com/sun/hotspot/igv/data/GroupTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/test/unit/src/com/sun/hotspot/igv/data/GroupTest.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,74 @@ +/* + * 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.data; + +import java.util.Arrays; +import java.util.HashSet; +import static org.junit.Assert.assertEquals; +import org.junit.*; + +/** + * + * @author Thomas Wuerthinger + */ +public class GroupTest { + + public GroupTest() { + } + + @BeforeClass + public static void setUpClass() throws Exception { + + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of getAllNodes method, of class Group. + */ + @Test + public void testGetAllNodes() { + final Group g = new Group(null); + final InputGraph graph1 = new InputGraph("1"); + final InputGraph graph2 = new InputGraph("2"); + g.addElement(graph1); + g.addElement(graph2); + graph1.addNode(new InputNode(1)); + graph1.addNode(new InputNode(2)); + graph2.addNode(new InputNode(2)); + graph2.addNode(new InputNode(3)); + assertEquals(g.getAllNodes(), new HashSet(Arrays.asList(1, 2, 3))); + } +} \ No newline at end of file diff -r 6cb549627941 -r 015fb895586b visualizer/Data/test/unit/src/com/sun/hotspot/igv/data/InputGraphTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/test/unit/src/com/sun/hotspot/igv/data/InputGraphTest.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,211 @@ +/* + * 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.data; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import org.junit.*; + +/** + * + * @author Thomas Wuerthinger + */ +public class InputGraphTest { + + /** + * 1 + * / \ + * 2 3 + * \ | 5 + * \ | / + * 4 + */ + private static InputGraph referenceGraph; + + private static InputGraph emptyGraph; + + private static final InputNode N1 = new InputNode(1); + private static final InputNode N2 = new InputNode(2); + private static final InputNode N3 = new InputNode(3); + private static final InputNode N4 = new InputNode(4); + private static final InputNode N5 = new InputNode(5); + private static final InputEdge E12 = new InputEdge((char)0, 1, 2); + private static final InputEdge E13 = new InputEdge((char)0, 1, 3); + private static final InputEdge E24 = new InputEdge((char)0, 2, 4); + private static final InputEdge E34 = new InputEdge((char)0, 3, 4); + private static final InputEdge E54 = new InputEdge((char)0, 5, 4); + + public InputGraphTest() { + } + + @BeforeClass + public static void setUpClass() throws Exception { + Group group = new Group(null); + + emptyGraph = new InputGraph("emptyGraph"); + group.addElement(emptyGraph); + + referenceGraph = new InputGraph("referenceGraph"); + group.addElement(referenceGraph); + referenceGraph.addNode(N1); + referenceGraph.addNode(N2); + referenceGraph.addNode(N3); + referenceGraph.addNode(N4); + referenceGraph.addNode(N5); + + referenceGraph.addEdge(E12); + referenceGraph.addEdge(E13); + referenceGraph.addEdge(E24); + referenceGraph.addEdge(E34); + referenceGraph.addEdge(E54); + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of equals method, of class InputGraph. + */ + @Test + public void testEquals() { + + Group parentA = new Group(null); + InputGraph a = new InputGraph("graph"); + parentA.addElement(a); + + Group parentB = new Group(null); + InputGraph b = new InputGraph("graph"); + parentB.addElement(b); + + InputGraph c = new InputGraph("graph"); + parentB.addElement(b); + + Util.assertGraphEquals(a, b); + Util.assertGraphEquals(b, c); + + a.addNode(new InputNode(1)); + Util.assertGraphNotEquals(a, b); + + b.addNode(new InputNode(1)); + Util.assertGraphEquals(a, b); + } + + /** + * Test of findRootNodes method, of class InputGraph. + */ + @Test + public void testFindRootNodes() { + assertTrue(emptyGraph.findRootNodes().isEmpty()); + + List result = referenceGraph.findRootNodes(); + assertTrue(result.size() == 2); + assertTrue(result.contains(N1)); + assertTrue(result.contains(N5)); + } + + /** + * Test of findAllOutgoingEdges method, of class InputGraph. + */ + @Test + public void testFindAllOutgoingEdges() { + assertTrue(emptyGraph.findAllOutgoingEdges().isEmpty()); + + Map> result = referenceGraph.findAllOutgoingEdges(); + assertTrue(result.size() == 5); + assertEquals(result.get(N1), Arrays.asList(E12, E13)); + assertEquals(result.get(N2), Arrays.asList(E24)); + assertEquals(result.get(N3), Arrays.asList(E34)); + assertEquals(result.get(N4), Arrays.asList()); + assertEquals(result.get(N5), Arrays.asList(E54)); + } + + /** + * Test of findAllIngoingEdges method, of class InputGraph. + */ + @Test + public void testFindAllIngoingEdges() { + assertTrue(emptyGraph.findAllIngoingEdges().isEmpty()); + + Map> result = referenceGraph.findAllIngoingEdges(); + assertTrue(result.size() == 5); + assertEquals(result.get(N1), Arrays.asList()); + assertEquals(result.get(N2), Arrays.asList(E12)); + assertEquals(result.get(N3), Arrays.asList(E13)); + assertEquals(result.get(N4), Arrays.asList(E24, E34, E54)); + assertEquals(result.get(N5), Arrays.asList()); + } + + /** + * Test of findOutgoingEdges method, of class InputGraph. + */ + @Test + public void testFindOutgoingEdges() { + assertTrue(emptyGraph.findOutgoingEdges(new InputNode(1)).isEmpty()); + + assertEquals(referenceGraph.findOutgoingEdges(N1), Arrays.asList(E12, E13)); + assertEquals(referenceGraph.findOutgoingEdges(N2), Arrays.asList(E24)); + assertEquals(referenceGraph.findOutgoingEdges(N3), Arrays.asList(E34)); + assertEquals(referenceGraph.findOutgoingEdges(N4), Arrays.asList()); + assertEquals(referenceGraph.findOutgoingEdges(N5), Arrays.asList(E54)); + } + + /** + * Test of getNext method, of class InputGraph. + */ + @Test + public void testGetNextPrev() { + final Group group = new Group(null); + + final InputGraph a = new InputGraph("a"); + + final InputGraph b = new InputGraph("b"); + + final InputGraph c = new InputGraph("c"); + group.addElement(a); + group.addElement(b); + group.addElement(c); + + assertEquals(null, a.getPrev()); + assertEquals(b, a.getNext()); + + assertEquals(a, b.getPrev()); + assertEquals(c, b.getNext()); + + assertEquals(b, c.getPrev()); + assertEquals(null, c.getNext()); + } +} \ No newline at end of file diff -r 6cb549627941 -r 015fb895586b visualizer/Data/test/unit/src/com/sun/hotspot/igv/data/InputMethodTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/test/unit/src/com/sun/hotspot/igv/data/InputMethodTest.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,93 @@ +/* + * 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.data; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.assertThat; +import org.junit.*; + +/** + * + * @author Thomas + */ +public class InputMethodTest { + + public InputMethodTest() { + } + + @BeforeClass + public static void setUpClass() throws Exception { + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + + /** + * Test of getBytecodes method, of class InputMethod. + */ + @Test + public void testGetSetBytecodes() { + + final String input = "0 iload_0\n" + + "1 iconst_1\n" + + "2 if_icmpne 7\n" + + "5 iconst_1\n" + + "6 ireturn\n" + + "7 iconst_0\n" + + "8 ireturn"; + + final Group g = new Group(null); + InputMethod m = new InputMethod(g, "name", "shortName", -1); + m.setBytecodes(input); + + assertThat(m.getBytecodes().size(), is(7)); + + assertThat(m.getBytecodes().get(0).getBci(), is(0)); + assertThat(m.getBytecodes().get(1).getBci(), is(1)); + assertThat(m.getBytecodes().get(2).getBci(), is(2)); + assertThat(m.getBytecodes().get(3).getBci(), is(5)); + + assertThat(m.getBytecodes().get(0).getName(), is("iload_0")); + assertThat(m.getBytecodes().get(1).getName(), is("iconst_1")); + assertThat(m.getBytecodes().get(2).getName(), is("if_icmpne 7")); + assertThat(m.getBytecodes().get(6).getName(), is("ireturn")); + + assertThat(m.getBytecodes().get(2).getInlined(), nullValue()); + assertThat(m.getBytecodes().get(6).getInlined(), nullValue()); + } + + +} \ No newline at end of file diff -r 6cb549627941 -r 015fb895586b visualizer/Data/test/unit/src/com/sun/hotspot/igv/data/PairTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/test/unit/src/com/sun/hotspot/igv/data/PairTest.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,98 @@ +/* + * 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.data; + +import static org.junit.Assert.*; +import org.junit.*; + +/** + * + * @author Thomas Wuerthinger + */ +public class PairTest { + + public PairTest() { + } + + @BeforeClass + public static void setUpClass() throws Exception { + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of getLeft method, of class Pair. + */ + @Test + public void testBase() { + Pair p = new Pair(); + assertTrue(p.getLeft() == null); + assertTrue(p.getRight() == null); + assertEquals("[null/null]", p.toString()); + assertFalse(p.equals(null)); + + Pair p2 = new Pair(1, 2); + assertTrue(p2.getLeft().intValue() == 1); + assertTrue(p2.getRight().intValue() == 2); + assertFalse(p.equals(p2)); + assertFalse(p2.equals(p)); + assertFalse(p.hashCode() == p2.hashCode()); + assertEquals("[1/2]", p2.toString()); + + Pair p3 = new Pair(1, 2); + assertTrue(p2.equals(p3)); + assertTrue(p2.hashCode() == p3.hashCode()); + + p2.setLeft(2); + assertFalse(p2.equals(p3)); + assertTrue(p2.getLeft().intValue() == 2); + assertTrue(p2.getRight().intValue() == 2); + assertFalse(p2.hashCode() == p3.hashCode()); + assertEquals("[2/2]", p2.toString()); + + p2.setRight(1); + assertFalse(p2.equals(p3)); + assertTrue(p2.getLeft().intValue() == 2); + assertTrue(p2.getRight().intValue() == 1); + assertFalse(p2.hashCode() == p3.hashCode()); + assertEquals("[2/1]", p2.toString()); + + p3.setLeft(2); + p3.setRight(1); + assertTrue(p2.hashCode() == p3.hashCode()); + assertTrue(p2.equals(p3)); + } +} \ No newline at end of file diff -r 6cb549627941 -r 015fb895586b visualizer/Data/test/unit/src/com/sun/hotspot/igv/data/PropertiesTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/test/unit/src/com/sun/hotspot/igv/data/PropertiesTest.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,401 @@ +/* + * 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.data; + +import com.sun.hotspot.igv.data.Properties.InvertPropertyMatcher; +import com.sun.hotspot.igv.data.Properties.PropertyMatcher; +import com.sun.hotspot.igv.data.Properties.PropertySelector; +import com.sun.hotspot.igv.data.Properties.RegexpPropertyMatcher; +import com.sun.hotspot.igv.data.Properties.StringPropertyMatcher; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import junit.framework.TestCase; + +/** + * + * @author Thomas Wuerthinger + */ +public class PropertiesTest extends TestCase { + + + + public PropertiesTest(String testName) { + super(testName); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + + /** + * Test of equals method, of class Properties. + */ + public void testEquals() { + Properties a = new Properties(); + assertFalse(a.equals(null)); + assertTrue(a.equals(a)); + + Properties b = new Properties(); + assertTrue(a.equals(b)); + assertTrue(a.hashCode() == b.hashCode()); + + a.setProperty("p1", "1"); + assertFalse(a.equals(b)); + assertFalse(b.equals(a)); + assertFalse(a.hashCode() == b.hashCode()); + + b.setProperty("p1", "1"); + assertTrue(a.equals(b)); + assertTrue(a.hashCode() == b.hashCode()); + + Properties c = new Properties(a); + assertTrue(c.equals(a)); + assertTrue(c.equals(b)); + + c.setProperty("p1", "2"); + assertFalse(c.equals(b)); + assertFalse(c.hashCode() == b.hashCode()); + assertFalse(c.equals(a)); + assertFalse(c.hashCode() == a.hashCode()); + + a.setProperty("p2", "2"); + Properties d = new Properties(); + d.setProperty("p2", "2"); + d.setProperty("p1", "1"); + assertTrue(d.equals(a)); + } + + /** + * Test of selectSingle method, of class Properties. + */ + public void testSelectSingle() { + + final boolean[] called = new boolean[1]; + final String v = "2"; + final String n = "p2"; + + PropertyMatcher matcher = new PropertyMatcher() { + + @Override + public String getName() { + assertFalse(called[0]); + called[0] = true; + return n; + } + + @Override + public boolean match(String value) { + assertTrue(v.equals(value)); + return true; + } + }; + + Properties instance = new Properties(); + instance.setProperty("p1", "1"); + instance.setProperty(n, v); + instance.setProperty("p3", "3"); + Property result = instance.selectSingle(matcher); + assertEquals(result, new Property(n, v)); + + + called[0] = false; + PropertyMatcher matcher2 = new PropertyMatcher() { + + @Override + public String getName() { + assertFalse(called[0]); + called[0] = true; + return n; + } + + @Override + public boolean match(String value) { + return false; + } + }; + + + Property result2 = instance.selectSingle(matcher2); + assertTrue(result2 == null); + } + + /** + * Test of get method, of class Properties. + */ + public void testGet() { + Properties instance = new Properties(); + instance.setProperty("p1", "1"); + assertEquals("1", instance.get("p1")); + assertEquals(null, instance.get("p2")); + } + + /** + * Test of getProperties method, of class Properties. + */ + public void testIterator() { + Properties instance = new Properties(); + instance.setProperty("p1", "1"); + instance.setProperty("p2", "2"); + Iterator result = instance.iterator(); + assertTrue(result.hasNext()); + assertEquals(new Property("p1", "1"), result.next()); + assertTrue(result.hasNext()); + assertEquals(new Property("p2", "2"), result.next()); + assertFalse(result.hasNext()); + assertTrue(result.next() == null); + + try { + result.remove(); + fail(); + } catch(UnsupportedOperationException e) {} + } + + /** + * Test of add method, of class Properties. + */ + public void testAdd() { + Properties a = new Properties(); + a.setProperty("p1", "1"); + a.setProperty("p2", "2"); + + Properties b = new Properties(); + b.setProperty("p1", "1"); + + Properties c = new Properties(); + c.setProperty("p2", "2"); + + assertFalse(a.equals(b)); + b.add(c); + + assertTrue(a.equals(b)); + + b.setProperty("p3", null); + assertTrue(a.equals(b)); + + Properties empty = new Properties(); + b.add(empty); + assertTrue(a.equals(b)); + + empty.add(b); + assertTrue(a.equals(empty)); + } + + + /** + * Test the multiple argument constructors. + */ + public void testConstructors() { + Properties a = new Properties("p1", "1", "p2", "2", "p3", "3"); + Properties b = new Properties("p1", "1", "p2", "2"); + Properties c = new Properties("p1", "1"); + + assertTrue(a.get("p3").equals("3")); + assertTrue(b.get("p2").equals("2")); + assertTrue(b.get("p1").equals("1")); + + b.setProperty("p3", "3"); + c.setProperty("p2", "2"); + c.setProperty("p3", "3"); + + assertTrue(a.equals(b)); + assertTrue(a.equals(c)); + } + + /** + * Test Entity class + */ + public void testEntity() { + + Properties p = new Properties(); + + Properties.Entity entity = new Properties.Entity(); + assertEquals(entity.getProperties(), p); + + entity.getProperties().setProperty("p1", "1"); + Properties.Entity entity2 = new Properties.Entity(entity); + assertEquals(entity.getProperties(), entity2.getProperties()); + } + + /** + * Test property selector + */ + public void testPropertySelector() { + final Collection c = new ArrayList<>(); + + final Properties.Entity e1 = new Properties.Entity(); + e1.getProperties().setProperty("p1", "1"); + e1.getProperties().setProperty("p2", "2"); + c.add(e1); + + final Properties.Entity e2 = new Properties.Entity(); + e2.getProperties().setProperty("p2", "2"); + e2.getProperties().setProperty("p1", "1"); + e2.getProperties().setProperty("p3", "3"); + c.add(e2); + + final Properties.Entity e3 = new Properties.Entity(); + e3.getProperties().setProperty("p3", "3"); + e3.getProperties().setProperty("p4", "4"); + c.add(e3); + + final PropertySelector sel = new PropertySelector<>(c); + + final StringPropertyMatcher matcher1 = new StringPropertyMatcher("p2", "2"); + assertTrue(sel.selectMultiple(matcher1).size() == 2); + assertTrue(sel.selectMultiple(matcher1).contains(e1)); + assertTrue(sel.selectMultiple(matcher1).contains(e2)); + assertTrue(sel.selectSingle(matcher1).equals(e1) || sel.selectSingle(matcher1).equals(e2)); + + final StringPropertyMatcher matcher2 = new StringPropertyMatcher("p3", "3"); + assertTrue(sel.selectMultiple(matcher2).size() == 2); + assertTrue(sel.selectMultiple(matcher2).contains(e2)); + assertTrue(sel.selectMultiple(matcher2).contains(e3)); + assertTrue(sel.selectSingle(matcher2).equals(e2) || sel.selectSingle(matcher2).equals(e3)); + + final StringPropertyMatcher matcher3 = new StringPropertyMatcher("p4", "4"); + assertTrue(sel.selectMultiple(matcher3).size() == 1); + assertTrue(sel.selectMultiple(matcher3).contains(e3)); + assertTrue(sel.selectSingle(matcher3).equals(e3)); + + final StringPropertyMatcher matcher4 = new StringPropertyMatcher("p5", "5"); + assertTrue(sel.selectMultiple(matcher4).size() == 0); + assertTrue(sel.selectSingle(matcher4) == null); + } + + public void testRemoveProperty() { + final Properties p = new Properties(); + p.setProperty("p1", "1"); + p.setProperty("p2", "2"); + + assertTrue(p.get("p1").equals("1")); + assertTrue(p.get("p2").equals("2")); + + p.setProperty("p1", null); + assertTrue(p.get("p1") == null); + assertTrue(p.get("p2").equals("2")); + + p.setProperty("p2", null); + assertTrue(p.get("p1") == null); + assertTrue(p.get("p2") == null); + + p.setProperty("p3", "3"); + assertTrue(p.get("p1") == null); + assertTrue(p.get("p2") == null); + assertTrue(p.get("p3").equals("3")); + } + + /** + * Test property matchers + */ + public void testPropertyMatchers() { + final StringPropertyMatcher matcher = new StringPropertyMatcher("p1", "1"); + assertTrue(matcher.getName().equals("p1")); + assertTrue(matcher.match("1")); + assertFalse(matcher.match("2")); + try { + matcher.match(null); + fail(); + } catch(IllegalArgumentException e) {} + + try { + new StringPropertyMatcher(null, "**"); + fail(); + } catch(IllegalArgumentException e) {} + + try { + new StringPropertyMatcher("p1", null); + fail(); + } catch(IllegalArgumentException e) {} + + final RegexpPropertyMatcher matcher2 = new RegexpPropertyMatcher("p1", "C.*"); + assertTrue(matcher2.getName().equals("p1")); + assertTrue(matcher2.match("C")); + assertTrue(matcher2.match("Casdf")); + assertFalse(matcher2.match(" C")); + assertFalse(matcher2.match("c")); + assertFalse(matcher2.match("asdfC")); + + try { + matcher2.match(null); + fail(); + } catch(IllegalArgumentException e) {} + + try { + new RegexpPropertyMatcher("p1", "**"); + fail(); + } catch(IllegalArgumentException e) {} + + try { + new RegexpPropertyMatcher(null, "1"); + fail(); + } catch(IllegalArgumentException e) {} + + try { + new RegexpPropertyMatcher("p1", null); + fail(); + } catch(IllegalArgumentException e) {} + + final InvertPropertyMatcher matcher3 = new InvertPropertyMatcher(matcher); + assertTrue(matcher3.getName().equals("p1")); + assertFalse(matcher3.match("1")); + assertTrue(matcher3.match("2")); + assertFalse(matcher3.match(null)); + } + + public void testToString() { + Properties p = new Properties(); + assertEquals(p.toString(), "[]"); + + p.setProperty("p1", "1"); + assertEquals(p.toString(), "[p1=1]"); + + Properties p2 = new Properties(); + p2.setProperty("p1", "1"); + p2.setProperty("p2", "2"); + assertEquals(p2.toString(), "[p1=1, p2=2]"); + + Properties p3 = new Properties(); + p3.setProperty("p2", "2"); + p3.setProperty("p1", "1"); + assertEquals(p3.toString(), "[p1=1, p2=2]"); + + p3.setProperty("p0", "0"); + assertEquals(p3.toString(), "[p0=0, p1=1, p2=2]"); + + p2.setProperty("p1", null); + assertEquals(p2.toString(), "[p2=2]"); + + p2.setProperty("p2", null); + assertEquals(p2.toString(), "[]"); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/test/unit/src/com/sun/hotspot/igv/data/PropertyTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/test/unit/src/com/sun/hotspot/igv/data/PropertyTest.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,116 @@ +/* + * 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.data; + +import static org.junit.Assert.*; +import org.junit.*; + +/** + * + * @author Thomas Wuerthinger + */ +public class PropertyTest { + + public PropertyTest() { + } + + @BeforeClass + public static void setUpClass() throws Exception { + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of getName method, of class Property. + */ + @Test + public void testGetNameAndValue() { + final Property p = new Property("name", "value"); + assertEquals(p.getName(), "name"); + assertEquals(p.getValue(), "value"); + + try { + new Property(null, "value"); + fail(); + } catch(IllegalArgumentException e) { + } + + + try { + new Property("name", null); + fail(); + } catch(IllegalArgumentException e) { + } + } + + /** + * Test of toString method, of class Property. + */ + @Test + public void testToString() { + final Property p = new Property("name", "value"); + assertEquals(p.toString(), "name=value"); + } + + /** + * Test of equals method, of class Property. + */ + @Test + public void testEquals() { + final Property p = new Property("name", "value"); + final Object o = new Object(); + assertFalse(p.equals(o)); + assertFalse(p.equals(null)); + assertTrue(p.equals(p)); + + final Property p2 = new Property("name", "value1"); + assertFalse(p.equals(p2)); + assertTrue(p.hashCode() != p2.hashCode()); + + final Property p3 = new Property("name2", "value"); + assertFalse(p.equals(p3)); + assertTrue(p.hashCode() != p3.hashCode()); + assertTrue(p2.hashCode() != p3.hashCode()); + + final Property p4 = new Property("name", "value"); + assertEquals(p, p4); + assertEquals(p.hashCode(), p4.hashCode()); + + final Property p5 = new Property("value", "name"); + assertFalse(p.equals(p5)); + assertTrue(p.hashCode() != p5.hashCode()); + } +} \ No newline at end of file diff -r 6cb549627941 -r 015fb895586b visualizer/Data/test/unit/src/com/sun/hotspot/igv/data/SourceTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/test/unit/src/com/sun/hotspot/igv/data/SourceTest.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,79 @@ +/* + * 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.data; + +import java.util.Arrays; +import java.util.LinkedHashSet; +import static org.junit.Assert.assertEquals; +import org.junit.*; + +/** + * + * @author Thomas + */ +public class SourceTest { + + public SourceTest() { + } + + @BeforeClass + public static void setUpClass() throws Exception { + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of getSourceNodes method, of class Source. + */ + @Test + public void testBase() { + final Source s = new Source(); + + final InputNode N1 = new InputNode(1); + final InputNode N2 = new InputNode(2); + + s.addSourceNode(N1); + assertEquals(s.getSourceNodes(), Arrays.asList(N1)); + assertEquals(s.getSourceNodesAsSet(), new LinkedHashSet<>(Arrays.asList(1))); + + s.addSourceNode(N2); + assertEquals(s.getSourceNodes(), Arrays.asList(N1, N2)); + assertEquals(s.getSourceNodesAsSet(), new LinkedHashSet<>(Arrays.asList(1, 2))); + + s.addSourceNode(N1); + assertEquals(s.getSourceNodes(), Arrays.asList(N1, N2)); + assertEquals(s.getSourceNodesAsSet(), new LinkedHashSet<>(Arrays.asList(1, 2))); + } +} \ No newline at end of file diff -r 6cb549627941 -r 015fb895586b visualizer/Data/test/unit/src/com/sun/hotspot/igv/data/Util.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/test/unit/src/com/sun/hotspot/igv/data/Util.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,126 @@ +/* + * 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.data; + +import static org.junit.Assert.*; + +/** + * + * @author Thomas Wuerthinger + */ +public class Util { + + public static void assertGraphDocumentNotEquals(GraphDocument a, GraphDocument b) { + try { + assertGraphDocumentEquals(a, b); + } catch(AssertionError e) { + return; + } + + fail("Graphs documents are equal!"); + } + + public static void assertGraphDocumentEquals(GraphDocument a, GraphDocument b) { + + if (a.getElements().size() != b.getElements().size()) { + fail(); + } + + int z = 0; + for (FolderElement e : b.getElements()) { + + if (e instanceof Group) { + Group g = (Group) e; + Group thisG = (Group) a.getElements().get(z); + assertGroupEquals(thisG, g); + z++; + } + } + } + + public static void assertGroupNotEquals(Group a, Group b) { + try { + assertGroupEquals(a, b); + } catch(AssertionError e) { + return; + } + + fail("Groups are equal!"); + } + + public static void assertGroupEquals(Group a, Group b) { + + if (a.getGraphsCount() != b.getGraphsCount()) { + fail(); + } + + int z = 0; + for (InputGraph graph : a.getGraphs()) { + InputGraph otherGraph = b.getGraphs().get(z); + assertGraphEquals(graph, otherGraph); + z++; + } + + if (a.getMethod() == null || b.getMethod() == null) { + if (a.getMethod() != b.getMethod()) { + fail(); + } + } else { + if (!a.getMethod().equals(b.getMethod())) { + fail(); + } + } + } + + public static void assertGraphNotEquals(InputGraph a, InputGraph b) { + try { + assertGraphEquals(a, b); + } catch(AssertionError e) { + return; + } + + fail("Graphs are equal!"); + } + + public static void assertGraphEquals(InputGraph a, InputGraph b) { + + if(!a.getNodesAsSet().equals(b.getNodesAsSet())) { + fail(); + } + + if (!a.getEdges().equals(b.getEdges())) { + fail(); + } + + if (a.getBlocks().equals(b.getBlocks())) { + fail(); + } + + for (InputNode n : a.getNodes()) { + assertEquals(a.getBlock(n), b.getBlock(n)); + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Data/test/unit/src/com/sun/hotspot/igv/data/serialization/ParserTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Data/test/unit/src/com/sun/hotspot/igv/data/serialization/ParserTest.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,223 @@ +/* + * 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.data.serialization; + +import com.sun.hotspot.igv.data.*; +import java.io.CharArrayWriter; +import java.io.StringReader; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import org.junit.*; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +/** + * + * @author Thomas Wuerthinger + */ +public class ParserTest { + + public ParserTest() { + } + + @BeforeClass + public static void setUpClass() throws Exception { + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + private void test(GraphDocument document) { + final Printer printer = new Printer(); + final CharArrayWriter writer = new CharArrayWriter(); + printer.export(writer, document); + test(document, writer.toString()); + } + + private void test(GraphDocument document, String xmlString) { + + StringReader sr = new StringReader(xmlString); + InputSource is = new InputSource(sr); + + try { + Parser parser = new Parser(); + final GraphDocument parsedDocument = parser.parse(is, null); + Util.assertGraphDocumentEquals(document, parsedDocument); + } catch (SAXException ex) { + fail(ex.toString()); + } + } + + private void testBoth(GraphDocument document, String xmlString) { + test(document); + test(document, xmlString); + } + + /** + * Test of graph document serialization + */ + @Test + public void testSerialization() { + final GraphDocument doc = new GraphDocument(); + + test(doc); + + final Group group1 = new Group(doc); + doc.addElement(group1); + test(doc); + + final Group group2 = new Group(doc); + doc.addElement(group2); + test(doc); + + final InputGraph graph = new InputGraph(""); + group1.addElement(graph); + test(doc); + + graph.addNode(new InputNode(0)); + test(doc); + + graph.addNode(new InputNode(1)); + test(doc); + + graph.addNode(new InputNode(2)); + test(doc); + + graph.addNode(new InputNode(3)); + test(doc); + + graph.addEdge(new InputEdge((char)0, (char)0, 0, 1)); + test(doc); + + graph.addEdge(new InputEdge((char)1, (char)1, 0, 1)); + test(doc); + + graph.addEdge(new InputEdge((char)0, (char)0, 1, 2)); + test(doc); + + graph.addEdge(new InputEdge((char)0, (char)0, 2, 3)); + test(doc); + + group1.setMethod(new InputMethod(group1, "testMethod", "tM", 1)); + test(doc); + + final InputBlock b1 = graph.addBlock("1"); + b1.addNode(0); + b1.addNode(1); + + final InputBlock b2 = graph.addBlock("2"); + b2.addNode(2); + b2.addNode(3); + test(doc); + + final GraphDocument document2 = new GraphDocument(); + doc.addGraphDocument(document2); + test(doc); + assertTrue(doc.getElements().size() == 2); + + final Group group3 = new Group(document2); + document2.addElement(group3); + doc.addGraphDocument(document2); + assertTrue(doc.getElements().size() == 3); + assertTrue(document2.getElements().size() == 0); + + doc.clear(); + test(doc); + Util.assertGraphDocumentEquals(doc, new GraphDocument()); + } + + @Test + public void testSimpleExport() { + GraphDocument document = new GraphDocument(); + Group g = new Group(document); + document.addElement(g); + + InputGraph graph = new InputGraph("TestGraph"); + g.addElement(graph); + graph.getProperties().setProperty("testName", "testValue"); + + InputNode n1 = new InputNode(0); + InputNode n2 = new InputNode(1); + InputEdge e1 = new InputEdge((char)0, 0, 1); + InputEdge e2 = new InputEdge((char)1, 0, 1); + graph.addNode(n1); + graph.addNode(n2); + graph.addEdge(e1); + graph.addEdge(e2); + + test(document); + } + + @Test + public void testComplexExport() { + + GraphDocument document = new GraphDocument(); + Group g = new Group(document); + document.addElement(g); + + InputGraph graph = new InputGraph("TestGraph"); + g.addElement(graph); + graph.getProperties().setProperty("testName", "testValue"); + + InputNode n1 = new InputNode(0); + InputNode n2 = new InputNode(1); + InputEdge e1 = new InputEdge((char)0, 0, 0); + InputEdge e2 = new InputEdge((char)1, 1, 1); + graph.addNode(n1); + graph.addNode(n2); + graph.addEdge(e1); + graph.addEdge(e2); + + InputGraph graph2 = new InputGraph("TestGraph2"); + g.addElement(graph2); + graph2.addNode(n1); + InputNode n3 = new InputNode(2); + graph2.addNode(n3); + InputEdge e3 = new InputEdge((char)0, 0, 2); + graph2.addEdge(e3); + + test(document); + } + + + /** + * Test of parse method, of class Parser. + */ + @Test + public void testParse() { + testBoth(new GraphDocument(), ""); + } + +} \ No newline at end of file diff -r 6cb549627941 -r 015fb895586b visualizer/Difference/manifest.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Difference/manifest.mf Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +OpenIDE-Module: com.sun.hotspot.igv.difference +OpenIDE-Module-Localizing-Bundle: com/sun/hotspot/igv/difference/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff -r 6cb549627941 -r 015fb895586b visualizer/Difference/src/com/sun/hotspot/igv/difference/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Difference/src/com/sun/hotspot/igv/difference/Bundle.properties Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,1 @@ +OpenIDE-Module-Name=Difference diff -r 6cb549627941 -r 015fb895586b visualizer/Difference/src/com/sun/hotspot/igv/difference/Difference.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Difference/src/com/sun/hotspot/igv/difference/Difference.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,381 @@ +/* + * 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.difference; + +import com.sun.hotspot.igv.data.Properties; +import com.sun.hotspot.igv.data.*; +import com.sun.hotspot.igv.data.services.Scheduler; +import java.util.*; +import org.openide.util.Lookup; + +/** + * + * @author Thomas Wuerthinger + */ +public class Difference { + + public static final String PROPERTY_STATE = "state"; + public static final String VALUE_NEW = "new"; + public static final String VALUE_CHANGED = "changed"; + public static final String VALUE_SAME = "same"; + public static final String VALUE_DELETED = "deleted"; + public static final String OLD_PREFIX = "OLD_"; + public static final String MAIN_PROPERTY = "name"; + public static final double LIMIT = 100.0; + public static final String[] IGNORE_PROPERTIES = new String[]{"idx", "debug_idx"}; + + public static InputGraph createDiffGraph(InputGraph a, InputGraph b) { + if (a.getGroup() == b.getGroup()) { + return createDiffSameGroup(a, b); + } else { + return createDiff(a, b); + } + } + + private static InputGraph createDiffSameGroup(InputGraph a, InputGraph b) { + Map keyMapB = new HashMap<>(b.getNodes().size()); + for (InputNode n : b.getNodes()) { + Integer key = n.getId(); + assert !keyMapB.containsKey(key); + keyMapB.put(key, n); + } + + Set pairs = new HashSet<>(); + + for (InputNode n : a.getNodes()) { + Integer key = n.getId(); + + + if (keyMapB.containsKey(key)) { + InputNode nB = keyMapB.get(key); + pairs.add(new NodePair(n, nB)); + } + } + + return createDiff(a, b, pairs); + } + + private static void ensureScheduled(InputGraph a) { + if (a.getBlocks().isEmpty()) { + Scheduler s = Lookup.getDefault().lookup(Scheduler.class); + a.clearBlocks(); + s.schedule(a); + a.ensureNodesInBlocks(); + } + } + + private static InputGraph createDiff(InputGraph a, InputGraph b, Set pairs) { + ensureScheduled(a); + ensureScheduled(b); + + Group g = new Group(null); + g.setMethod(a.getGroup().getMethod()); + if (a.getGroup() == b.getGroup()) { + g.getProperties().add(a.getGroup().getProperties()); + } else { + // copy properties that have the same value in both groups + Properties bps = b.getGroup().getProperties(); + for (Property p : a.getGroup().getProperties()) { + String value = p.getValue(); + if (value != null && value.equals(bps.get(p.getName()))) { + g.getProperties().setProperty(p.getName(), value); + } + } + } + g.getProperties().setProperty("name", "Difference"); + InputGraph graph = new InputGraph(a.getName() + ", " + b.getName()); + g.addElement(graph); + + Map blocksMap = new HashMap<>(); + for (InputBlock blk : a.getBlocks()) { + InputBlock diffblk = graph.addBlock(blk.getName()); + blocksMap.put(blk, diffblk); + } + for (InputBlock blk : b.getBlocks()) { + InputBlock diffblk = graph.getBlock(blk.getName()); + if (diffblk == null) { + diffblk = graph.addBlock(blk.getName()); + } + blocksMap.put(blk, diffblk); + } + + // Difference between block edges + Set> aEdges = new HashSet<>(); + for (InputBlockEdge edge : a.getBlockEdges()) { + aEdges.add(new Pair<>(edge.getFrom().getName(), edge.getTo().getName())); + } + for (InputBlockEdge bEdge : b.getBlockEdges()) { + InputBlock from = bEdge.getFrom(); + InputBlock to = bEdge.getTo(); + Pair pair = new Pair<>(from.getName(), to.getName()); + if (aEdges.contains(pair)) { + // same + graph.addBlockEdge(blocksMap.get(from), blocksMap.get(to)); + aEdges.remove(pair); + } else { + // added + InputBlockEdge edge = graph.addBlockEdge(blocksMap.get(from), blocksMap.get(to)); + edge.setState(InputBlockEdge.State.NEW); + } + } + for (Pair deleted : aEdges) { + // removed + InputBlock from = graph.getBlock(deleted.getLeft()); + InputBlock to = graph.getBlock(deleted.getRight()); + InputBlockEdge edge = graph.addBlockEdge(from, to); + edge.setState(InputBlockEdge.State.DELETED); + } + + Set nodesA = new HashSet<>(a.getNodes()); + Set nodesB = new HashSet<>(b.getNodes()); + + Map inputNodeMap = new HashMap<>(pairs.size()); + for (NodePair p : pairs) { + InputNode n = p.getLeft(); + assert nodesA.contains(n); + InputNode nB = p.getRight(); + assert nodesB.contains(nB); + + nodesA.remove(n); + nodesB.remove(nB); + InputNode n2 = new InputNode(n); + inputNodeMap.put(n, n2); + inputNodeMap.put(nB, n2); + graph.addNode(n2); + InputBlock block = blocksMap.get(a.getBlock(n)); + block.addNode(n2.getId()); + markAsChanged(n2, n, nB); + } + + for (InputNode n : nodesA) { + InputNode n2 = new InputNode(n); + graph.addNode(n2); + InputBlock block = blocksMap.get(a.getBlock(n)); + block.addNode(n2.getId()); + markAsDeleted(n2); + inputNodeMap.put(n, n2); + } + + int curIndex = 0; + for (InputNode n : nodesB) { + InputNode n2 = new InputNode(n); + + // Find new ID for node of b, does not change the id property + while (graph.getNode(curIndex) != null) { + curIndex++; + } + + n2.setId(curIndex); + graph.addNode(n2); + InputBlock block = blocksMap.get(b.getBlock(n)); + block.addNode(n2.getId()); + markAsNew(n2); + inputNodeMap.put(n, n2); + } + + Collection edgesA = a.getEdges(); + Collection edgesB = b.getEdges(); + + Set newEdges = new HashSet<>(); + + for (InputEdge e : edgesA) { + int from = e.getFrom(); + int to = e.getTo(); + InputNode nodeFrom = inputNodeMap.get(a.getNode(from)); + InputNode nodeTo = inputNodeMap.get(a.getNode(to)); + char fromIndex = e.getFromIndex(); + char toIndex = e.getToIndex(); + + InputEdge newEdge = new InputEdge(fromIndex, toIndex, nodeFrom.getId(), nodeTo.getId()); + if (!newEdges.contains(newEdge)) { + markAsDeleted(newEdge); + newEdges.add(newEdge); + graph.addEdge(newEdge); + } + } + + for (InputEdge e : edgesB) { + int from = e.getFrom(); + int to = e.getTo(); + InputNode nodeFrom = inputNodeMap.get(b.getNode(from)); + InputNode nodeTo = inputNodeMap.get(b.getNode(to)); + char fromIndex = e.getFromIndex(); + char toIndex = e.getToIndex(); + + InputEdge newEdge = new InputEdge(fromIndex, toIndex, nodeFrom.getId(), nodeTo.getId()); + if (!newEdges.contains(newEdge)) { + markAsNew(newEdge); + newEdges.add(newEdge); + graph.addEdge(newEdge); + } else { + newEdges.remove(newEdge); + graph.removeEdge(newEdge); + markAsSame(newEdge); + newEdges.add(newEdge); + graph.addEdge(newEdge); + } + } + + return graph; + } + + private static class NodePair extends Pair { + + + public NodePair(InputNode n1, InputNode n2) { + super(n1, n2); + } + + public double getValue() { + + double result = 0.0; + for (Property p : getLeft().getProperties()) { + double faktor = 1.0; + for (String forbidden : IGNORE_PROPERTIES) { + if (p.getName().equals(forbidden)) { + faktor = 0.1; + break; + } + } + String p2 = getRight().getProperties().get(p.getName()); + result += evaluate(p.getValue(), p2) * faktor; + } + + return result; + } + + private double evaluate(String p, String p2) { + if (p2 == null) { + return 1.0; + } + if (p.equals(p2)) { + return 0.0; + } else { + return (double) (Math.abs(p.length() - p2.length())) / p.length() + 0.5; + } + } + } + + private static InputGraph createDiff(InputGraph a, InputGraph b) { + + Set matched = new HashSet<>(); + + Set pairs = new HashSet<>(); + for (InputNode n : a.getNodes()) { + String s = n.getProperties().get(MAIN_PROPERTY); + if (s == null) { + s = ""; + } + for (InputNode n2 : b.getNodes()) { + String s2 = n2.getProperties().get(MAIN_PROPERTY); + if (s2 == null) { + s2 = ""; + } + + if (s.equals(s2)) { + NodePair p = new NodePair(n, n2); + pairs.add(p); + } + } + } + + Set selectedPairs = new HashSet<>(); + while (pairs.size() > 0) { + + double min = Double.MAX_VALUE; + NodePair minPair = null; + for (NodePair p : pairs) { + double cur = p.getValue(); + if (cur < min) { + minPair = p; + min = cur; + } + } + + if (min > LIMIT) { + break; + } else { + selectedPairs.add(minPair); + + Set toRemove = new HashSet<>(); + for (NodePair p : pairs) { + if (p.getLeft() == minPair.getLeft() || p.getRight() == minPair.getRight()) { + toRemove.add(p); + } + } + pairs.removeAll(toRemove); + } + } + + return createDiff(a, b, selectedPairs); + } + + private static void markAsNew(InputEdge e) { + e.setState(InputEdge.State.NEW); + } + + private static void markAsDeleted(InputEdge e) { + e.setState(InputEdge.State.DELETED); + + } + + private static void markAsSame(InputEdge e) { + e.setState(InputEdge.State.SAME); + } + + private static void markAsChanged(InputNode n, InputNode firstNode, InputNode otherNode) { + + boolean difference = false; + for (Property p : otherNode.getProperties()) { + String s = firstNode.getProperties().get(p.getName()); + if (!p.getValue().equals(s)) { + difference = true; + n.getProperties().setProperty(OLD_PREFIX + p.getName(), p.getValue()); + } + } + + for (Property p : firstNode.getProperties()) { + String s = otherNode.getProperties().get(p.getName()); + if (s == null && p.getValue().length() > 0) { + difference = true; + n.getProperties().setProperty(OLD_PREFIX + p.getName(), ""); + } + } + + if (difference) { + n.getProperties().setProperty(PROPERTY_STATE, VALUE_CHANGED); + } else { + n.getProperties().setProperty(PROPERTY_STATE, VALUE_SAME); + } + } + + private static void markAsDeleted(InputNode n) { + n.getProperties().setProperty(PROPERTY_STATE, VALUE_DELETED); + } + + private static void markAsNew(InputNode n) { + n.getProperties().setProperty(PROPERTY_STATE, VALUE_NEW); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Draw2DLibrary/manifest.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Draw2DLibrary/manifest.mf Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +OpenIDE-Module: org.eclipse.draw2d +OpenIDE-Module-Localizing-Bundle: org/eclipse/draw2d/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff -r 6cb549627941 -r 015fb895586b visualizer/Draw2DLibrary/release/modules/ext/org.eclipse.draw2d_3.1.0.jar Binary file visualizer/Draw2DLibrary/release/modules/ext/org.eclipse.draw2d_3.1.0.jar has changed diff -r 6cb549627941 -r 015fb895586b visualizer/Draw2DLibrary/src/org/eclipse/draw2d/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Draw2DLibrary/src/org/eclipse/draw2d/Bundle.properties Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,1 @@ +OpenIDE-Module-Name=Draw2DLibrary diff -r 6cb549627941 -r 015fb895586b visualizer/Editor/manifest.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Editor/manifest.mf Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,6 @@ +Manifest-Version: 1.0 +OpenIDE-Module: com.oracle.graal.visualizer.editor +OpenIDE-Module-Layer: com/oracle/graal/visualizer/editor/layer.xml +OpenIDE-Module-Localizing-Bundle: com/oracle/graal/visualizer/editor/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff -r 6cb549627941 -r 015fb895586b visualizer/Editor/src/META-INF/services/com.sun.hotspot.igv.data.services.GraphViewer --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Editor/src/META-INF/services/com.sun.hotspot.igv.data.services.GraphViewer Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,1 @@ +com.oracle.graal.visualizer.editor.GraphViewerImplementation diff -r 6cb549627941 -r 015fb895586b visualizer/Editor/src/com/oracle/graal/visualizer/editor/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Editor/src/com/oracle/graal/visualizer/editor/Bundle.properties Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,3 @@ +OpenIDE-Module-Name=Editor +CTL_EditorTopComponent=Compilation +HINT_EditorTopComponent=Shows the snapshots of a single compilation. \ No newline at end of file diff -r 6cb549627941 -r 015fb895586b visualizer/Editor/src/com/oracle/graal/visualizer/editor/CompilationViewer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Editor/src/com/oracle/graal/visualizer/editor/CompilationViewer.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +package com.oracle.graal.visualizer.editor; + +import com.sun.hotspot.igv.graph.Figure; +import java.awt.Component; +import java.awt.Graphics2D; +import java.util.Collection; +import org.openide.awt.UndoRedo; +import org.openide.util.Lookup; + +/** + * + * @author Thomas Wuerthinger + */ +public interface CompilationViewer { + + public Lookup getLookup(); + + public Component getComponent(); +} diff -r 6cb549627941 -r 015fb895586b visualizer/Editor/src/com/oracle/graal/visualizer/editor/CompilationViewerFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Editor/src/com/oracle/graal/visualizer/editor/CompilationViewerFactory.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ +package com.oracle.graal.visualizer.editor; + +import com.sun.hotspot.igv.data.InputGraph; + +public interface CompilationViewerFactory { + CompilationViewer createViewer(InputGraph firstGraph, InputGraph secondGraph); + String getName(); +} diff -r 6cb549627941 -r 015fb895586b visualizer/Editor/src/com/oracle/graal/visualizer/editor/DiagramViewModel.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Editor/src/com/oracle/graal/visualizer/editor/DiagramViewModel.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,289 @@ +/* + * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.visualizer.editor; + +import com.sun.hotspot.igv.data.*; +import com.sun.hotspot.igv.difference.Difference; +import com.sun.hotspot.igv.filter.CustomFilter; +import com.sun.hotspot.igv.filter.FilterChain; +import com.sun.hotspot.igv.graph.Diagram; +import com.sun.hotspot.igv.graph.Figure; +import com.sun.hotspot.igv.settings.Settings; +import java.util.*; + +public class DiagramViewModel { + + private Set hiddenNodes; + private Set onScreenNodes; + private Set selectedNodes; + private FilterChain filterChain; + private FilterChain sequenceFilterChain; + private Diagram diagram; + private InputGraph inputGraph; + private ChangedEvent diagramChangedEvent; + private ChangedEvent viewChangedEvent; + private ChangedEvent hiddenNodesChangedEvent; + private ChangedEvent viewPropertiesChangedEvent; + private boolean showNodeHull; + private final InputGraph secondGraph; + private final InputGraph firstGraph; + private ChangedListener filterChainChangedListener = new ChangedListener() { + + @Override + public void changed(FilterChain source) { + diagramChanged(); + } + }; + + public boolean getShowNodeHull() { + return showNodeHull; + } + + public void setShowNodeHull(boolean b) { + showNodeHull = b; + viewPropertiesChangedEvent.fire(); + } + + public DiagramViewModel(InputGraph firstGraph, InputGraph secondGraph, Group g, FilterChain filterChain, FilterChain sequenceFilterChain) { + + this.firstGraph = firstGraph; + this.secondGraph = secondGraph; + this.showNodeHull = true; + assert filterChain != null; + this.filterChain = filterChain; + assert sequenceFilterChain != null; + this.sequenceFilterChain = sequenceFilterChain; + hiddenNodes = new HashSet<>(); + onScreenNodes = new HashSet<>(); + selectedNodes = new HashSet<>(); + diagramChangedEvent = new ChangedEvent<>(this); + viewChangedEvent = new ChangedEvent<>(this); + hiddenNodesChangedEvent = new ChangedEvent<>(this); + viewPropertiesChangedEvent = new ChangedEvent<>(this); + + filterChain.getChangedEvent().addListener(filterChainChangedListener); + sequenceFilterChain.getChangedEvent().addListener(filterChainChangedListener); + } + + public ChangedEvent getDiagramChangedEvent() { + return diagramChangedEvent; + } + + public ChangedEvent getViewChangedEvent() { + return viewChangedEvent; + } + + public ChangedEvent getHiddenNodesChangedEvent() { + return hiddenNodesChangedEvent; + } + + public ChangedEvent getViewPropertiesChangedEvent() { + return viewPropertiesChangedEvent; + } + + public Set getSelectedNodes() { + return selectedNodes; + } + + public Set getHiddenNodes() { + return hiddenNodes; + } + + public Set getOnScreenNodes() { + return onScreenNodes; + } + + public void setSelectedNodes(Set nodes) { + this.selectedNodes = nodes; + /* List colors = new ArrayList<>(); + for (int i = 0; i < group.getGraphs().size(); ++i) { + colors.add(Color.black); + } + if (nodes.size() >= 1) { + for (Integer id : nodes) { + if (id < 0) { + id = -id; + } + InputNode last = null; + int index = 0; + for (InputGraph g : group.getGraphs()) { + Color curColor = colors.get(index); + InputNode cur = g.getNode(id); + if (cur != null) { + if (last == null) { + curColor = Color.green; + } else { + if (last.equals(cur)) { + if (curColor == Color.black) { + curColor = Color.white; + } + } else { + if (curColor != Color.green) { + curColor = Color.orange; + } + } + } + } + last = cur; + colors.set(index, curColor); + index++; + } + } + } + compilationViewModel.setColors(colors);*/ + // TODO: Add colorization. + viewChangedEvent.fire(); + } + + public void showNot(final Set nodes) { + System.out.println("Shownot called with " + nodes); + setHiddenNodes(nodes); + } + + public void showFigures(Collection

f) { + HashSet newHiddenNodes = new HashSet<>(getHiddenNodes()); + for (Figure fig : f) { + newHiddenNodes.removeAll(fig.getSource().getSourceNodesAsSet()); + } + setHiddenNodes(newHiddenNodes); + } + + public Set
getSelectedFigures() { + Set
result = new HashSet<>(); + for (Figure f : diagram.getFigures()) { + for (InputNode node : f.getSource().getSourceNodes()) { + if (getSelectedNodes().contains(node.getId())) { + result.add(f); + } + } + } + return result; + } + + public void showAll(final Collection
f) { + showFigures(f); + } + + public void showOnly(final Set nodes) { + final HashSet allNodes = new HashSet<>(getGraphToView().getGroup().getAllNodes()); + allNodes.removeAll(nodes); + setHiddenNodes(allNodes); + } + + public void setHiddenNodes(Set nodes) { + this.hiddenNodes = nodes; + hiddenNodesChangedEvent.fire(); + } + + public void setOnScreenNodes(Set onScreenNodes) { + this.onScreenNodes = onScreenNodes; + viewChangedEvent.fire(); + } + + public FilterChain getSequenceFilterChain() { + return filterChain; + } + + public void setSequenceFilterChain(FilterChain chain) { + assert chain != null : "sequenceFilterChain must never be null"; + sequenceFilterChain.getChangedEvent().removeListener(filterChainChangedListener); + sequenceFilterChain = chain; + sequenceFilterChain.getChangedEvent().addListener(filterChainChangedListener); + diagramChanged(); + } + + private void diagramChanged() { + // clear diagram + diagram = null; + getDiagramChangedEvent().fire(); + + } + + public FilterChain getFilterChain() { + return filterChain; + } + + public void setFilterChain(FilterChain chain) { + assert chain != null : "filterChain must never be null"; + filterChain.getChangedEvent().removeListener(filterChainChangedListener); + filterChain = chain; + filterChain.getChangedEvent().addListener(filterChainChangedListener); + diagramChanged(); + } + + private static List calculateStringList(Group g) { + List result = new ArrayList<>(); + for (InputGraph graph : g.getGraphs()) { + result.add(graph.getName()); + } + return result; + } + + public InputGraph getFirstGraph() { + return firstGraph; + } + + public InputGraph getSecondGraph() { + return secondGraph; + } + + public Diagram getDiagramToView() { + + if (diagram == null) { + diagram = Diagram.createDiagram(getGraphToView(), Settings.get().get(Settings.NODE_TEXT, Settings.NODE_TEXT_DEFAULT)); + getFilterChain().apply(diagram, getSequenceFilterChain()); + if (getFirstGraph() != getSecondGraph()) { + CustomFilter f = new CustomFilter( + "difference", "colorize('state', 'same', white);" + + "colorize('state', 'changed', orange);" + + "colorize('state', 'new', green);" + + "colorize('state', 'deleted', red);"); + f.apply(diagram); + } + } + + return diagram; + } + + public InputGraph getGraphToView() { + if (inputGraph == null) { + if (getFirstGraph() != getSecondGraph()) { + inputGraph = Difference.createDiffGraph(getFirstGraph(), getSecondGraph()); + } else { + inputGraph = getFirstGraph(); + } + } + + return inputGraph; + } + + void setSelectedFigures(List
list) { + Set newSelectedNodes = new HashSet<>(); + for (Figure f : list) { + newSelectedNodes.addAll(f.getSource().getSourceNodesAsSet()); + } + this.setSelectedNodes(newSelectedNodes); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Editor/src/com/oracle/graal/visualizer/editor/EditorTopComponent.form --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Editor/src/com/oracle/graal/visualizer/editor/EditorTopComponent.form Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,33 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 6cb549627941 -r 015fb895586b visualizer/Editor/src/com/oracle/graal/visualizer/editor/EditorTopComponent.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Editor/src/com/oracle/graal/visualizer/editor/EditorTopComponent.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,291 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ +package com.oracle.graal.visualizer.editor; + +import com.oracle.graal.visualizer.util.LookupUtils; +import com.sun.hotspot.igv.data.ChangedListener; +import com.sun.hotspot.igv.data.Group; +import com.sun.hotspot.igv.data.InputGraph; +import com.sun.hotspot.igv.util.RangeSliderModel; +import java.awt.BorderLayout; +import java.awt.CardLayout; +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.*; +import java.util.prefs.Preferences; +import javax.swing.*; +import org.openide.awt.Toolbar; +import org.openide.util.Lookup; +import org.openide.util.NbBundle; +import org.openide.util.NbPreferences; +import org.openide.util.Utilities; +import org.openide.util.actions.Presenter; +import org.openide.util.lookup.AbstractLookup; +import org.openide.util.lookup.InstanceContent; +import org.openide.util.lookup.Lookups; +import org.openide.util.lookup.ProxyLookup; +import org.openide.windows.Mode; +import org.openide.windows.TopComponent; +import org.openide.windows.WindowManager; + +public final class EditorTopComponent extends TopComponent { + + private InstanceContent content; + private static final String PREFERRED_ID = "EditorTopComponent"; + private RangeSliderModel rangeSliderModel; + private CompilationViewer activeViewer; + private CompilationViewerFactory activeFactory; + private Group group; + private final JToolBar viewerToolBar; + private final JPanel viewerPanel; + private final CardLayout viewerPanelCardLayout; + private final Map createdComponents = new HashMap<>(); + private final Lookup proxyLookup; + private Lookup currentLookup = Lookups.fixed(); + private final Lookup.Provider currentViewLookupProvider = new Lookup.Provider() { + + @Override + public Lookup getLookup() { + return currentLookup; + } + }; + private static final String PREFERENCE_FACTORY = "factory"; + + public static Preferences getPreferences() { + return NbPreferences.forModule(EditorTopComponent.class); + } + + private InputGraph getFirstGraph() { + return group.getGraphs().get(getModel().getFirstPosition()); + } + + private InputGraph getSecondGraph() { + return group.getGraphs().get(getModel().getSecondPosition()); + } + + private void updateDisplayName() { + int first = getModel().getFirstPosition(); + int second = getModel().getSecondPosition(); + if (first == second) { + setDisplayName(getModel().getPositions().get(first)); + } else { + setDisplayName(String.format("%s: %s - %s", activeFactory.getName(), getModel().getPositions().get(first), getModel().getPositions().get(second))); + } + } + + private void activateFactory(CompilationViewerFactory factory) { + this.activeFactory = factory; + getPreferences().put(PREFERENCE_FACTORY, activeFactory.getName()); + updateView(); + } + + public EditorTopComponent(InputGraph graph) { + setName(NbBundle.getMessage(EditorTopComponent.class, "CTL_EditorTopComponent")); + setToolTipText(NbBundle.getMessage(EditorTopComponent.class, "HINT_EditorTopComponent")); + + initComponents(); + + Toolbar toolBar = new Toolbar(); + this.add(BorderLayout.NORTH, toolBar); + + this.group = graph.getGroup(); + rangeSliderModel = new RangeSliderModel(calculateStringList(group)); + content = new InstanceContent(); + content.add(rangeSliderModel); + int graphPos = group.getGraphs().indexOf(graph); + rangeSliderModel.setPositions(graphPos, graphPos); + + Collection factories = Lookup.getDefault().lookupAll(CompilationViewerFactory.class); + proxyLookup = Lookups.proxy(currentViewLookupProvider); + this.associateLookup(new ProxyLookup(new Lookup[]{proxyLookup, new AbstractLookup(content)})); + + rangeSliderModel.getChangedEvent().addListener(rangeSliderListener); + + ButtonGroup factoryButtonGroup = new ButtonGroup(); + for (CompilationViewerFactory factory : factories) { + AbstractButton button = createFactoryChangeButton(factory); + factoryButtonGroup.add(button); + toolBar.add(button); + } + toolBar.addSeparator(); + + viewerToolBar = new JToolBar(); + viewerToolBar.setFloatable(false); + toolBar.add(viewerToolBar); + toolBar.add(Box.createHorizontalGlue()); + + Action action = Utilities.actionsForPath("QuickSearchShadow").get(0); + Component quicksearch = ((Presenter.Toolbar) action).getToolbarPresenter(); + quicksearch.setMinimumSize(quicksearch.getPreferredSize()); // necessary for GTK LAF + toolBar.add(quicksearch); + + viewerPanel = new JPanel(); + viewerPanelCardLayout = new CardLayout(); + viewerPanel.setLayout(viewerPanelCardLayout); + this.add(viewerPanel, BorderLayout.CENTER); + + if (factories.size() > 0) { + String activeFactoryName = getPreferences().get(PREFERENCE_FACTORY, factories.iterator().next().getName()); + Enumeration buttons = factoryButtonGroup.getElements(); + for (CompilationViewerFactory factory : factories) { + JToggleButton curButton = (JToggleButton) buttons.nextElement(); + if (factory.getName().equals(activeFactoryName)) { + activeFactory = factory; + curButton.setSelected(true); + } + } + } + updateView(); + } + + private static List calculateStringList(Group g) { + List result = new ArrayList<>(); + for (InputGraph graph : g.getGraphs()) { + result.add(graph.getName()); + } + return result; + } + + private RangeSliderModel getModel() { + return rangeSliderModel; + } + + public static EditorTopComponent getActive() { + Set modes = WindowManager.getDefault().getModes(); + for (Mode m : modes) { + TopComponent tc = m.getSelectedTopComponent(); + if (tc instanceof EditorTopComponent) { + return (EditorTopComponent) tc; + } + } + return null; + } + + /** + * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + jCheckBox1 = new javax.swing.JCheckBox(); + + org.openide.awt.Mnemonics.setLocalizedText(jCheckBox1, "jCheckBox1"); + jCheckBox1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); + jCheckBox1.setMargin(new java.awt.Insets(0, 0, 0, 0)); + + setLayout(new java.awt.BorderLayout()); + }// //GEN-END:initComponents + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JCheckBox jCheckBox1; + // End of variables declaration//GEN-END:variables + + @Override + public int getPersistenceType() { + return TopComponent.PERSISTENCE_NEVER; + } + + @Override + public void componentOpened() { + } + + @Override + public void componentClosed() { + } + + @Override + protected String preferredID() { + return PREFERRED_ID; + } + private ChangedListener rangeSliderListener = new ChangedListener() { + + @Override + public void changed(RangeSliderModel source) { + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + updateView(); + } + }); + } + }; + + private void updateView() { + updateDisplayName(); + String id = getViewStringIdentifier(); + if (!createdComponents.containsKey(id)) { + CompilationViewer newViewer = createViewer(activeFactory); + createdComponents.put(id, newViewer); + viewerPanel.add(newViewer.getComponent(), id); + } + + CompilationViewer newViewer = createdComponents.get(id); + if (newViewer != activeViewer) { + activeViewer = newViewer; + viewerPanelCardLayout.show(viewerPanel, id); + + currentLookup = new ProxyLookup(activeViewer.getLookup(), Lookups.fixed(getFirstGraph(), getSecondGraph())); + initializeToolBar(activeFactory.getName()); + + // Make sure that lookup is updated. + proxyLookup.lookup(Object.class); + } + } + + private String getViewStringIdentifier() { + return String.format("%s/%d/%d", activeFactory.getName(), getModel().getFirstPosition(), getModel().getSecondPosition()); + } + + private AbstractButton createFactoryChangeButton(final CompilationViewerFactory factory) { + JToggleButton toggleButton = new JToggleButton(factory.getName()); + toggleButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + activateFactory(factory); + } + }); + return toggleButton; + } + + private CompilationViewer createViewer(CompilationViewerFactory activeFactory) { + InputGraph firstSnapshot = getFirstGraph(); + InputGraph secondSnapshot = getSecondGraph(); + return activeFactory.createViewer(firstSnapshot, secondSnapshot); + } + + private void initializeToolBar(String id) { + viewerToolBar.removeAll(); + for (Action a : LookupUtils.lookupActions(String.format("CompilationViewer/%s/Actions", id), activeViewer.getLookup())) { + if (a instanceof Presenter.Toolbar) { + viewerToolBar.add(((Presenter.Toolbar) a).getToolbarPresenter()); + } else { + viewerToolBar.add(a); + } + } + viewerToolBar.updateUI(); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Editor/src/com/oracle/graal/visualizer/editor/GraphViewerImplementation.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Editor/src/com/oracle/graal/visualizer/editor/GraphViewerImplementation.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ +package com.oracle.graal.visualizer.editor; + +import com.sun.hotspot.igv.data.InputGraph; +import com.sun.hotspot.igv.data.services.GraphViewer; + +/** + * + * @author Thomas Wuerthinger + */ +public class GraphViewerImplementation implements GraphViewer { + + @Override + public void view(InputGraph graph) { + EditorTopComponent tc = new EditorTopComponent(graph); + tc.open(); + tc.requestActive(); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Editor/src/com/oracle/graal/visualizer/editor/NodeQuickSearch.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Editor/src/com/oracle/graal/visualizer/editor/NodeQuickSearch.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ +package com.oracle.graal.visualizer.editor; + +import com.sun.hotspot.igv.data.InputNode; +import com.sun.hotspot.igv.data.Properties; +import com.sun.hotspot.igv.data.Properties.RegexpPropertyMatcher; +import com.sun.hotspot.igv.data.services.InputGraphProvider; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.regex.Pattern; +import org.netbeans.spi.quicksearch.SearchProvider; +import org.netbeans.spi.quicksearch.SearchRequest; +import org.netbeans.spi.quicksearch.SearchResponse; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.NotifyDescriptor.Message; + +/** + * + * @author Thomas Wuerthinger + */ +public class NodeQuickSearch implements SearchProvider { + + private static final String DEFAULT_PROPERTY = "name"; + + /** + * Method is called by infrastructure when search operation was requested. + * Implementors should evaluate given request and fill response object with + * apropriate results + * + * @param request Search request object that contains information what to search for + * @param response Search response object that stores search results. Note that it's important to react to return value of SearchResponse.addResult(...) method and stop computation if false value is returned. + */ + @Override + public void evaluate(SearchRequest request, SearchResponse response) { + String query = request.getText(); + if (query.trim().isEmpty()) { + return; + } + + final String[] parts = query.split("=", 2); + + String name; + String value; + + if (parts.length == 1) { + name = DEFAULT_PROPERTY; + value = ".*" + Pattern.quote(parts[0]) + ".*"; + } else { + name = parts[0]; + value = parts[1]; + } + + if (value.isEmpty()) { + value = ".*"; + } + + final InputGraphProvider p = null;// TODO: FIXME LookupHistory.getLast(InputGraphProvider.class); + if (p != null && p.getGraph() != null) { + List matches = null; + try { + RegexpPropertyMatcher matcher = new RegexpPropertyMatcher(name, value, Pattern.CASE_INSENSITIVE); + Properties.PropertySelector selector = new Properties.PropertySelector<>(p.getGraph().getNodes()); + + matches = selector.selectMultiple(matcher); + } catch (Exception e) { + final String msg = e.getMessage(); + response.addResult(new Runnable() { + @Override + public void run() { + Message desc = new NotifyDescriptor.Message("An exception occurred during the search, " + + "perhaps due to a malformed query string:\n" + msg, + NotifyDescriptor.WARNING_MESSAGE); + DialogDisplayer.getDefault().notify(desc); + } + }, + "(Error during search)" + ); + } + + if (matches != null) { + final Set set = new HashSet<>(matches); + response.addResult(new Runnable() { + @Override + public void run() { + final EditorTopComponent comp = EditorTopComponent.getActive(); + if (comp != null) { + // TODO: find connection again! + //comp.setSelectedNodes(set); + comp.requestActive(); + } + } + }, + "All " + matches.size() + " matching nodes (" + name + "=" + value + ")" + ); + + // Single matches + for (final InputNode n : matches) { + response.addResult(new Runnable() { + @Override + public void run() { + final EditorTopComponent comp = EditorTopComponent.getActive(); + if (comp != null) { + final Set tmpSet = new HashSet<>(); + tmpSet.add(n); + // TODO: find connection again! + //comp.setSelectedNodes(tmpSet); + comp.requestActive(); + } + } + }, + n.getProperties().get(name) + " (" + n.getId() + " " + n.getProperties().get("name") + ")" + ); + } + } + } else { + System.out.println("no input graph provider!"); + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Editor/src/com/oracle/graal/visualizer/editor/SplitCompilationViewer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Editor/src/com/oracle/graal/visualizer/editor/SplitCompilationViewer.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ +package com.oracle.graal.visualizer.editor; + +import com.sun.hotspot.igv.graph.Figure; +import java.awt.BorderLayout; +import java.awt.Component; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.Collection; +import java.util.prefs.Preferences; +import javax.swing.JPanel; +import javax.swing.JSplitPane; +import javax.swing.JToolBar; +import org.openide.util.Lookup; +import org.openide.util.NbPreferences; +import org.openide.util.lookup.Lookups; +import org.openide.util.lookup.ProxyLookup; + +class SplitCompilationViewer implements CompilationViewer { + + private JSplitPane splitPane; + private Component firstPanel; + private Component secondPanel; + private Lookup combinedLookup; + private static final String DIVIDER_LOCATION = "dividerLocation"; + private final PropertyChangeListener splitChanged = new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent changeEvent) { + String propertyName = changeEvent.getPropertyName(); + if (propertyName.equals(JSplitPane.DIVIDER_LOCATION_PROPERTY)) { + setLastDividerLocation((Integer) changeEvent.getNewValue()); + } + } + }; + + private static void setLastDividerLocation(int pos) { + NbPreferences.forModule(SplitCompilationViewer.class).put(DIVIDER_LOCATION, Integer.toString(pos)); + } + + private static int getLastDividerLocation() { + try { + return Integer.parseInt(NbPreferences.forModule(SplitCompilationViewer.class).get(DIVIDER_LOCATION, "400")); + } catch (NumberFormatException e) { + return 400; + } + } + + public SplitCompilationViewer(CompilationViewer firstViewer, CompilationViewer secondViewer) { + splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); + firstPanel = createComponent(firstViewer); + secondPanel = createComponent(secondViewer); + splitPane.add(firstPanel); + splitPane.add(secondPanel); + splitPane.addPropertyChangeListener(splitChanged); + splitPane.setDividerLocation(getLastDividerLocation()); + combinedLookup = new ProxyLookup(firstViewer.getLookup(), secondViewer.getLookup()); + } + + @Override + public Lookup getLookup() { + return combinedLookup; + } + + @Override + public Component getComponent() { + return splitPane; + } + + private Component createComponent(CompilationViewer viewer) { + return viewer.getComponent(); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Editor/src/com/oracle/graal/visualizer/editor/SplitCompilationViewerFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Editor/src/com/oracle/graal/visualizer/editor/SplitCompilationViewerFactory.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +package com.oracle.graal.visualizer.editor; + +import com.sun.hotspot.igv.data.InputGraph; + +public abstract class SplitCompilationViewerFactory implements CompilationViewerFactory { + + @Override + public CompilationViewer createViewer(InputGraph firstGraph, InputGraph secondGraph) { + if (firstGraph == secondGraph) { + return createViewer(firstGraph); + } else { + CompilationViewer firstViewer = createViewer(firstGraph); + CompilationViewer secondViewer = createViewer(secondGraph); + return new SplitCompilationViewer(firstViewer, secondViewer); + } + } + + protected abstract CompilationViewer createViewer(InputGraph graph); +} diff -r 6cb549627941 -r 015fb895586b visualizer/Editor/src/com/oracle/graal/visualizer/editor/layer.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Editor/src/com/oracle/graal/visualizer/editor/layer.xml Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff -r 6cb549627941 -r 015fb895586b visualizer/Filter/manifest.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Filter/manifest.mf Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,6 @@ +Manifest-Version: 1.0 +OpenIDE-Module: com.sun.hotspot.igv.filter +OpenIDE-Module-Layer: com/sun/hotspot/igv/filter/layer.xml +OpenIDE-Module-Localizing-Bundle: com/sun/hotspot/igv/filter/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff -r 6cb549627941 -r 015fb895586b visualizer/Filter/src/com/sun/hotspot/igv/filter/AbstractFilter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Filter/src/com/sun/hotspot/igv/filter/AbstractFilter.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,63 @@ +/* + * 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.filter; + +import com.sun.hotspot.igv.data.ChangedEvent; +import com.sun.hotspot.igv.data.Properties; +import org.openide.cookies.OpenCookie; + +/** + * + * @author Thomas Wuerthinger + */ +public abstract class AbstractFilter implements Filter { + + private ChangedEvent changedEvent; + private Properties properties; + + public AbstractFilter() { + changedEvent = new ChangedEvent(this); + properties = new Properties(); + } + + @Override + public Properties getProperties() { + return properties; + } + + @Override + public OpenCookie getEditor() { + return null; + } + + @Override + public ChangedEvent getChangedEvent() { + return changedEvent; + } + + protected void fireChangedEvent() { + changedEvent.fire(); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Filter/src/com/sun/hotspot/igv/filter/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Filter/src/com/sun/hotspot/igv/filter/Bundle.properties Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,11 @@ +OpenIDE-Module-Name=Filter + +jLabel1.text=Name\: +jLabel2.text=Source\: + +nameTextField.text= + +jButton1.text=OK +jButton2.text=Cancel + +title=Edit Filter Dialog diff -r 6cb549627941 -r 015fb895586b visualizer/Filter/src/com/sun/hotspot/igv/filter/ColorFilter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Filter/src/com/sun/hotspot/igv/filter/ColorFilter.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,136 @@ +/* + * 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.filter; + +import com.sun.hotspot.igv.data.Properties; +import com.sun.hotspot.igv.graph.Connection.ConnectionStyle; +import com.sun.hotspot.igv.graph.*; +import java.awt.Color; +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public class ColorFilter extends AbstractFilter { + + private List colorRules; + private String name; + + public ColorFilter(String name) { + this.name = name; + colorRules = new ArrayList<>(); + } + + @Override + public String getName() { + return name; + } + + @Override + public void apply(Diagram diagram) { + + Properties.PropertySelector
selector = new Properties.PropertySelector<>(diagram.getFigures()); + for (ColorRule rule : colorRules) { + if (rule.getSelector() != null) { + List
figures = rule.getSelector().selected(diagram); + for (Figure f : figures) { + applyRule(rule, f); + if (rule.getColor() != null) { + f.setColor(rule.getColor()); + } + } + } else { + for (Figure f : diagram.getFigures()) { + applyRule(rule, f); + } + } + } + } + + private void applyRule(ColorRule rule, Figure f) { + if (rule.getColor() != null) { + f.setColor(rule.getColor()); + } + Color color = rule.getLineColor(); + ConnectionStyle style = rule.getLineStyle(); + + for (OutputSlot s : f.getOutputSlots()) { + for (Connection c : s.getConnections()) { + if (color != null) { + c.setColor(color); + } + + if (style != null) { + c.setStyle(style); + } + } + } + } + + public void addRule(ColorRule r) { + colorRules.add(r); + } + + public static class ColorRule { + + private Color color; + private Color lineColor; + private Connection.ConnectionStyle lineStyle; + private Selector selector; + + public ColorRule(Selector selector, Color c) { + this(selector, c, null, null); + } + + public ColorRule(Selector selector, Color c, Color lineColor, Connection.ConnectionStyle lineStyle) { + this.selector = selector; + this.color = c; + this.lineColor = lineColor; + this.lineStyle = lineStyle; + + } + + public ColorRule(Color c) { + this(null, c); + } + + public Color getColor() { + return color; + } + + public Selector getSelector() { + return selector; + } + + public Color getLineColor() { + return lineColor; + } + + public Connection.ConnectionStyle getLineStyle() { + return lineStyle; + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Filter/src/com/sun/hotspot/igv/filter/CombineFilter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Filter/src/com/sun/hotspot/igv/filter/CombineFilter.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,221 @@ +/* + * 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.filter; + +import com.sun.hotspot.igv.data.Properties; +import com.sun.hotspot.igv.data.Properties.PropertyMatcher; +import com.sun.hotspot.igv.graph.*; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * + * @author Thomas Wuerthinger + */ +public class CombineFilter extends AbstractFilter { + + private List rules; + private String name; + + public CombineFilter(String name) { + this.name = name; + rules = new ArrayList<>(); + } + + @Override + public String getName() { + return name; + } + + @Override + public void apply(Diagram diagram) { + + Properties.PropertySelector
selector = new Properties.PropertySelector<>(diagram.getFigures()); + for (CombineRule r : rules) { + + List
list = selector.selectMultiple(r.getFirstMatcher()); + Set
figuresToRemove = new HashSet<>(); + for (Figure f : list) { + + List
successors = new ArrayList<>(f.getSuccessors()); + if (r.isReversed()) { + if (successors.size() == 1) { + Figure succ = successors.get(0); + InputSlot slot = null; + + for (InputSlot s : succ.getInputSlots()) { + for (Connection c : s.getConnections()) { + if (c.getOutputSlot().getFigure() == f) { + slot = s; + } + } + } + + slot.getSource().addSourceNodes(f.getSource()); + if (r.getShortProperty() != null) { + String s = f.getProperties().get(r.getShortProperty()); + if (s != null && s.length() > 0) { + slot.setShortName(s); + slot.setText(s); + slot.setColor(f.getColor()); + } + } else { + assert slot != null; + slot.setText(f.getProperties().get("dump_spec")); + if (f.getProperties().get("short_name") != null) { + slot.setShortName(f.getProperties().get("short_name")); + } else { + String s = f.getProperties().get("dump_spec"); + if (s != null && s.length() <= 5) { + slot.setShortName(s); + } + } + } + + for (InputSlot s : f.getInputSlots()) { + for (Connection c : s.getConnections()) { + Connection newConn = diagram.createConnection(slot, c.getOutputSlot(), c.getLabel()); + newConn.setColor(c.getColor()); + newConn.setStyle(c.getStyle()); + } + } + + figuresToRemove.add(f); + } + } else { + + for (Figure succ : successors) { + if (succ.getPredecessors().size() == 1 && succ.getInputSlots().size() == 1) { + if (succ.getProperties().selectSingle(r.getSecondMatcher()) != null && succ.getOutputSlots().size() == 1) { + + + OutputSlot oldSlot = null; + for (OutputSlot s : f.getOutputSlots()) { + for (Connection c : s.getConnections()) { + if (c.getInputSlot().getFigure() == succ) { + oldSlot = s; + } + } + } + + assert oldSlot != null; + + OutputSlot nextSlot = succ.getOutputSlots().get(0); + int pos = 0; + if (succ.getProperties().get("con") != null) { + pos = Integer.parseInt(succ.getProperties().get("con")); + } + OutputSlot slot = f.createOutputSlot(pos); + slot.getSource().addSourceNodes(succ.getSource()); + if (r.getShortProperty() != null) { + String s = succ.getProperties().get(r.getShortProperty()); + if (s != null && s.length() > 0) { + slot.setShortName(s); + slot.setText(s); + slot.setColor(succ.getColor()); + } + } else { + slot.setText(succ.getProperties().get("dump_spec")); + if (succ.getProperties().get("short_name") != null) { + slot.setShortName(succ.getProperties().get("short_name")); + } else { + String s = succ.getProperties().get("dump_spec"); + if (s != null && s.length() <= 2) { + slot.setShortName(s); + } else { + String tmpName = succ.getProperties().get("name"); + if (tmpName != null && tmpName.length() > 0) { + slot.setShortName(tmpName.substring(0, 1)); + } + } + } + } + for (Connection c : nextSlot.getConnections()) { + Connection newConn = diagram.createConnection(c.getInputSlot(), slot, c.getLabel()); + newConn.setColor(c.getColor()); + newConn.setStyle(c.getStyle()); + } + + + figuresToRemove.add(succ); + + if (oldSlot.getConnections().size() == 0) { + f.removeSlot(oldSlot); + } + } + } + } + } + } + + diagram.removeAllFigures(figuresToRemove); + } + } + + public void addRule(CombineRule combineRule) { + rules.add(combineRule); + } + + public static class CombineRule { + + private PropertyMatcher first; + private PropertyMatcher second; + private boolean reversed; + private String shortProperty; + + public CombineRule(PropertyMatcher first, PropertyMatcher second) { + this(first, second, false); + + } + + public CombineRule(PropertyMatcher first, PropertyMatcher second, boolean reversed) { + this(first, second, reversed, null); + } + + public CombineRule(PropertyMatcher first, PropertyMatcher second, boolean reversed, String shortProperty) { + this.first = first; + this.second = second; + this.reversed = reversed; + this.shortProperty = shortProperty; + } + + public boolean isReversed() { + return reversed; + } + + public PropertyMatcher getFirstMatcher() { + return first; + } + + public PropertyMatcher getSecondMatcher() { + return second; + } + + public String getShortProperty() { + return shortProperty; + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Filter/src/com/sun/hotspot/igv/filter/ConnectionFilter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Filter/src/com/sun/hotspot/igv/filter/ConnectionFilter.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,104 @@ +/* + * 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.filter; + +import com.sun.hotspot.igv.data.Properties; +import com.sun.hotspot.igv.graph.*; +import java.awt.Color; +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public class ConnectionFilter extends AbstractFilter { + + private List connectionStyleRules; + private String name; + + public ConnectionFilter(String name) { + this.name = name; + connectionStyleRules = new ArrayList<>(); + } + + @Override + public String getName() { + return name; + } + + @Override + public void apply(Diagram diagram) { + + Properties.PropertySelector
selector = new Properties.PropertySelector<>(diagram.getFigures()); + for (ConnectionStyleRule rule : connectionStyleRules) { + List
figures = null; + if (rule.getSelector() != null) { + figures = rule.getSelector().selected(diagram); + } else { + figures = diagram.getFigures(); + } + + for (Figure f : figures) { + for (OutputSlot os : f.getOutputSlots()) { + for (Connection c : os.getConnections()) { + if (figures.contains(c.getInputSlot().getFigure())) { + c.setStyle(rule.getLineStyle()); + c.setColor(rule.getLineColor()); + } + } + } + } + } + } + + public void addRule(ConnectionStyleRule r) { + connectionStyleRules.add(r); + } + + public static class ConnectionStyleRule { + + private Color lineColor; + private Connection.ConnectionStyle lineStyle; + private Selector selector; + + public ConnectionStyleRule(Selector selector, Color lineColor, Connection.ConnectionStyle lineStyle) { + this.selector = selector; + this.lineColor = lineColor; + this.lineStyle = lineStyle; + } + + public Selector getSelector() { + return selector; + } + + public Color getLineColor() { + return lineColor; + } + + public Connection.ConnectionStyle getLineStyle() { + return lineStyle; + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Filter/src/com/sun/hotspot/igv/filter/CustomFilter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Filter/src/com/sun/hotspot/igv/filter/CustomFilter.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,138 @@ +/* + * 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.filter; + +import com.sun.hotspot.igv.graph.Diagram; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.script.*; +import org.openide.cookies.OpenCookie; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.util.Exceptions; + +/** + * + * @author Thomas Wuerthinger + */ +public class CustomFilter extends AbstractFilter { + + public static final String JAVASCRIPT_HELPER_ID = "JavaScriptHelper"; + private String code; + private String name; + + public CustomFilter(String name, String code) { + this.name = name; + this.code = code; + getProperties().setProperty("name", name); + } + + @Override + public String getName() { + return name; + } + + public String getCode() { + return code; + } + + public void setName(String s) { + name = s; + fireChangedEvent(); + } + + public void setCode(String s) { + code = s; + fireChangedEvent(); + } + + @Override + public OpenCookie getEditor() { + return new OpenCookie() { + + @Override + public void open() { + openInEditor(); + } + }; + } + + public boolean openInEditor() { + EditFilterDialog dialog = new EditFilterDialog(CustomFilter.this); + dialog.setVisible(true); + boolean result = dialog.wasAccepted(); + this.getChangedEvent().fire(); + return result; + } + + @Override + public String toString() { + return getName(); + } + + private static String getJsHelperText() { + InputStream is = null; + StringBuilder sb = new StringBuilder("importPackage(Packages.com.sun.hotspot.igv.filter);importPackage(Packages.com.sun.hotspot.igv.graph);importPackage(Packages.com.sun.hotspot.igv.data);importPackage(Packages.com.sun.hotspot.igv.util);importPackage(java.awt);"); + try { + FileObject fo = FileUtil.getConfigRoot().getFileObject(JAVASCRIPT_HELPER_ID); + is = fo.getInputStream(); + BufferedReader r = new BufferedReader(new InputStreamReader(is)); + String s; + while ((s = r.readLine()) != null) { + sb.append(s); + sb.append("\n"); + } + + } catch (IOException ex) { + Logger.getLogger("global").log(Level.SEVERE, null, ex); + } finally { + try { + is.close(); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + return sb.toString(); + } + + @Override + public void apply(Diagram d) { + try { + ScriptEngineManager sem = new ScriptEngineManager(); + ScriptEngine e = sem.getEngineByName("ECMAScript"); + e.eval(getJsHelperText()); + Bindings b = e.getContext().getBindings(ScriptContext.ENGINE_SCOPE); + b.put("graph", d); + b.put("IO", System.out); + e.eval(code, b); + } catch (ScriptException ex) { + Exceptions.printStackTrace(ex); + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Filter/src/com/sun/hotspot/igv/filter/EdgeColorIndexFilter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Filter/src/com/sun/hotspot/igv/filter/EdgeColorIndexFilter.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,77 @@ +/* + * 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.filter; + +import com.sun.hotspot.igv.graph.*; +import java.awt.Color; +import java.util.List; + +public class EdgeColorIndexFilter extends AbstractFilter { + + public static final String INPUTS = "INPUTS"; + public static final String OUTPUTS = "OUTPUTS"; + private final String applyTo; + private final Color[] colors; + + public EdgeColorIndexFilter(String applyTo, Color... color) { + if (!applyTo.equals(INPUTS) && !applyTo.equals(OUTPUTS)) { + throw new IllegalArgumentException("applyTo"); + } + + this.applyTo = applyTo; + this.colors = color; + } + + @Override + public String getName() { + return "Edge Color Index Filter"; + } + + @Override + public void apply(Diagram d) { + List
figures = d.getFigures(); + for (Figure f : figures) { + Slot[] slots; + if (applyTo.equals(INPUTS)) { + List inputSlots = f.getInputSlots(); + slots = inputSlots.toArray(new Slot[inputSlots.size()]); + } else { + List outputSlots = f.getOutputSlots(); + slots = outputSlots.toArray(new Slot[outputSlots.size()]); + } + int index = 0; + for (Slot slot : slots) { + if (index < colors.length && colors[index] != null) { + slot.setColor(colors[index]); + for (Connection c : slot.getConnections()) { + + c.setColor(colors[index]); + } + } + index++; + } + + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Filter/src/com/sun/hotspot/igv/filter/EditFilterDialog.form --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Filter/src/com/sun/hotspot/igv/filter/EditFilterDialog.form Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,133 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff -r 6cb549627941 -r 015fb895586b visualizer/Filter/src/com/sun/hotspot/igv/filter/EditFilterDialog.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Filter/src/com/sun/hotspot/igv/filter/EditFilterDialog.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,161 @@ +/* + * 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.filter; + +import org.openide.windows.WindowManager; + +/** + * + * @author Thomas Wuerthinger + */ +public class EditFilterDialog extends javax.swing.JDialog { + + private CustomFilter customFilter; + private boolean accepted; + + /** Creates new form EditFilterDialog */ + public EditFilterDialog(CustomFilter customFilter) { + super(WindowManager.getDefault().getMainWindow(), true); + this.customFilter = customFilter; + initComponents(); + + sourceTextArea.setText(customFilter.getCode()); + nameTextField.setText(customFilter.getName()); + } + + public boolean wasAccepted() { + return accepted; + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + jScrollPane1 = new javax.swing.JScrollPane(); + sourceTextArea = new javax.swing.JTextArea(); + nameTextField = new javax.swing.JTextField(); + nameLabel = new javax.swing.JLabel(); + sourceLabel = new javax.swing.JLabel(); + okButton = new javax.swing.JButton(); + cancelButton = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setTitle(org.openide.util.NbBundle.getMessage(EditFilterDialog.class, "title")); // NOI18N + setResizable(false); + + sourceTextArea.setColumns(20); + sourceTextArea.setRows(5); + jScrollPane1.setViewportView(sourceTextArea); + + nameTextField.setText("null"); + + nameLabel.setText(org.openide.util.NbBundle.getMessage(EditFilterDialog.class, "jLabel1.text")); // NOI18N + + sourceLabel.setText(org.openide.util.NbBundle.getMessage(EditFilterDialog.class, "jLabel2.text")); // NOI18N + + okButton.setText(org.openide.util.NbBundle.getMessage(EditFilterDialog.class, "jButton1.text")); // NOI18N + okButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + cancelButtonClicked(evt); + okButtonClicked(evt); + } + }); + + cancelButton.setText(org.openide.util.NbBundle.getMessage(EditFilterDialog.class, "jButton2.text")); // NOI18N + cancelButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + cancelButtonClicked(evt); + } + }); + + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(sourceLabel) + .add(nameLabel)) + .add(25, 25, 25) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 695, Short.MAX_VALUE) + .add(nameTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 695, Short.MAX_VALUE))) + .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() + .add(okButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 76, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(cancelButton))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(nameLabel) + .add(nameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(sourceLabel) + .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 337, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 16, Short.MAX_VALUE) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(cancelButton) + .add(okButton)) + .addContainerGap()) + ); + + pack(); + }// //GEN-END:initComponents + +private void okButtonClicked(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonClicked + this.customFilter.setName(this.nameTextField.getText()); + this.customFilter.setCode(this.sourceTextArea.getText()); + accepted = true; + setVisible(false); +}//GEN-LAST:event_okButtonClicked + +private void cancelButtonClicked(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonClicked + setVisible(false); +}//GEN-LAST:event_cancelButtonClicked + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton cancelButton; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JLabel nameLabel; + private javax.swing.JTextField nameTextField; + private javax.swing.JButton okButton; + private javax.swing.JLabel sourceLabel; + private javax.swing.JTextArea sourceTextArea; + // End of variables declaration//GEN-END:variables + +} diff -r 6cb549627941 -r 015fb895586b visualizer/Filter/src/com/sun/hotspot/igv/filter/Filter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Filter/src/com/sun/hotspot/igv/filter/Filter.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,46 @@ +/* + * 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.filter; + +import com.sun.hotspot.igv.data.ChangedEvent; +import com.sun.hotspot.igv.data.ChangedEventProvider; +import com.sun.hotspot.igv.data.Properties; +import com.sun.hotspot.igv.graph.Diagram; +import org.openide.cookies.OpenCookie; + +/** + * + * @author Thomas Wuerthinger + */ +public interface Filter extends Properties.Provider, ChangedEventProvider { + + public String getName(); + + public void apply(Diagram d); + + OpenCookie getEditor(); + + @Override + ChangedEvent getChangedEvent(); +} diff -r 6cb549627941 -r 015fb895586b visualizer/Filter/src/com/sun/hotspot/igv/filter/FilterChain.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Filter/src/com/sun/hotspot/igv/filter/FilterChain.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,135 @@ +/* + * 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.filter; + +import com.sun.hotspot.igv.data.ChangedEvent; +import com.sun.hotspot.igv.data.ChangedEventProvider; +import com.sun.hotspot.igv.data.ChangedListener; +import com.sun.hotspot.igv.graph.Diagram; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public class FilterChain implements ChangedEventProvider { + + private List filters; + private transient ChangedEvent changedEvent; + + private ChangedListener changedListener = new ChangedListener() { + @Override + public void changed(Filter source) { + changedEvent.fire(); + } + }; + + public FilterChain() { + filters = new ArrayList<>(); + changedEvent = new ChangedEvent<>(this); + } + + public FilterChain(FilterChain f) { + this.filters = new ArrayList<>(f.filters); + changedEvent = new ChangedEvent<>(this); + } + + @Override + public ChangedEvent getChangedEvent() { + return changedEvent; + } + + public Filter getFilterAt(int index) { + assert index >= 0 && index < filters.size(); + return filters.get(index); + } + + public void apply(Diagram d) { + for (Filter f : filters) { + f.apply(d); + } + } + + public void apply(Diagram d, FilterChain sequence) { + List applied = new ArrayList<>(); + for (Filter f : sequence.getFilters()) { + if (filters.contains(f)) { + f.apply(d); + applied.add(f); + } + } + + + for (Filter f : filters) { + if (!applied.contains(f)) { + f.apply(d); + } + } + } + + + public void addFilter(Filter filter) { + assert filter != null; + filters.add(filter); + filter.getChangedEvent().addListener(changedListener); + changedEvent.fire(); + } + + public boolean containsFilter(Filter filter) { + return filters.contains(filter); + } + + public void removeFilter(Filter filter) { + assert filters.contains(filter); + filters.remove(filter); + filter.getChangedEvent().removeListener(changedListener); + changedEvent.fire(); + } + + public void moveFilterUp(Filter filter) { + assert filters.contains(filter); + int index = filters.indexOf(filter); + if (index != 0) { + filters.remove(index); + filters.add(index - 1, filter); + } + changedEvent.fire(); + } + + public void moveFilterDown(Filter filter) { + assert filters.contains(filter); + int index = filters.indexOf(filter); + if (index != filters.size() - 1) { + filters.remove(index); + filters.add(index + 1, filter); + } + changedEvent.fire(); + } + + public List getFilters() { + return Collections.unmodifiableList(filters); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Filter/src/com/sun/hotspot/igv/filter/FilterChainProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Filter/src/com/sun/hotspot/igv/filter/FilterChainProvider.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,35 @@ +/* + * 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.filter; + +/** + * + * @author Thomas Wuerthinger + */ +public interface FilterChainProvider { + + public FilterChain getFilterChain(); + + public FilterChain getSequence(); +} diff -r 6cb549627941 -r 015fb895586b visualizer/Filter/src/com/sun/hotspot/igv/filter/FilterSetting.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Filter/src/com/sun/hotspot/igv/filter/FilterSetting.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,82 @@ +/* + * 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.filter; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +/** + * + * @author Thomas Wuerthinger + */ +public class FilterSetting { + + private Set filters; + private String name; + + public FilterSetting() { + this(null); + } + + public FilterSetting(String name) { + this.name = name; + filters = new HashSet<>(); + } + + public Set getFilters() { + return Collections.unmodifiableSet(filters); + } + + public void addFilter(Filter f) { + assert !filters.contains(f); + filters.add(f); + } + + public void removeFilter(Filter f) { + assert filters.contains(f); + filters.remove(f); + } + + public boolean containsFilter(Filter f) { + return filters.contains(f); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getFilterCount() { + return filters.size(); + } + + @Override + public String toString() { + return getName(); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Filter/src/com/sun/hotspot/igv/filter/GradientColorFilter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Filter/src/com/sun/hotspot/igv/filter/GradientColorFilter.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,161 @@ +/* + * 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.filter; + +import com.sun.hotspot.igv.graph.Diagram; +import com.sun.hotspot.igv.graph.Figure; +import java.awt.*; +import java.awt.geom.AffineTransform; +import java.awt.image.Raster; +import java.util.List; + +/** + * Filter that colors nodes using a customizable color gradient, based on how + * a numeric property is located in a specified interval. + * + * @author Peter Hofer + */ +public class GradientColorFilter extends AbstractFilter { + + public static final String LINEAR = "LINEAR"; + public static final String LOGARITHMIC = "LOGARITHMIC"; + + private String propertyName = "probability"; + private float minValue = 0; + private float maxValue = 500; + private float[] fractions = {0, 0.5f, 1}; + private Color[] colors = {Color.BLUE, Color.YELLOW, Color.RED}; + private int shadeCount = 8; + private String mode = LINEAR; + + @Override + public String getName() { + return "Gradient Color Filter"; + } + + @Override + public void apply(Diagram d) { + boolean logarithmic = mode.equalsIgnoreCase(LOGARITHMIC); + if (!logarithmic && !mode.equalsIgnoreCase(LINEAR)) { + throw new RuntimeException("Unknown mode: " + mode); + } + + Rectangle bounds = new Rectangle(shadeCount, 1); + LinearGradientPaint lgp = new LinearGradientPaint(bounds.x, bounds.y, bounds.width, bounds.y, fractions, colors); + PaintContext context = lgp.createContext(null, bounds, bounds.getBounds2D(), AffineTransform.getTranslateInstance(0, 0), new RenderingHints(null)); + Raster raster = context.getRaster(bounds.x, bounds.y, bounds.width, bounds.height); + int[] rgb = raster.getPixels(bounds.x, bounds.y, bounds.width, bounds.height, (int[]) null); + Color[] shades = new Color[rgb.length / 3]; + for (int i = 0; i < shades.length; ++i) { + shades[i] = new Color(rgb[i * 3], rgb[i * 3 + 1], rgb[i * 3 + 2]); + } + + List
figures = d.getFigures(); + for (Figure f : figures) { + String property = f.getProperties().get(propertyName); + if (property != null) { + try { + float value = Float.parseFloat(property); + + Color nodeColor; + if (value <= minValue) { + nodeColor = colors[0]; + } else if (value >= maxValue) { + nodeColor = colors[colors.length - 1]; + } else { + double normalized = value - minValue; + double interval = maxValue - minValue; + int index; + // Use Math.ceil() to make values above zero distinguishable from zero + if (logarithmic) { + index = (int) Math.ceil(shades.length * Math.log(1 + normalized) / Math.log(1 + interval)); + } else { + index = (int) Math.ceil(shades.length * normalized / interval); + } + nodeColor = shades[index]; + } + f.setColor(nodeColor); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } + + public String getPropertyName() { + return propertyName; + } + + public void setPropertyName(String propertyName) { + this.propertyName = propertyName; + } + + public float getMinValue() { + return minValue; + } + + public void setMinValue(float minValue) { + this.minValue = minValue; + } + + public float getMaxValue() { + return maxValue; + } + + public void setMaxValue(float maxValue) { + this.maxValue = maxValue; + } + + public float[] getFractions() { + return fractions; + } + + public void setFractions(float[] fractions) { + this.fractions = fractions; + } + + public Color[] getColors() { + return colors; + } + + public void setColors(Color[] colors) { + this.colors = colors; + } + + public int getShadeCount() { + return shadeCount; + } + + public void setShadeCount(int shadeCount) { + this.shadeCount = shadeCount; + } + + public String getMode() { + return mode; + } + + public void setMode(String mode) { + this.mode = mode; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Filter/src/com/sun/hotspot/igv/filter/RemoveFilter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Filter/src/com/sun/hotspot/igv/filter/RemoveFilter.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,104 @@ +/* + * 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.filter; + +import com.sun.hotspot.igv.graph.Diagram; +import com.sun.hotspot.igv.graph.Figure; +import com.sun.hotspot.igv.graph.Selector; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * + * @author Thomas Wuerthinger + */ +public class RemoveFilter extends AbstractFilter { + + private List rules; + private String name; + + public RemoveFilter(String name) { + this.name = name; + rules = new ArrayList<>(); + } + + @Override + public String getName() { + return name; + } + + @Override + public void apply(Diagram diagram) { + for (RemoveRule r : rules) { + List
selected = r.getSelector().selected(diagram); + Set
toRemove = new HashSet<>(selected); + + if (r.getRemoveOrphans()) { + boolean changed; + do { + changed = false; + for (Figure f : diagram.getFigures()) { + if (!toRemove.contains(f)) { + if (toRemove.containsAll(f.getPredecessors()) && toRemove.containsAll(f.getSuccessors())) { + toRemove.add(f); + changed = true; + } + } + } + } while (changed); + } + + diagram.removeAllFigures(toRemove); + } + } + + public void addRule(RemoveRule rule) { + rules.add(rule); + } + + public static class RemoveRule { + + private Selector selector; + private boolean removeOrphans; + + public RemoveRule(Selector selector) { + this(selector, false); + } + + public RemoveRule(Selector selector, boolean removeOrphans) { + this.selector = selector; + this.removeOrphans = removeOrphans; + } + + public Selector getSelector() { + return selector; + } + + public boolean getRemoveOrphans() { + return removeOrphans; + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Filter/src/com/sun/hotspot/igv/filter/RemoveInputsFilter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Filter/src/com/sun/hotspot/igv/filter/RemoveInputsFilter.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,140 @@ +/* + * 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.filter; + +import com.sun.hotspot.igv.graph.*; +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public class RemoveInputsFilter extends AbstractFilter { + + private List rules; + private String name; + + public RemoveInputsFilter(String name) { + this.name = name; + rules = new ArrayList<>(); + } + + @Override + public String getName() { + return name; + } + + @Override + public void apply(Diagram diagram) { + + for (RemoveInputsRule r : rules) { + + List
list = r.getSelector().selected(diagram); + for (Figure f : list) { + int z = 0; + List last = new ArrayList<>(); + for (InputSlot is : f.getInputSlots()) { + if (z >= r.getStartingIndex() && z <= r.getEndIndex() && is.getConnections().size() > 0) { + StringBuilder sb = new StringBuilder(); + List conns = is.getConnections(); + for (int i = 0; i < conns.size(); i++) { + Connection c = conns.get(i); + OutputSlot os = c.getOutputSlot(); + Figure pred = os.getFigure(); + if (i != 0) { + sb.append("
"); + } + sb.append(pred.getLines()[0]); + } + is.removeAllConnections(); + is.setShortName("X"); + is.setText(sb.toString()); + last.add(is); + } else { + last.clear(); + } + z++; + } + + if (last.size() > 3) { + InputSlot first = last.get(0); + first.setShortName("XX"); + + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < last.size(); i++) { + InputSlot is2 = last.get(i); + if (i != 0) { + sb.append("
"); + } + sb.append(is2.getText()); + } + + first.setText(sb.toString()); + + for (int i = 1; i < last.size(); i++) { + f.removeSlot(last.get(i)); + } + } + } + } + } + + public void addRule(RemoveInputsRule rule) { + rules.add(rule); + } + + public static class RemoveInputsRule { + + private Selector selector; + private int startingIndex; + private int endIndex; + + public RemoveInputsRule(Selector selector) { + this(selector, 0); + } + + public RemoveInputsRule(Selector selector, int startIndex) { + this(selector, startIndex, Integer.MAX_VALUE); + } + + public RemoveInputsRule(Selector selector, int startIndex, int endIndex) { + this.startingIndex = startIndex; + this.endIndex = endIndex; + this.selector = selector; + } + + public int getStartingIndex() { + return startingIndex; + } + + public int getEndIndex() { + return endIndex; + } + + public Selector getSelector() { + return selector; + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Filter/src/com/sun/hotspot/igv/filter/RemoveSelfLoopsFilter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Filter/src/com/sun/hotspot/igv/filter/RemoveSelfLoopsFilter.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,78 @@ +/* + * 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.filter; + +import com.sun.hotspot.igv.graph.*; +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public class RemoveSelfLoopsFilter extends AbstractFilter { + + private String name; + + /** Creates a new instance of RemoveSelfLoops */ + public RemoveSelfLoopsFilter(String name) { + this.name = name; + } + + @Override + public String getName() { + return name; + } + + @Override + public void apply(Diagram d) { + + for (Figure f : d.getFigures()) { + + for (InputSlot is : f.getInputSlots()) { + + List toRemove = new ArrayList<>(); + for (Connection c : is.getConnections()) { + + if (c.getOutputSlot().getFigure() == f) { + toRemove.add(c); + } + } + + for (Connection c : toRemove) { + + c.remove(); + + OutputSlot os = c.getOutputSlot(); + if (os.getConnections().size() == 0) { + f.removeSlot(os); + } + + c.getInputSlot().setShortName("O"); + c.getInputSlot().setText("Self Loop"); + } + } + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Filter/src/com/sun/hotspot/igv/filter/SplitFilter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Filter/src/com/sun/hotspot/igv/filter/SplitFilter.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,92 @@ +/* + * 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.filter; + +import com.sun.hotspot.igv.graph.*; +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public class SplitFilter extends AbstractFilter { + + private String name; + private Selector selector; + private String propertyName; + + public SplitFilter(String name, Selector selector, String propertyName) { + this.name = name; + this.selector = selector; + this.propertyName = propertyName; + } + + @Override + public String getName() { + return name; + } + + @Override + public void apply(Diagram d) { + List
list = selector.selected(d); + + for (Figure f : list) { + + for (InputSlot is : f.getInputSlots()) { + for (Connection c : is.getConnections()) { + OutputSlot os = c.getOutputSlot(); + if (f.getSource().getSourceNodes().size() > 0) { + os.getSource().addSourceNodes(f.getSource()); + os.setAssociatedNode(f.getSource().getSourceNodes().get(0)); + os.setColor(f.getColor()); + } + + + String s = Figure.resolveString(propertyName, f.getProperties()); + if (s != null) { + os.setShortName(s); + } + + } + } + for (OutputSlot os : f.getOutputSlots()) { + for (Connection c : os.getConnections()) { + InputSlot is = c.getInputSlot(); + if (f.getSource().getSourceNodes().size() > 0) { + is.getSource().addSourceNodes(f.getSource()); + is.setAssociatedNode(f.getSource().getSourceNodes().get(0)); + is.setColor(f.getColor()); + } + + String s = Figure.resolveString(propertyName, f.getProperties()); + if (s != null) { + is.setShortName(s); + } + } + } + + d.removeFigure(f); + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Filter/src/com/sun/hotspot/igv/filter/UnconnectedSlotFilter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Filter/src/com/sun/hotspot/igv/filter/UnconnectedSlotFilter.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,76 @@ +/* + * 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.filter; + +import com.sun.hotspot.igv.graph.*; +import java.util.ArrayList; +import java.util.List; + +/** + * Filter that hides slots with no connections. + */ +public class UnconnectedSlotFilter extends AbstractFilter { + + private final boolean removeInputs; + private final boolean removeOutputs; + + public UnconnectedSlotFilter(boolean inputs, boolean outputs) { + this.removeInputs = inputs; + this.removeOutputs = outputs; + } + + @Override + public String getName() { + return "Unconnected Slot Filter"; + } + + @Override + public void apply(Diagram d) { + if (!removeInputs && !removeOutputs) { + return; + } + + List
figures = d.getFigures(); + for (Figure f : figures) { + List remove = new ArrayList<>(); + if (removeInputs) { + for (InputSlot is : f.getInputSlots()) { + if (is.getConnections().isEmpty()) { + remove.add(is); + } + } + } + if (removeOutputs) { + for (OutputSlot os : f.getOutputSlots()) { + if (os.getConnections().isEmpty()) { + remove.add(os); + } + } + } + for (Slot s : remove) { + f.removeSlot(s); + } + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Filter/src/com/sun/hotspot/igv/filter/helper.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Filter/src/com/sun/hotspot/igv/filter/helper.js Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,114 @@ +/* + * 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. + * + */ + + /** + * + * @author Thomas Wuerthinger + */ + +function colorize(property, regexp, color) { + var f = new ColorFilter(""); + f.addRule(new ColorFilter.ColorRule(new MatcherSelector(new Properties.RegexpPropertyMatcher(property, regexp)), color)); + f.apply(graph); +} + +function remove(property, regexp) { + var f = new RemoveFilter(""); + f.addRule(new RemoveFilter.RemoveRule(new MatcherSelector(new Properties.RegexpPropertyMatcher(property, regexp)))); + f.apply(graph); +} + +function removeIncludingOrphans(property, regexp) { + var f = new RemoveFilter(""); + f.addRule(new RemoveFilter.RemoveRule(new MatcherSelector(new Properties.RegexpPropertyMatcher(property, regexp)), true)); + f.apply(graph); +} + +function split(property, regexp, propertyName) { + if (propertyName == undefined) { + propertyName = graph.getNodeText(); + } + var f = new SplitFilter("", new MatcherSelector(new Properties.RegexpPropertyMatcher(property, regexp)), propertyName); + f.apply(graph); +} + +function removeInputs(property, regexp, from, to) { + var f = new RemoveInputsFilter(""); + if(from == undefined && to == undefined) { + f.addRule(new RemoveInputsFilter.RemoveInputsRule(new MatcherSelector(new Properties.RegexpPropertyMatcher(property, regexp)))); + } else if(to == undefined) { + f.addRule(new RemoveInputsFilter.RemoveInputsRule(new MatcherSelector(new Properties.RegexpPropertyMatcher(property, regexp)), from)); + } else { + f.addRule(new RemoveInputsFilter.RemoveInputsRule(new MatcherSelector(new Properties.RegexpPropertyMatcher(property, regexp)), from, to)); + } + f.apply(graph); +} + +function removeUnconnectedSlots(inputs, outputs) { + var f = new UnconnectedSlotFilter(inputs, outputs); + f.apply(graph); +} + +function colorizeGradient(property, min, max) { + var f = new GradientColorFilter(); + f.setPropertyName(property); + f.setMinValue(min); + f.setMaxValue(max); + f.apply(graph); +} + +function colorizeGradientWithMode(property, min, max, mode) { + var f = new GradientColorFilter(); + f.setPropertyName(property); + f.setMinValue(min); + f.setMaxValue(max); + f.setMode(mode); + f.apply(graph); +} + +function colorizeGradientCustom(property, min, max, mode, colors, fractions, nshades) { + var f = new GradientColorFilter(); + f.setPropertyName(property); + f.setMinValue(min); + f.setMaxValue(max); + f.setMode(mode); + f.setColors(colors); + f.setFractions(fractions); + f.setShadeCount(nshades); + f.apply(graph); +} + +var black = Color.black; +var blue = Color.blue; +var cyan = Color.cyan; +var darkGray = Color.darkGray; +var gray = Color.gray; +var green = Color.green; +var lightGray = Color.lightGray; +var magenta = Color.magenta; +var orange = Color.orange; +var pink = Color.pink +var red = Color.red; +var yellow = Color.yellow; +var white = Color.white; \ No newline at end of file diff -r 6cb549627941 -r 015fb895586b visualizer/Filter/src/com/sun/hotspot/igv/filter/layer.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Filter/src/com/sun/hotspot/igv/filter/layer.xml Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,5 @@ + + + + + diff -r 6cb549627941 -r 015fb895586b visualizer/FilterWindow/manifest.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/FilterWindow/manifest.mf Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,6 @@ +Manifest-Version: 1.0 +OpenIDE-Module: com.sun.hotspot.igv.filterwindow +OpenIDE-Module-Layer: com/sun/hotspot/igv/filterwindow/layer.xml +OpenIDE-Module-Localizing-Bundle: com/sun/hotspot/igv/filterwindow/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff -r 6cb549627941 -r 015fb895586b visualizer/FilterWindow/src/META-INF/services/com.sun.hotspot.igv.filter.FilterChainProvider --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/FilterWindow/src/META-INF/services/com.sun.hotspot.igv.filter.FilterChainProvider Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,1 @@ +com.sun.hotspot.igv.filterwindow.FilterChainProviderImplementation diff -r 6cb549627941 -r 015fb895586b visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/Bundle.properties Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,3 @@ +OpenIDE-Module-Name=FilterWindow +CTL_FilterTopComponent=Filters +HINT_FilterTopComponent=Allows to choose active filters and modify them. diff -r 6cb549627941 -r 015fb895586b visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/CheckListView.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/CheckListView.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,52 @@ +/* + * 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.filterwindow; + +import javax.swing.JList; +import org.openide.explorer.view.ListView; +import org.openide.explorer.view.NodeListModel; + +/** + * + * @author Thomas Wuerthinger + */ +public class CheckListView extends ListView { + + @Override + public void showSelection(int[] indices) { + super.showSelection(indices); + } + + @Override + protected NodeListModel createModel() { + return new CheckNodeListModel(); + } + + @Override + protected JList createList() { + JList tmpList = super.createList(); + tmpList.setCellRenderer(new CheckRenderer(tmpList)); + return tmpList; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/CheckNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/CheckNode.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,70 @@ +/* + * 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.filterwindow; + +import com.sun.hotspot.igv.data.ChangedEvent; +import org.openide.nodes.AbstractNode; +import org.openide.nodes.Children; +import org.openide.util.Lookup; + +/** + * + * @author Thomas Wuerthinger + */ +public class CheckNode extends AbstractNode { + + private ChangedEvent selectionChangedEvent; + public boolean selected; + public boolean enabled; + + public CheckNode(Children c, Lookup lookup) { + super(c, lookup); + selectionChangedEvent = new ChangedEvent<>(this); + selected = false; + enabled = true; + } + + public ChangedEvent getSelectionChangedEvent() { + return selectionChangedEvent; + } + + public boolean isSelected() { + return selected; + } + + public void setSelected(boolean b) { + if (b != selected) { + selected = b; + selectionChangedEvent.fire(); + } + } + + public void setEnabled(boolean b) { + enabled = b; + } + + public boolean isEnabled() { + return enabled; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/CheckNodeListModel.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/CheckNodeListModel.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,42 @@ +/* + * 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.filterwindow; + +import org.openide.explorer.view.NodeListModel; +import org.openide.explorer.view.Visualizer; + +/** + * + * @author Thomas Wuerthinger + */ +public class CheckNodeListModel extends NodeListModel { + + public CheckNode getCheckNodeAt(int index) { + Object item = getElementAt(index); + if (item != null) { + return (CheckNode) Visualizer.findNode(item); + } + return null; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/CheckRenderer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/CheckRenderer.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,85 @@ +/* + * 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.filterwindow; + +import java.awt.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import javax.swing.JCheckBox; +import javax.swing.JList; +import javax.swing.ListCellRenderer; + +/** + * @author Thomas Wuerthinger + */ +public class CheckRenderer extends JCheckBox implements ListCellRenderer { + + private JList list; + private Color startBackground; + + public CheckRenderer(final JList list) { + this.list = list; + list.addMouseListener( + new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent e) { + int index = list.locationToIndex(e.getPoint()); + Point p2 = list.indexToLocation(index); + Rectangle r = new Rectangle(p2.x, p2.y, getPreferredSize().height, getPreferredSize().height); + if (r.contains(e.getPoint())) { + CheckNode node = ((CheckNodeListModel) list.getModel()).getCheckNodeAt(index); + node.setSelected(!node.isSelected()); + list.repaint(); + e.consume(); + } + } + }); + + this.setPreferredSize(new Dimension(getPreferredSize().width, getPreferredSize().height - 5)); + startBackground = this.getBackground(); + } + + @Override + public Component getListCellRendererComponent(final JList list, Object value, final int index, boolean isSelected, boolean cellHasFocus) { + setText(value.toString()); + CheckNode node = ((CheckNodeListModel) list.getModel()).getCheckNodeAt(index); + this.setSelected(node.isSelected()); + this.setEnabled(list.isEnabled()); + + if (isSelected && list.hasFocus()) { + this.setBackground(list.getSelectionBackground()); + this.setForeground(list.getSelectionForeground()); + } else if (isSelected) { + assert !list.hasFocus(); + this.setBackground(startBackground); + this.setForeground(list.getForeground()); + + } else { + this.setBackground(list.getBackground()); + this.setForeground(list.getForeground()); + } + return this; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/FilterChainProviderImplementation.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/FilterChainProviderImplementation.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,44 @@ +/* + * 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.filterwindow; + +import com.sun.hotspot.igv.filter.FilterChain; +import com.sun.hotspot.igv.filter.FilterChainProvider; + +/** + * + * @author Thomas Wuerthinger + */ +public class FilterChainProviderImplementation implements FilterChainProvider { + + @Override + public FilterChain getFilterChain() { + return FilterTopComponent.findInstance().getFilterChain(); + } + + @Override + public FilterChain getSequence() { + return FilterTopComponent.findInstance().getSequence(); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/FilterNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/FilterNode.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,117 @@ +/* + * 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.filterwindow; + +import com.sun.hotspot.igv.data.ChangedListener; +import com.sun.hotspot.igv.filter.Filter; +import com.sun.hotspot.igv.filter.FilterChain; +import com.sun.hotspot.igv.filterwindow.actions.MoveFilterDownAction; +import com.sun.hotspot.igv.filterwindow.actions.MoveFilterUpAction; +import com.sun.hotspot.igv.filterwindow.actions.RemoveFilterAction; +import com.sun.hotspot.igv.util.PropertiesSheet; +import javax.swing.Action; +import org.openide.actions.OpenAction; +import org.openide.nodes.Children; +import org.openide.nodes.Sheet; +import org.openide.util.Lookup; +import org.openide.util.LookupEvent; +import org.openide.util.LookupListener; +import org.openide.util.Utilities; +import org.openide.util.lookup.AbstractLookup; +import org.openide.util.lookup.InstanceContent; + +/** + * + * @author Thomas Wuerthinger + */ +public class FilterNode extends CheckNode implements LookupListener, ChangedListener { + + private Filter filter; + private Lookup.Result result; + + public FilterNode(Filter filter) { + this(filter, new InstanceContent()); + } + + private FilterNode(Filter filter, InstanceContent content) { + super(Children.LEAF, new AbstractLookup(content)); + content.add(filter); + + content.add(filter.getEditor()); + this.filter = filter; + filter.getChangedEvent().addListener(new ChangedListener() { + + @Override + public void changed(Filter source) { + update(); + } + }); + + update(); + + Lookup.Template tpl = new Lookup.Template<>(FilterChain.class); + result = Utilities.actionsGlobalContext().lookup(tpl); + result.addLookupListener(this); + + FilterTopComponent.findInstance().getFilterSettingsChangedEvent().addListener(this); + resultChanged(null); + + setShortDescription("Double-click to open filter"); + } + + private void update() { + this.setDisplayName(filter.getName()); + } + + public Filter getFilter() { + return filter; + } + + @Override + protected Sheet createSheet() { + Sheet s = super.createSheet(); + PropertiesSheet.initializeSheet(getFilter().getProperties(), s); + return s; + } + + @Override + public Action[] getActions(boolean b) { + return new Action[]{(Action) OpenAction.findObject(OpenAction.class, true), (Action) MoveFilterUpAction.findObject(MoveFilterUpAction.class, true), (Action) MoveFilterDownAction.findObject(MoveFilterDownAction.class, true), (Action) RemoveFilterAction.findObject(RemoveFilterAction.class, true)}; + } + + @Override + public Action getPreferredAction() { + return OpenAction.get(OpenAction.class).createContextAwareInstance(Utilities.actionsGlobalContext()); + } + + @Override + public void resultChanged(LookupEvent lookupEvent) { + changed(FilterTopComponent.findInstance()); + } + + @Override + public void changed(FilterTopComponent source) { + setSelected(source.getFilterChain().containsFilter(filter)); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/FilterTopComponent.form --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/FilterTopComponent.form Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,18 @@ + + +
+ + + + + + + + + + + + + + + diff -r 6cb549627941 -r 015fb895586b visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/FilterTopComponent.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/FilterTopComponent.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,670 @@ +/* + * 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.filterwindow; + +import com.sun.hotspot.igv.data.ChangedEvent; +import com.sun.hotspot.igv.data.ChangedListener; +import com.sun.hotspot.igv.filter.CustomFilter; +import com.sun.hotspot.igv.filter.Filter; +import com.sun.hotspot.igv.filter.FilterChain; +import com.sun.hotspot.igv.filter.FilterSetting; +import com.sun.hotspot.igv.filterwindow.actions.*; +import java.awt.BorderLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.*; +import java.util.*; +import javax.swing.JComboBox; +import javax.swing.UIManager; +import javax.swing.border.Border; +import org.openide.DialogDisplayer; +import org.openide.ErrorManager; +import org.openide.NotifyDescriptor; +import org.openide.awt.Toolbar; +import org.openide.awt.ToolbarPool; +import org.openide.explorer.ExplorerManager; +import org.openide.explorer.ExplorerUtils; +import org.openide.filesystems.FileLock; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.nodes.AbstractNode; +import org.openide.nodes.Children; +import org.openide.nodes.Node; +import org.openide.util.*; +import org.openide.util.actions.SystemAction; +import org.openide.windows.TopComponent; +import org.openide.windows.WindowManager; + +/** + * + * @author Thomas Wuerthinger + */ +public final class FilterTopComponent extends TopComponent implements LookupListener, ExplorerManager.Provider { + + private static FilterTopComponent instance; + public static final String FOLDER_ID = "Filters"; + public static final String AFTER_ID = "after"; + public static final String ENABLED_ID = "enabled"; + public static final String PREFERRED_ID = "FilterTopComponent"; + private CheckListView view; + private ExplorerManager manager; + private FilterChain filterChain; + private FilterChain sequence; + private Lookup.Result result; + private JComboBox comboBox; + private List filterSettings; + private FilterSetting customFilterSetting = new FilterSetting("-- Custom --"); + private ChangedEvent filterSettingsChangedEvent; + private ActionListener comboBoxActionListener = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + comboBoxSelectionChanged(); + } + }; + + public ChangedEvent getFilterSettingsChangedEvent() { + return filterSettingsChangedEvent; + } + + public FilterChain getSequence() { + return sequence; + } + + public void updateSelection() { + Node[] nodes = this.getExplorerManager().getSelectedNodes(); + int[] arr = new int[nodes.length]; + for (int i = 0; i < nodes.length; i++) { + int index = sequence.getFilters().indexOf(((FilterNode) nodes[i]).getFilter()); + arr[i] = index; + } + view.showSelection(arr); + } + + private void comboBoxSelectionChanged() { + + Object o = comboBox.getSelectedItem(); + if (o == null) { + return; + } + assert o instanceof FilterSetting; + FilterSetting s = (FilterSetting) o; + + if (s != customFilterSetting) { + FilterChain chain = getFilterChain(); + chain.getChangedEvent().beginAtomic(); + List toRemove = new ArrayList<>(); + for (Filter f : chain.getFilters()) { + if (!s.containsFilter(f)) { + toRemove.add(f); + } + } + for (Filter f : toRemove) { + chain.removeFilter(f); + } + + for (Filter f : s.getFilters()) { + if (!chain.containsFilter(f)) { + chain.addFilter(f); + } + } + + chain.getChangedEvent().endAtomic(); + filterSettingsChangedEvent.fire(); + } else { + this.updateComboBoxSelection(); + } + + SystemAction.get(RemoveFilterSettingsAction.class).setEnabled(comboBox.getSelectedItem() != this.customFilterSetting); + SystemAction.get(SaveFilterSettingsAction.class).setEnabled(comboBox.getSelectedItem() == this.customFilterSetting); + } + + private void updateComboBox() { + comboBox.removeAllItems(); + comboBox.addItem(customFilterSetting); + for (FilterSetting s : filterSettings) { + comboBox.addItem(s); + } + + this.updateComboBoxSelection(); + } + + public void addFilterSetting() { + NotifyDescriptor.InputLine l = new NotifyDescriptor.InputLine("Name of the new profile:", "Filter Profile"); + if (DialogDisplayer.getDefault().notify(l) == NotifyDescriptor.OK_OPTION) { + String name = l.getInputText(); + + FilterSetting toRemove = null; + for (FilterSetting s : filterSettings) { + if (s.getName().equals(name)) { + NotifyDescriptor.Confirmation conf = new NotifyDescriptor.Confirmation("Filter profile \"" + name + "\" already exists, do you want to replace it?", "Filter"); + if (DialogDisplayer.getDefault().notify(conf) == NotifyDescriptor.YES_OPTION) { + toRemove = s; + break; + } else { + return; + } + } + } + + if (toRemove != null) { + filterSettings.remove(toRemove); + } + FilterSetting setting = createFilterSetting(name); + filterSettings.add(setting); + + // Sort alphabetically + Collections.sort(filterSettings, new Comparator() { + + @Override + public int compare(FilterSetting o1, FilterSetting o2) { + return o1.getName().compareTo(o2.getName()); + } + }); + + updateComboBox(); + } + } + + public boolean canRemoveFilterSetting() { + return comboBox.getSelectedItem() != customFilterSetting; + } + + public void removeFilterSetting() { + if (canRemoveFilterSetting()) { + Object o = comboBox.getSelectedItem(); + assert o instanceof FilterSetting; + FilterSetting f = (FilterSetting) o; + assert f != customFilterSetting; + assert filterSettings.contains(f); + NotifyDescriptor.Confirmation l = new NotifyDescriptor.Confirmation("Do you really want to remove filter profile \"" + f + "\"?", "Filter Profile"); + if (DialogDisplayer.getDefault().notify(l) == NotifyDescriptor.YES_OPTION) { + filterSettings.remove(f); + updateComboBox(); + } + } + } + + private FilterSetting createFilterSetting(String name) { + FilterSetting s = new FilterSetting(name); + FilterChain chain = this.getFilterChain(); + for (Filter f : chain.getFilters()) { + s.addFilter(f); + } + return s; + } + + private void updateComboBoxSelection() { + List filters = this.getFilterChain().getFilters(); + boolean found = false; + for (FilterSetting s : filterSettings) { + if (s.getFilterCount() == filters.size()) { + boolean ok = true; + for (Filter f : filters) { + if (!s.containsFilter(f)) { + ok = false; + } + } + + if (ok) { + if (comboBox.getSelectedItem() != s) { + comboBox.setSelectedItem(s); + } + found = true; + break; + } + } + } + + if (!found && comboBox.getSelectedItem() != customFilterSetting) { + comboBox.setSelectedItem(customFilterSetting); + } + } + + private class FilterChildren extends Children.Keys implements ChangedListener { + + private HashMap nodeHash = new HashMap<>(); + + @Override + protected Node[] createNodes(Filter filter) { + if (nodeHash.containsKey(filter)) { + return new Node[]{nodeHash.get(filter)}; + } + + FilterNode node = new FilterNode(filter); + node.getSelectionChangedEvent().addListener(this); + nodeHash.put(filter, node); + return new Node[]{node}; + } + + public FilterChildren() { + sequence.getChangedEvent().addListener(new ChangedListener() { + + @Override + public void changed(FilterChain source) { + addNotify(); + } + }); + + setBefore(false); + } + + @Override + protected void addNotify() { + setKeys(sequence.getFilters()); + updateSelection(); + } + + @Override + public void changed(CheckNode source) { + FilterNode node = (FilterNode) source; + Filter f = node.getFilter(); + FilterChain chain = getFilterChain(); + if (node.isSelected()) { + if (!chain.containsFilter(f)) { + chain.addFilter(f); + } + } else { + if (chain.containsFilter(f)) { + chain.removeFilter(f); + } + } + view.revalidate(); + view.repaint(); + updateComboBoxSelection(); + } + } + + public FilterChain getFilterChain() { + return filterChain; + } + + private FilterTopComponent() { + filterSettingsChangedEvent = new ChangedEvent<>(this); + initComponents(); + setName(NbBundle.getMessage(FilterTopComponent.class, "CTL_FilterTopComponent")); + setToolTipText(NbBundle.getMessage(FilterTopComponent.class, "HINT_FilterTopComponent")); + // setIcon(Utilities.loadImage(ICON_PATH, true)); + + sequence = new FilterChain(); + filterChain = new FilterChain(); + initFilters(); + manager = new ExplorerManager(); + manager.setRootContext(new AbstractNode(new FilterChildren())); + associateLookup(ExplorerUtils.createLookup(manager, getActionMap())); + view = new CheckListView(); + + ToolbarPool.getDefault().setPreferredIconSize(16); + Toolbar toolBar = new Toolbar(); + Border b = (Border) UIManager.get("Nb.Editor.Toolbar.border"); //NOI18N + toolBar.setBorder(b); + comboBox = new JComboBox(); + toolBar.add(comboBox); + this.add(toolBar, BorderLayout.NORTH); + toolBar.add(SaveFilterSettingsAction.get(SaveFilterSettingsAction.class)); + toolBar.add(RemoveFilterSettingsAction.get(RemoveFilterSettingsAction.class)); + toolBar.addSeparator(); + toolBar.add(NewFilterAction.get(NewFilterAction.class)); + toolBar.add(RemoveFilterAction.get(RemoveFilterAction.class).createContextAwareInstance(this.getLookup())); + toolBar.add(MoveFilterUpAction.get(MoveFilterUpAction.class).createContextAwareInstance(this.getLookup())); + toolBar.add(MoveFilterDownAction.get(MoveFilterDownAction.class).createContextAwareInstance(this.getLookup())); + this.add(view, BorderLayout.CENTER); + + filterSettings = new ArrayList<>(); + updateComboBox(); + + comboBox.addActionListener(comboBoxActionListener); + setChain(filterChain); + } + + public void newFilter() { + CustomFilter cf = new CustomFilter("My custom filter", ""); + if (cf.openInEditor()) { + sequence.addFilter(cf); + FileObject fo = getFileObject(cf); + FilterChangedListener listener = new FilterChangedListener(fo, cf); + listener.changed(cf); + cf.getChangedEvent().addListener(listener); + } + } + + public void removeFilter(Filter f) { + com.sun.hotspot.igv.filter.CustomFilter cf = (com.sun.hotspot.igv.filter.CustomFilter) f; + + sequence.removeFilter(cf); + try { + getFileObject(cf).delete(); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + + } + + private static class FilterChangedListener implements ChangedListener { + + private FileObject fileObject; + private CustomFilter filter; + + public FilterChangedListener(FileObject fo, CustomFilter cf) { + fileObject = fo; + filter = cf; + } + + @Override + public void changed(Filter source) { + try { + if (!fileObject.getName().equals(filter.getName())) { + FileLock lock = fileObject.lock(); + fileObject.move(lock, fileObject.getParent(), filter.getName(), ""); + lock.releaseLock(); + FileObject newFileObject = fileObject.getParent().getFileObject(filter.getName()); + fileObject = newFileObject; + } + + FileLock lock = fileObject.lock(); + OutputStream os = fileObject.getOutputStream(lock); + try (Writer w = new OutputStreamWriter(os)) { + String s = filter.getCode(); + w.write(s); + } + lock.releaseLock(); + + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + } + + public void initFilters() { + FileObject folder = FileUtil.getConfigRoot().getFileObject(FOLDER_ID); + FileObject[] children = folder.getChildren(); + + List customFilters = new ArrayList<>(); + HashMap afterMap = new HashMap<>(); + Set enabledSet = new HashSet<>(); + HashMap map = new HashMap<>(); + + for (final FileObject fo : children) { + InputStream is = null; + + String code = ""; + FileLock lock = null; + try { + lock = fo.lock(); + is = fo.getInputStream(); + BufferedReader r = new BufferedReader(new InputStreamReader(is)); + String s; + StringBuilder sb = new StringBuilder(); + while ((s = r.readLine()) != null) { + sb.append(s); + sb.append("\n"); + } + code = sb.toString(); + } catch (FileNotFoundException ex) { + Exceptions.printStackTrace(ex); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } finally { + try { + is.close(); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + lock.releaseLock(); + } + + String displayName = fo.getName(); + + + final CustomFilter cf = new CustomFilter(displayName, code); + map.put(displayName, cf); + + String after = (String) fo.getAttribute(AFTER_ID); + afterMap.put(cf, after); + + Boolean enabled = (Boolean) fo.getAttribute(ENABLED_ID); + if (enabled != null && (boolean) enabled) { + enabledSet.add(cf); + } + + cf.getChangedEvent().addListener(new FilterChangedListener(fo, cf)); + + customFilters.add(cf); + } + + for (int j = 0; j < customFilters.size(); j++) { + for (int i = 0; i < customFilters.size(); i++) { + List copiedList = new ArrayList<>(customFilters); + for (CustomFilter cf : copiedList) { + + String after = afterMap.get(cf); + + if (map.containsKey(after)) { + CustomFilter afterCf = map.get(after); + int index = customFilters.indexOf(afterCf); + int currentIndex = customFilters.indexOf(cf); + + if (currentIndex < index) { + customFilters.remove(currentIndex); + customFilters.add(index, cf); + } + } + } + } + } + + for (CustomFilter cf : customFilters) { + sequence.addFilter(cf); + if (enabledSet.contains(cf)) { + filterChain.addFilter(cf); + } + } + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + setLayout(new java.awt.BorderLayout()); + + }// //GEN-END:initComponents + // Variables declaration - do not modify//GEN-BEGIN:variables + // End of variables declaration//GEN-END:variables + /** + * 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 FilterTopComponent getDefault() { + if (instance == null) { + instance = new FilterTopComponent(); + } + return instance; + } + + /** + * Obtain the FilterTopComponent instance. Never call {@link #getDefault} directly! + */ + public static synchronized FilterTopComponent findInstance() { + TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID); + if (win == null) { + ErrorManager.getDefault().log(ErrorManager.WARNING, "Cannot find Filter component. It will not be located properly in the window system."); + return getDefault(); + } + if (win instanceof FilterTopComponent) { + return (FilterTopComponent) 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 + protected String preferredID() { + return PREFERRED_ID; + } + + @Override + public ExplorerManager getExplorerManager() { + return manager; + } + + @Override + public void componentOpened() { + Lookup.Template tpl = new Lookup.Template<>(FilterChain.class); + result = Utilities.actionsGlobalContext().lookup(tpl); + result.addLookupListener(this); + } + + @Override + public void componentClosed() { + result.removeLookupListener(this); + result = null; + } + + @Override + public void resultChanged(LookupEvent lookupEvent) { + setChain(Utilities.actionsGlobalContext().lookup(FilterChain.class)); + } + + public void setChain(FilterChain chain) { + updateComboBoxSelection(); + } + + private FileObject getFileObject(CustomFilter cf) { + FileObject fo = FileUtil.getConfigRoot().getFileObject(FOLDER_ID + "/" + cf.getName()); + if (fo == null) { + try { + fo = FileUtil.getConfigRoot().getFileObject(FOLDER_ID).createData(cf.getName()); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + return fo; + } + + @Override + public boolean requestFocus(boolean temporary) { + view.requestFocus(); + return super.requestFocus(temporary); + } + + @Override + protected boolean requestFocusInWindow(boolean temporary) { + view.requestFocus(); + return super.requestFocusInWindow(temporary); + } + + @Override + public void requestActive() { + super.requestActive(); + view.requestFocus(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + super.writeExternal(out); + + out.writeInt(filterSettings.size()); + for (FilterSetting f : filterSettings) { + out.writeUTF(f.getName()); + + out.writeInt(f.getFilterCount()); + for (Filter filter : f.getFilters()) { + CustomFilter cf = (CustomFilter) filter; + out.writeUTF(cf.getName()); + } + } + + CustomFilter prev = null; + for (Filter f : this.sequence.getFilters()) { + CustomFilter cf = (CustomFilter) f; + FileObject fo = getFileObject(cf); + if (getFilterChain().containsFilter(cf)) { + fo.setAttribute(ENABLED_ID, true); + } else { + fo.setAttribute(ENABLED_ID, false); + } + + if (prev == null) { + fo.setAttribute(AFTER_ID, null); + } else { + fo.setAttribute(AFTER_ID, prev.getName()); + } + + prev = cf; + } + } + + public CustomFilter findFilter(String name) { + for (Filter f : sequence.getFilters()) { + + CustomFilter cf = (CustomFilter) f; + if (cf.getName().equals(name)) { + return cf; + } + } + + return null; + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + super.readExternal(in); + + int filterSettingsCount = in.readInt(); + for (int i = 0; i < filterSettingsCount; i++) { + String name = in.readUTF(); + FilterSetting s = new FilterSetting(name); + int filterCount = in.readInt(); + for (int j = 0; j < filterCount; j++) { + String filterName = in.readUTF(); + CustomFilter filter = findFilter(filterName); + if (filter != null) { + s.addFilter(filter); + } + } + + filterSettings.add(s); + } + updateComboBox(); + } + + final static class ResolvableHelper implements Serializable { + + private static final long serialVersionUID = 1L; + + public Object readResolve() { + return FilterTopComponent.getDefault(); + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/FilterTopComponentSettings.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/FilterTopComponentSettings.xml Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,8 @@ + + + + + + + + diff -r 6cb549627941 -r 015fb895586b visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/FilterTopComponentWstcref.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/FilterTopComponentWstcref.xml Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,7 @@ + + + + + + + diff -r 6cb549627941 -r 015fb895586b visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/Bundle.properties Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,7 @@ +CTL_FilterAction=Filters +CTL_MoveFilterUpAction=Move upwards +CTL_MoveFilterDownAction=Move downwards +CTL_RemoveFilterAction=Remove +CTL_RemoveFilterSettingsAction=Remove filter setting +CTL_SaveFilterSettingsAction=Create filter profile... +CTL_NewFilterAction=New filter... diff -r 6cb549627941 -r 015fb895586b visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/FilterAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/FilterAction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,48 @@ +/* + * 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.filterwindow.actions; + +import com.sun.hotspot.igv.filterwindow.FilterTopComponent; +import java.awt.event.ActionEvent; +import javax.swing.AbstractAction; +import org.openide.util.NbBundle; +import org.openide.windows.TopComponent; + +/** + * + * @author Thomas Wuerthinger + */ +public class FilterAction extends AbstractAction { + + public FilterAction() { + super(NbBundle.getMessage(FilterAction.class, "CTL_FilterAction")); + } + + @Override + public void actionPerformed(ActionEvent evt) { + TopComponent win = FilterTopComponent.findInstance(); + win.open(); + win.requestActive(); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/MoveFilterDownAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/MoveFilterDownAction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,90 @@ +/* + * 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.filterwindow.actions; + +import com.sun.hotspot.igv.filter.Filter; +import com.sun.hotspot.igv.filterwindow.FilterTopComponent; +import javax.swing.Action; +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 MoveFilterDownAction extends CookieAction { + + @Override + protected void performAction(Node[] activatedNodes) { + for (Node n : activatedNodes) { + Filter c = n.getLookup().lookup(Filter.class); + FilterTopComponent.findInstance().getSequence().moveFilterDown(c); + } + } + + @Override + protected int mode() { + return CookieAction.MODE_EXACTLY_ONE; + } + + public MoveFilterDownAction() { + + putValue(Action.SHORT_DESCRIPTION, "Move selected filter downwards"); + } + + @Override + public String getName() { + return NbBundle.getMessage(MoveFilterUpAction.class, "CTL_MoveFilterDownAction"); + } + + @Override + protected Class[] cookieClasses() { + return new Class[]{ + Filter.class + }; + } + + @Override + protected String iconResource() { + return "com/sun/hotspot/igv/filterwindow/images/down.png"; + } + + @Override + protected void initialize() { + super.initialize(); + putValue("noIconInMenu", Boolean.TRUE); + } + + @Override + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + @Override + protected boolean asynchronous() { + return false; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/MoveFilterUpAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/MoveFilterUpAction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,89 @@ +/* + * 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.filterwindow.actions; + +import com.sun.hotspot.igv.filter.Filter; +import com.sun.hotspot.igv.filterwindow.FilterTopComponent; +import javax.swing.Action; +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 MoveFilterUpAction extends CookieAction { + + @Override + protected void performAction(Node[] activatedNodes) { + for (Node n : activatedNodes) { + Filter c = n.getLookup().lookup(Filter.class); + FilterTopComponent.findInstance().getSequence().moveFilterUp(c); + } + } + + @Override + protected int mode() { + return CookieAction.MODE_EXACTLY_ONE; + } + + public MoveFilterUpAction() { + putValue(Action.SHORT_DESCRIPTION, "Move selected filter upwards"); + } + + @Override + public String getName() { + return NbBundle.getMessage(MoveFilterUpAction.class, "CTL_MoveFilterUpAction"); + } + + @Override + protected Class[] cookieClasses() { + return new Class[]{ + Filter.class + }; + } + + @Override + protected String iconResource() { + return "com/sun/hotspot/igv/filterwindow/images/up.png"; + } + + @Override + protected void initialize() { + super.initialize(); + putValue("noIconInMenu", Boolean.TRUE); + } + + @Override + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + @Override + protected boolean asynchronous() { + return false; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/NewFilterAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/NewFilterAction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,71 @@ +/* + * 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.filterwindow.actions; + +import com.sun.hotspot.igv.filterwindow.FilterTopComponent; +import javax.swing.Action; +import org.openide.util.HelpCtx; +import org.openide.util.NbBundle; +import org.openide.util.actions.CallableSystemAction; + +/** + * + * @author Thomas Wuerthinger + */ +public final class NewFilterAction extends CallableSystemAction { + + public NewFilterAction() { + putValue(Action.SHORT_DESCRIPTION, "Create new filter"); + } + + @Override + public void performAction() { + FilterTopComponent.findInstance().newFilter(); + } + + @Override + public String getName() { + return NbBundle.getMessage(SaveFilterSettingsAction.class, "CTL_NewFilterAction"); + } + + @Override + protected void initialize() { + super.initialize(); + } + + @Override + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + @Override + protected boolean asynchronous() { + return false; + } + + @Override + protected String iconResource() { + return "com/sun/hotspot/igv/filterwindow/images/plus.png"; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/RemoveFilterAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/RemoveFilterAction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,104 @@ +/* + * 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.filterwindow.actions; + +import com.sun.hotspot.igv.filter.Filter; +import com.sun.hotspot.igv.filterwindow.FilterTopComponent; +import javax.swing.Action; +import javax.swing.JOptionPane; +import org.openide.nodes.Node; +import org.openide.util.HelpCtx; +import org.openide.util.NbBundle; +import org.openide.util.actions.CookieAction; +import org.openide.windows.WindowManager; + +/** + * + * @author Thomas Wuerthinger + */ +public final class RemoveFilterAction extends CookieAction { + + @Override + protected void performAction(Node[] activatedNodes) { + Object[] options = {"Yes", + "No", + "Cancel" + }; + int n = JOptionPane.showOptionDialog(WindowManager.getDefault().getMainWindow(), + "Do you really want to delete " + activatedNodes.length + " filter(s)?", "Delete Filters", + JOptionPane.YES_NO_CANCEL_OPTION, + JOptionPane.QUESTION_MESSAGE, + null, + options, + options[2]); + + if (n == JOptionPane.YES_OPTION) { + for (int i = 0; i < activatedNodes.length; i++) { + FilterTopComponent.findInstance().removeFilter(activatedNodes[i].getLookup().lookup(Filter.class)); + } + } + } + + @Override + protected int mode() { + return CookieAction.MODE_ALL; + } + + @Override + public String getName() { + return NbBundle.getMessage(RemoveFilterAction.class, "CTL_RemoveFilterAction"); + } + + public RemoveFilterAction() { + putValue(Action.SHORT_DESCRIPTION, "Remove selected filter"); + } + + @Override + protected Class[] cookieClasses() { + return new Class[]{ + Filter.class + }; + } + + @Override + protected void initialize() { + super.initialize(); + putValue("noIconInMenu", Boolean.TRUE); + } + + @Override + protected String iconResource() { + return "com/sun/hotspot/igv/filterwindow/images/minus.png"; + } + + @Override + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + @Override + protected boolean asynchronous() { + return false; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/RemoveFilterSettingsAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/RemoveFilterSettingsAction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,71 @@ +/* + * 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.filterwindow.actions; + +import com.sun.hotspot.igv.filterwindow.FilterTopComponent; +import javax.swing.Action; +import org.openide.util.HelpCtx; +import org.openide.util.NbBundle; +import org.openide.util.actions.CallableSystemAction; + +/** + * + * @author Thomas Wuerthinger + */ +public final class RemoveFilterSettingsAction extends CallableSystemAction { + + @Override + public void performAction() { + FilterTopComponent.findInstance().removeFilterSetting(); + } + + @Override + public String getName() { + return NbBundle.getMessage(RemoveFilterSettingsAction.class, "CTL_RemoveFilterSettingsAction"); + } + + public RemoveFilterSettingsAction() { + putValue(Action.SHORT_DESCRIPTION, "Delete current filter profile"); + } + + @Override + protected void initialize() { + super.initialize(); + } + + @Override + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + @Override + protected boolean asynchronous() { + return false; + } + + @Override + protected String iconResource() { + return "com/sun/hotspot/igv/filterwindow/images/delete.png"; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/SaveFilterSettingsAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/SaveFilterSettingsAction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,71 @@ +/* + * 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.filterwindow.actions; + +import com.sun.hotspot.igv.filterwindow.FilterTopComponent; +import javax.swing.Action; +import org.openide.util.HelpCtx; +import org.openide.util.NbBundle; +import org.openide.util.actions.CallableSystemAction; + +/** + * + * @author Thomas Wuerthinger + */ +public final class SaveFilterSettingsAction extends CallableSystemAction { + + @Override + public void performAction() { + FilterTopComponent.findInstance().addFilterSetting(); + } + + @Override + public String getName() { + return NbBundle.getMessage(SaveFilterSettingsAction.class, "CTL_SaveFilterSettingsAction"); + } + + @Override + protected void initialize() { + super.initialize(); + } + + public SaveFilterSettingsAction() { + putValue(Action.SHORT_DESCRIPTION, "Save filter configuration as profile..."); + } + + @Override + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + @Override + protected boolean asynchronous() { + return false; + } + + @Override + protected String iconResource() { + return "com/sun/hotspot/igv/filterwindow/images/add.png"; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/customRightTopWsmode.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/customRightTopWsmode.xml Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff -r 6cb549627941 -r 015fb895586b visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/images/add.png Binary file visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/images/add.png has changed diff -r 6cb549627941 -r 015fb895586b visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/images/delete.png Binary file visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/images/delete.png has changed diff -r 6cb549627941 -r 015fb895586b visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/images/down.png Binary file visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/images/down.png has changed diff -r 6cb549627941 -r 015fb895586b visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/images/minus.png Binary file visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/images/minus.png has changed diff -r 6cb549627941 -r 015fb895586b visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/images/plus.png Binary file visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/images/plus.png has changed diff -r 6cb549627941 -r 015fb895586b visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/images/up.png Binary file visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/images/up.png has changed diff -r 6cb549627941 -r 015fb895586b visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/layer.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/layer.xml Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 6cb549627941 -r 015fb895586b visualizer/Graal/manifest.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Graal/manifest.mf Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,6 @@ +Manifest-Version: 1.0 +OpenIDE-Module: com.sun.hotspot.igv.graal +OpenIDE-Module-Layer: com/sun/hotspot/igv/graal/layer.xml +OpenIDE-Module-Localizing-Bundle: com/sun/hotspot/igv/graal/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff -r 6cb549627941 -r 015fb895586b visualizer/Graal/src/com/sun/hotspot/igv/graal/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Graal/src/com/sun/hotspot/igv/graal/Bundle.properties Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,1 @@ +OpenIDE-Module-Name=GraalCompilerSupport diff -r 6cb549627941 -r 015fb895586b visualizer/Graal/src/com/sun/hotspot/igv/graal/filters/GraalCFGFilter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Graal/src/com/sun/hotspot/igv/graal/filters/GraalCFGFilter.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,74 @@ +/* + * 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.graal.filters; + +import com.sun.hotspot.igv.data.Properties; +import com.sun.hotspot.igv.filter.AbstractFilter; +import com.sun.hotspot.igv.graph.Connection; +import com.sun.hotspot.igv.graph.Diagram; +import com.sun.hotspot.igv.graph.Figure; +import com.sun.hotspot.igv.graph.InputSlot; +import java.util.HashSet; +import java.util.Set; + +public class GraalCFGFilter extends AbstractFilter { + + @Override + public String getName() { + return "Graal CFG Filter"; + } + + @Override + public void apply(Diagram d) { + Set
figuresToRemove = new HashSet<>(); + Set connectionsToRemove = new HashSet<>(); + for (Figure f : d.getFigures()) { + final String prop = f.getProperties().get("probability"); + + if (prop == null) { + figuresToRemove.add(f); + } + } + d.removeAllFigures(figuresToRemove); + + for (Figure f : d.getFigures()) { + Properties p = f.getProperties(); + int predCount = Integer.parseInt(p.get("predecessorCount")); + for (InputSlot is : f.getInputSlots()) { + if (is.getPosition() >= predCount && !"EndNode".equals(is.getProperties().get("class"))) { + for (Connection c : is.getConnections()) { + if (!"EndNode".equals(c.getOutputSlot().getFigure().getProperties().get("class"))) { + connectionsToRemove.add(c); + } + } + } + } + } + + for (Connection c : connectionsToRemove) { + c.remove(); + System.out.println("rm " + c); + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Graal/src/com/sun/hotspot/igv/graal/filters/GraalColoringFilter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Graal/src/com/sun/hotspot/igv/graal/filters/GraalColoringFilter.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,81 @@ +/* + * 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.graal.filters; + +import com.sun.hotspot.igv.data.Properties; +import com.sun.hotspot.igv.filter.AbstractFilter; +import com.sun.hotspot.igv.graph.Diagram; +import com.sun.hotspot.igv.graph.Figure; +import java.awt.Color; +import java.util.List; + +public class GraalColoringFilter extends AbstractFilter { + + private String colorName; + + public GraalColoringFilter(String colorName) { + this.colorName = colorName; + } + + @Override + public String getName() { + return "Graal Coloring Filter (" + colorName + ")"; + } + + @Override + public void apply(Diagram d) { + List
figures = d.getFigures(); + int colors = 0; + for (Figure f : figures) { + Properties p = f.getProperties(); + final String prop = p.get(colorName + "Color"); + if (prop == null) { + continue; + } + try { + int color = Integer.parseInt(prop); + if (color > colors) { + colors = color; + } + } catch (NumberFormatException nfe) { + // nothing to do + } + } + colors++; + for (Figure f : figures) { + Properties p = f.getProperties(); + final String prop = p.get(colorName + "Color"); + if (prop == null) { + continue; + } + try { + int color = Integer.parseInt(prop); + Color c = Color.getHSBColor((float) color / colors, 1.0f, 0.7f); + f.setColor(c); + } catch (NumberFormatException nfe) { + // nothing to do + } + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Graal/src/com/sun/hotspot/igv/graal/filters/GraalEdgeColorFilter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Graal/src/com/sun/hotspot/igv/graal/filters/GraalEdgeColorFilter.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,114 @@ +/* + * 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.graal.filters; + +import com.sun.hotspot.igv.data.Properties; +import com.sun.hotspot.igv.filter.AbstractFilter; +import com.sun.hotspot.igv.graph.Connection; +import com.sun.hotspot.igv.graph.Connection.ConnectionStyle; +import com.sun.hotspot.igv.graph.Diagram; +import com.sun.hotspot.igv.graph.Figure; +import com.sun.hotspot.igv.graph.InputSlot; +import java.awt.Color; +import java.util.List; + +/** + * Filter that colors usage and successor edges differently. + * + * @author Peter Hofer + */ +public class GraalEdgeColorFilter extends AbstractFilter { + + private Color successorColor = Color.BLUE; + private Color usageColor = Color.RED; + private Color memoryColor = Color.GREEN; + + public GraalEdgeColorFilter() { + } + + @Override + public String getName() { + return "Graal Edge Color Filter"; + } + + @Override + public void apply(Diagram d) { + List
figures = d.getFigures(); + for (Figure f : figures) { + Properties p = f.getProperties(); + int predCount; + if (p.get("predecessorCount") != null) { + predCount = Integer.parseInt(p.get("predecessorCount")); + } else { + predCount = 0; + } + for (InputSlot is : f.getInputSlots()) { + Color color; + ConnectionStyle style = ConnectionStyle.NORMAL; + if (is.getPosition() < predCount) { + color = successorColor; + style = ConnectionStyle.BOLD; + } else { + color = usageColor; + } + + is.setColor(color); + for (Connection c : is.getConnections()) { + if (c.getLabel() == null || !c.getLabel().endsWith("#NDF")) { + c.setColor(color); + c.setStyle(style); + } else if ("EndNode".equals(c.getOutputSlot().getFigure().getProperties().get("class")) + || "EndNode".equals(c.getOutputSlot().getProperties().get("class"))) { + c.setColor(successorColor); + c.setStyle(ConnectionStyle.BOLD); + } + } + } + } + } + + public Color getUsageColor() { + return usageColor; + } + + public void setUsageColor(Color usageColor) { + this.usageColor = usageColor; + } + + public void setMemoryColor(Color memoryColor) { + this.memoryColor = memoryColor; + } + + public Color getMemoryColor() { + return memoryColor; + } + + public Color getSuccessorColor() { + return successorColor; + } + + public void setSuccessorColor(Color successorColor) { + this.successorColor = successorColor; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Graal/src/com/sun/hotspot/igv/graal/filters/beginend.filter --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Graal/src/com/sun/hotspot/igv/graal/filters/beginend.filter Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,4 @@ +var f = new CombineFilter("Combine Filter"); +f.addRule(new CombineFilter.CombineRule(new Properties.RegexpPropertyMatcher("class", ".*"), new Properties.RegexpPropertyMatcher("class", "BeginNode"), false, "shortName")); +f.addRule(new CombineFilter.CombineRule(new Properties.RegexpPropertyMatcher("class", "EndNode"), new Properties.RegexpPropertyMatcher("class", ".*"), true, "shortName")); +f.apply(graph); diff -r 6cb549627941 -r 015fb895586b visualizer/Graal/src/com/sun/hotspot/igv/graal/filters/callgraph.filter --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Graal/src/com/sun/hotspot/igv/graal/filters/callgraph.filter Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,4 @@ +colorize("name", ".*", yellow); +colorize("name", ".*", pink); +colorize("leaf", "1", lightGray); +colorize("cutoff", "1", red); diff -r 6cb549627941 -r 015fb895586b visualizer/Graal/src/com/sun/hotspot/igv/graal/filters/cfg.filter --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Graal/src/com/sun/hotspot/igv/graal/filters/cfg.filter Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,2 @@ +var f = new com.sun.hotspot.igv.graal.filters.GraalCFGFilter(); +f.apply(graph); diff -r 6cb549627941 -r 015fb895586b visualizer/Graal/src/com/sun/hotspot/igv/graal/filters/color.filter --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Graal/src/com/sun/hotspot/igv/graal/filters/color.filter Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,11 @@ +colorize("name", ".*", white); +colorize("name", "StartNode|EndNode|LoopBegin|LoopEnd|Return", orange); +colorize("name", "Phi:.*", magenta); +colorize("name", "FrameState@.*", new java.awt.Color(0.5, 0.8, 1.0)); +colorize("name", "If", pink); +colorize("name", "const.*", new java.awt.Color(0.7, 0.7, 0.7)); +colorize("name", "Local", new java.awt.Color(0.85, 0.85, 0.85)); +colorize("name", "\\+|-|\\*|/", cyan); +colorize("name", "Comp .*", yellow); + +colorize("notInOwnBlock", "true", red); \ No newline at end of file diff -r 6cb549627941 -r 015fb895586b visualizer/Graal/src/com/sun/hotspot/igv/graal/filters/edgeColor.filter --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Graal/src/com/sun/hotspot/igv/graal/filters/edgeColor.filter Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,4 @@ +var f = new com.sun.hotspot.igv.graal.filters.GraalEdgeColorFilter(); +f.setUsageColor(blue); +f.setSuccessorColor(red); +f.apply(graph); diff -r 6cb549627941 -r 015fb895586b visualizer/Graal/src/com/sun/hotspot/igv/graal/filters/framestatelocks.filter --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Graal/src/com/sun/hotspot/igv/graal/filters/framestatelocks.filter Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,2 @@ +colorize("class", "FrameState", red); +colorize("locks", "", gray); \ No newline at end of file diff -r 6cb549627941 -r 015fb895586b visualizer/Graal/src/com/sun/hotspot/igv/graal/filters/noframestate.filter --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Graal/src/com/sun/hotspot/igv/graal/filters/noframestate.filter Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,1 @@ +remove("class", "FrameState"); \ No newline at end of file diff -r 6cb549627941 -r 015fb895586b visualizer/Graal/src/com/sun/hotspot/igv/graal/filters/probability.filter --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Graal/src/com/sun/hotspot/igv/graal/filters/probability.filter Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,3 @@ +colorizeGradientWithMode("probability", 0, 500, "logarithmic"); + +// more parameters: colorizeGradientCustom("probability", 0, 500, "logarithmic", [blue, yellow, red], [0, 0.5, 1], 16); diff -r 6cb549627941 -r 015fb895586b visualizer/Graal/src/com/sun/hotspot/igv/graal/filters/slots.filter --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Graal/src/com/sun/hotspot/igv/graal/filters/slots.filter Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,1 @@ +removeUnconnectedSlots(true, true); diff -r 6cb549627941 -r 015fb895586b visualizer/Graal/src/com/sun/hotspot/igv/graal/layer.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Graal/src/com/sun/hotspot/igv/graal/layer.xml Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 6cb549627941 -r 015fb895586b visualizer/Graph/manifest.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Graph/manifest.mf Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +OpenIDE-Module: com.sun.hotspot.igv.graph +OpenIDE-Module-Localizing-Bundle: com/sun/hotspot/igv/graph/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff -r 6cb549627941 -r 015fb895586b visualizer/Graph/src/com/sun/hotspot/igv/graph/AndSelector.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Graph/src/com/sun/hotspot/igv/graph/AndSelector.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,55 @@ +/* + * 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.graph; + +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public class AndSelector implements Selector { + + private Selector selector1; + private Selector selector2; + + public AndSelector(Selector s1, Selector s2) { + this.selector1 = s1; + this.selector2 = s2; + } + + @Override + public List
selected(Diagram d) { + List
l1 = selector1.selected(d); + List
l2 = selector2.selected(d); + List
result = new ArrayList<>(); + for (Figure f : l2) { + if (l1.contains(f)) { + result.add(f); + } + } + return result; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Graph/src/com/sun/hotspot/igv/graph/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Graph/src/com/sun/hotspot/igv/graph/Bundle.properties Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,1 @@ +OpenIDE-Module-Name=Graph diff -r 6cb549627941 -r 015fb895586b visualizer/Graph/src/com/sun/hotspot/igv/graph/Connection.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Graph/src/com/sun/hotspot/igv/graph/Connection.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,154 @@ +/* + * 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.graph; + +import com.sun.hotspot.igv.data.Source; +import com.sun.hotspot.igv.layout.Link; +import com.sun.hotspot.igv.layout.Port; +import java.awt.Color; +import java.awt.Point; +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public class Connection implements Source.Provider, Link { + + @Override + public boolean isVIP() { + return style == ConnectionStyle.BOLD; + } + + public enum ConnectionStyle { + + NORMAL, + DASHED, + BOLD + } + private InputSlot inputSlot; + private OutputSlot outputSlot; + private Source source; + private Color color; + private ConnectionStyle style; + private List controlPoints; + private String label; + + protected Connection(InputSlot inputSlot, OutputSlot outputSlot, String label) { + this.inputSlot = inputSlot; + this.outputSlot = outputSlot; + this.label = label; + this.inputSlot.connections.add(this); + this.outputSlot.connections.add(this); + controlPoints = new ArrayList<>(); + Figure sourceFigure = this.outputSlot.getFigure(); + Figure destFigure = this.inputSlot.getFigure(); + sourceFigure.addSuccessor(destFigure); + destFigure.addPredecessor(sourceFigure); + source = new Source(); + + this.color = Color.BLACK; + this.style = ConnectionStyle.NORMAL; + } + + public InputSlot getInputSlot() { + return inputSlot; + } + + public OutputSlot getOutputSlot() { + return outputSlot; + } + + public Color getColor() { + return color; + } + + public ConnectionStyle getStyle() { + return style; + } + + public void setColor(Color c) { + color = c; + } + + public void setStyle(ConnectionStyle s) { + style = s; + } + + @Override + public Source getSource() { + return source; + } + + public String getLabel() { + return label; + } + + public void remove() { + inputSlot.getFigure().removePredecessor(outputSlot.getFigure()); + inputSlot.connections.remove(this); + outputSlot.getFigure().removeSuccessor(inputSlot.getFigure()); + outputSlot.connections.remove(this); + } + + public String getToolTipText() { + StringBuilder builder = new StringBuilder(); + if (label != null) { + builder.append(label).append(": from "); + } else { + builder.append("From "); + } + builder.append(getOutputSlot().getFigure()); + builder.append(" to "); + builder.append(getInputSlot().getFigure()); + return builder.toString(); + } + + @Override + public String toString() { + return "Connection('" + label + "', " + getFrom().getVertex() + " to " + getTo().getVertex() + ")"; + } + + @Override + public Port getFrom() { + return outputSlot; + } + + @Override + public Port getTo() { + return inputSlot; + } + + @Override + public List getControlPoints() { + return controlPoints; + } + + @Override + public void setControlPoints(List list) { + controlPoints = list; + } +} + diff -r 6cb549627941 -r 015fb895586b visualizer/Graph/src/com/sun/hotspot/igv/graph/Diagram.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Graph/src/com/sun/hotspot/igv/graph/Diagram.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,283 @@ +/* + * 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.graph; + +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.Properties; +import com.sun.hotspot.igv.data.Properties.StringPropertyMatcher; +import java.awt.Font; +import java.util.*; + +/** + * + * @author Thomas Wuerthinger + */ +public class Diagram { + + private List
figures; + private InputGraph graph; + private int curId; + private String nodeText; + private Font font; + private Font slotFont; + + public Font getFont() { + return font; + } + + public Font getSlotFont() { + return slotFont; + } + + private Diagram() { + figures = new ArrayList<>(); + this.nodeText = ""; + this.font = new Font("Arial", Font.PLAIN, 13); + this.slotFont = new Font("Arial", Font.PLAIN, 10); + } + + public String getNodeText() { + return nodeText; + } + + public Diagram getNext() { + return Diagram.createDiagram(graph.getNext(), nodeText); + } + + public Diagram getPrev() { + return Diagram.createDiagram(graph.getPrev(), nodeText); + } + + public List
getFigures() { + return Collections.unmodifiableList(figures); + } + + public Figure createFigure() { + Figure f = new Figure(this, curId); + curId++; + this.figures.add(f); + return f; + } + + public Connection createConnection(InputSlot inputSlot, OutputSlot outputSlot, String label) { + assert inputSlot.getFigure().getDiagram() == this; + assert outputSlot.getFigure().getDiagram() == this; + return new Connection(inputSlot, outputSlot, label); + } + + public Map> calcSourceToFigureRelation() { + Map> map = new HashMap<>(); + + for(InputNode node : this.getGraph().getNodes()) { + map.put(node, new HashSet
()); + } + + for(Figure f : this.getFigures()) { + for(InputNode node : f.getSource().getSourceNodes()) { + map.get(node).add(f); + } + } + + return map; + } + + public static Diagram createDiagram(InputGraph graph, String nodeText) { + if (graph == null) { + return null; + } + + Diagram d = new Diagram(); + d.graph = graph; + d.nodeText = nodeText; + + Collection nodes = graph.getNodes(); + Hashtable figureHash = new Hashtable<>(); + for (InputNode n : nodes) { + Figure f = d.createFigure(); + f.getSource().addSourceNode(n); + f.getProperties().add(n.getProperties()); + figureHash.put(n.getId(), f); + } + + for (InputEdge e : graph.getEdges()) { + + int from = e.getFrom(); + int to = e.getTo(); + Figure fromFigure = figureHash.get(from); + Figure toFigure = figureHash.get(to); + assert fromFigure != null && toFigure != null; + + if(fromFigure == null || toFigure == null) continue; + + int fromIndex = e.getFromIndex(); + while (fromFigure.getOutputSlots().size() <= fromIndex) { + fromFigure.createOutputSlot(); + } + OutputSlot outputSlot = fromFigure.getOutputSlots().get(fromIndex); + + int toIndex = e.getToIndex(); + while (toFigure.getInputSlots().size() <= toIndex) { + toFigure.createInputSlot(); + } + InputSlot inputSlot = toFigure.getInputSlots().get(toIndex); + + Connection c = d.createConnection(inputSlot, outputSlot, e.getLabel()); + + if (e.getState() == InputEdge.State.NEW) { + c.setStyle(Connection.ConnectionStyle.BOLD); + } else if (e.getState() == InputEdge.State.DELETED) { + c.setStyle(Connection.ConnectionStyle.DASHED); + } + } + + + return d; + } + + public void removeAllFigures(Set
figuresToRemove) { + for (Figure f : figuresToRemove) { + freeFigure(f); + } + + ArrayList
newFigures = new ArrayList<>(); + for (Figure f : this.figures) { + if (!figuresToRemove.contains(f)) { + newFigures.add(f); + } + } + figures = newFigures; + } + + private void freeFigure(Figure succ) { + + List inputSlots = new ArrayList<>(succ.getInputSlots()); + for (InputSlot s : inputSlots) { + succ.removeInputSlot(s); + } + + List outputSlots = new ArrayList<>(succ.getOutputSlots()); + for (OutputSlot s : outputSlots) { + succ.removeOutputSlot(s); + } + + assert succ.getInputSlots().size() == 0; + assert succ.getOutputSlots().size() == 0; + assert succ.getPredecessors().size() == 0; + assert succ.getSuccessors().size() == 0; + + } + + public void removeFigure(Figure succ) { + + assert this.figures.contains(succ); + freeFigure(succ); + this.figures.remove(succ); + } + + public String getName() { + return graph.getName(); + } + + public InputGraph getGraph() { + return graph; + } + + public Set getConnections() { + + Set connections = new HashSet<>(); + for (Figure f : figures) { + + for (InputSlot s : f.getInputSlots()) { + connections.addAll(s.getConnections()); + } + } + + return connections; + } + + public Figure getRootFigure() { + Properties.PropertySelector
selector = new Properties.PropertySelector<>(figures); + Figure root = selector.selectSingle(new StringPropertyMatcher("name", "Root")); + if (root == null) { + root = selector.selectSingle(new StringPropertyMatcher("name", "Start")); + } + if (root == null) { + List
rootFigures = getRootFigures(); + if (rootFigures.size() > 0) { + root = rootFigures.get(0); + } else if (figures.size() > 0) { + root = figures.get(0); + } + } + + return root; + } + + public void printStatistics() { + System.out.println("============================================================="); + System.out.println("Diagram statistics"); + + List
tmpFigures = getFigures(); + Set connections = getConnections(); + + System.out.println("Number of figures: " + tmpFigures.size()); + System.out.println("Number of connections: " + connections.size()); + + List
figuresSorted = new ArrayList<>(tmpFigures); + Collections.sort(figuresSorted, new Comparator
() { + + @Override + public int compare(Figure a, Figure b) { + return b.getPredecessors().size() + b.getSuccessors().size() - a.getPredecessors().size() - a.getSuccessors().size(); + } + }); + + final int COUNT = 10; + int z = 0; + for (Figure f : figuresSorted) { + + z++; + int sum = f.getPredecessors().size() + f.getSuccessors().size(); + System.out.println("#" + z + ": " + f + ", predCount=" + f.getPredecessors().size() + " succCount=" + f.getSuccessors().size()); + if (sum < COUNT) { + break; + } + + } + + System.out.println("============================================================="); + } + + public List
getRootFigures() { + ArrayList
rootFigures = new ArrayList<>(); + for (Figure f : figures) { + if (f.getPredecessors().size() == 0) { + rootFigures.add(f); + } + } + return rootFigures; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Graph/src/com/sun/hotspot/igv/graph/Figure.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Graph/src/com/sun/hotspot/igv/graph/Figure.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,355 @@ +/* + * 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.graph; + +import com.sun.hotspot.igv.data.InputNode; +import com.sun.hotspot.igv.data.Properties; +import com.sun.hotspot.igv.data.Source; +import com.sun.hotspot.igv.layout.Vertex; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.util.List; +import java.util.*; + +/** + * + * @author Thomas Wuerthinger + */ +public class Figure extends Properties.Entity implements Source.Provider, Vertex { + + public static final int INSET = 12; + public static int SLOT_WIDTH = 12; + public static final int OVERLAPPING = 6; + public static final int SLOT_START = 4; + public static final int SLOT_OFFSET = 8; + public static final boolean VERTICAL_LAYOUT = true; + protected List inputSlots; + protected List outputSlots; + private Source source; + private Diagram diagram; + private Point position; + private List
predecessors; + private List
successors; + private Color color; + private int id; + private String idString; + private String[] lines; + private int heightCash = -1; + private int widthCash = -1; + + public int getHeight() { + if (heightCash == -1) { + BufferedImage image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB); + Graphics g = image.getGraphics(); + g.setFont(diagram.getFont().deriveFont(Font.BOLD)); + FontMetrics metrics = g.getFontMetrics(); + String nodeText = diagram.getNodeText(); + heightCash = nodeText.split("\n").length * metrics.getHeight() + INSET; + } + return heightCash; + } + + public static List getAllBefore(List inputList, T tIn) { + List result = new ArrayList<>(); + for(T t : inputList) { + if(t.equals(tIn)) { + break; + } + result.add(t); + } + return result; + } + + public static int getSlotsWidth(Collection slots) { + int result = Figure.SLOT_OFFSET; + for(Slot s : slots) { + result += s.getWidth() + Figure.SLOT_OFFSET; + } + return result; + } + + public int getWidth() { + if (widthCash == -1) { + int max = 0; + BufferedImage image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB); + Graphics g = image.getGraphics(); + g.setFont(diagram.getFont().deriveFont(Font.BOLD)); + FontMetrics metrics = g.getFontMetrics(); + for (String s : getLines()) { + int cur = metrics.stringWidth(s); + if (cur > max) { + max = cur; + } + } + widthCash = max + INSET; + widthCash = Math.max(widthCash, Figure.getSlotsWidth(inputSlots)); + widthCash = Math.max(widthCash, Figure.getSlotsWidth(outputSlots)); + } + return widthCash; + } + + protected Figure(Diagram diagram, int id) { + this.diagram = diagram; + this.source = new Source(); + inputSlots = new ArrayList<>(5); + outputSlots = new ArrayList<>(1); + predecessors = new ArrayList<>(6); + successors = new ArrayList<>(6); + this.id = id; + idString = Integer.toString(id); + + this.position = new Point(0, 0); + this.color = Color.WHITE; + } + + public int getId() { + return id; + } + + public void setColor(Color color) { + this.color = color; + } + + public Color getColor() { + return color; + } + + public List
getPredecessors() { + return Collections.unmodifiableList(predecessors); + } + + public Set
getPredecessorSet() { + Set
result = new HashSet<>(); + for (Figure f : getPredecessors()) { + result.add(f); + } + return Collections.unmodifiableSet(result); + } + + public Set
getSuccessorSet() { + Set
result = new HashSet<>(); + for (Figure f : getSuccessors()) { + result.add(f); + } + return Collections.unmodifiableSet(result); + } + + public List
getSuccessors() { + return Collections.unmodifiableList(successors); + } + + protected void addPredecessor(Figure f) { + this.predecessors.add(f); + } + + protected void addSuccessor(Figure f) { + this.successors.add(f); + } + + protected void removePredecessor(Figure f) { + assert predecessors.contains(f); + predecessors.remove(f); + } + + protected void removeSuccessor(Figure f) { + assert successors.contains(f); + successors.remove(f); + } + + @Override + public void setPosition(Point p) { + this.position = p; + } + + @Override + public Point getPosition() { + return position; + } + + public Diagram getDiagram() { + return diagram; + } + + @Override + public Source getSource() { + return source; + } + + public InputSlot createInputSlot() { + InputSlot slot = new InputSlot(this, -1); + inputSlots.add(slot); + return slot; + } + + public InputSlot createInputSlot(int index) { + InputSlot slot = new InputSlot(this, index); + inputSlots.add(slot); + Collections.sort(inputSlots, Slot.slotIndexComparator); + return slot; + } + + public void removeSlot(Slot s) { + + assert inputSlots.contains(s) || outputSlots.contains(s); + + List connections = new ArrayList<>(s.getConnections()); + for (Connection c : connections) { + c.remove(); + } + + if (inputSlots.contains(s)) { + inputSlots.remove(s); + } else if (outputSlots.contains(s)) { + outputSlots.remove(s); + } + } + + public OutputSlot createOutputSlot() { + OutputSlot slot = new OutputSlot(this, -1); + outputSlots.add(slot); + return slot; + } + + public OutputSlot createOutputSlot(int index) { + OutputSlot slot = new OutputSlot(this, index); + outputSlots.add(slot); + Collections.sort(outputSlots, Slot.slotIndexComparator); + return slot; + } + + public List getInputSlots() { + return Collections.unmodifiableList(inputSlots); + } + + public Set getSlots() { + Set result = new HashSet<>(); + result.addAll(getInputSlots()); + result.addAll(getOutputSlots()); + return result; + } + + public List getOutputSlots() { + return Collections.unmodifiableList(outputSlots); + } + + void removeInputSlot(InputSlot s) { + s.removeAllConnections(); + inputSlots.remove(s); + } + + void removeOutputSlot(OutputSlot s) { + s.removeAllConnections(); + outputSlots.remove(s); + } + + public String[] getLines() { + if (lines == null) { + updateLines(); + } + return lines; + } + + public void updateLines() { + String[] strings = diagram.getNodeText().split("\n"); + String[] result = new String[strings.length]; + + for (int i = 0; i < strings.length; i++) { + result[i] = resolveString(strings[i], getProperties()); + } + + lines = result; + } + + public static final String resolveString(String string, Properties properties) { + + StringBuilder sb = new StringBuilder(); + boolean inBrackets = false; + StringBuilder curIdent = new StringBuilder(); + + for (int i = 0; i < string.length(); i++) { + char c = string.charAt(i); + if (inBrackets) { + if (c == ']') { + String value = properties.get(curIdent.toString()); + if (value == null) { + value = ""; + } + sb.append(value); + inBrackets = false; + } else { + curIdent.append(c); + } + } else { + if (c == '[') { + inBrackets = true; + curIdent = new StringBuilder(); + } else { + sb.append(c); + } + } + } + + return sb.toString(); + } + + @Override + public Dimension getSize() { + if (VERTICAL_LAYOUT) { + int width = Math.max(getWidth(), Figure.SLOT_WIDTH * (Math.max(inputSlots.size(), outputSlots.size()) + 1)); + int height = getHeight() + 2 * Figure.SLOT_WIDTH - 2 * Figure.OVERLAPPING; + + + return new Dimension(width, height); + } else { + int width = getWidth() + 2 * Figure.SLOT_WIDTH - 2*Figure.OVERLAPPING; + int height = Figure.SLOT_WIDTH * (Math.max(inputSlots.size(), outputSlots.size()) + 1); + return new Dimension(width, height); + } + } + + @Override + public String toString() { + return idString; + } + + @Override + public boolean isRoot() { + + List sourceNodes = source.getSourceNodes(); + if (sourceNodes.size() > 0 && sourceNodes.get(0).getProperties().get("name") != null) { + return source.getSourceNodes().get(0).getProperties().get("name").equals("Root"); + } else { + return false; + } + } + + @Override + public int compareTo(Vertex f) { + return toString().compareTo(f.toString()); + } + + public Rectangle getBounds() { + return new Rectangle(this.getPosition(), new Dimension(this.getWidth(), this.getHeight())); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Graph/src/com/sun/hotspot/igv/graph/InputSlot.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Graph/src/com/sun/hotspot/igv/graph/InputSlot.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,63 @@ +/* + * 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.graph; + +import java.awt.Point; +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public class InputSlot extends Slot { + + protected InputSlot(Figure figure, int wantedIndex) { + super(figure, wantedIndex); + } + + @Override + public int getPosition() { + return getFigure().getInputSlots().indexOf(this); + } + + @Override + public void setPosition(int position) { + List inputSlots = getFigure().inputSlots; + InputSlot s = inputSlots.remove(position); + inputSlots.add(position, s); + } + @Override + public Point getRelativePosition() { + int gap = getFigure().getWidth() - Figure.getSlotsWidth(getFigure().getInputSlots()); + double gapRatio = (double)gap / (double)(getFigure().getInputSlots().size() + 1); + int gapAmount = (int)((getPosition() + 1)*gapRatio); + return new Point(gapAmount + Figure.getSlotsWidth(Figure.getAllBefore(getFigure().getInputSlots(), this)) + getWidth()/2, -Figure.SLOT_START); + //return new Point((getFigure().getWidth() / (getFigure().getInputSlots().size() * 2)) * (getPosition() * 2 + 1), -Figure.SLOT_START); + } + + @Override + public String toString() { + return "InputSlot[figure=" + this.getFigure().toString() + ", position=" + getPosition() + "]"; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Graph/src/com/sun/hotspot/igv/graph/InvertSelector.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Graph/src/com/sun/hotspot/igv/graph/InvertSelector.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,54 @@ +/* + * 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.graph; + +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public class InvertSelector implements Selector { + + private Selector selector; + + public InvertSelector(Selector selector) { + this.selector = selector; + } + + @Override + public List
selected(Diagram d) { + + List
result = new ArrayList<>(); + List
otherResult = selector.selected(d); + for (Figure f : d.getFigures()) { + if (!otherResult.contains(f)) { + result.add(f); + } + } + + return result; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Graph/src/com/sun/hotspot/igv/graph/MatcherSelector.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Graph/src/com/sun/hotspot/igv/graph/MatcherSelector.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,48 @@ +/* + * 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.graph; + +import com.sun.hotspot.igv.data.Properties; +import com.sun.hotspot.igv.data.Properties.PropertyMatcher; +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public class MatcherSelector implements Selector { + + private PropertyMatcher matcher; + + public MatcherSelector(PropertyMatcher matcher) { + this.matcher = matcher; + } + + @Override + public List
selected(Diagram d) { + Properties.PropertySelector
selector = new Properties.PropertySelector<>(d.getFigures()); + List
list = selector.selectMultiple(matcher); + return list; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Graph/src/com/sun/hotspot/igv/graph/OrSelector.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Graph/src/com/sun/hotspot/igv/graph/OrSelector.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,57 @@ +/* + * 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.graph; + +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public class OrSelector implements Selector { + + private Selector selector1; + private Selector selector2; + + /** Creates a new instance of OrSelector */ + public OrSelector(Selector s1, Selector s2) { + this.selector1 = s1; + this.selector2 = s2; + } + + @Override + public List
selected(Diagram d) { + + List
l1 = selector1.selected(d); + List
l2 = selector2.selected(d); + + for (Figure f : l2) { + if (!l1.contains(f)) { + l1.add(f); + } + } + + return l1; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Graph/src/com/sun/hotspot/igv/graph/OutputSlot.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Graph/src/com/sun/hotspot/igv/graph/OutputSlot.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,64 @@ +/* + * 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.graph; + +import java.awt.Point; + +/** + * + * @author Thomas Wuerthinger + */ +public class OutputSlot extends Slot { + + protected OutputSlot(Figure figure, int wantedIndex) { + super(figure, wantedIndex); + } + + @Override + public int getPosition() { + return getFigure().getOutputSlots().indexOf(this); + } + + @Override + public void setPosition(int position) { + OutputSlot s = getFigure().outputSlots.remove(position); + getFigure().outputSlots.add(position, s); + } + + @Override + public Point getRelativePosition() { + int gap = getFigure().getWidth() - Figure.getSlotsWidth(getFigure().getOutputSlots()); + if(gap < 0) { + gap = 0; + } + double gapRatio = (double)gap / (double)(getFigure().getOutputSlots().size() + 1); + int gapAmount = (int)((getPosition() + 1)*gapRatio); + return new Point(gapAmount + Figure.getSlotsWidth(Figure.getAllBefore(getFigure().getOutputSlots(), this)) + getWidth()/2, Figure.SLOT_START); + } + + @Override + public String toString() { + return "OutputSlot[figure=" + this.getFigure().toString() + ", position=" + getPosition() + "]"; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Graph/src/com/sun/hotspot/igv/graph/PredecessorSelector.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Graph/src/com/sun/hotspot/igv/graph/PredecessorSelector.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,60 @@ +/* + * 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.graph; + +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public class PredecessorSelector implements Selector { + + private Selector innerSelector; + + public PredecessorSelector(Selector innerSelector) { + this.innerSelector = innerSelector; + } + + @Override + public List
selected(Diagram d) { + List
inner = innerSelector.selected(d); + List
result = new ArrayList<>(); + for (Figure f : d.getFigures()) { + boolean saved = false; + for (Figure f2 : f.getSuccessors()) { + if (inner.contains(f2)) { + saved = true; + } + } + + if (saved) { + result.add(f); + } + } + + return result; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Graph/src/com/sun/hotspot/igv/graph/Selector.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Graph/src/com/sun/hotspot/igv/graph/Selector.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,35 @@ +/* + * 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.graph; + +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public interface Selector { + + List
selected(Diagram d); +} diff -r 6cb549627941 -r 015fb895586b visualizer/Graph/src/com/sun/hotspot/igv/graph/Slot.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Graph/src/com/sun/hotspot/igv/graph/Slot.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,195 @@ +/* + * 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.graph; + +import com.sun.hotspot.igv.data.InputNode; +import com.sun.hotspot.igv.data.Properties; +import com.sun.hotspot.igv.data.Source; +import com.sun.hotspot.igv.layout.Port; +import com.sun.hotspot.igv.layout.Vertex; +import java.awt.Color; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.image.BufferedImage; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public abstract class Slot implements Port, Source.Provider, Properties.Provider { + + private int wantedIndex; + private Source source; + protected List connections; + private InputNode associatedNode; + private Color color; + private String text; + private String shortName; + private Figure figure; + + protected Slot(Figure figure, int wantedIndex) { + this.figure = figure; + connections = new ArrayList<>(2); + source = new Source(); + this.wantedIndex = wantedIndex; + text = ""; + shortName = ""; + assert figure != null; + } + + @Override + public Properties getProperties() { + Properties p = new Properties(); + if (source.getSourceNodes().size() > 0) { + for (InputNode n : source.getSourceNodes()) { + p.add(n.getProperties()); + } + } else { + p.setProperty("name", "Slot"); + p.setProperty("figure", figure.getProperties().get("name")); + p.setProperty("connectionCount", Integer.toString(connections.size())); + } + return p; + } + public static final Comparator slotIndexComparator = new Comparator() { + + @Override + public int compare(Slot o1, Slot o2) { + return o1.wantedIndex - o2.wantedIndex; + } + }; + public static final Comparator slotFigureComparator = new Comparator() { + + @Override + public int compare(Slot o1, Slot o2) { + return o1.figure.getId() - o2.figure.getId(); + } + }; + + public InputNode getAssociatedNode() { + return associatedNode; + } + + public void setAssociatedNode(InputNode node) { + associatedNode = node; + } + + public int getWidth() { + if (shortName == null || shortName.length() <= 1) { + return Figure.SLOT_WIDTH; + } else { + BufferedImage image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB); + Graphics g = image.getGraphics(); + g.setFont(figure.getDiagram().getSlotFont().deriveFont(Font.BOLD)); + FontMetrics metrics = g.getFontMetrics(); + return Math.max(Figure.SLOT_WIDTH, metrics.stringWidth(shortName) + 6); + } + } + + public int getWantedIndex() { + return wantedIndex; + } + + @Override + public Source getSource() { + return source; + } + + public String getText() { + return text; + } + + public void setShortName(String s) { + assert s != null; +// assert s.length() <= 2; + this.shortName = s; + + } + + public String getShortName() { + return shortName; + } + + public String getToolTipText() { + StringBuilder sb = new StringBuilder(); + sb.append(text); + + for (InputNode n : getSource().getSourceNodes()) { + sb.append("Node (ID=" + n.getId() + "): " + n.getProperties().get("name")); + sb.append("
"); + } + + return sb.toString(); + } + + public boolean shouldShowName() { + return getShortName() != null && getShortName().length() > 0; + } + + public void setText(String s) { + if (s == null) { + s = ""; + } + this.text = s; + } + + public Figure getFigure() { + assert figure != null; + return figure; + } + + public Color getColor() { + return this.color; + } + + public void setColor(Color c) { + color = c; + } + + public List getConnections() { + return Collections.unmodifiableList(connections); + } + + public void removeAllConnections() { + List connectionsCopy = new ArrayList<>(this.connections); + for (Connection c : connectionsCopy) { + c.remove(); + } + } + + @Override + public Vertex getVertex() { + return figure; + } + + public abstract int getPosition(); + + public abstract void setPosition(int position); +} + diff -r 6cb549627941 -r 015fb895586b visualizer/Graph/src/com/sun/hotspot/igv/graph/SuccessorSelector.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Graph/src/com/sun/hotspot/igv/graph/SuccessorSelector.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,60 @@ +/* + * 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.graph; + +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public class SuccessorSelector implements Selector { + + private Selector innerSelector; + + public SuccessorSelector(Selector innerSelector) { + this.innerSelector = innerSelector; + } + + @Override + public List
selected(Diagram d) { + List
inner = innerSelector.selected(d); + List
result = new ArrayList<>(); + for (Figure f : d.getFigures()) { + boolean saved = false; + for (Figure f2 : f.getPredecessors()) { + if (inner.contains(f2)) { + saved = true; + } + } + + if (saved) { + result.add(f); + } + } + + return result; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Graph/src/com/sun/hotspot/igv/graph/services/DiagramProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Graph/src/com/sun/hotspot/igv/graph/services/DiagramProvider.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,38 @@ +/* + * 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.graph.services; + +import com.sun.hotspot.igv.data.ChangedEvent; +import com.sun.hotspot.igv.graph.Diagram; + +/** + * + * @author Thomas Wuerthinger + */ +public interface DiagramProvider { + Diagram getDiagram(); + ChangedEvent getChangedEvent(); + +} diff -r 6cb549627941 -r 015fb895586b visualizer/HierarchicalLayout/manifest.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/HierarchicalLayout/manifest.mf Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +OpenIDE-Module: com.sun.hotspot.igv.hierarchicallayout +OpenIDE-Module-Localizing-Bundle: com/sun/hotspot/igv/hierarchicallayout/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff -r 6cb549627941 -r 015fb895586b visualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/Bundle.properties Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,1 @@ +OpenIDE-Module-Name=HierarchicalLayout diff -r 6cb549627941 -r 015fb895586b visualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/Edge.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/Edge.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,90 @@ +/* + * 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.hierarchicallayout; + +/** + * + * @author Thomas Wuerthinger + */ +public class Edge { + + private E data; + private Node source; + private Node dest; + + protected Edge(Graph graph, Node source, Node dest, E data) { + setData(data); + this.source = source; + this.dest = dest; + assert source != null; + assert dest != null; + assert source.getGraph() == dest.getGraph(); + assert source.getGraph() != null; + assert dest.getGraph() != null; + } + + public Node getSource() { + return source; + } + + public Node getDest() { + return dest; + } + + public E getData() { + return data; + } + + public void setData(E e) { + data = e; + } + + public void remove() { + source.getGraph().removeEdge(this, null); + } + + public boolean isSelfLoop() { + return source == dest; + } + + public void reverse() { + + // Remove from current source / dest + source.removeOutEdge(this); + dest.removeInEdge(this); + + Node tmp = source; + source = dest; + dest = tmp; + + // Add to new source / dest + source.addOutEdge(this); + dest.addInEdge(this); + } + + @Override + public String toString() { + return "Edge (" + source + " -- " + dest + "): " + data; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/Graph.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/Graph.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,292 @@ +/* + * 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.hierarchicallayout; + +import java.util.*; + +/** + * + * @author Thomas Wuerthinger + */ +public class Graph { + + private HashMap> nodes; + private HashMap> edges; + private List> nodeList; + + public Graph() { + nodes = new HashMap<>(); + edges = new HashMap<>(); + nodeList = new ArrayList<>(); + } + + public Node createNode(N data, Object key) { + Node n = new Node<>(this, data); + assert key == null || !nodes.containsKey(key); + if (key != null) { + nodes.put(key, n); + } + nodeList.add(n); + return n; + } + + public Edge createEdge(Node source, Node dest, E data, Object key) { + Edge e = new Edge<>(this, source, dest, data); + source.addOutEdge(e); + dest.addInEdge(e); + if (key != null) { + edges.put(key, e); + } + return e; + } + + public Node getNode(Object key) { + return nodes.get(key); + } + + public Edge getEdge(Object key) { + return edges.get(key); + } + + public Collection> getEdges() { + return Collections.unmodifiableCollection(edges.values()); + } + + public Collection> getNodes() { + return Collections.unmodifiableList(nodeList); + } + + public void removeEdge(Edge e, Object key) { + assert key == null || edges.containsKey(key); + if (key != null) { + edges.remove(key); + } + e.getSource().removeOutEdge(e); + e.getDest().removeInEdge(e); + } + + public class DFSTraversalVisitor { + + public void visitNode(Node n) { + } + + public boolean visitEdge(Edge e, boolean backEdge) { + return true; + } + } + + public class BFSTraversalVisitor { + + public void visitNode(Node n, int depth) { + } + } + + public List> getNodesWithInDegree(int x) { + return getNodesWithInDegree(x, true); + } + + public List> getNodesWithInDegree(int x, boolean countSelfLoops) { + + List> result = new ArrayList<>(); + for (Node n : getNodes()) { + if (n.getInDegree(countSelfLoops) == x) { + result.add(n); + } + } + + return result; + + } + + private void markReachable(Node startingNode) { + ArrayList> arr = new ArrayList<>(); + arr.add(startingNode); + for (Node n : getNodes()) { + n.setReachable(false); + } + traverseDFS(arr, new DFSTraversalVisitor() { + + @Override + public void visitNode(Node n) { + n.setReachable(true); + } + }); + } + + public void traverseBFS(Node startingNode, BFSTraversalVisitor tv, boolean longestPath) { + + if (longestPath) { + markReachable(startingNode); + } + + for (Node n : getNodes()) { + n.setVisited(false); + n.setActive(false); + } + + Queue> queue = new LinkedList<>(); + queue.add(startingNode); + startingNode.setVisited(true); + int layer = 0; + Node lastOfLayer = startingNode; + Node lastAdded = null; + + while (!queue.isEmpty()) { + + Node current = queue.poll(); + tv.visitNode(current, layer); + current.setActive(false); + + + for (Edge e : current.getOutEdges()) { + if (!e.getDest().isVisited()) { + + boolean allow = true; + if (longestPath) { + for (Node pred : e.getDest().getPredecessors()) { + if ((!pred.isVisited() || pred.isActive()) && pred.isReachable()) { + allow = false; + break; + } + } + } + + if (allow) { + queue.offer(e.getDest()); + lastAdded = e.getDest(); + e.getDest().setVisited(true); + e.getDest().setActive(true); + } + } + } + + if (current == lastOfLayer && !queue.isEmpty()) { + lastOfLayer = lastAdded; + layer++; + } + } + } + + public void traverseDFS(DFSTraversalVisitor tv) { + traverseDFS(getNodes(), tv); + } + + public void traverseDFS(Collection> startingNodes, DFSTraversalVisitor tv) { + + for (Node n : getNodes()) { + n.setVisited(false); + n.setActive(false); + } + + boolean result = false; + for (Node n : startingNodes) { + traverse(tv, n); + } + } + + private void traverse(DFSTraversalVisitor tv, Node n) { + + if (!n.isVisited()) { + n.setVisited(true); + n.setActive(true); + tv.visitNode(n); + + for (Edge e : n.getOutEdges()) { + + Node next = e.getDest(); + if (next.isActive()) { + tv.visitEdge(e, true); + } else { + if (tv.visitEdge(e, false)) { + traverse(tv, next); + } + } + } + + n.setActive(false); + } + + } + + public boolean hasCycles() { + + for (Node n : getNodes()) { + n.setVisited(false); + n.setActive(false); + } + + boolean result = false; + for (Node n : getNodes()) { + result |= checkCycles(n); + if (result) { + break; + } + } + return result; + } + + private boolean checkCycles(Node n) { + + if (n.isActive()) { + return true; + } + + if (!n.isVisited()) { + + n.setVisited(true); + n.setActive(true); + + for (Node succ : n.getSuccessors()) { + if (checkCycles(succ)) { + return true; + } + } + + n.setActive(false); + + } + + return false; + } + + @Override + public String toString() { + + StringBuilder s = new StringBuilder(); + s.append("Nodes: "); + for (Node n : getNodes()) { + s.append(n.toString()); + s.append("\n"); + } + + s.append("Edges: "); + + for (Edge e : getEdges()) { + s.append(e.toString()); + s.append("\n"); + } + + return s.toString(); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/HierarchicalLayoutManager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/HierarchicalLayoutManager.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,1749 @@ +/* + * 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.hierarchicallayout; + +import com.sun.hotspot.igv.layout.LayoutGraph; +import com.sun.hotspot.igv.layout.LayoutManager; +import com.sun.hotspot.igv.layout.Link; +import com.sun.hotspot.igv.layout.Vertex; +import java.awt.Dimension; +import java.awt.Point; +import java.util.*; + +/** + * + * @author Thomas Wuerthinger + */ +public class HierarchicalLayoutManager implements LayoutManager { + + public static final boolean TRACE = false; + public static final boolean CHECK = false; + public static final int SWEEP_ITERATIONS = 1; + public static final int CROSSING_ITERATIONS = 2; + public static final int DUMMY_HEIGHT = 1; + public static final int DUMMY_WIDTH = 1; + public static final int X_OFFSET = 9; + public static final int LAYER_OFFSET = 30; + public static final int MAX_LAYER_LENGTH = -1; + public static final int MIN_LAYER_DIFFERENCE = 1; + public static final int VIP_BONUS = 10; + + public enum Combine { + + NONE, + SAME_INPUTS, + SAME_OUTPUTS + } + // Options + private Combine combine; + private int dummyWidth; + private int dummyHeight; + private int xOffset; + private int layerOffset; + private int maxLayerLength; + private int minLayerDifference; + // Algorithm global datastructures + private Set reversedLinks; + private List nodes; + private HashMap vertexToLayoutNode; + private HashMap> reversedLinkStartPoints; + private HashMap> reversedLinkEndPoints; + private HashMap bottomEdgeHash; + private HashMap> splitStartPoints; + private HashMap> splitEndPoints; + private LayoutGraph graph; + private List[] layers; + private int layerCount; + private Set firstLayerHint; + private Set lastLayerHint; + private Set importantLinks; + private Set linksToFollow; + + private class LayoutNode { + + public int x; + public int y; + public int width; + public int height; + public int layer = -1; + public int xOffset; + public int yOffset; + public int bottomYOffset; + public Vertex vertex; // Only used for non-dummy nodes, otherwise null + + public List preds = new ArrayList<>(); + public List succs = new ArrayList<>(); + public HashMap outOffsets = new HashMap<>(); + public HashMap inOffsets = new HashMap<>(); + public int pos = -1; // Position within layer + + public int crossingNumber; + + @Override + public String toString() { + return "Node " + vertex; + } + } + + private class LayoutEdge { + + public LayoutNode from; + public LayoutNode to; + public int relativeFrom; + public int relativeTo; + public Link link; + public boolean vip; + } + + private abstract class AlgorithmPart { + + public void start() { + if (CHECK) { + preCheck(); + } + + long start = 0; + if (TRACE) { + System.out.println("##################################################"); + System.out.println("Starting part " + this.getClass().getName()); + start = System.currentTimeMillis(); + } + run(); + if (TRACE) { + System.out.println("Timing for " + this.getClass().getName() + " is " + (System.currentTimeMillis() - start)); + printStatistics(); + } + + if (CHECK) { + postCheck(); + } + } + + protected abstract void run(); + + protected void printStatistics() { + } + + protected void postCheck() { + } + + protected void preCheck() { + } + } + + public HierarchicalLayoutManager() { + this(Combine.NONE); + } + + public HierarchicalLayoutManager(Combine b) { + this.combine = b; + this.dummyWidth = DUMMY_WIDTH; + this.dummyHeight = DUMMY_HEIGHT; + this.xOffset = X_OFFSET; + this.layerOffset = LAYER_OFFSET; + this.maxLayerLength = MAX_LAYER_LENGTH; + this.minLayerDifference = MIN_LAYER_DIFFERENCE; + this.linksToFollow = new HashSet<>(); + } + + public int getMaxLayerLength() { + return maxLayerLength; + } + + public void setMaxLayerLength(int v) { + maxLayerLength = v; + } + + public void setMinLayerDifference(int v) { + minLayerDifference = v; + } + + @Override + public void doLayout(LayoutGraph graph) { + doLayout(graph, new HashSet(), new HashSet(), new HashSet()); + + } + + @Override + public void doLayout(LayoutGraph graph, Set firstLayerHint, Set lastLayerHint, Set importantLinks) { + + this.importantLinks = importantLinks; + this.graph = graph; + this.firstLayerHint = firstLayerHint; + this.lastLayerHint = lastLayerHint; + + vertexToLayoutNode = new HashMap<>(); + reversedLinks = new HashSet<>(); + reversedLinkStartPoints = new HashMap<>(); + reversedLinkEndPoints = new HashMap<>(); + bottomEdgeHash = new HashMap<>(); + nodes = new ArrayList<>(); + splitStartPoints = new HashMap<>(); + splitEndPoints = new HashMap<>(); + + // ############################################################# + // Step 1: Build up data structure + new BuildDatastructure().start(); + + // ############################################################# + // STEP 2: Reverse edges, handle backedges + new ReverseEdges().start(); + + for (LayoutNode n : nodes) { + ArrayList tmpArr = new ArrayList<>(); + for (LayoutEdge e : n.succs) { + if (importantLinks.contains(e.link)) { + tmpArr.add(e); + } + } + + for (LayoutEdge e : tmpArr) { + //System.out.println("Removed " + e); + e.from.succs.remove(e); + e.to.preds.remove(e); + } + } + + // ############################################################# + // STEP 3: Assign layers + new AssignLayers().start(); + + // ############################################################# + // STEP 4: Create dummy nodes + new CreateDummyNodes().start(); + + // ############################################################# + // STEP 5: Crossing Reduction + new CrossingReduction().start(); + + // ############################################################# + // STEP 7: Assign X coordinates + new AssignXCoordinates().start(); + + // ############################################################# + // STEP 6: Assign Y coordinates + new AssignYCoordinates().start(); + + // ############################################################# + // STEP 8: Write back to interface + new WriteResult().start(); + } + + private class WriteResult extends AlgorithmPart { + + private int pointCount; + + @Override + protected void run() { + + HashMap vertexPositions = new HashMap<>(); + HashMap> linkPositions = new HashMap<>(); + for (Vertex v : graph.getVertices()) { + LayoutNode n = vertexToLayoutNode.get(v); + assert !vertexPositions.containsKey(v); + vertexPositions.put(v, new Point(n.x + n.xOffset, n.y + n.yOffset)); + } + + for (LayoutNode n : nodes) { + + for (LayoutEdge e : n.preds) { + if (e.link != null) { + ArrayList points = new ArrayList<>(); + + Point p = new Point(e.to.x + e.relativeTo, e.to.y + e.to.yOffset + e.link.getTo().getRelativePosition().y); + points.add(p); + if (e.to.inOffsets.containsKey(e.relativeTo)) { + points.add(new Point(p.x, p.y + e.to.inOffsets.get(e.relativeTo) + e.link.getTo().getRelativePosition().y)); + } + + LayoutNode cur = e.from; + LayoutNode other = e.to; + LayoutEdge curEdge = e; + while (cur.vertex == null && cur.preds.size() != 0) { + if (points.size() > 1 && points.get(points.size() - 1).x == cur.x + cur.width / 2 && points.get(points.size() - 2).x == cur.x + cur.width / 2) { + points.remove(points.size() - 1); + } + points.add(new Point(cur.x + cur.width / 2, cur.y + cur.height)); + if (points.size() > 1 && points.get(points.size() - 1).x == cur.x + cur.width / 2 && points.get(points.size() - 2).x == cur.x + cur.width / 2) { + points.remove(points.size() - 1); + } + points.add(new Point(cur.x + cur.width / 2, cur.y)); + assert cur.preds.size() == 1; + curEdge = cur.preds.get(0); + cur = curEdge.from; + } + + p = new Point(cur.x + curEdge.relativeFrom, cur.y + cur.height - cur.bottomYOffset + (curEdge.link == null ? 0 : curEdge.link.getFrom().getRelativePosition().y)); + if (curEdge.from.outOffsets.containsKey(curEdge.relativeFrom)) { + points.add(new Point(p.x, p.y + curEdge.from.outOffsets.get(curEdge.relativeFrom) + (curEdge.link == null ? 0 : curEdge.link.getFrom().getRelativePosition().y))); + } + points.add(p); + + Collections.reverse(points); + + + + if (cur.vertex == null && cur.preds.size() == 0) { + + if (reversedLinkEndPoints.containsKey(e.link)) { + for (Point p1 : reversedLinkEndPoints.get(e.link)) { + points.add(new Point(p1.x + e.to.x, p1.y + e.to.y)); + } + } + + if (splitStartPoints.containsKey(e.link)) { + points.add(0, null); + points.addAll(0, splitStartPoints.get(e.link)); + + //checkPoints(points); + if (reversedLinks.contains(e.link)) { + Collections.reverse(points); + } + assert !linkPositions.containsKey(e.link); + linkPositions.put(e.link, points); + } else { + splitEndPoints.put(e.link, points); + } + + } else { + if (reversedLinks.contains(e.link)) { + Collections.reverse(points); + } + if (reversedLinkStartPoints.containsKey(e.link)) { + for (Point p1 : reversedLinkStartPoints.get(e.link)) { + points.add(new Point(p1.x + cur.x, p1.y + cur.y)); + } + } + + if (reversedLinkEndPoints.containsKey(e.link)) { + for (Point p1 : reversedLinkEndPoints.get(e.link)) { + points.add(0, new Point(p1.x + other.x, p1.y + other.y)); + } + } + + assert !linkPositions.containsKey(e.link); + linkPositions.put(e.link, points); + } + pointCount += points.size(); + + // No longer needed! + e.link = null; + } + } + + for (LayoutEdge e : n.succs) { + if (e.link != null) { + ArrayList points = new ArrayList<>(); + Point p = new Point(e.from.x + e.relativeFrom, e.from.y + e.from.height - e.from.bottomYOffset + e.link.getFrom().getRelativePosition().y); + points.add(p); + if (e.from.outOffsets.containsKey(e.relativeFrom)) { + points.add(new Point(p.x, p.y + e.from.outOffsets.get(e.relativeFrom) + e.link.getFrom().getRelativePosition().y)); + } + + LayoutNode cur = e.to; + LayoutNode other = e.from; + LayoutEdge curEdge = e; + while (cur.vertex == null && cur.succs.size() != 0) { + if (points.size() > 1 && points.get(points.size() - 1).x == cur.x + cur.width / 2 && points.get(points.size() - 2).x == cur.x + cur.width / 2) { + points.remove(points.size() - 1); + } + points.add(new Point(cur.x + cur.width / 2, cur.y)); + if (points.size() > 1 && points.get(points.size() - 1).x == cur.x + cur.width / 2 && points.get(points.size() - 2).x == cur.x + cur.width / 2) { + points.remove(points.size() - 1); + } + points.add(new Point(cur.x + cur.width / 2, cur.y + cur.height)); + if (cur.succs.size() == 0) { + break; + } + assert cur.succs.size() == 1; + curEdge = cur.succs.get(0); + cur = curEdge.to; + } + + + p = new Point(cur.x + curEdge.relativeTo, cur.y + cur.yOffset + ((curEdge.link == null) ? 0 : curEdge.link.getTo().getRelativePosition().y)); + points.add(p); + if (curEdge.to.inOffsets.containsKey(curEdge.relativeTo)) { + points.add(new Point(p.x, p.y + curEdge.to.inOffsets.get(curEdge.relativeTo) + ((curEdge.link == null) ? 0 : curEdge.link.getTo().getRelativePosition().y))); + } + + + if (cur.succs.size() == 0 && cur.vertex == null) { + if (reversedLinkStartPoints.containsKey(e.link)) { + for (Point p1 : reversedLinkStartPoints.get(e.link)) { + points.add(0, new Point(p1.x + other.x, p1.y + other.y)); + } + } + + if (splitEndPoints.containsKey(e.link)) { + points.add(null); + points.addAll(splitEndPoints.get(e.link)); + + //checkPoints(points); + if (reversedLinks.contains(e.link)) { + Collections.reverse(points); + } + assert !linkPositions.containsKey(e.link); + linkPositions.put(e.link, points); + } else { + splitStartPoints.put(e.link, points); + } + } else { + + if (reversedLinkStartPoints.containsKey(e.link)) { + for (Point p1 : reversedLinkStartPoints.get(e.link)) { + points.add(0, new Point(p1.x + other.x, p1.y + other.y)); + } + } + if (reversedLinkEndPoints.containsKey(e.link)) { + for (Point p1 : reversedLinkEndPoints.get(e.link)) { + points.add(new Point(p1.x + cur.x, p1.y + cur.y)); + } + } + if (reversedLinks.contains(e.link)) { + Collections.reverse(points); + } + //checkPoints(points); + assert !linkPositions.containsKey(e.link); + linkPositions.put(e.link, points); + } + + pointCount += points.size(); + e.link = null; + } + } + } + + int minX = Integer.MAX_VALUE; + int minY = Integer.MAX_VALUE; + for (Vertex v : vertexPositions.keySet()) { + Point p = vertexPositions.get(v); + minX = Math.min(minX, p.x); + minY = Math.min(minY, p.y); + } + + for (Link l : linkPositions.keySet()) { + List points = linkPositions.get(l); + for (Point p : points) { + if (p != null) { + minX = Math.min(minX, p.x); + minY = Math.min(minY, p.y); + } + } + + } + + for (Vertex v : vertexPositions.keySet()) { + Point p = vertexPositions.get(v); + p.x -= minX; + p.y -= minY; + v.setPosition(p); + } + + for (Link l : linkPositions.keySet()) { + List points = linkPositions.get(l); + for (Point p : points) { + if (p != null) { + p.x -= minX; + p.y -= minY; + } + } + l.setControlPoints(points); + + } + } + + @Override + protected void printStatistics() { + System.out.println("Number of nodes: " + nodes.size()); + int edgeCount = 0; + for (LayoutNode n : nodes) { + edgeCount += n.succs.size(); + } + System.out.println("Number of edges: " + edgeCount); + System.out.println("Number of points: " + pointCount); + } + } + + private static class Segment { + + public float d; + public int orderNumber = -1; + public ArrayList nodes = new ArrayList<>(); + public HashSet succs = new HashSet<>(); + public HashSet preds = new HashSet<>(); + public Region region; + } + private static final Comparator segmentComparator = new Comparator() { + + @Override + public int compare(Segment s1, Segment s2) { + return s1.orderNumber - s2.orderNumber; + } + }; + + private static class Region { + + public float d; + public int minOrderNumber; + public SortedSet segments = new TreeSet<>(segmentComparator); + public HashSet succs = new HashSet<>(4); + public HashSet preds = new HashSet<>(4); + } + private static final Comparator regionComparator = new Comparator() { + + @Override + public int compare(Region r1, Region r2) { + return r1.minOrderNumber - r2.minOrderNumber; + } + }; + private static final Comparator nodePositionComparator = new Comparator() { + + @Override + public int compare(LayoutNode n1, LayoutNode n2) { + return n1.pos - n2.pos; + } + }; + private static final Comparator nodeProcessingDownComparator = new Comparator() { + @Override + public int compare(LayoutNode n1, LayoutNode n2) { + if (n1.vertex == null) { + if (n2.vertex == null) { + return 0; + } + return -1; + } + if (n2.vertex == null) { + return 1; + } + return n1.preds.size() - n2.preds.size(); + } + }; + private static final Comparator nodeProcessingUpComparator = new Comparator() { + + @Override + public int compare(LayoutNode n1, LayoutNode n2) { + if (n1.vertex == null) { + if (n2.vertex == null) { + return 0; + } + return -1; + } + if (n2.vertex == null) { + return 1; + } + return n1.succs.size() - n2.succs.size(); + } + }; + + private class AssignXCoordinates extends AlgorithmPart { + + private ArrayList[] space; + private ArrayList[] downProcessingOrder; + private ArrayList[] upProcessingOrder; + + private void initialPositions() { + for (LayoutNode n : nodes) { + n.x = space[n.layer].get(n.pos); + } + } + + @SuppressWarnings("unchecked") + private void createArrays() { + space = new ArrayList[layers.length]; + downProcessingOrder = new ArrayList[layers.length]; + upProcessingOrder = new ArrayList[layers.length]; + } + + @Override + protected void run() { + createArrays(); + + for (int i = 0; i < layers.length; i++) { + space[i] = new ArrayList<>(); + downProcessingOrder[i] = new ArrayList<>(); + upProcessingOrder[i] = new ArrayList<>(); + + int curX = 0; + for (LayoutNode n : layers[i]) { + space[i].add(curX); + curX += n.width + xOffset; + downProcessingOrder[i].add(n); + upProcessingOrder[i].add(n); + } + + Collections.sort(downProcessingOrder[i], nodeProcessingDownComparator); + Collections.sort(upProcessingOrder[i], nodeProcessingUpComparator); + } + + initialPositions(); + for (int i = 0; i < SWEEP_ITERATIONS; i++) { + sweepDown(); + sweepUp(); + } + + sweepDown(); + //for (int i = 0; i < SWEEP_ITERATIONS; i++) { + // doubleSweep(); + //} + } + + private int calculateOptimalDown(LayoutNode n) { + int size = n.preds.size(); + if (size == 0) { + return n.x; + } + int[] values = new int[size]; + for (int i = 0; i < size; i++) { + LayoutEdge e = n.preds.get(i); + values[i] = e.from.x + e.relativeFrom - e.relativeTo; + if (e.vip) { + return values[i]; + } + } + return median(values); + } + + private int calculateOptimalBoth(LayoutNode n) { + if (n.preds.size() == n.succs.size()) { + return n.x; + } + + int[] values = new int[n.preds.size() + n.succs.size()]; + int i = 0; + + for (LayoutEdge e : n.preds) { + values[i] = e.from.x + e.relativeFrom - e.relativeTo; + i++; + } + + for (LayoutEdge e : n.succs) { + values[i] = e.to.x + e.relativeTo - e.relativeFrom; + i++; + } + + return median(values); + } + + private int calculateOptimalUp(LayoutNode n) { + int size = n.succs.size(); + if (size == 0) { + return n.x; + } + int[] values = new int[size]; + for (int i = 0; i < size; i++) { + LayoutEdge e = n.succs.get(i); + values[i] = e.to.x + e.relativeTo - e.relativeFrom; + if (e.vip) { + return values[i]; + } + } + return median(values); + } + + private int median(int[] values) { + Arrays.sort(values); + if (values.length % 2 == 0) { + return (values[values.length / 2 - 1] + values[values.length / 2]) / 2; + } else { + return values[values.length / 2]; + } + } + + private void sweepUp() { + for (int i = layers.length - 1; i >= 0; i--) { + NodeRow r = new NodeRow(space[i]); + for (LayoutNode n : upProcessingOrder[i]) { + int optimal = calculateOptimalUp(n); + r.insert(n, optimal); + } + } + } + + private void doubleSweep() { + for (int i = layers.length - 2; i >= 0; i--) { + NodeRow r = new NodeRow(space[i]); + for (LayoutNode n : upProcessingOrder[i]) { + int optimal = calculateOptimalBoth(n); + r.insert(n, optimal); + } + } + } + + private void sweepDown() { + for (int i = 1; i < layers.length; i++) { + NodeRow r = new NodeRow(space[i]); + for (LayoutNode n : downProcessingOrder[i]) { + int optimal = calculateOptimalDown(n); + r.insert(n, optimal); + } + } + } + } + + private static class NodeRow { + + private TreeSet treeSet; + private ArrayList space; + + public NodeRow(ArrayList space) { + treeSet = new TreeSet<>(nodePositionComparator); + this.space = space; + } + + public int offset(LayoutNode n1, LayoutNode n2) { + int v1 = space.get(n1.pos) + n1.width; + int v2 = space.get(n2.pos); + return v2 - v1; + } + + public void insert(LayoutNode n, int pos) { + + SortedSet headSet = treeSet.headSet(n); + + LayoutNode leftNeighbor = null; + int minX = Integer.MIN_VALUE; + if (!headSet.isEmpty()) { + leftNeighbor = headSet.last(); + minX = leftNeighbor.x + leftNeighbor.width + offset(leftNeighbor, n); + } + + if (pos < minX) { + n.x = minX; + } else { + + LayoutNode rightNeighbor = null; + SortedSet tailSet = treeSet.tailSet(n); + int maxX = Integer.MAX_VALUE; + if (!tailSet.isEmpty()) { + rightNeighbor = tailSet.first(); + maxX = rightNeighbor.x - offset(n, rightNeighbor) - n.width; + } + + if (pos > maxX) { + n.x = maxX; + } else { + n.x = pos; + } + + assert minX <= maxX; + } + + treeSet.add(n); + } + } + private static Comparator crossingNodeComparator = new Comparator() { + + @Override + public int compare(LayoutNode n1, LayoutNode n2) { + return n1.crossingNumber - n2.crossingNumber; + } + }; + + private class CrossingReduction extends AlgorithmPart { + + @Override + public void preCheck() { + for (LayoutNode n : nodes) { + assert n.layer < layerCount; + } + } + + @SuppressWarnings("unchecked") + private void createLayers() { + layers = new List[layerCount]; + + for (int i = 0; i < layerCount; i++) { + layers[i] = new ArrayList<>(); + } + } + + @Override + protected void run() { + createLayers(); + + // Generate initial ordering + HashSet visited = new HashSet<>(); + for (LayoutNode n : nodes) { + if (n.layer == 0) { + layers[0].add(n); + visited.add(n); + } else if (n.preds.size() == 0) { + layers[n.layer].add(n); + visited.add(n); + } + } + + for (int i = 0; i < layers.length - 1; i++) { + for (LayoutNode n : layers[i]) { + for (LayoutEdge e : n.succs) { + if (!visited.contains(e.to)) { + visited.add(e.to); + layers[i + 1].add(e.to); + } + } + } + } + + + updatePositions(); + + initX(); + + // Optimize + for (int i = 0; i < CROSSING_ITERATIONS; i++) { + downSweep(); + upSweep(); + } + if (reversedLinks.isEmpty()) { + // This graph seems to be a tree or forest. + // A final down-sweep will usually give us a better layout. + downSweep(); + } + } + + private void initX() { + + for (int i = 0; i < layers.length; i++) { + updateXOfLayer(i); + } + } + + private void updateXOfLayer(int index) { + int x = 0; + + for (LayoutNode n : layers[index]) { + n.x = x; + x += n.width + X_OFFSET; + } + } + + private void updatePositions() { + + for (int i = 0; i < layers.length; i++) { + int z = 0; + for (LayoutNode n : layers[i]) { + n.pos = z; + z++; + } + } + } + + private void downSweep() { + + // Downsweep + for (int i = 1; i < layerCount; i++) { + + for (LayoutNode n : layers[i]) { + n.crossingNumber = 0; + } + + for (LayoutNode n : layers[i]) { + + int sum = 0; + int count = 0; + for (LayoutEdge e : n.preds) { + int cur = e.from.x + e.relativeFrom; + int factor = 1; + if (e.vip) { + factor = VIP_BONUS; + } + sum += cur*factor; + count+=factor; + } + + if (count > 0) { + sum /= count; + n.crossingNumber = sum; + } + } + + + updateCrossingNumbers(i, true); + Collections.sort(layers[i], crossingNodeComparator); + updateXOfLayer(i); + + int z = 0; + for (LayoutNode n : layers[i]) { + n.pos = z; + z++; + } + } + } + + private void updateCrossingNumbers(int index, boolean down) { + for (int i = 0; i < layers[index].size(); i++) { + LayoutNode n = layers[index].get(i); + LayoutNode prev = null; + if (i > 0) { + prev = layers[index].get(i - 1); + } + LayoutNode next = null; + if (i < layers[index].size() - 1) { + next = layers[index].get(i + 1); + } + + boolean cond = n.succs.isEmpty(); + if (down) { + cond = n.preds.isEmpty(); + } + + if (cond) { + + if (prev != null && next != null) { + n.crossingNumber = (prev.crossingNumber + next.crossingNumber) / 2; + } else if (prev != null) { + n.crossingNumber = prev.crossingNumber; + } else if (next != null) { + n.crossingNumber = next.crossingNumber; + } + } + } + } + + private void upSweep() { + // Upsweep + for (int i = layerCount - 2; i >= 0; i--) { + + for (LayoutNode n : layers[i]) { + n.crossingNumber = 0; + } + + for (LayoutNode n : layers[i]) { + + int count = 0; + int sum = 0; + for (LayoutEdge e : n.succs) { + int cur = e.to.x + e.relativeTo; + int factor = 1; + if (e.vip) { + factor = VIP_BONUS; + } + sum += cur*factor; + count+=factor; + } + + if (count > 0) { + sum /= count; + n.crossingNumber = sum; + } + + } + + updateCrossingNumbers(i, false); + Collections.sort(layers[i], crossingNodeComparator); + updateXOfLayer(i); + + int z = 0; + for (LayoutNode n : layers[i]) { + n.pos = z; + z++; + } + } + } + + @Override + public void postCheck() { + + HashSet visited = new HashSet<>(); + for (int i = 0; i < layers.length; i++) { + for (LayoutNode n : layers[i]) { + assert !visited.contains(n); + assert n.layer == i; + visited.add(n); + } + } + + } + } + + private class AssignYCoordinates extends AlgorithmPart { + + @Override + protected void run() { + int curY = 0; + + for (int i = 0; i < layers.length; i++) { + int maxHeight = 0; + int baseLine = 0; + int bottomBaseLine = 0; + for (LayoutNode n : layers[i]) { + maxHeight = Math.max(maxHeight, n.height - n.yOffset - n.bottomYOffset); + baseLine = Math.max(baseLine, n.yOffset); + bottomBaseLine = Math.max(bottomBaseLine, n.bottomYOffset); + } + + int maxXOffset = 0; + for (LayoutNode n : layers[i]) { + if (n.vertex == null) { + // Dummy node + n.y = curY; + n.height = maxHeight + baseLine + bottomBaseLine; + + } else { + n.y = curY + baseLine + (maxHeight - (n.height - n.yOffset - n.bottomYOffset)) / 2 - n.yOffset; + } + + for (LayoutEdge e : n.succs) { + int curXOffset = Math.abs(n.x - e.to.x); + maxXOffset = Math.max(curXOffset, maxXOffset); + } + } + + curY += maxHeight + baseLine + bottomBaseLine; + curY += layerOffset + (int) Math.sqrt(maxXOffset); + } + } + } + + private class CreateDummyNodes extends AlgorithmPart { + + private int oldNodeCount; + + @Override + protected void preCheck() { + for (LayoutNode n : nodes) { + for (LayoutEdge e : n.succs) { + assert e.from != null; + assert e.from == n; + assert e.from.layer < e.to.layer; + } + + for (LayoutEdge e : n.preds) { + assert e.to != null; + assert e.to == n; + } + } + } + + @Override + protected void run() { + oldNodeCount = nodes.size(); + + + if (combine == Combine.SAME_OUTPUTS) { + + Comparator comparator = new Comparator() { + + @Override + public int compare(LayoutEdge e1, LayoutEdge e2) { + return e1.to.layer - e2.to.layer; + } + }; + HashMap> portHash = new HashMap<>(); + ArrayList currentNodes = new ArrayList<>(nodes); + for (LayoutNode n : currentNodes) { + portHash.clear(); + + ArrayList succs = new ArrayList<>(n.succs); + HashMap topNodeHash = new HashMap<>(); + HashMap> bottomNodeHash = new HashMap<>(); + for (LayoutEdge e : succs) { + assert e.from.layer < e.to.layer; + if (e.from.layer != e.to.layer - 1) { + if (maxLayerLength != -1 && e.to.layer - e.from.layer > maxLayerLength/* && e.to.preds.size() > 1 && e.from.succs.size() > 1*/) { + assert maxLayerLength > 2; + e.to.preds.remove(e); + e.from.succs.remove(e); + + LayoutEdge topEdge = null; + + if (combine == Combine.SAME_OUTPUTS && topNodeHash.containsKey(e.relativeFrom)) { + LayoutNode topNode = topNodeHash.get(e.relativeFrom); + topEdge = new LayoutEdge(); + topEdge.relativeFrom = e.relativeFrom; + topEdge.from = e.from; + topEdge.relativeTo = topNode.width / 2; + topEdge.to = topNode; + topEdge.link = e.link; + topEdge.vip = e.vip; + e.from.succs.add(topEdge); + topNode.preds.add(topEdge); + } else { + + LayoutNode topNode = new LayoutNode(); + topNode.layer = e.from.layer + 1; + topNode.width = DUMMY_WIDTH; + topNode.height = DUMMY_HEIGHT; + nodes.add(topNode); + topEdge = new LayoutEdge(); + topEdge.relativeFrom = e.relativeFrom; + topEdge.from = e.from; + topEdge.relativeTo = topNode.width / 2; + topEdge.to = topNode; + topEdge.link = e.link; + topEdge.vip = e.vip; + e.from.succs.add(topEdge); + topNode.preds.add(topEdge); + topNodeHash.put(e.relativeFrom, topNode); + bottomNodeHash.put(e.relativeFrom, new HashMap()); + } + + HashMap hash = bottomNodeHash.get(e.relativeFrom); + + LayoutNode bottomNode = null; + if (hash.containsKey(e.to.layer)) { + bottomNode = hash.get(e.to.layer); + } else { + + bottomNode = new LayoutNode(); + bottomNode.layer = e.to.layer - 1; + bottomNode.width = DUMMY_WIDTH; + bottomNode.height = DUMMY_HEIGHT; + nodes.add(bottomNode); + hash.put(e.to.layer, bottomNode); + } + + LayoutEdge bottomEdge = new LayoutEdge(); + bottomEdge.relativeTo = e.relativeTo; + bottomEdge.to = e.to; + bottomEdge.relativeFrom = bottomNode.width / 2; + bottomEdge.from = bottomNode; + bottomEdge.link = e.link; + bottomEdge.vip = e.vip; + e.to.preds.add(bottomEdge); + bottomEdgeHash.put(topEdge, bottomEdge); + bottomNode.succs.add(bottomEdge); + + } else { + Integer i = e.relativeFrom; + if (!portHash.containsKey(i)) { + portHash.put(i, new ArrayList()); + } + portHash.get(i).add(e); + } + } + } + + succs = new ArrayList<>(n.succs); + for (LayoutEdge e : succs) { + + Integer i = e.relativeFrom; + if (portHash.containsKey(i)) { + + List list = portHash.get(i); + Collections.sort(list, comparator); + + if (list.size() == 1) { + processSingleEdge(list.get(0)); + } else { + + int maxLayer = list.get(0).to.layer; + for (LayoutEdge curEdge : list) { + maxLayer = Math.max(maxLayer, curEdge.to.layer); + } + + + int cnt = maxLayer - n.layer - 1; + LayoutEdge[] edges = new LayoutEdge[cnt]; + LayoutNode[] nodes = new LayoutNode[cnt]; + edges[0] = new LayoutEdge(); + edges[0].from = n; + edges[0].relativeFrom = i; + edges[0].vip = e.vip; + n.succs.add(edges[0]); + + nodes[0] = new LayoutNode(); + nodes[0].width = dummyWidth; + nodes[0].height = dummyHeight; + nodes[0].layer = n.layer + 1; + nodes[0].preds.add(edges[0]); + edges[0].to = nodes[0]; + edges[0].relativeTo = nodes[0].width / 2; + for (int j = 1; j < cnt; j++) { + edges[j] = new LayoutEdge(); + edges[j].vip = e.vip; + edges[j].from = nodes[j - 1]; + edges[j].relativeFrom = nodes[j - 1].width / 2; + nodes[j - 1].succs.add(edges[j]); + nodes[j] = new LayoutNode(); + nodes[j].width = dummyWidth; + nodes[j].height = dummyHeight; + nodes[j].layer = n.layer + j + 1; + nodes[j].preds.add(edges[j]); + edges[j].to = nodes[j]; + edges[j].relativeTo = nodes[j].width / 2; + } + + for (LayoutEdge curEdge : list) { + assert curEdge.to.layer - n.layer - 2 >= 0; + assert curEdge.to.layer - n.layer - 2 < cnt; + LayoutNode anchor = nodes[curEdge.to.layer - n.layer - 2]; + anchor.succs.add(curEdge); + curEdge.from = anchor; + curEdge.relativeFrom = anchor.width / 2; + n.succs.remove(curEdge); + } + + } + + portHash.remove(i); + } + } + } + } else if (combine == Combine.SAME_INPUTS) { + throw new UnsupportedOperationException("Currently not supported"); + } else { + ArrayList currentNodes = new ArrayList<>(nodes); + for (LayoutNode n : currentNodes) { + for (LayoutEdge e : n.succs) { + processSingleEdge(e); + } + } + } + } + + private void processSingleEdge(LayoutEdge e) { + LayoutNode n = e.from; + if (e.to.layer > n.layer + 1) { + LayoutEdge last = e; + for (int i = n.layer + 1; i < last.to.layer; i++) { + last = addBetween(last, i); + } + } + } + + private LayoutEdge addBetween(LayoutEdge e, int layer) { + LayoutNode n = new LayoutNode(); + n.width = dummyWidth; + n.height = dummyHeight; + n.layer = layer; + n.preds.add(e); + nodes.add(n); + LayoutEdge result = new LayoutEdge(); + result.vip = e.vip; + n.succs.add(result); + result.from = n; + result.relativeFrom = n.width / 2; + result.to = e.to; + result.relativeTo = e.relativeTo; + e.relativeTo = n.width / 2; + e.to.preds.remove(e); + e.to.preds.add(result); + e.to = n; + return result; + } + + @Override + public void printStatistics() { + System.out.println("Dummy nodes created: " + (nodes.size() - oldNodeCount)); + } + + @Override + public void postCheck() { + ArrayList currentNodes = new ArrayList<>(nodes); + for (LayoutNode n : currentNodes) { + for (LayoutEdge e : n.succs) { + assert e.from.layer == e.to.layer - 1; + } + } + + for (int i = 0; i < layers.length; i++) { + assert layers[i].size() > 0; + for (LayoutNode n : layers[i]) { + assert n.layer == i; + } + } + } + } + + private class AssignLayers extends AlgorithmPart { + + @Override + public void preCheck() { + for (LayoutNode n : nodes) { + assert n.layer == -1; + } + } + + @Override + protected void run() { + + List insertOrder = new ArrayList<>(); + + HashSet set = new HashSet<>(); + for (LayoutNode n : nodes) { + if (n.preds.size() == 0) { + set.add(n); + insertOrder.add(n); + n.layer = 0; + } + } + + int z = minLayerDifference; + HashSet newSet = new HashSet<>(); + HashSet failed = new HashSet<>(); + while (!set.isEmpty()) { + + newSet.clear(); + failed.clear(); + + for (LayoutNode n : set) { + + for (LayoutEdge se : n.succs) { + LayoutNode s = se.to; + if (!newSet.contains(s) && !failed.contains(s)) { + boolean ok = true; + for (LayoutEdge pe : s.preds) { + LayoutNode p = pe.from; + if (p.layer == -1) { + ok = false; + break; + } + } + + if (ok) { + newSet.add(s); + } else { + failed.add(s); + } + } + } + + } + + for (LayoutNode n : newSet) { + n.layer = z; + insertOrder.add(n); + } + + // Swap sets + HashSet tmp = set; + set = newSet; + newSet = tmp; + z += minLayerDifference; + } + + optimize(insertOrder); + + layerCount = z - minLayerDifference; + + for (Vertex v : lastLayerHint) { + + LayoutNode n = vertexToLayoutNode.get(v); + assert n.succs.size() == 0; + n.layer = layerCount - 1; + } + + for (Vertex v : firstLayerHint) { + LayoutNode n = vertexToLayoutNode.get(v); + assert n.preds.size() == 0; + n.layer = 0; + assert n.layer == 0; + } + } + + public void optimize(List insertOrder) { + for (int i = insertOrder.size() - 1; i >= 0; i--) { + LayoutNode cur = insertOrder.get(i); + if (cur.succs.size() > cur.preds.size()) { + int minLayer = cur.succs.get(0).to.layer; + for (LayoutEdge e : cur.succs) { + minLayer = Math.min(minLayer, e.to.layer); + } + cur.layer = minLayer - 1; + } + } + } + + @Override + public void postCheck() { + for (LayoutNode n : nodes) { + assert n.layer >= 0; + assert n.layer < layerCount; + for (LayoutEdge e : n.succs) { + assert e.from.layer < e.to.layer; + } + } + } + } + + private class ReverseEdges extends AlgorithmPart { + + private HashSet visited; + private HashSet active; + + @Override + protected void run() { + + // Remove self-edges + for (LayoutNode node : nodes) { + ArrayList succs = new ArrayList<>(node.succs); + for (LayoutEdge e : succs) { + assert e.from == node; + if (e.to == node) { + node.succs.remove(e); + node.preds.remove(e); + } + } + } + + // Reverse inputs of roots + for (LayoutNode node : nodes) { + if (node.vertex.isRoot()) { + boolean ok = true; + for (LayoutEdge e : node.preds) { + if (e.from.vertex.isRoot()) { + ok = false; + break; + } + } + if (ok) { + reverseAllInputs(node); + } + } + } + + + // Start DFS and reverse back edges + visited = new HashSet<>(); + active = new HashSet<>(); + for (LayoutNode node : nodes) { + DFS(node); + } + + + for (LayoutNode node : nodes) { + + SortedSet reversedDown = new TreeSet<>(); + + for (LayoutEdge e : node.succs) { + if (reversedLinks.contains(e.link)) { + reversedDown.add(e.relativeFrom); + } + } + + + SortedSet reversedUp = null; + if (reversedDown.size() == 0) { + reversedUp = new TreeSet<>(Collections.reverseOrder()); + } else { + reversedUp = new TreeSet<>(); + } + + for (LayoutEdge e : node.preds) { + if (reversedLinks.contains(e.link)) { + reversedUp.add(e.relativeTo); + } + } + + final int offset = X_OFFSET + DUMMY_WIDTH; + + int curX = 0; + int curWidth = node.width + reversedDown.size() * offset; + for (int pos : reversedDown) { + ArrayList reversedSuccs = new ArrayList<>(); + for (LayoutEdge e : node.succs) { + if (e.relativeFrom == pos && reversedLinks.contains(e.link)) { + reversedSuccs.add(e); + e.relativeFrom = curWidth; + } + } + + ArrayList startPoints = new ArrayList<>(); + startPoints.add(new Point(curWidth, curX)); + startPoints.add(new Point(pos, curX)); + startPoints.add(new Point(pos, reversedDown.size() * offset)); + for (LayoutEdge e : reversedSuccs) { + reversedLinkStartPoints.put(e.link, startPoints); + } + + node.inOffsets.put(pos, -curX); + curX += offset; + node.height += offset; + node.yOffset += offset; + curWidth -= offset; + } + node.width += reversedDown.size() * offset; + + if (reversedDown.size() == 0) { + curX = offset; + } else { + curX = -offset; + } + + curX = 0; + int minX = 0; + if (reversedDown.size() != 0) { + minX = -offset * reversedUp.size(); + } + + int oldNodeHeight = node.height; + for (int pos : reversedUp) { + ArrayList reversedPreds = new ArrayList<>(); + for (LayoutEdge e : node.preds) { + if (e.relativeTo == pos && reversedLinks.contains(e.link)) { + if (reversedDown.size() == 0) { + e.relativeTo = node.width + offset; + } else { + e.relativeTo = curX - offset; + } + + reversedPreds.add(e); + } + } + node.height += offset; + ArrayList endPoints = new ArrayList<>(); + + if (reversedDown.size() == 0) { + + curX += offset; + node.width += offset; + endPoints.add(new Point(node.width, node.height)); + + } else { + curX -= offset; + node.width += offset; + endPoints.add(new Point(curX, node.height)); + } + + node.outOffsets.put(pos - minX, curX); + curX += offset; + node.bottomYOffset += offset; + + + endPoints.add(new Point(pos, node.height)); + endPoints.add(new Point(pos, oldNodeHeight)); + for (LayoutEdge e : reversedPreds) { + reversedLinkEndPoints.put(e.link, endPoints); + } + } + + + if (minX < 0) { + for (LayoutEdge e : node.preds) { + e.relativeTo -= minX; + } + + for (LayoutEdge e : node.succs) { + e.relativeFrom -= minX; + } + + node.xOffset = -minX; + node.width += -minX; + } + } + + } + + private void DFS(LayoutNode startNode) { + if (visited.contains(startNode)) { + return; + } + + Stack stack = new Stack<>(); + stack.push(startNode); + + while (!stack.empty()) { + LayoutNode node = stack.pop(); + + if (visited.contains(node)) { + // Node no longer active + active.remove(node); + continue; + } + + // Repush immediately to know when no longer active + stack.push(node); + visited.add(node); + active.add(node); + + ArrayList succs = new ArrayList<>(node.succs); + for (LayoutEdge e : succs) { + if (active.contains(e.to)) { + assert visited.contains(e.to); + // Encountered back edge + reverseEdge(e); + } else if (!visited.contains(e.to) && (linksToFollow.size() == 0 || linksToFollow.contains(e.link))) { + stack.push(e.to); + } + } + } + } + + private void reverseAllInputs(LayoutNode node) { + for (LayoutEdge e : node.preds) { + assert !reversedLinks.contains(e.link); + reversedLinks.add(e.link); + node.succs.add(e); + e.from.preds.add(e); + e.from.succs.remove(e); + int oldRelativeFrom = e.relativeFrom; + int oldRelativeTo = e.relativeTo; + e.to = e.from; + e.from = node; + e.relativeFrom = oldRelativeTo; + e.relativeTo = oldRelativeFrom; + } + node.preds.clear(); + } + + private void reverseEdge(LayoutEdge e) { + assert !reversedLinks.contains(e.link); + reversedLinks.add(e.link); + + LayoutNode oldFrom = e.from; + LayoutNode oldTo = e.to; + int oldRelativeFrom = e.relativeFrom; + int oldRelativeTo = e.relativeTo; + + e.from = oldTo; + e.to = oldFrom; + e.relativeFrom = oldRelativeTo; + e.relativeTo = oldRelativeFrom; + + oldFrom.succs.remove(e); + oldFrom.preds.add(e); + oldTo.preds.remove(e); + oldTo.succs.add(e); + } + + @Override + public void postCheck() { + + for (LayoutNode n : nodes) { + + HashSet curVisited = new HashSet<>(); + Queue queue = new LinkedList<>(); + for (LayoutEdge e : n.succs) { + LayoutNode s = e.to; + queue.add(s); + curVisited.add(s); + } + + while (!queue.isEmpty()) { + LayoutNode curNode = queue.remove(); + + for (LayoutEdge e : curNode.succs) { + assert e.to != n; + if (!curVisited.contains(e.to)) { + queue.add(e.to); + curVisited.add(e.to); + } + } + } + } + } + } + private Comparator linkComparator = new Comparator() { + + @Override + public int compare(Link l1, Link l2) { + + int result = l1.getFrom().getVertex().compareTo(l2.getFrom().getVertex()); + if (result != 0) { + return result; + } + result = l1.getTo().getVertex().compareTo(l2.getTo().getVertex()); + if (result != 0) { + return result; + } + result = l1.getFrom().getRelativePosition().x - l2.getFrom().getRelativePosition().x; + if (result != 0) { + return result; + } + result = l1.getTo().getRelativePosition().x - l2.getTo().getRelativePosition().x; + return result; + } + }; + + private class BuildDatastructure extends AlgorithmPart { + + @Override + protected void run() { + // Set up nodes + List vertices = new ArrayList<>(graph.getVertices()); + Collections.sort(vertices); + + for (Vertex v : vertices) { + LayoutNode node = new LayoutNode(); + Dimension size = v.getSize(); + node.width = (int) size.getWidth(); + node.height = (int) size.getHeight(); + node.vertex = v; + nodes.add(node); + vertexToLayoutNode.put(v, node); + } + + // Set up edges + List links = new ArrayList<>(graph.getLinks()); + Collections.sort(links, linkComparator); + for (Link l : links) { + LayoutEdge edge = new LayoutEdge(); + assert vertexToLayoutNode.containsKey(l.getFrom().getVertex()); + assert vertexToLayoutNode.containsKey(l.getTo().getVertex()); + edge.from = vertexToLayoutNode.get(l.getFrom().getVertex()); + edge.to = vertexToLayoutNode.get(l.getTo().getVertex()); + edge.relativeFrom = l.getFrom().getRelativePosition().x; + edge.relativeTo = l.getTo().getRelativePosition().x; + edge.link = l; + edge.from.succs.add(edge); + edge.to.preds.add(edge); + edge.vip = l.isVIP(); + //assert edge.from != edge.to; // No self-loops allowed + } + + for (Link l : importantLinks) { + if (!vertexToLayoutNode.containsKey(l.getFrom().getVertex()) || + vertexToLayoutNode.containsKey(l.getTo().getVertex())) { + continue; + } + LayoutNode from = vertexToLayoutNode.get(l.getFrom().getVertex()); + LayoutNode to = vertexToLayoutNode.get(l.getTo().getVertex()); + for (LayoutEdge e : from.succs) { + if (e.to == to) { + linksToFollow.add(e.link); + } + } + } + } + + @Override + public void postCheck() { + + assert vertexToLayoutNode.keySet().size() == nodes.size(); + assert nodes.size() == graph.getVertices().size(); + + for (Vertex v : graph.getVertices()) { + + LayoutNode node = vertexToLayoutNode.get(v); + assert node != null; + + for (LayoutEdge e : node.succs) { + assert e.from == node; + } + + for (LayoutEdge e : node.preds) { + assert e.to == node; + } + + } + } + } + + @Override + public void doRouting(LayoutGraph graph) { + // Do nothing for now + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/Node.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/Node.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,161 @@ +/* + * 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.hierarchicallayout; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public class Node { + + private N data; + private List> inEdges; + private List> outEdges; + private boolean visited; + private boolean active; + private boolean reachable; + private Graph graph; + + protected boolean isVisited() { + return visited; + } + + protected void setVisited(boolean b) { + visited = b; + } + + protected boolean isReachable() { + return reachable; + } + + protected void setReachable(boolean b) { + reachable = b; + } + + protected boolean isActive() { + return active; + } + + protected void setActive(boolean b) { + active = b; + } + + public int getInDegree() { + return getInDegree(true); + } + + public int getInDegree(boolean countSelfLoops) { + if (countSelfLoops) { + return inEdges.size(); + } else { + int cnt = 0; + for (Edge e : inEdges) { + if (e.getSource() != this) { + cnt++; + } + } + return cnt; + } + } + + public int getOutDegree() { + return outEdges.size(); + } + + protected Node(Graph graph, N data) { + setData(data); + this.graph = graph; + inEdges = new ArrayList<>(); + outEdges = new ArrayList<>(); + } + + protected void addInEdge(Edge e) { + inEdges.add(e); + } + + public Graph getGraph() { + return graph; + } + + protected void addOutEdge(Edge e) { + outEdges.add(e); + } + + protected void removeInEdge(Edge e) { + //assert inEdges.contains(e); + inEdges.remove(e); + } + + protected void removeOutEdge(Edge e) { + //assert outEdges.contains(e); + outEdges.remove(e); + } + + public List> getInEdges() { + return Collections.unmodifiableList(inEdges); + } + + public List> getOutEdges() { + return Collections.unmodifiableList(outEdges); + } + + public List> getSuccessors() { + ArrayList> succ = new ArrayList<>(); + for (Edge e : getOutEdges()) { + Node n = e.getDest(); + if (!succ.contains(n)) { + succ.add(n); + } + } + return succ; + } + + public List> getPredecessors() { + ArrayList> pred = new ArrayList<>(); + for (Edge e : getInEdges()) { + Node n = e.getSource(); + if (!pred.contains(n)) { + pred.add(n); + } + } + return pred; + } + + public N getData() { + return data; + } + + public void setData(N d) { + data = d; + } + + @Override + public String toString() { + return "Node: " + data; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/Timing.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/Timing.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,67 @@ +/* + * 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.hierarchicallayout; + +/** + * + * @author Thomas Wuerthinger + */ +public class Timing { + + private long lastValue; + private long sum; + private String name; + + public Timing(String name) { + this.name = name; + } + + @Override + public String toString() { + long val = sum; + if (lastValue != 0) { + // Timer running + long newValue = System.nanoTime(); + val += (newValue - lastValue); + } + return "Timing for " + name + " is: " + val / 1000000 + " ms"; + } + + public void print() { + System.out.println(toString()); + } + + public void start() { + lastValue = System.nanoTime(); + } + + public void stop() { + if (lastValue == 0) { + throw new IllegalStateException("You must call start before stop"); + } + long newValue = System.nanoTime(); + sum += newValue - lastValue; + lastValue = 0; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Layout/manifest.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Layout/manifest.mf Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +OpenIDE-Module: com.sun.hotspot.igv.layout +OpenIDE-Module-Localizing-Bundle: com/sun/hotspot/igv/layout/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff -r 6cb549627941 -r 015fb895586b visualizer/Layout/src/com/sun/hotspot/igv/layout/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Layout/src/com/sun/hotspot/igv/layout/Bundle.properties Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,1 @@ +OpenIDE-Module-Name=Layout diff -r 6cb549627941 -r 015fb895586b visualizer/Layout/src/com/sun/hotspot/igv/layout/LayoutGraph.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Layout/src/com/sun/hotspot/igv/layout/LayoutGraph.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,186 @@ +/* + * 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.layout; + +import java.util.*; + +/** + * + * @author Thomas Wuerthinger + */ +public class LayoutGraph { + + private Set links; + private SortedSet vertices; + private HashMap> inputPorts; + private HashMap> outputPorts; + private HashMap> portLinks; + + public LayoutGraph(Set links) { + this(links, new HashSet()); + } + + public LayoutGraph(Set links, Set additionalVertices) { + this.links = links; + assert verify(); + + vertices = new TreeSet<>(); + portLinks = new HashMap<>(links.size()); + inputPorts = new HashMap<>(links.size()); + outputPorts = new HashMap<>(links.size()); + + for (Link l : links) { + Port p = l.getFrom(); + Port p2 = l.getTo(); + Vertex v1 = p.getVertex(); + Vertex v2 = p2.getVertex(); + + if (!vertices.contains(v1)) { + + outputPorts.put(v1, new HashSet(1)); + inputPorts.put(v1, new HashSet(3)); + vertices.add(v1); + assert vertices.contains(v1); + } + + if (!vertices.contains(v2)) { + vertices.add(v2); + assert vertices.contains(v2); + outputPorts.put(v2, new HashSet(1)); + inputPorts.put(v2, new HashSet(3)); + } + + if (!portLinks.containsKey(p)) { + HashSet hashSet = new HashSet<>(3); + portLinks.put(p, hashSet); + } + + if (!portLinks.containsKey(p2)) { + portLinks.put(p2, new HashSet(3)); + } + + outputPorts.get(v1).add(p); + inputPorts.get(v2).add(p2); + + portLinks.get(p).add(l); + portLinks.get(p2).add(l); + } + + for (Vertex v : additionalVertices) { + if (!vertices.contains(v)) { + outputPorts.put(v, new HashSet(1)); + inputPorts.put(v, new HashSet(3)); + vertices.add(v); + vertices.contains(v); + } + } + } + + public Set getInputPorts(Vertex v) { + return this.inputPorts.get(v); + } + + public Set getOutputPorts(Vertex v) { + return this.outputPorts.get(v); + } + + public Set getPortLinks(Port p) { + return portLinks.get(p); + } + + public Set getLinks() { + return links; + } + + public boolean verify() { + return true; + } + + public SortedSet getVertices() { + return vertices; + } + + private void markNotRoot(Set notRootSet, Vertex v, Vertex startingVertex) { + + if (notRootSet.contains(v)) { + return; + } + if (v != startingVertex) { + notRootSet.add(v); + } + Set outPorts = getOutputPorts(v); + for (Port p : outPorts) { + Set portLinks = getPortLinks(p); + for (Link l : portLinks) { + Port other = l.getTo(); + Vertex otherVertex = other.getVertex(); + if (otherVertex != startingVertex) { + markNotRoot(notRootSet, otherVertex, startingVertex); + } + } + } + } + + // Returns a set of vertices with the following properties: + // - All Vertices in the set startingRoots are elements of the set. + // - When starting a DFS at every vertex in the set, every vertex of the + // whole graph is visited. + public Set findRootVertices(Set startingRoots) { + + Set notRootSet = new HashSet<>(); + for (Vertex v : startingRoots) { + if (!notRootSet.contains(v)) { + markNotRoot(notRootSet, v, v); + } + } + + Set tmpVertices = getVertices(); + for (Vertex v : tmpVertices) { + if (!notRootSet.contains(v)) { + if (this.getInputPorts(v).size() == 0) { + markNotRoot(notRootSet, v, v); + } + } + } + + for (Vertex v : tmpVertices) { + if (!notRootSet.contains(v)) { + markNotRoot(notRootSet, v, v); + } + } + + Set result = new HashSet<>(); + for (Vertex v : tmpVertices) { + if (!notRootSet.contains(v)) { + result.add(v); + } + } + assert tmpVertices.size() == 0 || result.size() > 0; + return result; + } + + public Set findRootVertices() { + return findRootVertices(new HashSet()); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Layout/src/com/sun/hotspot/igv/layout/LayoutManager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Layout/src/com/sun/hotspot/igv/layout/LayoutManager.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,39 @@ +/* + * 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.layout; + +import java.util.Set; + +/** + * + * @author Thomas Wuerthinger + */ +public interface LayoutManager { + + public void doLayout(LayoutGraph graph); + + public void doLayout(LayoutGraph graph, Set firstLayerHint, Set lastLayerHint, Set importantLinks); + + public void doRouting(LayoutGraph graph); +} diff -r 6cb549627941 -r 015fb895586b visualizer/Layout/src/com/sun/hotspot/igv/layout/Link.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Layout/src/com/sun/hotspot/igv/layout/Link.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,44 @@ +/* + * 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.layout; + +import java.awt.Point; +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public interface Link { + + public Port getFrom(); + + public Port getTo(); + + public boolean isVIP(); + + public List getControlPoints(); + + public void setControlPoints(List list); +} diff -r 6cb549627941 -r 015fb895586b visualizer/Layout/src/com/sun/hotspot/igv/layout/Port.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Layout/src/com/sun/hotspot/igv/layout/Port.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,37 @@ +/* + * 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.layout; + +import java.awt.Point; + +/** + * + * @author Thomas Wuerthinger + */ +public interface Port { + + public Vertex getVertex(); + + public Point getRelativePosition(); +} diff -r 6cb549627941 -r 015fb895586b visualizer/Layout/src/com/sun/hotspot/igv/layout/Vertex.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Layout/src/com/sun/hotspot/igv/layout/Vertex.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,42 @@ +/* + * 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.layout; + +import java.awt.Dimension; +import java.awt.Point; + +/** + * + * @author Thomas Wuerthinger + */ +public interface Vertex extends Comparable { + + public Dimension getSize(); + + public Point getPosition(); + + public void setPosition(Point p); + + public boolean isRoot(); +} diff -r 6cb549627941 -r 015fb895586b visualizer/OutlineView/manifest.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/OutlineView/manifest.mf Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,6 @@ +Manifest-Version: 1.0 +OpenIDE-Module: com.oracle.graal.visualizer.outline +OpenIDE-Module-Layer: com/oracle/graal/visualizer/outline/layer.xml +OpenIDE-Module-Localizing-Bundle: com/oracle/graal/visualizer/outline/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff -r 6cb549627941 -r 015fb895586b visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/Bundle.properties Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,5 @@ +AdvancedOption_DisplayName_Coordinator=Settings +AdvancedOption_Tooltip_Coordinator=Visualization Tool Settings +CTL_OutlineTopComponent=Outline +HINT_OutlineTopComponent=Displays loaded compilations. +OpenIDE-Module-Name=OutlineView diff -r 6cb549627941 -r 015fb895586b visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/CompilationNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/CompilationNode.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ +package com.oracle.graal.visualizer.outline; + +import com.sun.hotspot.igv.data.*; +import com.sun.hotspot.igv.data.services.GraphViewer; +import java.awt.Image; +import java.util.ArrayList; +import java.util.List; +import javax.swing.Action; +import javax.swing.JOptionPane; +import org.openide.actions.OpenAction; +import org.openide.cookies.OpenCookie; +import org.openide.nodes.AbstractNode; +import org.openide.nodes.Children; +import org.openide.nodes.Node; +import org.openide.util.ImageUtilities; +import org.openide.util.Lookup; +import org.openide.util.lookup.AbstractLookup; +import org.openide.util.lookup.InstanceContent; +import org.openide.util.lookup.Lookups; + +public class CompilationNode extends AbstractNode implements ChangedListener { + + private CompilationNode(final Folder folder, Children children, InstanceContent content) { + super(children, new AbstractLookup(content)); + this.setDisplayName(folder.getName()); + + if (folder instanceof Group) { + content.add(new OpenCookie() { + + @Override + public void open() { + final List graphs = ((Group) folder).getGraphs(); + if (graphs.isEmpty()) { + JOptionPane.showMessageDialog(null, "Cannot open compilation, because there was no snapshots recorded!"); + } else { + Lookup.getDefault().lookup(GraphViewer.class).view(graphs.get(0)); + } + } + }); + } + content.add(folder); + folder.getChangedEvent().addListener(this); + } + + @Override + public void changed(Object folder) { + if (this.getChildren() == Children.LEAF) { + setChildren(createFolderChildren((Folder) folder)); + this.fireIconChange(); + } + } + + private static class FolderChildren extends Children.Keys { + + private final Folder folder; + + public FolderChildren(Folder folder) { + this.folder = folder; + folder.getChangedEvent().addListener(changedListener); + } + + @Override + protected Node[] createNodes(Folder e) { + return new Node[]{new CompilationNode(e)}; + } + + @Override + public void addNotify() { + List result = new ArrayList<>(); + for (FolderElement o : folder.getElements()) { + if (o instanceof Folder) { + result.add((Folder) o); + } + } + this.setKeys(result); + } + private final ChangedListener changedListener = new ChangedListener() { + + @Override + public void changed(Object source) { + addNotify(); + } + }; + } + + @Override + public Image getIcon(int i) { + if (this.getChildren() == Children.LEAF) { + return ImageUtilities.loadImage("com/oracle/graal/visualizer/outline/images/leaf_node.gif"); + } else { + return ImageUtilities.loadImage("com/oracle/graal/visualizer/outline/images/node.gif"); + } + } + + protected CompilationNode(Folder folder) { + this(folder, createFolderChildren(folder), new InstanceContent()); + } + + private static Children createFolderChildren(Folder folder) { + for (FolderElement elem : folder.getElements()) { + if (elem instanceof Folder) { + return new FolderChildren(folder); + } + } + return Children.LEAF; + } + + @Override + public Action[] getActions(boolean context) { + List actions = new ArrayList<>(); + actions.add((Action) OpenAction.findObject(OpenAction.class, true)); + actions.addAll(Lookups.forPath(OutlineTopComponent.NODE_ACTIONS_FOLDER).lookupAll(Action.class)); + return actions.toArray(new Action[actions.size()]); + } + + @Override + public Action getPreferredAction() { + return (Action) OpenAction.findObject(OpenAction.class, true); + } + + @Override + public Image getOpenedIcon(int i) { + return getIcon(i); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/OutlineTopComponent.form --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/OutlineTopComponent.form Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,32 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 6cb549627941 -r 015fb895586b visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/OutlineTopComponent.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/OutlineTopComponent.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ +package com.oracle.graal.visualizer.outline; + +import com.oracle.graal.visualizer.outline.server.ServerPanel; +import com.oracle.graal.visualizer.util.LookupUtils; +import com.sun.hotspot.igv.data.GraphDocument; +import java.awt.BorderLayout; +import javax.swing.Action; +import org.openide.actions.GarbageCollectAction; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.Toolbar; +import org.openide.explorer.ExplorerManager; +import org.openide.explorer.ExplorerUtils; +import org.openide.explorer.view.BeanTreeView; +import org.openide.util.NbBundle; +import org.openide.windows.TopComponent; +import org.openide.windows.WindowManager; + +@TopComponent.Description(preferredID = OutlineTopComponent.PREFERRED_ID, persistenceType = TopComponent.PERSISTENCE_ALWAYS) +@TopComponent.Registration(mode = "explorer", openAtStartup = true) +@ActionID(category = "Window", id = "com.oracle.graal.visualizer.outline.OutlineTopComponent") +@ActionReference(path = "Menu/Window") +@TopComponent.OpenActionRegistration(displayName = "Outline", preferredID = OutlineTopComponent.PREFERRED_ID) +public final class OutlineTopComponent extends TopComponent implements ExplorerManager.Provider { + + public static final String GLOBAL_ACTIONS_FOLDER = "Actions/Outline/Global"; + public static final String NODE_ACTIONS_FOLDER = "Actions/Outline/Nodes"; + public static OutlineTopComponent instance; + public static final String PREFERRED_ID = "OutlineTopComponent"; + private ExplorerManager manager; + private GraphDocument document; + + private OutlineTopComponent() { + initComponents(); + + setName(NbBundle.getMessage(OutlineTopComponent.class, "CTL_OutlineTopComponent")); + setToolTipText(NbBundle.getMessage(OutlineTopComponent.class, "HINT_OutlineTopComponent")); + + document = new GraphDocument(); + initListView(); + initToolbar(); + } + + private void initListView() { + manager = new ExplorerManager(); + manager.setRootContext(new CompilationNode(document)); + ((BeanTreeView) this.treeView).setRootVisible(false); + associateLookup(ExplorerUtils.createLookup(manager, getActionMap())); + } + + private void initToolbar() { + Toolbar toolbar = new Toolbar(); + this.add(toolbar, BorderLayout.NORTH); + for (Action a : LookupUtils.lookupActions(GLOBAL_ACTIONS_FOLDER, getLookup())) { + toolbar.add(a); + } + toolbar.add(GarbageCollectAction.get(GarbageCollectAction.class).getToolbarPresenter()); + toolbar.add(new ServerPanel(getDocument())); + } + + @Override + public ExplorerManager getExplorerManager() { + return manager; + } + + public GraphDocument getDocument() { + return document; + } + + public static OutlineTopComponent findInstance() { + return (OutlineTopComponent) WindowManager.getDefault().findTopComponent(PREFERRED_ID); + } + + @Override + public int getPersistenceType() { + return TopComponent.PERSISTENCE_NEVER; + } + + @Override + protected String preferredID() { + return PREFERRED_ID; + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + treeView = new BeanTreeView(); + + setLayout(new java.awt.BorderLayout()); + add(treeView, java.awt.BorderLayout.CENTER); + }// //GEN-END:initComponents + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JScrollPane treeView; + // End of variables declaration//GEN-END:variables +} diff -r 6cb549627941 -r 015fb895586b visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/actions/ImportAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/actions/ImportAction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +package com.oracle.graal.visualizer.outline.actions; + +import com.oracle.graal.visualizer.outline.OutlineTopComponent; +import com.sun.hotspot.igv.data.GraphDocument; +import com.sun.hotspot.igv.data.serialization.Parser; +import com.sun.hotspot.igv.data.serialization.XMLParser; +import com.sun.hotspot.igv.settings.Settings; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import javax.swing.JFileChooser; +import javax.swing.SwingUtilities; +import javax.swing.filechooser.FileFilter; +import org.netbeans.api.progress.ProgressHandle; +import org.netbeans.api.progress.ProgressHandleFactory; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; +import org.openide.awt.ActionRegistration; +import org.openide.util.RequestProcessor; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +@ActionID(id = "com.oracle.graal.visualizer.outline.actions.ImportAction", category = "File") +@ActionRegistration(displayName = "Import", iconBase="com/oracle/graal/visualizer/outline/images/import.png") +@ActionReferences(value = { + @ActionReference(path = "Menu/File", position = 100), + @ActionReference(path = OutlineTopComponent.GLOBAL_ACTIONS_FOLDER)}) +public final class ImportAction implements ActionListener { + + public static FileFilter getFileFilter() { + return new FileFilter() { + + @Override + public boolean accept(File f) { + return f.getName().toLowerCase().endsWith(".xml") || f.isDirectory(); + } + + @Override + public String getDescription() { + return "XML files (*.xml)"; + } + }; + } + + @Override + public void actionPerformed(ActionEvent e) { + + JFileChooser fc = new JFileChooser(); + fc.setFileFilter(ImportAction.getFileFilter()); + fc.setCurrentDirectory(new File(Settings.get().get(Settings.DIRECTORY, Settings.DIRECTORY_DEFAULT))); + + if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { + File file = fc.getSelectedFile(); + + File dir = file; + if (!dir.isDirectory()) { + dir = dir.getParentFile(); + } + + Settings.get().put(Settings.DIRECTORY, dir.getAbsolutePath()); + + try { + final FileInputStream inputStream = new FileInputStream(file); + final InputSource is = new InputSource(inputStream); + + final ProgressHandle handle = ProgressHandleFactory.createHandle("Opening file " + file.getName()); + final int basis = 1000; + handle.start(basis); + final int start = inputStream.available(); + + final XMLParser.ParseMonitor parseMonitor = new XMLParser.ParseMonitor() { + + @Override + public void setProgress(double d) { + try { + int curAvailable = inputStream.available(); + int prog = (int) (basis * (double) (start - curAvailable) / (double) start); + handle.progress(prog); + } catch (IOException ex) { + } + } + + @Override + public void setState(String state) { + setProgress(0.0); + handle.progress(state); + } + }; + final Parser parser = new Parser(); + final OutlineTopComponent component = OutlineTopComponent.findInstance(); + + component.requestActive(); + + RequestProcessor.getDefault().post(new Runnable() { + + @Override + public void run() { + try { + final GraphDocument document = parser.parse(is, parseMonitor); + parseMonitor.setState("Finishing"); + SwingUtilities.invokeLater(new Runnable(){ + + @Override + public void run() { + component.getDocument().addGraphDocument(document); + } + }); + } catch (SAXException ex) { + String s = "Exception during parsing the XML file, could not load document!"; + if (ex instanceof XMLParser.MissingAttributeException) { + XMLParser.MissingAttributeException e = (XMLParser.MissingAttributeException) ex; + s += "\nMissing attribute \"" + e.getAttributeName() + "\""; + } + NotifyDescriptor d = new NotifyDescriptor.Message(s, NotifyDescriptor.ERROR_MESSAGE); + DialogDisplayer.getDefault().notify(d); + } + handle.finish(); + } + }); + + } catch (IOException ex) { + DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message("Error reading file!", NotifyDescriptor.ERROR_MESSAGE)); + } + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/actions/RemoveAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/actions/RemoveAction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ +package com.oracle.graal.visualizer.outline.actions; + +import com.oracle.graal.visualizer.outline.OutlineTopComponent; +import com.sun.hotspot.igv.data.FolderElement; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.List; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; +import org.openide.awt.ActionRegistration; + +@ActionID(id = "com.oracle.graal.visualizer.outline.actions.RemoveAction", category = "Edit") +@ActionRegistration(displayName = "Remove", iconBase = "com/oracle/graal/visualizer/outline/images/remove.png") +@ActionReferences(value = { + @ActionReference(path = "Menu/File", position = 400), + @ActionReference(path = OutlineTopComponent.NODE_ACTIONS_FOLDER)}) +public final class RemoveAction implements ActionListener { + + List elements; + + public RemoveAction(List elements) { + this.elements = elements; + } + + @Override + public void actionPerformed(ActionEvent e) { + for (FolderElement element : elements) { + element.getParent().removeElement(element); + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/actions/RemoveAllAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/actions/RemoveAllAction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.visualizer.outline.actions; + +import com.oracle.graal.visualizer.outline.OutlineTopComponent; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; +import org.openide.awt.ActionRegistration; + +@ActionID(id = "com.oracle.graal.visualizer.outline.actions.RemoveAllAction", category = "Edit") +@ActionRegistration(displayName = "Remove all", iconBase = "com/oracle/graal/visualizer/outline/images/removeall.png") +@ActionReferences(value = { + @ActionReference(path = "Menu/File", position = 500), + @ActionReference(path = OutlineTopComponent.GLOBAL_ACTIONS_FOLDER)}) +public final class RemoveAllAction implements ActionListener { + + @Override + public void actionPerformed(ActionEvent e) { + OutlineTopComponent.findInstance().getDocument().clear(); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/actions/SaveAllAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/actions/SaveAllAction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.visualizer.outline.actions; + +import com.oracle.graal.visualizer.outline.OutlineTopComponent; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; +import org.openide.awt.ActionRegistration; + +@ActionID(id = "com.oracle.graal.visualizer.outline.actions.SaveAllAction", category = "File") +@ActionRegistration(displayName = "Save all..", iconBase = "com/oracle/graal/visualizer/outline/images/saveall.gif") +@ActionReferences(value = { + @ActionReference(path = "Menu/File", position = 300), + @ActionReference(path = OutlineTopComponent.GLOBAL_ACTIONS_FOLDER)}) +public final class SaveAllAction implements ActionListener { + + @Override + public void actionPerformed(ActionEvent e) { + final OutlineTopComponent component = OutlineTopComponent.findInstance(); + SaveAsAction.save(component.getDocument()); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/actions/SaveAsAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/actions/SaveAsAction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +package com.oracle.graal.visualizer.outline.actions; + +import com.oracle.graal.visualizer.outline.OutlineTopComponent; +import com.sun.hotspot.igv.data.Folder; +import com.sun.hotspot.igv.data.FolderElement; +import com.sun.hotspot.igv.data.GraphDocument; +import com.sun.hotspot.igv.data.serialization.Printer; +import com.sun.hotspot.igv.settings.Settings; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.*; +import java.util.List; +import javax.swing.JFileChooser; +import javax.swing.JOptionPane; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; +import org.openide.awt.ActionRegistration; + +@ActionID(id = "com.oracle.graal.visualizer.outline.actions.SaveAsAction", category = "File") +@ActionRegistration(displayName = "Save as...", iconBase="com/oracle/graal/visualizer/outline/images/save.png") +@ActionReferences(value = { + @ActionReference(path = "Menu/File", position = 200), + @ActionReference(path = OutlineTopComponent.NODE_ACTIONS_FOLDER)}) +public final class SaveAsAction implements ActionListener { + + private final List elements; + + public SaveAsAction(List elements) { + this.elements = elements; + } + + + @Override + public void actionPerformed(ActionEvent e) { + GraphDocument doc = new GraphDocument(); + outer: for (FolderElement element : elements) { + Folder cur = element.getParent(); + while (cur instanceof FolderElement) { + FolderElement curElement = (FolderElement) cur; + if (elements.contains(curElement)) { + continue outer; + } + cur = curElement.getParent(); + } + + Folder previousParent = element.getParent(); + doc.addElement(element); + element.setParent(previousParent); + } + + save(doc); + } + + public static void save(GraphDocument doc) { + JFileChooser fc = new JFileChooser(); + fc.setFileFilter(ImportAction.getFileFilter()); + fc.setCurrentDirectory(new File(Settings.get().get(Settings.DIRECTORY, Settings.DIRECTORY_DEFAULT))); + + if (fc.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { + File file = fc.getSelectedFile(); + if (!file.getName().contains(".")) { + file = new File(file.getAbsolutePath() + ".xml"); + } + + File dir = file; + if (!dir.isDirectory()) { + dir = dir.getParentFile(); + } + Settings.get().put(Settings.DIRECTORY, dir.getAbsolutePath()); + try { + try (Writer writer = new OutputStreamWriter(new FileOutputStream(file))) { + Printer p = new Printer(); + p.export(writer, doc); + } + } catch (IOException e) { + JOptionPane.showMessageDialog(null, "Error writing file " + file.getAbsolutePath()); + } + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/import.png Binary file visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/import.png has changed diff -r 6cb549627941 -r 015fb895586b visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/leaf_node.gif Binary file visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/leaf_node.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/node.gif Binary file visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/node.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/remove.png Binary file visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/remove.png has changed diff -r 6cb549627941 -r 015fb895586b visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/removeall.png Binary file visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/removeall.png has changed diff -r 6cb549627941 -r 015fb895586b visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/save.png Binary file visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/save.png has changed diff -r 6cb549627941 -r 015fb895586b visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/saveall.gif Binary file visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/images/saveall.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/layer.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/layer.xml Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,161 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 6cb549627941 -r 015fb895586b visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/server/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/server/Bundle.properties Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,1 @@ +OpenIDE-Module-Name=NetworkConnection diff -r 6cb549627941 -r 015fb895586b visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/server/Client.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/server/Client.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.visualizer.outline.server; + +import com.sun.hotspot.igv.data.serialization.Parser; +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.Socket; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +public class Client implements Runnable { + + private Socket socket; + private ServerCallback callback; + + public Client(Socket socket, ServerCallback callback) { + this.callback = callback; + this.socket = socket; + } + + @Override + public void run() { + callback.connectionOpened(socket.getInetAddress()); + try { + InputStream inputStream = new BufferedInputStream(socket.getInputStream()); + InputSource is = new InputSource(inputStream); + + try { + Parser parser = new Parser(callback); + parser.parse(is, null); + } catch (SAXException ex) { + throw new IOException(ex); + } + } catch (IOException ex) { + } finally { + try { + socket.close(); + } catch (IOException ex) { + } + callback.connectionClosed(); + } + } +} \ No newline at end of file diff -r 6cb549627941 -r 015fb895586b visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/server/Server.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/server/Server.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.visualizer.outline.server; + +import java.io.IOException; +import java.net.ServerSocket; +import java.net.Socket; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.util.RequestProcessor; + +public class Server { + + private Runnable serverRunnable; + private ServerSocket serverSocket; + + private Server() {} + + + public static Server start(final ServerCallback callback, int port) { + + final Server server = new Server(); + + try { + server.serverSocket = new java.net.ServerSocket(port); + } catch (IOException ex) { + NotifyDescriptor message = new NotifyDescriptor.Message("Could not create server. Listening for incoming data is disabled.", NotifyDescriptor.ERROR_MESSAGE); + DialogDisplayer.getDefault().notifyLater(message); + return null; + } + + Runnable runnable = new Runnable() { + + @Override + public void run() { + while (true) { + try { + Socket clientSocket = server.serverSocket.accept(); + if (server.serverRunnable != this) { + clientSocket.close(); + return; + } + RequestProcessor.getDefault().post(new Client(clientSocket, callback), 0, Thread.MAX_PRIORITY); + } catch (IOException ex) { + server.serverSocket = null; + NotifyDescriptor message = new NotifyDescriptor.Message("Error during listening for incoming connections. Listening for incoming data is disabled.", NotifyDescriptor.ERROR_MESSAGE); + DialogDisplayer.getDefault().notifyLater(message); + return; + } + } + } + }; + + server.serverRunnable = runnable; + RequestProcessor.getDefault().post(runnable, 0, Thread.MAX_PRIORITY); + return server; + } + + void shutdown() { + try { + serverSocket.close(); + } catch (IOException ex) { + } + + serverSocket = null; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/server/ServerCallback.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/server/ServerCallback.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.oracle.graal.visualizer.outline.server; + +import com.sun.hotspot.igv.data.services.GroupCallback; +import java.net.InetAddress; + +public interface ServerCallback extends GroupCallback { + + public void connectionOpened(InetAddress inetAddress); + + public void connectionClosed(); + +} diff -r 6cb549627941 -r 015fb895586b visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/server/ServerPanel.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/OutlineView/src/com/oracle/graal/visualizer/outline/server/ServerPanel.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.visualizer.outline.server; + +import com.sun.hotspot.igv.data.GraphDocument; +import com.sun.hotspot.igv.data.Group; +import com.sun.hotspot.igv.settings.Settings; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Font; +import java.net.InetAddress; +import java.util.prefs.PreferenceChangeEvent; +import java.util.prefs.PreferenceChangeListener; +import javax.swing.BorderFactory; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; + +public class ServerPanel extends JPanel { + + private final static int BORDER_SIZE = 2; + JLabel label; + private Server server; + private int port = -1; + private int numberOfConnections; + private final GraphDocument document; + private final PreferenceChangeListener preferenceChanged = new PreferenceChangeListener() { + + @Override + public void preferenceChange(PreferenceChangeEvent evt) { + updateServer(); + } + }; + private ServerCallback callback = new ServerCallback() { + + @Override + public void connectionOpened(InetAddress inetAddress) { + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + numberOfConnections++; + updateLabel(); + } + }); + } + + @Override + public void connectionClosed() { + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + numberOfConnections--; + updateLabel(); + } + }); + } + + @Override + public void started(Group g) { + document.addElement(g); + } + }; + + private void updateLabel() { + if (numberOfConnections == 0) { + label.setText(String.format("Listening on %d", port)); + label.setFont(label.getFont().deriveFont(Font.PLAIN)); + } else { + label.setText(String.format("%d connections", numberOfConnections)); + label.setFont(label.getFont().deriveFont(Font.BOLD)); + } + } + + private void updateServer() { + int curPort = Integer.parseInt(Settings.get().get(Settings.PORT, Settings.PORT_DEFAULT)); + if (curPort != port) { + port = curPort; + if (server != null) { + server.shutdown(); + } + server = Server.start(callback, port); + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + updateLabel(); + } + }); + } + } + + public ServerPanel(GraphDocument document) { + + this.document = document; + Settings.get().addPreferenceChangeListener(preferenceChanged); + label = new JLabel(); + label.setBorder(BorderFactory.createEmptyBorder(0, BORDER_SIZE, 0, BORDER_SIZE)); + this.setLayout(new BorderLayout()); + this.add(label, BorderLayout.WEST); + updateServer(); + } + + public Component getToolbarPresenter() { + return label; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/SelectionCoordinator/src/com/sun/hotspot/igv/selectioncoordinator/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/SelectionCoordinator/src/com/sun/hotspot/igv/selectioncoordinator/Bundle.properties Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,1 @@ +OpenIDE-Module-Name=SelectionCoordinator diff -r 6cb549627941 -r 015fb895586b visualizer/SelectionCoordinator/src/com/sun/hotspot/igv/selectioncoordinator/SelectionCoordinator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/SelectionCoordinator/src/com/sun/hotspot/igv/selectioncoordinator/SelectionCoordinator.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,138 @@ +/* + * 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.selectioncoordinator; + +import com.sun.hotspot.igv.data.ChangedEvent; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +/** + * + * @author Thomas + */ +public class SelectionCoordinator { + + private static SelectionCoordinator singleInstance = new SelectionCoordinator(); + private Set selectedObjects; + private Set highlightedObjects; + private ChangedEvent selectedChangedEvent; + private ChangedEvent highlightedChangedEvent; + + public static SelectionCoordinator getInstance() { + return singleInstance; + } + + private SelectionCoordinator() { + selectedChangedEvent = new ChangedEvent<>(this); + highlightedChangedEvent = new ChangedEvent<>(this); + selectedObjects = new HashSet<>(); + highlightedObjects = new HashSet<>(); + } + + public Set getSelectedObjects() { + return Collections.unmodifiableSet(selectedObjects); + } + + public Set getHighlightedObjects() { + return Collections.unmodifiableSet(highlightedObjects); + } + + public ChangedEvent getHighlightedChangedEvent() { + return highlightedChangedEvent; + } + + public ChangedEvent getSelectedChangedEvent() { + return selectedChangedEvent; + } + + public void addHighlighted(Object o) { + if (!highlightedObjects.contains(o)) { + highlightedObjects.add(o); + highlightedObjectsChanged(); + } + } + + public void removeHighlighted(Object o) { + if (highlightedObjects.contains(o)) { + highlightedObjects.remove(o); + highlightedObjectsChanged(); + } + } + + public void addAllHighlighted(Set s) { + int oldSize = highlightedObjects.size(); + highlightedObjects.addAll(s); + if (oldSize != highlightedObjects.size()) { + highlightedObjectsChanged(); + } + } + + public void removeAllHighlighted(Set s) { + int oldSize = highlightedObjects.size(); + highlightedObjects.removeAll(s); + if (oldSize != highlightedObjects.size()) { + highlightedObjectsChanged(); + } + } + + private void highlightedObjectsChanged() { + highlightedChangedEvent.fire(); + } + + public void addAllSelected(Set s) { + int oldSize = selectedObjects.size(); + selectedObjects.addAll(s); + if (oldSize != selectedObjects.size()) { + selectedObjectsChanged(); + } + } + + public void removeAllSelected(Set s) { + int oldSize = selectedObjects.size(); + selectedObjects.removeAll(s); + if (oldSize != selectedObjects.size()) { + selectedObjectsChanged(); + } + } + + public void setSelectedObjects(Set s) { + assert s != null; + selectedObjects.clear(); + selectedObjects.addAll(s); + selectedObjectsChanged(); + } + + private void selectedObjectsChanged() { + selectedChangedEvent.fire(); + } + + public void setHighlightedObjects(Set s) { + assert s != null; + this.highlightedObjects.clear(); + this.highlightedObjects.addAll(s); + highlightedObjectsChanged(); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Settings/manifest.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Settings/manifest.mf Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,6 @@ +Manifest-Version: 1.0 +OpenIDE-Module: com.sun.hotspot.igv.settings +OpenIDE-Module-Layer: com/sun/hotspot/igv/settings/layer.xml +OpenIDE-Module-Localizing-Bundle: com/sun/hotspot/igv/settings/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff -r 6cb549627941 -r 015fb895586b visualizer/Settings/src/com/sun/hotspot/igv/settings/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Settings/src/com/sun/hotspot/igv/settings/Bundle.properties Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,5 @@ +AdvancedOption_DisplayName_Settings=Settings +AdvancedOption_Tooltip_Settings=Application Settings +OpenIDE-Module-Name=Settings +OptionsCategory_Name_View=General +OptionsCategory_Title_View=View Settings diff -r 6cb549627941 -r 015fb895586b visualizer/Settings/src/com/sun/hotspot/igv/settings/Settings.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Settings/src/com/sun/hotspot/igv/settings/Settings.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,47 @@ +/* + * 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.settings; + +import java.util.prefs.Preferences; + +/** + * + * @author Thomas Wuerthinger + */ +public class Settings { + + public final static String NODE_TEXT = "nodeText"; + public final static String NODE_TEXT_DEFAULT = "[idx] [name]"; + public final static String NODE_WIDTH = "nodeWidth"; + public final static String NODE_WIDTH_DEFAULT = "100"; + public final static String PORT = "port"; + public final static String PORT_DEFAULT = "4444"; + public final static String DIRECTORY = "directory"; + public final static String DIRECTORY_DEFAULT = System.getProperty("user.dir"); + + public static Preferences get() { + return Preferences.userNodeForPackage(Settings.class); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Settings/src/com/sun/hotspot/igv/settings/ViewOptionsCategory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Settings/src/com/sun/hotspot/igv/settings/ViewOptionsCategory.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,58 @@ +/* + * 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.settings; + +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; +import org.openide.util.NbBundle; + +/** + * + * @author Thomas Wuerthinger + */ +public final class ViewOptionsCategory extends OptionsCategory { + + @Override + public Icon getIcon() { + return new ImageIcon(ImageUtilities.loadImage("com/sun/hotspot/igv/settings/settings.png")); + } + + @Override + public String getCategoryName() { + return NbBundle.getMessage(ViewOptionsCategory.class, "OptionsCategory_Name_View"); + } + + @Override + public String getTitle() { + return NbBundle.getMessage(ViewOptionsCategory.class, "OptionsCategory_Title_View"); + } + + @Override + public OptionsPanelController create() { + return new ViewOptionsPanelController(); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Settings/src/com/sun/hotspot/igv/settings/ViewOptionsPanelController.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Settings/src/com/sun/hotspot/igv/settings/ViewOptionsPanelController.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,104 @@ +/* + * 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.settings; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import javax.swing.JComponent; +import org.netbeans.spi.options.OptionsPanelController; +import org.openide.util.HelpCtx; +import org.openide.util.Lookup; + +/** + * + * @author Thomas Wuerthinger + */ +final class ViewOptionsPanelController extends OptionsPanelController { + + private ViewPanel panel; + private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); + private boolean changed; + + @Override + public void update() { + getPanel().load(); + changed = false; + } + + @Override + public void applyChanges() { + getPanel().store(); + changed = false; + } + + @Override + public void cancel() { + // need not do anything special, if no changes have been persisted yet + } + + @Override + public boolean isValid() { + return getPanel().valid(); + } + + @Override + public boolean isChanged() { + return changed; + } + + @Override + public HelpCtx getHelpCtx() { + return null; // new HelpCtx("...ID") if you have a help set + } + + @Override + public JComponent getComponent(Lookup masterLookup) { + return getPanel(); + } + + @Override + public void addPropertyChangeListener(PropertyChangeListener l) { + pcs.addPropertyChangeListener(l); + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener l) { + pcs.removePropertyChangeListener(l); + } + + private ViewPanel getPanel() { + if (panel == null) { + panel = new ViewPanel(this); + } + return panel; + } + + void changed() { + if (!changed) { + changed = true; + pcs.firePropertyChange(OptionsPanelController.PROP_CHANGED, false, true); + } + pcs.firePropertyChange(OptionsPanelController.PROP_VALID, null, null); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Settings/src/com/sun/hotspot/igv/settings/ViewPanel.form --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Settings/src/com/sun/hotspot/igv/settings/ViewPanel.form Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,121 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff -r 6cb549627941 -r 015fb895586b visualizer/Settings/src/com/sun/hotspot/igv/settings/ViewPanel.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Settings/src/com/sun/hotspot/igv/settings/ViewPanel.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,144 @@ +/* + * 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.settings; + +/** + * + * @author Thomas Wuerthinger + */ +final class ViewPanel extends javax.swing.JPanel { + + private final ViewOptionsPanelController controller; + + ViewPanel(ViewOptionsPanelController controller) { + this.controller = controller; + initComponents(); + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + jPanel1 = new javax.swing.JPanel(); + jLabel1 = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); + portSpinner = new javax.swing.JSpinner(); + jScrollPane1 = new javax.swing.JScrollPane(); + nodeTextArea = new javax.swing.JTextArea(); + nodeWidthSpinner = new javax.swing.JSpinner(); + jLabel3 = new javax.swing.JLabel(); + + org.openide.awt.Mnemonics.setLocalizedText(jLabel1, "Node Text"); + + org.openide.awt.Mnemonics.setLocalizedText(jLabel2, "Node Width"); + + nodeTextArea.setColumns(20); + nodeTextArea.setRows(5); + jScrollPane1.setViewportView(nodeTextArea); + + org.openide.awt.Mnemonics.setLocalizedText(jLabel3, "Network Port"); + + org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1); + jPanel1.setLayout(jPanel1Layout); + jPanel1Layout.setHorizontalGroup( + jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup() + .addContainerGap() + .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(jLabel1) + .add(jLabel3) + .add(jLabel2)) + .add(39, 39, 39) + .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(portSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 63, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(nodeWidthSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 63, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 365, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addContainerGap()) + ); + jPanel1Layout.setVerticalGroup( + jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(jPanel1Layout.createSequentialGroup() + .addContainerGap() + .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(jPanel1Layout.createSequentialGroup() + .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(18, 18, 18) + .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(nodeWidthSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(jLabel2)) + .add(18, 18, 18) + .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(portSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(jLabel3))) + .add(jLabel1)) + .add(73, 73, 73)) + ); + + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 232, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addContainerGap(206, Short.MAX_VALUE)) + ); + }// //GEN-END:initComponents + void load() { + nodeTextArea.setText(Settings.get().get(Settings.NODE_TEXT, Settings.NODE_TEXT_DEFAULT)); + nodeWidthSpinner.setValue(Integer.parseInt(Settings.get().get(Settings.NODE_WIDTH, Settings.NODE_WIDTH_DEFAULT))); + portSpinner.setValue(Integer.parseInt(Settings.get().get(Settings.PORT, Settings.PORT_DEFAULT))); + } + + void store() { + Settings.get().put(Settings.NODE_TEXT, nodeTextArea.getText()); + Settings.get().put(Settings.NODE_WIDTH, nodeWidthSpinner.getValue().toString()); + Settings.get().put(Settings.PORT, portSpinner.getValue().toString()); + } + + boolean valid() { + return true; + } + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JPanel jPanel1; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTextArea nodeTextArea; + private javax.swing.JSpinner nodeWidthSpinner; + private javax.swing.JSpinner portSpinner; + // End of variables declaration//GEN-END:variables +} diff -r 6cb549627941 -r 015fb895586b visualizer/Settings/src/com/sun/hotspot/igv/settings/layer.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Settings/src/com/sun/hotspot/igv/settings/layer.xml Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,11 @@ + + + + + + + + + + diff -r 6cb549627941 -r 015fb895586b visualizer/Settings/src/com/sun/hotspot/igv/settings/settings.png Binary file visualizer/Settings/src/com/sun/hotspot/igv/settings/settings.png has changed diff -r 6cb549627941 -r 015fb895586b visualizer/SharedActions/manifest.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/SharedActions/manifest.mf Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +OpenIDE-Module: com.oracle.graal.visualizer.sharedactions +OpenIDE-Module-Localizing-Bundle: com/oracle/graal/visualizer/sharedactions/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff -r 6cb549627941 -r 015fb895586b visualizer/SharedActions/src/com/oracle/graal/visualizer/sharedactions/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/SharedActions/src/com/oracle/graal/visualizer/sharedactions/Bundle.properties Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,1 @@ +OpenIDE-Module-Name=SharedActions diff -r 6cb549627941 -r 015fb895586b visualizer/SharedActions/src/com/oracle/graal/visualizer/sharedactions/ExportSVGAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/SharedActions/src/com/oracle/graal/visualizer/sharedactions/ExportSVGAction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,118 @@ +/* + * 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.sharedactions; + +import com.sun.hotspot.igv.svg.BatikSVG; +import java.awt.Graphics2D; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.*; +import javax.swing.JFileChooser; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionRegistration; +import org.openide.util.NbPreferences; + +@ActionID(id = "com.oracle.graal.visualizer.sharedactions.ExportSVGAction", category = "File") +@ActionRegistration(displayName = "Export", iconBase = "com/oracle/graal/visualizer/sharedactions/images/export.png") +@ActionReference(path = "Menu/File", position = 600) +public class ExportSVGAction implements ActionListener { + + private static final String PREFERENCE_DIR = "dir"; + private ExportSVGCookie exportCookie; + + public ExportSVGAction(ExportSVGCookie exportCookie) { + this.exportCookie = exportCookie; + } + + @Override + public void actionPerformed(ActionEvent actionEvent) { + 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); + return; + } + + File f = selectFile(); + if (f != null) { + exportCookie.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 File selectFile() { + JFileChooser fc = new JFileChooser(); + fc.setFileFilter(new javax.swing.filechooser.FileFilter() { + + @Override + public boolean accept(File f) { + return true; + } + + @Override + public String getDescription() { + return "SVG files (*.svg)"; + } + }); + fc.setCurrentDirectory(new File(NbPreferences.forModule(ExportSVGAction.class).get(PREFERENCE_DIR, "~"))); + + + if (fc.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { + File file = fc.getSelectedFile(); + if (!file.getName().contains(".")) { + file = new File(file.getAbsolutePath() + ".svg"); + } + + File dir = file; + if (!dir.isDirectory()) { + dir = dir.getParentFile(); + } + + NbPreferences.forModule(ExportSVGAction.class).put(PREFERENCE_DIR, dir.getAbsolutePath()); + return file; + } + + return null; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/SharedActions/src/com/oracle/graal/visualizer/sharedactions/ExportSVGCookie.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/SharedActions/src/com/oracle/graal/visualizer/sharedactions/ExportSVGCookie.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,30 @@ +/* + * 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.sharedactions; + +import java.awt.Graphics2D; + +public interface ExportSVGCookie { + void paint(Graphics2D g); +} diff -r 6cb549627941 -r 015fb895586b visualizer/SharedActions/src/com/oracle/graal/visualizer/sharedactions/ShowAllAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/SharedActions/src/com/oracle/graal/visualizer/sharedactions/ShowAllAction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,50 @@ +/* + * 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.sharedactions; + +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 = "com.oracle.graal.visualizer.sharedactions.ShowAllAction", category = "View") +@ActionRegistration(displayName = "Fit Scene to Window", iconBase="com/oracle/graal/visualizer/sharedactions/images/autosize.gif") +@ActionReference(path = "Menu/View", position = 500) +public class ShowAllAction implements ActionListener { + + private List zoomCookies; + + public ShowAllAction(List zoomCookies) { + this.zoomCookies = zoomCookies; + } + + @Override + public void actionPerformed(ActionEvent e) { + for (ZoomCookie c : zoomCookies) { + c.showAll(); + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/SharedActions/src/com/oracle/graal/visualizer/sharedactions/ZoomCookie.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/SharedActions/src/com/oracle/graal/visualizer/sharedactions/ZoomCookie.java Tue Feb 07 22:41:09 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.sharedactions; + +public interface ZoomCookie { + void zoomIn(); + void zoomOut(); + void showAll(); + +} diff -r 6cb549627941 -r 015fb895586b visualizer/SharedActions/src/com/oracle/graal/visualizer/sharedactions/ZoomInAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/SharedActions/src/com/oracle/graal/visualizer/sharedactions/ZoomInAction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,50 @@ +/* + * 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.sharedactions; + +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 = "com.oracle.graal.visualizer.sharedactions.ZoomInAction", category = "View") +@ActionRegistration(displayName = "Zoom In", iconBase="com/oracle/graal/visualizer/sharedactions/images/zoomin.gif") +@ActionReference(path = "Menu/View", position = 600) +public class ZoomInAction implements ActionListener { + + private List zoomCookies; + + public ZoomInAction(List zoomCookies) { + this.zoomCookies = zoomCookies; + } + + @Override + public void actionPerformed(ActionEvent e) { + for (ZoomCookie c : zoomCookies) { + c.zoomIn(); + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/SharedActions/src/com/oracle/graal/visualizer/sharedactions/ZoomOutAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/SharedActions/src/com/oracle/graal/visualizer/sharedactions/ZoomOutAction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,50 @@ +/* + * 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.sharedactions; + +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 = "com.oracle.graal.visualizer.sharedactions.ZoomOutAction", category = "View") +@ActionRegistration(displayName = "Zoom Out", iconBase="com/oracle/graal/visualizer/sharedactions/images/zoomout.gif") +@ActionReference(path = "Menu/View", position = 700) +public class ZoomOutAction implements ActionListener { + + private List zoomCookies; + + public ZoomOutAction(List zoomCookies) { + this.zoomCookies = zoomCookies; + } + + @Override + public void actionPerformed(ActionEvent e) { + for (ZoomCookie c : zoomCookies) { + c.zoomOut(); + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/SharedActions/src/com/oracle/graal/visualizer/sharedactions/images/autosize.gif Binary file visualizer/SharedActions/src/com/oracle/graal/visualizer/sharedactions/images/autosize.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/SharedActions/src/com/oracle/graal/visualizer/sharedactions/images/export.png Binary file visualizer/SharedActions/src/com/oracle/graal/visualizer/sharedactions/images/export.png has changed diff -r 6cb549627941 -r 015fb895586b visualizer/SharedActions/src/com/oracle/graal/visualizer/sharedactions/images/zoomin.gif Binary file visualizer/SharedActions/src/com/oracle/graal/visualizer/sharedactions/images/zoomin.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/SharedActions/src/com/oracle/graal/visualizer/sharedactions/images/zoomout.gif Binary file visualizer/SharedActions/src/com/oracle/graal/visualizer/sharedactions/images/zoomout.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/SnapshotsView/manifest.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/SnapshotsView/manifest.mf Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,7 @@ +Manifest-Version: 1.0 +OpenIDE-Module: com.oracle.graal.visualizer.snapshots +OpenIDE-Module-Layer: com/oracle/graal/visualizer/snapshots/layer.xml +OpenIDE-Module-Localizing-Bundle: com/oracle/graal/visualizer/snapshots/Bundle.properties +OpenIDE-Module-Requires: org.openide.windows.WindowManager +OpenIDE-Module-Specification-Version: 1.0 + diff -r 6cb549627941 -r 015fb895586b visualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/Bundle.properties Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,1 @@ +OpenIDE-Module-Name=SnapshotsView diff -r 6cb549627941 -r 015fb895586b visualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/SnapshotTopComponent.form --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/SnapshotTopComponent.form Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,28 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
diff -r 6cb549627941 -r 015fb895586b visualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/SnapshotTopComponent.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/SnapshotTopComponent.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ +package com.oracle.graal.visualizer.snapshots; + +import com.oracle.graal.visualizer.editor.EditorTopComponent; +import com.oracle.graal.visualizer.util.LookupUtils; +import com.sun.hotspot.igv.data.ChangedEvent; +import com.sun.hotspot.igv.data.ChangedListener; +import com.sun.hotspot.igv.util.RangeSlider; +import com.sun.hotspot.igv.util.RangeSliderModel; +import java.awt.BorderLayout; +import javax.swing.JScrollPane; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.util.Lookup.Result; +import org.openide.util.LookupEvent; +import org.openide.util.LookupListener; +import org.openide.windows.TopComponent; +import org.openide.windows.WindowManager; + +@TopComponent.Description(preferredID = SnapshotTopComponent.PREFERRED_ID, persistenceType = TopComponent.PERSISTENCE_ALWAYS) +@TopComponent.Registration(mode = "belowExplorer", openAtStartup = true) +@ActionID(category = "Window", id = "com.oracle.graal.visualizer.snapshots.SnapshotTopComponent") +@ActionReference(path = "Menu/Window") +@TopComponent.OpenActionRegistration(displayName = "Snapshot", preferredID = SnapshotTopComponent.PREFERRED_ID) +public final class SnapshotTopComponent extends TopComponent { + public static final String PREFERRED_ID = "SnapshotTopComponent"; + + private final Result result; + private final RangeSlider rangeSlider; + private final ChangedEvent rangeSliderChangedEvent = new ChangedEvent(null); + private final LookupListener lookupListener = new LookupListener() { + + @Override + public void resultChanged(LookupEvent le) { + update(); + } + }; + + private final ChangedListener rangeSliderChangedListener = new ChangedListener(){ + + @Override + public void changed(RangeSliderModel source) { + rangeSliderChangedEvent.fire(); + } + }; + + public SnapshotTopComponent() { + initComponents(); + setName("Snapshot Window"); + setToolTipText("This is a Snapshot window"); + + result = LookupUtils.getLastActiveDelegatingLookup(EditorTopComponent.class).lookupResult(RangeSliderModel.class); + result.addLookupListener(lookupListener); + this.rangeSlider = new RangeSlider(null); + this.setLayout(new BorderLayout()); + this.add(new JScrollPane(rangeSlider), BorderLayout.CENTER); + update(); + } + + private void update() { + RangeSliderModel newModel; + if (result.allInstances().size() > 0) { + newModel = result.allInstances().iterator().next(); + } else { + newModel = null; + } + if (rangeSlider.getModel() != null) { + rangeSlider.getModel().getChangedEvent().removeListener(rangeSliderChangedListener); + } + rangeSlider.setModel(newModel); + rangeSliderChangedEvent.changeObject(newModel); + if (newModel != null) { + newModel.getChangedEvent().addListener(rangeSliderChangedListener); + } + } + + public ChangedEvent getRangeSliderChangedEvent() { + return rangeSliderChangedEvent; + } + + public static SnapshotTopComponent findInstance() { + return (SnapshotTopComponent) WindowManager.getDefault().findTopComponent(PREFERRED_ID); + } + + /** + * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 400, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 300, Short.MAX_VALUE) + ); + }// //GEN-END:initComponents + // Variables declaration - do not modify//GEN-BEGIN:variables + // End of variables declaration//GEN-END:variables + +} diff -r 6cb549627941 -r 015fb895586b visualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/actions/NextSnapshotAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/actions/NextSnapshotAction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ +package com.oracle.graal.visualizer.snapshots.actions; + +import com.oracle.graal.visualizer.snapshots.SnapshotTopComponent; +import com.sun.hotspot.igv.data.ChangedListener; +import com.sun.hotspot.igv.util.RangeSliderModel; +import java.awt.event.ActionEvent; +import javax.swing.AbstractAction; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionRegistration; + +@ActionID(id = "com.oracle.graal.visualizer.editor.actions.NextSnapshotAction", category = "View") +@ActionRegistration(displayName = "Next snapshot", iconBase = "com/oracle/graal/visualizer/snapshots/images/next_snapshot.png") +@ActionReference(path = "Menu/View", position = 150) +public final class NextSnapshotAction extends AbstractAction{ + + private RangeSliderModel model; + + public NextSnapshotAction() { + SnapshotTopComponent.findInstance().getRangeSliderChangedEvent().addListenerAndFire(changeListener); + } + private final ChangedListener changeListener = new ChangedListener() { + + @Override + public void changed(RangeSliderModel source) { + model = source; + setEnabled(model != null && model.getSecondPosition() != model.getPositions().size() - 1); + } + }; + + @Override + public void actionPerformed(ActionEvent e) { + if (model != null) { + int fp = model.getFirstPosition(); + int sp = model.getSecondPosition(); + if (sp != model.getPositions().size() - 1) { + int nfp = fp + 1; + int nsp = sp + 1; + model.setPositions(nfp, nsp); + } + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/actions/PrevSnapshotAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/actions/PrevSnapshotAction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ +package com.oracle.graal.visualizer.snapshots.actions; + +import com.oracle.graal.visualizer.snapshots.SnapshotTopComponent; +import com.sun.hotspot.igv.data.ChangedListener; +import com.sun.hotspot.igv.util.RangeSliderModel; +import java.awt.event.ActionEvent; +import javax.swing.AbstractAction; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionRegistration; + +@ActionID(id = "com.oracle.graal.visualizer.editor.actions.PrevSnapshotAction", category = "View") +@ActionRegistration(displayName = "Previous snapshot", iconBase = "com/oracle/graal/visualizer/snapshots/images/prev_snapshot.png") +@ActionReference(path = "Menu/View", position = 100) +public final class PrevSnapshotAction extends AbstractAction { + + private RangeSliderModel model; + + public PrevSnapshotAction() { + SnapshotTopComponent.findInstance().getRangeSliderChangedEvent().addListenerAndFire(changeListener); + } + private final ChangedListener changeListener = new ChangedListener() { + + @Override + public void changed(RangeSliderModel source) { + model = source; + setEnabled(model != null && model.getFirstPosition() != 0); + } + }; + + @Override + public void actionPerformed(ActionEvent e) { + if (model != null) { + int fp = model.getFirstPosition(); + int sp = model.getSecondPosition(); + if (fp != 0) { + int nfp = fp - 1; + int nsp = sp - 1; + model.setPositions(nfp, nsp); + } + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/belowExplorerWsmode.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/belowExplorerWsmode.xml Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff -r 6cb549627941 -r 015fb895586b visualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/images/next_snapshot.png Binary file visualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/images/next_snapshot.png has changed diff -r 6cb549627941 -r 015fb895586b visualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/images/prev_snapshot.png Binary file visualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/images/prev_snapshot.png has changed diff -r 6cb549627941 -r 015fb895586b visualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/layer.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/SnapshotsView/src/com/oracle/graal/visualizer/snapshots/layer.xml Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,9 @@ + + + + + + + + + diff -r 6cb549627941 -r 015fb895586b visualizer/Util/manifest.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Util/manifest.mf Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +OpenIDE-Module: com.sun.hotspot.igv.util +OpenIDE-Module-Localizing-Bundle: com/sun/hotspot/igv/util/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff -r 6cb549627941 -r 015fb895586b visualizer/Util/src/com/oracle/graal/visualizer/util/LookupUtils.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Util/src/com/oracle/graal/visualizer/util/LookupUtils.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +package com.oracle.graal.visualizer.util; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.ArrayList; +import java.util.List; +import javax.swing.Action; +import org.openide.util.ContextAwareAction; +import org.openide.util.Lookup; +import org.openide.util.Lookup.Provider; +import org.openide.util.lookup.Lookups; +import org.openide.windows.TopComponent; + +/** + * Utilities that build upon the Lookup API. + */ +public class LookupUtils { + + + /** + * Creates a new lookup that will delegate to the last open window of a specified top component class. If the window is closed, the lookup will be empty. + * @param clazz the class identifying the top component type + * @return a delegating lookup + */ + public static Lookup getLastActiveDelegatingLookup(Class clazz) { + final TopComponentLookup topComponentLookupImpl = new TopComponentLookup(clazz); + TopComponent.getRegistry().addPropertyChangeListener(topComponentLookupImpl); + return topComponentLookupImpl.lookup; + } + + public static Iterable lookupActions(String path) { + return lookupActions(path, null); + } + + public static Iterable lookupActions(String path, Lookup context) { + List actions = new ArrayList<>(); + for (Action a : Lookups.forPath(path).lookupAll(Action.class)) { + Action newAction = a; + if (a instanceof ContextAwareAction && context != null) { + newAction = ((ContextAwareAction) a).createContextAwareInstance(context); + } + newAction.putValue(Action.SHORT_DESCRIPTION, newAction.getValue(Action.NAME)); + actions.add(newAction); + + } + return actions; + } + + private static class TopComponentLookup implements PropertyChangeListener { + private final Class clazz; + private final Lookup lookup; + private TopComponent lastActive; + + private final Provider lookupProvider = new Provider() { + + @Override + public Lookup getLookup() { + if (lastActive == null) { + return Lookup.EMPTY; + } else { + return lastActive.getLookup(); + } + } + }; + + public TopComponentLookup(Class clazz) { + this.clazz = clazz; + lookup = Lookups.proxy(lookupProvider); + update(); + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + update(); + } + + private void update() { + TopComponent curActivated = TopComponent.getRegistry().getActivated(); + if (curActivated != lastActive) { + if (clazz.isAssignableFrom(curActivated.getClass())) { + // We have a new top component for our lookup. + lastActive = curActivated; + refreshLookup(); + } else { + // We have no new top component. Check if the old one is still opened. + if (lastActive != null && !TopComponent.getRegistry().getOpened().contains(lastActive)) { + // The top component was closed => Remove lookup. + lastActive = null; + refreshLookup(); + } + } + } + } + + private void refreshLookup() { + lookup.lookup(Object.class); + } + }; +} diff -r 6cb549627941 -r 015fb895586b visualizer/Util/src/com/sun/hotspot/igv/util/BoundedZoomAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Util/src/com/sun/hotspot/igv/util/BoundedZoomAction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,180 @@ +/* + * 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.util; + +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) { + 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 <= 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--; + } + while (amount < 0 && zoom * zoomMultiplier >= minFactor && 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 <= 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--; + } + while (amount < 0 && zoom * zoomMultiplier >= minFactor && 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) { + scene.validate(); // Call validate to update size of scene + Dimension size = scrollPane.getViewport().getExtentSize(); + viewPosition.x -= xOffset; + viewPosition.y -= yOffset; + scene.resolveBounds(scene.getLocation(), bounds); + scene.getView().setPreferredSize(componentSize); + scene.getView().revalidate(); + scene.getView().addNotify(); + scrollPane.getViewport().setViewPosition(viewPosition); + } + + return WidgetAction.State.CONSUMED; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Util/src/com/sun/hotspot/igv/util/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Util/src/com/sun/hotspot/igv/util/Bundle.properties Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,1 @@ +OpenIDE-Module-Name=Util diff -r 6cb549627941 -r 015fb895586b visualizer/Util/src/com/sun/hotspot/igv/util/ColorIcon.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Util/src/com/sun/hotspot/igv/util/ColorIcon.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,58 @@ +/* + * 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.util; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Graphics; +import javax.swing.Icon; + +/** + * + * @author Thomas Wuerthinger + */ +public class ColorIcon implements Icon { + + private Color color; + + public ColorIcon(Color c) { + color = c; + } + + @Override + public void paintIcon(Component c, Graphics g, int x, int y) { + g.setColor(color); + g.fillRect(x, y, 16, 16); + } + + @Override + public int getIconWidth() { + return 16; + } + + @Override + public int getIconHeight() { + return 16; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Util/src/com/sun/hotspot/igv/util/CompilationViewModel.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Util/src/com/sun/hotspot/igv/util/CompilationViewModel.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,47 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.sun.hotspot.igv.util; + +import com.sun.hotspot.igv.data.*; +import java.awt.Color; +import java.util.List; + +public class CompilationViewModel implements ChangedEventProvider { + + private final ChangedEvent changedEvent = new ChangedEvent<>(this); + private final RangeSliderModel model; + private final Group group; + + @Override + public ChangedEvent getChangedEvent() { + return changedEvent; + } + + public CompilationViewModel(RangeSliderModel model, Group group) { + this.model = model; + this.group = group; + model.getChangedEvent().addListener(rangeSliderChangedListener); + } + + private final ChangedListener rangeSliderChangedListener = new ChangedListener() { + @Override + public void changed(RangeSliderModel source) { + changedEvent.fire(); + } + }; + + public InputGraph getFirstSnapshot() { + return group.getGraphs().get(model.getFirstPosition()); + } + + public InputGraph getSecondSnapshot() { + return group.getGraphs().get(model.getSecondPosition()); + } + + public void setColors(List colors) { + model.setColors(colors); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Util/src/com/sun/hotspot/igv/util/DoubleClickAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Util/src/com/sun/hotspot/igv/util/DoubleClickAction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,49 @@ +/* + * 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.util; + +import org.netbeans.api.visual.action.WidgetAction; +import org.netbeans.api.visual.widget.Widget; + +/** + * + * @author Thomas Wuerthinger + */ +public class DoubleClickAction extends WidgetAction.Adapter { + + private DoubleClickHandler handler; + + public DoubleClickAction(DoubleClickHandler handler) { + this.handler = handler; + } + + @Override + public WidgetAction.State mouseClicked(Widget widget, WidgetAction.WidgetMouseEvent event) { + if (event.getClickCount() > 1) { + handler.handleDoubleClick(widget, event); + return WidgetAction.State.CONSUMED; + } + return WidgetAction.State.REJECTED; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Util/src/com/sun/hotspot/igv/util/DoubleClickHandler.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Util/src/com/sun/hotspot/igv/util/DoubleClickHandler.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,36 @@ +/* + * 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.util; + +import org.netbeans.api.visual.action.WidgetAction.WidgetMouseEvent; +import org.netbeans.api.visual.widget.Widget; + +/** + * + * @author Thomas Wuerthinger + */ +public interface DoubleClickHandler { + + public void handleDoubleClick(Widget w, WidgetMouseEvent e); +} diff -r 6cb549627941 -r 015fb895586b visualizer/Util/src/com/sun/hotspot/igv/util/ExtendedSatelliteComponent.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Util/src/com/sun/hotspot/igv/util/ExtendedSatelliteComponent.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,208 @@ +/* + * 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.util; + +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 Scene scene; + private Image image; + private int imageWidth; + private int imageHeight; + + public ExtendedSatelliteComponent(Scene 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; + repaint(); + } + + @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); + scene.paint(ig); + } + + 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); + + } + + @Override + public void sceneRepaint() { + } + + @Override + public void sceneValidating() { + } + + @Override + public void sceneValidated() { + } + + @Override + public void componentResized(ComponentEvent e) { + repaint(); + } + + @Override + public void componentMoved(ComponentEvent e) { + repaint(); + } + + @Override + public void componentShown(ComponentEvent e) { + } + + @Override + public void componentHidden(ComponentEvent e) { + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Util/src/com/sun/hotspot/igv/util/ExtendedSelectAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Util/src/com/sun/hotspot/igv/util/ExtendedSelectAction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,69 @@ +/* + * 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.util; + +import java.awt.event.MouseEvent; +import javax.swing.JPanel; +import org.netbeans.api.visual.action.ActionFactory; +import org.netbeans.api.visual.action.SelectProvider; +import org.netbeans.api.visual.action.WidgetAction; +import org.netbeans.api.visual.action.WidgetAction.State; +import org.netbeans.api.visual.action.WidgetAction.WidgetKeyEvent; +import org.netbeans.api.visual.action.WidgetAction.WidgetMouseEvent; +import org.netbeans.api.visual.widget.Widget; + +/** + * + * @author Thomas Wuerthinger + */ +public class ExtendedSelectAction extends WidgetAction.Adapter { + + private WidgetAction innerAction; + private JPanel panel; + + public ExtendedSelectAction(SelectProvider provider) { + innerAction = ActionFactory.createSelectAction(provider); + panel = new JPanel(); + } + + @Override + public State mousePressed(Widget widget, WidgetMouseEvent event) { + // TODO: Solve this differently? + if (event.getButton() != MouseEvent.BUTTON2) { + return innerAction.mousePressed(widget, new WidgetMouseEvent(event.getEventID(), new MouseEvent(panel, (int) event.getEventID(), event.getWhen(), event.getModifiersEx(), event.getPoint().x, event.getPoint().y, event.getClickCount(), event.isPopupTrigger(), MouseEvent.BUTTON1))); + } else { + return super.mousePressed(widget, event); + } + } + + @Override + public State mouseReleased(Widget widget, WidgetMouseEvent event) { + return innerAction.mouseReleased(widget, event); + } + + @Override + public State keyTyped(Widget widget, WidgetKeyEvent event) { + return innerAction.keyTyped(widget, event); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Util/src/com/sun/hotspot/igv/util/PropertiesSheet.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Util/src/com/sun/hotspot/igv/util/PropertiesSheet.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,71 @@ +/* + * 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.util; + +import com.sun.hotspot.igv.data.Properties; +import com.sun.hotspot.igv.data.Property; +import java.lang.reflect.InvocationTargetException; +import org.openide.nodes.Node; +import org.openide.nodes.Sheet; + +/** + * + * @author Thomas Wuerthinger + */ +public class PropertiesSheet { + + public static void initializeSheet(final Properties properties, Sheet s) { + + Sheet.Set set1 = Sheet.createPropertiesSet(); + set1.setDisplayName("Properties"); + for (final Property p : properties) { + Node.Property prop = new Node.Property(String.class) { + + @Override + public boolean canRead() { + return true; + } + + @Override + public String getValue() throws IllegalAccessException, InvocationTargetException { + return p.getValue(); + } + + @Override + public boolean canWrite() { + return false; + } + + @Override + public void setValue(String arg0) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { + properties.setProperty(p.getName(), arg0); + } + }; + prop.setName(p.getName()); + set1.put(prop); + } + s.put(set1); + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Util/src/com/sun/hotspot/igv/util/RangeSlider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Util/src/com/sun/hotspot/igv/util/RangeSlider.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,262 @@ +/* + * 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.util; + +import com.sun.hotspot.igv.data.ChangedListener; +import java.awt.*; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.util.List; +import javax.swing.JComponent; + +public final class RangeSlider extends JComponent { + + 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 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 Point startPoint; + private RangeSliderModel tempModel; + private Point lastMouseMove; + + public RangeSlider(RangeSliderModel newModel) { + this.addMouseMotionListener(mouseMotionListener); + this.addMouseListener(mouseListener); + setModel(newModel); + } + + private RangeSliderModel getPaintingModel() { + if (tempModel != null) { + return tempModel; + } + return model; + } + + @Override + public Dimension getPreferredSize() { + if (getPaintingModel() != null) { + Graphics g = this.getGraphics(); + int maxWidth = 0; + List list = getPaintingModel().getPositions(); + for (int i = 0; i < list.size(); i++) { + String curS = list.get(i); + if (curS != null && curS.length() > 0) { + FontMetrics metrics = g.getFontMetrics(); + Rectangle bounds = metrics.getStringBounds(curS, g).getBounds(); + maxWidth = Math.max(maxWidth, (int) bounds.getWidth()); + } + } + return new Dimension(maxWidth + ITEM_WIDTH, ITEM_HEIGHT * list.size()); + } + return super.getPreferredSize(); + } + private ChangedListener modelChangedListener = new ChangedListener() { + + @Override + public void changed(RangeSliderModel source) { + update(); + } + }; + + private void update() { + this.repaint(); + } + + 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 + public void paint(Graphics g) { + super.paint(g); + Graphics2D g2 = (Graphics2D) g; + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + int width = getWidth(); + int height = getHeight(); + + g2.setColor(BACKGROUND_COLOR); + g2.fillRect(0, 0, width, height); + + // Nothing to paint? + if (getPaintingModel() == null || getPaintingModel().getPositions().isEmpty()) { + return; + } + + paintSelected(g2); + paintBar(g2); + + } + + private void fillRect(Graphics2D g, int startX, int startY, int endY, int thickness) { + g.fillRect(startX - thickness / 2, startY, thickness, endY - startY); + } + + private void paintBar(Graphics2D g) { + List list = getPaintingModel().getPositions(); + + g.setColor(BAR_COLOR); + Rectangle firstItemBounds = getItemBounds(0); + Rectangle lastItemBounds = getItemBounds(list.size() - 1); + fillRect(g, (int) firstItemBounds.getCenterX(), (int) firstItemBounds.getCenterY(), (int) lastItemBounds.getCenterY(), BAR_THICKNESS); + + for (int i = 0; i < list.size(); i++) { + Rectangle curItemBounds = getItemBounds(i); + g.setColor(getPaintingModel().getColors().get(i)); + 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((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) { + FontMetrics metrics = g.getFontMetrics(); + Rectangle bounds = metrics.getStringBounds(curS, g).getBounds(); + g.setColor(Color.black); + g.drawString(curS, curItemBounds.x + curItemBounds.width, (int) curItemBounds.getCenterY() + bounds.height / 2 - 2); + } + } + + } + + private void paintSelected(Graphics2D g) { + List list = getPaintingModel().getPositions(); + for (int i = 0; i < list.size(); i++) { + Rectangle curItemBounds = getItemBounds(i); + if (lastMouseMove != null && curItemBounds.y <= lastMouseMove.y && curItemBounds.y + curItemBounds.height > lastMouseMove.y) { + g.setColor(TEXT_SELECTION_COLOR); + g.fillRect(0, curItemBounds.y, getWidth(), curItemBounds.height); + } + } + final Rectangle barBounds = getBarBounds(); + + g.setColor(BAR_SELECTION_COLOR); + g.fill(barBounds); + } + + 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); + } + + private int getIndexFromPosition(int y) { + for (int i = 0; i < getPaintingModel().getPositions().size() - 1; i++) { + 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() { + + @Override + public void mouseDragged(MouseEvent e) { + if (startPoint != null) { + int startIndex = getIndexFromPosition(startPoint.y); + int curIndex = getIndexFromPosition(e.getPoint().y); + tempModel.setPositions(startIndex, curIndex); + } + } + + @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); + } + } + + @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); + } + } + + @Override + public void mouseReleased(MouseEvent e) { + if (tempModel != null) { + model.setPositions(tempModel.getFirstPosition(), tempModel.getSecondPosition()); + tempModel = null; + startPoint = null; + } + } + + @Override + public void mouseEntered(MouseEvent e) { + } + + @Override + public void mouseExited(MouseEvent e) { + lastMouseMove = null; + repaint(); + } + }; + + public RangeSliderModel getModel() { + return model; + } + + 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(); + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/Util/src/com/sun/hotspot/igv/util/RangeSliderModel.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/Util/src/com/sun/hotspot/igv/util/RangeSliderModel.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,127 @@ +/* + * 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.util; + +import com.sun.hotspot.igv.data.ChangedEvent; +import com.sun.hotspot.igv.data.ChangedEventProvider; +import java.awt.Color; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public class RangeSliderModel implements ChangedEventProvider { + + // Warning: Update setData method if fields are added + private ChangedEvent changedEvent; + private List positions; + private int firstPosition; + private int secondPosition; + private List colors; + + public void setData(RangeSliderModel model) { + boolean changed = false; + changed |= (positions != model.positions); + positions = model.positions; + changed |= (firstPosition != model.firstPosition); + firstPosition = model.firstPosition; + changed |= (secondPosition != model.secondPosition); + secondPosition = model.secondPosition; + changed |= (colors != model.colors); + colors = model.colors; + if (changed) { + changedEvent.fire(); + } + } + + public RangeSliderModel(List positions) { + assert positions.size() > 0; + this.changedEvent = new ChangedEvent<>(this); + setPositions(positions); + } + + protected final void setPositions(List positions) { + this.positions = positions; + colors = new ArrayList<>(); + for (int i = 0; i < positions.size(); i++) { + colors.add(Color.black); + } + firstPosition = Math.min(firstPosition, positions.size() - 1); + secondPosition = Math.min(secondPosition, positions.size() - 1); + changedEvent.fire(); + } + + public void setColors(List colors) { + this.colors = colors; + changedEvent.fire(); + } + + public List getColors() { + return colors; + } + + public RangeSliderModel copy() { + RangeSliderModel newModel = new RangeSliderModel(positions); + newModel.setData(this); + return newModel; + } + + public List getPositions() { + return Collections.unmodifiableList(positions); + } + + public int getFirstPosition() { + return firstPosition; + } + + public int getSecondPosition() { + return secondPosition; + } + + public void setPositions(int fp, int sp) { + assert fp >= 0 && fp < positions.size(); + assert sp >= 0 && sp < positions.size(); + firstPosition = fp; + secondPosition = sp; + ensureOrder(); + changedEvent.fire(); + } + + private void ensureOrder() { + if (secondPosition < firstPosition) { + int tmp = secondPosition; + secondPosition = firstPosition; + firstPosition = tmp; + } + } + + @Override + public ChangedEvent getChangedEvent() { + return changedEvent; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/View/manifest.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/View/manifest.mf Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,6 @@ +Manifest-Version: 1.0 +OpenIDE-Module: com.sun.hotspot.igv.view +OpenIDE-Module-Layer: com/sun/hotspot/igv/view/layer.xml +OpenIDE-Module-Localizing-Bundle: com/sun/hotspot/igv/view/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff -r 6cb549627941 -r 015fb895586b visualizer/View/src/META-INF/services/com.oracle.graal.visualizer.editor.CompilationViewerFactory --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/View/src/META-INF/services/com.oracle.graal.visualizer.editor.CompilationViewerFactory Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,1 @@ +com.sun.hotspot.igv.view.scene.GraphCompilationViewerFactory diff -r 6cb549627941 -r 015fb895586b visualizer/View/src/com/sun/hotspot/igv/view/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/View/src/com/sun/hotspot/igv/view/Bundle.properties Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,1 @@ +OpenIDE-Module-Name=View \ No newline at end of file diff -r 6cb549627941 -r 015fb895586b visualizer/View/src/com/sun/hotspot/igv/view/actions/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/View/src/com/sun/hotspot/igv/view/actions/Bundle.properties Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,4 @@ +CTL_EditorAction=Open Editor Window +CTL_EnableBlockLayoutAction=Enable block layout +CTL_NodeFindAction=Find +CTL_ExportAction=Export current graph... diff -r 6cb549627941 -r 015fb895586b visualizer/View/src/com/sun/hotspot/igv/view/actions/ExpandPredecessorsAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/View/src/com/sun/hotspot/igv/view/actions/ExpandPredecessorsAction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,63 @@ +/* + * 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.oracle.graal.visualizer.editor.EditorTopComponent; +import org.openide.util.HelpCtx; +import org.openide.util.actions.CallableSystemAction; + +/** + * + * @author Thomas Wuerthinger + */ +public final class ExpandPredecessorsAction extends CallableSystemAction { + + @Override + public void performAction() { + EditorTopComponent editor = EditorTopComponent.getActive(); + if (editor != null) { + //editor.expandPredecessors(); + } + } + + @Override + public String getName() { + return "Expand Above"; + } + + @Override + protected void initialize() { + super.initialize(); + } + + @Override + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + @Override + protected boolean asynchronous() { + return false; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/View/src/com/sun/hotspot/igv/view/actions/ExpandSuccessorsAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/View/src/com/sun/hotspot/igv/view/actions/ExpandSuccessorsAction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,63 @@ +/* + * 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.oracle.graal.visualizer.editor.EditorTopComponent; +import org.openide.util.HelpCtx; +import org.openide.util.actions.CallableSystemAction; + +/** + * + * @author Thomas Wuerthinger + */ +public final class ExpandSuccessorsAction extends CallableSystemAction { + + @Override + public void performAction() { + EditorTopComponent editor = EditorTopComponent.getActive(); + if (editor != null) { + //editor.expandSuccessors(); + } + } + + @Override + public String getName() { + return "Expand Below"; + } + + @Override + protected void initialize() { + super.initialize(); + } + + @Override + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + @Override + protected boolean asynchronous() { + return false; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/View/src/com/sun/hotspot/igv/view/actions/ExtractAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/View/src/com/sun/hotspot/igv/view/actions/ExtractAction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,83 @@ +/* + * 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.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; + +/** + * + * @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(); + } + } + + public ExtractAction() { + putValue(Action.SHORT_DESCRIPTION, "Extract current set of selected nodes"); + putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.CTRL_MASK, false)); + } + + @Override + public String getName() { + return "Extract action"; + } + + @Override + protected void initialize() { + super.initialize(); + } + + @Override + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + @Override + protected boolean asynchronous() { + return false; + } + + @Override + protected String iconResource() { + return "com/sun/hotspot/igv/view/images/extract.gif"; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/View/src/com/sun/hotspot/igv/view/actions/HideAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/View/src/com/sun/hotspot/igv/view/actions/HideAction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,83 @@ +/* + * 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.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; + +/** + * + * @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(); + } + } + + public HideAction() { + putValue(Action.SHORT_DESCRIPTION, "Hide selected nodes"); + putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_H, Event.CTRL_MASK, false)); + } + + @Override + public String getName() { + return "Hide"; + } + + @Override + protected void initialize() { + super.initialize(); + } + + @Override + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + @Override + protected boolean asynchronous() { + return false; + } + + @Override + protected String iconResource() { + return "com/sun/hotspot/igv/view/images/hide.gif"; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/View/src/com/sun/hotspot/igv/view/actions/MouseOverAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/View/src/com/sun/hotspot/igv/view/actions/MouseOverAction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,59 @@ +/* + * 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 org.netbeans.api.visual.action.HoverProvider; +import org.netbeans.api.visual.action.WidgetAction; +import org.netbeans.api.visual.action.WidgetAction.State; +import org.netbeans.api.visual.widget.Widget; + +/** + * + * @author Thomas Wuerthinger + */ +public class MouseOverAction extends WidgetAction.Adapter { + + private long eventID = Integer.MIN_VALUE; + private HoverProvider provider; + + public MouseOverAction(HoverProvider provider) { + this.provider = provider; + } + + @Override + public State mouseMoved(Widget widget, WidgetMouseEvent event) { + long id = event.getEventID(); + if (id != eventID) { + eventID = id; + provider.widgetHovered(widget); + } + return State.REJECTED; + } + + @Override + public State mouseExited(Widget widget, WidgetMouseEvent event) { + provider.widgetHovered(null); + return State.REJECTED; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/View/src/com/sun/hotspot/igv/view/actions/PredSuccAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/View/src/com/sun/hotspot/igv/view/actions/PredSuccAction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,57 @@ +/* + * 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 PredSuccAction extends AbstractAction { + + private boolean state; + public static final String STATE = "state"; + + public PredSuccAction() { + state = true; + putValue(AbstractAction.SMALL_ICON, new ImageIcon(ImageUtilities.loadImage(iconResource()))); + putValue(STATE, true); + putValue(Action.SHORT_DESCRIPTION, "Show neighboring nodes of fully visible nodes semi-transparent"); + } + + @Override + public void actionPerformed(ActionEvent ev) { + this.state = !state; + this.putValue(STATE, state); + } + + protected String iconResource() { + return "com/sun/hotspot/igv/view/images/predsucc.gif"; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/View/src/com/sun/hotspot/igv/view/images/blocks.gif Binary file visualizer/View/src/com/sun/hotspot/igv/view/images/blocks.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/View/src/com/sun/hotspot/igv/view/images/expand.gif Binary file visualizer/View/src/com/sun/hotspot/igv/view/images/expand.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/View/src/com/sun/hotspot/igv/view/images/extract.gif Binary file visualizer/View/src/com/sun/hotspot/igv/view/images/extract.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/View/src/com/sun/hotspot/igv/view/images/hide.gif Binary file visualizer/View/src/com/sun/hotspot/igv/view/images/hide.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/View/src/com/sun/hotspot/igv/view/images/overview.png Binary file visualizer/View/src/com/sun/hotspot/igv/view/images/overview.png has changed diff -r 6cb549627941 -r 015fb895586b visualizer/View/src/com/sun/hotspot/igv/view/images/pan_mode.png Binary file visualizer/View/src/com/sun/hotspot/igv/view/images/pan_mode.png has changed diff -r 6cb549627941 -r 015fb895586b visualizer/View/src/com/sun/hotspot/igv/view/images/predsucc.gif Binary file visualizer/View/src/com/sun/hotspot/igv/view/images/predsucc.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/View/src/com/sun/hotspot/igv/view/images/selection_mode.png Binary file visualizer/View/src/com/sun/hotspot/igv/view/images/selection_mode.png has changed diff -r 6cb549627941 -r 015fb895586b visualizer/View/src/com/sun/hotspot/igv/view/images/zoom_in.png Binary file visualizer/View/src/com/sun/hotspot/igv/view/images/zoom_in.png has changed diff -r 6cb549627941 -r 015fb895586b visualizer/View/src/com/sun/hotspot/igv/view/images/zoom_out.png Binary file visualizer/View/src/com/sun/hotspot/igv/view/images/zoom_out.png has changed diff -r 6cb549627941 -r 015fb895586b visualizer/View/src/com/sun/hotspot/igv/view/layer.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/View/src/com/sun/hotspot/igv/view/layer.xml Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff -r 6cb549627941 -r 015fb895586b visualizer/View/src/com/sun/hotspot/igv/view/scene/CustomizablePanWidgetAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/View/src/com/sun/hotspot/igv/view/scene/CustomizablePanWidgetAction.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,146 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package com.sun.hotspot.igv.view.scene; + +import java.awt.Container; +import java.awt.Point; +import java.awt.Rectangle; +import javax.swing.JComponent; +import javax.swing.JScrollPane; +import javax.swing.SwingUtilities; +import org.netbeans.api.visual.action.WidgetAction; +import org.netbeans.api.visual.action.WidgetAction.State; +import org.netbeans.api.visual.action.WidgetAction.WidgetMouseEvent; +import org.netbeans.api.visual.widget.Scene; +import org.netbeans.api.visual.widget.Widget; + +/** + * @author David Kaspar + * @author Peter Hofer + */ +public class CustomizablePanWidgetAction extends WidgetAction.LockedAdapter { + private boolean enabled = true; + + private Scene scene; + private JScrollPane scrollPane; + private Point lastLocation; + + private final int modifiersExMask; + private final int modifiersEx; + + public CustomizablePanWidgetAction(int modifiersExMask, int modifiersEx) { + this.modifiersExMask = modifiersExMask; + this.modifiersEx = modifiersEx; + } + + @Override + protected boolean isLocked() { + return scrollPane != null; + } + + public void setEnabled(boolean enabled) { + if (this.enabled != enabled) { + if (isLocked()) + throw new IllegalStateException(); + + this.enabled = enabled; + } + } + + @Override + public State mousePressed (Widget widget, WidgetMouseEvent event) { + if (isLocked ()) + return State.createLocked (widget, this); + if (enabled && (event.getModifiersEx() & modifiersExMask) == modifiersEx) { + scene = widget.getScene (); + scrollPane = findScrollPane (scene.getView ()); + if (scrollPane != null) { + lastLocation = scene.convertSceneToView (widget.convertLocalToScene (event.getPoint ())); + SwingUtilities.convertPointToScreen (lastLocation, scene.getView ()); + return State.createLocked (widget, this); + } + } + return State.REJECTED; + } + + private JScrollPane findScrollPane (JComponent component) { + for (;;) { + if (component == null) + return null; + if (component instanceof JScrollPane) + return ((JScrollPane) component); + Container parent = component.getParent (); + if (! (parent instanceof JComponent)) + return null; + component = (JComponent) parent; + } + } + + @Override + public State mouseReleased (Widget widget, WidgetMouseEvent event) { + boolean state = pan (widget, event.getPoint ()); + if (state) + scrollPane = null; + return state ? State.createLocked (widget, this) : State.REJECTED; + } + + @Override + public State mouseDragged (Widget widget, WidgetMouseEvent event) { + return pan (widget, event.getPoint ()) ? State.createLocked (widget, this) : State.REJECTED; + } + + private boolean pan (Widget widget, Point newLocation) { + if (scrollPane == null || scene != widget.getScene ()) + return false; + newLocation = scene.convertSceneToView (widget.convertLocalToScene (newLocation)); + SwingUtilities.convertPointToScreen (newLocation, scene.getView ()); + JComponent view = scene.getView (); + Rectangle rectangle = view.getVisibleRect (); + rectangle.x += lastLocation.x - newLocation.x; + rectangle.y += lastLocation.y - newLocation.y; + view.scrollRectToVisible (rectangle); + lastLocation = newLocation; + return true; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/View/src/com/sun/hotspot/igv/view/scene/DiagramScene.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/View/src/com/sun/hotspot/igv/view/scene/DiagramScene.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,964 @@ +/* + * 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.DiagramViewModel; +import com.oracle.graal.visualizer.sharedactions.ExportSVGCookie; +import com.oracle.graal.visualizer.sharedactions.ZoomCookie; +import com.sun.hotspot.igv.data.ChangedListener; +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.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; + +public class DiagramScene extends ObjectScene implements ExportSVGCookie, ZoomCookie { + + private CustomizablePanWidgetAction panAction; + private WidgetAction hoverAction; + private WidgetAction selectAction; + private Lookup lookup; + private InstanceContent content; + private Action[] actions; + private LayerWidget connectionLayer; + private JScrollPane scrollPane; + private LayerWidget mainLayer; + private LayerWidget blockLayer; + private Widget topLeft; + private Widget bottomRight; + private DiagramViewModel model; + private WidgetAction zoomAction; + private boolean rebuilding; + /** + * The alpha level of partially visible figures. + */ + public static final float ALPHA = 0.4f; + /** + * The offset of the graph to the border of the window showing it. + */ + public static final int BORDER_SIZE = 20; + public static final int UNDOREDO_LIMIT = 100; + public static final int SCROLL_UNIT_INCREMENT = 80; + public static final int SCROLL_BLOCK_INCREMENT = 400; + public static final float ZOOM_MAX_FACTOR = 3.0f; + public static final float ZOOM_MIN_FACTOR = 0.0f;//0.15f; + public static final float ZOOM_INCREMENT = 1.5f; + public static final int SLOT_OFFSET = 6; + public static final int ANIMATION_LIMIT = 40; + private PopupMenuProvider popupMenuProvider = new PopupMenuProvider() { + + @Override + public JPopupMenu getPopupMenu(Widget widget, Point localLocation) { + return DiagramScene.this.createPopupMenu(); + } + }; + private RectangularSelectDecorator rectangularSelectDecorator = new RectangularSelectDecorator() { + + @Override + public Widget createSelectionWidget() { + Widget widget = new Widget(DiagramScene.this); + widget.setBorder(BorderFactory.createLineBorder(Color.black, 2)); + widget.setForeground(Color.red); + return widget; + } + }; + + @SuppressWarnings("unchecked") + public T getWidget(Object o) { + Widget w = this.findWidget(o); + return (T) w; + } + + @SuppressWarnings("unchecked") + public T getWidget(Object o, Class klass) { + Widget w = this.findWidget(o); + return (T) w; + } + + public void zoomOut() { + double zoom = getZoomFactor(); + Point viewPosition = getScrollPane().getViewport().getViewPosition(); + double newZoom = zoom / DiagramScene.ZOOM_INCREMENT; + if (newZoom > DiagramScene.ZOOM_MIN_FACTOR) { + setZoomFactor(newZoom); + validate(); + getScrollPane().getViewport().setViewPosition(new Point((int) (viewPosition.x / DiagramScene.ZOOM_INCREMENT), (int) (viewPosition.y / DiagramScene.ZOOM_INCREMENT))); + } + } + + public void zoomIn() { + + double zoom = getZoomFactor(); + Point viewPosition = getScrollPane().getViewport().getViewPosition(); + double newZoom = zoom * DiagramScene.ZOOM_INCREMENT; + if (newZoom < DiagramScene.ZOOM_MAX_FACTOR) { + setZoomFactor(newZoom); + validate(); + getScrollPane().getViewport().setViewPosition(new Point((int) (viewPosition.x * DiagramScene.ZOOM_INCREMENT), (int) (viewPosition.y * DiagramScene.ZOOM_INCREMENT))); + } + } + + private void centerFigures(Collection
list) { + gotoFigures(list); + } + + private RectangularSelectProvider rectangularSelectProvider = new RectangularSelectProvider() { + + @Override + public void performSelection(Rectangle rectangle) { + if (rectangle.width < 0) { + rectangle.x += rectangle.width; + rectangle.width *= -1; + } + + if (rectangle.height < 0) { + rectangle.y += rectangle.height; + rectangle.height *= -1; + } + + Set selectedObjects = new HashSet<>(); + for (Figure f : getModel().getDiagramToView().getFigures()) { + FigureWidget w = getWidget(f); + if (w != null) { + Rectangle r = new Rectangle(w.getBounds()); + r.setLocation(w.getLocation()); + + if (r.intersects(rectangle)) { + selectedObjects.add(f); + } + + for (Slot s : f.getSlots()) { + SlotWidget sw = getWidget(s); + Rectangle r2 = new Rectangle(sw.getBounds()); + r2.setLocation(sw.convertLocalToScene(new Point(0, 0))); + + if (r2.intersects(rectangle)) { + selectedObjects.add(s); + } + } + } else { + assert false : "w should not be null here!"; + } + } + + setSelectedObjects(selectedObjects); + } + }; + private MouseWheelListener mouseWheelListener = new MouseWheelListener() { + + @Override + public void mouseWheelMoved(MouseWheelEvent e) { + if (e.isControlDown()) { + DiagramScene.this.relayoutWithoutLayout(null); + } + } + }; + + public Point getScrollPosition() { + return getScrollPane().getViewport().getViewPosition(); + } + + public void setScrollPosition(Point p) { + getScrollPane().getViewport().setViewPosition(p); + } + + private JScrollPane createScrollPane() { + JComponent comp = this.createView(); + comp.setDoubleBuffered(true); + comp.setBackground(Color.WHITE); + comp.setOpaque(true); + this.setBackground(Color.WHITE); + this.setOpaque(true); + JScrollPane result = new JScrollPane(comp); + result.setBackground(Color.WHITE); + result.getVerticalScrollBar().setUnitIncrement(SCROLL_UNIT_INCREMENT); + result.getVerticalScrollBar().setBlockIncrement(SCROLL_BLOCK_INCREMENT); + result.getHorizontalScrollBar().setUnitIncrement(SCROLL_UNIT_INCREMENT); + result.getHorizontalScrollBar().setBlockIncrement(SCROLL_BLOCK_INCREMENT); + return result; + } + private ObjectSceneListener selectionChangedListener = new ObjectSceneListener() { + + @Override + public void objectAdded(ObjectSceneEvent arg0, Object arg1) { + } + + @Override + public void objectRemoved(ObjectSceneEvent arg0, Object arg1) { + } + + @Override + public void objectStateChanged(ObjectSceneEvent e, Object o, ObjectState oldState, ObjectState newState) { + } + + @Override + public void selectionChanged(ObjectSceneEvent e, Set oldSet, Set newSet) { + DiagramScene scene = (DiagramScene) e.getObjectScene(); + if (scene.isRebuilding()) { + return; + } + + content.set(newSet, null); + + Set nodeSelection = new HashSet<>(); + for (Object o : newSet) { + if (o instanceof Properties.Provider) { + final Properties.Provider provider = (Properties.Provider) o; + AbstractNode node = new AbstractNode(Children.LEAF) { + + @Override + protected Sheet createSheet() { + Sheet s = super.createSheet(); + PropertiesSheet.initializeSheet(provider.getProperties(), s); + return s; + } + }; + node.setDisplayName(provider.getProperties().get("name")); + content.add(node); + } + + + if (o instanceof Figure) { + nodeSelection.addAll(((Figure) o).getSource().getSourceNodesAsSet()); + } else if (o instanceof Slot) { + nodeSelection.addAll(((Slot) o).getSource().getSourceNodesAsSet()); + } + } + getModel().setSelectedNodes(nodeSelection); + } + + @Override + public void highlightingChanged(ObjectSceneEvent e, Set oldSet, Set newSet) { + Set nodeHighlighting = new HashSet<>(); + for (Object o : newSet) { + if (o instanceof Figure) { + nodeHighlighting.addAll(((Figure) o).getSource().getSourceNodesAsSet()); + } else if (o instanceof Slot) { + nodeHighlighting.addAll(((Slot) o).getSource().getSourceNodesAsSet()); + } + } +// boolean b = highlightedCoordinatorListener.isEnabled(); +// highlightedCoordinatorListener.setEnabled(false); +// SelectionCoordinator.getInstance().setHighlightedObjects(nodeHighlighting); +// highlightedCoordinatorListener.setEnabled(b); + validate(); + } + + @Override + public void hoverChanged(ObjectSceneEvent e, Object oldObject, Object newObject) { + Set newHighlightedObjects = new HashSet<>(DiagramScene.this.getHighlightedObjects()); + if (oldObject != null) { + newHighlightedObjects.remove(oldObject); + } + if (newObject != null) { + newHighlightedObjects.add(newObject); + } + DiagramScene.this.setHighlightedObjects(newHighlightedObjects); + } + + @Override + public void focusChanged(ObjectSceneEvent arg0, Object arg1, Object arg2) { + } + }; + + public void setActions(Action[] actions) { + this.actions = actions; + } + + + + public DiagramScene(DiagramViewModel model) { + + this.model = model; + content = new InstanceContent(); + lookup = new AbstractLookup(content); + content.add(this); + + this.setCheckClipping(true); + + scrollPane = createScrollPane(); + + hoverAction = createObjectHoverAction(); + + // This panAction handles the event only when the left mouse button is + // pressed without any modifier keys, otherwise it will not consume it + // and the selection action (below) will handle the event + panAction = new CustomizablePanWidgetAction(~0, MouseEvent.BUTTON1_DOWN_MASK); + this.getActions().addAction(panAction); + + selectAction = createSelectAction(); + this.getActions().addAction(selectAction); + + blockLayer = new LayerWidget(this); + this.addChild(blockLayer); + + mainLayer = new LayerWidget(this); + this.addChild(mainLayer); + + topLeft = new Widget(this); + topLeft.setPreferredLocation(new Point(-BORDER_SIZE, -BORDER_SIZE)); + this.addChild(topLeft); + + bottomRight = new Widget(this); + bottomRight.setPreferredLocation(new Point(-BORDER_SIZE, -BORDER_SIZE)); + this.addChild(bottomRight); + + connectionLayer = new LayerWidget(this); + this.addChild(connectionLayer); + + LayerWidget selectionLayer = new LayerWidget(this); + this.addChild(selectionLayer); + + this.setLayout(LayoutFactory.createAbsoluteLayout()); + + this.getInputBindings().setZoomActionModifiers(KeyEvent.CTRL_MASK); + zoomAction = ActionFactory.createMouseCenteredZoomAction(1.2); + this.getActions().addAction(zoomAction); + this.getView().addMouseWheelListener(mouseWheelListener); + this.getActions().addAction(ActionFactory.createPopupMenuAction(popupMenuProvider)); + + this.getActions().addAction(ActionFactory.createWheelPanAction()); + + LayerWidget selectLayer = new LayerWidget(this); + this.addChild(selectLayer); + this.getActions().addAction(ActionFactory.createRectangularSelectAction(rectangularSelectDecorator, selectLayer, rectangularSelectProvider)); + + this.addObjectSceneListener(selectionChangedListener, ObjectSceneEventType.OBJECT_SELECTION_CHANGED, ObjectSceneEventType.OBJECT_HIGHLIGHTING_CHANGED, ObjectSceneEventType.OBJECT_HOVER_CHANGED); + + update(); + } + + public DiagramViewModel getModel() { + return model; + } + + public JScrollPane getScrollPane() { + return scrollPane; + } + + Component getComponent() { + return scrollPane; + } + + public boolean isAllVisible() { + return getModel().getHiddenNodes().isEmpty(); + } + + public Action createGotoAction(final Figure f) { + final DiagramScene diagramScene = this; + Action a = new AbstractAction() { + + @Override + public void actionPerformed(ActionEvent e) { + diagramScene.gotoFigure(f); + } + }; + + a.setEnabled(true); + a.putValue(Action.SMALL_ICON, new ColorIcon(f.getColor())); + String name = f.getLines()[0]; + + name += " ("; + + if (!this.getWidget(f, FigureWidget.class).isVisible()) { + name += "hidden"; + } + name += ")"; + a.putValue(Action.NAME, name); + return a; + } + + private void update() { + mainLayer.removeChildren(); + blockLayer.removeChildren(); + + rebuilding = true; + + Collection objects = new ArrayList<>(this.getObjects()); + for (Object o : objects) { + this.removeObject(o); + } + + Diagram d = getModel().getDiagramToView(); + + for (Figure f : d.getFigures()) { + FigureWidget w = new FigureWidget(f, hoverAction, selectAction, this, mainLayer); + w.getActions().addAction(ActionFactory.createPopupMenuAction(w)); + w.getActions().addAction(selectAction); + w.getActions().addAction(hoverAction); + w.setVisible(false); + + this.addObject(f, w); + + for (InputSlot s : f.getInputSlots()) { + SlotWidget sw = new InputSlotWidget(s, this, w, w); + addObject(s, sw); + sw.getActions().addAction(new DoubleClickAction(sw)); + sw.getActions().addAction(hoverAction); + sw.getActions().addAction(selectAction); + } + + for (OutputSlot s : f.getOutputSlots()) { + SlotWidget sw = new OutputSlotWidget(s, this, w, w); + addObject(s, sw); + sw.getActions().addAction(new DoubleClickAction(sw)); + sw.getActions().addAction(hoverAction); + sw.getActions().addAction(selectAction); + } + } + + rebuilding = false; + this.smallUpdate(true); + } + + public boolean isRebuilding() { + return rebuilding; + } + + private void smallUpdate(boolean relayout) { + + this.updateHiddenNodes(model.getHiddenNodes(), relayout); + this.validate(); + } + + private boolean isVisible(Connection c) { + FigureWidget w1 = getWidget(c.getInputSlot().getFigure()); + FigureWidget w2 = getWidget(c.getOutputSlot().getFigure()); + + if (w1.isVisible() && w2.isVisible()) { + return true; + } + + return false; + } + + private void relayout(Set oldVisibleWidgets) { + System.out.println("relayout called with old visible widgets: " + oldVisibleWidgets); + + Diagram diagram = getModel().getDiagramToView(); + + HashSet
figures = new HashSet<>(); + + for (Figure f : diagram.getFigures()) { + FigureWidget w = getWidget(f); + if (w.isVisible()) { + figures.add(f); + } + } + + HashSet edges = new HashSet<>(); + + for (Connection c : diagram.getConnections()) { + if (isVisible(c)) { + edges.add(c); + } + } + + HierarchicalLayoutManager manager = new HierarchicalLayoutManager(HierarchicalLayoutManager.Combine.SAME_OUTPUTS); + manager.setMaxLayerLength(10); + manager.doLayout(new LayoutGraph(edges, figures)); + relayoutWithoutLayout(oldVisibleWidgets); + } + private Set> lineCache = new HashSet<>(); + + private void relayoutWithoutLayout(Set oldVisibleWidgets) { + + System.out.println("relayout without layout with visible widgets: " + oldVisibleWidgets); + + Diagram diagram = getModel().getDiagramToView(); + + int maxX = -BORDER_SIZE; + int maxY = -BORDER_SIZE; + for (Figure f : diagram.getFigures()) { + FigureWidget w = getWidget(f); + if (w.isVisible()) { + Point p = f.getPosition(); + Dimension d = f.getSize(); + maxX = Math.max(maxX, p.x + d.width); + maxY = Math.max(maxY, p.y + d.height); + } + } + + for (Connection c : diagram.getConnections()) { + List points = c.getControlPoints(); + FigureWidget w1 = getWidget((Figure) c.getTo().getVertex()); + FigureWidget w2 = getWidget((Figure) c.getFrom().getVertex()); + if (w1.isVisible() && w2.isVisible()) { + for (Point p : points) { + if (p != null) { + maxX = Math.max(maxX, p.x); + maxY = Math.max(maxY, p.y); + } + } + } + } + + bottomRight.setPreferredLocation(new Point(maxX + BORDER_SIZE, maxY + BORDER_SIZE)); + int offx = 0; + int offy = 0; + int curWidth = maxX + 2 * BORDER_SIZE; + int curHeight = maxY + 2 * BORDER_SIZE; + + Rectangle bounds = this.getScrollPane().getBounds(); + bounds.width /= getZoomFactor(); + bounds.height /= getZoomFactor(); + if (curWidth < bounds.width) { + offx = (bounds.width - curWidth) / 2; + } + + if (curHeight < bounds.height) { + offy = (bounds.height - curHeight) / 2; + } + + final int offx2 = offx; + final int offy2 = offy; + + SceneAnimator animator = this.getSceneAnimator(); + connectionLayer.removeChildren(); + int visibleFigureCount = 0; + for (Figure f : diagram.getFigures()) { + if (getWidget(f, FigureWidget.class).isVisible()) { + visibleFigureCount++; + } + } + + + Set> lastLineCache = lineCache; + lineCache = new HashSet<>(); + for (Figure f : diagram.getFigures()) { + for (OutputSlot s : f.getOutputSlots()) { + SceneAnimator anim = animator; + if (visibleFigureCount > ANIMATION_LIMIT || oldVisibleWidgets == null) { + anim = null; + } + processOutputSlot(lastLineCache, s, s.getConnections(), 0, null, null, offx2, offy2, anim); + } + } + + for (Figure f : diagram.getFigures()) { + FigureWidget w = getWidget(f); + if (w.isVisible()) { + Point p = f.getPosition(); + Point p2 = new Point(p.x + offx2, p.y + offy2); + if ((visibleFigureCount <= ANIMATION_LIMIT && oldVisibleWidgets != null && oldVisibleWidgets.contains(w))) { + animator.animatePreferredLocation(w, p2); + } else { + w.setPreferredLocation(p2); + animator.animatePreferredLocation(w, p2); + } + } + } + + this.validate(); + } + private final Point specialNullPoint = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE); + + private void processOutputSlot(Set> lastLineCache, OutputSlot s, List connections, int controlPointIndex, Point lastPoint, LineWidget predecessor, int offx, int offy, SceneAnimator animator) { + Map> pointMap = new HashMap<>(connections.size()); + + for (Connection c : connections) { + + if (!isVisible(c)) { + continue; + } + + List controlPoints = c.getControlPoints(); + if (controlPointIndex >= controlPoints.size()) { + continue; + } + + Point cur = controlPoints.get(controlPointIndex); + if (cur == null) { + cur = specialNullPoint; + } else if (controlPointIndex == 0 && !s.shouldShowName()) { + cur = new Point(cur.x, cur.y - SLOT_OFFSET); + } else if (controlPointIndex == controlPoints.size() - 1 && !c.getInputSlot().shouldShowName()) { + cur = new Point(cur.x, cur.y + SLOT_OFFSET); + } + + if (pointMap.containsKey(cur)) { + pointMap.get(cur).add(c); + } else { + List newList = new ArrayList<>(2); + newList.add(c); + pointMap.put(cur, newList); + } + + } + + for (Point p : pointMap.keySet()) { + List connectionList = pointMap.get(p); + + boolean isBold = false; + boolean isDashed = true; + + for (Connection c : connectionList) { + + if (c.getStyle() == Connection.ConnectionStyle.BOLD) { + isBold = true; + } + + if (c.getStyle() != Connection.ConnectionStyle.DASHED) { + isDashed = false; + } + } + + LineWidget newPredecessor = predecessor; + if (p == specialNullPoint) { + } else if (lastPoint == specialNullPoint) { + } else if (lastPoint != null) { + Point p1 = new Point(lastPoint.x + offx, lastPoint.y + offy); + Point p2 = new Point(p.x + offx, p.y + offy); + + Pair curPair = new Pair<>(p1, p2); + SceneAnimator curAnimator = animator; + if (lastLineCache.contains(curPair)) { + curAnimator = null; + } + LineWidget w = new LineWidget(this, s, connectionList, p1, p2, predecessor, curAnimator, isBold, isDashed); + lineCache.add(curPair); + + newPredecessor = w; + connectionLayer.addChild(w); + w.getActions().addAction(hoverAction); + } + + processOutputSlot(lastLineCache, s, connectionList, controlPointIndex + 1, p, newPredecessor, offx, offy, animator); + } + } + + @Override + public Lookup getLookup() { + return lookup; + } + + private void gotoFigures(final Collection
figures) { + Rectangle overall = null; + getModel().showFigures(figures); + for (Figure f : figures) { + + FigureWidget fw = getWidget(f); + if (fw != null) { + Rectangle r = fw.getBounds(); + Point p = fw.getLocation(); + Rectangle r2 = new Rectangle(p.x, p.y, r.width, r.height); + + if (overall == null) { + overall = r2; + } else { + overall = overall.union(r2); + } + } + } + if (overall != null) { + centerRectangle(overall); + } + } + + private Set idSetToObjectSet(Set ids) { + + Set result = new HashSet<>(); + for (Figure f : getModel().getDiagramToView().getFigures()) { + if (DiagramScene.doesIntersect(f.getSource().getSourceNodesAsSet(), ids)) { + result.add(f); + } + + for (Slot s : f.getSlots()) { + if (DiagramScene.doesIntersect(s.getSource().getSourceNodesAsSet(), ids)) { + result.add(s); + } + } + } + return result; + } + + public void gotoSelection(Set ids) { + + Rectangle overall = null; + Set hiddenNodes = new HashSet<>(this.getModel().getHiddenNodes()); + hiddenNodes.removeAll(ids); + this.getModel().showNot(hiddenNodes); + + Set objects = idSetToObjectSet(ids); + for (Object o : objects) { + + Widget w = getWidget(o); + if (w != null) { + Rectangle r = w.getBounds(); + Point p = w.convertLocalToScene(new Point(0, 0)); + + Rectangle r2 = new Rectangle(p.x, p.y, r.width, r.height); + + if (overall == null) { + overall = r2; + } else { + overall = overall.union(r2); + } + } + } + if (overall != null) { + centerRectangle(overall); + } + + setSelectedObjects(objects); + } + + private Point calcCenter(Rectangle r) { + + Point center = new Point((int) r.getCenterX(), (int) r.getCenterY()); + center.x -= getScrollPane().getViewport().getViewRect().width / 2; + center.y -= getScrollPane().getViewport().getViewRect().height / 2; + + // Ensure to be within area + center.x = Math.max(0, center.x); + center.x = Math.min(getScrollPane().getViewport().getViewSize().width - getScrollPane().getViewport().getViewRect().width, center.x); + center.y = Math.max(0, center.y); + center.y = Math.min(getScrollPane().getViewport().getViewSize().height - getScrollPane().getViewport().getViewRect().height, center.y); + + return center; + } + + private void centerRectangle(Rectangle r) { + + if (getScrollPane().getViewport().getViewRect().width == 0 || getScrollPane().getViewport().getViewRect().height == 0) { + return; + } + + Rectangle r2 = new Rectangle(r.x, r.y, r.width, r.height); + r2 = convertSceneToView(r2); + + double factorX = (double) r2.width / (double) getScrollPane().getViewport().getViewRect().width; + double factorY = (double) r2.height / (double) getScrollPane().getViewport().getViewRect().height; + double factor = Math.max(factorX, factorY); + if (factor >= 1.0) { + Point p = getScrollPane().getViewport().getViewPosition(); + setZoomFactor(getZoomFactor() / factor); + r2.x /= factor; + r2.y /= factor; + r2.width /= factor; + r2.height /= factor; + getScrollPane().getViewport().setViewPosition(calcCenter(r2)); + } else { + getScrollPane().getViewport().setViewPosition(calcCenter(r2)); + } + } + + void setSelection(Collection
list) { + super.setSelectedObjects(new HashSet<>(list)); + centerFigures(list); + } + + private boolean isVisible(Figure f) { + for (Integer n : f.getSource().getSourceNodesAsSet()) { + if (getModel().getHiddenNodes().contains(n)) { + return false; + } + } + return true; + } + + public static boolean doesIntersect(Set s1, Set s2) { + if (s1.size() > s2.size()) { + Set tmp = s1; + s1 = s2; + s2 = tmp; + } + + for (Object o : s1) { + if (s2.contains(o)) { + return true; + } + } + + return false; + } + + private void updateHiddenNodes(Set newHiddenNodes, boolean doRelayout) { + + System.out.println("newHiddenNodes: " + newHiddenNodes); + + Diagram diagram = getModel().getDiagramToView(); + assert diagram != null; + + Set oldVisibleWidgets = new HashSet<>(); + + for (Figure f : diagram.getFigures()) { + FigureWidget w = getWidget(f); + if (w != null && w.isVisible()) { + oldVisibleWidgets.add(w); + } + } + + for (Figure f : diagram.getFigures()) { + boolean hiddenAfter = doesIntersect(f.getSource().getSourceNodesAsSet(), newHiddenNodes); + + FigureWidget w = getWidget(f); + w.setBoundary(false); + if (!hiddenAfter) { + // Figure is shown + w.setVisible(true); + } else { + // Figure is hidden + w.setVisible(false); + } + } + + if (getModel().getShowNodeHull()) { + List boundaries = new ArrayList<>(); + for (Figure f : diagram.getFigures()) { + FigureWidget w = getWidget(f); + if (!w.isVisible()) { + Set
set = new HashSet<>(f.getPredecessorSet()); + set.addAll(f.getSuccessorSet()); + + boolean b = false; + for (Figure neighbor : set) { + FigureWidget neighborWidget = getWidget(neighbor); + if (neighborWidget.isVisible()) { + b = true; + break; + } + } + + if (b) { + w.setBoundary(true); + boundaries.add(w); + } + } + } + + for (FigureWidget w : boundaries) { + if (w.isBoundary()) { + w.setVisible(true); + } + } + } + + if (doRelayout) { + relayout(oldVisibleWidgets); + } + this.validate(); + } + + private void showFigure(Figure f) { + HashSet newHiddenNodes = new HashSet<>(getModel().getHiddenNodes()); + newHiddenNodes.removeAll(f.getSource().getSourceNodesAsSet()); + updateHiddenNodes(newHiddenNodes, true); + } + + public void show(final Figure f) { + showFigure(f); + } + + public void setSelectedObjects(Object... args) { + Set set = new HashSet<>(); + for (Object o : args) { + set.add(o); + } + super.setSelectedObjects(set); + } + + private void centerWidget(Widget w) { + Rectangle r = w.getBounds(); + Point p = w.getLocation(); + centerRectangle(new Rectangle(p.x, p.y, r.width, r.height)); + } + + public void gotoFigure(final Figure f) { + if (!isVisible(f)) { + showFigure(f); + } + + FigureWidget fw = getWidget(f); + if (fw != null) { + setSelection(new HashSet<>(Arrays.asList(f))); + } + } + + public JPopupMenu createPopupMenu() { + JPopupMenu menu = new JPopupMenu(); + for (Action a : actions) { + if (a == null) { + menu.addSeparator(); + } else { + menu.add(a); + } + } + return menu; + } + + private final ChangedListener fullChange = new ChangedListener() { + + @Override + public void changed(DiagramViewModel source) { + assert source == model : "Receive only changed event from current model!"; + assert source != null; + update(); + } + }; + private final ChangedListener hiddenNodesChange = new ChangedListener() { + + @Override + public void changed(DiagramViewModel source) { + assert source == model : "Receive only changed event from current model!"; + assert source != null; + smallUpdate(true); + } + }; + private final ChangedListener selectionChange = new ChangedListener() { + + @Override + public void changed(DiagramViewModel source) { + assert source == model : "Receive only changed event from current model!"; + assert source != null; + smallUpdate(false); + } + }; + + @Override + public void showAll() { + // TODO(tw): Implement. + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/View/src/com/sun/hotspot/igv/view/scene/GraphCompilationViewer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/View/src/com/sun/hotspot/igv/view/scene/GraphCompilationViewer.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,82 @@ +/* + * 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.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 PredSuccAction predSuccAction; + + GraphCompilationViewer(DiagramViewModel model) { + + scene = new DiagramScene(model); + + Action[] actions = new Action[]{ + }; + + scene.setActions(actions); + } + + @Override + public Lookup getLookup() { + return scene.getLookup(); + } + + @Override + public Component getComponent() { + return scene.getComponent(); + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (evt.getSource() == this.predSuccAction) { + boolean b = (Boolean) predSuccAction.getValue(PredSuccAction.STATE); + scene.getModel().setShowNodeHull(b); + } else { + assert false : "Unknown event source"; + } + } + +} diff -r 6cb549627941 -r 015fb895586b visualizer/View/src/com/sun/hotspot/igv/view/scene/GraphCompilationViewerFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/View/src/com/sun/hotspot/igv/view/scene/GraphCompilationViewerFactory.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +package com.sun.hotspot.igv.view.scene; + +import com.oracle.graal.visualizer.editor.CompilationViewer; +import com.oracle.graal.visualizer.editor.CompilationViewerFactory; +import com.oracle.graal.visualizer.editor.DiagramViewModel; +import com.sun.hotspot.igv.data.InputGraph; +import com.sun.hotspot.igv.filter.FilterChain; +import com.sun.hotspot.igv.filter.FilterChainProvider; +import org.openide.util.Lookup; + +public class GraphCompilationViewerFactory implements CompilationViewerFactory{ + + @Override + public CompilationViewer createViewer(InputGraph firstGraph, InputGraph secondGraph) { + FilterChain filterChain; + FilterChain sequence; + FilterChainProvider provider = Lookup.getDefault().lookup(FilterChainProvider.class); + if (provider == null) { + filterChain = new FilterChain(); + sequence = new FilterChain(); + } else { + filterChain = provider.getFilterChain(); + sequence = provider.getSequence(); + } + DiagramViewModel model = new DiagramViewModel(firstGraph, secondGraph, firstGraph.getGroup(), filterChain, filterChain); + return new GraphCompilationViewer(model); + } + + @Override + public String getName() { + return "Graph"; + } + +} diff -r 6cb549627941 -r 015fb895586b visualizer/View/src/com/sun/hotspot/igv/view/widgets/FigureWidget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/View/src/com/sun/hotspot/igv/view/widgets/FigureWidget.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,363 @@ +/* + * 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.widgets; + +import com.sun.hotspot.igv.data.Properties; +import com.sun.hotspot.igv.graph.Figure; +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.scene.DiagramScene; +import java.awt.*; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Set; +import javax.swing.Action; +import javax.swing.BorderFactory; +import javax.swing.JMenu; +import javax.swing.JPopupMenu; +import javax.swing.event.MenuEvent; +import javax.swing.event.MenuListener; +import org.netbeans.api.visual.action.PopupMenuProvider; +import org.netbeans.api.visual.action.WidgetAction; +import org.netbeans.api.visual.layout.LayoutFactory; +import org.netbeans.api.visual.model.ObjectState; +import org.netbeans.api.visual.widget.LabelWidget; +import org.netbeans.api.visual.widget.Widget; +import org.openide.nodes.AbstractNode; +import org.openide.nodes.Children; +import org.openide.nodes.Node; +import org.openide.nodes.Sheet; + +/** + * + * @author Thomas Wuerthinger + */ +public class FigureWidget extends Widget implements Properties.Provider, PopupMenuProvider, DoubleClickHandler { + + public static final boolean VERTICAL_LAYOUT = true; + //public static final int MAX_STRING_LENGTH = 20; + private static final double LABEL_ZOOM_FACTOR = 0.3; + private static final double ZOOM_FACTOR = 0.1; + private Font font; + private Font boldFont; + private Figure figure; + private Widget leftWidget; + private Widget rightWidget; + private Widget middleWidget; + private ArrayList labelWidgets; + private DiagramScene diagramScene; + private boolean boundary; + private Node node; + private Widget dummyTop; + + public void setBoundary(boolean b) { + boundary = b; + } + + public boolean isBoundary() { + return boundary; + } + + public Node getNode() { + return node; + } + + @Override + public boolean isHitAt(Point localLocation) { + return middleWidget.isHitAt(localLocation); + } + + + public FigureWidget(final Figure f, WidgetAction hoverAction, WidgetAction selectAction, DiagramScene scene, Widget parent) { + + super(scene); + + assert this.getScene() != null; + assert this.getScene().getView() != null; + + this.figure = f; + font = f.getDiagram().getFont(); + boldFont = f.getDiagram().getFont().deriveFont(Font.BOLD); + this.setCheckClipping(true); + this.diagramScene = scene; + parent.addChild(this); + + Widget outer = new Widget(scene); + outer.setBackground(f.getColor()); + outer.setLayout(LayoutFactory.createOverlayLayout()); + + middleWidget = new Widget(scene); + middleWidget.setLayout(LayoutFactory.createVerticalFlowLayout(LayoutFactory.SerialAlignment.CENTER, 0)); + middleWidget.setBackground(f.getColor()); + middleWidget.setOpaque(true); + //middleWidget.setBorder(BorderFactory.createLineBorder(Color.BLACK)); + middleWidget.getActions().addAction(new DoubleClickAction(this)); + middleWidget.setCheckClipping(true); + + labelWidgets = new ArrayList<>(); + + String[] strings = figure.getLines(); + + dummyTop = new Widget(scene); + dummyTop.setMinimumSize(new Dimension(Figure.INSET / 2, 1)); + middleWidget.addChild(dummyTop); + + + for (String cur : strings) { + + String displayString = cur; + + LabelWidget lw = new LabelWidget(scene); + labelWidgets.add(lw); + middleWidget.addChild(lw); + lw.setLabel(displayString); + lw.setFont(font); + lw.setForeground(Color.BLACK); + lw.setAlignment(LabelWidget.Alignment.CENTER); + lw.setVerticalAlignment(LabelWidget.VerticalAlignment.CENTER); + lw.setBorder(BorderFactory.createEmptyBorder()); + } + + Widget dummyBottom = new Widget(scene); + dummyBottom.setMinimumSize(new Dimension(Figure.INSET / 2, 1)); + middleWidget.addChild(dummyBottom); + + middleWidget.setPreferredBounds(new Rectangle(0, Figure.SLOT_WIDTH - Figure.OVERLAPPING, f.getWidth(), f.getHeight())); + //outer.addChild(middleWidget); + this.addChild(middleWidget); + + // Initialize node for property sheet + node = new AbstractNode(Children.LEAF) { + + @Override + protected Sheet createSheet() { + Sheet s = super.createSheet(); + PropertiesSheet.initializeSheet(f.getProperties(), s); + return s; + } + }; + node.setDisplayName(getName()); + } + + public Widget getLeftWidget() { + return leftWidget; + } + + public Widget getRightWidget() { + return rightWidget; + } + + @Override + protected void notifyStateChanged(ObjectState previousState, ObjectState state) { + super.notifyStateChanged(previousState, state); + + Color borderColor = Color.BLACK; + Color innerBorderColor = getFigure().getColor(); + int thickness = 1; + boolean repaint = false; + Font f = font; + if (state.isSelected() || state.isHighlighted()) { + thickness = 2; + } + if(state.isSelected()) { + f = boldFont; + innerBorderColor = borderColor; + } else { + } + + if (state.isHighlighted()) { + innerBorderColor = borderColor = Color.BLUE; + repaint = true; + } else { + repaint = true; + } + + if (state.isHovered() != previousState.isHovered()) { + + /* + if (state.isHovered()) { + diagramScene.addAllHighlighted(this.getFigure().getSource().getSourceNodesAsSet()); + } else { + diagramScene.removeAllHighlighted(this.getFigure().getSource().getSourceNodesAsSet()); + }*/ + repaint = true; + } + + if (state.isSelected() != previousState.isSelected()) { + repaint = true; + } + + if (repaint) { + middleWidget.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(borderColor, 1), BorderFactory.createLineBorder(innerBorderColor, 1))); + for (LabelWidget labelWidget : labelWidgets) { + labelWidget.setFont(f); + } + repaint(); + } + } + + public String getName() { + return getProperties().get("name"); + } + + @Override + public Properties getProperties() { + return figure.getProperties(); + } + + public Figure getFigure() { + return figure; + } + + @Override + protected void paintChildren() { + Composite oldComposite = null; + if (boundary) { + oldComposite = getScene().getGraphics().getComposite(); + float alpha = DiagramScene.ALPHA; + this.getScene().getGraphics().setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); + } + + if (diagramScene.getZoomFactor() < LABEL_ZOOM_FACTOR) { + + for (LabelWidget labelWidget : labelWidgets) { + labelWidget.setVisible(false); + } + super.paintChildren(); + for (LabelWidget labelWidget : labelWidgets) { + labelWidget.setVisible(true); + } + + } else { + super.paintChildren(); + } + + if (boundary) { + getScene().getGraphics().setComposite(oldComposite); + } + } + + @Override + public JPopupMenu getPopupMenu(Widget widget, Point point) { + JPopupMenu menu = diagramScene.createPopupMenu(); + menu.addSeparator(); + + JMenu predecessors = new JMenu("Nodes Above"); + predecessors.addMenuListener(new NeighborMenuListener(predecessors, getFigure(), false)); + menu.add(predecessors); + + JMenu successors = new JMenu("Nodes Below"); + successors.addMenuListener(new NeighborMenuListener(successors, getFigure(), true)); + menu.add(successors); + + return menu; + } + + /** + * Builds the submenu for a figure's neighbors on demand. + */ + private class NeighborMenuListener implements MenuListener { + + private final JMenu menu; + private final Figure figure; + private final boolean successors; + + public NeighborMenuListener(JMenu menu, Figure figure, boolean successors) { + this.menu = menu; + this.figure = figure; + this.successors = successors; + } + + @Override + public void menuSelected(MenuEvent e) { + if (menu.getItemCount() > 0) { + // already built before + return; + } + + Set
set = figure.getPredecessorSet(); + if (successors) { + set = figure.getSuccessorSet(); + } + + boolean first = true; + for (Figure f : set) { + if (f == figure) { + continue; + } + + if (first) { + first = false; + } else { + menu.addSeparator(); + } + + Action go = diagramScene.createGotoAction(f); + menu.add(go); + + JMenu preds = new JMenu("Nodes Above"); + preds.addMenuListener(new NeighborMenuListener(preds, f, false)); + menu.add(preds); + + JMenu succs = new JMenu("Nodes Below"); + succs.addMenuListener(new NeighborMenuListener(succs, f, true)); + menu.add(succs); + } + + if (menu.getItemCount() == 0) { + menu.add("(none)"); + } + } + + @Override + public void menuDeselected(MenuEvent e) { + // ignore + } + + @Override + public void menuCanceled(MenuEvent e) { + // ignore + } + } + + @Override + public void handleDoubleClick(Widget w, WidgetAction.WidgetMouseEvent e) { + + if (diagramScene.isAllVisible()) { + final Set hiddenNodes = new HashSet<>(diagramScene.getModel().getGraphToView().getGroup().getAllNodes()); + hiddenNodes.removeAll(this.getFigure().getSource().getSourceNodesAsSet()); + this.diagramScene.getModel().showNot(hiddenNodes); + } else if (isBoundary()) { + + final Set hiddenNodes = new HashSet<>(diagramScene.getModel().getHiddenNodes()); + hiddenNodes.removeAll(this.getFigure().getSource().getSourceNodesAsSet()); + this.diagramScene.getModel().showNot(hiddenNodes); + } else { + final Set hiddenNodes = new HashSet<>(diagramScene.getModel().getHiddenNodes()); + hiddenNodes.addAll(this.getFigure().getSource().getSourceNodesAsSet()); + this.diagramScene.getModel().showNot(hiddenNodes); + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/View/src/com/sun/hotspot/igv/view/widgets/InputSlotWidget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/View/src/com/sun/hotspot/igv/view/widgets/InputSlotWidget.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,73 @@ +/* + * 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.widgets; + +import com.sun.hotspot.igv.graph.Figure; +import com.sun.hotspot.igv.graph.InputSlot; +import com.sun.hotspot.igv.view.scene.DiagramScene; +import java.awt.Point; +import java.util.List; +import org.netbeans.api.visual.widget.Widget; + +/** + * + * @author Thomas Wuerthinger + */ +public class InputSlotWidget extends SlotWidget { + + private InputSlot inputSlot; + + public InputSlotWidget(InputSlot slot, DiagramScene scene, Widget parent, FigureWidget fw) { + super(slot, scene, parent, fw); + inputSlot = slot; + //init(); + //getFigureWidget().getLeftWidget().addChild(this); + Point p = inputSlot.getRelativePosition(); + p.x -= this.calculateClientArea().width / 2; + p.y += Figure.SLOT_START; + this.setPreferredLocation(p); + } + + public InputSlot getInputSlot() { + return inputSlot; + } + + @Override + protected int calculateSlotWidth() { + List slots = getSlot().getFigure().getInputSlots(); + assert slots.contains(getSlot()); + return calculateWidth(slots.size()); + } +/* + protected Point calculateRelativeLocation() { + if (getFigureWidget().getBounds() == null) { + return new Point(0, 0); + } + + double x = 0; + List slots = inputSlot.getFigure().getInputSlots(); + assert slots.contains(inputSlot); + return new Point((int) x, (int) (calculateRelativeY(slots.size(), slots.indexOf(inputSlot)))); + }*/ +} diff -r 6cb549627941 -r 015fb895586b visualizer/View/src/com/sun/hotspot/igv/view/widgets/LineWidget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/View/src/com/sun/hotspot/igv/view/widgets/LineWidget.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,343 @@ +/* + * 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.widgets; + +import com.sun.hotspot.igv.graph.Connection; +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.scene.DiagramScene; +import java.awt.*; +import java.awt.geom.Line2D; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import javax.swing.JPopupMenu; +import javax.swing.event.PopupMenuEvent; +import javax.swing.event.PopupMenuListener; +import org.netbeans.api.visual.action.ActionFactory; +import org.netbeans.api.visual.action.PopupMenuProvider; +import org.netbeans.api.visual.action.SelectProvider; +import org.netbeans.api.visual.animator.SceneAnimator; +import org.netbeans.api.visual.model.ObjectState; +import org.netbeans.api.visual.widget.Widget; + +/** + * + * @author Thomas Wuerthinger + */ +public class LineWidget extends Widget implements PopupMenuProvider { + + public final int BORDER = 5; + public final int ARROW_SIZE = 6; + public final int BOLD_ARROW_SIZE = 7; + public final int HOVER_ARROW_SIZE = 8; + public final int BOLD_STROKE_WIDTH = 2; + public final int HOVER_STROKE_WIDTH = 3; + private static double ZOOM_FACTOR = 0.1; + private OutputSlot outputSlot; + private DiagramScene scene; + private List connections; + private Point from; + private Point to; + private Rectangle clientArea; + private Color color = Color.BLACK; + private LineWidget predecessor; + private List successors; + private boolean highlighted; + private boolean popupVisible; + private boolean isBold; + private boolean isDashed; + + public LineWidget(DiagramScene scene, OutputSlot s, List connections, Point from, Point to, LineWidget predecessor, SceneAnimator animator, boolean isBold, boolean isDashed) { + super(scene); + this.scene = scene; + this.outputSlot = s; + this.connections = connections; + this.from = from; + this.to = to; + this.predecessor = predecessor; + this.successors = new ArrayList<>(); + if (predecessor != null) { + predecessor.addSuccessor(this); + } + + this.isBold = isBold; + this.isDashed = isDashed; + + int minX = from.x; + int minY = from.y; + int maxX = to.x; + int maxY = to.y; + if (minX > maxX) { + int tmp = minX; + minX = maxX; + maxX = tmp; + } + + if (minY > maxY) { + int tmp = minY; + minY = maxY; + maxY = tmp; + } + + clientArea = new Rectangle(minX, minY, maxX - minX + 1, maxY - minY + 1); + clientArea.grow(BORDER, BORDER); + + if (connections.size() > 0) { + color = connections.get(0).getColor(); + } + + this.setToolTipText("" + generateToolTipText(this.connections) + ""); + + this.setCheckClipping(true); + + this.getActions().addAction(ActionFactory.createPopupMenuAction(this)); + if (animator == null) { + this.setBackground(color); + } else { + this.setBackground(Color.WHITE); + animator.animateBackgroundColor(this, color); + } + + this.getActions().addAction(ActionFactory.createSelectAction(new SelectProvider() { + + @Override + public boolean isAimingAllowed(Widget arg0, Point arg1, boolean arg2) { + return true; + } + + @Override + public boolean isSelectionAllowed(Widget arg0, Point arg1, boolean arg2) { + return true; + } + + @Override + public void select(Widget arg0, Point arg1, boolean arg2) { + Set
set = new HashSet<>(); + for (Connection c : LineWidget.this.connections) { + set.add(c.getInputSlot().getFigure()); + set.add(c.getOutputSlot().getFigure()); + } + LineWidget.this.scene.setSelectedObjects(set); + } + })); + } + + private String generateToolTipText(List conn) { + StringBuilder sb = new StringBuilder(); + for (Connection c : conn) { + sb.append(c.getToolTipText()); + sb.append("
"); + } + return sb.toString(); + } + + public Point getFrom() { + return from; + } + + public Point getTo() { + return to; + } + + private void addSuccessor(LineWidget widget) { + this.successors.add(widget); + } + + @Override + protected Rectangle calculateClientArea() { + return clientArea; + } + + @Override + protected void paintWidget() { + if (scene.getZoomFactor() < ZOOM_FACTOR) { + return; + } + + Graphics2D g = getScene().getGraphics(); + g.setPaint(this.getBackground()); + float width = 1.0f; + + if (isBold) { + width = BOLD_STROKE_WIDTH; + } + + if (highlighted || popupVisible) { + width = HOVER_STROKE_WIDTH; + } + + Stroke oldStroke = g.getStroke(); + if (isDashed) { + float[] dashPattern = {5, 5, 5, 5}; + g.setStroke(new BasicStroke(width, BasicStroke.CAP_BUTT, + BasicStroke.JOIN_MITER, 10, + dashPattern, 0)); + } else { + g.setStroke(new BasicStroke(width)); + } + + g.drawLine(from.x, from.y, to.x, to.y); + + boolean sameFrom = false; + boolean sameTo = successors.size() == 0; + for (LineWidget w : successors) { + if (w.getFrom().equals(getTo())) { + sameTo = true; + } + } + + if (predecessor == null || predecessor.getTo().equals(getFrom())) { + sameFrom = true; + } + + + int size = ARROW_SIZE; + if (isBold) { + size = BOLD_ARROW_SIZE; + } + if (highlighted || popupVisible) { + size = HOVER_ARROW_SIZE; + } + if (!sameFrom) { + g.fillPolygon( + new int[]{from.x - size / 2, from.x + size / 2, from.x}, + new int[]{from.y - size / 2, from.y - size / 2, from.y + size / 2}, + 3); + } + if (!sameTo) { + g.fillPolygon( + new int[]{to.x - size / 2, to.x + size / 2, to.x}, + new int[]{to.y - size / 2, to.y - size / 2, to.y + size / 2}, + 3); + } + g.setStroke(oldStroke); + } + + private void setHighlighted(boolean b) { + this.highlighted = b; + Set highlightedObjects = new HashSet<>(scene.getHighlightedObjects()); + Set highlightedObjectsChange = new HashSet<>(); + for (Connection c : connections) { + highlightedObjectsChange.add(c.getInputSlot().getFigure()); + highlightedObjectsChange.add(c.getInputSlot()); + highlightedObjectsChange.add(c.getOutputSlot().getFigure()); + highlightedObjectsChange.add(c.getOutputSlot()); + } + if(b) { + highlightedObjects.addAll(highlightedObjectsChange); + } else { + highlightedObjects.removeAll(highlightedObjectsChange); + } + scene.setHighlightedObjects(highlightedObjects); + this.revalidate(true); + } + + private void setPopupVisible(boolean b) { + this.popupVisible = b; + this.revalidate(true); + } + + @Override + public boolean isHitAt(Point localPoint) { + return Line2D.ptLineDistSq(from.x, from.y, to.x, to.y, localPoint.x, localPoint.y) <= BORDER * BORDER; + } + + @Override + protected void notifyStateChanged(ObjectState previousState, ObjectState state) { + if (previousState.isHovered() != state.isHovered()) { + setRecursiveHighlighted(state.isHovered()); + } + } + + private void setRecursiveHighlighted(boolean b) { + LineWidget cur = predecessor; + while (cur != null) { + cur.setHighlighted(b); + cur = cur.predecessor; + } + + highlightSuccessors(b); + this.setHighlighted(b); + } + + private void highlightSuccessors(boolean b) { + for (LineWidget s : successors) { + s.setHighlighted(b); + s.highlightSuccessors(b); + } + } + + private void setRecursivePopupVisible(boolean b) { + LineWidget cur = predecessor; + while (cur != null) { + cur.setPopupVisible(b); + cur = cur.predecessor; + } + + popupVisibleSuccessors(b); + setPopupVisible(b); + } + + private void popupVisibleSuccessors(boolean b) { + for (LineWidget s : successors) { + s.setPopupVisible(b); + s.popupVisibleSuccessors(b); + } + } + + @Override + public JPopupMenu getPopupMenu(Widget widget, Point localLocation) { + JPopupMenu menu = new JPopupMenu(); + menu.add(scene.createGotoAction(outputSlot.getFigure())); + menu.addSeparator(); + + for (Connection c : connections) { + InputSlot s = c.getInputSlot(); + menu.add(scene.createGotoAction(s.getFigure())); + } + + final LineWidget w = this; + menu.addPopupMenuListener(new PopupMenuListener() { + + @Override + public void popupMenuWillBecomeVisible(PopupMenuEvent e) { + w.setRecursivePopupVisible(true); + } + + @Override + public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { + w.setRecursivePopupVisible(false); + } + + @Override + public void popupMenuCanceled(PopupMenuEvent e) { + } + }); + + return menu; + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/View/src/com/sun/hotspot/igv/view/widgets/OutputSlotWidget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/View/src/com/sun/hotspot/igv/view/widgets/OutputSlotWidget.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,76 @@ +/* + * 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.widgets; + +import com.sun.hotspot.igv.graph.Figure; +import com.sun.hotspot.igv.graph.OutputSlot; +import com.sun.hotspot.igv.view.scene.DiagramScene; +import java.awt.Point; +import java.util.List; +import org.netbeans.api.visual.widget.Widget; + +/** + * + * @author Thomas Wuerthinger + */ +public class OutputSlotWidget extends SlotWidget { + + private OutputSlot outputSlot; + + public OutputSlotWidget(OutputSlot slot, DiagramScene scene, Widget parent, FigureWidget fw) { + super(slot, scene, parent, fw); + outputSlot = slot; + //init(); + //getFigureWidget().getRightWidget().addChild(this); + Point p = outputSlot.getRelativePosition(); + p.y += getSlot().getFigure().getHeight() - Figure.SLOT_START; + p.x -= this.calculateClientArea().width / 2; + //p.x += this.calculateClientArea().width / 2; + this.setPreferredLocation(p); + } + + public OutputSlot getOutputSlot() { + return outputSlot; + } + + @Override + protected int calculateSlotWidth() { + + List slots = getSlot().getFigure().getOutputSlots(); + assert slots.contains(getSlot()); + return calculateWidth(slots.size()); + + } + /* + protected Point calculateRelativeLocation() { + if (getFigureWidget().getBounds() == null) { + return new Point(0, 0); + } + + double x = this.getFigureWidget().getBounds().width; + List slots = outputSlot.getFigure().getOutputSlots(); + assert slots.contains(outputSlot); + return new Point((int) x, (int) (calculateRelativeY(slots.size(), slots.indexOf(outputSlot)))); + }*/ +} diff -r 6cb549627941 -r 015fb895586b visualizer/View/src/com/sun/hotspot/igv/view/widgets/SlotWidget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/View/src/com/sun/hotspot/igv/view/widgets/SlotWidget.java Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,177 @@ +/* + * 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.widgets; + +import com.sun.hotspot.igv.graph.Figure; +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.scene.DiagramScene; +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics2D; +import java.awt.Rectangle; +import java.awt.geom.Rectangle2D; +import java.util.HashSet; +import java.util.Set; +import org.netbeans.api.visual.action.WidgetAction; +import org.netbeans.api.visual.model.ObjectState; +import org.netbeans.api.visual.widget.Widget; + +/** + * + * @author Thomas Wuerthinger + */ +public abstract class SlotWidget extends Widget implements DoubleClickHandler { + + private Slot slot; + private FigureWidget figureWidget; + private static double TEXT_ZOOM_FACTOR = 0.9; + private static double ZOOM_FACTOR = 0.6; + private DiagramScene diagramScene; + + public SlotWidget(Slot slot, DiagramScene scene, Widget parent, FigureWidget fw) { + super(scene); + this.diagramScene = scene; + this.slot = slot; + figureWidget = fw; + this.setToolTipText("" + slot.getToolTipText() + ""); + this.setCheckClipping(true); + parent.addChild(this); + + //this.setPreferredBounds(this.calculateClientArea()); + } + + + @Override + protected void notifyStateChanged(ObjectState previousState, ObjectState state) { + super.notifyStateChanged(previousState, state); + repaint(); + } + + public Slot getSlot() { + return slot; + } + + public FigureWidget getFigureWidget() { + return figureWidget; + } + + @Override + protected void paintWidget() { + + if (getScene().getZoomFactor() < ZOOM_FACTOR) { + return; + } + + Graphics2D g = this.getGraphics(); + // g.setColor(Color.DARK_GRAY); + int w = this.getBounds().width; + int h = this.getBounds().height; + + if(getSlot().getSource().getSourceNodes().size() > 0) { + final int SMALLER = 0; + g.setColor(getSlot().getColor()); + + int FONT_OFFSET = 2; + + int s = h - SMALLER; + int rectW = s; + + Font font = this.getSlot().getFigure().getDiagram().getSlotFont(); + if(this.getState().isSelected()) { + font = font.deriveFont(Font.BOLD); + } + + if (getSlot().getShortName() != null && getSlot().getShortName().length() > 0) { + g.setFont(font); + Rectangle2D r1 = g.getFontMetrics().getStringBounds(getSlot().getShortName(), g); + rectW = (int)r1.getWidth() + FONT_OFFSET * 2; + } + g.fillRect(w/2 - rectW/2, 0, rectW-1, s-1); + + if(this.getState().isHighlighted()) { + g.setColor(Color.BLUE); + } else { + g.setColor(Color.BLACK); + } + g.drawRect(w/2 - rectW/2, 0, rectW-1, s-1); + + + if (getSlot().getShortName() != null && getSlot().getShortName().length() > 0 && getScene().getZoomFactor() >= TEXT_ZOOM_FACTOR) { + Rectangle2D r1 = g.getFontMetrics().getStringBounds(getSlot().getShortName(), g); + g.drawString(getSlot().getShortName(), (int) (w - r1.getWidth()) / 2, g.getFontMetrics().getAscent()-1);//(int) (r1.getHeight())); + } + + } else { + + if(this.getState().isHighlighted()) { + g.setColor(Color.BLUE); + } else { + g.setColor(Color.BLACK); + } + int r = 2; + if (slot instanceof OutputSlot) { + g.fillOval(w/2-r, Figure.SLOT_WIDTH - Figure.SLOT_START - r, 2*r, 2*r); + //g.fillArc(w / 2 - r, -r, 2*r, 2*r, 180, 180); + } else { + g.fillOval(w/2-r, Figure.SLOT_START - r, 2*r, 2*r); + //g.fillArc(w / 2 - r, h - r, 2*r, 2*r, 0, 180); + } + } + } + + @Override + protected Rectangle calculateClientArea() { + return new Rectangle(0, 0, slot.getWidth(), Figure.SLOT_WIDTH); + } + + protected abstract int calculateSlotWidth(); + + protected int calculateWidth(int count) { + return getFigureWidget().getFigure().getWidth() / count; + } + + @Override + public void handleDoubleClick(Widget w, WidgetAction.WidgetMouseEvent e) { + Set hiddenNodes = new HashSet<>(diagramScene.getModel().getHiddenNodes()); + if (diagramScene.isAllVisible()) { + hiddenNodes = new HashSet<>(diagramScene.getModel().getGraphToView().getGroup().getAllNodes()); + } + + boolean progress = false; + for(Figure f : diagramScene.getModel().getDiagramToView().getFigures()) { + for(Slot s : f.getSlots()) { + if(DiagramScene.doesIntersect(s.getSource().getSourceNodesAsSet(), slot.getSource().getSourceNodesAsSet())) { + progress = true; + hiddenNodes.removeAll(f.getSource().getSourceNodesAsSet()); + } + } + } + + if(progress) { + this.diagramScene.getModel().showNot(hiddenNodes); + } + } +} diff -r 6cb549627941 -r 015fb895586b visualizer/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,7 @@ +currentVersion=Graal Visualizer {0} +LBL_splash_window_title=Starting Graal Visualizer +SPLASH_WIDTH=475 +SplashProgressBarBounds=0,273,475,6 +SplashProgressBarColor=0xFFFFFF +SplashRunningTextBounds=10,283,460,12 +SplashRunningTextColor=0xFFFFFF diff -r 6cb549627941 -r 015fb895586b visualizer/branding/core/core.jar/org/netbeans/core/startup/frame.gif Binary file visualizer/branding/core/core.jar/org/netbeans/core/startup/frame.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/branding/core/core.jar/org/netbeans/core/startup/frame32.gif Binary file visualizer/branding/core/core.jar/org/netbeans/core/startup/frame32.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/branding/core/core.jar/org/netbeans/core/startup/frame48.gif Binary file visualizer/branding/core/core.jar/org/netbeans/core/startup/frame48.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/branding/core/core.jar/org/netbeans/core/startup/splash.gif Binary file visualizer/branding/core/core.jar/org/netbeans/core/startup/splash.gif has changed diff -r 6cb549627941 -r 015fb895586b visualizer/branding/modules/org-netbeans-core-windows.jar/org/netbeans/core/windows/view/ui/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visualizer/branding/modules/org-netbeans-core-windows.jar/org/netbeans/core/windows/view/ui/Bundle.properties Tue Feb 07 22:41:09 2012 +0100 @@ -0,0 +1,2 @@ +CTL_MainWindow_Title=Graal Visualizer {0} +CTL_MainWindow_Title_No_Project=Graal Visualizer {0}