diff --git a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/removeall.gif b/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/removeall.gif new file mode 100644 index 0000000000000000000000000000000000000000..9eeab3cad6d41d9398254672379395a82f6ddf13 Binary files /dev/null and b/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/removeall.gif differ diff --git a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/save.gif b/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/save.gif new file mode 100644 index 0000000000000000000000000000000000000000..954f1accde64db9e98e9a6e528b459f3027b018c Binary files /dev/null and b/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/save.gif differ diff --git a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/saveall.gif b/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/saveall.gif new file mode 100644 index 0000000000000000000000000000000000000000..2d31c8b2ccd48d32acf35dccf6c5689a38a04a36 Binary files /dev/null and b/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/saveall.gif differ diff --git a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/structure.gif b/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/structure.gif new file mode 100644 index 0000000000000000000000000000000000000000..2be848748743d34bba27e3a697ebac3ff8ec552c Binary files /dev/null and b/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/structure.gif differ diff --git a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/structured.gif b/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/structured.gif new file mode 100644 index 0000000000000000000000000000000000000000..71aa946d53918697f7043a6c255611b50d5d11cd Binary files /dev/null and b/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/images/structured.gif differ diff --git a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/layer.xml b/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/layer.xml new file mode 100644 index 0000000000000000000000000000000000000000..999997db9f617eb884f61d0c1716edb8a2ceab3b --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/layer.xml @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/share/tools/IdealGraphVisualizer/Data/build.xml b/src/share/tools/IdealGraphVisualizer/Data/build.xml new file mode 100644 index 0000000000000000000000000000000000000000..dd626066c85e933b7ed6eaa8ec8d25a919dcada8 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/build.xml @@ -0,0 +1,8 @@ + + + + + + Builds, tests, and runs the project com.sun.hotspot.igv.data. + + diff --git a/src/share/tools/IdealGraphVisualizer/Data/manifest.mf b/src/share/tools/IdealGraphVisualizer/Data/manifest.mf new file mode 100644 index 0000000000000000000000000000000000000000..702ae8764a2289521993d10db34b34c9d522ca33 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/manifest.mf @@ -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 --git a/src/share/tools/IdealGraphVisualizer/Data/nbproject/build-impl.xml b/src/share/tools/IdealGraphVisualizer/Data/nbproject/build-impl.xml new file mode 100644 index 0000000000000000000000000000000000000000..942d7a628fcfa5959b63b84046095c1b558fbacc --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/nbproject/build-impl.xml @@ -0,0 +1,30 @@ + + + + + + You must set 'suite.dir' to point to your containing module suite + + + + + + + + + + + + + + + + + + + + + diff --git a/src/share/tools/IdealGraphVisualizer/Data/nbproject/genfiles.properties b/src/share/tools/IdealGraphVisualizer/Data/nbproject/genfiles.properties new file mode 100644 index 0000000000000000000000000000000000000000..621e413c962281f120f1ad9192ede58e1221b104 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=a403efd8 +build.xml.script.CRC32=b87f73ba +build.xml.stylesheet.CRC32=79c3b980 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=a403efd8 +nbproject/build-impl.xml.script.CRC32=cc649146 +nbproject/build-impl.xml.stylesheet.CRC32=deb65f65 diff --git a/src/share/tools/IdealGraphVisualizer/Data/nbproject/platform.properties b/src/share/tools/IdealGraphVisualizer/Data/nbproject/platform.properties new file mode 100644 index 0000000000000000000000000000000000000000..68ad75e5766f33be5a65a19d28cc7605c5b50a1c --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/nbproject/platform.properties @@ -0,0 +1,29 @@ +# Deprecated since 5.0u1; for compatibility with 5.0: +disabled.clusters=\ + apisupport1,\ + harness,\ + ide8,\ + java1,\ + nb6.0,\ + profiler2 +disabled.modules=\ + org.netbeans.core.execution,\ + org.netbeans.core.multiview,\ + org.netbeans.core.output2,\ + org.netbeans.modules.applemenu,\ + org.netbeans.modules.autoupdate.services,\ + org.netbeans.modules.autoupdate.ui,\ + org.netbeans.modules.core.kit,\ + org.netbeans.modules.favorites,\ + org.netbeans.modules.javahelp,\ + org.netbeans.modules.masterfs,\ + org.netbeans.modules.options.keymap,\ + org.netbeans.modules.sendopts,\ + org.netbeans.modules.templates,\ + org.openide.compat,\ + org.openide.execution,\ + org.openide.util.enumerations +enabled.clusters=\ + platform7 +nbjdk.active=JDK_1.6 +nbplatform.active=default diff --git a/src/share/tools/IdealGraphVisualizer/Data/nbproject/project.properties b/src/share/tools/IdealGraphVisualizer/Data/nbproject/project.properties new file mode 100644 index 0000000000000000000000000000000000000000..152f44eca60ab831869539ffae9192aa03915f3b --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/nbproject/project.properties @@ -0,0 +1,2 @@ +javac.source=1.5 +javac.compilerargs=-Xlint -Xlint:-serial diff --git a/src/share/tools/IdealGraphVisualizer/Data/nbproject/project.xml b/src/share/tools/IdealGraphVisualizer/Data/nbproject/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..dce4d28a7c307a91e17bd4284fb82d5c27889007 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/nbproject/project.xml @@ -0,0 +1,16 @@ + + + org.netbeans.modules.apisupport.project + + + com.sun.hotspot.igv.data + + + + com.sun.hotspot.igv.data + com.sun.hotspot.igv.data.serialization + com.sun.hotspot.igv.data.services + + + + diff --git a/src/share/tools/IdealGraphVisualizer/Data/nbproject/suite.properties b/src/share/tools/IdealGraphVisualizer/Data/nbproject/suite.properties new file mode 100644 index 0000000000000000000000000000000000000000..29d7cc9bd6fdd81453543cdf1bcf1dab301e3a92 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/nbproject/suite.properties @@ -0,0 +1 @@ +suite.dir=${basedir}/.. diff --git a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Bundle.properties b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Bundle.properties new file mode 100644 index 0000000000000000000000000000000000000000..f17788c7ff4ef389166ae04a7b0994a36d8992a4 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Bundle.properties @@ -0,0 +1 @@ +OpenIDE-Module-Name=Data diff --git a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/ChangedEvent.java b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/ChangedEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..18a8cedbabfbafe7e972eb7f31536baadf41a477 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/ChangedEvent.java @@ -0,0 +1,44 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.data; + +/** + * + * @author Thomas Wuerthinger + */ +public class ChangedEvent extends Event> { + + private T object; + + public ChangedEvent() { + } + + public ChangedEvent(T object) { + this.object = object; + } + + protected void fire(ChangedListener l) { + l.changed(object); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/ChangedEventProvider.java b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/ChangedEventProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..5e2978e82604d6911b6d42680027e7ef57be26ba --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/ChangedEventProvider.java @@ -0,0 +1,34 @@ +/* + * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ +package com.sun.hotspot.igv.data; + +/** + * + * @author Thomas Wuerthinger + */ +public interface ChangedEventProvider { + + public ChangedEvent getChangedEvent(); +} diff --git a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/ChangedListener.java b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/ChangedListener.java new file mode 100644 index 0000000000000000000000000000000000000000..806b339be1731ec7dd0fb8b50600cb4abfd0d3f9 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/ChangedListener.java @@ -0,0 +1,33 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.data; + +/** + * + * @author Thomas Wuerthinger + */ +public interface ChangedListener { + + public void changed(T source); +} diff --git a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Event.java b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Event.java new file mode 100644 index 0000000000000000000000000000000000000000..c31e5935a1297acaeb95bbabf2d814797ab9dd17 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Event.java @@ -0,0 +1,57 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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; + + public Event() { + listener = new ArrayList(); + } + + public void addListener(L l) { + listener.add(l); + } + + public void removeListener(L l) { + listener.remove(l); + } + + public void fire() { + List tmpList = new ArrayList(listener); + for (L l : tmpList) { + fire(l); + } + } + + protected abstract void fire(L l); +} diff --git a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/GraphDocument.java b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/GraphDocument.java new file mode 100644 index 0000000000000000000000000000000000000000..27d09c38f712b644897b8fde3dbad0cce3224e29 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/GraphDocument.java @@ -0,0 +1,91 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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 GraphDocument extends Properties.Object implements ChangedEventProvider { + + private List groups; + private ChangedEvent changedEvent; + + public GraphDocument() { + groups = new ArrayList(); + changedEvent = new ChangedEvent(this); + } + + public void clear() { + groups.clear(); + getChangedEvent().fire(); + } + + public ChangedEvent getChangedEvent() { + return changedEvent; + } + + public List getGroups() { + return Collections.unmodifiableList(groups); + } + + public void addGroup(Group group) { + group.setDocument(this); + groups.add(group); + getChangedEvent().fire(); + } + + public void removeGroup(Group group) { + if (groups.contains(group)) { + group.setDocument(null); + groups.remove(group); + getChangedEvent().fire(); + } + } + + public void addGraphDocument(GraphDocument document) { + for (Group g : document.groups) { + this.addGroup(g); + } + document.clear(); + getChangedEvent().fire(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + sb.append("GraphDocument: " + getProperties().toString() + " \n\n"); + for (Group g : getGroups()) { + sb.append(g.toString()); + sb.append("\n\n"); + } + + return sb.toString(); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Group.java b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Group.java new file mode 100644 index 0000000000000000000000000000000000000000..8f0aa15e9928f58b1a608d9fecc9c7455c6ef776 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Group.java @@ -0,0 +1,141 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.data; + +import com.sun.hotspot.igv.data.ChangedEvent; +import com.sun.hotspot.igv.data.ChangedEventProvider; +import com.sun.hotspot.igv.data.Properties; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * + * @author Thomas Wuerthinger + */ +public class Group extends Properties.Object implements ChangedEventProvider { + + private List graphs; + private transient ChangedEvent changedEvent; + private GraphDocument document; + private InputMethod method; + private String assembly; + + public Group() { + graphs = new ArrayList(); + init(); + } + + private void init() { + changedEvent = new ChangedEvent(this); + } + + public void fireChangedEvent() { + changedEvent.fire(); + } + + public void setAssembly(String s) { + this.assembly = s; + } + + public String getAssembly() { + return assembly; + } + + public void setMethod(InputMethod method) { + this.method = method; + } + + public InputMethod getMethod() { + return method; + } + + void setDocument(GraphDocument document) { + this.document = document; + } + + public GraphDocument getDocument() { + return document; + } + + public ChangedEvent getChangedEvent() { + return changedEvent; + } + + public List getGraphs() { + return Collections.unmodifiableList(graphs); + } + + public void addGraph(InputGraph g) { + assert g != null; + assert !graphs.contains(g); + graphs.add(g); + changedEvent.fire(); + } + + public void removeGraph(InputGraph g) { + int index = graphs.indexOf(g); + if (index != -1) { + graphs.remove(g); + changedEvent.fire(); + } + } + + public Set getAllNodes() { + Set result = new HashSet(); + for (InputGraph g : graphs) { + Set ids = g.getNodesAsSet(); + result.addAll(g.getNodesAsSet()); + for (Integer i : ids) { + result.add(-i); + } + } + return result; + } + + public InputGraph getLastAdded() { + if (graphs.size() == 0) { + return null; + } + return graphs.get(graphs.size() - 1); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("Group " + getProperties().toString() + "\n"); + for (InputGraph g : graphs) { + sb.append(g.toString()); + sb.append("\n"); + } + return sb.toString(); + } + + public String getName() { + return getProperties().get("name"); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputBlock.java b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputBlock.java new file mode 100644 index 0000000000000000000000000000000000000000..1c1367738afcfa64caf3f57d9033a321bb4a13a9 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputBlock.java @@ -0,0 +1,140 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.data; + +import java.awt.Rectangle; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * + * @author Thomas Wuerthinger + */ +public class InputBlock { + + private List nodes; + private List successorNames; + private String name; + private InputGraph graph; + private Rectangle bounds; + private Set successors; + private Set predecessors; + private Set inputs; + private Set outputs; + + public InputBlock(InputGraph graph, String name) { + this.graph = graph; + this.name = name; + nodes = new ArrayList(); + successorNames = new ArrayList(); + successors = new HashSet(); + predecessors = new HashSet(); + inputs = new HashSet(); + outputs = new HashSet(); + } + + public void removeSuccessor(InputBlock b) { + if (successors.contains(b)) { + successors.remove(b); + b.predecessors.remove(this); + InputBlockEdge e = new InputBlockEdge(this, b); + assert outputs.contains(e); + outputs.remove(e); + assert b.inputs.contains(e); + b.inputs.remove(e); + } + } + + public String getName() { + return name; + } + + public void setName(String s) { + name = s; + } + + public List getNodes() { + return Collections.unmodifiableList(nodes); + } + + public void addNode(int id) { + InputNode n = graph.getNode(id); + assert n != null; + graph.setBlock(n, this); + addNode(graph.getNode(id)); + } + + public void addNode(InputNode node) { + assert !nodes.contains(node); + nodes.add(node); + } + + public Set getPredecessors() { + return Collections.unmodifiableSet(predecessors); + } + + public Set getSuccessors() { + return Collections.unmodifiableSet(successors); + } + + public Set getInputs() { + return Collections.unmodifiableSet(inputs); + } + + public Set getOutputs() { + return Collections.unmodifiableSet(outputs); + } + + // resolveBlockLinks must be called afterwards + public void addSuccessor(String name) { + successorNames.add(name); + } + + public void resolveBlockLinks() { + for (String s : successorNames) { + InputBlock b = graph.getBlock(s); + addSuccessor(b); + } + + successorNames.clear(); + } + + public void addSuccessor(InputBlock b) { + if (!successors.contains(b)) { + successors.add(b); + b.predecessors.add(this); + InputBlockEdge e = new InputBlockEdge(this, b); + outputs.add(e); + b.inputs.add(e); + } + } + + @Override + public String toString() { + return this.getName(); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputBlockEdge.java b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputBlockEdge.java new file mode 100644 index 0000000000000000000000000000000000000000..10cac158a4a1e1315a102650339f561bfb03a1ce --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputBlockEdge.java @@ -0,0 +1,65 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.data; + +/** + * + * @author Thomas Wuerthinger + */ +public class InputBlockEdge { + + private InputBlock from; + private InputBlock to; + + 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; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof InputBlockEdge && obj != null) { + InputBlockEdge e = (InputBlockEdge) obj; + return e.from.equals(from) && e.to.equals(to); + } + return super.equals(obj); + } + + @Override + public int hashCode() { + int hash = from.hashCode(); + hash = 59 * hash + to.hashCode(); + return hash; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputBytecode.java b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputBytecode.java new file mode 100644 index 0000000000000000000000000000000000000000..14ab1f340599acc212fafad76a8fc1b99534db9b --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputBytecode.java @@ -0,0 +1,56 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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 --git a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputEdge.java b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputEdge.java new file mode 100644 index 0000000000000000000000000000000000000000..d1c440ec09a3da8803982847119a85da26b80c17 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputEdge.java @@ -0,0 +1,92 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.data; + +/** + * + * @author Thomas Wuerthinger + */ +public class InputEdge { + + public enum State { + + SAME, + NEW, + DELETED + } + private char toIndex; + private int from; + private int to; + private State state; + + public InputEdge(char toIndex, int from, int to) { + this.toIndex = toIndex; + this.from = from; + this.to = to; + this.state = State.SAME; + } + + public State getState() { + return state; + } + + public void setState(State x) { + this.state = x; + } + + public char getToIndex() { + return toIndex; + } + + public String getName() { + return "in" + toIndex; + } + + public int getFrom() { + return from; + } + + public int getTo() { + return to; + } + + @Override + public boolean equals(Object o) { + if (o == null || !(o instanceof InputEdge)) { + return false; + } + InputEdge conn2 = (InputEdge) o; + return conn2.toIndex == toIndex && conn2.from == from && conn2.to == to; + } + + @Override + public String toString() { + return "Edge from " + from + " to " + to + "(" + (int) toIndex + ") "; + } + + @Override + public int hashCode() { + return (from << 20 | to << 8 | toIndex); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputGraph.java b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputGraph.java new file mode 100644 index 0000000000000000000000000000000000000000..b929fd627c6ab793cd09162aa5e52d4bd18341ec --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputGraph.java @@ -0,0 +1,249 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.data; + +import com.sun.hotspot.igv.data.Properties; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * + * @author Thomas Wuerthinger + */ +public class InputGraph extends Properties.Object { + + private Map nodes; + private Set edges; + private Group parent; + private Map blocks; + private Map nodeToBlock; + private boolean isDifferenceGraph; + + public InputGraph(Group parent) { + this(parent, null); + } + + public InputGraph(Group parent, InputGraph last) { + this(parent, last, ""); + } + + private void clearBlocks() { + blocks.clear(); + nodeToBlock.clear(); + } + + public InputGraph(Group parent, InputGraph last, String name) { + this.parent = parent; + setName(name); + nodes = new Hashtable(); + edges = new HashSet(); + blocks = new Hashtable(); + nodeToBlock = new Hashtable(); + if (last != null) { + + for (InputNode n : last.getNodes()) { + addNode(n); + } + + for (InputEdge c : last.getEdges()) { + addEdge(c); + } + } + } + + public void schedule(Collection newBlocks) { + clearBlocks(); + InputBlock noBlock = new InputBlock(this, "no block"); + Set scheduledNodes = new HashSet(); + + for (InputBlock b : newBlocks) { + 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)) { + noBlock.addNode(n.getId()); + } + } + + if (noBlock.getNodes().size() != 0) { + newBlocks.add(noBlock); + } + for (InputBlock b : newBlocks) { + addBlock(b); + } + + for (InputNode n : this.getNodes()) { + 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) { + return getBlock(node.getId()); + } + + public InputGraph getNext() { + List list = parent.getGraphs(); + if (!list.contains(this)) { + return null; + } + int index = list.indexOf(this); + if (index == list.size() - 1) { + return null; + } else { + return list.get(index + 1); + } + } + + public InputGraph getPrev() { + List list = parent.getGraphs(); + if (!list.contains(this)) { + return null; + } + int index = list.indexOf(this); + if (index == 0) { + return null; + } else { + return list.get(index - 1); + } + } + + public String getName() { + return getProperties().get("name"); + } + + public String getAbsoluteName() { + String result = getName(); + if (this.parent != null) { + result = parent.getName() + ": " + result; + } + return result; + } + + 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 Set getEdges() { + return Collections.unmodifiableSet(edges); + } + + public void removeEdge(InputEdge c) { + assert edges.contains(c); + edges.remove(c); + assert !edges.contains(c); + } + + public void addEdge(InputEdge c) { + assert !edges.contains(c); + edges.add(c); + assert edges.contains(c); + } + + public Group getGroup() { + return parent; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("Graph " + getName() + " " + getProperties().toString() + "\n"); + for (InputNode n : nodes.values()) { + sb.append(n.toString()); + sb.append("\n"); + } + + for (InputEdge c : edges) { + sb.append(c.toString()); + sb.append("\n"); + } + return sb.toString(); + } + + public void addBlock(InputBlock b) { + blocks.put(b.getName(), b); + for (InputNode n : b.getNodes()) { + this.nodeToBlock.put(n.getId(), b); + } + } + + public void resolveBlockLinks() { + for (InputBlock b : blocks.values()) { + b.resolveBlockLinks(); + } + } + + public void setName(String s) { + getProperties().setProperty("name", s); + } + + public InputBlock getBlock(String s) { + return blocks.get(s); + } + + public boolean isDifferenceGraph() { + return this.isDifferenceGraph; + } + + public void setIsDifferenceGraph(boolean b) { + isDifferenceGraph = b; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputMethod.java b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputMethod.java new file mode 100644 index 0000000000000000000000000000000000000000..eac6b1a03085e1637e9681db100b582be458be3d --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputMethod.java @@ -0,0 +1,127 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.data; + +import com.sun.hotspot.igv.data.Properties; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public class InputMethod extends Properties.Object { + + private String name; + private int bci; + private String shortName; + private List inlined; + private InputMethod parentMethod; + private Group group; + private List 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 --git a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputNode.java b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputNode.java new file mode 100644 index 0000000000000000000000000000000000000000..ad15d141ac9c61f98adfebb080e3ef4d9ed28cf7 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputNode.java @@ -0,0 +1,73 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.data; + +/** + * + * @author Thomas Wuerthinger + */ +public class InputNode extends Properties.Object { + + private int id; + + 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; + if (n.id != id) { + return false; + } + return getProperties().equals(n.getProperties()); + } + + @Override + public int hashCode() { + return id; + } + + @Override + public String toString() { + return "Node " + id + " " + getProperties().toString(); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Pair.java b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Pair.java new file mode 100644 index 0000000000000000000000000000000000000000..3becd18cbc5819bb585aebae847b00f16fa18bb7 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Pair.java @@ -0,0 +1,72 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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 instanceof Pair)) { + return false; + } + Pair obj = (Pair) o; + return l.equals(obj.l) && r.equals(obj.r); + } + + @Override + public int hashCode() { + return l.hashCode() * 71 + r.hashCode(); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Properties.java b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Properties.java new file mode 100644 index 0000000000000000000000000000000000000000..07a29962f9ff8643e853507490cf0e7eb1c7638e --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Properties.java @@ -0,0 +1,288 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.data; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * + * @author Thomas Wuerthinger + */ +public class Properties implements Serializable { + + public static final long serialVersionUID = 1L; + private Map map; + + public Properties() { + map = new HashMap(5); + } + + @Override + public boolean equals(java.lang.Object o) { + if (!(o instanceof Properties)) { + return false; + } + + Properties p = (Properties) o; + + if (getProperties().size() != p.getProperties().size()) { + return false; + } + for (Property prop : getProperties()) { + String value = p.get(prop.getName()); + if (value == null || !value.equals(prop.getValue())) { + return false; + } + } + return true; + } + + @Override + public int hashCode() { + int hash = 5; + hash = 83 * hash + (this.map != null ? this.map.hashCode() : 0); + return hash; + } + + public Properties(String name, String value) { + this(); + this.add(new Property(name, value)); + } + + public Properties(String name, String value, String name1, String value1) { + this(name, value); + this.add(new Property(name1, value1)); + } + + public Properties(String name, String value, String name1, String value1, String name2, String value2) { + this(name, value, name1, value1); + this.add(new Property(name2, value2)); + } + + public Properties(Properties p) { + map = new HashMap(p.map); + } + + public static class Object implements Provider { + + private Properties properties; + + public Object() { + properties = new Properties(); + } + + public Object(Properties.Object object) { + properties = new Properties(object.getProperties()); + } + + 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; + } + + public String getName() { + return matcher.getName(); + } + + public boolean match(String p) { + return !matcher.match(p); + } + } + + public static class StringPropertyMatcher implements PropertyMatcher { + + private String name; + private String value; + + public StringPropertyMatcher(String name, String value) { + this.name = name; + this.value = value; + } + + public String getName() { + return name; + } + + public boolean match(String p) { + return p.equals(value); + } + } + + public static class RegexpPropertyMatcher implements PropertyMatcher { + + private String name; + private Pattern valuePattern; + + public RegexpPropertyMatcher(String name, String value) { + this.name = name; + valuePattern = Pattern.compile(value); + } + + public String getName() { + return name; + } + + public boolean match(String p) { + Matcher m = valuePattern.matcher(p); + return m.matches(); + } + } + + public Property selectSingle(PropertyMatcher matcher) { + + Property p = this.map.get(matcher.getName()); + if (p == null) { + return null; + } + if (matcher.match(p.getValue())) { + return p; + } else { + return null; + } + } + + public interface Provider { + + public Properties getProperties(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("["); + for (Property p : map.values()) { + sb.append(p.toString()); + } + return sb.append("]").toString(); + } + + public static class PropertySelector { + + private Collection objects; + + public PropertySelector(Collection objects) { + this.objects = objects; + } + + public T selectSingle(final String name, final String value) { + return selectSingle(new StringPropertyMatcher(name, value)); + } + + 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(final String name, final String value) { + return selectMultiple(new StringPropertyMatcher(name, value)); + } + + 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) { + Property p = map.get(key); + if (p == null) { + return null; + } else { + return p.getValue(); + } + } + + public String getProperty(String string) { + return get(string); + } + + public Property setProperty(String name, String value) { + + if (value == null) { + // remove this property + return map.remove(name); + } else { + Property p = map.get(name); + if (p == null) { + p = new Property(name, value); + map.put(name, p); + } else { + p.setValue(value); + } + return p; + } + } + + public Collection getProperties() { + return Collections.unmodifiableCollection(map.values()); + } + + public void add(Properties properties) { + for (Property p : properties.getProperties()) { + add(p); + } + } + + public void add(Property property) { + assert property.getName() != null; + assert property.getValue() != null; + map.put(property.getName(), property); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Property.java b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Property.java new file mode 100644 index 0000000000000000000000000000000000000000..6694153d3b7f237fef27c14ff288d8a217af88bc --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Property.java @@ -0,0 +1,75 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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; + + public Property() { + this(null, null); + } + + public Property(Property p) { + this(p.getName(), p.getValue()); + } + + public Property(String name) { + this(name, null); + } + + public Property(String name, String value) { + this.name = name; + this.value = value; + } + + public String getName() { + return name; + } + + public String getValue() { + return value; + } + + public void setName(String s) { + this.name = s; + } + + public void setValue(String s) { + this.value = s; + } + + @Override + public String toString() { + return name + " = " + value + "; "; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/Parser.java b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/Parser.java new file mode 100644 index 0000000000000000000000000000000000000000..410ee7c41a854b9c547af4f86242e4448975ac00 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/Parser.java @@ -0,0 +1,422 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.data.serialization; + +import com.sun.hotspot.igv.data.GraphDocument; +import com.sun.hotspot.igv.data.Group; +import com.sun.hotspot.igv.data.InputBlock; +import com.sun.hotspot.igv.data.InputEdge; +import com.sun.hotspot.igv.data.InputGraph; +import com.sun.hotspot.igv.data.InputMethod; +import com.sun.hotspot.igv.data.InputNode; +import com.sun.hotspot.igv.data.Properties; +import com.sun.hotspot.igv.data.Property; +import com.sun.hotspot.igv.data.services.GroupCallback; +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 java.io.IOException; +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 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 TO_INDEX_PROPERTY = "index"; + 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 boolean difference; + private GroupCallback groupCallback; + // + private ElementHandler topHandler = new ElementHandler(TOP_ELEMENT) { + + @Override + protected GraphDocument start() throws SAXException { + return new GraphDocument(); + } + }; + // + private ElementHandler groupHandler = new XMLParser.ElementHandler(GROUP_ELEMENT) { + + @Override + protected Group start() throws SAXException { + Group group = new Group(); + Parser.this.difference = false; + String differenceProperty = this.readAttribute(DIFFERENCE_PROPERTY); + if (differenceProperty != null && (differenceProperty.equals("1") || differenceProperty.equals("true"))) { + Parser.this.difference = true; + } + + ParseMonitor monitor = getMonitor(); + if (monitor != null) { + monitor.setState(group.getName()); + } + + return group; + } + + @Override + protected void end(String text) throws SAXException { + if (groupCallback == null) { + getParentObject().addGroup(getObject()); + } + } + }; + private HandoverElementHandler assemblyHandler = new XMLParser.HandoverElementHandler(ASSEMBLY_ELEMENT, true) { + + @Override + protected void end(String text) throws SAXException { + getParentObject().setAssembly(text); + } + }; + // + 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) { + + private InputGraph graph; + + @Override + protected InputGraph start() throws SAXException { + + String name = readAttribute(GRAPH_NAME_PROPERTY); + InputGraph previous = getParentObject().getLastAdded(); + if (!difference) { + previous = null; + } + InputGraph curGraph = new InputGraph(getParentObject(), previous, name); + getParentObject().addGraph(curGraph); + this.graph = curGraph; + return curGraph; + } + + @Override + protected void end(String text) throws SAXException { + graph.resolveBlockLinks(); + } + }; + // + 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 = new InputBlock(getParentObject(), name); + graph.addBlock(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 = Integer.parseInt(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); + getParentObject().addSuccessor(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 = Integer.parseInt(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 = Integer.parseInt(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 static class EdgeElementHandler extends ElementHandler { + + public EdgeElementHandler(String name) { + super(name); + } + + @Override + protected InputEdge start() throws SAXException { + int toIndex = 0; + int from = -1; + int to = -1; + + try { + String toIndexString = readAttribute(TO_INDEX_PROPERTY); + if (toIndexString != null) { + toIndex = Integer.parseInt(toIndexString); + } + + from = Integer.parseInt(readRequiredAttribute(FROM_PROPERTY)); + to = Integer.parseInt(readRequiredAttribute(TO_PROPERTY)); + } catch (NumberFormatException e) { + throw new SAXException(e); + } + + + InputEdge conn = new InputEdge((char) toIndex, from, to); + 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) { + groupCallback.started(getParentObject()); + } + } + }; + // + private ElementHandler propertyHandler = new XMLParser.ElementHandler(PROPERTY_ELEMENT, true) { + + @Override + public Property start() throws SAXException { + String value = ""; + String name = readRequiredAttribute(PROPERTY_NAME_PROPERTY).intern(); + return getParentObject().getProperties().setProperty(name, value); + } + + @Override + public void end(String text) { + getObject().setValue(text.trim().intern()); + } + }; + + public Parser() { + this(null); + } + + public Parser(GroupCallback groupCallback) { + + this.groupCallback = groupCallback; + + // Initialize dependencies + xmlDocument.addChild(topHandler); + topHandler.addChild(groupHandler); + + groupHandler.addChild(methodHandler); + groupHandler.addChild(assemblyHandler); + groupHandler.addChild(graphHandler); + + 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(XMLReader reader, InputSource source, XMLParser.ParseMonitor monitor) throws SAXException { + reader.setContentHandler(new XMLParser(xmlDocument, monitor)); + try { + reader.parse(source); + } catch (IOException ex) { + throw new SAXException(ex); + } + + return topHandler.getObject(); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/Printer.java b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/Printer.java new file mode 100644 index 0000000000000000000000000000000000000000..c5b794fce2f7ce54ae0a6fbf0406a4df3fbe7784 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/Printer.java @@ -0,0 +1,217 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.data.serialization; + +import com.sun.hotspot.igv.data.GraphDocument; +import com.sun.hotspot.igv.data.Group; +import com.sun.hotspot.igv.data.InputBlock; +import com.sun.hotspot.igv.data.InputBytecode; +import com.sun.hotspot.igv.data.InputEdge; +import com.sun.hotspot.igv.data.InputGraph; +import com.sun.hotspot.igv.data.InputMethod; +import com.sun.hotspot.igv.data.InputNode; +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.HashSet; +import java.util.Set; + +/** + * + * @author Thomas Wuerthinger + */ +public class Printer { + + 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 (Group g : document.getGroups()) { + export(xmlWriter, g); + } + + xmlWriter.endTag(); + xmlWriter.flush(); + } + + private void export(XMLWriter writer, Group g) throws IOException { + Properties attributes = new Properties(); + attributes.add(new Property("difference", Boolean.toString(true))); + writer.startTag(Parser.GROUP_ELEMENT, attributes); + writer.writeProperties(g.getProperties()); + + if (g.getMethod() != null) { + export(writer, g.getMethod()); + } + + InputGraph previous = null; + for (InputGraph graph : g.getGraphs()) { + export(writer, graph, previous, true); + previous = graph; + } + + 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())); + + 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(); + + 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(); + p.setProperty(Parser.TO_INDEX_PROPERTY, Integer.toString(edge.getToIndex())); + p.setProperty(Parser.TO_PROPERTY, Integer.toString(edge.getTo())); + p.setProperty(Parser.FROM_PROPERTY, Integer.toString(edge.getFrom())); + return p; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/XMLParser.java b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/XMLParser.java new file mode 100644 index 0000000000000000000000000000000000000000..1efcd06dec9de23d022ef124d0ad10104bd0984e --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/XMLParser.java @@ -0,0 +1,254 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.data.serialization; + +import com.sun.hotspot.igv.data.Property; +import com.sun.hotspot.igv.data.Properties; +import java.util.Hashtable; +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 T object; + private Attributes attr; + private StringBuilder currentText; + private ParseMonitor monitor; + private Hashtable> hashtable; + private boolean needsText; + private ElementHandler parentElement; + + public ElementHandler(String name) { + this(name, false); + } + + public ElementHandler getParentElement() { + return parentElement; + } + + public P getParentObject() { + return getParentElement().getObject(); + } + + protected boolean needsText() { + return needsText; + } + + public ElementHandler(String name, boolean needsText) { + this.hashtable = new Hashtable>(); + 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; + } + + 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).intern(); + String localName = attr.getLocalName(i).intern(); + p.add(new Property(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 = parentElement; + object = start(); + } + + protected T start() throws SAXException { + return null; + } + + protected void end(String text) throws SAXException { + + } + + public void endElement() throws SAXException { + end(currentText.toString()); + } + + 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); + } + + public void setDocumentLocator(Locator locator) { + if (monitor != null) { + monitor.setState("Starting parsing"); + } + } + + public void startDocument() throws SAXException { + } + + public void endDocument() throws SAXException { + } + + public void startPrefixMapping(String prefix, String uri) throws SAXException { + } + + public void endPrefixMapping(String prefix) throws SAXException { + } + + 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); + } + + public void endElement(String uri, String localName, String qName) throws SAXException { + ElementHandler handler = stack.pop(); + if (handler != null) { + handler.endElement(); + } + } + + 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); + } + } + + public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { + } + + public void processingInstruction(String target, String data) throws SAXException { + } + + public void skippedEntity(String name) throws SAXException { + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/XMLWriter.java b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/XMLWriter.java new file mode 100644 index 0000000000000000000000000000000000000000..e112dbf4f076591f422963658a314adde0c4260b --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/XMLWriter.java @@ -0,0 +1,128 @@ +/* + * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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); + } + + 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); + } + } + } + + public void flush() throws IOException { + inner.flush(); + } + + 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.getProperties()) { + 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.getProperties()) { + inner.write(" " + p.getName() + "=\""); + write(p.getValue().toCharArray()); + inner.write("\""); + } + + inner.write("/>\n"); + } + + public void writeProperties(Properties props) throws IOException { + if (props.getProperties().size() == 0) { + return; + } + + startTag(Parser.PROPERTIES_ELEMENT); + + for (Property p : props.getProperties()) { + startTag(Parser.PROPERTY_ELEMENT, new Properties(Parser.PROPERTY_NAME_PROPERTY, p.getName())); + this.write(p.getValue().toCharArray()); + endTag(); + } + + endTag(); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/GraphViewer.java b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/GraphViewer.java new file mode 100644 index 0000000000000000000000000000000000000000..153221d55e5d44648a2a178deae1fb0a81488841 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/GraphViewer.java @@ -0,0 +1,35 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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 --git a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/GroupCallback.java b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/GroupCallback.java new file mode 100644 index 0000000000000000000000000000000000000000..8b0115e84b155f5e75621bd7729ecdd17e4196c8 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/GroupCallback.java @@ -0,0 +1,36 @@ +/* + * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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 --git a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/GroupOrganizer.java b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/GroupOrganizer.java new file mode 100644 index 0000000000000000000000000000000000000000..90d61ebc10dc207180bcda65c05c97a55decb80c --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/GroupOrganizer.java @@ -0,0 +1,39 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.data.services; + +import com.sun.hotspot.igv.data.Group; +import com.sun.hotspot.igv.data.Pair; +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public interface GroupOrganizer { + + public String getName(); + + public List>> organize(List subFolders, List groups); +} diff --git a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/GroupReceiver.java b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/GroupReceiver.java new file mode 100644 index 0000000000000000000000000000000000000000..8b730c3e29166e61a09fe9f5e2c4df9c8b5d1028 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/GroupReceiver.java @@ -0,0 +1,35 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.data.services; + +import java.awt.Component; + +/** + * + * @author Thomas Wuerthinger + */ +public interface GroupReceiver { + + public Component init(GroupCallback callback); +} diff --git a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/InputGraphProvider.java b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/InputGraphProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..0006ec55a13bb46347fa1d03b98842cf0cc0d241 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/InputGraphProvider.java @@ -0,0 +1,40 @@ +/* + * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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 --git a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/Scheduler.java b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/Scheduler.java new file mode 100644 index 0000000000000000000000000000000000000000..18207df4c1f6f18e18a2842c902afe90f53185b7 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/Scheduler.java @@ -0,0 +1,38 @@ +/* + * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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 --git a/src/share/tools/IdealGraphVisualizer/Difference/build.xml b/src/share/tools/IdealGraphVisualizer/Difference/build.xml new file mode 100644 index 0000000000000000000000000000000000000000..bc11fd91f85ea92c550811b95213d3f4c986c395 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Difference/build.xml @@ -0,0 +1,8 @@ + + + + + + Builds, tests, and runs the project com.sun.hotspot.igv.difference. + + diff --git a/src/share/tools/IdealGraphVisualizer/Difference/manifest.mf b/src/share/tools/IdealGraphVisualizer/Difference/manifest.mf new file mode 100644 index 0000000000000000000000000000000000000000..febe22452a0704dd162839504976d74a5c339fbc --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Difference/manifest.mf @@ -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 --git a/src/share/tools/IdealGraphVisualizer/Difference/nbproject/build-impl.xml b/src/share/tools/IdealGraphVisualizer/Difference/nbproject/build-impl.xml new file mode 100644 index 0000000000000000000000000000000000000000..1c1b96a9deaa376b109c3a8a9169aeba1577f5c0 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Difference/nbproject/build-impl.xml @@ -0,0 +1,30 @@ + + + + + + You must set 'suite.dir' to point to your containing module suite + + + + + + + + + + + + + + + + + + + + + diff --git a/src/share/tools/IdealGraphVisualizer/Difference/nbproject/genfiles.properties b/src/share/tools/IdealGraphVisualizer/Difference/nbproject/genfiles.properties new file mode 100644 index 0000000000000000000000000000000000000000..1c01a0733d172fdb82f82241d3a0e492b01de72c --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Difference/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=1657ecfe +build.xml.script.CRC32=03909051 +build.xml.stylesheet.CRC32=79c3b980 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=1657ecfe +nbproject/build-impl.xml.script.CRC32=2208e770 +nbproject/build-impl.xml.stylesheet.CRC32=deb65f65 diff --git a/src/share/tools/IdealGraphVisualizer/Difference/nbproject/platform.properties b/src/share/tools/IdealGraphVisualizer/Difference/nbproject/platform.properties new file mode 100644 index 0000000000000000000000000000000000000000..68ad75e5766f33be5a65a19d28cc7605c5b50a1c --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Difference/nbproject/platform.properties @@ -0,0 +1,29 @@ +# Deprecated since 5.0u1; for compatibility with 5.0: +disabled.clusters=\ + apisupport1,\ + harness,\ + ide8,\ + java1,\ + nb6.0,\ + profiler2 +disabled.modules=\ + org.netbeans.core.execution,\ + org.netbeans.core.multiview,\ + org.netbeans.core.output2,\ + org.netbeans.modules.applemenu,\ + org.netbeans.modules.autoupdate.services,\ + org.netbeans.modules.autoupdate.ui,\ + org.netbeans.modules.core.kit,\ + org.netbeans.modules.favorites,\ + org.netbeans.modules.javahelp,\ + org.netbeans.modules.masterfs,\ + org.netbeans.modules.options.keymap,\ + org.netbeans.modules.sendopts,\ + org.netbeans.modules.templates,\ + org.openide.compat,\ + org.openide.execution,\ + org.openide.util.enumerations +enabled.clusters=\ + platform7 +nbjdk.active=JDK_1.6 +nbplatform.active=default diff --git a/src/share/tools/IdealGraphVisualizer/Difference/nbproject/project.properties b/src/share/tools/IdealGraphVisualizer/Difference/nbproject/project.properties new file mode 100644 index 0000000000000000000000000000000000000000..152f44eca60ab831869539ffae9192aa03915f3b --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Difference/nbproject/project.properties @@ -0,0 +1,2 @@ +javac.source=1.5 +javac.compilerargs=-Xlint -Xlint:-serial diff --git a/src/share/tools/IdealGraphVisualizer/Difference/nbproject/project.xml b/src/share/tools/IdealGraphVisualizer/Difference/nbproject/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..1225db629713bd96c86d14ad446c9840f06d0c9c --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Difference/nbproject/project.xml @@ -0,0 +1,23 @@ + + + org.netbeans.modules.apisupport.project + + + com.sun.hotspot.igv.difference + + + + com.sun.hotspot.igv.data + + + + 1.0 + + + + + com.sun.hotspot.igv.difference + + + + diff --git a/src/share/tools/IdealGraphVisualizer/Difference/nbproject/suite.properties b/src/share/tools/IdealGraphVisualizer/Difference/nbproject/suite.properties new file mode 100644 index 0000000000000000000000000000000000000000..29d7cc9bd6fdd81453543cdf1bcf1dab301e3a92 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Difference/nbproject/suite.properties @@ -0,0 +1 @@ +suite.dir=${basedir}/.. diff --git a/src/share/tools/IdealGraphVisualizer/Difference/src/com/sun/hotspot/igv/difference/Bundle.properties b/src/share/tools/IdealGraphVisualizer/Difference/src/com/sun/hotspot/igv/difference/Bundle.properties new file mode 100644 index 0000000000000000000000000000000000000000..5c4d7e177fb4b317fbc3d57e1998fad0d9e2051d --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Difference/src/com/sun/hotspot/igv/difference/Bundle.properties @@ -0,0 +1 @@ +OpenIDE-Module-Name=Difference diff --git a/src/share/tools/IdealGraphVisualizer/Difference/src/com/sun/hotspot/igv/difference/Difference.java b/src/share/tools/IdealGraphVisualizer/Difference/src/com/sun/hotspot/igv/difference/Difference.java new file mode 100644 index 0000000000000000000000000000000000000000..335344eb77bb43fd65bca60c442516da176fc6bf --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Difference/src/com/sun/hotspot/igv/difference/Difference.java @@ -0,0 +1,320 @@ +/* + * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ +package com.sun.hotspot.igv.difference; + +import com.sun.hotspot.igv.data.Group; +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.Property; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * + * @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(); + 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 Pair(n, nB)); + } + } + + return createDiff(a, b, pairs); + } + + private static InputGraph createDiff(InputGraph a, InputGraph b, Set pairs) { + Group g = new Group(); + g.setMethod(a.getGroup().getMethod()); + g.setAssembly(a.getGroup().getAssembly()); + g.getProperties().setProperty("name", "Difference"); + InputGraph graph = new InputGraph(g, null); + graph.setName(a.getName() + ", " + b.getName()); + graph.setIsDifferenceGraph(true); + + Set nodesA = new HashSet(a.getNodes()); + Set nodesB = new HashSet(b.getNodes()); + + Map inputNodeMap = new HashMap(); + for (Pair p : pairs) { + InputNode n = p.getN1(); + assert nodesA.contains(n); + InputNode nB = p.getN2(); + 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); + markAsChanged(n2, n, nB); + } + + for (InputNode n : nodesA) { + InputNode n2 = new InputNode(n); + graph.addNode(n2); + markAsNew(n2); + inputNodeMap.put(n, n2); + } + + for (InputNode n : nodesB) { + InputNode n2 = new InputNode(n); + n2.setId(-n2.getId()); + graph.addNode(n2); + markAsDeleted(n2); + inputNodeMap.put(n, n2); + } + + Set edgesA = a.getEdges(); + Set 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 index = e.getToIndex(); + + InputEdge newEdge = new InputEdge(index, nodeFrom.getId(), nodeTo.getId()); + if (!newEdges.contains(newEdge)) { + markAsNew(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 index = e.getToIndex(); + + InputEdge newEdge = new InputEdge(index, nodeFrom.getId(), nodeTo.getId()); + if (!newEdges.contains(newEdge)) { + markAsDeleted(newEdge); + newEdges.add(newEdge); + graph.addEdge(newEdge); + } else { + newEdges.remove(newEdge); + graph.removeEdge(newEdge); + markAsSame(newEdge); + newEdges.add(newEdge); + graph.addEdge(newEdge); + } + } + + g.addGraph(graph); + return graph; + } + + private static class Pair { + + private InputNode n1; + private InputNode n2; + + public Pair(InputNode n1, InputNode n2) { + this.n1 = n1; + this.n2 = n2; + } + + public double getValue() { + + double result = 0.0; + for (Property p : n1.getProperties().getProperties()) { + double faktor = 1.0; + for (String forbidden : IGNORE_PROPERTIES) { + if (p.getName().equals(forbidden)) { + faktor = 0.1; + break; + } + } + String p2 = n2.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; + } + } + + public InputNode getN1() { + return n1; + } + + public InputNode getN2() { + return n2; + } + } + + 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)) { + Pair p = new Pair(n, n2); + pairs.add(p); + } + } + } + + Set selectedPairs = new HashSet(); + while (pairs.size() > 0) { + + double min = Double.MAX_VALUE; + Pair minPair = null; + for (Pair 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 (Pair p : pairs) { + if (p.getN1() == minPair.getN1() || p.getN2() == minPair.getN2()) { + 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().getProperties()) { + String s = firstNode.getProperties().getProperty(p.getName()); + if (!p.getValue().equals(s)) { + difference = true; + n.getProperties().add(new Property(OLD_PREFIX + p.getName(), p.getValue())); + } + } + + for (Property p : firstNode.getProperties().getProperties()) { + String s = otherNode.getProperties().getProperty(p.getName()); + if (s == null && p.getValue().length() > 0) { + difference = true; + n.getProperties().add(new Property(OLD_PREFIX + p.getName(), "")); + } + } + + if (difference) { + n.getProperties().add(new Property(PROPERTY_STATE, VALUE_CHANGED)); + } else { + n.getProperties().add(new Property(PROPERTY_STATE, VALUE_SAME)); + } + } + + private static void markAsDeleted(InputNode n) { + n.getProperties().add(new Property(PROPERTY_STATE, VALUE_DELETED)); + } + + private static void markAsNew(InputNode n) { + n.getProperties().add(new Property(PROPERTY_STATE, VALUE_NEW)); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Filter/build.xml b/src/share/tools/IdealGraphVisualizer/Filter/build.xml new file mode 100644 index 0000000000000000000000000000000000000000..2182f70466c3381ea7aaf6cbabcd4e4117d38107 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Filter/build.xml @@ -0,0 +1,8 @@ + + + + + + Builds, tests, and runs the project com.sun.hotspot.igv.filter. + + diff --git a/src/share/tools/IdealGraphVisualizer/Filter/manifest.mf b/src/share/tools/IdealGraphVisualizer/Filter/manifest.mf new file mode 100644 index 0000000000000000000000000000000000000000..185ff360536c3b812b17178de87dec59eaad3e5d --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Filter/manifest.mf @@ -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 --git a/src/share/tools/IdealGraphVisualizer/Filter/nbproject/build-impl.xml b/src/share/tools/IdealGraphVisualizer/Filter/nbproject/build-impl.xml new file mode 100644 index 0000000000000000000000000000000000000000..363a56cc9d97743af403986924b414feb057c834 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Filter/nbproject/build-impl.xml @@ -0,0 +1,30 @@ + + + + + + You must set 'suite.dir' to point to your containing module suite + + + + + + + + + + + + + + + + + + + + + diff --git a/src/share/tools/IdealGraphVisualizer/Filter/nbproject/genfiles.properties b/src/share/tools/IdealGraphVisualizer/Filter/nbproject/genfiles.properties new file mode 100644 index 0000000000000000000000000000000000000000..0b45838e0769bba9982ebfec15ccf11bdb88b30c --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Filter/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=7c032ebf +build.xml.script.CRC32=3b022a25 +build.xml.stylesheet.CRC32=79c3b980 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=7c032ebf +nbproject/build-impl.xml.script.CRC32=26513f91 +nbproject/build-impl.xml.stylesheet.CRC32=deb65f65 diff --git a/src/share/tools/IdealGraphVisualizer/Filter/nbproject/platform.properties b/src/share/tools/IdealGraphVisualizer/Filter/nbproject/platform.properties new file mode 100644 index 0000000000000000000000000000000000000000..68ad75e5766f33be5a65a19d28cc7605c5b50a1c --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Filter/nbproject/platform.properties @@ -0,0 +1,29 @@ +# Deprecated since 5.0u1; for compatibility with 5.0: +disabled.clusters=\ + apisupport1,\ + harness,\ + ide8,\ + java1,\ + nb6.0,\ + profiler2 +disabled.modules=\ + org.netbeans.core.execution,\ + org.netbeans.core.multiview,\ + org.netbeans.core.output2,\ + org.netbeans.modules.applemenu,\ + org.netbeans.modules.autoupdate.services,\ + org.netbeans.modules.autoupdate.ui,\ + org.netbeans.modules.core.kit,\ + org.netbeans.modules.favorites,\ + org.netbeans.modules.javahelp,\ + org.netbeans.modules.masterfs,\ + org.netbeans.modules.options.keymap,\ + org.netbeans.modules.sendopts,\ + org.netbeans.modules.templates,\ + org.openide.compat,\ + org.openide.execution,\ + org.openide.util.enumerations +enabled.clusters=\ + platform7 +nbjdk.active=JDK_1.6 +nbplatform.active=default diff --git a/src/share/tools/IdealGraphVisualizer/Filter/nbproject/project.properties b/src/share/tools/IdealGraphVisualizer/Filter/nbproject/project.properties new file mode 100644 index 0000000000000000000000000000000000000000..152f44eca60ab831869539ffae9192aa03915f3b --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Filter/nbproject/project.properties @@ -0,0 +1,2 @@ +javac.source=1.5 +javac.compilerargs=-Xlint -Xlint:-serial diff --git a/src/share/tools/IdealGraphVisualizer/Filter/nbproject/project.xml b/src/share/tools/IdealGraphVisualizer/Filter/nbproject/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..31414d5503e0414b28b0cda0ee4d1bc3c62a5276 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Filter/nbproject/project.xml @@ -0,0 +1,80 @@ + + + org.netbeans.modules.apisupport.project + + + com.sun.hotspot.igv.filter + + + + com.sun.hotspot.igv.data + + + + 1.0 + + + + com.sun.hotspot.igv.graph + + + + 1.0 + + + + org.jdesktop.layout + + + + 1 + 1.4.1 + + + + org.openide.dialogs + + + + 7.5.1 + + + + org.openide.filesystems + + + + 7.3 + + + + org.openide.nodes + + + + 7.2.0.1 + + + + org.openide.util + + + + 7.9.0.1 + + + + org.openide.windows + + + + 6.16 + + + + + com.sun.hotspot.igv.filter + + + + diff --git a/src/share/tools/IdealGraphVisualizer/Filter/nbproject/suite.properties b/src/share/tools/IdealGraphVisualizer/Filter/nbproject/suite.properties new file mode 100644 index 0000000000000000000000000000000000000000..29d7cc9bd6fdd81453543cdf1bcf1dab301e3a92 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Filter/nbproject/suite.properties @@ -0,0 +1 @@ +suite.dir=${basedir}/.. diff --git a/src/share/tools/IdealGraphVisualizer/Filter/src/META-INF/services/com.sun.hotspot.igv.filter.ScriptEngineAbstraction b/src/share/tools/IdealGraphVisualizer/Filter/src/META-INF/services/com.sun.hotspot.igv.filter.ScriptEngineAbstraction new file mode 100644 index 0000000000000000000000000000000000000000..4ebfb455217336de99e15dc13e03d95e9bccf89f --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Filter/src/META-INF/services/com.sun.hotspot.igv.filter.ScriptEngineAbstraction @@ -0,0 +1 @@ +com.sun.hotspot.igv.filter.JavaSE6ScriptEngine \ No newline at end of file diff --git a/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/AbstractFilter.java b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/AbstractFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..d015e64189522ba3a4bab47bbd23f08d560ca471 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/AbstractFilter.java @@ -0,0 +1,60 @@ +/* + * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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(); + } + + public Properties getProperties() { + return properties; + } + + public OpenCookie getEditor() { + return null; + } + + public ChangedEvent getChangedEvent() { + return changedEvent; + } + + protected void fireChangedEvent() { + changedEvent.fire(); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/Bundle.properties b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/Bundle.properties new file mode 100644 index 0000000000000000000000000000000000000000..cd43cb80c2a8fe64dcd1160c34de204547cc51e3 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/Bundle.properties @@ -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 --git a/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/ColorFilter.java b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/ColorFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..f0dd2ca95cb091d2f6d3549c417802320ed9c88d --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/ColorFilter.java @@ -0,0 +1,138 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.filter; + +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.OutputSlot; +import com.sun.hotspot.igv.graph.Selector; +import com.sun.hotspot.igv.data.Properties; +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(); + } + + public String getName() { + return name; + } + + 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 --git a/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/CombineFilter.java b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/CombineFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..613ca154cf4fec6c65c30aca84409afeaf3f588c --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/CombineFilter.java @@ -0,0 +1,194 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.filter; + +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 com.sun.hotspot.igv.graph.OutputSlot; +import com.sun.hotspot.igv.data.Properties; +import com.sun.hotspot.igv.data.Properties.PropertyMatcher; +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(); + } + + public String getName() { + return name; + } + + 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; + } + } + } + + assert slot != null; + slot.setName(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()); + newConn.setColor(c.getColor()); + newConn.setStyle(c.getStyle()); + } + } + + figuresToRemove.add(f); + } + } else { + + for (Figure succ : successors) { + if (succ.getPredecessors().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.setName(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); + 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; + + public CombineRule(PropertyMatcher first, PropertyMatcher second) { + this(first, second, false); + + } + + public CombineRule(PropertyMatcher first, PropertyMatcher second, boolean reversed) { + this.first = first; + this.second = second; + this.reversed = reversed; + } + + public boolean isReversed() { + return reversed; + } + + public PropertyMatcher getFirstMatcher() { + return first; + } + + public PropertyMatcher getSecondMatcher() { + return second; + } + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/ConnectionFilter.java b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/ConnectionFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..d4057918483204c253c9a94f512e9f7ebc80cd61 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/ConnectionFilter.java @@ -0,0 +1,106 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.filter; + +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.OutputSlot; +import com.sun.hotspot.igv.graph.Selector; +import com.sun.hotspot.igv.data.Properties; +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(); + } + + public String getName() { + return name; + } + + 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 --git a/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/CustomFilter.java b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/CustomFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..762d8d2a22e71ffe7b5d73ae68d7945fe5f37fef --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/CustomFilter.java @@ -0,0 +1,159 @@ +/* + * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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.data.Property; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.Collection; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.cookies.OpenCookie; +import org.openide.filesystems.Repository; +import org.openide.filesystems.FileSystem; +import org.openide.filesystems.FileObject; +import org.openide.util.Exceptions; +import org.openide.util.Lookup; + +/** + * + * @author Thomas Wuerthinger + */ +public class CustomFilter extends AbstractFilter { + + public static final String JAVASCRIPT_HELPER_ID = "JavaScriptHelper"; + private static ScriptEngineAbstraction engine; + private String code; + private String name; + + public CustomFilter(String name, String code) { + this.name = name; + this.code = code; + getProperties().add(new Property("name", name)); + } + + 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() { + + public void open() { + openInEditor(); + } + }; + } + + public boolean openInEditor() { + EditFilterDialog dialog = new EditFilterDialog(CustomFilter.this); + dialog.setVisible(true); + return dialog.wasAccepted(); + } + + @Override + public String toString() { + return getName(); + } + + public static ScriptEngineAbstraction getEngine() { + if (engine == null) { + + ScriptEngineAbstraction chosen = null; + try { + Collection list = Lookup.getDefault().lookupAll(ScriptEngineAbstraction.class); + for (ScriptEngineAbstraction s : list) { + if (s.initialize(getJsHelperText())) { + if (chosen == null || !(chosen instanceof JavaSE6ScriptEngine)) { + chosen = s; + } + } + } + } catch (NoClassDefFoundError ncdfe) { + Logger.getLogger("global").log(Level.SEVERE, null, ncdfe); + } + + if (chosen == null) { + NotifyDescriptor message = new NotifyDescriptor.Message("Could not find a scripting engine. Please make sure that the Rhino scripting engine is available. Otherwise filter cannot be used.", NotifyDescriptor.ERROR_MESSAGE); + DialogDisplayer.getDefault().notifyLater(message); + chosen = new NullScriptEngine(); + } + + engine = chosen; + } + + return engine; + } + + 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 { + FileSystem fs = Repository.getDefault().getDefaultFileSystem(); + FileObject fo = fs.getRoot().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(); + } + + public void apply(Diagram d) { + getEngine().execute(d, code); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/EditFilterDialog.form b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/EditFilterDialog.form new file mode 100644 index 0000000000000000000000000000000000000000..58a40cd1c8ae8605053f4916998a6da4fce00c4a --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/EditFilterDialog.form @@ -0,0 +1,133 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/EditFilterDialog.java b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/EditFilterDialog.java new file mode 100644 index 0000000000000000000000000000000000000000..7383e7f82e5b879b103b1ebe713e0f6a24c3d9ed --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/EditFilterDialog.java @@ -0,0 +1,161 @@ +/* + * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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 --git a/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/Filter.java b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/Filter.java new file mode 100644 index 0000000000000000000000000000000000000000..2742ad28bb47db321b3d33319e9a35ff019cfdba --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/Filter.java @@ -0,0 +1,45 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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(); + + ChangedEvent getChangedEvent(); +} diff --git a/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/FilterChain.java b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/FilterChain.java new file mode 100644 index 0000000000000000000000000000000000000000..340c7483c2f42a242b8be53dea60e0cacc30376b --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/FilterChain.java @@ -0,0 +1,155 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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.data.ChangedEvent; +import com.sun.hotspot.igv.data.ChangedEventProvider; +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 boolean fireEvents; + + public FilterChain() { + filters = new ArrayList(); + changedEvent = new ChangedEvent(this); + this.fireEvents = true; + } + + public FilterChain(FilterChain f) { + this.filters = new ArrayList(f.filters); + changedEvent = new ChangedEvent(this); + this.fireEvents = true; + } + + 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 beginAtomic() { + this.fireEvents = false; + } + + public void endAtomic() { + this.fireEvents = true; + changedEvent.fire(); + } + + public void addFilter(Filter filter) { + assert filter != null; + filters.add(filter); + if (fireEvents) { + changedEvent.fire(); + } + } + + public void addFilterSameSequence(Filter filter) { + assert filter != null; + filters.add(filter); + if (fireEvents) { + changedEvent.fire(); + } + } + + public boolean containsFilter(Filter filter) { + return filters.contains(filter); + } + + public void removeFilter(Filter filter) { + assert filters.contains(filter); + filters.remove(filter); + if (fireEvents) { + 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); + } + if (fireEvents) { + 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); + } + if (fireEvents) { + changedEvent.fire(); + } + } + + public List getFilters() { + return Collections.unmodifiableList(filters); + } + + public void clear() { + filters.clear(); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/FilterChainProvider.java b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/FilterChainProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..d9ae82e0629bcbe383a34c39090a75aba7487511 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/FilterChainProvider.java @@ -0,0 +1,35 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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 --git a/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/FilterSetting.java b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/FilterSetting.java new file mode 100644 index 0000000000000000000000000000000000000000..aadd4bb32ecd8ad180d4744143d6dff4df9ea079 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/FilterSetting.java @@ -0,0 +1,82 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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 --git a/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/JavaSE6ScriptEngine.java b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/JavaSE6ScriptEngine.java new file mode 100644 index 0000000000000000000000000000000000000000..1ba7fbc123ab2a1fcdc8aeda709867eb2bd23ca5 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/JavaSE6ScriptEngine.java @@ -0,0 +1,68 @@ +/* + * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ +package com.sun.hotspot.igv.filter; + +import com.sun.hotspot.igv.graph.Diagram; +import javax.script.Bindings; +import javax.script.ScriptContext; +import javax.script.ScriptEngine; +import javax.script.ScriptEngineManager; +import javax.script.ScriptException; +import org.openide.util.Exceptions; + +/** + * + * @author Thomas Wuerthinger + */ +public class JavaSE6ScriptEngine implements ScriptEngineAbstraction { + + private ScriptEngine engine; + private Bindings bindings; + + public boolean initialize(String jsHelperText) { + try { + ScriptEngineManager sem = new ScriptEngineManager(); + ScriptEngine e = sem.getEngineByName("ECMAScript"); + engine = e; + e.eval(jsHelperText); + Bindings b = e.getContext().getBindings(ScriptContext.ENGINE_SCOPE); + b.put("IO", System.out); + bindings = b; + return true; + } catch (Exception e) { + return false; + } + } + + public void execute(Diagram d, String code) { + try { + Bindings b = bindings; + b.put("graph", d); + engine.eval(code, b); + } catch (ScriptException ex) { + Exceptions.printStackTrace(ex); + } + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/NullScriptEngine.java b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/NullScriptEngine.java new file mode 100644 index 0000000000000000000000000000000000000000..94f3848affb77c6e6fed5204493fdb4102a999f8 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/NullScriptEngine.java @@ -0,0 +1,40 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.filter; + +import com.sun.hotspot.igv.graph.Diagram; + +/** + * + * @author Thomas Wuerthinger + */ +public class NullScriptEngine implements ScriptEngineAbstraction { + + public boolean initialize(String jsHelperText) { + return true; + } + + public void execute(Diagram d, String code) { + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/RemoveFilter.java b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/RemoveFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..f43793ccffecb947fef150b212d294287247fdf8 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/RemoveFilter.java @@ -0,0 +1,132 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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.InputSlot; +import com.sun.hotspot.igv.graph.Selector; +import com.sun.hotspot.igv.data.Properties; +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(); + } + + public String getName() { + return name; + } + + public void apply(Diagram diagram) { + + for (RemoveRule r : rules) { + + List
list = r.getSelector().selected(diagram); + Set
figuresToRemove = new HashSet
(); + + List
protectedFigures = null; + if (r.getRemoveAllWithoutPredecessor()) { + protectedFigures = diagram.getRootFigures(); + } + + for (Figure f : list) { + if (r.getRemoveOnlyInputs()) { + List inputSlots = new ArrayList(); + for (InputSlot is : f.getInputSlots()) { + inputSlots.add(is); + } + for (InputSlot is : inputSlots) { + f.removeSlot(is); + } + + f.createInputSlot(); + } else { + figuresToRemove.add(f); + } + } + + if (r.getRemoveAllWithoutPredecessor()) { + boolean progress = true; + while (progress) { + List
rootFigures = diagram.getRootFigures(); + progress = false; + for (Figure f : rootFigures) { + if (!protectedFigures.contains(f)) { + figuresToRemove.add(f); + progress = true; + } + } + } + } + + diagram.removeAllFigures(figuresToRemove); + } + } + + public void addRule(RemoveRule rule) { + rules.add(rule); + } + + public static class RemoveRule { + + private Selector selector; + private boolean removeAllWithoutPredecessor; + private boolean removeOnlyInputs; + + public RemoveRule(Selector selector, boolean b) { + this(selector, b, false); + } + + public RemoveRule(Selector selector, boolean removeAllWithoutPredecessor, boolean removeOnlyInputs) { + this.selector = selector; + this.removeOnlyInputs = removeOnlyInputs; + this.removeAllWithoutPredecessor = removeAllWithoutPredecessor; + } + + public Selector getSelector() { + return selector; + } + + public boolean getRemoveOnlyInputs() { + return removeOnlyInputs; + } + + public boolean getRemoveAllWithoutPredecessor() { + return removeAllWithoutPredecessor; + } + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/RemoveInputsFilter.java b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/RemoveInputsFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..61b21a0652c7cd66c6f2bc77cbf8ac474e31804d --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/RemoveInputsFilter.java @@ -0,0 +1,143 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.filter; + +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 com.sun.hotspot.igv.graph.OutputSlot; +import com.sun.hotspot.igv.graph.Selector; +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(); + } + + public String getName() { + return name; + } + + 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.setName(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.getName()); + } + + first.setName(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 --git a/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/RemoveSelfLoopsFilter.java b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/RemoveSelfLoopsFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..c8fd54b1156c44b5c2ce60dbe252cedf7f0b6b18 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/RemoveSelfLoopsFilter.java @@ -0,0 +1,80 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.filter; + +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 com.sun.hotspot.igv.graph.OutputSlot; +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; + } + + public String getName() { + return name; + } + + 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().setName("Self Loop"); + } + } + } + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/ScriptEngineAbstraction.java b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/ScriptEngineAbstraction.java new file mode 100644 index 0000000000000000000000000000000000000000..065725ed3da5436f6ac3230923ade671974fc470 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/ScriptEngineAbstraction.java @@ -0,0 +1,38 @@ +/* + * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ +package com.sun.hotspot.igv.filter; + +import com.sun.hotspot.igv.graph.Diagram; + +/** + * + * @author Thomas Wuerthinger + */ +public interface ScriptEngineAbstraction { + + public boolean initialize(String jsHelperText); + + public void execute(Diagram d, String code); +} diff --git a/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/SplitFilter.java b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/SplitFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..e4c2554bda5c7af074a58eea445fcd795b25e1a3 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/SplitFilter.java @@ -0,0 +1,70 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.filter; + +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 com.sun.hotspot.igv.graph.OutputSlot; +import com.sun.hotspot.igv.graph.Selector; +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public class SplitFilter extends AbstractFilter { + + private String name; + private Selector selector; + + public SplitFilter(String name, Selector selector) { + this.name = name; + this.selector = selector; + } + + public String getName() { + return name; + } + + public void apply(Diagram d) { + List
list = selector.selected(d); + + for (Figure f : list) { + for (OutputSlot os : f.getOutputSlots()) { + for (Connection c : os.getConnections()) { + InputSlot is = c.getInputSlot(); + is.setName(f.getProperties().getProperty("dump_spec")); + String s = f.getProperties().getProperty("short_name"); + if (s != null) { + is.setShortName(s); + } + } + } + + d.removeFigure(f); + } + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/helper.js b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/helper.js new file mode 100644 index 0000000000000000000000000000000000000000..d45f682d63430b459a14dd01f107e348fc1332f0 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/helper.js @@ -0,0 +1,71 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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)), false, false)); + f.apply(graph); +} + +function split(property, regexp) { + var f = new SplitFilter("", new MatcherSelector(new Properties.RegexpPropertyMatcher(property, regexp))); + 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); +} + +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; diff --git a/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/layer.xml b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/layer.xml new file mode 100644 index 0000000000000000000000000000000000000000..32fe79fc1a8e2de2d0409250370efd6f515abbb6 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/layer.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/build.xml b/src/share/tools/IdealGraphVisualizer/FilterWindow/build.xml new file mode 100644 index 0000000000000000000000000000000000000000..e604ea7bcba681eef998b163601fa5eafe7e9a0c --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/FilterWindow/build.xml @@ -0,0 +1,8 @@ + + + + + + Builds, tests, and runs the project com.sun.hotspot.igv.filterwindow. + + diff --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/manifest.mf b/src/share/tools/IdealGraphVisualizer/FilterWindow/manifest.mf new file mode 100644 index 0000000000000000000000000000000000000000..ba1485636f6eef3cfe6e462ee1b1523bf6ca5697 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/FilterWindow/manifest.mf @@ -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 --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/nbproject/build-impl.xml b/src/share/tools/IdealGraphVisualizer/FilterWindow/nbproject/build-impl.xml new file mode 100644 index 0000000000000000000000000000000000000000..01265560daad173cf07a855e0737174caf53ef43 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/FilterWindow/nbproject/build-impl.xml @@ -0,0 +1,30 @@ + + + + + + You must set 'suite.dir' to point to your containing module suite + + + + + + + + + + + + + + + + + + + + + diff --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/nbproject/genfiles.properties b/src/share/tools/IdealGraphVisualizer/FilterWindow/nbproject/genfiles.properties new file mode 100644 index 0000000000000000000000000000000000000000..b9832d5e5967f5e6c48b829a8d7971a0a74cdace --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/FilterWindow/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=401b2654 +build.xml.script.CRC32=9c158403 +build.xml.stylesheet.CRC32=79c3b980 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=401b2654 +nbproject/build-impl.xml.script.CRC32=19fb08e0 +nbproject/build-impl.xml.stylesheet.CRC32=deb65f65 diff --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/nbproject/project.properties b/src/share/tools/IdealGraphVisualizer/FilterWindow/nbproject/project.properties new file mode 100644 index 0000000000000000000000000000000000000000..152f44eca60ab831869539ffae9192aa03915f3b --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/FilterWindow/nbproject/project.properties @@ -0,0 +1,2 @@ +javac.source=1.5 +javac.compilerargs=-Xlint -Xlint:-serial diff --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/nbproject/project.xml b/src/share/tools/IdealGraphVisualizer/FilterWindow/nbproject/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..7740f12aef910e6d8c724d4fa99881fbd49301f1 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/FilterWindow/nbproject/project.xml @@ -0,0 +1,109 @@ + + + org.netbeans.modules.apisupport.project + + + com.sun.hotspot.igv.filterwindow + + + + com.sun.hotspot.igv.data + + + + 1.0 + + + + com.sun.hotspot.igv.filter + + + + 1.0 + + + + com.sun.hotspot.igv.graph + + + + 1.0 + + + + com.sun.hotspot.igv.util + + + + 1.0 + + + + org.openide.actions + + + + 6.6.1.1 + + + + org.openide.dialogs + + + + 7.5.1 + + + + org.openide.explorer + + + + 6.12.1 + + + + org.openide.filesystems + + + + 7.3.1 + + + + org.openide.loaders + + + + 6.7.1 + + + + org.openide.nodes + + + + 7.2.1.1 + + + + org.openide.util + + + + 7.10.1.1 + + + + org.openide.windows + + + + 6.18.1 + + + + + + + diff --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/nbproject/suite.properties b/src/share/tools/IdealGraphVisualizer/FilterWindow/nbproject/suite.properties new file mode 100644 index 0000000000000000000000000000000000000000..29d7cc9bd6fdd81453543cdf1bcf1dab301e3a92 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/FilterWindow/nbproject/suite.properties @@ -0,0 +1 @@ +suite.dir=${basedir}/.. diff --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/src/META-INF/services/com.sun.hotspot.igv.filter.FilterChainProvider b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/META-INF/services/com.sun.hotspot.igv.filter.FilterChainProvider new file mode 100644 index 0000000000000000000000000000000000000000..a3cdc882cca85961b8f7b6d26c80d7ecea2dffd0 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/META-INF/services/com.sun.hotspot.igv.filter.FilterChainProvider @@ -0,0 +1 @@ +com.sun.hotspot.igv.filterwindow.FilterChainProviderImplementation diff --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/Bundle.properties b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/Bundle.properties new file mode 100644 index 0000000000000000000000000000000000000000..c7f2ba7357f89d07474e73753fe003b9ac2e90cb --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/Bundle.properties @@ -0,0 +1,3 @@ +OpenIDE-Module-Name=FilterWindow +CTL_FilterTopComponent=Filter Window +HINT_FilterTopComponent=This is a Filter window diff --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/CheckListView.java b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/CheckListView.java new file mode 100644 index 0000000000000000000000000000000000000000..911a7c7e5354e3df8fb18d4eacb389977d5ee855 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/CheckListView.java @@ -0,0 +1,52 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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 --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/CheckNode.java b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/CheckNode.java new file mode 100644 index 0000000000000000000000000000000000000000..d8f2e04abe01cdbc230a5f157728bacdf8dd8a5d --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/CheckNode.java @@ -0,0 +1,70 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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 --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/CheckNodeListModel.java b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/CheckNodeListModel.java new file mode 100644 index 0000000000000000000000000000000000000000..caf75023000eaa5c2521e79d8ad7ad8c9245abba --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/CheckNodeListModel.java @@ -0,0 +1,46 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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.nodes.Node; + +/** + * + * @author Thomas Wuerthinger + */ +public class CheckNodeListModel extends NodeListModel { + + private Node rootNode; + + @Override + public void setNode(Node rootNode) { + this.rootNode = rootNode; + super.setNode(rootNode); + } + + public CheckNode getCheckNodeAt(int index) { + return (CheckNode) rootNode.getChildren().getNodes()[index]; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/CheckRenderer.java b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/CheckRenderer.java new file mode 100644 index 0000000000000000000000000000000000000000..f37716ff04994f4195ff5d52fadcbcf85b058c24 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/CheckRenderer.java @@ -0,0 +1,88 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.filterwindow; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Point; +import java.awt.Rectangle; +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(); + } + + 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 --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/FilterChainProviderImplementation.java b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/FilterChainProviderImplementation.java new file mode 100644 index 0000000000000000000000000000000000000000..407ce3989abdb90e18197ae19718816319bad3eb --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/FilterChainProviderImplementation.java @@ -0,0 +1,42 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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 { + + public FilterChain getFilterChain() { + return FilterTopComponent.findInstance().getFilterChain(); + } + + public FilterChain getSequence() { + return FilterTopComponent.findInstance().getSequence(); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/FilterNode.java b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/FilterNode.java new file mode 100644 index 0000000000000000000000000000000000000000..962651327b3456f298996c2f0a9c8fb40fc5572e --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/FilterNode.java @@ -0,0 +1,112 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.filterwindow; + +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.filter.Filter; +import com.sun.hotspot.igv.filter.FilterChain; +import com.sun.hotspot.igv.data.ChangedListener; +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() { + + 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); + } + + 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()); + } + + public void resultChanged(LookupEvent lookupEvent) { + changed(FilterTopComponent.findInstance()); + } + + public void changed(FilterTopComponent source) { + setSelected(source.getFilterChain().containsFilter(filter)); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/FilterTopComponent.form b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/FilterTopComponent.form new file mode 100644 index 0000000000000000000000000000000000000000..f3fc524ebe3105669274fea8454266fd296494b9 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/FilterTopComponent.form @@ -0,0 +1,16 @@ + + +
+ + + + + + + + + + + + + diff --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/FilterTopComponent.java b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/FilterTopComponent.java new file mode 100644 index 0000000000000000000000000000000000000000..7cd32e8f6ef344225a69a88ca9c9b2c0b6f00bcc --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/FilterTopComponent.java @@ -0,0 +1,689 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.filterwindow; + +import com.sun.hotspot.igv.filterwindow.actions.MoveFilterDownAction; +import com.sun.hotspot.igv.filterwindow.actions.MoveFilterUpAction; +import com.sun.hotspot.igv.filterwindow.actions.NewFilterAction; +import com.sun.hotspot.igv.filterwindow.actions.RemoveFilterAction; +import com.sun.hotspot.igv.filterwindow.actions.RemoveFilterSettingsAction; +import com.sun.hotspot.igv.filterwindow.actions.SaveFilterSettingsAction; +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.data.ChangedEvent; +import com.sun.hotspot.igv.data.ChangedListener; +import java.awt.BorderLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Serializable; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +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.ToolbarPool; +import org.openide.explorer.ExplorerManager; +import org.openide.explorer.ExplorerUtils; +import org.openide.nodes.AbstractNode; +import org.openide.nodes.Children; +import org.openide.nodes.Node; +import org.openide.util.Exceptions; +import org.openide.util.Lookup; +import org.openide.util.LookupEvent; +import org.openide.util.LookupListener; +import org.openide.util.NbBundle; +import org.openide.util.Utilities; +import org.openide.awt.Toolbar; +import org.openide.filesystems.FileLock; +import org.openide.util.actions.SystemAction; +import org.openide.windows.TopComponent; +import org.openide.windows.WindowManager; +import org.openide.filesystems.Repository; +import org.openide.filesystems.FileSystem; +import org.openide.filesystems.FileObject; + +/** + * + * @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() { + + 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.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.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("Enter a name:", "Filter"); + 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 \"" + name + "\" already exists, to you want to overwrite?", "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() { + + 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 \"" + f + "\"?", "Filter"); + 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 Node[] oldSelection; + //private ArrayList newSelection; + private HashMap nodeHash = new HashMap(); + + protected Node[] createNodes(Object object) { + if (nodeHash.containsKey(object)) { + return new Node[]{nodeHash.get(object)}; + } + + assert object instanceof Filter; + Filter filter = (Filter) object; + com.sun.hotspot.igv.filterwindow.FilterNode node = new com.sun.hotspot.igv.filterwindow.FilterNode(filter); + node.getSelectionChangedEvent().addListener(this); + nodeHash.put(object, node); + return new Node[]{node}; + } + + public FilterChildren() { + sequence.getChangedEvent().addListener(new ChangedListener() { + + public void changed(FilterChain source) { + addNotify(); + } + }); + + setBefore(false); + } + + protected void addNotify() { + setKeys(sequence.getFilters()); + updateSelection(); + } + + 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;/* + EditorTopComponent tc = EditorTopComponent.getActive(); + if (tc == null) { + return filterChain; + } + return tc.getFilterChain();*/ + } + + 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(MoveFilterUpAction.get(MoveFilterUpAction.class).createContextAwareInstance(this.getLookup())); + toolBar.add(MoveFilterDownAction.get(MoveFilterDownAction.class).createContextAwareInstance(this.getLookup())); + toolBar.add(RemoveFilterAction.get(RemoveFilterAction.class).createContextAwareInstance(this.getLookup())); + toolBar.add(NewFilterAction.get(NewFilterAction.class)); + 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; + } + + 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); + Writer w = new OutputStreamWriter(os); + String s = filter.getCode(); + w.write(s); + w.close(); + lock.releaseLock(); + + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + } + + public void initFilters() { + + FileSystem fs = Repository.getDefault().getDefaultFileSystem(); + FileObject folder = fs.getRoot().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; + StringBuffer sb = new StringBuffer(); + 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; + } + + public void resultChanged(LookupEvent lookupEvent) { + setChain(Utilities.actionsGlobalContext().lookup(FilterChain.class)); + /* + EditorTopComponent tc = EditorTopComponent.getActive(); + if (tc != null) { + setChain(tc.getFilterChain()); + }*/ + } + + public void setChain(FilterChain chain) { + updateComboBoxSelection(); + } + + private FileObject getFileObject(CustomFilter cf) { + FileObject fo = Repository.getDefault().getDefaultFileSystem().getRoot().getFileObject(FOLDER_ID + "/" + cf.getName()); + if (fo == null) { + try { + fo = org.openide.filesystems.Repository.getDefault().getDefaultFileSystem().getRoot().getFileObject(FOLDER_ID).createData(cf.getName()); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + return fo; + } + + @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 --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/FilterTopComponentSettings.xml b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/FilterTopComponentSettings.xml new file mode 100644 index 0000000000000000000000000000000000000000..6ae22f0fcd8e5d5a1c78c3ede13edb6901fe962c --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/FilterTopComponentSettings.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/FilterTopComponentWstcref.xml b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/FilterTopComponentWstcref.xml new file mode 100644 index 0000000000000000000000000000000000000000..cc493bc5d6df7659a575880f12a1381673149dea --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/FilterTopComponentWstcref.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/Bundle.properties b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/Bundle.properties new file mode 100644 index 0000000000000000000000000000000000000000..8cf238dc8c3d40bfff76a8b238efb712de076617 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/Bundle.properties @@ -0,0 +1,10 @@ +# To change this template, choose Tools | Templates +# and open the template in the editor. + +CTL_FilterAction=Open Filter Window +CTL_MoveFilterDownAction=Move downwards +CTL_MoveFilterUpAction=Move upwards +CTL_NewFilterAction=New filter... +CTL_RemoveFilterAction=Remove +CTL_RemoveFilterSettingsAction=Remove filter setting +CTL_SaveFilterSettingsAction=Save filter settings... diff --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/FilterAction.java b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/FilterAction.java new file mode 100644 index 0000000000000000000000000000000000000000..ad2d1e435b1d401e05e64efee66ce628863f91ee --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/FilterAction.java @@ -0,0 +1,47 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.filterwindow.actions; + +import com.sun.hotspot.igv.filterwindow.*; +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")); + } + + public void actionPerformed(ActionEvent evt) { + TopComponent win = FilterTopComponent.findInstance(); + win.open(); + win.requestActive(); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/MoveFilterDownAction.java b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/MoveFilterDownAction.java new file mode 100644 index 0000000000000000000000000000000000000000..c2849fc1163b82c7df00e0c6561d9fb10cb05eb7 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/MoveFilterDownAction.java @@ -0,0 +1,85 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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 com.sun.hotspot.igv.filter.Filter; +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 { + + protected void performAction(Node[] activatedNodes) { + for (Node n : activatedNodes) { + Filter c = n.getLookup().lookup(Filter.class); + FilterTopComponent.findInstance().getSequence().moveFilterDown(c); + } + } + + protected int mode() { + return CookieAction.MODE_EXACTLY_ONE; + } + + public MoveFilterDownAction() { + + putValue(Action.SHORT_DESCRIPTION, "Move filter downwards"); + } + + public String getName() { + return NbBundle.getMessage(MoveFilterUpAction.class, "CTL_MoveFilterDownAction"); + } + + protected Class[] cookieClasses() { + return new Class[]{ + Filter.class + }; + } + + @Override + protected String iconResource() { + return "com/sun/hotspot/igv/filterwindow/images/down.gif"; + } + + @Override + protected void initialize() { + super.initialize(); + putValue("noIconInMenu", Boolean.TRUE); + } + + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + @Override + protected boolean asynchronous() { + return false; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/MoveFilterUpAction.java b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/MoveFilterUpAction.java new file mode 100644 index 0000000000000000000000000000000000000000..c75238ba05c41ec89fbb86755cf627c1bac53289 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/MoveFilterUpAction.java @@ -0,0 +1,84 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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 com.sun.hotspot.igv.filter.Filter; +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 { + + protected void performAction(Node[] activatedNodes) { + for (Node n : activatedNodes) { + Filter c = n.getLookup().lookup(Filter.class); + FilterTopComponent.findInstance().getSequence().moveFilterUp(c); + } + } + + protected int mode() { + return CookieAction.MODE_EXACTLY_ONE; + } + + public MoveFilterUpAction() { + putValue(Action.SHORT_DESCRIPTION, "Move filter upwards"); + } + + public String getName() { + return NbBundle.getMessage(MoveFilterUpAction.class, "CTL_MoveFilterUpAction"); + } + + protected Class[] cookieClasses() { + return new Class[]{ + Filter.class + }; + } + + @Override + protected String iconResource() { + return "com/sun/hotspot/igv/filterwindow/images/up.gif"; + } + + @Override + protected void initialize() { + super.initialize(); + putValue("noIconInMenu", Boolean.TRUE); + } + + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + @Override + protected boolean asynchronous() { + return false; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/NewFilterAction.java b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/NewFilterAction.java new file mode 100644 index 0000000000000000000000000000000000000000..22bb760613dedacc7c9b55b22cf99889d65778bb --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/NewFilterAction.java @@ -0,0 +1,68 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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"); + } + + public void performAction() { + FilterTopComponent.findInstance().newFilter(); + } + + public String getName() { + return NbBundle.getMessage(SaveFilterSettingsAction.class, "CTL_NewFilterAction"); + } + + @Override + protected void initialize() { + super.initialize(); + } + + 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.gif"; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/RemoveFilterAction.java b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/RemoveFilterAction.java new file mode 100644 index 0000000000000000000000000000000000000000..86d8577f2c86b2bfcd95a790d069e69bacdabdce --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/RemoveFilterAction.java @@ -0,0 +1,99 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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 com.sun.hotspot.igv.filter.Filter; +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 { + + 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?", + 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)); + } + } + } + + protected int mode() { + return CookieAction.MODE_ALL; + } + + public String getName() { + return NbBundle.getMessage(RemoveFilterAction.class, "CTL_RemoveFilterAction"); + } + + public RemoveFilterAction() { + putValue(Action.SHORT_DESCRIPTION, "Remove filter"); + } + + 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.gif"; + } + + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + @Override + protected boolean asynchronous() { + return false; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/RemoveFilterSettingsAction.java b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/RemoveFilterSettingsAction.java new file mode 100644 index 0000000000000000000000000000000000000000..ead48f27cde7b15241286498bc8d721d9efc9351 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/RemoveFilterSettingsAction.java @@ -0,0 +1,68 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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 { + + public void performAction() { + FilterTopComponent.findInstance().removeFilterSetting(); + } + + public String getName() { + return NbBundle.getMessage(RemoveFilterSettingsAction.class, "CTL_RemoveFilterSettingsAction"); + } + + public RemoveFilterSettingsAction() { + putValue(Action.SHORT_DESCRIPTION, "Remove filter profile"); + } + + @Override + protected void initialize() { + super.initialize(); + } + + 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.gif"; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/SaveFilterSettingsAction.java b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/SaveFilterSettingsAction.java new file mode 100644 index 0000000000000000000000000000000000000000..59d5b7895944411c0edcac7b5db59feb7233329d --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/actions/SaveFilterSettingsAction.java @@ -0,0 +1,68 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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 { + + public void performAction() { + FilterTopComponent.findInstance().addFilterSetting(); + } + + public String getName() { + return NbBundle.getMessage(SaveFilterSettingsAction.class, "CTL_SaveFilterSettingsAction"); + } + + @Override + protected void initialize() { + super.initialize(); + } + + public SaveFilterSettingsAction() { + putValue(Action.SHORT_DESCRIPTION, "Create new filter profile"); + } + + 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.gif"; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/customRightTopWsmode.xml b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/customRightTopWsmode.xml new file mode 100644 index 0000000000000000000000000000000000000000..ca1b2772e896a5dec8630016278a47c35595e2c7 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/customRightTopWsmode.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/images/add.gif b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/images/add.gif new file mode 100644 index 0000000000000000000000000000000000000000..0fc47e193cf88cea7e6718e602e71f560cfad5cd Binary files /dev/null and b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/images/add.gif differ diff --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/images/delete.gif b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/images/delete.gif new file mode 100644 index 0000000000000000000000000000000000000000..3f83fce4b9a1a5b0877c01c48194a3075b94c691 Binary files /dev/null and b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/images/delete.gif differ diff --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/images/down.gif b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/images/down.gif new file mode 100644 index 0000000000000000000000000000000000000000..6123422dddedce65fce1f19a1aa5bde5396bb4e8 Binary files /dev/null and b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/images/down.gif differ diff --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/images/minus.gif b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/images/minus.gif new file mode 100644 index 0000000000000000000000000000000000000000..ba0d281cf907caa6f1265f5149aaad845788d74c Binary files /dev/null and b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/images/minus.gif differ diff --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/images/plus.gif b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/images/plus.gif new file mode 100644 index 0000000000000000000000000000000000000000..5e2274da3fceb3ed25678305ddafc4bb8352385b Binary files /dev/null and b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/images/plus.gif differ diff --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/images/up.gif b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/images/up.gif new file mode 100644 index 0000000000000000000000000000000000000000..277f5bb492bb3d8be707aa649c5856682ac6f9c8 Binary files /dev/null and b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/images/up.gif differ diff --git a/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/layer.xml b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/layer.xml new file mode 100644 index 0000000000000000000000000000000000000000..8d1367e773afd8f680c946336d27cd235b7bd856 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/FilterWindow/src/com/sun/hotspot/igv/filterwindow/layer.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/share/tools/IdealGraphVisualizer/Graph/build.xml b/src/share/tools/IdealGraphVisualizer/Graph/build.xml new file mode 100644 index 0000000000000000000000000000000000000000..7843b57f1d5942f4a32715820b667926fbe436e5 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Graph/build.xml @@ -0,0 +1,8 @@ + + + + + + Builds, tests, and runs the project com.sun.hotspot.igv.graph. + + diff --git a/src/share/tools/IdealGraphVisualizer/Graph/manifest.mf b/src/share/tools/IdealGraphVisualizer/Graph/manifest.mf new file mode 100644 index 0000000000000000000000000000000000000000..aee3b0e8ec588d29f3d67d031bcc61cd27acddf9 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Graph/manifest.mf @@ -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 --git a/src/share/tools/IdealGraphVisualizer/Graph/nbproject/build-impl.xml b/src/share/tools/IdealGraphVisualizer/Graph/nbproject/build-impl.xml new file mode 100644 index 0000000000000000000000000000000000000000..d4b873896f222de514dbbffbe02f6701a103ceca --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Graph/nbproject/build-impl.xml @@ -0,0 +1,30 @@ + + + + + + You must set 'suite.dir' to point to your containing module suite + + + + + + + + + + + + + + + + + + + + + diff --git a/src/share/tools/IdealGraphVisualizer/Graph/nbproject/genfiles.properties b/src/share/tools/IdealGraphVisualizer/Graph/nbproject/genfiles.properties new file mode 100644 index 0000000000000000000000000000000000000000..473f81981cdb78ec4c1733c86e57afa334910791 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Graph/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=b2bc2f02 +build.xml.script.CRC32=486d5dab +build.xml.stylesheet.CRC32=79c3b980 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=b2bc2f02 +nbproject/build-impl.xml.script.CRC32=17fa0f49 +nbproject/build-impl.xml.stylesheet.CRC32=deb65f65 diff --git a/src/share/tools/IdealGraphVisualizer/Graph/nbproject/platform.properties b/src/share/tools/IdealGraphVisualizer/Graph/nbproject/platform.properties new file mode 100644 index 0000000000000000000000000000000000000000..68ad75e5766f33be5a65a19d28cc7605c5b50a1c --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Graph/nbproject/platform.properties @@ -0,0 +1,29 @@ +# Deprecated since 5.0u1; for compatibility with 5.0: +disabled.clusters=\ + apisupport1,\ + harness,\ + ide8,\ + java1,\ + nb6.0,\ + profiler2 +disabled.modules=\ + org.netbeans.core.execution,\ + org.netbeans.core.multiview,\ + org.netbeans.core.output2,\ + org.netbeans.modules.applemenu,\ + org.netbeans.modules.autoupdate.services,\ + org.netbeans.modules.autoupdate.ui,\ + org.netbeans.modules.core.kit,\ + org.netbeans.modules.favorites,\ + org.netbeans.modules.javahelp,\ + org.netbeans.modules.masterfs,\ + org.netbeans.modules.options.keymap,\ + org.netbeans.modules.sendopts,\ + org.netbeans.modules.templates,\ + org.openide.compat,\ + org.openide.execution,\ + org.openide.util.enumerations +enabled.clusters=\ + platform7 +nbjdk.active=JDK_1.6 +nbplatform.active=default diff --git a/src/share/tools/IdealGraphVisualizer/Graph/nbproject/project.properties b/src/share/tools/IdealGraphVisualizer/Graph/nbproject/project.properties new file mode 100644 index 0000000000000000000000000000000000000000..152f44eca60ab831869539ffae9192aa03915f3b --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Graph/nbproject/project.properties @@ -0,0 +1,2 @@ +javac.source=1.5 +javac.compilerargs=-Xlint -Xlint:-serial diff --git a/src/share/tools/IdealGraphVisualizer/Graph/nbproject/project.xml b/src/share/tools/IdealGraphVisualizer/Graph/nbproject/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..c8fbe3c294f56199725f6cb86cd92742f7485231 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Graph/nbproject/project.xml @@ -0,0 +1,31 @@ + + + org.netbeans.modules.apisupport.project + + + com.sun.hotspot.igv.graph + + + + com.sun.hotspot.igv.data + + + + 1.0 + + + + com.sun.hotspot.igv.layout + + + + 1.0 + + + + + com.sun.hotspot.igv.graph + + + + diff --git a/src/share/tools/IdealGraphVisualizer/Graph/nbproject/suite.properties b/src/share/tools/IdealGraphVisualizer/Graph/nbproject/suite.properties new file mode 100644 index 0000000000000000000000000000000000000000..29d7cc9bd6fdd81453543cdf1bcf1dab301e3a92 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Graph/nbproject/suite.properties @@ -0,0 +1 @@ +suite.dir=${basedir}/.. diff --git a/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/AndSelector.java b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/AndSelector.java new file mode 100644 index 0000000000000000000000000000000000000000..d15ed8d152db23062a3c2635a233faa39d473b31 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/AndSelector.java @@ -0,0 +1,54 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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; + } + + 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 --git a/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Block.java b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Block.java new file mode 100644 index 0000000000000000000000000000000000000000..eaa73b70519eab4005c197f388178f723caf35fa --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Block.java @@ -0,0 +1,82 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.graph; + +import com.sun.hotspot.igv.data.InputBlock; +import com.sun.hotspot.igv.layout.Cluster; +import java.awt.Rectangle; +import java.util.HashSet; +import java.util.Set; + +/** + * + * @author Thomas Wuerthinger + */ +public class Block implements Cluster { + + private InputBlock inputBlock; + private Rectangle bounds; + private Diagram diagram; + + public Block(InputBlock inputBlock, Diagram diagram) { + this.inputBlock = inputBlock; + this.diagram = diagram; + } + + public Cluster getOuter() { + return null; + } + + public InputBlock getInputBlock() { + return inputBlock; + } + + public Set getSuccessors() { + Set succs = new HashSet(); + for (InputBlock b : inputBlock.getSuccessors()) { + succs.add(diagram.getBlock(b)); + } + return succs; + } + + public Set getPredecessors() { + Set succs = new HashSet(); + for (InputBlock b : inputBlock.getPredecessors()) { + succs.add(diagram.getBlock(b)); + } + return succs; + } + + public void setBounds(Rectangle r) { + this.bounds = r; + } + + public Rectangle getBounds() { + return bounds; + } + + public int compareTo(Cluster o) { + return toString().compareTo(o.toString()); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Bundle.properties b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Bundle.properties new file mode 100644 index 0000000000000000000000000000000000000000..b7434e09e9833dc959107039cf8085f07ab7421e --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Bundle.properties @@ -0,0 +1 @@ +OpenIDE-Module-Name=Graph diff --git a/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Connection.java b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Connection.java new file mode 100644 index 0000000000000000000000000000000000000000..8c027b0b3c307ee2d6c698e23e9bb539f568ce85 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Connection.java @@ -0,0 +1,123 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.graph; + +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 { + + public enum ConnectionStyle { + + NORMAL, + DASHED, + BOLD + } + private InputSlot inputSlot; + private OutputSlot outputSlot; + private Source source; + private Color color; + private ConnectionStyle style; + private List controlPoints; + + protected Connection(InputSlot inputSlot, OutputSlot outputSlot) { + this.inputSlot = inputSlot; + this.outputSlot = outputSlot; + 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; + } + + public Source getSource() { + return source; + } + + public void remove() { + inputSlot.getFigure().removePredecessor(outputSlot.getFigure()); + inputSlot.connections.remove(this); + outputSlot.getFigure().removeSuccessor(inputSlot.getFigure()); + outputSlot.connections.remove(this); + } + + @Override + public String toString() { + return "Connection(" + getFrom().getVertex() + " to " + getTo().getVertex() + ")"; + } + + public Port getFrom() { + return outputSlot; + } + + public Port getTo() { + return inputSlot; + } + + public List getControlPoints() { + return controlPoints; + } + + public void setControlPoints(List list) { + controlPoints = list; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Diagram.java b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Diagram.java new file mode 100644 index 0000000000000000000000000000000000000000..00d48f6e9267e73fa4e24e2cde7232ba1477f9ec --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Diagram.java @@ -0,0 +1,294 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.graph; + +import com.sun.hotspot.igv.data.InputBlock; +import com.sun.hotspot.igv.data.InputEdge; +import com.sun.hotspot.igv.data.InputGraph; +import com.sun.hotspot.igv.data.InputNode; +import com.sun.hotspot.igv.data.Properties; +import java.awt.Font; +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.Hashtable; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * + * @author Thomas Wuerthinger + */ +public class Diagram { + + private List
figures; + private Map blocks; + private InputGraph graph; + private int curId; + private String nodeText; + private Font font; + + public Font getFont() { + return font; + } + + private Diagram() { + figures = new ArrayList
(); + blocks = new HashMap(); + this.nodeText = ""; + this.font = new Font("Serif", Font.PLAIN, 14); + } + + public Block getBlock(InputBlock b) { + return blocks.get(b); + } + + public String getNodeText() { + return nodeText; + } + + public void schedule(Collection newBlocks) { + graph.schedule(newBlocks); + updateBlocks(); + } + + private void updateBlocks() { + blocks.clear(); + for (InputBlock b : graph.getBlocks()) { + Block curBlock = new Block(b, this); + blocks.put(b, curBlock); + } + } + + public Diagram getNext() { + return Diagram.createDiagram(graph.getNext(), nodeText); + } + + public Collection getBlocks() { + return Collections.unmodifiableCollection(blocks.values()); + } + + 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) { + assert inputSlot.getFigure().getDiagram() == this; + assert outputSlot.getFigure().getDiagram() == this; + return new Connection(inputSlot, outputSlot); + } + + public static Diagram createDiagram(InputGraph graph, String nodeText) { + if (graph == null) { + return null; + } + + Diagram d = new Diagram(); + d.graph = graph; + d.nodeText = nodeText; + + d.updateBlocks(); + + 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; + + int toIndex = e.getToIndex(); + + while (fromFigure.getOutputSlots().size() <= 0) { + fromFigure.createOutputSlot(); + } + + OutputSlot outputSlot = fromFigure.getOutputSlots().get(0); + + while (toFigure.getInputSlots().size() <= toIndex) { + toFigure.createInputSlot(); + } + + InputSlot inputSlot = toFigure.getInputSlots().get(toIndex); + + Connection c = d.createConnection(inputSlot, outputSlot); + + 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("name", "Root"); + if (root == null) { + root = selector.selectSingle("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
() { + + 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 --git a/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Figure.java b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Figure.java new file mode 100644 index 0000000000000000000000000000000000000000..cfb913ca31887e3638b12ab773ddf1489ef3ebab --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Figure.java @@ -0,0 +1,328 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.graph; + +import com.sun.hotspot.igv.layout.Cluster; +import com.sun.hotspot.igv.layout.Vertex; +import com.sun.hotspot.igv.data.Properties; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.Point; +import java.awt.image.BufferedImage; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * + * @author Thomas Wuerthinger + */ +public class Figure extends Properties.Object implements Source.Provider, Vertex { + + public static final int INSET = 6; + public static final int SLOT_WIDTH = 10; + public static final int SLOT_START = 3; + 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()); + FontMetrics metrics = g.getFontMetrics(); + String nodeText = diagram.getNodeText(); + heightCash = nodeText.split("\n").length * metrics.getHeight() + INSET; + } + return heightCash; + } + + 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()); + FontMetrics metrics = g.getFontMetrics(); + for (String s : lines) { + int cur = metrics.stringWidth(s); + if (cur > max) { + max = cur; + } + } + widthCash = max + INSET; + } + 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); + } + + public void setPosition(Point p) { + this.position = p; + } + + public Point getPosition() { + return position; + } + + public Diagram getDiagram() { + return diagram; + } + + 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 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]); + } + + lines = result; + } + + private String resolveString(String string) { + + 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 = getProperties().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(); + } + + 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; + return new Dimension(width, height); + } else { + int width = getWidth() + 2 * Figure.SLOT_WIDTH; + int height = Figure.SLOT_WIDTH * (Math.max(inputSlots.size(), outputSlots.size()) + 1); + return new Dimension(width, height); + } + } + + @Override + public String toString() { + return idString; + } + + public Cluster getCluster() { + if (getSource().getSourceNodes().size() == 0) { + assert false : "Should never reach here, every figure must have at least one source node!"; + return null; + } else { + Cluster result = diagram.getBlock(diagram.getGraph().getBlock(getSource().getSourceNodes().get(0))); + assert result != null; + return result; + } + } + + public boolean isRoot() { + if (source.getSourceNodes().size() > 0 && source.getSourceNodes().get(0).getProperties().get("name").equals("Root")) { + return true; + } else { + return false; + } + } + + public int compareTo(Vertex f) { + return toString().compareTo(f.toString()); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/InputSlot.java b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/InputSlot.java new file mode 100644 index 0000000000000000000000000000000000000000..9ffa077cddde565eae38f5ac38aae55e056f1050 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/InputSlot.java @@ -0,0 +1,57 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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); + } + + public int getPosition() { + return getFigure().getInputSlots().indexOf(this); + } + + public void setPosition(int position) { + List inputSlots = getFigure().inputSlots; + InputSlot s = inputSlots.remove(position); + inputSlots.add(position, s); + } + + public Point getRelativePosition() { + return new Point(getFigure().getWidth() * (getPosition() + 1) / (getFigure().getInputSlots().size() + 1), Figure.SLOT_WIDTH - Figure.SLOT_START); + } + + @Override + public String toString() { + return "InputSlot[figure=" + this.getFigure().toString() + ", position=" + getPosition() + "]"; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/InvertSelector.java b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/InvertSelector.java new file mode 100644 index 0000000000000000000000000000000000000000..8cd8e467bf705e14e3a04006116a7c302ed88f5a --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/InvertSelector.java @@ -0,0 +1,53 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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; + } + + 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 --git a/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/MatcherSelector.java b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/MatcherSelector.java new file mode 100644 index 0000000000000000000000000000000000000000..7ad17dd40a1e8bcd015bca8b4abe21b4dfe3dd20 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/MatcherSelector.java @@ -0,0 +1,47 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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; + } + + public List
selected(Diagram d) { + Properties.PropertySelector
selector = new Properties.PropertySelector
(d.getFigures()); + List
list = selector.selectMultiple(matcher); + return list; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/OrSelector.java b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/OrSelector.java new file mode 100644 index 0000000000000000000000000000000000000000..3a7e8299cc2350569f8bca3212c6b75346de2526 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/OrSelector.java @@ -0,0 +1,56 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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; + } + + 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 --git a/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/OutputSlot.java b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/OutputSlot.java new file mode 100644 index 0000000000000000000000000000000000000000..b85f3d37cfd9ec5cb97bc52d5ff78f293f34e8a5 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/OutputSlot.java @@ -0,0 +1,55 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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); + } + + public int getPosition() { + return getFigure().getOutputSlots().indexOf(this); + } + + public void setPosition(int position) { + OutputSlot s = getFigure().outputSlots.remove(position); + getFigure().outputSlots.add(position, s); + } + + public Point getRelativePosition() { + return new Point(getFigure().getWidth() * (getPosition() + 1) / (getFigure().getOutputSlots().size() + 1), getFigure().getSize().height - Figure.SLOT_WIDTH + Figure.SLOT_START); + } + + @Override + public String toString() { + return "OutputSlot[figure=" + this.getFigure().toString() + ", position=" + getPosition() + "]"; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/PredecessorSelector.java b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/PredecessorSelector.java new file mode 100644 index 0000000000000000000000000000000000000000..ab069325e065ea1148da42ee3b197c37432b9818 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/PredecessorSelector.java @@ -0,0 +1,59 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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; + } + + 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 --git a/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Selector.java b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Selector.java new file mode 100644 index 0000000000000000000000000000000000000000..9b47d89eb7fce1d94b432a7bc5d2167ebd129e61 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Selector.java @@ -0,0 +1,35 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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 --git a/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Slot.java b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Slot.java new file mode 100644 index 0000000000000000000000000000000000000000..d525dbfe85791a594083e322e2db20fe146bc77c --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Slot.java @@ -0,0 +1,125 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.graph; + +import com.sun.hotspot.igv.layout.Port; +import com.sun.hotspot.igv.layout.Vertex; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Comparator; + +/** + * + * @author Thomas Wuerthinger + */ +public abstract class Slot implements Port, Source.Provider { + + private int wantedIndex; + private String name; + private String shortName; // 1 - 2 characters + private Source source; + protected List connections; + private Figure figure; + + protected Slot(Figure figure, int wantedIndex) { + this.figure = figure; + connections = new ArrayList(2); + source = new Source(); + this.wantedIndex = wantedIndex; + name = ""; + shortName = ""; + assert figure != null; + } + public static final Comparator slotIndexComparator = new Comparator() { + + public int compare(Slot o1, Slot o2) { + return o1.wantedIndex - o2.wantedIndex; + } + }; + public static final Comparator slotFigureComparator = new Comparator() { + + public int compare(Slot o1, Slot o2) { + return o1.figure.getId() - o2.figure.getId(); + } + }; + + public int getWantedIndex() { + return wantedIndex; + } + + public Source getSource() { + return source; + } + + public String getName() { + return name; + } + + public void setShortName(String s) { + assert s != null; + assert s.length() <= 2; + this.shortName = s; + + } + + public String getShortName() { + return shortName; + } + + public boolean getShowName() { + return getShortName() != null && getShortName().length() > 0; + } + + public void setName(String s) { + if (s == null) { + s = ""; + } + this.name = s; + } + + public Figure getFigure() { + assert figure != null; + return figure; + } + + public List getConnections() { + return Collections.unmodifiableList(connections); + } + + public void removeAllConnections() { + List connectionsCopy = new ArrayList(this.connections); + for (Connection c : connectionsCopy) { + c.remove(); + } + } + + public Vertex getVertex() { + return figure; + } + + public abstract int getPosition(); + + public abstract void setPosition(int position); +} diff --git a/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Source.java b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Source.java new file mode 100644 index 0000000000000000000000000000000000000000..a43b905d242f737c5e63e587ca131c3bbefb4039 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Source.java @@ -0,0 +1,100 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.graph; + +import com.sun.hotspot.igv.data.InputBlock; +import com.sun.hotspot.igv.data.InputGraph; +import com.sun.hotspot.igv.data.InputNode; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * + * @author Thomas Wuerthinger + */ +public class Source { + + private List sourceNodes; + private Set set; + + public Source() { + sourceNodes = new ArrayList(1); + } + + public List getSourceNodes() { + return Collections.unmodifiableList(sourceNodes); + } + + public Set getSourceNodesAsSet() { + if (set == null) { + set = new HashSet(); + for (InputNode n : sourceNodes) { + int id = n.getId(); + //if(id < 0) id = -id; + set.add(id); + } + } + return set; + } + + public void addSourceNode(InputNode n) { + sourceNodes.add(n); + set = null; + } + + public void removeSourceNode(InputNode n) { + sourceNodes.remove(n); + set = null; + } + + public interface Provider { + + public Source getSource(); + } + + public void setSourceNodes(List sourceNodes) { + this.sourceNodes = sourceNodes; + set = null; + } + + public void addSourceNodes(Source s) { + for (InputNode n : s.getSourceNodes()) { + sourceNodes.add(n); + } + set = null; + } + + public boolean isInBlock(InputGraph g, InputBlock blockNode) { + + for (InputNode n : this.getSourceNodes()) { + if (g.getBlock(n) == blockNode) { + return true; + } + } + return false; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/SuccessorSelector.java b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/SuccessorSelector.java new file mode 100644 index 0000000000000000000000000000000000000000..da95a1796d6386f5deae54454ffeebf5cad06d78 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/SuccessorSelector.java @@ -0,0 +1,59 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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; + } + + 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 --git a/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/build.xml b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/build.xml new file mode 100644 index 0000000000000000000000000000000000000000..8376e08d8a8fd6dbf766ef86cdcbddd98821cdfb --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/build.xml @@ -0,0 +1,8 @@ + + + + + + Builds, tests, and runs the project com.sun.hotspot.igv.hierarchicallayout. + + diff --git a/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/manifest.mf b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/manifest.mf new file mode 100644 index 0000000000000000000000000000000000000000..723afd12fac629bb9dc9b7ed2dc5e484c275a094 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/manifest.mf @@ -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 --git a/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/nbproject/build-impl.xml b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/nbproject/build-impl.xml new file mode 100644 index 0000000000000000000000000000000000000000..3257988a7018d6808da14eec03db48b2d1f8a4ba --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/nbproject/build-impl.xml @@ -0,0 +1,30 @@ + + + + + + You must set 'suite.dir' to point to your containing module suite + + + + + + + + + + + + + + + + + + + + + diff --git a/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/nbproject/genfiles.properties b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/nbproject/genfiles.properties new file mode 100644 index 0000000000000000000000000000000000000000..cb74676188abfb5a331ae50dcd65368f9ffaea08 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=de087df9 +build.xml.script.CRC32=98977c36 +build.xml.stylesheet.CRC32=79c3b980 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=de087df9 +nbproject/build-impl.xml.script.CRC32=0d734625 +nbproject/build-impl.xml.stylesheet.CRC32=deb65f65 diff --git a/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/nbproject/platform.properties b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/nbproject/platform.properties new file mode 100644 index 0000000000000000000000000000000000000000..68ad75e5766f33be5a65a19d28cc7605c5b50a1c --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/nbproject/platform.properties @@ -0,0 +1,29 @@ +# Deprecated since 5.0u1; for compatibility with 5.0: +disabled.clusters=\ + apisupport1,\ + harness,\ + ide8,\ + java1,\ + nb6.0,\ + profiler2 +disabled.modules=\ + org.netbeans.core.execution,\ + org.netbeans.core.multiview,\ + org.netbeans.core.output2,\ + org.netbeans.modules.applemenu,\ + org.netbeans.modules.autoupdate.services,\ + org.netbeans.modules.autoupdate.ui,\ + org.netbeans.modules.core.kit,\ + org.netbeans.modules.favorites,\ + org.netbeans.modules.javahelp,\ + org.netbeans.modules.masterfs,\ + org.netbeans.modules.options.keymap,\ + org.netbeans.modules.sendopts,\ + org.netbeans.modules.templates,\ + org.openide.compat,\ + org.openide.execution,\ + org.openide.util.enumerations +enabled.clusters=\ + platform7 +nbjdk.active=JDK_1.6 +nbplatform.active=default diff --git a/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/nbproject/project.properties b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/nbproject/project.properties new file mode 100644 index 0000000000000000000000000000000000000000..152f44eca60ab831869539ffae9192aa03915f3b --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/nbproject/project.properties @@ -0,0 +1,2 @@ +javac.source=1.5 +javac.compilerargs=-Xlint -Xlint:-serial diff --git a/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/nbproject/project.xml b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/nbproject/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..fc4c20a9dad4fbeba5ee8e25a7a2c6c681125127 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/nbproject/project.xml @@ -0,0 +1,23 @@ + + + org.netbeans.modules.apisupport.project + + + com.sun.hotspot.igv.hierarchicallayout + + + + com.sun.hotspot.igv.layout + + + + 1.0 + + + + + com.sun.hotspot.igv.hierarchicallayout + + + + diff --git a/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/nbproject/suite.properties b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/nbproject/suite.properties new file mode 100644 index 0000000000000000000000000000000000000000..29d7cc9bd6fdd81453543cdf1bcf1dab301e3a92 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/nbproject/suite.properties @@ -0,0 +1 @@ +suite.dir=${basedir}/.. diff --git a/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/Bundle.properties b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/Bundle.properties new file mode 100644 index 0000000000000000000000000000000000000000..037223194d30c0c1113dfd0e32a6a5235790e0a3 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/Bundle.properties @@ -0,0 +1 @@ +OpenIDE-Module-Name=HierarchicalLayout diff --git a/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/ClusterEdge.java b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/ClusterEdge.java new file mode 100644 index 0000000000000000000000000000000000000000..343cc65f5c650ec2a876e8f23668ba8034816c3d --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/ClusterEdge.java @@ -0,0 +1,63 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.hierarchicallayout; + +import com.sun.hotspot.igv.layout.Link; +import com.sun.hotspot.igv.layout.Port; +import java.awt.Point; +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public class ClusterEdge implements Link { + + private ClusterNode from; + private ClusterNode to; + private List points; + + public ClusterEdge(ClusterNode from, ClusterNode to) { + assert from != null; + assert to != null; + this.from = from; + this.to = to; + } + + public Port getTo() { + return to.getInputSlot(); + } + + public Port getFrom() { + return from.getInputSlot(); + } + + public void setControlPoints(List p) { + this.points = p; + } + + public List getControlPoints() { + return points; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/ClusterIngoingConnection.java b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/ClusterIngoingConnection.java new file mode 100644 index 0000000000000000000000000000000000000000..e6588771c5b80dffc93705609a1c72107ed82bf6 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/ClusterIngoingConnection.java @@ -0,0 +1,76 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.hierarchicallayout; + +import com.sun.hotspot.igv.layout.Link; +import com.sun.hotspot.igv.layout.Port; +import java.awt.Point; +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public class ClusterIngoingConnection implements Link { + + private List controlPoints; + private ClusterInputSlotNode inputSlotNode; + private Link connection; + private Port inputSlot; + private Port outputSlot; + + public ClusterIngoingConnection(ClusterInputSlotNode inputSlotNode, Link c) { + this.inputSlotNode = inputSlotNode; + this.connection = c; + this.controlPoints = new ArrayList(); + + inputSlot = c.getTo(); + outputSlot = inputSlotNode.getOutputSlot(); + } + + public Link getConnection() { + return connection; + } + + public ClusterInputSlotNode getInputSlotNode() { + return inputSlotNode; + } + + public Port getTo() { + return inputSlot; + } + + public Port getFrom() { + return outputSlot; + } + + public void setControlPoints(List p) { + this.controlPoints = p; + } + + public List getControlPoints() { + return controlPoints; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/ClusterInputSlotNode.java b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/ClusterInputSlotNode.java new file mode 100644 index 0000000000000000000000000000000000000000..8458ed5afab8e61705113da1bcbe9a68fba5d3a9 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/ClusterInputSlotNode.java @@ -0,0 +1,145 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.hierarchicallayout; + +import com.sun.hotspot.igv.layout.Cluster; +import com.sun.hotspot.igv.layout.Port; +import com.sun.hotspot.igv.layout.Vertex; +import java.awt.Dimension; +import java.awt.Point; + +/** + * + * @author Thomas Wuerthinger + */ +public class ClusterInputSlotNode implements Vertex { + + private final int SIZE = 0; + private Point position; + private Port inputSlot; + private Port outputSlot; + private ClusterNode blockNode; + private InterClusterConnection interBlockConnection; + private Cluster cluster; + private ClusterIngoingConnection conn; + + public void setIngoingConnection(ClusterIngoingConnection c) { + conn = c; + } + + public ClusterIngoingConnection getIngoingConnection() { + return conn; + } + private String id; + + @Override + public String toString() { + return id; + } + + public ClusterInputSlotNode(ClusterNode n, String id) { + this.blockNode = n; + this.id = id; + + n.addSubNode(this); + + final Vertex thisNode = this; + final ClusterNode thisBlockNode = blockNode; + + outputSlot = new Port() { + + public Point getRelativePosition() { + return new Point(0, 0); + } + + public Vertex getVertex() { + return thisNode; + } + + @Override + public String toString() { + return "OutPort of " + thisNode.toString(); + } + }; + + inputSlot = new Port() { + + public Point getRelativePosition() { + Point p = new Point(thisNode.getPosition()); + p.x += ClusterNode.BORDER; + p.y = 0; + return p; + } + + public Vertex getVertex() { + return thisBlockNode; + } + + @Override + public String toString() { + return "InPort of " + thisNode.toString(); + } + }; + } + + public Port getInputSlot() { + return inputSlot; + } + + public InterClusterConnection getInterBlockConnection() { + return interBlockConnection; + } + + public Port getOutputSlot() { + return outputSlot; + } + + public Dimension getSize() { + return new Dimension(SIZE, SIZE); + } + + public void setPosition(Point p) { + this.position = p; + } + + public Point getPosition() { + return position; + } + + public void setInterBlockConnection(InterClusterConnection interBlockConnection) { + this.interBlockConnection = interBlockConnection; + } + + public Cluster getCluster() { + return cluster; + } + + public boolean isRoot() { + return true; + } + + public int compareTo(Vertex o) { + return toString().compareTo(o.toString()); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/ClusterNode.java b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/ClusterNode.java new file mode 100644 index 0000000000000000000000000000000000000000..315ff82ae6e9fedcf403c46ea9f42bc38f9e2553 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/ClusterNode.java @@ -0,0 +1,233 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.hierarchicallayout; + +import com.sun.hotspot.igv.layout.Cluster; +import com.sun.hotspot.igv.layout.Link; +import com.sun.hotspot.igv.layout.Port; +import com.sun.hotspot.igv.layout.Vertex; +import java.awt.Dimension; +import java.awt.Point; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * + * @author Thomas Wuerthinger + */ +public class ClusterNode implements Vertex { + + private Cluster cluster; + private Port inputSlot; + private Port outputSlot; + private Set subNodes; + private Dimension size; + private Point position; + private Set subEdges; + private boolean dirty; + private boolean root; + private String name; + public static final int BORDER = 20; + + public ClusterNode(Cluster cluster, String name) { + this.subNodes = new HashSet(); + this.subEdges = new HashSet(); + this.cluster = cluster; + position = new Point(0, 0); + this.name = name; + } + + public void addSubNode(Vertex v) { + subNodes.add(v); + } + + public void addSubEdge(Link l) { + subEdges.add(l); + } + + public Set getSubEdges() { + return Collections.unmodifiableSet(subEdges); + } + + public void updateSize() { + + + calculateSize(); + + final ClusterNode widget = this; + inputSlot = new Port() { + + public Point getRelativePosition() { + return new Point(size.width / 2, 0); + } + + public Vertex getVertex() { + return widget; + } + }; + + outputSlot = new Port() { + + public Point getRelativePosition() { + return new Point(size.width / 2, size.height); + } + + public Vertex getVertex() { + return widget; + } + }; + } + + private void calculateSize() { + + if (subNodes.size() == 0) { + size = new Dimension(0, 0); + } + + int minX = Integer.MAX_VALUE; + int maxX = Integer.MIN_VALUE; + int minY = Integer.MAX_VALUE; + int maxY = Integer.MIN_VALUE; + + + for (Vertex n : subNodes) { + Point p = n.getPosition(); + minX = Math.min(minX, p.x); + minY = Math.min(minY, p.y); + maxX = Math.max(maxX, p.x + n.getSize().width); + maxY = Math.max(maxY, p.y + n.getSize().height); + } + + for (Link l : subEdges) { + List points = l.getControlPoints(); + for (Point p : points) { + if (p != null) { + minX = Math.min(minX, p.x); + maxX = Math.max(maxX, p.x); + minY = Math.min(minY, p.y); + maxY = Math.max(maxY, p.y); + } + } + } + + size = new Dimension(maxX - minX, maxY - minY); + + // Normalize coordinates + for (Vertex n : subNodes) { + n.setPosition(new Point(n.getPosition().x - minX, n.getPosition().y - minY)); + } + + for (Link l : subEdges) { + List points = new ArrayList(l.getControlPoints()); + for (Point p : points) { + p.x -= minX; + p.y -= minY; + } + l.setControlPoints(points); + + } + + size.width += 2 * BORDER; + size.height += 2 * BORDER; + } + + public Port getInputSlot() { + return inputSlot; + + } + + public Port getOutputSlot() { + return outputSlot; + } + + public Dimension getSize() { + return size; + } + + public Point getPosition() { + return position; + } + + public void setPosition(Point pos) { + + this.position = pos; + for (Vertex n : subNodes) { + Point cur = new Point(n.getPosition()); + cur.translate(pos.x + BORDER, pos.y + BORDER); + n.setPosition(cur); + } + + for (Link e : subEdges) { + List arr = e.getControlPoints(); + ArrayList newArr = new ArrayList(); + for (Point p : arr) { + if (p != null) { + Point p2 = new Point(p); + p2.translate(pos.x + BORDER, pos.y + BORDER); + newArr.add(p2); + } else { + newArr.add(null); + } + } + + e.setControlPoints(newArr); + } + } + + public Cluster getCluster() { + return cluster; + } + + public void setCluster(Cluster c) { + cluster = c; + } + + public void setDirty(boolean b) { + dirty = b; + } + + public void setRoot(boolean b) { + root = b; + } + + public boolean isRoot() { + return root; + } + + public int compareTo(Vertex o) { + return toString().compareTo(o.toString()); + } + + @Override + public String toString() { + return name; + } + + public Set getSubNodes() { + return subNodes; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/ClusterOutgoingConnection.java b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/ClusterOutgoingConnection.java new file mode 100644 index 0000000000000000000000000000000000000000..babf2f228b5283e364a0cef12cee36e7eced9926 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/ClusterOutgoingConnection.java @@ -0,0 +1,68 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.hierarchicallayout; + +import com.sun.hotspot.igv.layout.Link; +import com.sun.hotspot.igv.layout.Port; +import java.awt.Point; +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public class ClusterOutgoingConnection implements Link { + + private List intermediatePoints; + private ClusterOutputSlotNode outputSlotNode; + private Link connection; + private Port inputSlot; + private Port outputSlot; + + public ClusterOutgoingConnection(ClusterOutputSlotNode outputSlotNode, Link c) { + this.outputSlotNode = outputSlotNode; + this.connection = c; + this.intermediatePoints = new ArrayList(); + + outputSlot = c.getFrom(); + inputSlot = outputSlotNode.getInputSlot(); + } + + public Port getTo() { + return inputSlot; + } + + public Port getFrom() { + return outputSlot; + } + + public void setControlPoints(List p) { + this.intermediatePoints = p; + } + + public List getControlPoints() { + return intermediatePoints; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/ClusterOutputSlotNode.java b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/ClusterOutputSlotNode.java new file mode 100644 index 0000000000000000000000000000000000000000..924c9e0845c0f94cd63601174a5a278c8e5176ea --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/ClusterOutputSlotNode.java @@ -0,0 +1,145 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.hierarchicallayout; + +import com.sun.hotspot.igv.layout.Cluster; +import com.sun.hotspot.igv.layout.Port; +import com.sun.hotspot.igv.layout.Vertex; +import java.awt.Dimension; +import java.awt.Point; + +/** + * + * @author Thomas Wuerthinger + */ +public class ClusterOutputSlotNode implements Vertex { + + private final int SIZE = 0; + private Point position; + private Port inputSlot; + private Port outputSlot; + private ClusterNode blockNode; + private boolean root; + private Cluster cluster; + private ClusterOutgoingConnection conn; + private String id; + + public void setOutgoingConnection(ClusterOutgoingConnection c) { + this.conn = c; + } + + public ClusterOutgoingConnection getOutgoingConnection() { + return conn; + } + + @Override + public String toString() { + return id; + } + + public ClusterOutputSlotNode(ClusterNode n, String id) { + this.blockNode = n; + this.id = id; + + n.addSubNode(this); + + final Vertex thisNode = this; + final ClusterNode thisBlockNode = blockNode; + + inputSlot = new Port() { + + public Point getRelativePosition() { + return new Point(0, 0); + } + + public Vertex getVertex() { + return thisNode; + } + + @Override + public String toString() { + return "InPort of " + thisNode.toString(); + } + }; + + outputSlot = new Port() { + + public Point getRelativePosition() { + Point p = new Point(thisNode.getPosition()); + p.x += ClusterNode.BORDER; + p.y = thisBlockNode.getSize().height; + return p; + } + + public Vertex getVertex() { + return thisBlockNode; + } + + @Override + public String toString() { + return "OutPort of " + thisNode.toString(); + } + }; + } + + public Dimension getSize() { + return new Dimension(SIZE, SIZE); + } + + public void setPosition(Point p) { + this.position = p; + } + + public Point getPosition() { + return position; + } + + public Port getInputSlot() { + return inputSlot; + } + + public Port getOutputSlot() { + return outputSlot; + } + + public void setCluster(Cluster c) { + cluster = c; + } + + public void setRoot(boolean b) { + root = b; + } + + public Cluster getCluster() { + return cluster; + } + + public boolean isRoot() { + return root; + } + + public int compareTo(Vertex o) { + return toString().compareTo(o.toString()); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/Edge.java b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/Edge.java new file mode 100644 index 0000000000000000000000000000000000000000..2c11ce67c75abeb93e6d57047abbe13676809735 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/Edge.java @@ -0,0 +1,89 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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); + } + + public String toString() { + return "Edge (" + source + " -- " + dest + "): " + data; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/Graph.java b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/Graph.java new file mode 100644 index 0000000000000000000000000000000000000000..98dbe392c2187daaf6910944f56f63c53a0617e6 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/Graph.java @@ -0,0 +1,298 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.hierarchicallayout; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Hashtable; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + +/** + * + * @author Thomas Wuerthinger + */ +public class Graph { + + private Hashtable> nodes; + private Hashtable> edges; + private List> nodeList; + + public Graph() { + nodes = new Hashtable>(); + edges = new Hashtable>(); + 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 --git a/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/HierarchicalClusterLayoutManager.java b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/HierarchicalClusterLayoutManager.java new file mode 100644 index 0000000000000000000000000000000000000000..1dc1b3691d721490046907bb490b9bc1e51025fa --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/HierarchicalClusterLayoutManager.java @@ -0,0 +1,247 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.hierarchicallayout; + +import java.awt.Point; +import java.awt.Rectangle; +import java.util.Hashtable; +import java.util.List; +import java.util.Set; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.TreeSet; +import com.sun.hotspot.igv.layout.Cluster; +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.Port; +import com.sun.hotspot.igv.layout.Vertex; + +/** + * + * @author Thomas Wuerthinger + */ +public class HierarchicalClusterLayoutManager implements LayoutManager { + + private OldHierarchicalLayoutManager.Combine combine; + private LayoutManager subManager = new OldHierarchicalLayoutManager(combine); + private LayoutManager manager = new OldHierarchicalLayoutManager(combine, 150); + private static final boolean TRACE = false; + + public HierarchicalClusterLayoutManager(OldHierarchicalLayoutManager.Combine combine) { + this.combine = combine; + } + + public void doLayout(LayoutGraph graph) { + doLayout(graph, new HashSet(), new HashSet(), new HashSet()); + } + + public void setSubManager(LayoutManager manager) { + this.subManager = manager; + } + + public void setManager(LayoutManager manager) { + this.manager = manager; + } + + public void doLayout(LayoutGraph graph, Set firstLayerHint, Set lastLayerHint, Set importantLinks) { + + assert graph.verify(); + + Hashtable> lists = new Hashtable>(); + Hashtable> listsConnection = new Hashtable>(); + Hashtable> clusterInputSlotHash = new Hashtable>(); + Hashtable> clusterOutputSlotHash = new Hashtable>(); + + Hashtable clusterNodes = new Hashtable(); + Hashtable> clusterInputSlotSet = new Hashtable>(); + Hashtable> clusterOutputSlotSet = new Hashtable>(); + Set clusterEdges = new HashSet(); + Set interClusterEdges = new HashSet(); + Hashtable linkClusterOutgoingConnection = new Hashtable(); + Hashtable linkInterClusterConnection = new Hashtable(); + Hashtable linkClusterIngoingConnection = new Hashtable(); + Set clusterNodeSet = new HashSet(); + + Set cluster = graph.getClusters(); + int z = 0; + for (Cluster c : cluster) { + lists.put(c, new ArrayList()); + listsConnection.put(c, new ArrayList()); + clusterInputSlotHash.put(c, new Hashtable()); + clusterOutputSlotHash.put(c, new Hashtable()); + clusterOutputSlotSet.put(c, new TreeSet()); + clusterInputSlotSet.put(c, new TreeSet()); + ClusterNode cn = new ClusterNode(c, "" + z); + clusterNodes.put(c, cn); + clusterNodeSet.add(cn); + z++; + } + + // Add cluster edges + for (Cluster c : cluster) { + + ClusterNode start = clusterNodes.get(c); + + for (Cluster succ : c.getSuccessors()) { + ClusterNode end = clusterNodes.get(succ); + if (end != null && start != end) { + ClusterEdge e = new ClusterEdge(start, end); + clusterEdges.add(e); + interClusterEdges.add(e); + } + } + } + + for (Vertex v : graph.getVertices()) { + Cluster c = v.getCluster(); + assert c != null; + clusterNodes.get(c).addSubNode(v); + } + + for (Link l : graph.getLinks()) { + + Port fromPort = l.getFrom(); + Port toPort = l.getTo(); + Vertex fromVertex = fromPort.getVertex(); + Vertex toVertex = toPort.getVertex(); + Cluster fromCluster = fromVertex.getCluster(); + Cluster toCluster = toVertex.getCluster(); + + Port samePort = null; + if (combine == OldHierarchicalLayoutManager.Combine.SAME_INPUTS) { + samePort = toPort; + } else if (combine == OldHierarchicalLayoutManager.Combine.SAME_OUTPUTS) { + samePort = fromPort; + } + + assert listsConnection.containsKey(fromCluster); + assert listsConnection.containsKey(toCluster); + + if (fromCluster == toCluster) { + listsConnection.get(fromCluster).add(l); + clusterNodes.get(fromCluster).addSubEdge(l); + } else { + ClusterInputSlotNode inputSlotNode = null; + ClusterOutputSlotNode outputSlotNode = null; + + if (samePort != null) { + outputSlotNode = clusterOutputSlotHash.get(fromCluster).get(samePort); + inputSlotNode = clusterInputSlotHash.get(toCluster).get(samePort); + } + + if (outputSlotNode == null) { + outputSlotNode = new ClusterOutputSlotNode(clusterNodes.get(fromCluster), "Out " + fromCluster.toString() + " " + samePort.toString()); + clusterOutputSlotSet.get(fromCluster).add(outputSlotNode); + ClusterOutgoingConnection conn = new ClusterOutgoingConnection(outputSlotNode, l); + outputSlotNode.setOutgoingConnection(conn); + clusterNodes.get(fromCluster).addSubEdge(conn); + if (samePort != null) { + clusterOutputSlotHash.get(fromCluster).put(samePort, outputSlotNode); + } + + linkClusterOutgoingConnection.put(l, conn); + } else { + linkClusterOutgoingConnection.put(l, outputSlotNode.getOutgoingConnection()); + } + + if (inputSlotNode == null) { + inputSlotNode = new ClusterInputSlotNode(clusterNodes.get(toCluster), "In " + toCluster.toString() + " " + samePort.toString()); + clusterInputSlotSet.get(toCluster).add(inputSlotNode); + } + + ClusterIngoingConnection conn = new ClusterIngoingConnection(inputSlotNode, l); + inputSlotNode.setIngoingConnection(conn); + clusterNodes.get(toCluster).addSubEdge(conn); + if (samePort != null) { + clusterInputSlotHash.get(toCluster).put(samePort, inputSlotNode); + } + + linkClusterIngoingConnection.put(l, conn); + + + InterClusterConnection interConn = new InterClusterConnection(outputSlotNode, inputSlotNode); + linkInterClusterConnection.put(l, interConn); + clusterEdges.add(interConn); + } + } + + Timing t = null; + + if (TRACE) { + new Timing("Child timing"); + t.start(); + } + + for (Cluster c : cluster) { + ClusterNode n = clusterNodes.get(c); + subManager.doLayout(new LayoutGraph(n.getSubEdges(), n.getSubNodes()), clusterInputSlotSet.get(c), clusterOutputSlotSet.get(c), new HashSet()); + n.updateSize(); + } + + Set roots = new LayoutGraph(interClusterEdges).findRootVertices(); + for (Vertex v : roots) { + assert v instanceof ClusterNode; + ((ClusterNode) v).setRoot(true); + } + + manager.doLayout(new LayoutGraph(clusterEdges, clusterNodeSet), new HashSet(), new HashSet(), interClusterEdges); + + for (Cluster c : cluster) { + ClusterNode n = clusterNodes.get(c); + c.setBounds(new Rectangle(n.getPosition(), n.getSize())); + } + + // TODO: handle case where blocks are not fully connected + + if (TRACE) { + t.stop(); + t.print(); + } + + for (Link l : graph.getLinks()) { + + if (linkInterClusterConnection.containsKey(l)) { + ClusterOutgoingConnection conn1 = linkClusterOutgoingConnection.get(l); + InterClusterConnection conn2 = linkInterClusterConnection.get(l); + ClusterIngoingConnection conn3 = linkClusterIngoingConnection.get(l); + + assert conn1 != null; + assert conn2 != null; + assert conn3 != null; + + List points = new ArrayList(); + + points.addAll(conn1.getControlPoints()); + points.addAll(conn2.getControlPoints()); + points.addAll(conn3.getControlPoints()); + + l.setControlPoints(points); + } + } + } + + public void doRouting(LayoutGraph graph) { + } +} diff --git a/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/HierarchicalLayoutManager.java b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/HierarchicalLayoutManager.java new file mode 100644 index 0000000000000000000000000000000000000000..9e5656f489f6b484c27ef3b7434015c6617e8c32 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/HierarchicalLayoutManager.java @@ -0,0 +1,2110 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashSet; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; +import java.util.Set; +import java.util.SortedSet; +import java.util.Stack; +import java.util.TreeSet; + +/** + * + * @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 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; + } + + 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; + } + + public void doLayout(LayoutGraph graph) { + doLayout(graph, new HashSet(), new HashSet(), new HashSet()); + + } + + 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(); + new AssignXCoordinates2().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; + + 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); + points.add(p); + if (e.to.inOffsets.containsKey(e.relativeTo)) { + points.add(new Point(p.x, p.y + e.to.inOffsets.get(e.relativeTo))); + } + + 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); + if (curEdge.from.outOffsets.containsKey(curEdge.relativeFrom)) { + points.add(new Point(p.x, p.y + curEdge.from.outOffsets.get(curEdge.relativeFrom))); + } + 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); + points.add(p); + if (e.from.outOffsets.containsKey(e.relativeFrom)) { + points.add(new Point(p.x, p.y + e.from.outOffsets.get(e.relativeFrom))); + } + + 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); + points.add(p); + if (curEdge.to.inOffsets.containsKey(curEdge.relativeTo)) { + points.add(new Point(p.x, p.y + curEdge.to.inOffsets.get(curEdge.relativeTo))); + } + + + 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() { + + 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() { + + public int compare(Region r1, Region r2) { + return r1.minOrderNumber - r2.minOrderNumber; + } + }; + private static final Comparator nodePositionComparator = new Comparator() { + + public int compare(LayoutNode n1, LayoutNode n2) { + return n1.pos - n2.pos; + } + }; + private static final Comparator nodeProcessingDownComparator = new Comparator() { + + public int compare(LayoutNode n1, LayoutNode n2) { + if (n1.vertex == null) { + return -1; + } + if (n2.vertex == null) { + return 1; + } + return n1.preds.size() - n2.preds.size(); + } + }; + private static final Comparator nodeProcessingUpComparator = new Comparator() { + + public int compare(LayoutNode n1, LayoutNode n2) { + if (n1.vertex == null) { + return -1; + } + if (n2.vertex == null) { + return 1; + } + return n1.succs.size() - n2.succs.size(); + } + }; + + private class AssignXCoordinates2 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); + } + } + + protected void run() { + + space = new ArrayList[layers.length]; + downProcessingOrder = new ArrayList[layers.length]; + upProcessingOrder = new ArrayList[layers.length]; + + 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(); + } + + for (int i = 0; i < SWEEP_ITERATIONS; i++) { + doubleSweep(); + } + } + + private int calculateOptimalDown(LayoutNode n) { + + List values = new ArrayList(); + if (n.preds.size() == 0) { + return n.x; + } + for (LayoutEdge e : n.preds) { + int cur = e.from.x + e.relativeFrom - e.relativeTo; + values.add(cur); + } + return median(values); + } + + private int calculateOptimalBoth(LayoutNode n) { + + List values = new ArrayList(); + if (n.preds.size() == 0 + n.succs.size()) { + return n.x; + } + for (LayoutEdge e : n.preds) { + int cur = e.from.x + e.relativeFrom - e.relativeTo; + values.add(cur); + } + + for (LayoutEdge e : n.succs) { + int cur = e.to.x + e.relativeTo - e.relativeFrom; + values.add(cur); + } + + return median(values); + } + + private int calculateOptimalUp(LayoutNode n) { + + //List values = new ArrayList(); + int size = n.succs.size(); + if (size == 0) { + return n.x; + } else { + int result = 0; + for (LayoutEdge e : n.succs) { + int cur = e.to.x + e.relativeTo - e.relativeFrom; + result += cur; + } + return result / size; //median(values); + } + } + + private int median(List values) { + Collections.sort(values); + if (values.size() % 2 == 0) { + return (values.get(values.size() / 2 - 1) + values.get(values.size() / 2)) / 2; + } else { + return values.get(values.size() / 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); + } + } + /* + for(int i=0; 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 class AssignXCoordinates extends AlgorithmPart { + + HashMap hashMap = new HashMap(); + ArrayList segments = new ArrayList(); + + private void generateSegments() { + + for (int i = 0; i < layerCount; i++) { + for (LayoutNode n : layers[i]) { + if (!hashMap.containsKey(n)) { + Segment s = new Segment(); + segments.add(s); + LayoutNode curNode = n; + + int maxLength = 0; + while (curNode.succs.size() == 1 && curNode.preds.size() == 1) { + s.nodes.add(curNode); + assert !hashMap.containsKey(curNode); + hashMap.put(curNode, s); + curNode = curNode.succs.get(0).to; + maxLength++; + //if(maxLength > 10) break; + } + + if (s.nodes.size() > 0 && curNode.preds.size() == 1 && curNode.vertex == null) { + s.nodes.add(curNode); + assert !hashMap.containsKey(curNode); + hashMap.put(curNode, s); + } + + if (s.nodes.size() == 0) { + // Simple segment with a single node + s.nodes.add(n); + hashMap.put(n, s); + } + } + } + } + } + + private void addEdges() { + + for (int i = 0; i < layerCount; i++) { + LayoutNode prev = null; + for (LayoutNode n : layers[i]) { + + if (prev != null) { + Segment s1 = hashMap.get(prev); + Segment s2 = hashMap.get(n); + + if (s1 != s2) { + s1.succs.add(s2); + s2.preds.add(s1); + } + } + prev = n; + + } + } + } + + private void topologicalSorting() { + + Queue queue = new LinkedList(); + + int index = 0; + ArrayList newList = new ArrayList(); + for (Segment s : segments) { + if (s.preds.size() == 0) { + s.orderNumber = index; + newList.add(s); + index++; + queue.add(s); + } + } + + while (!queue.isEmpty()) { + Segment s = queue.remove(); + + for (Segment succ : s.succs) { + succ.preds.remove(s); + if (succ.preds.size() == 0) { + queue.add(succ); + succ.orderNumber = index; + newList.add(succ); + index++; + } + } + } + + segments = newList; + } + + private void initialPositions() { + + int[] minPos = new int[layers.length]; + + for (Segment s : segments) { + int max = 0; + for (LayoutNode n : s.nodes) { + int x = minPos[n.layer]; + if (x > max) { + max = x; + } + } + + for (LayoutNode n : s.nodes) { + minPos[n.layer] = max + n.width + xOffset; + n.x = max; + } + } + } + + private int predSum(LayoutNode n) { + int sum = 0; + for (LayoutEdge e : n.preds) { + assert e.to == n; + //sum += (e.from.x + e.relativeFrom + (int)hashMap.get(e.from).d) - (e.to.x + e.relativeTo + (int)hashMap.get(e.to).d); + sum += (e.from.x + e.relativeFrom) - (e.to.x + e.relativeTo); + } + + return sum; + } + + private int succSum(LayoutNode n) { + int sum = 0; + for (LayoutEdge e : n.succs) { + + assert e.from == n; + sum += (e.to.x + e.relativeTo) - (e.from.x + e.relativeFrom); + //sum += (e.to.x + e.relativeTo + (int)hashMap.get(e.to).d) - (e.from.x + e.relativeFrom + (int)hashMap.get(e.from).d); + } + + return sum; + + } + + private void downValues() { + + for (Segment s : segments) { + downValues(s); + + } + + } + + private void downValues(Segment s) { + LayoutNode n = s.nodes.get(0); // Only first node needed, all other have same coordinate + + if (n.preds.size() == 0) { + // Value is 0.0; + if (n.succs.size() == 0) { + s.d = 0.0f; + } else { + s.d = (((float) succSum(n) / (float) n.succs.size())) / 2; + } + } else { + s.d = (float) predSum(n) / (float) n.preds.size(); + } + } + + private void upValues() { + for (Segment s : segments) { + upValues(s); + } + } + + private void upValues(Segment s) { + LayoutNode n = s.nodes.get(0); // Only first node needed, all other have same coordinate + + if (n.succs.size() == 0) { + // Value is 0.0; + if (n.preds.size() == 0) { + s.d = 0.0f; + } else { + s.d = (float) predSum(n) / (float) n.preds.size(); + } + } else { + s.d = ((float) succSum(n) / (float) n.succs.size()) / 2; + } + } + + private void sweep(boolean down) { + + if (down) { + downValues(); + } else { + upValues(); + } + + SortedSet regions = new TreeSet(regionComparator); + for (Segment s : segments) { + s.region = new Region(); + s.region.minOrderNumber = s.orderNumber; + s.region.segments.add(s); + s.region.d = s.d; + regions.add(s.region); + } + + for (Segment s : segments) { + for (LayoutNode n : s.nodes) { + if (n.pos != 0) { + LayoutNode prevNode = layers[n.layer].get(n.pos - 1); + if (prevNode.x + prevNode.width + xOffset == n.x) { + Segment other = hashMap.get(prevNode); + Region r1 = s.region; + Region r2 = other.region; + // They are close together + if (r1 != r2 && r2.d >= r1.d) { + + if (r2.segments.size() < r1.segments.size()) { + + r1.d = (r1.d * r1.segments.size() + r2.d * r2.segments.size()) / (r1.segments.size() + r2.segments.size()); + + for (Segment tempS : r2.segments) { + r1.segments.add(tempS); + tempS.region = r1; + r1.minOrderNumber = Math.min(r1.minOrderNumber, tempS.orderNumber); + } + + regions.remove(r2); + } else { + + r2.d = (r1.d * r1.segments.size() + r2.d * r2.segments.size()) / (r1.segments.size() + r2.segments.size()); + + for (Segment tempS : r1.segments) { + r2.segments.add(tempS); + tempS.region = r2; + r2.minOrderNumber = Math.min(r2.minOrderNumber, tempS.orderNumber); + } + + regions.remove(r1); + } + } + } + } + } + } + + + + ArrayList reversedRegions = new ArrayList(); + for (Region r : regions) { + if (r.d < 0) { + processRegion(r, down); + } else { + reversedRegions.add(0, r); + } + } + + for (Region r : reversedRegions) { + processRegion(r, down); + } + + } + + private void processRegion(Region r, boolean down) { + + // Do not move + if ((int) r.d == 0) { + return; + } + + ArrayList arr = new ArrayList(); + for (Segment s : r.segments) { + arr.add(s); + } + + if (r.d > 0) { + Collections.reverse(arr); + } + + for (Segment s : arr) { + + + int min = (int) r.d; + if (min < 0) { + min = -min; + } + + for (LayoutNode n : s.nodes) { + + int layer = n.layer; + int pos = n.pos; + + + if (r.d > 0) { + + if (pos != layers[layer].size() - 1) { + + int off = layers[layer].get(pos + 1).x - n.x - xOffset - n.width; + assert off >= 0; + if (off < min) { + min = off; + } + } + + } else { + + if (pos != 0) { + + int off = n.x - xOffset - layers[layer].get(pos - 1).x - layers[layer].get(pos - 1).width; + assert off >= 0; + if (off < min) { + min = off; + } + } + } + } + + assert min >= 0; + if (min != 0) { + for (LayoutNode n : s.nodes) { + if (r.d > 0) { + n.x += min; + } else { + n.x -= min; + } + + } + } + } + } + + protected void run() { + + generateSegments(); + addEdges(); + topologicalSorting(); + initialPositions(); + for (int i = 0; i < SWEEP_ITERATIONS; i++) { + + sweep(true); + sweep(true); + sweep(false); + sweep(false); + } + + sweep(true); + sweep(true); + } + } + private static Comparator crossingNodeComparator = new Comparator() { + + 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; + } + } + + protected void run() { + + layers = new List[layerCount]; + + for (int i = 0; i < layerCount; i++) { + layers[i] = new ArrayList(); + } + + + // 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(); + } + + /*for(int i=0; i 0) { + sum /= n.preds.size(); + n.crossingNumber = sum; + //if(n.vertex == null) n.crossingNumber += layers[i].size(); + } + } + + + 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.size() == 0); + if (down) { + cond = (n.preds.size() == 0); + } + + 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 doubleSweep() { + // Downsweep + for(int i=0; i= layerCount) { + index = 2*layerCount - i - 1; + } + for(LayoutNode n : layers[index]) { + float sum = 0.0f; + for(LayoutEdge e : n.preds) { + float cur = e.from.pos; + if(e.from.width != 0 && e.relativeFrom != 0) { + cur += (float)e.relativeFrom / (float)(e.from.width); + } + sum += cur; + } + for(LayoutEdge e : n.succs) { + float cur = e.to.pos; + if(e.to.width != 0 && e.relativeTo != 0) { + cur += (float)e.relativeTo / (float)(e.to.width); + } + sum += cur; + } + if(n.preds.size() + n.succs.size() > 0) { + sum /= n.preds.size() + n.succs.size(); + n.crossingNumber = sum; + } + } + Collections.sort(layers[index], crossingNodeComparator); + updateXOfLayer(index); + int z = 0; + for(LayoutNode n : layers[index]) { + n.pos = z; + z++; + } + } + }*/ + + 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 sum = 0; + for (LayoutEdge e : n.succs) { + int cur = e.to.x + e.relativeTo;//pos; + /* + if(e.to.width != 0 && e.relativeTo != 0) { + cur += (float)e.relativeTo / (float)(e.to.width); + }*/ + + sum += cur; + } + + if (n.succs.size() > 0) { + sum /= n.succs.size(); + n.crossingNumber = sum; + //if(n.vertex == null) n.crossingNumber += layers[i].size(); + } + + } + + updateCrossingNumbers(i, false); + Collections.sort(layers[i], crossingNodeComparator); + updateXOfLayer(i); + + int z = 0; + for (LayoutNode n : layers[i]) { + n.pos = z; + z++; + } + } + } + + private int evaluate() { + // TODO: Implement efficient evaluate / crossing min + return 0; + } + + @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 { + + protected void run() { + int curY = 0; + //maxLayerHeight = new int[layers.length]; + 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); + } + } + + //maxLayerHeight[i] = maxHeight + baseLine + bottomBaseLine; + + 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; + } + } + } + + protected void run() { + oldNodeCount = nodes.size(); + + + if (combine == Combine.SAME_OUTPUTS) { + + Comparator comparator = new Comparator() { + + 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; + 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; + 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; + 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()); + } + + if (n.vertex.toString().equals("1012 CastPP")) { + int x = 0; + } + + 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; + 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].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(); + 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; + } + } + + protected void run() { + HashSet set = new HashSet(); + for (LayoutNode n : nodes) { + if (n.preds.size() == 0) { + set.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; + } + + // Swap sets + HashSet tmp = set; + set = newSet; + newSet = tmp; + z += minLayerDifference; + } + + optimize(set); + + 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; + assert n.layer == 0; + } + } + + public void optimize(HashSet set) { + + for (LayoutNode n : set) { + if (n.preds.size() == 0 && n.succs.size() > 0) { + int minLayer = n.succs.get(0).to.layer; + for (LayoutEdge e : n.succs) { + minLayer = Math.min(minLayer, e.to.layer); + } + + n.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; + + protected void run() { + + // Remove self-edges, TODO: Special treatment + 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() { + + 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 { + + 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); + //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; + } + + } + } + } + + public void doRouting(LayoutGraph graph) { + // Do nothing for now + } +} diff --git a/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/InterClusterConnection.java b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/InterClusterConnection.java new file mode 100644 index 0000000000000000000000000000000000000000..ef423ed753f42856520a6dcb77bd35ef259c78d3 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/InterClusterConnection.java @@ -0,0 +1,76 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.hierarchicallayout; + +import com.sun.hotspot.igv.layout.Link; +import com.sun.hotspot.igv.layout.Port; +import java.awt.Point; +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public class InterClusterConnection implements Link { + + private Port inputSlot; + private Port outputSlot; + private List intermediatePoints; + private ClusterInputSlotNode inputSlotNode; + private ClusterOutputSlotNode outputSlotNode; + + public InterClusterConnection(ClusterOutputSlotNode outputSlotNode, ClusterInputSlotNode inputSlotNode) { + this.outputSlotNode = outputSlotNode; + this.inputSlotNode = inputSlotNode; + this.inputSlot = inputSlotNode.getInputSlot(); + this.outputSlot = outputSlotNode.getOutputSlot(); + intermediatePoints = new ArrayList(); + } + + public ClusterOutputSlotNode getOutputSlotNode() { + return outputSlotNode; + } + + public Port getTo() { + return inputSlot; + } + + public Port getFrom() { + return outputSlot; + } + + public void setControlPoints(List p) { + this.intermediatePoints = p; + } + + public List getControlPoints() { + return intermediatePoints; + } + + @Override + public String toString() { + return "InterClusterConnection[from=" + getFrom() + ", to=" + getTo() + "]"; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/Node.java b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/Node.java new file mode 100644 index 0000000000000000000000000000000000000000..3d43e91be9417592823c84f3a16a48e4facd29bc --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/Node.java @@ -0,0 +1,161 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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 --git a/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/OldHierarchicalLayoutManager.java b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/OldHierarchicalLayoutManager.java new file mode 100644 index 0000000000000000000000000000000000000000..5ed6c93afa1d46896a1ceed81cf984a578a8118a --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/OldHierarchicalLayoutManager.java @@ -0,0 +1,1222 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.hierarchicallayout; + +import java.awt.Point; +import java.util.ArrayList; +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 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.Port; +import com.sun.hotspot.igv.layout.Vertex; + +/** + * + * @author Thomas Wuerthinger + */ +public class OldHierarchicalLayoutManager implements LayoutManager { + + public static final int DUMMY_WIDTH = 0; + public static final int DUMMY_HEIGHT = 0; + public static final int LAYER_OFFSET = 50; + public static final int OFFSET = 8; + public static final boolean VERTICAL_LAYOUT = true; + public static final boolean ASSERT = false; + public static final boolean TRACE = false; + public static final Timing initTiming = new Timing("init"); + public static final Timing removeCyclesTiming = new Timing("removeCycles"); + public static final Timing reversedEdgesTiming = new Timing("reversedEdges"); + public static final Timing assignLayersTiming = new Timing("assignLayers"); + public static final Timing dummyNodesTiming = new Timing("dummyNodes"); + public static final Timing crossingReductionTiming = new Timing("crossingReduction"); + public static final Timing assignCoordinatesTiming = new Timing("assignCoordinates"); + public static final Timing assignRealTiming = new Timing("assignReal"); + public static final Timing rootVertexTiming = new Timing("rootVertex"); + public static final Timing createEdgesTiming = new Timing("createEdges"); + public static final Timing optimizeMedianTiming = new Timing("optimizeMedian"); + private Combine combine; + + public enum Combine { + + NONE, + SAME_INPUTS, + SAME_OUTPUTS + } + + private class NodeData { + + private Map reversePositions; + private Vertex node; + private Link edge; + private int layer; + private int x; + private int y; + private int width; + + public NodeData(Vertex node) { + reversePositions = new HashMap(); + layer = -1; + this.node = node; + assert node != null; + + if (VERTICAL_LAYOUT) { + width = node.getSize().width; + } else { + width = node.getSize().height; + } + } + + public NodeData(Link edge) { + layer = -1; + this.edge = edge; + assert edge != null; + + if (VERTICAL_LAYOUT) { + width = DUMMY_WIDTH; + } else { + width = DUMMY_HEIGHT; + } + } + + public Vertex getNode() { + return node; + } + + public Link getEdge() { + return edge; + } + + public int getCoordinate() { + return x; + } + + public void setCoordinate(int x) { + this.x = x; + } + + public int getX() { + if (VERTICAL_LAYOUT) { + return x; + } else { + return y; + } + } + + public int getY() { + if (VERTICAL_LAYOUT) { + return y; + } else { + return x; + } + } + + public void setLayerCoordinate(int y) { + this.y = y; + } + + public void setLayer(int x) { + layer = x; + } + + public int getLayer() { + return layer; + } + + public boolean isDummy() { + return edge != null; + } + + public int getWidth() { + return width; + } + + public void addReversedStartEdge(Edge e) { + assert e.getData().isReversed(); + Port port = e.getData().getEdge().getTo(); + int pos = addReversedPort(port); + Point start = e.getData().getRelativeStart(); + e.getData().addStartPoint(start); + int yCoord = node.getSize().height + width - node.getSize().width; + e.getData().addStartPoint(new Point(start.x, yCoord)); + e.getData().addStartPoint(new Point(pos, yCoord)); + e.getData().setRelativeStart(new Point(pos, 0)); + } + + private int addReversedPort(Port p) { + if (reversePositions.containsKey(p)) { + return reversePositions.get(p); + } else { + width += OFFSET; + reversePositions.put(p, width); + return width; + } + } + + public void addReversedEndEdge(Edge e) { + assert e.getData().isReversed(); + int pos = addReversedPort(e.getData().getEdge().getFrom()); + Point end = e.getData().getRelativeEnd(); + e.getData().setRelativeEnd(new Point(pos, node.getSize().height)); + int yCoord = 0 - width + node.getSize().width; + e.getData().addEndPoint(new Point(pos, yCoord)); + e.getData().addEndPoint(new Point(end.x, yCoord)); + e.getData().addEndPoint(end); + } + + public int getHeight() { + if (isDummy()) { + if (VERTICAL_LAYOUT) { + return DUMMY_HEIGHT; + } else { + return DUMMY_WIDTH; + } + + } else { + if (VERTICAL_LAYOUT) { + return node.getSize().height; + } else { + return node.getSize().width; + } + } + } + + @Override + public String toString() { + if (isDummy()) { + return edge.toString() + "(layer=" + layer + ")"; + } else { + return node.toString() + "(layer=" + layer + ")"; + } + } + } + + private class EdgeData { + + private Point relativeEnd; + private Point relativeStart; + private List startPoints; + private List endPoints; + private boolean important; + private boolean reversed; + private Link edge; + + public EdgeData(Link edge) { + this(edge, false); + } + + public EdgeData(Link edge, boolean rev) { + this.edge = edge; + reversed = rev; + relativeStart = edge.getFrom().getRelativePosition(); + relativeEnd = edge.getTo().getRelativePosition(); + assert relativeStart.x >= 0 && relativeStart.x <= edge.getFrom().getVertex().getSize().width; + assert relativeStart.y >= 0 && relativeStart.y <= edge.getFrom().getVertex().getSize().height; + assert relativeEnd.x >= 0 && relativeEnd.x <= edge.getTo().getVertex().getSize().width; + assert relativeEnd.y >= 0 && relativeEnd.y <= edge.getTo().getVertex().getSize().height; + startPoints = new ArrayList(); + endPoints = new ArrayList(); + this.important = true; + } + + public boolean isImportant() { + return important; + } + + public void setImportant(boolean b) { + this.important = b; + } + + public List getStartPoints() { + return startPoints; + } + + public List getEndPoints() { + return endPoints; + } + + public List getAbsoluteEndPoints() { + if (endPoints.size() == 0) { + return endPoints; + } + + List result = new ArrayList(); + Point point = edge.getTo().getVertex().getPosition(); + for (Point p : endPoints) { + Point p2 = new Point(p.x + point.x, p.y + point.y); + result.add(p2); + } + + return result; + } + + public List getAbsoluteStartPoints() { + if (startPoints.size() == 0) { + return startPoints; + } + + List result = new ArrayList(); + Point point = edge.getFrom().getVertex().getPosition(); + for (Point p : startPoints) { + Point p2 = new Point(p.x + point.x, p.y + point.y); + result.add(p2); + } + + return result; + } + + public void addEndPoint(Point p) { + endPoints.add(p); + } + + public void addStartPoint(Point p) { + startPoints.add(p); + } + + public Link getEdge() { + return edge; + } + + public void setRelativeEnd(Point p) { + relativeEnd = p; + } + + public void setRelativeStart(Point p) { + relativeStart = p; + } + + public Point getRelativeEnd() { + return relativeEnd; + } + + public Point getRelativeStart() { + return relativeStart; + } + + public boolean isReversed() { + return reversed; + } + + public void setReversed(boolean b) { + reversed = b; + } + + @Override + public String toString() { + return "EdgeData[reversed=" + reversed + "]"; + } + } + private Graph graph; + private Map> nodeMap; + private int layerOffset; + + /** Creates a new instance of HierarchicalPositionManager */ + public OldHierarchicalLayoutManager(Combine combine) { + this(combine, LAYER_OFFSET); + } + + public OldHierarchicalLayoutManager(Combine combine, int layerOffset) { + this.combine = combine; + this.layerOffset = layerOffset; + } + + public void doRouting(LayoutGraph graph) { + } + + //public void setPositions(PositionedNode rootNode, List nodes, List edges) { + public void doLayout(LayoutGraph layoutGraph) { + doLayout(layoutGraph, new HashSet(), new HashSet()); + } + + public void doLayout(LayoutGraph layoutGraph, Set firstLayerHint, Set lastLayerHint) { + doLayout(layoutGraph, firstLayerHint, lastLayerHint, new HashSet()); + } + + public void doLayout(LayoutGraph layoutGraph, Set firstLayerHint, Set lastLayerHint, Set importantLinksHint) { + + if (TRACE) { + System.out.println("HierarchicalPositionManager.doLayout called"); + System.out.println("Vertex count = " + layoutGraph.getVertices().size() + " Link count = " + layoutGraph.getLinks().size()); + } + + // Nothing to do => quit immediately + if (layoutGraph.getVertices().size() == 0) { + return; + } + + initTiming.start(); + + // Mapping vertex to Node in graph + nodeMap = new HashMap>(); + + graph = new Graph(); + + Set> rootNodes = new HashSet>(); + Set startRootVertices = new HashSet(); + + for (Vertex v : layoutGraph.getVertices()) { + if (v.isRoot()) { + startRootVertices.add(v); + } + } + + rootVertexTiming.start(); + Set rootVertices = layoutGraph.findRootVertices(startRootVertices); + rootVertexTiming.stop(); + + + for (Vertex node : layoutGraph.getVertices()) { + + NodeData data = new NodeData(node); + Node n = graph.createNode(data, node); + nodeMap.put(node, n); + + if (rootVertices.contains(node)) { + rootNodes.add(n); + } + } + + Set links = layoutGraph.getLinks(); + Link[] linkArr = new Link[links.size()]; + links.toArray(linkArr); + + List linkList = new ArrayList(); + for (Link l : linkArr) { + linkList.add(l); + } + + createEdgesTiming.start(); + Collections.sort(linkList, new Comparator() { + + public int compare(Link o1, Link o2) { + int result = o1.getFrom().getVertex().compareTo(o2.getFrom().getVertex()); + if (result == 0) { + return o1.getTo().getVertex().compareTo(o2.getTo().getVertex()); + } else { + return result; + } + } + }); + + for (Link edge : linkList) { + EdgeData data = new EdgeData(edge); + graph.createEdge(graph.getNode(edge.getFrom().getVertex()), graph.getNode(edge.getTo().getVertex()), data, data); + if (importantLinksHint.size() > 0 && !importantLinksHint.contains(edge)) { + data.setImportant(false); + } + } + createEdgesTiming.stop(); + + initTiming.stop(); + + removeCyclesTiming.start(); + + // STEP 1: Remove cycles! + removeCycles(rootNodes); + if (ASSERT) { + assert checkRemoveCycles(); + } + + removeCyclesTiming.stop(); + + reversedEdgesTiming.start(); + + for (Node n : graph.getNodes()) { + List> edges = new ArrayList>(n.getOutEdges()); + Collections.sort(edges, new Comparator>() { + + public int compare(Edge o1, Edge o2) { + return o2.getData().getRelativeEnd().x - o1.getData().getRelativeEnd().x; + } + }); + + + for (Edge e : edges) { + + if (e.getData().isReversed()) { + e.getSource().getData().addReversedEndEdge(e); + } + } + } + + for (Node n : graph.getNodes()) { + List> edges = new ArrayList>(n.getInEdges()); + Collections.sort(edges, new Comparator>() { + + public int compare(Edge o1, Edge o2) { + return o2.getData().getRelativeStart().x - o1.getData().getRelativeStart().x; + } + }); + + + for (Edge e : edges) { + if (e.getData().isReversed()) { + e.getDest().getData().addReversedStartEdge(e); + } + } + } + + reversedEdgesTiming.stop(); + + assignLayersTiming.start(); + // STEP 2: Assign layers! + int maxLayer = assignLayers(rootNodes, firstLayerHint, lastLayerHint); + if (ASSERT) { + assert checkAssignLayers(); + } + + // Put into layer array + //int maxLayer = 0; + //for(Node n : graph.getNodes()) { + // maxLayer = Math.max(maxLayer, n.getData().getLayer()); + //} + + + ArrayList> layers[] = new ArrayList[maxLayer + 1]; + int layerSizes[] = new int[maxLayer + 1]; + for (int i = 0; i < maxLayer + 1; i++) { + layers[i] = new ArrayList>(); + } + + for (Node n : graph.getNodes()) { + int curLayer = n.getData().getLayer(); + layers[curLayer].add(n); + } + + assignLayersTiming.stop(); + + // STEP 3: Insert dummy nodes! + dummyNodesTiming.start(); + insertDummyNodes(layers); + if (ASSERT) { + assert checkDummyNodes(); + } + dummyNodesTiming.stop(); + + crossingReductionTiming.start(); + // STEP 4: Assign Y coordinates + assignLayerCoordinates(layers, layerSizes); + + // STEP 5: Crossing reduction + crossingReduction(layers); + crossingReductionTiming.stop(); + + // STEP 6: Assign Y coordinates + assignCoordinatesTiming.start(); + assignCoordinates(layers); + assignCoordinatesTiming.stop(); + + assignRealTiming.start(); + + // Assign coordinates of nodes to real objects + for (Node n : graph.getNodes()) { + if (!n.getData().isDummy()) { + + Vertex node = n.getData().getNode(); + node.setPosition(new Point(n.getData().getX(), n.getData().getY())); + } + } + + for (Node n : graph.getNodes()) { + if (!n.getData().isDummy()) { + + Vertex node = n.getData().getNode(); + + List> outEdges = n.getOutEdges(); + for (Edge e : outEdges) { + Node succ = e.getDest(); + if (succ.getData().isDummy()) { + //PositionedEdge edge = succ.getData().getEdge(); + List points = new ArrayList(); + assignToRealObjects(layerSizes, succ, points); + } else { + List points = new ArrayList(); + + EdgeData otherEdgeData = e.getData(); + points.addAll(otherEdgeData.getAbsoluteStartPoints()); + Link otherEdge = otherEdgeData.getEdge(); + Point relFrom = new Point(otherEdgeData.getRelativeStart()); + Point from = otherEdge.getFrom().getVertex().getPosition(); + relFrom.move(relFrom.x + from.x, relFrom.y + from.y); + points.add(relFrom); + + Point relTo = new Point(otherEdgeData.getRelativeEnd()); + Point to = otherEdge.getTo().getVertex().getPosition(); + relTo.move(relTo.x + to.x, relTo.y + to.y); + assert from != null; + assert to != null; + points.add(relTo); + points.addAll(otherEdgeData.getAbsoluteEndPoints()); + e.getData().getEdge().setControlPoints(points); + } + } + } + } + + assignRealTiming.stop(); + + initTiming.print(); + removeCyclesTiming.print(); + reversedEdgesTiming.print(); + assignLayersTiming.print(); + dummyNodesTiming.print(); + crossingReductionTiming.print(); + assignCoordinatesTiming.print(); + assignRealTiming.print(); + rootVertexTiming.print(); + createEdgesTiming.print(); + optimizeMedianTiming.print(); + } + + public boolean onOneLine(Point p1, Point p2, Point p3) { + int xoff1 = p1.x - p2.x; + int yoff1 = p1.y - p2.y; + int xoff2 = p3.x - p2.x; + int yoff2 = p3.y - p2.x; + + return (xoff1 * yoff2 - yoff1 * xoff2 == 0); + } + + private void assignToRealObjects(int layerSizes[], Node cur, List points) { + assert cur.getData().isDummy(); + + ArrayList otherPoints = new ArrayList(points); + + int size = layerSizes[cur.getData().getLayer()]; + otherPoints.add(new Point(cur.getData().getX(), cur.getData().getY() - size / 2)); + if (otherPoints.size() >= 3 && onOneLine(otherPoints.get(otherPoints.size() - 1), otherPoints.get(otherPoints.size() - 2), otherPoints.get(otherPoints.size() - 3))) { + otherPoints.remove(otherPoints.size() - 2); + } + otherPoints.add(new Point(cur.getData().getX(), cur.getData().getY() + size / 2)); + if (otherPoints.size() >= 3 && onOneLine(otherPoints.get(otherPoints.size() - 1), otherPoints.get(otherPoints.size() - 2), otherPoints.get(otherPoints.size() - 3))) { + otherPoints.remove(otherPoints.size() - 2); + } + + for (int i = 0; i < cur.getOutEdges().size(); i++) { + Node otherSucc = cur.getOutEdges().get(i).getDest(); + + if (otherSucc.getData().isDummy()) { + assignToRealObjects(layerSizes, otherSucc, otherPoints); + } else { + EdgeData otherEdgeData = cur.getOutEdges().get(i).getData(); + Link otherEdge = otherEdgeData.getEdge(); + + List middlePoints = new ArrayList(otherPoints); + if (cur.getOutEdges().get(i).getData().isReversed()) { + Collections.reverse(middlePoints); + } + + ArrayList copy = new ArrayList(); + Point relFrom = new Point(otherEdgeData.getRelativeStart()); + Point from = otherEdge.getFrom().getVertex().getPosition(); + //int moveUp = (size - otherEdge.getFrom().getVertex().getSize().height) / 2; + relFrom.move(relFrom.x + from.x, relFrom.y + from.y); + copy.addAll(otherEdgeData.getAbsoluteStartPoints()); + copy.add(relFrom); + copy.addAll(middlePoints); + + Point relTo = new Point(otherEdgeData.getRelativeEnd()); + Point to = otherEdge.getTo().getVertex().getPosition(); + relTo.move(relTo.x + to.x, relTo.y + to.y); + copy.add(relTo); + + copy.addAll(otherEdgeData.getAbsoluteEndPoints()); + + + otherEdge.setControlPoints(copy); + } + } + } + + private boolean checkDummyNodes() { + for (Edge e : graph.getEdges()) { + if (e.getSource().getData().getLayer() != e.getDest().getData().getLayer() - 1) { + return false; + } + } + + return true; + } + + private void insertDummyNodes(ArrayList> layers[]) { + + int sum = 0; + List> nodes = new ArrayList>(graph.getNodes()); + int edgeCount = 0; + int innerMostLoop = 0; + + for (Node n : nodes) { + List> edges = new ArrayList>(n.getOutEdges()); + for (Edge e : edges) { + + edgeCount++; + Link edge = e.getData().getEdge(); + Node destNode = e.getDest(); + Node lastNode = n; + Edge lastEdge = e; + + boolean searchForNode = (combine != Combine.NONE); + for (int i = n.getData().getLayer() + 1; i < destNode.getData().getLayer(); i++) { + + Node foundNode = null; + if (searchForNode) { + for (Node sameLayerNode : layers[i]) { + innerMostLoop++; + + if (combine == Combine.SAME_OUTPUTS) { + if (sameLayerNode.getData().isDummy() && sameLayerNode.getData().getEdge().getFrom() == edge.getFrom()) { + foundNode = sameLayerNode; + break; + } + } else if (combine == Combine.SAME_INPUTS) { + if (sameLayerNode.getData().isDummy() && sameLayerNode.getData().getEdge().getTo() == edge.getTo()) { + foundNode = sameLayerNode; + break; + } + } + } + } + + if (foundNode == null) { + searchForNode = false; + NodeData intermediateData = new NodeData(edge); + Node curNode = graph.createNode(intermediateData, null); + curNode.getData().setLayer(i); + layers[i].add(0, curNode); + sum++; + lastEdge.remove(); + graph.createEdge(lastNode, curNode, e.getData(), null); + assert lastNode.getData().getLayer() == curNode.getData().getLayer() - 1; + lastEdge = graph.createEdge(curNode, destNode, e.getData(), null); + lastNode = curNode; + } else { + lastEdge.remove(); + lastEdge = graph.createEdge(foundNode, destNode, e.getData(), null); + lastNode = foundNode; + } + + } + } + } + + if (TRACE) { + System.out.println("Number of edges: " + edgeCount); + } + if (TRACE) { + System.out.println("Dummy nodes inserted: " + sum); + } + } + + private void assignLayerCoordinates(ArrayList> layers[], int layerSizes[]) { + int cur = 0; + for (int i = 0; i < layers.length; i++) { + int maxHeight = 0; + for (Node n : layers[i]) { + maxHeight = Math.max(maxHeight, n.getData().getHeight()); + } + + layerSizes[i] = maxHeight; + for (Node n : layers[i]) { + int curCoordinate = cur + (maxHeight - n.getData().getHeight()) / 2; + n.getData().setLayerCoordinate(curCoordinate); + } + cur += maxHeight + layerOffset; + + } + } + + private void assignCoordinates(ArrayList> layers[]) { + + // TODO: change this + for (int i = 0; i < layers.length; i++) { + ArrayList> curArray = layers[i]; + int curY = 0; + for (Node n : curArray) { + + n.getData().setCoordinate(curY); + if (!n.getData().isDummy()) { + curY += n.getData().getWidth(); + } + curY += OFFSET; + + } + } + + int curSol = evaluateSolution(); + if (TRACE) { + System.out.println("First coordinate solution found: " + curSol); + } + + // Sort to correct order + for (int i = 0; i < layers.length; i++) { + Collections.sort(layers[i], new Comparator>() { + + public int compare(Node o1, Node o2) { + if (o2.getData().isDummy()) { + return 1; + } else if (o1.getData().isDummy()) { + return -1; + } + return o2.getInEdges().size() + o2.getOutEdges().size() - o1.getInEdges().size() - o1.getOutEdges().size(); + } + }); + } + + + optimizeMedianTiming.start(); + for (int i = 0; i < 2; i++) { + optimizeMedian(layers); + curSol = evaluateSolution(); + if (TRACE) { + System.out.println("Current coordinate solution found: " + curSol); + } + } + optimizeMedianTiming.stop(); + normalizeCoordinate(); + + } + + private void normalizeCoordinate() { + + int min = Integer.MAX_VALUE; + for (Node n : graph.getNodes()) { + min = Math.min(min, n.getData().getCoordinate()); + } + + for (Node n : graph.getNodes()) { + n.getData().setCoordinate(n.getData().getCoordinate() - min); + } + + } + + private void optimizeMedian(ArrayList> layers[]) { + + // Downsweep + for (int i = 1; i < layers.length; i++) { + + ArrayList> processingList = layers[i]; + ArrayList> alreadyAssigned = new ArrayList>(); + for (Node n : processingList) { + + + ArrayList> preds = new ArrayList>(n.getPredecessors()); + int pos = n.getData().getCoordinate(); + if (preds.size() > 0) { + + Collections.sort(preds, new Comparator>() { + + public int compare(Node o1, Node o2) { + return o1.getData().getCoordinate() - o2.getData().getCoordinate(); + } + }); + + if (preds.size() % 2 == 0) { + assert preds.size() >= 2; + pos = (preds.get(preds.size() / 2).getData().getCoordinate() - calcRelativeCoordinate(preds.get(preds.size() / 2), n) + preds.get(preds.size() / 2 - 1).getData().getCoordinate() - calcRelativeCoordinate(preds.get(preds.size() / 2 - 1), n)) / 2; + } else { + assert preds.size() >= 1; + pos = preds.get(preds.size() / 2).getData().getCoordinate() - calcRelativeCoordinate(preds.get(preds.size() / 2), n); + } + } + + tryAdding(alreadyAssigned, n, pos); + } + } + // Upsweep + for (int i = layers.length - 2; i >= 0; i--) { + ArrayList> processingList = layers[i]; + ArrayList> alreadyAssigned = new ArrayList>(); + for (Node n : processingList) { + + ArrayList> succs = new ArrayList>(n.getSuccessors()); + int pos = n.getData().getCoordinate(); + if (succs.size() > 0) { + + Collections.sort(succs, new Comparator>() { + + public int compare(Node o1, Node o2) { + return o1.getData().getCoordinate() - o2.getData().getCoordinate(); + } + }); + + if (succs.size() % 2 == 0) { + assert succs.size() >= 2; + pos = (succs.get(succs.size() / 2).getData().getCoordinate() - calcRelativeCoordinate(n, succs.get(succs.size() / 2)) + succs.get(succs.size() / 2 - 1).getData().getCoordinate() - calcRelativeCoordinate(n, succs.get(succs.size() / 2 - 1))) / 2; + } else { + assert succs.size() >= 1; + pos = succs.get(succs.size() / 2).getData().getCoordinate() - calcRelativeCoordinate(n, succs.get(succs.size() / 2)); + } + } + + tryAdding(alreadyAssigned, n, pos); + } + } + } + + private int median(ArrayList arr) { + assert arr.size() > 0; + Collections.sort(arr); + if (arr.size() % 2 == 0) { + return (arr.get(arr.size() / 2) + arr.get(arr.size() / 2 - 1)) / 2; + } else { + return arr.get(arr.size() / 2); + } + } + + private int calcRelativeCoordinate(Node n, Node succ) { + + if (n.getData().isDummy() && succ.getData().isDummy()) { + return 0; + } + + int pos = 0; + int pos2 = 0; + ArrayList coords2 = new ArrayList(); + ArrayList coords = new ArrayList(); + /*if(!n.getData().isDummy())*/ { + for (Edge e : n.getOutEdges()) { + + //System.out.println("reversed: " + e.getData().isReversed()); + if (e.getDest() == succ) { + + if (e.getData().isReversed()) { + if (!n.getData().isDummy()) { + coords.add(e.getData().getRelativeEnd().x); + } + + if (!succ.getData().isDummy()) { + coords2.add(e.getData().getRelativeStart().x); + } + } else { + if (!n.getData().isDummy()) { + coords.add(e.getData().getRelativeStart().x); + } + + if (!succ.getData().isDummy()) { + coords2.add(e.getData().getRelativeEnd().x); + } + } + } + } + + // assert coords.size() > 0; + if (!n.getData().isDummy()) { + pos = median(coords); + } + + if (!succ.getData().isDummy()) { + pos2 = median(coords2); + } + } + //System.out.println("coords=" + coords); + //System.out.println("coords2=" + coords2); + + return pos - pos2; + } + + private boolean intersect(int v1, int w1, int v2, int w2) { + if (v1 >= v2 && v1 < v2 + w2) { + return true; + } + if (v1 + w1 > v2 && v1 + w1 < v2 + w2) { + return true; + } + if (v1 < v2 && v1 + w1 > v2) { + return true; + } + return false; + } + + private boolean intersect(Node n1, Node n2) { + return intersect(n1.getData().getCoordinate(), n1.getData().getWidth() + OFFSET, n2.getData().getCoordinate(), n2.getData().getWidth() + OFFSET); + } + + private void tryAdding(List> alreadyAssigned, Node node, int pos) { + + boolean doesIntersect = false; + node.getData().setCoordinate(pos); + for (Node n : alreadyAssigned) { + if (n.getData().getCoordinate() + n.getData().getWidth() < pos) { + break; + } else if (intersect(node, n)) { + doesIntersect = true; + break; + } + + } + + if (!doesIntersect) { + + // Everything fine, just place the node + int z = 0; + for (Node n : alreadyAssigned) { + if (pos > n.getData().getCoordinate()) { + break; + } + z++; + } + + if (z == -1) { + z = alreadyAssigned.size(); + } + + + if (ASSERT) { + assert !findOverlap(alreadyAssigned, node); + } + alreadyAssigned.add(z, node); + + } else { + + assert alreadyAssigned.size() > 0; + + // Search for alternative location + int minOffset = Integer.MAX_VALUE; + int minIndex = -1; + int minPos = 0; + int w = node.getData().getWidth() + OFFSET; + + // Try top-most + minIndex = 0; + minPos = alreadyAssigned.get(0).getData().getCoordinate() + alreadyAssigned.get(0).getData().getWidth() + OFFSET; + minOffset = Math.abs(minPos - pos); + + // Try bottom-most + Node lastNode = alreadyAssigned.get(alreadyAssigned.size() - 1); + int lastPos = lastNode.getData().getCoordinate() - w; + int lastOffset = Math.abs(lastPos - pos); + if (lastOffset < minOffset) { + minPos = lastPos; + minOffset = lastOffset; + minIndex = alreadyAssigned.size(); + } + + // Try between + for (int i = 0; i < alreadyAssigned.size() - 1; i++) { + Node curNode = alreadyAssigned.get(i); + Node nextNode = alreadyAssigned.get(i + 1); + + int start = nextNode.getData().getCoordinate() + nextNode.getData().getWidth() + OFFSET; + int end = curNode.getData().getCoordinate() - OFFSET; + + int bestPoss = end - node.getData().getWidth(); + if (bestPoss < pos && pos - bestPoss > minOffset) { + // No better solution possible => break + break; + } + + if (end - start >= node.getData().getWidth()) { + // Node could fit here + int cand1 = start; + int cand2 = end - node.getData().getWidth(); + int off1 = Math.abs(cand1 - pos); + int off2 = Math.abs(cand2 - pos); + if (off1 < minOffset) { + minPos = cand1; + minOffset = off1; + minIndex = i + 1; + } + + if (off2 < minOffset) { + minPos = cand2; + minOffset = off2; + minIndex = i + 1; + } + } + } + + assert minIndex != -1; + node.getData().setCoordinate(minPos); + if (ASSERT) { + assert !findOverlap(alreadyAssigned, node); + } + alreadyAssigned.add(minIndex, node); + } + + } + + private boolean findOverlap(List> nodes, Node node) { + + for (Node n1 : nodes) { + if (intersect(n1, node)) { + return true; + } + } + + return false; + } + + private int evaluateSolution() { + + int sum = 0; + for (Edge e : graph.getEdges()) { + Node source = e.getSource(); + Node dest = e.getDest(); + int offset = 0; + offset = Math.abs(source.getData().getCoordinate() - dest.getData().getCoordinate()); + sum += offset; + } + + return sum; + } + + private void crossingReduction(ArrayList> layers[]) { + + for (int i = 0; i < layers.length - 1; i++) { + + ArrayList> curNodes = layers[i]; + ArrayList> nextNodes = layers[i + 1]; + for (Node n : curNodes) { + for (Node succ : n.getSuccessors()) { + if (ASSERT) { + assert nextNodes.contains(succ); + } + nextNodes.remove(succ); + nextNodes.add(succ); + } + } + + } + + } + + private void removeCycles(Set> rootNodes) { + final List> reversedEdges = new ArrayList>(); + + + int removedCount = 0; + int reversedCount = 0; + + Graph.DFSTraversalVisitor visitor = graph.new DFSTraversalVisitor() { + + @Override + public boolean visitEdge(Edge e, boolean backEdge) { + if (backEdge) { + if (ASSERT) { + assert !reversedEdges.contains(e); + } + reversedEdges.add(e); + e.getData().setReversed(!e.getData().isReversed()); + } + + return e.getData().isImportant(); + } + }; + Set> nodes = new HashSet>(); + nodes.addAll(rootNodes); + + assert nodes.size() > 0; + + this.graph.traverseDFS(nodes, visitor); + + for (Edge e : reversedEdges) { + if (e.isSelfLoop()) { + e.remove(); + removedCount++; + } else { + e.reverse(); + reversedCount++; + } + } + } + + private boolean checkRemoveCycles() { + return !graph.hasCycles(); + } + // Only used by assignLayers + private int maxLayerTemp; + + private int assignLayers(Set> rootNodes, Set firstLayerHints, + Set lastLayerHints) { + this.maxLayerTemp = -1; + for (Node n : graph.getNodes()) { + n.getData().setLayer(-1); + } + + Graph.BFSTraversalVisitor traverser = graph.new BFSTraversalVisitor() { + + @Override + public void visitNode(Node n, int depth) { + if (depth > n.getData().getLayer()) { + n.getData().setLayer(depth); + maxLayerTemp = Math.max(maxLayerTemp, depth); + } + } + }; + + for (Node n : rootNodes) { + if (n.getData().getLayer() == -1) { + this.graph.traverseBFS(n, traverser, true); + } + } + + for (Vertex v : firstLayerHints) { + assert nodeMap.containsKey(v); + nodeMap.get(v).getData().setLayer(0); + } + + for (Vertex v : lastLayerHints) { + assert nodeMap.containsKey(v); + nodeMap.get(v).getData().setLayer(maxLayerTemp); + } + + return maxLayerTemp; + } + + private boolean checkAssignLayers() { + + for (Edge e : graph.getEdges()) { + Node source = e.getSource(); + Node dest = e.getDest(); + + + if (source.getData().getLayer() >= dest.getData().getLayer()) { + return false; + } + } + int maxLayer = 0; + for (Node n : graph.getNodes()) { + assert n.getData().getLayer() >= 0; + if (n.getData().getLayer() > maxLayer) { + maxLayer = n.getData().getLayer(); + } + } + + int countPerLayer[] = new int[maxLayer + 1]; + for (Node n : graph.getNodes()) { + countPerLayer[n.getData().getLayer()]++; + } + + if (TRACE) { + System.out.println("Number of layers: " + maxLayer); + } + return true; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/Timing.java b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/Timing.java new file mode 100644 index 0000000000000000000000000000000000000000..fe6cd28f2a04b4252c841ccfdb5b8339f9c08f47 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/HierarchicalLayout/src/com/sun/hotspot/igv/hierarchicallayout/Timing.java @@ -0,0 +1,67 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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 --git a/src/share/tools/IdealGraphVisualizer/Layout/build.xml b/src/share/tools/IdealGraphVisualizer/Layout/build.xml new file mode 100644 index 0000000000000000000000000000000000000000..002f9bcc3e83e78c8cfc4614b7ed88cfeb99c823 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Layout/build.xml @@ -0,0 +1,8 @@ + + + + + + Builds, tests, and runs the project com.sun.hotspot.igv.layout. + + diff --git a/src/share/tools/IdealGraphVisualizer/Layout/manifest.mf b/src/share/tools/IdealGraphVisualizer/Layout/manifest.mf new file mode 100644 index 0000000000000000000000000000000000000000..eafc2369dc6a9f4b1f2b79c1ff3794613c2905ed --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Layout/manifest.mf @@ -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 --git a/src/share/tools/IdealGraphVisualizer/Layout/nbproject/build-impl.xml b/src/share/tools/IdealGraphVisualizer/Layout/nbproject/build-impl.xml new file mode 100644 index 0000000000000000000000000000000000000000..84413d256763fe223d569e5c9db80a2880842a13 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Layout/nbproject/build-impl.xml @@ -0,0 +1,30 @@ + + + + + + You must set 'suite.dir' to point to your containing module suite + + + + + + + + + + + + + + + + + + + + + diff --git a/src/share/tools/IdealGraphVisualizer/Layout/nbproject/genfiles.properties b/src/share/tools/IdealGraphVisualizer/Layout/nbproject/genfiles.properties new file mode 100644 index 0000000000000000000000000000000000000000..f054d11726d2cd334fe6fc13210c2823b0ffb145 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Layout/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=cb0889d9 +build.xml.script.CRC32=d65fccb9 +build.xml.stylesheet.CRC32=79c3b980 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=cb0889d9 +nbproject/build-impl.xml.script.CRC32=7f82736d +nbproject/build-impl.xml.stylesheet.CRC32=deb65f65 diff --git a/src/share/tools/IdealGraphVisualizer/Layout/nbproject/platform.properties b/src/share/tools/IdealGraphVisualizer/Layout/nbproject/platform.properties new file mode 100644 index 0000000000000000000000000000000000000000..68ad75e5766f33be5a65a19d28cc7605c5b50a1c --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Layout/nbproject/platform.properties @@ -0,0 +1,29 @@ +# Deprecated since 5.0u1; for compatibility with 5.0: +disabled.clusters=\ + apisupport1,\ + harness,\ + ide8,\ + java1,\ + nb6.0,\ + profiler2 +disabled.modules=\ + org.netbeans.core.execution,\ + org.netbeans.core.multiview,\ + org.netbeans.core.output2,\ + org.netbeans.modules.applemenu,\ + org.netbeans.modules.autoupdate.services,\ + org.netbeans.modules.autoupdate.ui,\ + org.netbeans.modules.core.kit,\ + org.netbeans.modules.favorites,\ + org.netbeans.modules.javahelp,\ + org.netbeans.modules.masterfs,\ + org.netbeans.modules.options.keymap,\ + org.netbeans.modules.sendopts,\ + org.netbeans.modules.templates,\ + org.openide.compat,\ + org.openide.execution,\ + org.openide.util.enumerations +enabled.clusters=\ + platform7 +nbjdk.active=JDK_1.6 +nbplatform.active=default diff --git a/src/share/tools/IdealGraphVisualizer/Layout/nbproject/project.properties b/src/share/tools/IdealGraphVisualizer/Layout/nbproject/project.properties new file mode 100644 index 0000000000000000000000000000000000000000..152f44eca60ab831869539ffae9192aa03915f3b --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Layout/nbproject/project.properties @@ -0,0 +1,2 @@ +javac.source=1.5 +javac.compilerargs=-Xlint -Xlint:-serial diff --git a/src/share/tools/IdealGraphVisualizer/Layout/nbproject/project.xml b/src/share/tools/IdealGraphVisualizer/Layout/nbproject/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..edd56a5bc6611a1990e640f7f3d26ae651ccc603 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Layout/nbproject/project.xml @@ -0,0 +1,14 @@ + + + org.netbeans.modules.apisupport.project + + + com.sun.hotspot.igv.layout + + + + com.sun.hotspot.igv.layout + + + + diff --git a/src/share/tools/IdealGraphVisualizer/Layout/nbproject/suite.properties b/src/share/tools/IdealGraphVisualizer/Layout/nbproject/suite.properties new file mode 100644 index 0000000000000000000000000000000000000000..29d7cc9bd6fdd81453543cdf1bcf1dab301e3a92 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Layout/nbproject/suite.properties @@ -0,0 +1 @@ +suite.dir=${basedir}/.. diff --git a/src/share/tools/IdealGraphVisualizer/Layout/src/com/sun/hotspot/igv/layout/Bundle.properties b/src/share/tools/IdealGraphVisualizer/Layout/src/com/sun/hotspot/igv/layout/Bundle.properties new file mode 100644 index 0000000000000000000000000000000000000000..578627a2b9eb0c4921d819489a8f5cd5361d30e4 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Layout/src/com/sun/hotspot/igv/layout/Bundle.properties @@ -0,0 +1 @@ +OpenIDE-Module-Name=Layout diff --git a/src/share/tools/IdealGraphVisualizer/Layout/src/com/sun/hotspot/igv/layout/Cluster.java b/src/share/tools/IdealGraphVisualizer/Layout/src/com/sun/hotspot/igv/layout/Cluster.java new file mode 100644 index 0000000000000000000000000000000000000000..a4bfda5fdffe9b09959c5250142e6862b668beef --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Layout/src/com/sun/hotspot/igv/layout/Cluster.java @@ -0,0 +1,42 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.layout; + +import java.awt.Rectangle; +import java.util.Set; + +/** + * + * @author Thomas Wuerthinger + */ +public interface Cluster extends Comparable { + + public Cluster getOuter(); + + public void setBounds(Rectangle r); + + public Set getSuccessors(); + + public Set getPredecessors(); +} diff --git a/src/share/tools/IdealGraphVisualizer/Layout/src/com/sun/hotspot/igv/layout/LayoutGraph.java b/src/share/tools/IdealGraphVisualizer/Layout/src/com/sun/hotspot/igv/layout/LayoutGraph.java new file mode 100644 index 0000000000000000000000000000000000000000..ac262c95e74ea849f605bfcecd0ac3ed39a3c65b --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Layout/src/com/sun/hotspot/igv/layout/LayoutGraph.java @@ -0,0 +1,202 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.layout; + +import java.util.HashSet; +import java.util.Hashtable; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +/** + * + * @author Thomas Wuerthinger + */ +public class LayoutGraph { + + private Set links; + private SortedSet vertices; + private Hashtable> inputPorts; + private Hashtable> outputPorts; + private Hashtable> 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 Hashtable>(); + inputPorts = new Hashtable>(); + outputPorts = new Hashtable>(); + + 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()); + } + + public SortedSet getClusters() { + + SortedSet clusters = new TreeSet(); + for (Vertex v : getVertices()) { + if (v.getCluster() != null) { + clusters.add(v.getCluster()); + } + } + + return clusters; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Layout/src/com/sun/hotspot/igv/layout/LayoutManager.java b/src/share/tools/IdealGraphVisualizer/Layout/src/com/sun/hotspot/igv/layout/LayoutManager.java new file mode 100644 index 0000000000000000000000000000000000000000..25d0a5eb913a5969e0e4e0da4a4a49eb1110557e --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Layout/src/com/sun/hotspot/igv/layout/LayoutManager.java @@ -0,0 +1,39 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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 --git a/src/share/tools/IdealGraphVisualizer/Layout/src/com/sun/hotspot/igv/layout/Link.java b/src/share/tools/IdealGraphVisualizer/Layout/src/com/sun/hotspot/igv/layout/Link.java new file mode 100644 index 0000000000000000000000000000000000000000..b885d4823a48daafe5042789df96869ccee5ede9 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Layout/src/com/sun/hotspot/igv/layout/Link.java @@ -0,0 +1,42 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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 List getControlPoints(); + + public void setControlPoints(List list); +} diff --git a/src/share/tools/IdealGraphVisualizer/Layout/src/com/sun/hotspot/igv/layout/Port.java b/src/share/tools/IdealGraphVisualizer/Layout/src/com/sun/hotspot/igv/layout/Port.java new file mode 100644 index 0000000000000000000000000000000000000000..0bfe394aa83c3014bf5ac212886a73021aa3f3c6 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Layout/src/com/sun/hotspot/igv/layout/Port.java @@ -0,0 +1,37 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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 --git a/src/share/tools/IdealGraphVisualizer/Layout/src/com/sun/hotspot/igv/layout/Vertex.java b/src/share/tools/IdealGraphVisualizer/Layout/src/com/sun/hotspot/igv/layout/Vertex.java new file mode 100644 index 0000000000000000000000000000000000000000..3a6020b3b9f056f8160c63cd722a62f330033e92 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Layout/src/com/sun/hotspot/igv/layout/Vertex.java @@ -0,0 +1,44 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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 Cluster getCluster(); + + public Dimension getSize(); + + public Point getPosition(); + + public void setPosition(Point p); + + public boolean isRoot(); +} diff --git a/src/share/tools/IdealGraphVisualizer/NetworkConnection/build.xml b/src/share/tools/IdealGraphVisualizer/NetworkConnection/build.xml new file mode 100644 index 0000000000000000000000000000000000000000..4565a3d64029ce2809e23101038198451e6d01c2 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/NetworkConnection/build.xml @@ -0,0 +1,8 @@ + + + + + + Builds, tests, and runs the project com.sun.hotspot.igv.connection. + + diff --git a/src/share/tools/IdealGraphVisualizer/NetworkConnection/manifest.mf b/src/share/tools/IdealGraphVisualizer/NetworkConnection/manifest.mf new file mode 100644 index 0000000000000000000000000000000000000000..791c20daf71bcbbdc5edfcb8da4f733e97be5e58 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/NetworkConnection/manifest.mf @@ -0,0 +1,6 @@ +Manifest-Version: 1.0 +OpenIDE-Module: com.sun.hotspot.igv.connection +OpenIDE-Module-Layer: com/sun/hotspot/igv/connection/layer.xml +OpenIDE-Module-Localizing-Bundle: com/sun/hotspot/igv/connection/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff --git a/src/share/tools/IdealGraphVisualizer/NetworkConnection/nbproject/build-impl.xml b/src/share/tools/IdealGraphVisualizer/NetworkConnection/nbproject/build-impl.xml new file mode 100644 index 0000000000000000000000000000000000000000..5e1c4139d0f3318bfb9e635fe72302ceb95b4af2 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/NetworkConnection/nbproject/build-impl.xml @@ -0,0 +1,30 @@ + + + + + + You must set 'suite.dir' to point to your containing module suite + + + + + + + + + + + + + + + + + + + + + diff --git a/src/share/tools/IdealGraphVisualizer/NetworkConnection/nbproject/genfiles.properties b/src/share/tools/IdealGraphVisualizer/NetworkConnection/nbproject/genfiles.properties new file mode 100644 index 0000000000000000000000000000000000000000..0897ad916a44d174a1c2833b03cd635b487a2c78 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/NetworkConnection/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=f8e21cb6 +build.xml.script.CRC32=a265137e +build.xml.stylesheet.CRC32=79c3b980 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=f8e21cb6 +nbproject/build-impl.xml.script.CRC32=36f3138c +nbproject/build-impl.xml.stylesheet.CRC32=deb65f65 diff --git a/src/share/tools/IdealGraphVisualizer/NetworkConnection/nbproject/project.properties b/src/share/tools/IdealGraphVisualizer/NetworkConnection/nbproject/project.properties new file mode 100644 index 0000000000000000000000000000000000000000..152f44eca60ab831869539ffae9192aa03915f3b --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/NetworkConnection/nbproject/project.properties @@ -0,0 +1,2 @@ +javac.source=1.5 +javac.compilerargs=-Xlint -Xlint:-serial diff --git a/src/share/tools/IdealGraphVisualizer/NetworkConnection/nbproject/project.xml b/src/share/tools/IdealGraphVisualizer/NetworkConnection/nbproject/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..5edaba9763b578c898e5f6f71ce20dd7f4b92813 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/NetworkConnection/nbproject/project.xml @@ -0,0 +1,55 @@ + + + org.netbeans.modules.apisupport.project + + + com.sun.hotspot.igv.connection + + + + com.sun.hotspot.igv.data + + + + 1.0 + + + + com.sun.hotspot.igv.settings + + + + 1.0 + + + + org.openide.awt + + + + 6.11.1.1 + + + + org.openide.dialogs + + + + 7.5.1 + + + + org.openide.util + + + + 7.10.1.1 + + + + + com.sun.hotspot.igv.connection + + + + diff --git a/src/share/tools/IdealGraphVisualizer/NetworkConnection/nbproject/suite.properties b/src/share/tools/IdealGraphVisualizer/NetworkConnection/nbproject/suite.properties new file mode 100644 index 0000000000000000000000000000000000000000..29d7cc9bd6fdd81453543cdf1bcf1dab301e3a92 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/NetworkConnection/nbproject/suite.properties @@ -0,0 +1 @@ +suite.dir=${basedir}/.. diff --git a/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/META-INF/services/com.sun.hotspot.igv.data.services.GroupReceiver b/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/META-INF/services/com.sun.hotspot.igv.data.services.GroupReceiver new file mode 100644 index 0000000000000000000000000000000000000000..62561a6709f622cc1698e33eaa9fa2777b334c68 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/META-INF/services/com.sun.hotspot.igv.data.services.GroupReceiver @@ -0,0 +1 @@ +com.sun.hotspot.igv.connection.Server \ No newline at end of file diff --git a/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Bundle.properties b/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Bundle.properties new file mode 100644 index 0000000000000000000000000000000000000000..6cbad75a668105de6991be70f339a675184f6918 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Bundle.properties @@ -0,0 +1 @@ +OpenIDE-Module-Name=NetworkConnection diff --git a/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Client.java b/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Client.java new file mode 100644 index 0000000000000000000000000000000000000000..a16c2eced3bd081a0e06c15ea9655fb40bd2e8a1 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Client.java @@ -0,0 +1,96 @@ +/* + * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ +package com.sun.hotspot.igv.connection; + +import com.sun.hotspot.igv.data.Group; +import com.sun.hotspot.igv.data.services.GroupCallback; +import com.sun.hotspot.igv.data.serialization.Parser; +import com.sun.hotspot.igv.data.Properties.RegexpPropertyMatcher; +import java.io.IOException; +import java.io.InputStream; +import java.net.Socket; +import javax.swing.JTextField; +import org.openide.util.Exceptions; +import org.openide.xml.XMLUtil; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; + +/** + * + * @author Thomas Wuerthinger + */ +public class Client implements Runnable, GroupCallback { + + private Socket socket; + private JTextField networkTextField; + private GroupCallback callback; + + public Client(Socket socket, JTextField networkTextField, GroupCallback callback) { + this.callback = callback; + this.socket = socket; + this.networkTextField = networkTextField; + } + + public void run() { + + try { + InputStream inputStream = socket.getInputStream(); + + if (networkTextField.isEnabled()) { + + socket.getOutputStream().write('y'); + InputSource is = new InputSource(inputStream); + + try { + XMLReader reader = XMLUtil.createXMLReader(); + Parser parser = new Parser(this); + parser.parse(reader, is, null); + } catch (SAXException ex) { + ex.printStackTrace(); + } + } else { + socket.getOutputStream().write('n'); + } + + socket.close(); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + + public void started(final Group g) { + try { + RegexpPropertyMatcher matcher = new RegexpPropertyMatcher("name", ".*" + networkTextField.getText() + ".*"); + if (g.getProperties().selectSingle(matcher) != null && networkTextField.isEnabled()) { + socket.getOutputStream().write('y'); + callback.started(g); + } else { + socket.getOutputStream().write('n'); + } + } catch (IOException e) { + } + } +} diff --git a/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Server.java b/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Server.java new file mode 100644 index 0000000000000000000000000000000000000000..6bd3dd67bb1db524135e487b1410e73a989658a7 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Server.java @@ -0,0 +1,145 @@ +/* + * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ +package com.sun.hotspot.igv.connection; + +import com.sun.hotspot.igv.data.Group; +import com.sun.hotspot.igv.data.services.GroupCallback; +import com.sun.hotspot.igv.data.services.GroupReceiver; +import com.sun.hotspot.igv.settings.Settings; +import java.awt.Component; +import java.io.IOException; +import java.net.ServerSocket; +import java.net.Socket; +import java.util.prefs.PreferenceChangeEvent; +import java.util.prefs.PreferenceChangeListener; +import javax.swing.SwingUtilities; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.util.RequestProcessor; + +/** + * + * @author Thomas Wuerthinger + */ +public class Server implements GroupCallback, GroupReceiver, PreferenceChangeListener { + + private javax.swing.JPanel jPanel1; + private javax.swing.JCheckBox networkCheckBox; + private javax.swing.JTextField networkTextField; + private ServerSocket serverSocket; + private GroupCallback callback; + private int port; + private Runnable serverRunnable; + + public Component init(GroupCallback callback) { + + this.callback = callback; + + jPanel1 = new javax.swing.JPanel(); + networkTextField = new javax.swing.JTextField(); + networkCheckBox = new javax.swing.JCheckBox(); + + + jPanel1.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5)); + jPanel1.setLayout(new java.awt.BorderLayout(10, 10)); + jPanel1.add(networkTextField, java.awt.BorderLayout.CENTER); + + networkCheckBox.setSelected(true); + org.openide.awt.Mnemonics.setLocalizedText(networkCheckBox, "Receive when name contains"); + networkCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); + networkCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0)); + networkCheckBox.addChangeListener(new javax.swing.event.ChangeListener() { + + public void stateChanged(javax.swing.event.ChangeEvent evt) { + networkCheckBoxChanged(evt); + } + }); + jPanel1.add(networkCheckBox, java.awt.BorderLayout.WEST); + networkCheckBox.getAccessibleContext().setAccessibleName("Read from network when name contains"); + + initializeNetwork(); + Settings.get().addPreferenceChangeListener(this); + return jPanel1; + } + + private void networkCheckBoxChanged(javax.swing.event.ChangeEvent evt) { + networkTextField.setEnabled(networkCheckBox.isSelected()); + } + + public void preferenceChange(PreferenceChangeEvent e) { + + int curPort = Integer.parseInt(Settings.get().get(Settings.PORT, Settings.PORT_DEFAULT)); + if (curPort != port) { + initializeNetwork(); + } + } + + private void initializeNetwork() { + + int curPort = Integer.parseInt(Settings.get().get(Settings.PORT, Settings.PORT_DEFAULT)); + this.port = curPort; + try { + serverSocket = new java.net.ServerSocket(curPort); + } catch (IOException ex) { + NotifyDescriptor message = new NotifyDescriptor.Message("Could not create server. Listening for incoming data is disabled.", NotifyDescriptor.ERROR_MESSAGE); + DialogDisplayer.getDefault().notifyLater(message); + return; + } + + Runnable runnable = new Runnable() { + + public void run() { + while (true) { + try { + Socket clientSocket = serverSocket.accept(); + if (serverRunnable != this) { + clientSocket.close(); + return; + } + RequestProcessor.getDefault().post(new Client(clientSocket, networkTextField, Server.this), 0, Thread.MAX_PRIORITY); + } catch (IOException ex) { + serverSocket = null; + NotifyDescriptor message = new NotifyDescriptor.Message("Error during listening for incoming connections. Listening for incoming data is disabled.", NotifyDescriptor.ERROR_MESSAGE); + DialogDisplayer.getDefault().notifyLater(message); + return; + } + } + } + }; + + serverRunnable = runnable; + + RequestProcessor.getDefault().post(runnable, 0, Thread.MAX_PRIORITY); + } + + public void started(final Group g) { + SwingUtilities.invokeLater(new Runnable() { + + public void run() { + callback.started(g); + } + }); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/layer.xml b/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/layer.xml new file mode 100644 index 0000000000000000000000000000000000000000..c16a8a0fed65d0e94e1d893610c5efdcd3523b01 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/layer.xml @@ -0,0 +1,4 @@ + + + + diff --git a/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/build.xml b/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/build.xml new file mode 100644 index 0000000000000000000000000000000000000000..dfdd092231613c00b5938fd16ffa87cb082a7967 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/build.xml @@ -0,0 +1,8 @@ + + + + + + Builds, tests, and runs the project com.sun.hotspot.igv.rhino. + + diff --git a/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/manifest.mf b/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/manifest.mf new file mode 100644 index 0000000000000000000000000000000000000000..18ba3a45614f200b02a627d7cef217e1a6842dd8 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/manifest.mf @@ -0,0 +1,6 @@ +Manifest-Version: 1.0 +OpenIDE-Module: com.sun.hotspot.igv.rhino +OpenIDE-Module-Layer: com/sun/hotspot/igv/rhino/layer.xml +OpenIDE-Module-Localizing-Bundle: com/sun/hotspot/igv/rhino/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff --git a/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/nbproject/build-impl.xml b/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/nbproject/build-impl.xml new file mode 100644 index 0000000000000000000000000000000000000000..d627b3a01c1f901c2a43406ccb26d2b60ebca692 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/nbproject/build-impl.xml @@ -0,0 +1,30 @@ + + + + + + You must set 'suite.dir' to point to your containing module suite + + + + + + + + + + + + + + + + + + + + + diff --git a/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/nbproject/genfiles.properties b/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/nbproject/genfiles.properties new file mode 100644 index 0000000000000000000000000000000000000000..e21cae5f34b08937d0691c6b6a7d8386de3a40d5 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=0c3e7912 +build.xml.script.CRC32=44d0050c +build.xml.stylesheet.CRC32=79c3b980 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=0c3e7912 +nbproject/build-impl.xml.script.CRC32=7aab3f52 +nbproject/build-impl.xml.stylesheet.CRC32=deb65f65 diff --git a/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/nbproject/project.properties b/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/nbproject/project.properties new file mode 100644 index 0000000000000000000000000000000000000000..152f44eca60ab831869539ffae9192aa03915f3b --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/nbproject/project.properties @@ -0,0 +1,2 @@ +javac.source=1.5 +javac.compilerargs=-Xlint -Xlint:-serial diff --git a/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/nbproject/project.xml b/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/nbproject/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..1f9e5814f48415beb130f3e8f12e89d06041f429 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/nbproject/project.xml @@ -0,0 +1,31 @@ + + + org.netbeans.modules.apisupport.project + + + com.sun.hotspot.igv.rhino + + + + com.sun.hotspot.igv.filter + + + + 1.0 + + + + com.sun.hotspot.igv.graph + + + + 1.0 + + + + + com.sun.hotspot.igv.rhino + + + + diff --git a/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/nbproject/suite.properties b/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/nbproject/suite.properties new file mode 100644 index 0000000000000000000000000000000000000000..29d7cc9bd6fdd81453543cdf1bcf1dab301e3a92 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/nbproject/suite.properties @@ -0,0 +1 @@ +suite.dir=${basedir}/.. diff --git a/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/src/META-INF/services/com.sun.hotspot.igv.filter.ScriptEngineAbstraction b/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/src/META-INF/services/com.sun.hotspot.igv.filter.ScriptEngineAbstraction new file mode 100644 index 0000000000000000000000000000000000000000..11a13a78ee0f6ea245f9bad1d60d311ffa0b1c63 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/src/META-INF/services/com.sun.hotspot.igv.filter.ScriptEngineAbstraction @@ -0,0 +1 @@ +com.sun.hotspot.igv.rhino.RhinoScriptEngine \ No newline at end of file diff --git a/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/src/com/sun/hotspot/igv/rhino/Bundle.properties b/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/src/com/sun/hotspot/igv/rhino/Bundle.properties new file mode 100644 index 0000000000000000000000000000000000000000..e389254eb05df035b96898efd1838ebd183eb933 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/src/com/sun/hotspot/igv/rhino/Bundle.properties @@ -0,0 +1 @@ +OpenIDE-Module-Name=RhinoScriptEngineProxy diff --git a/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/src/com/sun/hotspot/igv/rhino/RhinoScriptEngine.java b/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/src/com/sun/hotspot/igv/rhino/RhinoScriptEngine.java new file mode 100644 index 0000000000000000000000000000000000000000..187aa0567bef2a715c90ec4617dfe02a4c02273a --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/src/com/sun/hotspot/igv/rhino/RhinoScriptEngine.java @@ -0,0 +1,85 @@ +/* + * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ +package com.sun.hotspot.igv.rhino; + +import com.sun.hotspot.igv.filter.ScriptEngineAbstraction; +import com.sun.hotspot.igv.graph.Diagram; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +/** + * + * @author Thomas Wuerthinger + */ +public class RhinoScriptEngine implements ScriptEngineAbstraction { + + private String jsHelperText; + private Constructor importer; + private Method scope_put; + private Method cx_evaluateString; + private Method context_enter; + private Method context_exit; + + public boolean initialize(String s) { + this.jsHelperText = s; + Class importerTopLevel = null; + try { + ClassLoader cl = RhinoScriptEngine.class.getClassLoader(); + Class context = cl.loadClass("org.mozilla.javascript.Context"); + Class scriptable = cl.loadClass("org.mozilla.javascript.Scriptable"); + importerTopLevel = cl.loadClass("org.mozilla.javascript.ImporterTopLevel"); + importer = importerTopLevel.getDeclaredConstructor(context); + scope_put = importerTopLevel.getMethod("put", new Class[]{String.class, scriptable, Object.class}); + cx_evaluateString = context.getDeclaredMethod("evaluateString", new Class[]{scriptable, String.class, String.class, Integer.TYPE, Object.class}); + context_enter = context.getDeclaredMethod("enter", new Class[0]); + context_exit = context.getDeclaredMethod("exit", new Class[0]); + return true; + } catch (NoSuchMethodException nsme) { + return false; + } catch (ClassNotFoundException cnfe) { + return false; + } + } + + public void execute(Diagram d, String code) { + try { + Object cx = context_enter.invoke(null, (Object[]) null); + try { + Object scope = importer.newInstance(cx); + scope_put.invoke(scope, "IO", scope, System.out); + scope_put.invoke(scope, "graph", scope, d); + cx_evaluateString.invoke(cx, scope, jsHelperText, "jsHelper.js", 1, null); + cx_evaluateString.invoke(cx, scope, code, "", 1, null); + } finally { + // Exit from the context. + context_exit.invoke(null, (Object[]) null); + } + } catch (InvocationTargetException iae) { + } catch (IllegalAccessException iae) { + } catch (InstantiationException iae) { + } + } +} diff --git a/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/src/com/sun/hotspot/igv/rhino/layer.xml b/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/src/com/sun/hotspot/igv/rhino/layer.xml new file mode 100644 index 0000000000000000000000000000000000000000..c16a8a0fed65d0e94e1d893610c5efdcd3523b01 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/RhinoScriptEngineProxy/src/com/sun/hotspot/igv/rhino/layer.xml @@ -0,0 +1,4 @@ + + + + diff --git a/src/share/tools/IdealGraphVisualizer/ServerCompiler/build.xml b/src/share/tools/IdealGraphVisualizer/ServerCompiler/build.xml new file mode 100644 index 0000000000000000000000000000000000000000..31a102f060e7b7ac635fa87e6c514958fa3f9030 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/ServerCompiler/build.xml @@ -0,0 +1,8 @@ + + + + + + Builds, tests, and runs the project com.sun.hotspot.igv.servercompilerscheduler. + + diff --git a/src/share/tools/IdealGraphVisualizer/ServerCompiler/manifest.mf b/src/share/tools/IdealGraphVisualizer/ServerCompiler/manifest.mf new file mode 100644 index 0000000000000000000000000000000000000000..20c6b68683345eae04f6e4f26a96822e6e298f19 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/ServerCompiler/manifest.mf @@ -0,0 +1,6 @@ +Manifest-Version: 1.0 +OpenIDE-Module: com.sun.hotspot.igv.servercompiler +OpenIDE-Module-Layer: com/sun/hotspot/igv/servercompiler/layer.xml +OpenIDE-Module-Localizing-Bundle: com/sun/hotspot/igv/servercompiler/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff --git a/src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/build-impl.xml b/src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/build-impl.xml new file mode 100644 index 0000000000000000000000000000000000000000..97fbd021e861aef7f6088b00a3d576530d416ed9 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/build-impl.xml @@ -0,0 +1,30 @@ + + + + + + You must set 'suite.dir' to point to your containing module suite + + + + + + + + + + + + + + + + + + + + + diff --git a/src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/genfiles.properties b/src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/genfiles.properties new file mode 100644 index 0000000000000000000000000000000000000000..18f1a882ca0ad1e5edcf041fd798eb0378afbde6 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=d1360a65 +build.xml.script.CRC32=a9d94ef8 +build.xml.stylesheet.CRC32=79c3b980 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=d1360a65 +nbproject/build-impl.xml.script.CRC32=52847236 +nbproject/build-impl.xml.stylesheet.CRC32=deb65f65 diff --git a/src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/platform.properties b/src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/platform.properties new file mode 100644 index 0000000000000000000000000000000000000000..68ad75e5766f33be5a65a19d28cc7605c5b50a1c --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/platform.properties @@ -0,0 +1,29 @@ +# Deprecated since 5.0u1; for compatibility with 5.0: +disabled.clusters=\ + apisupport1,\ + harness,\ + ide8,\ + java1,\ + nb6.0,\ + profiler2 +disabled.modules=\ + org.netbeans.core.execution,\ + org.netbeans.core.multiview,\ + org.netbeans.core.output2,\ + org.netbeans.modules.applemenu,\ + org.netbeans.modules.autoupdate.services,\ + org.netbeans.modules.autoupdate.ui,\ + org.netbeans.modules.core.kit,\ + org.netbeans.modules.favorites,\ + org.netbeans.modules.javahelp,\ + org.netbeans.modules.masterfs,\ + org.netbeans.modules.options.keymap,\ + org.netbeans.modules.sendopts,\ + org.netbeans.modules.templates,\ + org.openide.compat,\ + org.openide.execution,\ + org.openide.util.enumerations +enabled.clusters=\ + platform7 +nbjdk.active=JDK_1.6 +nbplatform.active=default diff --git a/src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/project.properties b/src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/project.properties new file mode 100644 index 0000000000000000000000000000000000000000..152f44eca60ab831869539ffae9192aa03915f3b --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/project.properties @@ -0,0 +1,2 @@ +javac.source=1.5 +javac.compilerargs=-Xlint -Xlint:-serial diff --git a/src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/project.xml b/src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..56151ed37c8fef5eaaf999d50f92daff2b27df55 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/project.xml @@ -0,0 +1,21 @@ + + + org.netbeans.modules.apisupport.project + + + com.sun.hotspot.igv.servercompiler + + + + com.sun.hotspot.igv.data + + + + 1.0 + + + + + + + diff --git a/src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/suite.properties b/src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/suite.properties new file mode 100644 index 0000000000000000000000000000000000000000..29d7cc9bd6fdd81453543cdf1bcf1dab301e3a92 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/ServerCompiler/nbproject/suite.properties @@ -0,0 +1 @@ +suite.dir=${basedir}/.. diff --git a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/META-INF/services/com.sun.hotspot.igv.data.services.GroupOrganizer b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/META-INF/services/com.sun.hotspot.igv.data.services.GroupOrganizer new file mode 100644 index 0000000000000000000000000000000000000000..9da82d4ca10af61c1e0c4d7cd248366f82ce739e --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/META-INF/services/com.sun.hotspot.igv.data.services.GroupOrganizer @@ -0,0 +1 @@ +com.sun.hotspot.igv.servercompiler.JavaGroupOrganizer \ No newline at end of file diff --git a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/META-INF/services/com.sun.hotspot.igv.data.services.Scheduler b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/META-INF/services/com.sun.hotspot.igv.data.services.Scheduler new file mode 100644 index 0000000000000000000000000000000000000000..530080f9f70fea9a4d8ae3350c05c1d1d4e8e95d --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/META-INF/services/com.sun.hotspot.igv.data.services.Scheduler @@ -0,0 +1 @@ +com.sun.hotspot.igv.servercompiler.ServerCompilerScheduler diff --git a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/Bundle.properties b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/Bundle.properties new file mode 100644 index 0000000000000000000000000000000000000000..c5daf04b712d4267e5fd666bf54163748bf5929b --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/Bundle.properties @@ -0,0 +1 @@ +OpenIDE-Module-Name=ServerCompiler diff --git a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/JavaGroupOrganizer.java b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/JavaGroupOrganizer.java new file mode 100644 index 0000000000000000000000000000000000000000..e9cc2d62fb9e0efc1eaeaded52764a2834fea314 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/JavaGroupOrganizer.java @@ -0,0 +1,200 @@ +/* + * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ +package com.sun.hotspot.igv.servercompiler; + +import com.sun.hotspot.igv.data.Group; +import com.sun.hotspot.igv.data.services.GroupOrganizer; +import com.sun.hotspot.igv.data.Pair; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; + +/** + * + * @author Thomas Wuerthinger + */ +public class JavaGroupOrganizer implements GroupOrganizer { + + public String getName() { + return "Java structure"; + } + + public List>> organize(List subFolders, List groups) { + + List>> result = new ArrayList>>(); + + if (subFolders.size() == 0) { + buildResult(result, groups, packageNameProvider); + } else if (subFolders.size() == 1) { + buildResult(result, groups, classNameProvider); + } else if (subFolders.size() == 2) { + for (Group g : groups) { + List children = new ArrayList(); + children.add(g); + Pair> p = new Pair>(); + p.setLeft(reducedNameProvider.getName(g)); + p.setRight(children); + result.add(p); + } + } else { + result.add(new Pair>("", groups)); + } + + return result; + } + + private void buildResult(List>> result, List groups, NameProvider provider) { + HashMap> map = new HashMap>(); + for (Group g : groups) { + String s = provider.getName(g); + + if (!map.containsKey(s)) { + List list = new ArrayList(); + Pair> pair = new Pair>(s, list); + result.add(pair); + map.put(s, list); + } + + List curList = map.get(s); + curList.add(g); + } + + Collections.sort(result, new Comparator>>() { + + public int compare(Pair> a, Pair> b) { + return a.getLeft().compareTo(b.getLeft()); + } + }); + } + + private static interface NameProvider { + + public String getName(Group g); + } + private NameProvider reducedNameProvider = new NameProvider() { + + public String getName(Group g) { + String name = g.getName(); + assert name != null : "name of group must be set!"; + final String noReducedName = name; + + int firstPoint = name.indexOf("."); + if (firstPoint == -1) { + return noReducedName; + } + + int firstParenthese = name.indexOf("("); + if (firstParenthese == -1 || firstParenthese < firstPoint) { + return noReducedName; + } + + int current = firstPoint; + while (current > 0 && name.charAt(current) != ' ') { + current--; + } + + String tmp = name.substring(0, firstParenthese); + int lastPoint = tmp.lastIndexOf("."); + if (lastPoint == -1) { + return noReducedName; + } + + name = name.substring(0, current + 1) + name.substring(lastPoint + 1); + return name; + } + }; + private NameProvider packageNameProvider = new NameProvider() { + + public String getName(Group g) { + String name = g.getName(); + assert name != null : "name of group must be set!"; + final String noPackage = ""; + + int firstPoint = name.indexOf("."); + if (firstPoint == -1) { + return noPackage; + } + + int firstParenthese = name.indexOf("("); + if (firstParenthese == -1 || firstParenthese < firstPoint) { + return noPackage; + } + + int current = firstPoint; + while (current > 0 && name.charAt(current) != ' ') { + current--; + } + + String fullClassName = name.substring(current + 1, firstParenthese); + int lastPoint = fullClassName.lastIndexOf("."); + if (lastPoint == -1) { + return noPackage; + } + lastPoint = fullClassName.lastIndexOf(".", lastPoint - 1); + if (lastPoint == -1) { + return noPackage; + } + + String packageName = fullClassName.substring(0, lastPoint); + return packageName; + } + }; + private NameProvider classNameProvider = new NameProvider() { + + public String getName(Group g) { + String name = g.getName(); + assert name != null : "name of group must be set!"; + + final String noClass = ""; + + int firstPoint = name.indexOf("."); + if (firstPoint == -1) { + return noClass; + } + + int firstParenthese = name.indexOf("("); + if (firstParenthese == -1 || firstParenthese < firstPoint) { + return noClass; + } + + int current = firstPoint; + while (current > 0 && name.charAt(current) != ' ') { + current--; + } + + String fullClassName = name.substring(current + 1, firstParenthese); + int lastPoint = fullClassName.lastIndexOf("."); + if (lastPoint == -1) { + return noClass; + } + int lastlastPoint = fullClassName.lastIndexOf(".", lastPoint - 1); + + String className = fullClassName.substring(lastlastPoint + 1, lastPoint); + return className; + } + }; +} diff --git a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/ServerCompilerScheduler.java b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/ServerCompilerScheduler.java new file mode 100644 index 0000000000000000000000000000000000000000..408f142ad8a74cb2db64a19110b61d5cf9a05132 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/ServerCompilerScheduler.java @@ -0,0 +1,597 @@ +/* + * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ +package com.sun.hotspot.igv.servercompiler; + +import com.sun.hotspot.igv.data.InputBlock; +import com.sun.hotspot.igv.data.InputEdge; +import com.sun.hotspot.igv.data.InputGraph; +import com.sun.hotspot.igv.data.InputNode; +import com.sun.hotspot.igv.data.services.Scheduler; +import java.util.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.Stack; +import java.util.Vector; + +/** + * + * @author Thomas Wuerthinger + */ +public class ServerCompilerScheduler implements Scheduler { + + private static class Node { + + public InputNode inputNode; + public Set succs = new HashSet(); + public List preds = new ArrayList(); + public InputBlock block; + public boolean isBlockProjection; + public boolean isBlockStart; + } + private InputGraph graph; + private Collection nodes; + private Map inputNodeToNode; + private Vector blocks; + private Map dominatorMap; + private Map blockIndex; + private InputBlock[][] commonDominator; + private static final Comparator edgeComparator = new Comparator() { + + public int compare(InputEdge o1, InputEdge o2) { + return o1.getToIndex() - o2.getToIndex(); + } + }; + + public void buildBlocks() { + + blocks = new Vector(); + Node root = findRoot(); + if (root == null) { + return; + } + Stack stack = new Stack(); + Set visited = new HashSet(); + stack.add(root); + int blockCount = 0; + InputBlock rootBlock = null; + + + while (!stack.isEmpty()) { + Node proj = stack.pop(); + Node parent = proj; + if (proj.isBlockProjection && proj.preds.size() > 0) { + parent = proj.preds.get(0); + } + + if (!visited.contains(parent)) { + visited.add(parent); + InputBlock block = new InputBlock(graph, "" + blockCount); + blocks.add(block); + if (parent == root) { + rootBlock = block; + } + blockCount++; + parent.block = block; + if (proj != parent && proj.succs.size() == 1 && proj.succs.contains(root)) { + // Special treatment of Halt-nodes + proj.block = block; + } + + Node p = proj; + do { + if (p.preds.size() == 0 || p.preds.get(0) == null) { + p = parent; + break; + } + p = p.preds.get(0); + + if (p.block == null) { + p.block = block; + } + } while (!p.isBlockProjection && !p.isBlockStart); + + if (block != rootBlock) { + for (Node n : p.preds) { + if (n != null && n != p) { + if (n.isBlockProjection) { + n = n.preds.get(0); + } + if (n.block != null) { + n.block.addSuccessor(block); + } + } + } + } + + for (Node n : parent.succs) { + if (n != root && n.isBlockProjection) { + for (Node n2 : n.succs) { + + if (n2 != parent && n2.block != null && n2.block != rootBlock) { + block.addSuccessor(n2.block); + } + } + } else { + if (n != parent && n.block != null && n.block != rootBlock) { + block.addSuccessor(n.block); + } + } + } + + int num_preds = p.preds.size(); + int bottom = -1; + if (isRegion(p) || isPhi(p)) { + bottom = 0; + } + + int pushed = 0; + for (int i = num_preds - 1; i > bottom; i--) { + if (p.preds.get(i) != null && p.preds.get(i) != p) { + stack.push(p.preds.get(i)); + pushed++; + } + } + + if (pushed == 0 && p == root) { + // TODO: special handling when root backedges are not built yet + } + } + } + + for (Node n : nodes) { + InputBlock block = n.block; + if (block != null) { + block.addNode(n.inputNode.getId()); + } + } + + int z = 0; + blockIndex = new HashMap(); + for (InputBlock b : blocks) { + blockIndex.put(b, z); + z++; + } + } + + private String getBlockName(InputNode n) { + return n.getProperties().get("block"); + } + + public Collection schedule(InputGraph graph) { + if (graph.getBlocks().size() > 0) { + Collection tmpNodes = new ArrayList(graph.getNodes()); + for (InputNode n : tmpNodes) { + String block = getBlockName(n); + if (graph.getBlock(n) == null) { + graph.getBlock(block).addNode(n); + assert graph.getBlock(n) != null; + } + } + return graph.getBlocks(); + } else { + nodes = new ArrayList(); + inputNodeToNode = new HashMap(); + + this.graph = graph; + buildUpGraph(); + buildBlocks(); + buildDominators(); + buildCommonDominators(); + scheduleLatest(); + + for (InputNode n : graph.getNodes()) { + assert graph.getBlock(n) != null; + } + + return blocks; + } + } + + public void scheduleLatest() { + + + Node root = findRoot(); + + // Mark all nodes reachable in backward traversal from root + Set reachable = new HashSet(); + reachable.add(root); + Stack stack = new Stack(); + stack.push(root); + while (!stack.isEmpty()) { + Node cur = stack.pop(); + for (Node n : cur.preds) { + if (!reachable.contains(n)) { + reachable.add(n); + stack.push(n); + } + } + } + + Set unscheduled = new HashSet(); + for (Node n : this.nodes) { + if (n.block == null && reachable.contains(n)) { + unscheduled.add(n); + } + } + + while (unscheduled.size() > 0) { + boolean progress = false; + + Set newUnscheduled = new HashSet(); + for (Node n : unscheduled) { + + InputBlock block = null; + if (this.isPhi(n) && n.preds.get(0) != null) { + // Phi nodes in same block as region nodes + block = n.preds.get(0).block; + } else { + for (Node s : n.succs) { + if (reachable.contains(s)) { + if (s.block == null) { + block = null; + break; + } else { + if (block == null) { + block = s.block; + } else { + block = commonDominator[this.blockIndex.get(block)][blockIndex.get(s.block)]; + } + } + } + } + } + + if (block != null) { + n.block = block; + block.addNode(n.inputNode.getId()); + progress = true; + } else { + newUnscheduled.add(n); + } + } + + unscheduled = newUnscheduled; + + if (!progress) { + break; + } + } + + Set curReachable = new HashSet(reachable); + for (Node n : curReachable) { + if (n.block != null) { + for (Node s : n.succs) { + if (!reachable.contains(s)) { + markWithBlock(s, n.block, reachable); + } + } + } + } + + } + + private void markWithBlock(Node n, InputBlock b, Set reachable) { + assert !reachable.contains(n); + Stack stack = new Stack(); + stack.push(n); + n.block = b; + b.addNode(n.inputNode.getId()); + reachable.add(n); + + while (!stack.isEmpty()) { + Node cur = stack.pop(); + for (Node s : cur.succs) { + if (!reachable.contains(s)) { + reachable.add(s); + s.block = b; + b.addNode(s.inputNode.getId()); + stack.push(s); + } + } + + for (Node s : cur.preds) { + if (!reachable.contains(s)) { + reachable.add(s); + s.block = b; + b.addNode(s.inputNode.getId()); + stack.push(s); + } + } + } + } + + private class BlockIntermediate { + + InputBlock block; + int index; + int dominator; + int semi; + int parent; + int label; + int ancestor; + List pred; + List bucket; + } + + public void buildCommonDominators() { + commonDominator = new InputBlock[this.blocks.size()][this.blocks.size()]; + for (int i = 0; i < blocks.size(); i++) { + for (int j = 0; j < blocks.size(); j++) { + commonDominator[i][j] = getCommonDominator(i, j); + } + } + } + + public InputBlock getCommonDominator(int a, int b) { + InputBlock ba = blocks.get(a); + InputBlock bb = blocks.get(b); + if (ba == bb) { + return ba; + } + Set visited = new HashSet(); + while (ba != null) { + visited.add(ba); + ba = dominatorMap.get(ba); + } + + while (bb != null) { + if (visited.contains(bb)) { + return bb; + } + bb = dominatorMap.get(bb); + } + + assert false; + return null; + } + + public void buildDominators() { + dominatorMap = new HashMap(); + if (blocks.size() == 0) { + return; + } + Vector intermediate = new Vector(); + Map map = new HashMap(); + int z = 0; + for (InputBlock b : blocks) { + BlockIntermediate bi = new BlockIntermediate(); + bi.block = b; + bi.index = z; + bi.dominator = -1; + bi.semi = -1; + bi.parent = -1; + bi.label = z; + bi.ancestor = -1; + bi.pred = new ArrayList(); + bi.bucket = new ArrayList(); + intermediate.add(bi); + map.put(b, bi); + z++; + } + Stack stack = new Stack(); + stack.add(0); + + Vector array = new Vector(); + intermediate.get(0).dominator = 0; + + int n = 0; + while (!stack.isEmpty()) { + int index = stack.pop(); + BlockIntermediate ib = intermediate.get(index); + ib.semi = n; + array.add(ib); + n = n + 1; + for (InputBlock b : ib.block.getSuccessors()) { + BlockIntermediate succ = map.get(b); + if (succ.semi == -1) { + succ.parent = index; + stack.push(succ.index); // TODO: check if same node could be pushed twice + } + succ.pred.add(index); + } + } + + for (int i = n - 1; i > 0; i--) { + BlockIntermediate block = array.get(i); + int block_index = block.index; + for (int predIndex : block.pred) { + int curIndex = eval(predIndex, intermediate); + BlockIntermediate curBlock = intermediate.get(curIndex); + if (curBlock.semi < block.semi) { + block.semi = curBlock.semi; + } + } + + + int semiIndex = block.semi; + BlockIntermediate semiBlock = array.get(semiIndex); + semiBlock.bucket.add(block_index); + + link(block.parent, block_index, intermediate); + BlockIntermediate parentBlock = intermediate.get(block.parent); + + for (int j = 0; j < parentBlock.bucket.size(); j++) { + for (int curIndex : parentBlock.bucket) { + int newIndex = eval(curIndex, intermediate); + BlockIntermediate curBlock = intermediate.get(curIndex); + BlockIntermediate newBlock = intermediate.get(newIndex); + int dom = block.parent; + if (newBlock.semi < curBlock.semi) { + dom = newIndex; + } + + curBlock.dominator = dom; + } + } + + + parentBlock.bucket.clear(); + } + + for (int i = 1; i < n; i++) { + + BlockIntermediate block = array.get(i); + int block_index = block.index; + + int semi_index = block.semi; + BlockIntermediate semi_block = array.get(semi_index); + + if (block.dominator != semi_block.index) { + int new_dom = intermediate.get(block.dominator).dominator; + block.dominator = new_dom; + } + } + + for (BlockIntermediate ib : intermediate) { + if (ib.dominator == -1) { + ib.dominator = 0; + } + } + + for (BlockIntermediate bi : intermediate) { + InputBlock b = bi.block; + int dominator = bi.dominator; + InputBlock dominatorBlock = null; + if (dominator != -1) { + dominatorBlock = intermediate.get(dominator).block; + } + + if (dominatorBlock == b) { + dominatorBlock = null; + } + this.dominatorMap.put(b, dominatorBlock); + } + } + + private void compress(int index, Vector blocks) { + BlockIntermediate block = blocks.get(index); + + int ancestor = block.ancestor; + assert ancestor != -1; + + BlockIntermediate ancestor_block = blocks.get(ancestor); + if (ancestor_block.ancestor != -1) { + compress(ancestor, blocks); + + int label = block.label; + BlockIntermediate label_block = blocks.get(label); + + int ancestor_label = ancestor_block.label; + BlockIntermediate ancestor_label_block = blocks.get(label); + if (ancestor_label_block.semi < label_block.semi) { + block.label = ancestor_label; + } + + block.ancestor = ancestor_block.ancestor; + } + } + + private int eval(int index, Vector blocks) { + BlockIntermediate block = blocks.get(index); + if (block.ancestor == -1) { + return index; + } else { + compress(index, blocks); + return block.label; + } + } + + private void link(int index1, int index2, Vector blocks) { + BlockIntermediate block2 = blocks.get(index2); + block2.ancestor = index1; + } + + private boolean isRegion(Node n) { + return n.inputNode.getProperties().get("name").equals("Region"); + } + + private boolean isPhi(Node n) { + return n.inputNode.getProperties().get("name").equals("Phi"); + } + + private Node findRoot() { + + for (Node n : nodes) { + InputNode inputNode = n.inputNode; + if (inputNode.getProperties().get("name").equals("Root")) { + return n; + } + } + + return null; + } + + public void buildUpGraph() { + + for (InputNode n : graph.getNodes()) { + Node node = new Node(); + node.inputNode = n; + nodes.add(node); + String p = n.getProperties().get("is_block_proj"); + node.isBlockProjection = (p != null && p.equals("true")); + p = n.getProperties().get("is_block_start"); + node.isBlockStart = (p != null && p.equals("true")); + inputNodeToNode.put(n, node); + } + + Map> edgeMap = new HashMap>(); + for (InputEdge e : graph.getEdges()) { + + int to = e.getTo(); + if (!edgeMap.containsKey(to)) { + edgeMap.put(to, new ArrayList()); + } + + + List list = edgeMap.get(to); + list.add(e); + } + + + for (Integer i : edgeMap.keySet()) { + + List list = edgeMap.get(i); + Collections.sort(list, edgeComparator); + + int to = i; + InputNode toInputNode = graph.getNode(to); + Node toNode = inputNodeToNode.get(toInputNode); + for (InputEdge e : list) { + assert to == e.getTo(); + int from = e.getFrom(); + InputNode fromInputNode = graph.getNode(from); + Node fromNode = inputNodeToNode.get(fromInputNode); + fromNode.succs.add(toNode); + toNode.preds.add(fromNode); + } + } + } +} diff --git a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/color.filter b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/color.filter new file mode 100644 index 0000000000000000000000000000000000000000..3ad07276df86227dbc8ef52b97d3d6e1e1edbcb5 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/color.filter @@ -0,0 +1,5 @@ +colorize("name", ".*", yellow); +colorize("name", "Catch.*", blue); + +colorize("name", "Region|Loop|CountedLoop|Root", red); +colorize("name", "CProj|IfFalse|IfTrue|JProj|CatchProj", magenta); diff --git a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/combine.filter b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/combine.filter new file mode 100644 index 0000000000000000000000000000000000000000..8e5c5a0a7c75776c5c184bf502f4030c5bd9f394 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/combine.filter @@ -0,0 +1,4 @@ +var f = new CombineFilter("Combine Filter"); +f.addRule(new CombineFilter.CombineRule(new Properties.RegexpPropertyMatcher("name", ".*"), new Properties.RegexpPropertyMatcher("name", "Proj|IfFalse|IfTrue|JProj|MachProj|JumpProj|CatchProj"))); +f.addRule(new CombineFilter.CombineRule(new Properties.RegexpPropertyMatcher("name", "Cmp.*"), new Properties.RegexpPropertyMatcher("name", "Bool"))); +f.apply(graph); \ No newline at end of file diff --git a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/difference.filter b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/difference.filter new file mode 100644 index 0000000000000000000000000000000000000000..53277373d60939b12ddc2c53a7ea876e809c6df8 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/difference.filter @@ -0,0 +1,4 @@ +colorize("state", "same", white); +colorize("state", "changed", orange); +colorize("state", "new", green); +colorize("state", "deleted", red); diff --git a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/extendedColor.filter b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/extendedColor.filter new file mode 100644 index 0000000000000000000000000000000000000000..1ea0fb36abe14b95969f4aba08ea8e76cc064ca0 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/extendedColor.filter @@ -0,0 +1,3 @@ +colorize("name", "Con.*", orange); +colorize("name", "Parm|Proj", lightGray); +colorize("bci", "..*", magenta); \ No newline at end of file diff --git a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/linestyle.filter b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/linestyle.filter new file mode 100644 index 0000000000000000000000000000000000000000..9aa15e792984c96d1c371833d01db92aa5f12980 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/linestyle.filter @@ -0,0 +1,7 @@ +var f = new ColorFilter("Line Style filter"); +f.addRule(new ColorFilter.ColorRule(new MatcherSelector(new Properties.StringPropertyMatcher("type", "int:")), null, Color.BLUE, null)); +f.addRule(new ColorFilter.ColorRule(new MatcherSelector(new Properties.StringPropertyMatcher("type", "control")), null, Color.RED, null)); +f.addRule(new ColorFilter.ColorRule(new MatcherSelector(new Properties.StringPropertyMatcher("type", "memory")), null, Color.GREEN, null)); +f.addRule(new ColorFilter.ColorRule(new MatcherSelector(new Properties.StringPropertyMatcher("type", "tuple:")), null, Color.MAGENTA, null)); +f.addRule(new ColorFilter.ColorRule(new MatcherSelector(new Properties.StringPropertyMatcher("type", "bottom")), null, Color.LIGHT_GRAY, null)); +f.apply(graph); \ No newline at end of file diff --git a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/matchingFlags.filter b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/matchingFlags.filter new file mode 100644 index 0000000000000000000000000000000000000000..0f18448e162efa10931d05340a1919958a7cdc3b --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/matchingFlags.filter @@ -0,0 +1,3 @@ +colorize("is_dontcare", "false", white); +colorize("is_shared", "true", green); +colorize("is_dontcare", "true", red); diff --git a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/onlyControlFlow.filter b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/onlyControlFlow.filter new file mode 100644 index 0000000000000000000000000000000000000000..7230576a2ac4a440d5579416dfd5d5eed5175ae4 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/onlyControlFlow.filter @@ -0,0 +1,24 @@ +var f = new RemoveFilter("Show only control flow"); +f.addRule( + new RemoveFilter.RemoveRule( + new InvertSelector( + new OrSelector( + new OrSelector( + new SuccessorSelector( + new MatcherSelector( + new Properties.StringPropertyMatcher("type", "control") + ) + ), + new MatcherSelector( + new Properties.StringPropertyMatcher("type", "control") + ) + ), + new MatcherSelector( + new Properties.StringPropertyMatcher("name", "Start") + ) + ) + ), false + ) +); +f.addRule( new RemoveFilter.RemoveRule(new MatcherSelector(new Properties.RegexpPropertyMatcher("name", "Phi|Store.")), false)); +f.apply(graph); \ No newline at end of file diff --git a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/register.filter b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/register.filter new file mode 100644 index 0000000000000000000000000000000000000000..5328246d2880d2737ee5e7577b4b72220a92e7c7 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/register.filter @@ -0,0 +1,4 @@ +colorize("reg", "EAX", green); +colorize("reg", "EFLAGS", gray); +colorize("reg", "EBP", orange); +colorize("reg", "ECX", cyan); diff --git a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/remove.filter b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/remove.filter new file mode 100644 index 0000000000000000000000000000000000000000..0333fccb3375212f4212e32cb4c5730432096543 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/remove.filter @@ -0,0 +1 @@ +remove("dump_spec", "FramePtr|ReturnAdr|I_O"); \ No newline at end of file diff --git a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/removeMemory.filter b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/removeMemory.filter new file mode 100644 index 0000000000000000000000000000000000000000..842caed3b7f4e39070756754931fcd87d0f0b5f7 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/removeMemory.filter @@ -0,0 +1,7 @@ + +//var f = new RemoveFilter("Remove Memory"); +//f.addRule(new RemoveFilter.RemoveRule(new MatcherSelector(new Properties.StringPropertyMatcher("dump_spec", "Memory")), false)); +//f.addRule(new RemoveFilter.RemoveRule(new AndSelector(new MatcherSelector(new Properties.StringPropertyMatcher("name", "Proj")), new MatcherSelector(new Properties.StringPropertyMatcher("type", "memory"))), false)); +//f.apply(graph); + +remove("dump_spec", "Memory"); diff --git a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/removeRootInputs.filter b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/removeRootInputs.filter new file mode 100644 index 0000000000000000000000000000000000000000..8f6aacd4c4dc5dd6fdd86d5422269b6d24838dd3 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/removeRootInputs.filter @@ -0,0 +1 @@ +removeInputs("name", "Root"); \ No newline at end of file diff --git a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/removeSafepointInputs.filter b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/removeSafepointInputs.filter new file mode 100644 index 0000000000000000000000000000000000000000..b2abf0ee717876e129b0f7e12bdba685c45fc05e --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/removeSafepointInputs.filter @@ -0,0 +1,4 @@ +removeInputs("name", "SafePoint|CallStaticJava|CallDynamicJava|CallJava|CallLeaf|CallRuntime|AbstractLock|CallLeafNoFP|Call|CallStaticJavaDirect", 5); +removeInputs("name", "Unlock|Lock", 7); +removeInputs("name", "Allocate", 7); +removeInputs("name", "AllocateArray", 9); diff --git a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/removeSelfLoops.filter b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/removeSelfLoops.filter new file mode 100644 index 0000000000000000000000000000000000000000..debfd596de0fdafb7cf41a217775e6d7a56981a2 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/removeSelfLoops.filter @@ -0,0 +1,2 @@ +var f = new RemoveSelfLoopsFilter("Remove Self-Loops"); +f.apply(graph); \ No newline at end of file diff --git a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/split.filter b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/split.filter new file mode 100644 index 0000000000000000000000000000000000000000..5f344ca6d766230058eaa29cac610ccbddc90830 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/filters/split.filter @@ -0,0 +1,2 @@ +split("name", "BoxLock"); +split("name", "(Con.*)|(loadCon.*)"); \ No newline at end of file diff --git a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/layer.xml b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/layer.xml new file mode 100644 index 0000000000000000000000000000000000000000..461692d832ecc34d36bb7bc6e7d0e927ec718f29 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/layer.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/share/tools/IdealGraphVisualizer/Settings/build.xml b/src/share/tools/IdealGraphVisualizer/Settings/build.xml new file mode 100644 index 0000000000000000000000000000000000000000..7ba84f5cc6d4cea5f24729e7c134791f7323286a --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Settings/build.xml @@ -0,0 +1,8 @@ + + + + + + Builds, tests, and runs the project com.sun.hotspot.igv.settings. + + diff --git a/src/share/tools/IdealGraphVisualizer/Settings/manifest.mf b/src/share/tools/IdealGraphVisualizer/Settings/manifest.mf new file mode 100644 index 0000000000000000000000000000000000000000..15f55c9f98501e75ee7afc9c5db2215fbd1c9109 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Settings/manifest.mf @@ -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 --git a/src/share/tools/IdealGraphVisualizer/Settings/nbproject/build-impl.xml b/src/share/tools/IdealGraphVisualizer/Settings/nbproject/build-impl.xml new file mode 100644 index 0000000000000000000000000000000000000000..ca15154cf9f573343b7e9cb2590d16773321c349 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Settings/nbproject/build-impl.xml @@ -0,0 +1,30 @@ + + + + + + You must set 'suite.dir' to point to your containing module suite + + + + + + + + + + + + + + + + + + + + + diff --git a/src/share/tools/IdealGraphVisualizer/Settings/nbproject/genfiles.properties b/src/share/tools/IdealGraphVisualizer/Settings/nbproject/genfiles.properties new file mode 100644 index 0000000000000000000000000000000000000000..d7271112dad956534103d8ae5967b76c1df6973f --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Settings/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=8869440a +build.xml.script.CRC32=7ef09117 +build.xml.stylesheet.CRC32=79c3b980 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=8869440a +nbproject/build-impl.xml.script.CRC32=1a0e7f21 +nbproject/build-impl.xml.stylesheet.CRC32=deb65f65 diff --git a/src/share/tools/IdealGraphVisualizer/Settings/nbproject/platform.properties b/src/share/tools/IdealGraphVisualizer/Settings/nbproject/platform.properties new file mode 100644 index 0000000000000000000000000000000000000000..68ad75e5766f33be5a65a19d28cc7605c5b50a1c --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Settings/nbproject/platform.properties @@ -0,0 +1,29 @@ +# Deprecated since 5.0u1; for compatibility with 5.0: +disabled.clusters=\ + apisupport1,\ + harness,\ + ide8,\ + java1,\ + nb6.0,\ + profiler2 +disabled.modules=\ + org.netbeans.core.execution,\ + org.netbeans.core.multiview,\ + org.netbeans.core.output2,\ + org.netbeans.modules.applemenu,\ + org.netbeans.modules.autoupdate.services,\ + org.netbeans.modules.autoupdate.ui,\ + org.netbeans.modules.core.kit,\ + org.netbeans.modules.favorites,\ + org.netbeans.modules.javahelp,\ + org.netbeans.modules.masterfs,\ + org.netbeans.modules.options.keymap,\ + org.netbeans.modules.sendopts,\ + org.netbeans.modules.templates,\ + org.openide.compat,\ + org.openide.execution,\ + org.openide.util.enumerations +enabled.clusters=\ + platform7 +nbjdk.active=JDK_1.6 +nbplatform.active=default diff --git a/src/share/tools/IdealGraphVisualizer/Settings/nbproject/project.properties b/src/share/tools/IdealGraphVisualizer/Settings/nbproject/project.properties new file mode 100644 index 0000000000000000000000000000000000000000..152f44eca60ab831869539ffae9192aa03915f3b --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Settings/nbproject/project.properties @@ -0,0 +1,2 @@ +javac.source=1.5 +javac.compilerargs=-Xlint -Xlint:-serial diff --git a/src/share/tools/IdealGraphVisualizer/Settings/nbproject/project.xml b/src/share/tools/IdealGraphVisualizer/Settings/nbproject/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..0748a12fcafd32faf536ae6a19110f331b55b123 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Settings/nbproject/project.xml @@ -0,0 +1,49 @@ + + + org.netbeans.modules.apisupport.project + + + com.sun.hotspot.igv.settings + + + + org.jdesktop.layout + + + + 1 + 1.4 + + + + org.netbeans.modules.options.api + + + + 1 + 1.5 + + + + org.openide.awt + + + + 6.11.0.1 + + + + org.openide.util + + + + 7.9.0.1 + + + + + com.sun.hotspot.igv.settings + + + + diff --git a/src/share/tools/IdealGraphVisualizer/Settings/nbproject/suite.properties b/src/share/tools/IdealGraphVisualizer/Settings/nbproject/suite.properties new file mode 100644 index 0000000000000000000000000000000000000000..29d7cc9bd6fdd81453543cdf1bcf1dab301e3a92 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Settings/nbproject/suite.properties @@ -0,0 +1 @@ +suite.dir=${basedir}/.. diff --git a/src/share/tools/IdealGraphVisualizer/Settings/src/com/sun/hotspot/igv/settings/Bundle.properties b/src/share/tools/IdealGraphVisualizer/Settings/src/com/sun/hotspot/igv/settings/Bundle.properties new file mode 100644 index 0000000000000000000000000000000000000000..2c701a08276fa12c523399afcbe5a50d462ec5e7 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Settings/src/com/sun/hotspot/igv/settings/Bundle.properties @@ -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 --git a/src/share/tools/IdealGraphVisualizer/Settings/src/com/sun/hotspot/igv/settings/Settings.java b/src/share/tools/IdealGraphVisualizer/Settings/src/com/sun/hotspot/igv/settings/Settings.java new file mode 100644 index 0000000000000000000000000000000000000000..af7627cdecad49a0148768d0b9aa781b2b70e971 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Settings/src/com/sun/hotspot/igv/settings/Settings.java @@ -0,0 +1,47 @@ +/* + * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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 --git a/src/share/tools/IdealGraphVisualizer/Settings/src/com/sun/hotspot/igv/settings/ViewOptionsCategory.java b/src/share/tools/IdealGraphVisualizer/Settings/src/com/sun/hotspot/igv/settings/ViewOptionsCategory.java new file mode 100644 index 0000000000000000000000000000000000000000..857f87edd33de4854a4905d68fcaf10a2c11cb3b --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Settings/src/com/sun/hotspot/igv/settings/ViewOptionsCategory.java @@ -0,0 +1,55 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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.NbBundle; +import org.openide.util.Utilities; + +/** + * + * @author Thomas Wuerthinger + */ +public final class ViewOptionsCategory extends OptionsCategory { + + @Override + public Icon getIcon() { + return new ImageIcon(Utilities.loadImage("com/sun/hotspot/igv/settings/settings.gif")); + } + + public String getCategoryName() { + return NbBundle.getMessage(ViewOptionsCategory.class, "OptionsCategory_Name_View"); + } + + public String getTitle() { + return NbBundle.getMessage(ViewOptionsCategory.class, "OptionsCategory_Title_View"); + } + + public OptionsPanelController create() { + return new ViewOptionsPanelController(); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Settings/src/com/sun/hotspot/igv/settings/ViewOptionsPanelController.java b/src/share/tools/IdealGraphVisualizer/Settings/src/com/sun/hotspot/igv/settings/ViewOptionsPanelController.java new file mode 100644 index 0000000000000000000000000000000000000000..0e6c09a24223ce91b7dbfd9bb281d6c03540bc0c --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Settings/src/com/sun/hotspot/igv/settings/ViewOptionsPanelController.java @@ -0,0 +1,95 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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; + + public void update() { + getPanel().load(); + changed = false; + } + + public void applyChanges() { + getPanel().store(); + changed = false; + } + + public void cancel() { + // need not do anything special, if no changes have been persisted yet + } + + public boolean isValid() { + return getPanel().valid(); + } + + public boolean isChanged() { + return changed; + } + + public HelpCtx getHelpCtx() { + return null; // new HelpCtx("...ID") if you have a help set + } + + public JComponent getComponent(Lookup masterLookup) { + return getPanel(); + } + + public void addPropertyChangeListener(PropertyChangeListener l) { + pcs.addPropertyChangeListener(l); + } + + 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 --git a/src/share/tools/IdealGraphVisualizer/Settings/src/com/sun/hotspot/igv/settings/ViewPanel.form b/src/share/tools/IdealGraphVisualizer/Settings/src/com/sun/hotspot/igv/settings/ViewPanel.form new file mode 100644 index 0000000000000000000000000000000000000000..9b3fc1ec942f0bb30a4abfd4ebdff8dae1281224 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Settings/src/com/sun/hotspot/igv/settings/ViewPanel.form @@ -0,0 +1,121 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/share/tools/IdealGraphVisualizer/Settings/src/com/sun/hotspot/igv/settings/ViewPanel.java b/src/share/tools/IdealGraphVisualizer/Settings/src/com/sun/hotspot/igv/settings/ViewPanel.java new file mode 100644 index 0000000000000000000000000000000000000000..b02644a5866c6a5b3eaaf9d5db2166785dba838f --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Settings/src/com/sun/hotspot/igv/settings/ViewPanel.java @@ -0,0 +1,144 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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 --git a/src/share/tools/IdealGraphVisualizer/Settings/src/com/sun/hotspot/igv/settings/layer.xml b/src/share/tools/IdealGraphVisualizer/Settings/src/com/sun/hotspot/igv/settings/layer.xml new file mode 100644 index 0000000000000000000000000000000000000000..f7a7aba501810f1af1033e7d155dccd17c864e00 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Settings/src/com/sun/hotspot/igv/settings/layer.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/share/tools/IdealGraphVisualizer/Settings/src/com/sun/hotspot/igv/settings/settings.gif b/src/share/tools/IdealGraphVisualizer/Settings/src/com/sun/hotspot/igv/settings/settings.gif new file mode 100644 index 0000000000000000000000000000000000000000..030be8228d70c7bd5f31382613fcb0ed151d8700 Binary files /dev/null and b/src/share/tools/IdealGraphVisualizer/Settings/src/com/sun/hotspot/igv/settings/settings.gif differ diff --git a/src/share/tools/IdealGraphVisualizer/Util/build.xml b/src/share/tools/IdealGraphVisualizer/Util/build.xml new file mode 100644 index 0000000000000000000000000000000000000000..1af1e360034dddf9bd9ff1920b938ed35b7abc12 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Util/build.xml @@ -0,0 +1,8 @@ + + + + + + Builds, tests, and runs the project com.sun.hotspot.igv.util. + + diff --git a/src/share/tools/IdealGraphVisualizer/Util/manifest.mf b/src/share/tools/IdealGraphVisualizer/Util/manifest.mf new file mode 100644 index 0000000000000000000000000000000000000000..9c10b50e24fc1e9b5e8e25dc708d9ac1a08f2d6e --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Util/manifest.mf @@ -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 --git a/src/share/tools/IdealGraphVisualizer/Util/nbproject/build-impl.xml b/src/share/tools/IdealGraphVisualizer/Util/nbproject/build-impl.xml new file mode 100644 index 0000000000000000000000000000000000000000..8a444c36b55b39f8fd0124e2df006bfea7cd4d29 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Util/nbproject/build-impl.xml @@ -0,0 +1,30 @@ + + + + + + You must set 'suite.dir' to point to your containing module suite + + + + + + + + + + + + + + + + + + + + + diff --git a/src/share/tools/IdealGraphVisualizer/Util/nbproject/genfiles.properties b/src/share/tools/IdealGraphVisualizer/Util/nbproject/genfiles.properties new file mode 100644 index 0000000000000000000000000000000000000000..494d2b8ef84a2fe4aabe809c2cf6476a9b930cfb --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Util/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=a470a16f +build.xml.script.CRC32=466cf03b +build.xml.stylesheet.CRC32=05353c81 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=a470a16f +nbproject/build-impl.xml.script.CRC32=39f45e01 +nbproject/build-impl.xml.stylesheet.CRC32=3f8b4615 diff --git a/src/share/tools/IdealGraphVisualizer/Util/nbproject/platform.properties b/src/share/tools/IdealGraphVisualizer/Util/nbproject/platform.properties new file mode 100644 index 0000000000000000000000000000000000000000..68ad75e5766f33be5a65a19d28cc7605c5b50a1c --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Util/nbproject/platform.properties @@ -0,0 +1,29 @@ +# Deprecated since 5.0u1; for compatibility with 5.0: +disabled.clusters=\ + apisupport1,\ + harness,\ + ide8,\ + java1,\ + nb6.0,\ + profiler2 +disabled.modules=\ + org.netbeans.core.execution,\ + org.netbeans.core.multiview,\ + org.netbeans.core.output2,\ + org.netbeans.modules.applemenu,\ + org.netbeans.modules.autoupdate.services,\ + org.netbeans.modules.autoupdate.ui,\ + org.netbeans.modules.core.kit,\ + org.netbeans.modules.favorites,\ + org.netbeans.modules.javahelp,\ + org.netbeans.modules.masterfs,\ + org.netbeans.modules.options.keymap,\ + org.netbeans.modules.sendopts,\ + org.netbeans.modules.templates,\ + org.openide.compat,\ + org.openide.execution,\ + org.openide.util.enumerations +enabled.clusters=\ + platform7 +nbjdk.active=JDK_1.6 +nbplatform.active=default diff --git a/src/share/tools/IdealGraphVisualizer/Util/nbproject/project.properties b/src/share/tools/IdealGraphVisualizer/Util/nbproject/project.properties new file mode 100644 index 0000000000000000000000000000000000000000..152f44eca60ab831869539ffae9192aa03915f3b --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Util/nbproject/project.properties @@ -0,0 +1,2 @@ +javac.source=1.5 +javac.compilerargs=-Xlint -Xlint:-serial diff --git a/src/share/tools/IdealGraphVisualizer/Util/nbproject/project.xml b/src/share/tools/IdealGraphVisualizer/Util/nbproject/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..3ae7755b1aae164abd2aa8de9d8702a1813c2388 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Util/nbproject/project.xml @@ -0,0 +1,47 @@ + + + org.netbeans.modules.apisupport.project + + + com.sun.hotspot.igv.util + + + + com.sun.hotspot.igv.data + + + + 1.0 + + + + org.netbeans.api.visual + + + + 2.9 + + + + org.openide.nodes + + + + 7.2.1.1 + + + + org.openide.util + + + + 7.10.1.1 + + + + + com.sun.hotspot.igv.util + + + + diff --git a/src/share/tools/IdealGraphVisualizer/Util/nbproject/suite.properties b/src/share/tools/IdealGraphVisualizer/Util/nbproject/suite.properties new file mode 100644 index 0000000000000000000000000000000000000000..29d7cc9bd6fdd81453543cdf1bcf1dab301e3a92 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Util/nbproject/suite.properties @@ -0,0 +1 @@ +suite.dir=${basedir}/.. diff --git a/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/BoundedZoomAction.java b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/BoundedZoomAction.java new file mode 100644 index 0000000000000000000000000000000000000000..f79113fea4cdfd2ec151ea5b13bf554556ddd89e --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/BoundedZoomAction.java @@ -0,0 +1,182 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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; + Point oldViewPosition = null; + Rectangle bounds = new Rectangle(scene.getBounds()); + Dimension componentSize = new Dimension(scene.getView().getPreferredSize()); + + if (scrollPane != null) { + viewPosition = new Point(scrollPane.getViewport().getViewPosition()); + oldViewPosition = new Point(viewPosition); + xOffset = (mouseLocation.x - viewPosition.x); + yOffset = (mouseLocation.y - viewPosition.y); + viewPosition.x += xOffset; + 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 --git a/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/Bundle.properties b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/Bundle.properties new file mode 100644 index 0000000000000000000000000000000000000000..ad93affc8a59479400086ecf51f6cea7214e9f9b --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/Bundle.properties @@ -0,0 +1 @@ +OpenIDE-Module-Name=Util diff --git a/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/ColorIcon.java b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/ColorIcon.java new file mode 100644 index 0000000000000000000000000000000000000000..2c0c2ff8d236cce065b63047212e184ee6ff6a07 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/ColorIcon.java @@ -0,0 +1,55 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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; + } + + public void paintIcon(Component c, Graphics g, int x, int y) { + g.setColor(color); + g.fillRect(x, y, 16, 16); + } + + public int getIconWidth() { + return 16; + } + + public int getIconHeight() { + return 16; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/ContextAction.java b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/ContextAction.java new file mode 100644 index 0000000000000000000000000000000000000000..cc82017ca240148a510274b2100465b5ce641d0c --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/ContextAction.java @@ -0,0 +1,95 @@ +/* + * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ +package com.sun.hotspot.igv.util; + +import java.awt.EventQueue; +import org.openide.util.ContextAwareAction; +import org.openide.util.Lookup; +import org.openide.util.LookupEvent; +import org.openide.util.LookupListener; +import org.openide.util.Utilities; +import org.openide.util.actions.CallableSystemAction; + +/** + * + * @author Thomas Wuerthinger + */ +public abstract class ContextAction extends CallableSystemAction implements LookupListener, ContextAwareAction { + + private Lookup context = null; + private Lookup.Result result = null; + + public ContextAction() { + this(Utilities.actionsGlobalContext()); + } + + public ContextAction(Lookup context) { + init(context); + } + + private void init(Lookup context) { + this.context = context; + result = context.lookupResult(contextClass()); + result.addLookupListener(this); + resultChanged(null); + } + + public void resultChanged(LookupEvent e) { + if (result.allItems().size() != 0) { + update(result.allInstances().iterator().next()); + } else { + update(null); + } + } + + @Override + public void performAction() { + final T t = result.allInstances().iterator().next(); + + // Ensure it's AWT event thread + EventQueue.invokeLater(new Runnable() { + + public void run() { + performAction(t); + } + }); + } + + public void update(T t) { + if (t == null) { + setEnabled(false); + } else { + setEnabled(isEnabled(t)); + } + } + + public boolean isEnabled(T context) { + return true; + } + + public abstract Class contextClass(); + + public abstract void performAction(T context); +} diff --git a/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/DoubleClickAction.java b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/DoubleClickAction.java new file mode 100644 index 0000000000000000000000000000000000000000..e01f8c8b1317dd35cf0ef932a967cae998c7908b --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/DoubleClickAction.java @@ -0,0 +1,49 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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 --git a/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/DoubleClickHandler.java b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/DoubleClickHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..61ccaed0bf0dc6e3724c8e2e44102df38756d219 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/DoubleClickHandler.java @@ -0,0 +1,36 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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 --git a/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/ExtendedSatelliteComponent.java b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/ExtendedSatelliteComponent.java new file mode 100644 index 0000000000000000000000000000000000000000..81cf5c7ba92f5a78860d83610c12f33bf1de5593 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/ExtendedSatelliteComponent.java @@ -0,0 +1,195 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.util; + +import org.netbeans.api.visual.widget.Scene; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; + +/** + * @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); + } + } + + public void mouseClicked(MouseEvent e) { + } + + public void mousePressed(MouseEvent e) { + moveVisibleRect(e.getPoint()); + } + + public void mouseReleased(MouseEvent e) { + moveVisibleRect(e.getPoint()); + } + + public void mouseEntered(MouseEvent e) { + } + + public void mouseExited(MouseEvent e) { + } + + public void mouseDragged(MouseEvent e) { + moveVisibleRect(e.getPoint()); + } + + 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); + + } + + public void sceneRepaint() { + } + + public void sceneValidating() { + } + + public void sceneValidated() { + } + + public void componentResized(ComponentEvent e) { + repaint(); + } + + public void componentMoved(ComponentEvent e) { + repaint(); + } + + public void componentShown(ComponentEvent e) { + } + + public void componentHidden(ComponentEvent e) { + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/ExtendedSelectAction.java b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/ExtendedSelectAction.java new file mode 100644 index 0000000000000000000000000000000000000000..7501c14720b09c233f8e12f4e2a20d04d4aad92b --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/ExtendedSelectAction.java @@ -0,0 +1,69 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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 --git a/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/PropertiesSheet.java b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/PropertiesSheet.java new file mode 100644 index 0000000000000000000000000000000000000000..f058edda6ae784a6bde1dcdb1920c80a7419bb22 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/PropertiesSheet.java @@ -0,0 +1,71 @@ +/* + * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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(Properties properties, Sheet s) { + + Sheet.Set set1 = Sheet.createPropertiesSet(); + set1.setDisplayName("Properties"); + for (final Property p : properties.getProperties()) { + 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 { + p.setValue(arg0); + } + }; + prop.setName(p.getName()); + set1.put(prop); + } + s.put(set1); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/RangeSlider.java b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/RangeSlider.java new file mode 100644 index 0000000000000000000000000000000000000000..c5f3100f2052952b8dc4826883ae71ee456d300c --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/RangeSlider.java @@ -0,0 +1,360 @@ +/* + * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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.Color; +import java.awt.Cursor; +import java.awt.Dimension; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.RenderingHints; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.util.List; +import javax.swing.JComponent; + +/** + * + * @author Thomas Wuerthinger + */ +public class RangeSlider extends JComponent implements ChangedListener, MouseListener, MouseMotionListener { + + public static final int HEIGHT = 40; + public static final int BAR_HEIGHT = 22; + public static final int BAR_SELECTION_ENDING_HEIGHT = 16; + public static final int BAR_SELECTION_HEIGHT = 10; + public static final int BAR_THICKNESS = 2; + public static final int BAR_CIRCLE_SIZE = 9; + public static final int MOUSE_ENDING_OFFSET = 3; + public static final Color BACKGROUND_COLOR = Color.white; + public static final Color BAR_COLOR = Color.black; + public static final Color BAR_SELECTION_COLOR = new Color(255, 0, 0, 120); + public static final Color BAR_SELECTION_COLOR_ROLLOVER = new Color(255, 0, 255, 120); + public static final Color BAR_SELECTION_COLOR_DRAG = new Color(0, 0, 255, 120); + private RangeSliderModel model; + private State state; + private Point startPoint; + private RangeSliderModel tempModel; + private boolean isOverBar; + + private enum State { + + Initial, + DragBar, + DragFirstPosition, + DragSecondPosition + } + + public RangeSlider() { + state = State.Initial; + this.addMouseMotionListener(this); + this.addMouseListener(this); + } + + public void setModel(RangeSliderModel newModel) { + if (model != null) { + model.getChangedEvent().removeListener(this); + model.getColorChangedEvent().removeListener(this); + } + if (newModel != null) { + newModel.getChangedEvent().addListener(this); + newModel.getColorChangedEvent().addListener(this); + } + this.model = newModel; + update(); + } + + private RangeSliderModel getPaintingModel() { + if (tempModel != null) { + return tempModel; + } + return model; + } + + @Override + public Dimension getPreferredSize() { + Dimension d = super.getPreferredSize(); + d.height = HEIGHT; + return d; + } + + public void changed(RangeSliderModel source) { + update(); + } + + private void update() { + this.repaint(); + } + + private int getXPosition(int index) { + assert index >= 0 && index < getPaintingModel().getPositions().size(); + return getXOffset() * (index + 1); + } + + private int getXOffset() { + int size = getPaintingModel().getPositions().size(); + int width = getWidth(); + return (width / (size + 1)); + } + + private int getEndXPosition(int index) { + return getXPosition(index) + getXOffset() / 2; + } + + private int getStartXPosition(int index) { + return getXPosition(index) - getXOffset() / 2; + } + + @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().size() == 0) { + return; + } + + int firstPos = getPaintingModel().getFirstPosition(); + int secondPos = getPaintingModel().getSecondPosition(); + + paintSelected(g2, firstPos, secondPos); + paintBar(g2); + + } + + private int getBarStartY() { + return getHeight() - BAR_HEIGHT; + } + + private void paintBar(Graphics2D g) { + List list = getPaintingModel().getPositions(); + int barStartY = getBarStartY(); + + g.setColor(BAR_COLOR); + g.fillRect(getXPosition(0), barStartY + BAR_HEIGHT / 2 - BAR_THICKNESS / 2, getXPosition(list.size() - 1) - getXPosition(0), BAR_THICKNESS); + + int circleCenterY = barStartY + BAR_HEIGHT / 2; + for (int i = 0; i < list.size(); i++) { + int curX = getXPosition(i); + g.setColor(getPaintingModel().getColors().get(i)); + g.fillOval(curX - BAR_CIRCLE_SIZE / 2, circleCenterY - BAR_CIRCLE_SIZE / 2, BAR_CIRCLE_SIZE, BAR_CIRCLE_SIZE); + g.setColor(Color.black); + g.drawOval(curX - BAR_CIRCLE_SIZE / 2, circleCenterY - BAR_CIRCLE_SIZE / 2, BAR_CIRCLE_SIZE, BAR_CIRCLE_SIZE); + + + String curS = list.get(i); + if (curS != null && curS.length() > 0) { + int startX = getStartXPosition(i); + int endX = getEndXPosition(i); + FontMetrics metrics = g.getFontMetrics(); + Rectangle bounds = metrics.getStringBounds(curS, g).getBounds(); + if (bounds.width < endX - startX && bounds.height < barStartY) { + g.setColor(Color.black); + g.drawString(curS, startX + (endX - startX) / 2 - bounds.width / 2, barStartY / 2 + bounds.height / 2); + } + } + } + + } + + private void paintSelected(Graphics2D g, int start, int end) { + + int startX = getStartXPosition(start); + int endX = getEndXPosition(end); + int barStartY = getBarStartY(); + int barSelectionEndingStartY = barStartY + BAR_HEIGHT / 2 - BAR_SELECTION_ENDING_HEIGHT / 2; + paintSelectedEnding(g, startX, barSelectionEndingStartY); + paintSelectedEnding(g, endX, barSelectionEndingStartY); + + g.setColor(BAR_SELECTION_COLOR); + if (state == State.DragBar) { + g.setColor(BAR_SELECTION_COLOR_DRAG); + } else if (isOverBar) { + g.setColor(BAR_SELECTION_COLOR_ROLLOVER); + } + g.fillRect(startX, barStartY + BAR_HEIGHT / 2 - BAR_SELECTION_HEIGHT / 2, endX - startX, BAR_SELECTION_HEIGHT); + } + + private void paintSelectedEnding(Graphics g, int x, int y) { + g.setColor(BAR_COLOR); + g.fillRect(x - BAR_THICKNESS / 2, y, BAR_THICKNESS, BAR_SELECTION_ENDING_HEIGHT); + } + + private boolean isOverSecondPosition(Point p) { + if (p.y >= getBarStartY()) { + int destX = getEndXPosition(getPaintingModel().getSecondPosition()); + int off = Math.abs(destX - p.x); + return off <= MOUSE_ENDING_OFFSET; + } + return false; + } + + private boolean isOverFirstPosition(Point p) { + if (p.y >= getBarStartY()) { + int destX = getStartXPosition(getPaintingModel().getFirstPosition()); + int off = Math.abs(destX - p.x); + return off <= MOUSE_ENDING_OFFSET; + } + return false; + } + + private boolean isOverSelection(Point p) { + if (p.y >= getBarStartY() && !isOverFirstPosition(p) && !isOverSecondPosition(p)) { + return p.x > getStartXPosition(getPaintingModel().getFirstPosition()) && p.x < getEndXPosition(getPaintingModel().getSecondPosition()); + } + return false; + } + + public void mouseDragged(MouseEvent e) { + if (state == State.DragBar) { + int firstX = this.getStartXPosition(model.getFirstPosition()); + int newFirstX = firstX + e.getPoint().x - startPoint.x; + int newIndex = getIndexFromPosition(newFirstX) + 1; + if (newIndex + model.getSecondPosition() - model.getFirstPosition() >= model.getPositions().size()) { + newIndex = model.getPositions().size() - (model.getSecondPosition() - model.getFirstPosition()) - 1; + } + int secondPosition = newIndex + model.getSecondPosition() - model.getFirstPosition(); + tempModel.setPositions(newIndex, secondPosition); + update(); + } else if (state == State.DragFirstPosition) { + int firstPosition = getIndexFromPosition(e.getPoint().x) + 1; + int secondPosition = model.getSecondPosition(); + if (firstPosition > secondPosition) { + firstPosition--; + } + tempModel.setPositions(firstPosition, secondPosition); + update(); + } else if (state == State.DragSecondPosition) { + int firstPosition = model.getFirstPosition(); + int secondPosition = getIndexFromPosition(e.getPoint().x); + if (secondPosition < firstPosition) { + secondPosition++; + } + tempModel.setPositions(firstPosition, secondPosition); + update(); + } + } + + private int getIndexFromPosition(int x) { + if (x < getXPosition(0)) { + return -1; + } + for (int i = 0; i < getPaintingModel().getPositions().size() - 1; i++) { + int startX = getXPosition(i); + int endX = getXPosition(i + 1); + if (x >= startX && x <= endX) { + return i; + } + } + return getPaintingModel().getPositions().size() - 1; + } + + private int getCircleIndexFromPosition(int x) { + int result = 0; + for (int i = 1; i < getPaintingModel().getPositions().size() - 1; i++) { + if (x > getStartXPosition(i)) { + result = i; + } + } + return result; + } + + public void mouseMoved(MouseEvent e) { + isOverBar = false; + if (model == null) { + return; + } + + + Point p = e.getPoint(); + if (isOverFirstPosition(p) || isOverSecondPosition(p)) { + setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR)); + } else if (isOverSelection(p)) { + isOverBar = true; + setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + } else { + this.setCursor(Cursor.getDefaultCursor()); + } + repaint(); + } + + public void mouseClicked(MouseEvent e) { + if (e.getClickCount() > 1) { + // Double click + int index = getCircleIndexFromPosition(e.getPoint().x); + model.setPositions(index, index); + } + } + + public void mousePressed(MouseEvent e) { + if (model == null) { + return; + } + + Point p = e.getPoint(); + if (isOverFirstPosition(p)) { + state = State.DragFirstPosition; + } else if (isOverSecondPosition(p)) { + state = State.DragSecondPosition; + } else if (isOverSelection(p)) { + state = State.DragBar; + } else { + return; + } + + startPoint = e.getPoint(); + tempModel = model.copy(); + } + + public void mouseReleased(MouseEvent e) { + if (model == null || tempModel == null) { + return; + } + state = State.Initial; + model.setPositions(tempModel.getFirstPosition(), tempModel.getSecondPosition()); + tempModel = null; + } + + public void mouseEntered(MouseEvent e) { + } + + public void mouseExited(MouseEvent e) { + isOverBar = false; + repaint(); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/RangeSliderModel.java b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/RangeSliderModel.java new file mode 100644 index 0000000000000000000000000000000000000000..71766ec3b67b0c5091b230daecf75299b1c5d730 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/RangeSliderModel.java @@ -0,0 +1,130 @@ +/* + * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ +package com.sun.hotspot.igv.util; + +import com.sun.hotspot.igv.data.ChangedEventProvider; +import com.sun.hotspot.igv.data.ChangedEvent; +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 ChangedEvent colorChangedEvent; + 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; + boolean colorChanged = (colors != model.colors); + colors = model.colors; + if (changed) { + changedEvent.fire(); + } + if (colorChanged) { + colorChangedEvent.fire(); + } + } + + public RangeSliderModel(List positions) { + assert positions.size() > 0; + this.positions = positions; + this.changedEvent = new ChangedEvent(this); + this.colorChangedEvent = new ChangedEvent(this); + colors = new ArrayList(); + for (int i = 0; i < positions.size(); i++) { + colors.add(Color.black); + } + } + + public void setColors(List colors) { + this.colors = colors; + colorChangedEvent.fire(); + } + + public List getColors() { + return colors; + } + + public RangeSliderModel copy() { + RangeSliderModel newModel = new RangeSliderModel(positions); + newModel.firstPosition = firstPosition; + newModel.secondPosition = secondPosition; + newModel.colors = colors; + 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; + } + } + + public ChangedEvent getColorChangedEvent() { + return colorChangedEvent; + } + + public ChangedEvent getChangedEvent() { + return changedEvent; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/View/build.xml b/src/share/tools/IdealGraphVisualizer/View/build.xml new file mode 100644 index 0000000000000000000000000000000000000000..c0c4cd49d7a09fc8ef82d225166c3777a0b7511c --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/build.xml @@ -0,0 +1,8 @@ + + + + + + Builds, tests, and runs the project com.sun.hotspot.igv.view. + + diff --git a/src/share/tools/IdealGraphVisualizer/View/manifest.mf b/src/share/tools/IdealGraphVisualizer/View/manifest.mf new file mode 100644 index 0000000000000000000000000000000000000000..870dc9065a6da37ea4068d8adb946e1d7eb7faab --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/manifest.mf @@ -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 --git a/src/share/tools/IdealGraphVisualizer/View/nbproject/build-impl.xml b/src/share/tools/IdealGraphVisualizer/View/nbproject/build-impl.xml new file mode 100644 index 0000000000000000000000000000000000000000..0de8e534ead150e4a1ac99c1b63922dbccd9e818 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/nbproject/build-impl.xml @@ -0,0 +1,30 @@ + + + + + + You must set 'suite.dir' to point to your containing module suite + + + + + + + + + + + + + + + + + + + + + diff --git a/src/share/tools/IdealGraphVisualizer/View/nbproject/genfiles.properties b/src/share/tools/IdealGraphVisualizer/View/nbproject/genfiles.properties new file mode 100644 index 0000000000000000000000000000000000000000..8d7a4ea4c02d0e69be5187bd486416f51d6a5837 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=2de95ef6 +build.xml.script.CRC32=31afe4b1 +build.xml.stylesheet.CRC32=79c3b980 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=2de95ef6 +nbproject/build-impl.xml.script.CRC32=fa7a4119 +nbproject/build-impl.xml.stylesheet.CRC32=deb65f65 diff --git a/src/share/tools/IdealGraphVisualizer/View/nbproject/platform.properties b/src/share/tools/IdealGraphVisualizer/View/nbproject/platform.properties new file mode 100644 index 0000000000000000000000000000000000000000..68ad75e5766f33be5a65a19d28cc7605c5b50a1c --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/nbproject/platform.properties @@ -0,0 +1,29 @@ +# Deprecated since 5.0u1; for compatibility with 5.0: +disabled.clusters=\ + apisupport1,\ + harness,\ + ide8,\ + java1,\ + nb6.0,\ + profiler2 +disabled.modules=\ + org.netbeans.core.execution,\ + org.netbeans.core.multiview,\ + org.netbeans.core.output2,\ + org.netbeans.modules.applemenu,\ + org.netbeans.modules.autoupdate.services,\ + org.netbeans.modules.autoupdate.ui,\ + org.netbeans.modules.core.kit,\ + org.netbeans.modules.favorites,\ + org.netbeans.modules.javahelp,\ + org.netbeans.modules.masterfs,\ + org.netbeans.modules.options.keymap,\ + org.netbeans.modules.sendopts,\ + org.netbeans.modules.templates,\ + org.openide.compat,\ + org.openide.execution,\ + org.openide.util.enumerations +enabled.clusters=\ + platform7 +nbjdk.active=JDK_1.6 +nbplatform.active=default diff --git a/src/share/tools/IdealGraphVisualizer/View/nbproject/project.properties b/src/share/tools/IdealGraphVisualizer/View/nbproject/project.properties new file mode 100644 index 0000000000000000000000000000000000000000..152f44eca60ab831869539ffae9192aa03915f3b --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/nbproject/project.properties @@ -0,0 +1,2 @@ +javac.source=1.5 +javac.compilerargs=-Xlint -Xlint:-serial diff --git a/src/share/tools/IdealGraphVisualizer/View/nbproject/project.xml b/src/share/tools/IdealGraphVisualizer/View/nbproject/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..96b103188e9793ec59758ebad17311ab0d808b99 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/nbproject/project.xml @@ -0,0 +1,151 @@ + + + org.netbeans.modules.apisupport.project + + + com.sun.hotspot.igv.view + + + + com.sun.hotspot.igv.data + + + + 1.0 + + + + com.sun.hotspot.igv.difference + + + + 1.0 + + + + com.sun.hotspot.igv.filter + + + + 1.0 + + + + com.sun.hotspot.igv.graph + + + + 1.0 + + + + com.sun.hotspot.igv.hierarchicallayout + + + + 1.0 + + + + com.sun.hotspot.igv.layout + + + + 1.0 + + + + com.sun.hotspot.igv.settings + + + + 1.0 + + + + com.sun.hotspot.igv.svg + + + + 1.0 + + + + com.sun.hotspot.igv.util + + + + 1.0 + + + + org.netbeans.api.visual + + + + 2.9 + + + + org.openide.actions + + + + 6.6.0.1 + + + + org.openide.awt + + + + 6.11.0.1 + + + + org.openide.dialogs + + + + 7.5.1 + + + + org.openide.loaders + + + + 6.7 + + + + org.openide.nodes + + + + 7.2.1.1 + + + + org.openide.util + + + + 7.9.0.1 + + + + org.openide.windows + + + + 6.16 + + + + + com.sun.hotspot.igv.view + + + + diff --git a/src/share/tools/IdealGraphVisualizer/View/nbproject/suite.properties b/src/share/tools/IdealGraphVisualizer/View/nbproject/suite.properties new file mode 100644 index 0000000000000000000000000000000000000000..29d7cc9bd6fdd81453543cdf1bcf1dab301e3a92 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/nbproject/suite.properties @@ -0,0 +1 @@ +suite.dir=${basedir}/.. diff --git a/src/share/tools/IdealGraphVisualizer/View/src/META-INF/services/com.sun.hotspot.igv.data.services.GraphViewer b/src/share/tools/IdealGraphVisualizer/View/src/META-INF/services/com.sun.hotspot.igv.data.services.GraphViewer new file mode 100644 index 0000000000000000000000000000000000000000..ad042e6fb3d7c1be915e3fc21bce1f7c13c34a1b --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/META-INF/services/com.sun.hotspot.igv.data.services.GraphViewer @@ -0,0 +1 @@ +com.sun.hotspot.igv.view.GraphViewerImplementation diff --git a/src/share/tools/IdealGraphVisualizer/View/src/META-INF/services/com.sun.hotspot.igv.data.services.InputGraphProvider b/src/share/tools/IdealGraphVisualizer/View/src/META-INF/services/com.sun.hotspot.igv.data.services.InputGraphProvider new file mode 100644 index 0000000000000000000000000000000000000000..e057d732d3d398a69203d8c14b8711c7418c5f9a --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/META-INF/services/com.sun.hotspot.igv.data.services.InputGraphProvider @@ -0,0 +1 @@ +com.sun.hotspot.igv.view.EditorInputGraphProvider diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/BoundedZoomAction.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/BoundedZoomAction.java new file mode 100644 index 0000000000000000000000000000000000000000..87b8fd3cf57682af5f27dd827447af79d265f8c7 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/BoundedZoomAction.java @@ -0,0 +1,175 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.view; + +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Point; +import java.awt.Rectangle; +import javax.swing.JComponent; +import javax.swing.JScrollPane; +import org.netbeans.api.visual.action.WidgetAction; +import org.netbeans.api.visual.action.WidgetAction.State; +import org.netbeans.api.visual.action.WidgetAction.WidgetMouseWheelEvent; +import org.netbeans.api.visual.animator.SceneAnimator; +import org.netbeans.api.visual.widget.Scene; +import org.netbeans.api.visual.widget.Widget; + +/** + * + * @author Thomas Wuerthinger + */ +public class BoundedZoomAction extends WidgetAction.Adapter { + + private double minFactor = 0.0; + private double maxFactor = Double.MAX_VALUE; + private double zoomMultiplier; + private boolean useAnimator; + + public BoundedZoomAction(double zoomMultiplier, boolean useAnimator) { + assert zoomMultiplier > 1.0; + this.zoomMultiplier = zoomMultiplier; + this.useAnimator = useAnimator; + } + + public double getMinFactor() { + return minFactor; + } + + public void setMinFactor(double d) { + minFactor = d; + } + + public double getMaxFactor() { + return maxFactor; + } + + public void setMaxFactor(double d) { + maxFactor = d; + } + + private JScrollPane findScrollPane(JComponent component) { + for (;;) { + if (component == null) { + return null; + } + if (component instanceof JScrollPane) { + return ((JScrollPane) component); + } + Container parent = component.getParent(); + if (!(parent instanceof JComponent)) { + return null; + } + component = (JComponent) parent; + } + } + + @Override + public State mouseWheelMoved(Widget widget, WidgetMouseWheelEvent event) { + final Scene scene = widget.getScene(); + int amount = event.getWheelRotation(); + JScrollPane scrollPane = findScrollPane(scene.getView()); + Point viewPosition = null; + Point mouseLocation = scene.convertSceneToView(event.getPoint()); + int xOffset = 0; + int yOffset = 0; + Rectangle bounds = new Rectangle(scene.getBounds()); + Dimension componentSize = new Dimension(scene.getView().getPreferredSize()); + if (scrollPane != null) { + viewPosition = new Point(scrollPane.getViewport().getViewPosition()); + xOffset = (mouseLocation.x - viewPosition.x); + yOffset = (mouseLocation.y - viewPosition.y); + viewPosition.x += xOffset; + viewPosition.y += yOffset; + } + + if (useAnimator) { + SceneAnimator sceneAnimator = scene.getSceneAnimator(); + synchronized (sceneAnimator) { + double zoom = sceneAnimator.isAnimatingZoomFactor() ? sceneAnimator.getTargetZoomFactor() : scene.getZoomFactor(); + while (amount > 0 && zoom / zoomMultiplier >= minFactor) { + zoom /= zoomMultiplier; + if (viewPosition != null) { + viewPosition.x /= zoomMultiplier; + viewPosition.y /= zoomMultiplier; + bounds.width /= zoomMultiplier; + bounds.height /= zoomMultiplier; + componentSize.width /= zoomMultiplier; + componentSize.height /= zoomMultiplier; + } + amount--; + } + while (amount < 0 && zoom * zoomMultiplier <= maxFactor) { + zoom *= zoomMultiplier; + if (viewPosition != null) { + viewPosition.x *= zoomMultiplier; + viewPosition.y *= zoomMultiplier; + bounds.width *= zoomMultiplier; + bounds.height *= zoomMultiplier; + componentSize.width *= zoomMultiplier; + componentSize.height *= zoomMultiplier; + } + amount++; + } + sceneAnimator.animateZoomFactor(zoom); + } + } else { + double zoom = scene.getZoomFactor(); + while (amount > 0 && zoom / zoomMultiplier >= minFactor) { + zoom /= zoomMultiplier; + if (viewPosition != null) { + viewPosition.x /= zoomMultiplier; + viewPosition.y /= zoomMultiplier; + bounds.width /= zoomMultiplier; + bounds.height /= zoomMultiplier; + componentSize.width /= zoomMultiplier; + componentSize.height /= zoomMultiplier; + } + amount--; + } + while (amount < 0 && zoom * zoomMultiplier <= maxFactor) { + zoom *= zoomMultiplier; + if (viewPosition != null) { + viewPosition.x *= zoomMultiplier; + viewPosition.y *= zoomMultiplier; + bounds.width *= zoomMultiplier; + bounds.height *= zoomMultiplier; + componentSize.width *= zoomMultiplier; + componentSize.height *= zoomMultiplier; + } + amount++; + } + scene.setZoomFactor(zoom); + } + + if (scrollPane != null) { + viewPosition.x -= xOffset; + viewPosition.y -= yOffset; + scrollPane.getViewport().setViewPosition(viewPosition); + } + + + return WidgetAction.State.CONSUMED; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/Bundle.properties b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/Bundle.properties new file mode 100644 index 0000000000000000000000000000000000000000..4593549d591a5ea5cbc5b97e7b6940e1ec26297c --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/Bundle.properties @@ -0,0 +1,3 @@ +HINT_EditorTopComponent=This is a Editor window +OpenIDE-Module-Name=View +CTL_EditorTopComponent=Editor Window diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/ConnectionAnchor.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/ConnectionAnchor.java new file mode 100644 index 0000000000000000000000000000000000000000..3ede4ba17310f5ba6704e5abd3dcf5c44a1bca75 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/ConnectionAnchor.java @@ -0,0 +1,84 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.view; + +import com.sun.hotspot.igv.view.widgets.SlotWidget; +import java.awt.Point; +import java.awt.Rectangle; +import org.netbeans.api.visual.anchor.Anchor; +import org.netbeans.api.visual.anchor.Anchor.Entry; +import org.netbeans.api.visual.anchor.Anchor.Result; +import org.netbeans.api.visual.widget.Widget; + +/** + * + * @author Thomas Wuerthinger + */ +public class ConnectionAnchor extends Anchor { + + public enum HorizontalAlignment { + + Left, + Center, + Right + } + private HorizontalAlignment alignment; + + public ConnectionAnchor(Widget widget) { + this(HorizontalAlignment.Center, widget); + } + + public ConnectionAnchor(HorizontalAlignment alignment, Widget widget) { + super(widget); + this.alignment = alignment; + } + + public Result compute(Entry entry) { + return new Result(getRelatedSceneLocation(), Anchor.DIRECTION_ANY); + } + + @Override + public Point getRelatedSceneLocation() { + Point p = null; + Widget w = getRelatedWidget(); + if (w != null) { + if (w instanceof SlotWidget) { + p = ((SlotWidget) w).getAnchorPosition(); + } else { + Rectangle r = w.convertLocalToScene(w.getBounds()); + int y = r.y + r.height / 2; + int x = r.x; + if (alignment == HorizontalAlignment.Center) { + x = r.x + r.width / 2; + } else if (alignment == HorizontalAlignment.Right) { + x = r.x + r.width; + } + + p = new Point(x, y); + } + } + + return p; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/DiagramScene.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/DiagramScene.java new file mode 100644 index 0000000000000000000000000000000000000000..2ee3067acfe8749367b017978e5cc1315568856d --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/DiagramScene.java @@ -0,0 +1,1254 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.view; + +import com.sun.hotspot.igv.view.widgets.BlockWidget; +import com.sun.hotspot.igv.view.widgets.LineWidget; +import com.sun.hotspot.igv.util.DoubleClickAction; +import com.sun.hotspot.igv.data.InputBlock; +import com.sun.hotspot.igv.data.InputNode; +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 com.sun.hotspot.igv.graph.OutputSlot; +import com.sun.hotspot.igv.graph.Slot; +import com.sun.hotspot.igv.hierarchicallayout.HierarchicalClusterLayoutManager; +import com.sun.hotspot.igv.hierarchicallayout.OldHierarchicalLayoutManager; +import com.sun.hotspot.igv.hierarchicallayout.HierarchicalLayoutManager; +import com.sun.hotspot.igv.view.widgets.FigureWidget; +import com.sun.hotspot.igv.view.widgets.InputSlotWidget; +import com.sun.hotspot.igv.view.widgets.OutputSlotWidget; +import com.sun.hotspot.igv.view.widgets.SlotWidget; +import com.sun.hotspot.igv.layout.LayoutGraph; +import com.sun.hotspot.igv.data.services.Scheduler; +import com.sun.hotspot.igv.data.ChangedListener; +import com.sun.hotspot.igv.graph.Block; +import com.sun.hotspot.igv.util.ColorIcon; +import com.sun.hotspot.igv.util.ExtendedSelectAction; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.awt.event.MouseWheelEvent; +import java.awt.event.MouseWheelListener; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.BorderFactory; +import javax.swing.JComponent; +import javax.swing.JPopupMenu; +import javax.swing.JScrollPane; +import javax.swing.SwingUtilities; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.event.UndoableEditEvent; +import javax.swing.undo.AbstractUndoableEdit; +import javax.swing.undo.CannotRedoException; +import javax.swing.undo.CannotUndoException; +import org.netbeans.api.visual.action.ActionFactory; +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.SelectProvider; +import org.netbeans.api.visual.action.WidgetAction; +import org.netbeans.api.visual.animator.SceneAnimator; +import org.netbeans.api.visual.layout.LayoutFactory; +import org.netbeans.api.visual.widget.ConnectionWidget; +import org.netbeans.api.visual.widget.LayerWidget; +import org.netbeans.api.visual.widget.Scene; +import org.netbeans.api.visual.widget.Widget; +import org.netbeans.api.visual.widget.LabelWidget; +import org.openide.awt.UndoRedo; +import org.openide.util.Lookup; +import org.openide.util.lookup.AbstractLookup; +import org.openide.util.lookup.InstanceContent; + +/** + * + * @author Thomas Wuerthinger + */ +public class DiagramScene extends Scene implements ChangedListener { + + private Hashtable figureWidgets; + private Hashtable slotWidgets; + private Hashtable connectionWidgets; + private Hashtable blockWidgets; + private Widget hoverWidget; + private WidgetAction hoverAction; + private List selectedWidgets; + private Lookup lookup; + private InstanceContent content; + private Action[] actions; + private LayerWidget connectionLayer; + private JScrollPane scrollPane; + private UndoRedo.Manager undoRedoManager; + private LayerWidget mainLayer; + private LayerWidget slotLayer; + private LayerWidget blockLayer; + private double realZoomFactor; + private BoundedZoomAction zoomAction; + private WidgetAction panAction; + private Widget topLeft; + private Widget bottomRight; + private LayerWidget startLayer; + private LabelWidget startLabel; + private DiagramViewModel model; + private DiagramViewModel modelCopy; + public static final int AFTER = 1; + public static final int BEFORE = 1; + public static final float ALPHA = 0.4f; + public static final int GRID_SIZE = 30; + 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() { + + public JPopupMenu getPopupMenu(Widget widget, Point localLocation) { + return DiagramScene.this.createPopupMenu(); + } + }; + private RectangularSelectDecorator rectangularSelectDecorator = new RectangularSelectDecorator() { + + public Widget createSelectionWidget() { + Widget widget = new Widget(DiagramScene.this); + widget.setBorder(BorderFactory.createLineBorder(Color.black, 2)); + widget.setForeground(Color.red); + return widget; + } + }; + private RectangularSelectProvider rectangularSelectProvider = new RectangularSelectProvider() { + + 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; + } + + boolean updated = false; + for (Figure f : getModel().getDiagramToView().getFigures()) { + FigureWidget w = figureWidgets.get(f); + Rectangle r = new Rectangle(w.getBounds()); + r.setLocation(w.getLocation()); + if (r.intersects(rectangle)) { + if (!selectedWidgets.contains(w)) { + addToSelection(w); + updated = true; + } + } else { + if (selectedWidgets.contains(w)) { + selectedWidgets.remove(w); + content.remove(w.getNode()); + w.setState(w.getState().deriveSelected(false)); + updated = true; + } + } + } + + if (updated) { + selectionUpdated(); + } + } + }; + private SelectProvider selectProvider = new SelectProvider() { + + public boolean isAimingAllowed(Widget widget, Point point, boolean b) { + return false; + } + + public boolean isSelectionAllowed(Widget widget, Point point, boolean b) { + return widget instanceof FigureWidget || widget == DiagramScene.this; + } + + public void select(Widget w, Point point, boolean change) { + + boolean updated = false; + + if (w == DiagramScene.this) { + if (DiagramScene.this.selectedWidgets.size() != 0) { + clearSelection(); + selectionUpdated(); + } + return; + } + + FigureWidget widget = (FigureWidget) w; + + + if (change) { + if (widget.getState().isSelected()) { + assert selectedWidgets.contains(widget); + widget.setState(widget.getState().deriveSelected(false)); + selectedWidgets.remove(widget); + content.remove(widget.getNode()); + updated = true; + } else { + assert !selectedWidgets.contains(widget); + addToSelection(widget); + updated = true; + assert widget.getState().isSelected(); + } + } else { + + if (widget.getState().isSelected()) { + assert selectedWidgets.contains(widget); + } else { + + assert !selectedWidgets.contains(widget); + clearSelection(); + addToSelection(widget); + updated = true; + assert widget.getState().isSelected(); + } + } + + if (updated) { + selectionUpdated(); + } + + } + }; + + private FigureWidget getFigureWidget(Figure f) { + return figureWidgets.get(f); + } + private FocusListener focusListener = new FocusListener() { + + public void focusGained(FocusEvent e) { + DiagramScene.this.getView().requestFocus(); + } + + public void focusLost(FocusEvent e) { + } + }; + private MouseWheelListener mouseWheelListener = new MouseWheelListener() { + + public void mouseWheelMoved(MouseWheelEvent e) { + DiagramScene.this.zoomAction.mouseWheelMoved(DiagramScene.this, new WidgetAction.WidgetMouseWheelEvent(0, e)); + DiagramScene.this.validate(); + } + }; + private MouseListener mouseListener = new MouseListener() { + + public void mouseClicked(MouseEvent e) { + DiagramScene.this.panAction.mouseClicked(DiagramScene.this, new WidgetAction.WidgetMouseEvent(0, e)); + } + + public void mousePressed(MouseEvent e) { + DiagramScene.this.panAction.mousePressed(DiagramScene.this, new WidgetAction.WidgetMouseEvent(0, e)); + } + + public void mouseReleased(MouseEvent e) { + DiagramScene.this.panAction.mouseReleased(DiagramScene.this, new WidgetAction.WidgetMouseEvent(0, e)); + } + + public void mouseEntered(MouseEvent e) { + DiagramScene.this.panAction.mouseEntered(DiagramScene.this, new WidgetAction.WidgetMouseEvent(0, e)); + } + + public void mouseExited(MouseEvent e) { + DiagramScene.this.panAction.mouseExited(DiagramScene.this, new WidgetAction.WidgetMouseEvent(0, e)); + } + }; + private MouseMotionListener mouseMotionListener = new MouseMotionListener() { + + public void mouseDragged(MouseEvent e) { + DiagramScene.this.panAction.mouseDragged(DiagramScene.this, new WidgetAction.WidgetMouseEvent(0, e)); + } + + public void mouseMoved(MouseEvent e) { + } + }; + private ScrollChangeListener scrollChangeListener = new ScrollChangeListener(); + + private class ScrollChangeListener implements ChangeListener { + + private Map relativePositions = new HashMap(); + private Point oldPosition; + + public void register(Widget w, Point p) { + relativePositions.put(w, p); + } + + public void unregister(Widget w) { + relativePositions.remove(w); + } + + public void stateChanged(ChangeEvent e) { + Point p = DiagramScene.this.getScrollPane().getViewport().getViewPosition(); + if (oldPosition == null || !p.equals(oldPosition)) { + for (Widget w : relativePositions.keySet()) { + Point curPoint = relativePositions.get(w); + Point newPoint = new Point(p.x + curPoint.x, p.y + curPoint.y); + w.setPreferredLocation(newPoint); + DiagramScene.this.validate(); + } + oldPosition = p; + } + } + } + + public Point getScrollPosition() { + return getScrollPane().getViewport().getViewPosition(); + } + + public void setScrollPosition(Point p) { + getScrollPane().getViewport().setViewPosition(p); + } + + public DiagramScene(Action[] actions, DiagramViewModel model) { + this.actions = actions; + selectedWidgets = new ArrayList(); + content = new InstanceContent(); + lookup = new AbstractLookup(content); + this.setCheckClipping(true); + this.getInputBindings().setZoomActionModifiers(0); + + JComponent comp = this.createView(); + comp.setDoubleBuffered(true); + comp.setBackground(Color.WHITE); + comp.setOpaque(true); + + this.setBackground(Color.WHITE); + this.setOpaque(true); + scrollPane = new JScrollPane(comp); + scrollPane.setBackground(Color.WHITE); + scrollPane.getVerticalScrollBar().setUnitIncrement(SCROLL_UNIT_INCREMENT); + scrollPane.getVerticalScrollBar().setBlockIncrement(SCROLL_BLOCK_INCREMENT); + scrollPane.getHorizontalScrollBar().setUnitIncrement(SCROLL_UNIT_INCREMENT); + scrollPane.getHorizontalScrollBar().setBlockIncrement(SCROLL_BLOCK_INCREMENT); + scrollPane.getViewport().addChangeListener(scrollChangeListener); + hoverAction = this.createWidgetHoverAction(); + + blockLayer = new LayerWidget(this); + this.addChild(blockLayer); + + startLayer = new LayerWidget(this); + this.addChild(startLayer); + // TODO: String startLabelString = "Loading graph with " + originalDiagram.getFigures().size() + " figures and " + originalDiagram.getConnections().size() + " connections..."; + String startLabelString = ""; + LabelWidget w = new LabelWidget(this, startLabelString); + scrollChangeListener.register(w, new Point(10, 10)); + w.setAlignment(LabelWidget.Alignment.CENTER); + startLabel = w; + startLayer.addChild(w); + + 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); + + slotLayer = new LayerWidget(this); + this.addChild(slotLayer); + + connectionLayer = new LayerWidget(this); + this.addChild(connectionLayer); + + LayerWidget selectionLayer = new LayerWidget(this); + this.addChild(selectionLayer); + + this.setLayout(LayoutFactory.createAbsoluteLayout()); + + this.getActions().addAction(hoverAction); + zoomAction = new BoundedZoomAction(1.1, false); + zoomAction.setMaxFactor(ZOOM_MAX_FACTOR); + zoomAction.setMinFactor(ZOOM_MIN_FACTOR); + this.getActions().addAction(ActionFactory.createMouseCenteredZoomAction(1.1)); + panAction = new ExtendedPanAction(); + this.getActions().addAction(panAction); + this.getActions().addAction(ActionFactory.createPopupMenuAction(popupMenuProvider)); + + LayerWidget selectLayer = new LayerWidget(this); + this.addChild(selectLayer); + this.getActions().addAction(ActionFactory.createRectangularSelectAction(rectangularSelectDecorator, selectLayer, rectangularSelectProvider)); + + blockWidgets = new Hashtable(); + + boolean b = this.getUndoRedoEnabled(); + this.setUndoRedoEnabled(false); + this.setNewModel(model); + this.setUndoRedoEnabled(b); + } + + private void selectionUpdated() { + getModel().setSelectedNodes(this.getSelectedNodes()); + addUndo(); + } + + public DiagramViewModel getModel() { + return model; + } + + public void setRealZoomFactor(double d) { + this.realZoomFactor = d; + } + + public double getRealZoomFactor() { + if (realZoomFactor == 0.0) { + return getZoomFactor(); + } else { + return realZoomFactor; + } + } + + public JScrollPane getScrollPane() { + return scrollPane; + } + + public boolean isAllVisible() { + return getModel().getHiddenNodes().size() == 0; + } + + public Action createGotoAction(final Figure f) { + final DiagramScene diagramScene = this; + Action a = new AbstractAction() { + + 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 (f.getCluster() != null) { + name += "B" + f.getCluster().toString(); + } + if (!this.getFigureWidget(f).isVisible()) { + if (f.getCluster() != null) { + name += ", "; + } + name += "hidden"; + } + name += ")"; + a.putValue(Action.NAME, name); + return a; + } + + public void setNewModel(DiagramViewModel model) { + if (this.model != null) { + this.model.getDiagramChangedEvent().removeListener(this); + this.model.getViewPropertiesChangedEvent().removeListener(this); + } + this.model = model; + + if (this.model == null) { + this.modelCopy = null; + } else { + this.modelCopy = this.model.copy(); + } + + model.getDiagramChangedEvent().addListener(this); + model.getViewPropertiesChangedEvent().addListener(this); + + update(); + } + + private void update() { + + /*if (startLabel != null) { + // Animate fade-out + final LabelWidget labelWidget = this.startLabel; + labelWidget.setVisible(true); + RequestProcessor.getDefault().post(new Runnable() { + public void run() { + final int Sleep = 200; + final int Progress = 10; + for (int i = 0; i < 255 / Progress + 1; i++) { + try { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + Color c = labelWidget.getForeground(); + int v = c.getRed(); + v += Progress; + if (v > 255) { + v = 255; + } + labelWidget.setForeground(new Color(v, v, v, 255 - v)); + labelWidget.getScene().validate(); + } + }); + } catch (InterruptedException ex) { + } catch (InvocationTargetException ex) { + } + try { + Thread.sleep(Sleep); + } catch (InterruptedException ex) { + } + } + labelWidget.setVisible(false); + DiagramScene.this.scrollChangeListener.unregister(labelWidget); + } + }, 1000); + startLabel = null; + }*/ + + slotLayer.removeChildren(); + mainLayer.removeChildren(); + blockLayer.removeChildren(); + + blockWidgets.clear(); + figureWidgets = new Hashtable(); + slotWidgets = new Hashtable(); + connectionWidgets = new Hashtable(); + + WidgetAction selectAction = new ExtendedSelectAction(selectProvider); + Diagram d = getModel().getDiagramToView(); + + if (getModel().getShowBlocks()) { + Scheduler s = Lookup.getDefault().lookup(Scheduler.class); + Collection newBlocks = new ArrayList(s.schedule(d.getGraph())); + d.schedule(newBlocks); + } + + for (Figure f : d.getFigures()) { + FigureWidget w = new FigureWidget(f, this, mainLayer); + w.getActions().addAction(selectAction); + w.getActions().addAction(hoverAction); + w.getActions().addAction(ActionFactory.createPopupMenuAction(w)); + w.getActions().addAction(new DoubleClickAction(w)); + w.setVisible(false); + + figureWidgets.put(f, w); + + for (InputSlot s : f.getInputSlots()) { + SlotWidget sw = new InputSlotWidget(s, this, slotLayer, w); + slotWidgets.put(s, sw); + sw.getActions().addAction(selectAction); + } + + for (OutputSlot s : f.getOutputSlots()) { + SlotWidget sw = new OutputSlotWidget(s, this, slotLayer, w); + slotWidgets.put(s, sw); + sw.getActions().addAction(selectAction); + } + } + + if (getModel().getShowBlocks()) { + for (InputBlock bn : d.getGraph().getBlocks()) { + BlockWidget w = new BlockWidget(this, d, bn); + w.setVisible(false); + blockWidgets.put(bn, w); + blockLayer.addChild(w); + } + } + + this.smallUpdate(true); + + } + + private void smallUpdate(boolean relayout) { + + this.updateHiddenNodes(model.getHiddenNodes(), relayout); + boolean b = this.getUndoRedoEnabled(); + this.setUndoRedoEnabled(false); + this.setSelection(getModel().getSelectedNodes()); + this.setUndoRedoEnabled(b); + this.validate(); + } + + private boolean isVisible(Connection c) { + FigureWidget w1 = figureWidgets.get(c.getInputSlot().getFigure()); + FigureWidget w2 = figureWidgets.get(c.getOutputSlot().getFigure()); + + if (w1.isVisible() && w2.isVisible()) { + return true; + } + + return false; + } + + private void relayout(Set oldVisibleWidgets) { + + Diagram diagram = getModel().getDiagramToView(); + + HashSet
figures = new HashSet
(); + + for (Figure f : diagram.getFigures()) { + FigureWidget w = figureWidgets.get(f); + if (w.isVisible()) { + figures.add(f); + } + } + + HashSet edges = new HashSet(); + + for (Connection c : diagram.getConnections()) { + if (isVisible(c)) { + edges.add(c); + } + } + + if (getModel().getShowBlocks()) { + HierarchicalClusterLayoutManager m = new HierarchicalClusterLayoutManager(OldHierarchicalLayoutManager.Combine.SAME_OUTPUTS); + HierarchicalLayoutManager manager = new HierarchicalLayoutManager(HierarchicalLayoutManager.Combine.SAME_OUTPUTS); + manager.setMaxLayerLength(9); + manager.setMinLayerDifference(3); + m.setManager(manager); + m.setSubManager(new HierarchicalLayoutManager(HierarchicalLayoutManager.Combine.SAME_OUTPUTS)); + m.doLayout(new LayoutGraph(edges, figures)); + + } else { + HierarchicalLayoutManager manager = new HierarchicalLayoutManager(HierarchicalLayoutManager.Combine.SAME_OUTPUTS); + manager.setMaxLayerLength(10); + manager.doLayout(new LayoutGraph(edges, figures)); + } + + int maxX = -BORDER_SIZE; + int maxY = -BORDER_SIZE; + for (Figure f : diagram.getFigures()) { + FigureWidget w = figureWidgets.get(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 = figureWidgets.get((Figure) c.getTo().getVertex()); + FigureWidget w2 = figureWidgets.get((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); + } + } + } + } + + if (getModel().getShowBlocks()) { + for (Block b : diagram.getBlocks()) { + BlockWidget w = blockWidgets.get(b.getInputBlock()); + if (w != null && w.isVisible()) { + Rectangle r = b.getBounds(); + maxX = Math.max(maxX, r.x + r.width); + maxY = Math.max(maxY, r.y + r.height); + } + } + } + + 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(); + 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 (figureWidgets.get(f).isVisible()) { + visibleFigureCount++; + } + } + + for (Figure f : diagram.getFigures()) { + for (OutputSlot s : f.getOutputSlots()) { + SceneAnimator anim = animator; + if (visibleFigureCount > ANIMATION_LIMIT) { + anim = null; + } + processOutputSlot(s, s.getConnections(), 0, null, null, offx2, offy2, anim); + } + } + + for (Figure f : diagram.getFigures()) { + FigureWidget w = figureWidgets.get(f); + if (w.isVisible()) { + Point p = f.getPosition(); + Point p2 = new Point(p.x + offx2, p.y + offy2); + Rectangle r = new Rectangle(p.x + offx2, p.y + offy2, f.getSize().width, f.getSize().height); + if (oldVisibleWidgets.contains(w)) { + if (visibleFigureCount > ANIMATION_LIMIT) { + w.setPreferredLocation(p2); + } else { + animator.animatePreferredLocation(w, p2); + } + } else { + w.setPreferredLocation(p2); + } + } + } + + if (getModel().getShowBlocks()) { + for (Block b : diagram.getBlocks()) { + BlockWidget w = blockWidgets.get(b.getInputBlock()); + if (w != null && w.isVisible()) { + Point location = new Point(b.getBounds().x + offx2, b.getBounds().y + offy2); + Rectangle r = new Rectangle(location.x, location.y, b.getBounds().width, b.getBounds().height); + if (oldVisibleWidgets.contains(w)) { + if (visibleFigureCount > ANIMATION_LIMIT) { + w.setPreferredBounds(r); + } else { + animator.animatePreferredBounds(w, r); + } + } else { + w.setPreferredBounds(r); + } + } + } + } + } + private final Point specialNullPoint = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE); + + private void processOutputSlot(OutputSlot s, List connections, int controlPointIndex, Point lastPoint, LineWidget predecessor, int offx, int offy, SceneAnimator animator) { + Map> pointMap = new HashMap>(); + + 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.getShowName()) { + cur = new Point(cur.x, cur.y - SLOT_OFFSET); + } else if (controlPointIndex == controlPoints.size() - 1 && !c.getInputSlot().getShowName()) { + 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); + LineWidget w = new LineWidget(this, s, connectionList, p1, p2, predecessor, animator, isBold, isDashed); + newPredecessor = w; + connectionLayer.addChild(w); + w.getActions().addAction(hoverAction); + } + + processOutputSlot(s, connectionList, controlPointIndex + 1, p, newPredecessor, offx, offy, animator); + } + } + + private void clearSelection() { + if (selectedWidgets.size() == 0) { + return; + } + for (FigureWidget w : selectedWidgets) { + assert w.getState().isSelected(); + w.setState(w.getState().deriveSelected(false)); + content.remove(w.getNode()); + } + selectedWidgets.clear(); + } + + public Lookup getLookup() { + return lookup; + } + + public void gotoFigures(final List
figures) { + Rectangle overall = null; + showFigures(figures); + for (Figure f : figures) { + + FigureWidget fw = getFigureWidget(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 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)); + } + } + + private void addToSelection(Figure f) { + FigureWidget w = getFigureWidget(f); + addToSelection(w); + } + + private void addToSelection(FigureWidget w) { + assert !selectedWidgets.contains(w); + selectedWidgets.add(w); + content.add(w.getNode()); + w.setState(w.getState().deriveSelected(true)); + } + + private void setSelection(Set nodes) { + clearSelection(); + for (Figure f : getModel().getDiagramToView().getFigures()) { + if (doesIntersect(f.getSource().getSourceNodesAsSet(), nodes)) { + addToSelection(f); + } + } + selectionUpdated(); + this.validate(); + } + + public void setSelection(Collection
list) { + clearSelection(); + for (Figure f : list) { + addToSelection(f); + } + + selectionUpdated(); + this.validate(); + } + + public Set
getSelectedFigures() { + Set
result = new HashSet
(); + for (Widget w : selectedWidgets) { + if (w instanceof FigureWidget) { + FigureWidget fw = (FigureWidget) w; + if (fw.getState().isSelected()) { + result.add(fw.getFigure()); + } + } + } + return result; + } + + public Set getSelectedNodes() { + Set result = new HashSet(); + for (Widget w : selectedWidgets) { + if (w instanceof FigureWidget) { + FigureWidget fw = (FigureWidget) w; + if (fw.getState().isSelected()) { + result.addAll(fw.getFigure().getSource().getSourceNodesAsSet()); + } + } + } + return result; + } + + private UndoRedo.Manager getUndoRedoManager() { + if (undoRedoManager == null) { + undoRedoManager = new UndoRedo.Manager(); + undoRedoManager.setLimit(UNDOREDO_LIMIT); + } + + return undoRedoManager; + } + + public UndoRedo getUndoRedo() { + return getUndoRedoManager(); + } + + private boolean isVisible(Figure f) { + for (Integer n : f.getSource().getSourceNodesAsSet()) { + if (getModel().getHiddenNodes().contains(n)) { + return false; + } + } + return true; + } + + private 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; + } + + public void showNot(final Set nodes) { + updateHiddenNodes(nodes, true); + } + + public void showOnly(final Set nodes) { + HashSet allNodes = new HashSet(getModel().getGraphToView().getGroup().getAllNodes()); + allNodes.removeAll(nodes); + updateHiddenNodes(allNodes, true); + } + + private void updateHiddenNodes(Set newHiddenNodes, boolean doRelayout) { + + Set visibleBlocks = new HashSet(); + + Diagram diagram = getModel().getDiagramToView(); + assert diagram != null; + + Set oldVisibleWidgets = new HashSet(); + + for (Figure f : diagram.getFigures()) { + FigureWidget w = figureWidgets.get(f); + if (w.isVisible()) { + oldVisibleWidgets.add(w); + } + } + + if (getModel().getShowBlocks()) { + for (InputBlock b : diagram.getGraph().getBlocks()) { + BlockWidget w = blockWidgets.get(b); + if (w.isVisible()) { + oldVisibleWidgets.add(w); + } + } + } + + for (Figure f : diagram.getFigures()) { + boolean hiddenAfter = doesIntersect(f.getSource().getSourceNodesAsSet(), newHiddenNodes); + + FigureWidget w = this.figureWidgets.get(f); + w.setBoundary(false); + if (!hiddenAfter) { + // Figure is shown + w.setVisible(true); + for (InputNode n : f.getSource().getSourceNodes()) { + visibleBlocks.add(diagram.getGraph().getBlock(n)); + } + } else { + // Figure is hidden + w.setVisible(false); + } + } + + if (getModel().getShowNodeHull()) { + List boundaries = new ArrayList(); + for (Figure f : diagram.getFigures()) { + FigureWidget w = this.figureWidgets.get(f); + if (!w.isVisible()) { + Set
set = new HashSet
(f.getPredecessorSet()); + set.addAll(f.getSuccessorSet()); + + boolean b = false; + for (Figure neighbor : set) { + FigureWidget neighborWidget = figureWidgets.get(neighbor); + if (neighborWidget.isVisible()) { + b = true; + break; + } + } + + if (b) { + w.setBoundary(true); + for (InputNode n : f.getSource().getSourceNodes()) { + visibleBlocks.add(diagram.getGraph().getBlock(n)); + } + boundaries.add(w); + } + } + } + + for (FigureWidget w : boundaries) { + if (w.isBoundary()) { + w.setVisible(true); + } + } + } + + if (getModel().getShowBlocks()) { + for (InputBlock b : diagram.getGraph().getBlocks()) { + + boolean visibleAfter = visibleBlocks.contains(b); + + BlockWidget w = blockWidgets.get(b); + if (visibleAfter) { + // Block must be shown + w.setVisible(true); + } else { + // Block must be hidden + w.setVisible(false); + } + } + } + + getModel().setHiddenNodes(newHiddenNodes); + if (doRelayout) { + relayout(oldVisibleWidgets); + } + this.validate(); + addUndo(); + } + + private void showFigures(Collection
f) { + HashSet newHiddenNodes = new HashSet(getModel().getHiddenNodes()); + for (Figure fig : f) { + newHiddenNodes.removeAll(fig.getSource().getSourceNodesAsSet()); + } + updateHiddenNodes(newHiddenNodes, true); + } + + private void showFigure(Figure f) { + HashSet newHiddenNodes = new HashSet(getModel().getHiddenNodes()); + newHiddenNodes.removeAll(f.getSource().getSourceNodesAsSet()); + updateHiddenNodes(newHiddenNodes, true); + } + + public void showAll(final Collection
f) { + showFigures(f); + + } + + public void show(final Figure f) { + showFigure(f); + } + + public void gotoFigure(final Figure f) { + + if (!isVisible(f)) { + showFigure(f); + } + + FigureWidget fw = getFigureWidget(f); + if (fw != null) { + Rectangle r = fw.getBounds(); + Point p = fw.getLocation(); + centerRectangle(new Rectangle(p.x, p.y, r.width, r.height)); + + // Select figure + clearSelection(); + addToSelection(fw); + selectionUpdated(); + } + } + + public JPopupMenu createPopupMenu() { + JPopupMenu menu = new JPopupMenu(); + for (Action a : actions) { + if (a == null) { + menu.addSeparator(); + } else { + menu.add(a); + } + } + return menu; + } + + private static class DiagramUndoRedo extends AbstractUndoableEdit implements ChangedListener { + + private DiagramViewModel oldModel; + private DiagramViewModel newModel; + private Point oldScrollPosition; + private DiagramScene scene; + + public DiagramUndoRedo(DiagramScene scene, Point oldScrollPosition, DiagramViewModel oldModel, DiagramViewModel newModel) { + assert oldModel != null; + assert newModel != null; + this.oldModel = oldModel; + this.newModel = newModel; + this.scene = scene; + this.oldScrollPosition = oldScrollPosition; + } + + @Override + public void redo() throws CannotRedoException { + super.redo(); + boolean b = scene.getUndoRedoEnabled(); + scene.setUndoRedoEnabled(false); + scene.getModel().getViewChangedEvent().addListener(this); + scene.getModel().setData(newModel); + scene.getModel().getViewChangedEvent().removeListener(this); + scene.setUndoRedoEnabled(b); + } + + @Override + public void undo() throws CannotUndoException { + super.undo(); + boolean b = scene.getUndoRedoEnabled(); + scene.setUndoRedoEnabled(false); + scene.getModel().getViewChangedEvent().addListener(this); + scene.getModel().setData(oldModel); + scene.getModel().getViewChangedEvent().removeListener(this); + + SwingUtilities.invokeLater(new Runnable() { + + public void run() { + scene.setScrollPosition(oldScrollPosition); + } + }); + + scene.setUndoRedoEnabled(b); + } + + public void changed(DiagramViewModel source) { + scene.getModel().getViewChangedEvent().removeListener(this); + if (oldModel.getSelectedNodes().equals(newModel.getHiddenNodes())) { + scene.smallUpdate(false); + } else { + scene.smallUpdate(true); + } + } + } + private boolean undoRedoEnabled = true; + + public void setUndoRedoEnabled(boolean b) { + this.undoRedoEnabled = b; + } + + public boolean getUndoRedoEnabled() { + return undoRedoEnabled; + } + + public void changed(DiagramViewModel source) { + assert source == model : "Receive only changed event from current model!"; + assert source != null; + update(); + } + + private void addUndo() { + + DiagramViewModel newModelCopy = model.copy(); + + if (undoRedoEnabled) { + this.getUndoRedoManager().undoableEditHappened(new UndoableEditEvent(this, new DiagramUndoRedo(this, this.getScrollPosition(), modelCopy, newModelCopy))); + } + + this.modelCopy = newModelCopy; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/DiagramViewModel.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/DiagramViewModel.java new file mode 100644 index 0000000000000000000000000000000000000000..e374873b584eab26ef72ff2d5bf6ffac15afd4d3 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/DiagramViewModel.java @@ -0,0 +1,303 @@ +/* + * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ +package com.sun.hotspot.igv.view; + +import com.sun.hotspot.igv.data.Group; +import com.sun.hotspot.igv.data.InputGraph; +import com.sun.hotspot.igv.data.InputNode; +import com.sun.hotspot.igv.difference.Difference; +import com.sun.hotspot.igv.filter.FilterChain; +import com.sun.hotspot.igv.graph.Diagram; +import com.sun.hotspot.igv.data.ChangedEvent; +import com.sun.hotspot.igv.util.RangeSliderModel; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import com.sun.hotspot.igv.data.ChangedListener; +import com.sun.hotspot.igv.settings.Settings; +import java.awt.Color; + +/** + * + * @author Thomas Wuerthinger + */ +public class DiagramViewModel extends RangeSliderModel implements ChangedListener { + + // Warning: Update setData method if fields are added + private Group group; + private Set hiddenNodes; + private Set onScreenNodes; + private Set selectedNodes; + private FilterChain filterChain; + private FilterChain sequenceFilterChain; + private Diagram diagram; + private ChangedEvent diagramChangedEvent; + private ChangedEvent viewChangedEvent; + private ChangedEvent viewPropertiesChangedEvent; + private boolean showBlocks; + private boolean showNodeHull; + private ChangedListener filterChainChangedListener = new ChangedListener() { + + public void changed(FilterChain source) { + diagramChanged(); + } + }; + + public DiagramViewModel copy() { + DiagramViewModel result = new DiagramViewModel(group, filterChain, sequenceFilterChain); + result.setData(this); + return result; + } + + public void setData(DiagramViewModel newModel) { + super.setData(newModel); + boolean diagramChanged = false; + boolean viewChanged = false; + boolean viewPropertiesChanged = false; + + this.group = newModel.group; + diagramChanged |= (filterChain != newModel.filterChain); + this.filterChain = newModel.filterChain; + diagramChanged |= (sequenceFilterChain != newModel.sequenceFilterChain); + this.sequenceFilterChain = newModel.sequenceFilterChain; + diagramChanged |= (diagram != newModel.diagram); + this.diagram = newModel.diagram; + viewChanged |= (hiddenNodes != newModel.hiddenNodes); + this.hiddenNodes = newModel.hiddenNodes; + viewChanged |= (onScreenNodes != newModel.onScreenNodes); + this.onScreenNodes = newModel.onScreenNodes; + viewChanged |= (selectedNodes != newModel.selectedNodes); + this.selectedNodes = newModel.selectedNodes; + viewPropertiesChanged |= (showBlocks != newModel.showBlocks); + this.showBlocks = newModel.showBlocks; + viewPropertiesChanged |= (showNodeHull != newModel.showNodeHull); + this.showNodeHull = newModel.showNodeHull; + + if (diagramChanged) { + diagramChangedEvent.fire(); + } + if (viewPropertiesChanged) { + viewPropertiesChangedEvent.fire(); + } + if (viewChanged) { + viewChangedEvent.fire(); + } + } + + public boolean getShowBlocks() { + return showBlocks; + } + + public void setShowBlocks(boolean b) { + showBlocks = b; + viewPropertiesChangedEvent.fire(); + } + + public boolean getShowNodeHull() { + return showNodeHull; + } + + public void setShowNodeHull(boolean b) { + showNodeHull = b; + viewPropertiesChangedEvent.fire(); + } + + public DiagramViewModel(Group g, FilterChain filterChain, FilterChain sequenceFilterChain) { + super(calculateStringList(g)); + + this.showNodeHull = true; + this.showBlocks = true; + this.group = g; + assert filterChain != null; + this.filterChain = filterChain; + assert sequenceFilterChain != null; + this.sequenceFilterChain = sequenceFilterChain; + hiddenNodes = new HashSet(); + onScreenNodes = new HashSet(); + selectedNodes = new HashSet(); + super.getChangedEvent().addListener(this); + diagramChangedEvent = new ChangedEvent(this); + viewChangedEvent = new ChangedEvent(this); + viewPropertiesChangedEvent = new ChangedEvent(this); + + filterChain.getChangedEvent().addListener(filterChainChangedListener); + sequenceFilterChain.getChangedEvent().addListener(filterChainChangedListener); + } + + public ChangedEvent getDiagramChangedEvent() { + return diagramChangedEvent; + } + + public ChangedEvent getViewChangedEvent() { + return viewChangedEvent; + } + + public ChangedEvent getViewPropertiesChangedEvent() { + return viewPropertiesChangedEvent; + } + + public Set getSelectedNodes() { + return Collections.unmodifiableSet(selectedNodes); + } + + public Set getHiddenNodes() { + return Collections.unmodifiableSet(hiddenNodes); + } + + public Set getOnScreenNodes() { + return Collections.unmodifiableSet(onScreenNodes); + } + + public void setSelectedNodes(Set nodes) { + this.selectedNodes = nodes; + List colors = new ArrayList(); + for (String s : getPositions()) { + colors.add(Color.black); + } + if (nodes.size() >= 1) { + for (Integer id : nodes) { + if (id < 0) { + id = -id; + } + InputNode last = null; + int index = 0; + for (InputGraph g : group.getGraphs()) { + Color curColor = colors.get(index); + InputNode cur = g.getNode(id); + if (cur != null) { + if (last == null) { + curColor = Color.green; + } else { + if (last.equals(cur)) { + if (curColor == Color.black) { + curColor = Color.white; + } + } else { + if (curColor != Color.green) { + curColor = Color.orange; + } + } + } + } + last = cur; + colors.set(index, curColor); + index++; + } + } + this.setColors(colors); + } + setColors(colors); + viewChangedEvent.fire(); + } + + public void setHiddenNodes(Set nodes) { + this.hiddenNodes = nodes; + viewChangedEvent.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 group.getGraphs().get(getFirstPosition()); + } + + public InputGraph getSecondGraph() { + return group.getGraphs().get(getSecondPosition()); + } + + public void selectGraph(InputGraph g) { + int index = group.getGraphs().indexOf(g); + assert index != -1; + setPositions(index, index); + } + + public Diagram getDiagramToView() { + + if (diagram == null) { + diagram = Diagram.createDiagram(getGraphToView(), Settings.get().get(Settings.NODE_TEXT, Settings.NODE_TEXT_DEFAULT)); + getFilterChain().apply(diagram, getSequenceFilterChain()); + } + + return diagram; + } + + public InputGraph getGraphToView() { + if (getFirstGraph() != getSecondGraph()) { + InputGraph inputGraph = Difference.createDiffGraph(getSecondGraph(), getFirstGraph()); + return inputGraph; + } else { + InputGraph inputGraph = getFirstGraph(); + return inputGraph; + } + } + + public void changed(RangeSliderModel source) { + diagramChanged(); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorInputGraphProvider.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorInputGraphProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..f1c3f042985ab0df6628f1a155aefc06cc19d5c5 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorInputGraphProvider.java @@ -0,0 +1,52 @@ +/* + * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ +package com.sun.hotspot.igv.view; + +import com.sun.hotspot.igv.data.InputGraph; +import com.sun.hotspot.igv.data.services.InputGraphProvider; +import com.sun.hotspot.igv.data.InputNode; +import java.util.Set; + +/** + * + * @author Thomas Wuerthinger + */ +public class EditorInputGraphProvider implements InputGraphProvider { + + public InputGraph getGraph() { + EditorTopComponent e = EditorTopComponent.getActive(); + if (e == null) { + return null; + } + return e.getDiagramModel().getGraphToView(); + } + + public void setSelectedNodes(Set nodes) { + EditorTopComponent e = EditorTopComponent.getActive(); + if (e != null) { + e.setSelectedNodes(nodes); + } + } +} diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorTopComponent.form b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorTopComponent.form new file mode 100644 index 0000000000000000000000000000000000000000..dc990facd9c5c7827f2ec068835d7511746913c7 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorTopComponent.form @@ -0,0 +1,31 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorTopComponent.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorTopComponent.java new file mode 100644 index 0000000000000000000000000000000000000000..e923544eda1bef79ceac70715150472b080d28c1 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorTopComponent.java @@ -0,0 +1,577 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.view; + +import com.sun.hotspot.igv.data.InputNode; +import com.sun.hotspot.igv.filter.FilterChain; +import com.sun.hotspot.igv.graph.Diagram; +import com.sun.hotspot.igv.graph.Figure; +import com.sun.hotspot.igv.view.actions.EnableBlockLayoutAction; +import com.sun.hotspot.igv.view.actions.ExpandPredecessorsAction; +import com.sun.hotspot.igv.view.actions.ExpandSuccessorsAction; +import com.sun.hotspot.igv.view.actions.ExtractAction; +import com.sun.hotspot.igv.view.actions.HideAction; +import com.sun.hotspot.igv.view.actions.NextDiagramAction; +import com.sun.hotspot.igv.view.actions.NodeFindAction; +import com.sun.hotspot.igv.view.actions.OverviewAction; +import com.sun.hotspot.igv.view.actions.PredSuccAction; +import com.sun.hotspot.igv.view.actions.PrevDiagramAction; +import com.sun.hotspot.igv.view.actions.ShowAllAction; +import com.sun.hotspot.igv.view.actions.ZoomInAction; +import com.sun.hotspot.igv.view.actions.ZoomOutAction; +import com.sun.hotspot.igv.data.ChangedListener; +import com.sun.hotspot.igv.data.Properties; +import com.sun.hotspot.igv.data.Properties.PropertyMatcher; +import com.sun.hotspot.igv.filter.FilterChainProvider; +import com.sun.hotspot.igv.util.RangeSlider; +import com.sun.hotspot.igv.util.RangeSliderModel; +import com.sun.hotspot.igv.svg.BatikSVG; +import java.awt.BorderLayout; +import java.awt.CardLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.event.HierarchyBoundsListener; +import java.awt.event.HierarchyEvent; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; +import java.io.Writer; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import javax.swing.Action; +import javax.swing.ActionMap; +import javax.swing.JPanel; +import javax.swing.JToggleButton; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; +import javax.swing.border.Border; +import org.openide.DialogDisplayer; +import org.openide.actions.FindAction; +import org.openide.actions.RedoAction; +import org.openide.actions.UndoAction; +import org.openide.awt.Toolbar; +import org.openide.awt.ToolbarPool; +import org.openide.awt.UndoRedo; +import org.openide.util.Lookup; +import org.openide.util.NbBundle; +import org.openide.util.actions.CallbackSystemAction; +import org.openide.util.actions.SystemAction; +import org.openide.util.lookup.AbstractLookup; +import org.openide.util.lookup.InstanceContent; +import org.openide.util.lookup.ProxyLookup; +import org.openide.windows.Mode; +import org.openide.windows.TopComponent; +import org.openide.windows.WindowManager; +import org.openide.NotifyDescriptor; + +/** + * + * @author Thomas Wuerthinger + */ +public final class EditorTopComponent extends TopComponent implements ChangedListener, PropertyChangeListener { + + private DiagramScene scene; + private InstanceContent content; + private FindPanel findPanel; + private EnableBlockLayoutAction blockLayoutAction; + private OverviewAction overviewAction; + private PredSuccAction predSuccAction; + private boolean notFirstTime; + private ExtendedSatelliteComponent satelliteComponent; + private JPanel centerPanel; + private CardLayout cardLayout; + private RangeSlider rangeSlider; + private JToggleButton overviewButton; + private static final String PREFERRED_ID = "EditorTopComponent"; + private static final String SATELLITE_STRING = "satellite"; + private static final String SCENE_STRING = "scene"; + private DiagramViewModel rangeSliderModel; + private ExportCookie exportCookie = new ExportCookie() { + + public void export(File f) { + + Graphics2D svgGenerator = BatikSVG.createGraphicsObject(); + + if (svgGenerator == null) { + NotifyDescriptor message = new NotifyDescriptor.Message("For export to SVG files the Batik SVG Toolkit must be intalled.", NotifyDescriptor.ERROR_MESSAGE); + DialogDisplayer.getDefault().notifyLater(message); + } else { + scene.paint(svgGenerator); + FileOutputStream os = null; + try { + os = new FileOutputStream(f); + Writer out = new OutputStreamWriter(os, "UTF-8"); + BatikSVG.printToStream(svgGenerator, out, true); + } catch (FileNotFoundException e) { + NotifyDescriptor message = new NotifyDescriptor.Message("For export to SVG files the Batik SVG Toolkit must be intalled.", NotifyDescriptor.ERROR_MESSAGE); + DialogDisplayer.getDefault().notifyLater(message); + + } catch (UnsupportedEncodingException e) { + } finally { + if (os != null) { + try { + os.close(); + } catch (IOException e) { + } + } + } + + } + } + }; + + private void updateDisplayName() { + setDisplayName(getDiagram().getName()); + } + + public EditorTopComponent(Diagram diagram) { + + FilterChain filterChain = null; + FilterChain sequence = null; + FilterChainProvider provider = Lookup.getDefault().lookup(FilterChainProvider.class); + if (provider == null) { + filterChain = new FilterChain(); + sequence = new FilterChain(); + } else { + filterChain = provider.getFilterChain(); + sequence = provider.getSequence(); + } + + setName(NbBundle.getMessage(EditorTopComponent.class, "CTL_EditorTopComponent")); + setToolTipText(NbBundle.getMessage(EditorTopComponent.class, "HINT_EditorTopComponent")); + + Action[] actions = new Action[]{ + PrevDiagramAction.get(PrevDiagramAction.class), + NextDiagramAction.get(NextDiagramAction.class), + null, + ExtractAction.get(ExtractAction.class), + ShowAllAction.get(HideAction.class), + ShowAllAction.get(ShowAllAction.class), + null, + ZoomInAction.get(ZoomInAction.class), + ZoomOutAction.get(ZoomOutAction.class), + null, + ExpandPredecessorsAction.get(ExpandPredecessorsAction.class), + ExpandSuccessorsAction.get(ExpandSuccessorsAction.class) + }; + + + initComponents(); + + ActionMap actionMap = getActionMap(); + + ToolbarPool.getDefault().setPreferredIconSize(16); + Toolbar toolBar = new Toolbar(); + Border b = (Border) UIManager.get("Nb.Editor.Toolbar.border"); //NOI18N + toolBar.setBorder(b); + JPanel container = new JPanel(); + this.add(container, BorderLayout.NORTH); + container.setLayout(new BorderLayout()); + container.add(BorderLayout.NORTH, toolBar); + + rangeSliderModel = new DiagramViewModel(diagram.getGraph().getGroup(), filterChain, sequence); + rangeSliderModel.selectGraph(diagram.getGraph()); + rangeSlider = new RangeSlider(); + rangeSlider.setModel(rangeSliderModel); + rangeSliderModel.getChangedEvent().addListener(this); + container.add(BorderLayout.CENTER, rangeSlider); + + scene = new DiagramScene(actions, rangeSliderModel); + content = new InstanceContent(); + this.associateLookup(new ProxyLookup(new Lookup[]{scene.getLookup(), new AbstractLookup(content)})); + content.add(exportCookie); + content.add(rangeSliderModel); + + + findPanel = new FindPanel(diagram.getFigures()); + findPanel.setMaximumSize(new Dimension(200, 50)); + toolBar.add(findPanel); + toolBar.add(NodeFindAction.get(NodeFindAction.class)); + toolBar.addSeparator(); + toolBar.add(NextDiagramAction.get(NextDiagramAction.class)); + toolBar.add(PrevDiagramAction.get(PrevDiagramAction.class)); + toolBar.addSeparator(); + toolBar.add(ExtractAction.get(ExtractAction.class)); + toolBar.add(ShowAllAction.get(HideAction.class)); + toolBar.add(ShowAllAction.get(ShowAllAction.class)); + toolBar.addSeparator(); + toolBar.add(ShowAllAction.get(ZoomInAction.class)); + toolBar.add(ShowAllAction.get(ZoomOutAction.class)); + + blockLayoutAction = new EnableBlockLayoutAction(); + JToggleButton button = new JToggleButton(blockLayoutAction); + button.setSelected(true); + toolBar.add(button); + blockLayoutAction.addPropertyChangeListener(this); + + overviewAction = new OverviewAction(); + overviewButton = new JToggleButton(overviewAction); + overviewButton.setSelected(false); + toolBar.add(overviewButton); + overviewAction.addPropertyChangeListener(this); + + predSuccAction = new PredSuccAction(); + button = new JToggleButton(predSuccAction); + button.setSelected(true); + toolBar.add(button); + predSuccAction.addPropertyChangeListener(this); + + toolBar.addSeparator(); + toolBar.add(UndoAction.get(UndoAction.class)); + toolBar.add(RedoAction.get(RedoAction.class)); + + centerPanel = new JPanel(); + this.add(centerPanel, BorderLayout.CENTER); + cardLayout = new CardLayout(); + centerPanel.setLayout(cardLayout); + centerPanel.add(SCENE_STRING, scene.getScrollPane()); + centerPanel.setBackground(Color.WHITE); + satelliteComponent = new ExtendedSatelliteComponent(scene); + satelliteComponent.setSize(200, 200); + centerPanel.add(SATELLITE_STRING, satelliteComponent); + + CallbackSystemAction callFindAction = (CallbackSystemAction) SystemAction.get(FindAction.class); + NodeFindAction findAction = NodeFindAction.get(NodeFindAction.class); + Object key = callFindAction.getActionMapKey(); + actionMap.put(key, findAction); + + scene.getScrollPane().addKeyListener(keyListener); + scene.getView().addKeyListener(keyListener); + satelliteComponent.addKeyListener(keyListener); + + scene.getScrollPane().addHierarchyBoundsListener(new HierarchyBoundsListener() { + + public void ancestorMoved(HierarchyEvent e) { + } + + public void ancestorResized(HierarchyEvent e) { + if (!notFirstTime && scene.getScrollPane().getBounds().width > 0) { + notFirstTime = true; + SwingUtilities.invokeLater(new Runnable() { + + public void run() { + Figure f = EditorTopComponent.this.scene.getModel().getDiagramToView().getRootFigure(); + if (f != null) { + scene.setUndoRedoEnabled(false); + scene.gotoFigure(f); + scene.setUndoRedoEnabled(true); + } + } + }); + } + } + }); + + updateDisplayName(); + } + private KeyListener keyListener = new KeyListener() { + + public void keyTyped(KeyEvent e) { + } + + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_S) { + EditorTopComponent.this.overviewButton.setSelected(true); + EditorTopComponent.this.overviewAction.setState(true); + } + } + + public void keyReleased(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_S) { + EditorTopComponent.this.overviewButton.setSelected(false); + EditorTopComponent.this.overviewAction.setState(false); + } + } + }; + + public DiagramViewModel getDiagramModel() { + return scene.getModel(); + } + + private void showSatellite() { + cardLayout.show(centerPanel, SATELLITE_STRING); + satelliteComponent.requestFocus(); + + } + + private void showScene() { + cardLayout.show(centerPanel, SCENE_STRING); + scene.getView().requestFocus(); + } + + public void findNode() { + findPanel.find(); + } + + public void zoomOut() { + double zoom = scene.getZoomFactor(); + Point viewPosition = scene.getScrollPane().getViewport().getViewPosition(); + double newZoom = zoom / DiagramScene.ZOOM_INCREMENT; + if (newZoom > DiagramScene.ZOOM_MIN_FACTOR) { + scene.setZoomFactor(newZoom); + scene.validate(); + scene.getScrollPane().getViewport().setViewPosition(new Point((int) (viewPosition.x / DiagramScene.ZOOM_INCREMENT), (int) (viewPosition.y / DiagramScene.ZOOM_INCREMENT))); + this.satelliteComponent.update(); + } + } + + public void zoomIn() { + double zoom = scene.getZoomFactor(); + Point viewPosition = scene.getScrollPane().getViewport().getViewPosition(); + double newZoom = zoom * DiagramScene.ZOOM_INCREMENT; + if (newZoom < DiagramScene.ZOOM_MAX_FACTOR) { + scene.setZoomFactor(newZoom); + scene.validate(); + scene.getScrollPane().getViewport().setViewPosition(new Point((int) (viewPosition.x * DiagramScene.ZOOM_INCREMENT), (int) (viewPosition.y * DiagramScene.ZOOM_INCREMENT))); + this.satelliteComponent.update(); + } + } + + public void showPrevDiagram() { + int fp = getModel().getFirstPosition(); + int sp = getModel().getSecondPosition(); + if (fp != 0) { + fp--; + sp--; + getModel().setPositions(fp, sp); + } + } + + public DiagramViewModel getModel() { + return scene.getModel(); + } + + public FilterChain getFilterChain() { + return this.scene.getModel().getFilterChain(); + } + + public static EditorTopComponent getActive() { + Set modes = WindowManager.getDefault().getModes(); + for (Mode m : modes) { + TopComponent tc = m.getSelectedTopComponent(); + if (tc instanceof EditorTopComponent) { + return (EditorTopComponent) tc; + } + } + return null; + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + jCheckBox1 = new javax.swing.JCheckBox(); + + org.openide.awt.Mnemonics.setLocalizedText(jCheckBox1, "jCheckBox1"); + jCheckBox1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); + jCheckBox1.setMargin(new java.awt.Insets(0, 0, 0, 0)); + + setLayout(new java.awt.BorderLayout()); + + }// //GEN-END:initComponents + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JCheckBox jCheckBox1; + // End of variables declaration//GEN-END:variables + @Override + public int getPersistenceType() { + return TopComponent.PERSISTENCE_NEVER; + } + + @Override + public void componentOpened() { + } + + @Override + public void componentClosed() { + } + + @Override + protected String preferredID() { + return PREFERRED_ID; + } + + public void changed(RangeSliderModel model) { + updateDisplayName(); + } + + public boolean showPredSucc() { + return (Boolean) predSuccAction.getValue(PredSuccAction.STATE); + } + + public void setSelection(PropertyMatcher matcher) { + + Properties.PropertySelector
selector = new Properties.PropertySelector
(scene.getModel().getDiagramToView().getFigures()); + List
list = selector.selectMultiple(matcher); + boolean b = scene.getUndoRedoEnabled(); + scene.setUndoRedoEnabled(false); + scene.gotoFigures(list); + scene.setUndoRedoEnabled(b); + scene.setSelection(list); + } + + public void setSelectedNodes(Set nodes) { + + List
list = new ArrayList
(); + Set ids = new HashSet(); + for (InputNode n : nodes) { + ids.add(n.getId()); + } + + for (Figure f : scene.getModel().getDiagramToView().getFigures()) { + for (InputNode n : f.getSource().getSourceNodes()) { + if (ids.contains(n.getId())) { + list.add(f); + break; + } + } + } + + scene.gotoFigures(list); + scene.setSelection(list); + } + + public void propertyChange(PropertyChangeEvent evt) { + if (evt.getSource() == this.predSuccAction) { + boolean b = (Boolean) predSuccAction.getValue(PredSuccAction.STATE); + this.getModel().setShowNodeHull(b); + } else if (evt.getSource() == this.overviewAction) { + boolean b = (Boolean) overviewAction.getValue(OverviewAction.STATE); + if (b) { + showSatellite(); + } else { + showScene(); + } + } else if (evt.getSource() == this.blockLayoutAction) { + boolean b = (Boolean) blockLayoutAction.getValue(EnableBlockLayoutAction.STATE); + System.out.println("Showblocks = " + b); + this.getModel().setShowBlocks(b); + } else { + assert false : "Unknown event source"; + } + } + + public void extract() { + scene.showOnly(scene.getSelectedNodes()); + } + + public void hideNodes() { + Set selectedNodes = this.scene.getSelectedNodes(); + HashSet nodes = new HashSet(scene.getModel().getHiddenNodes()); + nodes.addAll(selectedNodes); + this.scene.showNot(nodes); + } + + public void expandPredecessors() { + Set
oldSelection = scene.getSelectedFigures(); + Set
figures = new HashSet
(); + + for (Figure f : this.getDiagramModel().getDiagramToView().getFigures()) { + boolean ok = false; + if (oldSelection.contains(f)) { + ok = true; + } else { + for (Figure pred : f.getSuccessors()) { + if (oldSelection.contains(pred)) { + ok = true; + break; + } + } + } + + if (ok) { + figures.add(f); + } + } + + scene.showAll(figures); + } + + public void expandSuccessors() { + Set
oldSelection = scene.getSelectedFigures(); + Set
figures = new HashSet
(); + + for (Figure f : this.getDiagramModel().getDiagramToView().getFigures()) { + boolean ok = false; + if (oldSelection.contains(f)) { + ok = true; + } else { + for (Figure succ : f.getPredecessors()) { + if (oldSelection.contains(succ)) { + ok = true; + break; + } + } + } + + if (ok) { + figures.add(f); + } + } + + scene.showAll(figures); + } + + public void showAll() { + scene.showNot(new HashSet()); + } + + public Diagram getDiagram() { + return getDiagramModel().getDiagramToView(); + } + + @Override + protected void componentActivated() { + } + + @Override + public void requestFocus() { + super.requestFocus(); + scene.getView().requestFocus(); + } + + @Override + public boolean requestFocusInWindow() { + super.requestFocusInWindow(); + return scene.getView().requestFocusInWindow(); + } + + @Override + public UndoRedo getUndoRedo() { + return scene.getUndoRedo(); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/ExportCookie.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/ExportCookie.java new file mode 100644 index 0000000000000000000000000000000000000000..539865e2bc210b1b8158fdbda3a4d3521d033fa6 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/ExportCookie.java @@ -0,0 +1,36 @@ +/* + * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ +package com.sun.hotspot.igv.view; + +import java.io.File; + +/** + * + * @author Thomas Wuerthinger + */ +public interface ExportCookie { + + void export(File f); +} diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/ExtendedPanAction.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/ExtendedPanAction.java new file mode 100644 index 0000000000000000000000000000000000000000..15ae3218b26c78b9e7cfd19bdc3725469211ee9b --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/ExtendedPanAction.java @@ -0,0 +1,131 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.view; + +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Point; +import org.netbeans.api.visual.widget.Scene; +import org.netbeans.api.visual.widget.Widget; +import org.netbeans.api.visual.action.WidgetAction; + +import java.awt.event.MouseEvent; +import javax.swing.JComponent; +import javax.swing.JScrollPane; +import javax.swing.SwingUtilities; + +/** + * @author David Kaspar + * @author Thomas Wuerthinger + */ +public class ExtendedPanAction extends WidgetAction.LockedAdapter { + + private Scene scene; + private JScrollPane scrollPane; + private Point lastLocation; + + protected boolean isLocked() { + return scrollPane != null; + } + + @Override + public State mousePressed(Widget widget, WidgetMouseEvent event) { + if (event.getButton() == MouseEvent.BUTTON2 || event.getButton() == MouseEvent.BUTTON1 && ((event.getModifiers() & MouseEvent.CTRL_MASK) != 0)) { + scene = widget.getScene(); + scrollPane = findScrollPane(scene.getView()); + if (scrollPane != null) { + lastLocation = scene.convertSceneToView(widget.convertLocalToScene(event.getPoint())); + SwingUtilities.convertPointToScreen(lastLocation, scrollPane.getViewport().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, scrollPane.getViewport().getView()); + Point viewPosition = scrollPane.getViewport().getViewPosition(); + Dimension viewSize = scrollPane.getViewport().getViewSize(); + Dimension viewPortSize = scrollPane.getViewport().getSize(); + + int xOffset = lastLocation.x - newLocation.x; + int yOffset = lastLocation.y - newLocation.y; + + if (viewPortSize.height == viewSize.height) { + yOffset = 0; + } + + if (viewPortSize.width == viewSize.width) { + xOffset = 0; + } + + if (xOffset == 0 && yOffset == 0) { + return true; + } + viewPosition = new Point(viewPosition.x + xOffset, viewPosition.y + yOffset); + viewPosition.x = Math.max(viewPosition.x, 0); + viewPosition.y = Math.max(viewPosition.y, 0); + viewPosition.x = Math.min(viewPosition.x, scrollPane.getViewport().getView().getSize().width - scrollPane.getViewport().getSize().width); + viewPosition.y = Math.min(viewPosition.y, scrollPane.getViewport().getView().getSize().height - scrollPane.getViewport().getSize().height); + + scrollPane.getViewport().setViewPosition(viewPosition); + scrollPane.getViewport().getView().repaint(); + lastLocation = newLocation; + return true; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/ExtendedSatelliteComponent.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/ExtendedSatelliteComponent.java new file mode 100644 index 0000000000000000000000000000000000000000..cd3e8940933e6ca3343c2d34a08434b03f346001 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/ExtendedSatelliteComponent.java @@ -0,0 +1,200 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.view; + +import org.netbeans.api.visual.widget.Scene; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; + +/** + * @author David Kaspar + * @author Thomas Wuerthinger + */ +public class ExtendedSatelliteComponent extends JComponent implements MouseListener, MouseMotionListener, Scene.SceneListener, ComponentListener { + + private DiagramScene scene; + private Image image; + private int imageWidth; + private int imageHeight; + + public ExtendedSatelliteComponent(DiagramScene scene) { + this.scene = scene; + setDoubleBuffered(true); + setPreferredSize(new Dimension(128, 128)); + addMouseListener(this); + addMouseMotionListener(this); + } + + public void addNotify() { + super.addNotify(); + scene.addSceneListener(this); + JComponent viewComponent = scene.getView(); + if (viewComponent == null) { + viewComponent = scene.createView(); + } + viewComponent.addComponentListener(this); + repaint(); + } + + public void removeNotify() { + scene.getView().removeComponentListener(this); + scene.removeSceneListener(this); + super.removeNotify(); + } + + public void update() { + this.image = null; + if (this.isVisible()) { + repaint(); + revalidate(); + validate(); + } + } + + 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.setRealZoomFactor(scale); + scene.paint(ig); + scene.setRealZoomFactor(0.0); + } + + 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); + } + } + + public void mouseClicked(MouseEvent e) { + } + + public void mousePressed(MouseEvent e) { + moveVisibleRect(e.getPoint()); + } + + public void mouseReleased(MouseEvent e) { + moveVisibleRect(e.getPoint()); + } + + public void mouseEntered(MouseEvent e) { + } + + public void mouseExited(MouseEvent e) { + } + + public void mouseDragged(MouseEvent e) { + moveVisibleRect(e.getPoint()); + } + + public void mouseMoved(MouseEvent e) { + } + + private void moveVisibleRect(Point center) { + JComponent component = scene.getView(); + if (component == null) { + return; + } + double zoomFactor = scene.getZoomFactor(); + Rectangle bounds = scene.getBounds(); + Dimension size = getSize(); + + double sx = bounds.width > 0 ? (double) size.width / bounds.width : 0.0; + double sy = bounds.width > 0 ? (double) size.height / bounds.height : 0.0; + double scale = Math.min(sx, sy); + + int vw = (int) (scale * bounds.width); + int vh = (int) (scale * bounds.height); + int vx = (size.width - vw) / 2; + int vy = (size.height - vh) / 2; + + int cx = (int) ((double) (center.x - vx) / scale * zoomFactor); + int cy = (int) ((double) (center.y - vy) / scale * zoomFactor); + + Rectangle visibleRect = component.getVisibleRect(); + visibleRect.x = cx - visibleRect.width / 2; + visibleRect.y = cy - visibleRect.height / 2; + component.scrollRectToVisible(visibleRect); + + this.repaint(); + } + + public void sceneRepaint() { + //repaint (); + } + + public void sceneValidating() { + } + + public void sceneValidated() { + } + + public void componentResized(ComponentEvent e) { + repaint(); + } + + public void componentMoved(ComponentEvent e) { + repaint(); + } + + public void componentShown(ComponentEvent e) { + } + + public void componentHidden(ComponentEvent e) { + } +} diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/FindPanel.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/FindPanel.java new file mode 100644 index 0000000000000000000000000000000000000000..7d45f1b35c6d8febf2e60c7bfc02c87b26dc34e1 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/FindPanel.java @@ -0,0 +1,111 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.view; + +import com.sun.hotspot.igv.graph.Figure; +import com.sun.hotspot.igv.data.Properties; +import com.sun.hotspot.igv.data.Properties.RegexpPropertyMatcher; +import com.sun.hotspot.igv.data.Property; +import java.awt.GridLayout; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; +import javax.swing.JComboBox; +import javax.swing.JPanel; +import javax.swing.JTextField; + +/** + * + * @author Thomas Wuerthinger + */ +class FindPanel extends JPanel implements KeyListener { + + private JComboBox nameComboBox; + private JTextField valueTextField; + + public FindPanel(List
figures) { + createDesign(); + updateComboBox(figures); + } + + protected void createDesign() { + setLayout(new GridLayout()); + nameComboBox = new JComboBox(); + valueTextField = new JTextField(); + add(nameComboBox); + add(valueTextField); + valueTextField.addKeyListener(this); + } + + public void updateComboBox(List
figures) { + + String sel = (String) nameComboBox.getSelectedItem(); + SortedSet propertyNames = new TreeSet(); + + for (Figure f : figures) { + Properties prop = f.getProperties(); + for (Property p : prop.getProperties()) { + if (!propertyNames.contains(p.getName())) { + propertyNames.add(p.getName()); + } + } + } + + for (String s : propertyNames) { + nameComboBox.addItem(s); + } + nameComboBox.setSelectedItem(sel); + } + + public String getNameText() { + return (String) nameComboBox.getSelectedItem(); + } + + public String getValueText() { + return valueTextField.getText(); + } + + public void keyTyped(KeyEvent e) { + } + + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_ENTER) { + find(); + } + } + + public void find() { + EditorTopComponent comp = EditorTopComponent.getActive(); + if (comp != null) { + RegexpPropertyMatcher matcher = new RegexpPropertyMatcher(getNameText(), getValueText()); + comp.setSelection(matcher); + } + } + + public void keyReleased(KeyEvent e) { + + } +} diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/GraphViewerImplementation.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/GraphViewerImplementation.java new file mode 100644 index 0000000000000000000000000000000000000000..e303b51aab98715dfed521f727889086c3c8eac9 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/GraphViewerImplementation.java @@ -0,0 +1,43 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.view; + +import com.sun.hotspot.igv.data.InputGraph; +import com.sun.hotspot.igv.data.services.GraphViewer; +import com.sun.hotspot.igv.graph.Diagram; +import com.sun.hotspot.igv.settings.Settings; + +/** + * + * @author Thomas Wuerthinger + */ +public class GraphViewerImplementation implements GraphViewer { + + public void view(InputGraph graph) { + Diagram diagram = Diagram.createDiagram(graph, Settings.get().get(Settings.NODE_TEXT, Settings.NODE_TEXT_DEFAULT)); + EditorTopComponent tc = new EditorTopComponent(diagram); + tc.open(); + tc.requestActive(); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/PreferenceConstants.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/PreferenceConstants.java new file mode 100644 index 0000000000000000000000000000000000000000..31df010ea865bf21273aba7cd6f580f512d6a2fe --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/PreferenceConstants.java @@ -0,0 +1,34 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.view; + +/** + * + * @author Thomas Wuerthinger + */ +public class PreferenceConstants { + + public static final String KEY_LINE_GENERATOR = "lineGenerator"; + public static final String DEFAULT_LINE_GENERATOR = "com.sun.hotspot.igv.positioning.BasicLineGenerator"; +} diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/SlotLayout.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/SlotLayout.java new file mode 100644 index 0000000000000000000000000000000000000000..9176297c771c104389fe1cb3319124d7f1aba73d --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/SlotLayout.java @@ -0,0 +1,171 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.view; + +import java.awt.Point; +import java.awt.Rectangle; +import java.util.Collection; +import java.util.List; +import org.netbeans.api.visual.layout.Layout; +import org.netbeans.api.visual.layout.LayoutFactory; +import org.netbeans.api.visual.widget.Widget; + +/** + * + * @author Thomas Wuerthinger + */ +public class SlotLayout implements Layout { + + public enum HorizontalAlignment { + + Left, + Center, + Right + } + private Layout baseLayout; + private HorizontalAlignment alignment; + private boolean vertical; + + public SlotLayout() { + this(HorizontalAlignment.Center, false); + } + + public SlotLayout(HorizontalAlignment alignment, boolean vertical) { + this.alignment = alignment; + baseLayout = LayoutFactory.createVerticalFlowLayout(); + this.vertical = vertical; + } + + public void layout(Widget widget) { + if (!vertical) { + Collection children = widget.getChildren(); + int gap = 0; + int max = 0; + for (Widget child : children) { + Rectangle preferredBounds = child.getPreferredBounds(); + int i = preferredBounds.width; + if (i > max) { + max = i; + } + } + int pos = 0; + for (Widget child : children) { + Rectangle preferredBounds = child.getPreferredBounds(); + int x = preferredBounds.x; + int y = preferredBounds.y; + int width = preferredBounds.width; + int height = preferredBounds.height; + if (pos == 0) { + pos += height / 2; + } + int lx = -x; + int ly = pos - y; + switch (alignment) { + case Center: + lx += (max - width) / 2; + break; + case Left: + break; + case Right: + lx += max - width; + break; + } + child.resolveBounds(new Point(lx, ly), new Rectangle(x, y, width, height)); + pos += height + gap; + } + } else { + + Collection children = widget.getChildren(); + int gap = 0; + int max = 0; + for (Widget child : children) { + Rectangle preferredBounds = child.getPreferredBounds(); + int i = preferredBounds.height; + if (i > max) { + max = i; + } + } + int pos = 0; + for (Widget child : children) { + Rectangle preferredBounds = child.getPreferredBounds(); + int x = preferredBounds.x; + int y = preferredBounds.y; + int width = preferredBounds.width; + int height = preferredBounds.height; + if (pos == 0) { + pos += width / 2; + } + int lx = pos - x; + int ly = -y; + switch (alignment) { + case Center: + ly += (max - height) / 2; + break; + case Left: + break; + case Right: + ly += max - height; + break; + } + child.resolveBounds(new Point(lx, ly), new Rectangle(x, y, width, height)); + pos += width + gap; + } + + } + } + + public boolean requiresJustification(Widget widget) { + return true; + } + + public void justify(Widget widget) { + baseLayout.justify(widget); + + Rectangle client = widget.getClientArea(); + List children = widget.getChildren(); + + int count = children.size(); + int z = 0; + + int maxWidth = 0; + for (Widget c : children) { + if (c.getPreferredBounds().width > maxWidth) { + maxWidth = c.getPreferredBounds().width; + } + } + + for (Widget c : children) { + z++; + Point curLocation = c.getLocation(); + Rectangle curBounds = c.getBounds(); + + + Point location = new Point(curLocation.x, client.y + client.height * z / (count + 1) - curBounds.height / 2); + if (vertical) { + location = new Point(client.x + client.width * z / (count + 1) - maxWidth / 2, curLocation.y); + } + c.resolveBounds(location, null); + } + } +} diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/Bundle.properties b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/Bundle.properties new file mode 100644 index 0000000000000000000000000000000000000000..2f1fad500248f3bf64dbc88a24d4f2c8d0174f38 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/Bundle.properties @@ -0,0 +1,7 @@ +CTL_EditorAction=Open Editor Window +CTL_LineGeneratorAction=Line Generator +CTL_NextDiagramAction=Show next graph +CTL_EnableBlockLayoutAction=Enable block layout +CTL_NodeFindAction=Find +CTL_PrevDiagramAction=Show previous graph +CTL_ExportAction=Export... diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/EnableBlockLayoutAction.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/EnableBlockLayoutAction.java new file mode 100644 index 0000000000000000000000000000000000000000..231d5c18d773a338d5a8a25693b84cc726aedecd --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/EnableBlockLayoutAction.java @@ -0,0 +1,55 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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; + +/** + * + * @author Thomas Wuerthinger + */ +public class EnableBlockLayoutAction extends AbstractAction { + + private boolean state; + public static final String STATE = "state"; + + public EnableBlockLayoutAction() { + state = true; + putValue(AbstractAction.SMALL_ICON, new ImageIcon(org.openide.util.Utilities.loadImage(iconResource()))); + putValue(STATE, true); + putValue(Action.SHORT_DESCRIPTION, "Cluster nodes into blocks"); + } + + public void actionPerformed(ActionEvent ev) { + this.state = !state; + this.putValue(STATE, state); + } + + protected String iconResource() { + return "com/sun/hotspot/igv/view/images/blocks.gif"; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExpandPredecessorsAction.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExpandPredecessorsAction.java new file mode 100644 index 0000000000000000000000000000000000000000..3bb9dbeba0203893c160a547c2f99e65217b8a5c --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExpandPredecessorsAction.java @@ -0,0 +1,60 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.view.actions; + +import com.sun.hotspot.igv.view.EditorTopComponent; +import org.openide.util.HelpCtx; +import org.openide.util.actions.CallableSystemAction; + +/** + * + * @author Thomas Wuerthinger + */ +public final class ExpandPredecessorsAction extends CallableSystemAction { + + public void performAction() { + EditorTopComponent editor = EditorTopComponent.getActive(); + if (editor != null) { + editor.expandPredecessors(); + } + } + + public String getName() { + return "Expand Predecessors"; + } + + @Override + protected void initialize() { + super.initialize(); + } + + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + @Override + protected boolean asynchronous() { + return false; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExpandSuccessorsAction.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExpandSuccessorsAction.java new file mode 100644 index 0000000000000000000000000000000000000000..6ca1508f2abe5d35a2536c154a472905b3e44b55 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExpandSuccessorsAction.java @@ -0,0 +1,60 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.view.actions; + +import com.sun.hotspot.igv.view.EditorTopComponent; +import org.openide.util.HelpCtx; +import org.openide.util.actions.CallableSystemAction; + +/** + * + * @author Thomas Wuerthinger + */ +public final class ExpandSuccessorsAction extends CallableSystemAction { + + public void performAction() { + EditorTopComponent editor = EditorTopComponent.getActive(); + if (editor != null) { + editor.expandSuccessors(); + } + } + + public String getName() { + return "Expand Successors"; + } + + @Override + protected void initialize() { + super.initialize(); + } + + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + @Override + protected boolean asynchronous() { + return false; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExportAction.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExportAction.java new file mode 100644 index 0000000000000000000000000000000000000000..771e25c895e14d0e6e0c82efe6beb38a8690bb87 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExportAction.java @@ -0,0 +1,117 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.view.actions; + +import com.sun.hotspot.igv.settings.Settings; +import com.sun.hotspot.igv.view.ExportCookie; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import java.io.File; +import javax.swing.Action; +import javax.swing.JFileChooser; +import javax.swing.KeyStroke; +import javax.swing.filechooser.FileFilter; +import org.openide.util.HelpCtx; +import org.openide.util.Lookup; +import org.openide.util.LookupEvent; +import org.openide.util.LookupListener; +import org.openide.util.NbBundle; +import org.openide.util.Utilities; +import org.openide.util.actions.CallableSystemAction; + +/** + * + * @author Thomas Wuerthinger + */ +public final class ExportAction extends CallableSystemAction implements LookupListener { + + private final Lookup lookup; + private final Lookup.Result result; + + public ExportAction() { + putValue(Action.SHORT_DESCRIPTION, "Export current graph as an SVG file"); + putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.CTRL_MASK)); + lookup = Utilities.actionsGlobalContext(); + result = lookup.lookup(new Lookup.Template(ExportCookie.class)); + result.addLookupListener(this); + resultChanged(null); + } + + public void resultChanged(LookupEvent e) { + super.setEnabled(result.allInstances().size() > 0); + } + + public void performAction() { + + JFileChooser fc = new JFileChooser(); + fc.setFileFilter(new FileFilter() { + + public boolean accept(File f) { + return true; + } + + public String getDescription() { + return "SVG files (*.svg)"; + } + }); + 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() + ".svg"); + } + + File dir = file; + if (!dir.isDirectory()) { + dir = dir.getParentFile(); + } + + Settings.get().put(Settings.DIRECTORY, dir.getAbsolutePath()); + ExportCookie cookie = Utilities.actionsGlobalContext().lookup(ExportCookie.class); + if (cookie != null) { + cookie.export(file); + } + } + } + + public String getName() { + return NbBundle.getMessage(ExportAction.class, "CTL_ExportAction"); + } + + @Override + protected String iconResource() { + return "com/sun/hotspot/igv/view/images/export.gif"; + } + + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + @Override + protected boolean asynchronous() { + return false; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExtractAction.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExtractAction.java new file mode 100644 index 0000000000000000000000000000000000000000..008ba3c386122be79ada9911e181dac2ec320271 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ExtractAction.java @@ -0,0 +1,74 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.view.actions; + +import com.sun.hotspot.igv.view.EditorTopComponent; +import java.awt.Event; +import java.awt.event.KeyEvent; +import javax.swing.Action; +import javax.swing.KeyStroke; +import org.openide.util.HelpCtx; +import org.openide.util.actions.CallableSystemAction; + +/** + * + * @author Thomas Wuerthinger + */ +public final class ExtractAction extends CallableSystemAction { + + 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)); + } + + public String getName() { + return "Extract action"; + } + + @Override + protected void initialize() { + super.initialize(); + } + + 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 --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/HideAction.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/HideAction.java new file mode 100644 index 0000000000000000000000000000000000000000..8ac2ffb629fef4edbb24fcafc88e6c47a16ce851 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/HideAction.java @@ -0,0 +1,74 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.view.actions; + +import com.sun.hotspot.igv.view.EditorTopComponent; +import java.awt.Event; +import java.awt.event.KeyEvent; +import javax.swing.Action; +import javax.swing.KeyStroke; +import org.openide.util.HelpCtx; +import org.openide.util.actions.CallableSystemAction; + +/** + * + * @author Thomas Wuerthinger + */ +public final class HideAction extends CallableSystemAction { + + 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)); + } + + public String getName() { + return "Hide"; + } + + @Override + protected void initialize() { + super.initialize(); + } + + 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 --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/MouseOverAction.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/MouseOverAction.java new file mode 100644 index 0000000000000000000000000000000000000000..10afb7c20a79e1096edc3c5e7c16df8ff43d11c1 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/MouseOverAction.java @@ -0,0 +1,59 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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 --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/NextDiagramAction.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/NextDiagramAction.java new file mode 100644 index 0000000000000000000000000000000000000000..d7f7216f2a469fe6a6e38a0398caf15246f01f83 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/NextDiagramAction.java @@ -0,0 +1,105 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.view.actions; + +import com.sun.hotspot.igv.view.DiagramViewModel; +import com.sun.hotspot.igv.data.ChangedListener; +import com.sun.hotspot.igv.util.ContextAction; +import javax.swing.Action; +import javax.swing.ImageIcon; +import org.openide.util.HelpCtx; +import org.openide.util.Lookup; +import org.openide.util.NbBundle; +import org.openide.util.Utilities; + +/** + * + * @author Thomas Wuerthinger + */ +public final class NextDiagramAction extends ContextAction implements ChangedListener { + + private DiagramViewModel model; + + public NextDiagramAction() { + this(Utilities.actionsGlobalContext()); + } + + public NextDiagramAction(Lookup lookup) { + putValue(Action.SHORT_DESCRIPTION, "Show next graph of current group"); + putValue(Action.SMALL_ICON, new ImageIcon(Utilities.loadImage("com/sun/hotspot/igv/view/images/next_diagram.png"))); + } + + public String getName() { + return NbBundle.getMessage(NextDiagramAction.class, "CTL_NextDiagramAction"); + } + + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + @Override + public Class contextClass() { + return DiagramViewModel.class; + } + + @Override + public void performAction(DiagramViewModel model) { + int fp = model.getFirstPosition(); + int sp = model.getSecondPosition(); + if (sp != model.getPositions().size() - 1) { + int nfp = fp + 1; + int nsp = sp + 1; + model.setPositions(nfp, nsp); + } + } + + @Override + public void update(DiagramViewModel model) { + super.update(model); + + if (this.model != model) { + if (this.model != null) { + this.model.getDiagramChangedEvent().removeListener(this); + } + + this.model = model; + if (this.model != null) { + this.model.getDiagramChangedEvent().addListener(this); + } + } + } + + @Override + public boolean isEnabled(DiagramViewModel model) { + return model.getSecondPosition() != model.getPositions().size() - 1; + } + + public Action createContextAwareInstance(Lookup arg0) { + return new NextDiagramAction(arg0); + } + + public void changed(DiagramViewModel source) { + update(source); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/NodeFindAction.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/NodeFindAction.java new file mode 100644 index 0000000000000000000000000000000000000000..03911b0d224715b647e38aabd2607804d41ba275 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/NodeFindAction.java @@ -0,0 +1,71 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.view.actions; + +import com.sun.hotspot.igv.view.EditorTopComponent; +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 NodeFindAction extends CallableSystemAction { + + public void performAction() { + EditorTopComponent comp = EditorTopComponent.getActive(); + if (comp != null) { + comp.findNode(); + } + } + + public NodeFindAction() { + putValue(Action.SHORT_DESCRIPTION, "Find nodes"); + } + + public String getName() { + return NbBundle.getMessage(NodeFindAction.class, "CTL_NodeFindAction"); + } + + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + @Override + protected boolean asynchronous() { + return false; + } + + @Override + public boolean isEnabled() { + return true; + } + + @Override + protected String iconResource() { + return "com/sun/hotspot/igv/view/images/search.gif"; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/OverviewAction.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/OverviewAction.java new file mode 100644 index 0000000000000000000000000000000000000000..0a54ca0bad21fcfe9b2061cac80bd16b0dac03ec --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/OverviewAction.java @@ -0,0 +1,58 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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; + +/** + * + * @author Thomas Wuerthinger + */ +public class OverviewAction extends AbstractAction { + + private boolean state; + public static final String STATE = "state"; + + public OverviewAction() { + putValue(AbstractAction.SMALL_ICON, new ImageIcon(org.openide.util.Utilities.loadImage(iconResource()))); + putValue(Action.SHORT_DESCRIPTION, "Show satellite view of whole graph"); + setState(false); + } + + public void actionPerformed(ActionEvent ev) { + setState(!state); + } + + public void setState(boolean b) { + this.putValue(STATE, b); + this.state = b; + } + + protected String iconResource() { + return "com/sun/hotspot/igv/view/images/overview.gif"; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/PredSuccAction.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/PredSuccAction.java new file mode 100644 index 0000000000000000000000000000000000000000..6e2d79b213b470b24212c3b66155824bbe783bb1 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/PredSuccAction.java @@ -0,0 +1,55 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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; + +/** + * + * @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(org.openide.util.Utilities.loadImage(iconResource()))); + putValue(STATE, true); + putValue(Action.SHORT_DESCRIPTION, "Show neighboring nodes of fully visible nodes semi-transparent"); + } + + 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 --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/PrevDiagramAction.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/PrevDiagramAction.java new file mode 100644 index 0000000000000000000000000000000000000000..2945c2003923331218610a13e65d6de1bee0b0e8 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/PrevDiagramAction.java @@ -0,0 +1,105 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.view.actions; + +import com.sun.hotspot.igv.data.ChangedListener; +import com.sun.hotspot.igv.view.DiagramViewModel; +import com.sun.hotspot.igv.util.ContextAction; +import javax.swing.Action; +import javax.swing.ImageIcon; +import org.openide.util.HelpCtx; +import org.openide.util.Lookup; +import org.openide.util.NbBundle; +import org.openide.util.Utilities; + +/** + * + * @author Thomas Wuerthinger + */ +public final class PrevDiagramAction extends ContextAction implements ChangedListener { + + private DiagramViewModel model; + + public PrevDiagramAction() { + this(Utilities.actionsGlobalContext()); + } + + public PrevDiagramAction(Lookup lookup) { + putValue(Action.SHORT_DESCRIPTION, "Show previous graph of current group"); + putValue(Action.SMALL_ICON, new ImageIcon(Utilities.loadImage("com/sun/hotspot/igv/view/images/prev_diagram.png"))); + } + + public String getName() { + return NbBundle.getMessage(PrevDiagramAction.class, "CTL_PrevDiagramAction"); + } + + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + @Override + public Class contextClass() { + return DiagramViewModel.class; + } + + @Override + public void performAction(DiagramViewModel model) { + int fp = model.getFirstPosition(); + int sp = model.getSecondPosition(); + if (fp != 0) { + int nfp = fp - 1; + int nsp = sp - 1; + model.setPositions(nfp, nsp); + } + } + + @Override + public void update(DiagramViewModel model) { + super.update(model); + + if (this.model != model) { + if (this.model != null) { + this.model.getDiagramChangedEvent().removeListener(this); + } + + this.model = model; + if (this.model != null) { + this.model.getDiagramChangedEvent().addListener(this); + } + } + } + + @Override + public boolean isEnabled(DiagramViewModel model) { + return model.getFirstPosition() != 0; + } + + public Action createContextAwareInstance(Lookup arg0) { + return new PrevDiagramAction(arg0); + } + + public void changed(DiagramViewModel source) { + update(source); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ShowAllAction.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ShowAllAction.java new file mode 100644 index 0000000000000000000000000000000000000000..f9f3b4be67061b19a33f6c65c9c589f0ddebf6d0 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ShowAllAction.java @@ -0,0 +1,74 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.view.actions; + +import com.sun.hotspot.igv.view.*; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import javax.swing.Action; +import javax.swing.KeyStroke; +import org.openide.util.HelpCtx; +import org.openide.util.actions.CallableSystemAction; + +/** + * + * @author Thomas Wuerthinger + */ +public final class ShowAllAction extends CallableSystemAction { + + public void performAction() { + EditorTopComponent editor = EditorTopComponent.getActive(); + if (editor != null) { + editor.showAll(); + } + } + + public ShowAllAction() { + putValue(Action.SHORT_DESCRIPTION, "Show all nodes"); + putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK)); + } + + public String getName() { + return "Show all"; + } + + @Override + protected void initialize() { + super.initialize(); + } + + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + @Override + protected boolean asynchronous() { + return false; + } + + @Override + protected String iconResource() { + return "com/sun/hotspot/igv/view/images/expand.gif"; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ZoomInAction.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ZoomInAction.java new file mode 100644 index 0000000000000000000000000000000000000000..9b059725562bf02410f6e4c4bf08c77ddf8272cf --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ZoomInAction.java @@ -0,0 +1,69 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.view.actions; + +import com.sun.hotspot.igv.view.EditorTopComponent; +import java.awt.Event; +import java.awt.event.KeyEvent; +import javax.swing.Action; +import javax.swing.KeyStroke; +import org.openide.util.HelpCtx; +import org.openide.util.actions.CallableSystemAction; + +/** + * + * @author Thomas Wuerthinger + */ +public final class ZoomInAction extends CallableSystemAction { + + public void performAction() { + EditorTopComponent editor = EditorTopComponent.getActive(); + if (editor != null) { + editor.zoomIn(); + } + } + + public String getName() { + return "Zoom in"; + } + + public ZoomInAction() { + putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, Event.CTRL_MASK, false)); + putValue(Action.SHORT_DESCRIPTION, "Zoom in"); + } + + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + @Override + protected boolean asynchronous() { + return false; + } + + @Override + protected String iconResource() { + return "com/sun/hotspot/igv/view/images/zoomin.gif"; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ZoomOutAction.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ZoomOutAction.java new file mode 100644 index 0000000000000000000000000000000000000000..6ec6d24216e9df139965c5e9182875e52595d70b --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/ZoomOutAction.java @@ -0,0 +1,75 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.view.actions; + +import com.sun.hotspot.igv.view.EditorTopComponent; +import java.awt.Event; +import java.awt.event.KeyEvent; +import javax.swing.Action; +import javax.swing.KeyStroke; +import org.openide.util.HelpCtx; +import org.openide.util.actions.CallableSystemAction; + +/** + * + * @author Thomas Wuerthinger + */ +public final class ZoomOutAction extends CallableSystemAction { + + public void performAction() { + EditorTopComponent editor = EditorTopComponent.getActive(); + if (editor != null) { + editor.zoomOut(); + } + } + + public ZoomOutAction() { + + putValue(Action.SHORT_DESCRIPTION, "Zoom out"); + putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, Event.CTRL_MASK, false)); + } + + public String getName() { + return "Zoom out"; + } + + @Override + protected void initialize() { + super.initialize(); + } + + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + @Override + protected boolean asynchronous() { + return false; + } + + @Override + protected String iconResource() { + return "com/sun/hotspot/igv/view/images/zoomout.gif"; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/blocks.gif b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/blocks.gif new file mode 100644 index 0000000000000000000000000000000000000000..71aa946d53918697f7043a6c255611b50d5d11cd Binary files /dev/null and b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/blocks.gif differ diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/expand.gif b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/expand.gif new file mode 100644 index 0000000000000000000000000000000000000000..ebc418d05392bb3f05bcc6e716e840f06b90713e Binary files /dev/null and b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/expand.gif differ diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/export.gif b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/export.gif new file mode 100644 index 0000000000000000000000000000000000000000..d15a80acc5f34832d78cd6de20dd2e26896c2deb Binary files /dev/null and b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/export.gif differ diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/extract.gif b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/extract.gif new file mode 100644 index 0000000000000000000000000000000000000000..7a0f1aa85e9722027ad3d7a0470169c8a016184a Binary files /dev/null and b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/extract.gif differ diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/hide.gif b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/hide.gif new file mode 100644 index 0000000000000000000000000000000000000000..25a0c0ff3a5b69af40568a0dba0cc2145cc7aad9 Binary files /dev/null and b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/hide.gif differ diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/next_diagram.png b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/next_diagram.png new file mode 100644 index 0000000000000000000000000000000000000000..b0a40e670d3085b4f185073c9dd63a3741f72b8a Binary files /dev/null and b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/next_diagram.png differ diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/overview.gif b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/overview.gif new file mode 100644 index 0000000000000000000000000000000000000000..abafbe28cfa5b88476d5b4a5d7fbe5f557b42adc Binary files /dev/null and b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/overview.gif differ diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/predsucc.gif b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/predsucc.gif new file mode 100644 index 0000000000000000000000000000000000000000..5009b345c75a2038801daa8190b005a6206daa9b Binary files /dev/null and b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/predsucc.gif differ diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/prev_diagram.png b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/prev_diagram.png new file mode 100644 index 0000000000000000000000000000000000000000..7eabfd938f581183ee38b0fceb060319cd78cadb Binary files /dev/null and b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/prev_diagram.png differ diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/search.gif b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/search.gif new file mode 100644 index 0000000000000000000000000000000000000000..9e488969a627368b6d64dd45c677ed60a2e08bed Binary files /dev/null and b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/search.gif differ diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/zoomin.gif b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/zoomin.gif new file mode 100644 index 0000000000000000000000000000000000000000..2329426e4817c9edf7f8db004d72cc096d0888e0 Binary files /dev/null and b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/zoomin.gif differ diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/zoomout.gif b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/zoomout.gif new file mode 100644 index 0000000000000000000000000000000000000000..f9f7565878fd3029321017566085b2d15cc853f1 Binary files /dev/null and b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/zoomout.gif differ diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/layer.xml b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/layer.xml new file mode 100644 index 0000000000000000000000000000000000000000..eff917a44bf4a3308874e12f6313d11ad9356b2e --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/layer.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/BlockWidget.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/BlockWidget.java new file mode 100644 index 0000000000000000000000000000000000000000..9465d25f8e227955a4782b3f676f1a99030feef0 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/BlockWidget.java @@ -0,0 +1,82 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.view.widgets; + +import com.sun.hotspot.igv.data.InputBlock; +import com.sun.hotspot.igv.graph.Diagram; +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics2D; +import java.awt.Rectangle; +import java.awt.Stroke; +import java.awt.geom.Rectangle2D; +import org.netbeans.api.visual.widget.Scene; +import org.netbeans.api.visual.widget.Widget; + +/** + * + * @author Thomas Wuerthinger + */ +public class BlockWidget extends Widget { + + public static final int BORDER = 20; + public static final Color BACKGROUND_COLOR = new Color(235, 235, 255); + private static final Font titleFont = new Font("Serif", Font.PLAIN, 14).deriveFont(Font.BOLD); + private InputBlock blockNode; + private Diagram diagram; + + public BlockWidget(Scene scene, Diagram d, InputBlock blockNode) { + super(scene); + this.blockNode = blockNode; + this.diagram = d; + this.setBackground(BACKGROUND_COLOR); + this.setOpaque(true); + this.setCheckClipping(true); + } + + @Override + protected void paintWidget() { + super.paintWidget(); + Graphics2D g = this.getGraphics(); + Stroke old = g.getStroke(); + g.setColor(Color.BLUE); + Rectangle r = new Rectangle(this.getPreferredBounds()); + r.width--; + r.height--; + if (this.getBounds().width > 0 && this.getBounds().height > 0) { + g.setStroke(new BasicStroke(2)); + g.drawRect(r.x, r.y, r.width, r.height); + } + + Color titleColor = Color.BLACK; + g.setColor(titleColor); + g.setFont(titleFont); + + String s = "B" + blockNode.toString(); + Rectangle2D r1 = g.getFontMetrics().getStringBounds(s, g); + g.drawString(s, r.x + 5, r.y + (int) r1.getHeight()); + g.setStroke(old); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/DiagramConnectionWidget.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/DiagramConnectionWidget.java new file mode 100644 index 0000000000000000000000000000000000000000..98e696151db9fbfe77139f664bee74e5ba06f302 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/DiagramConnectionWidget.java @@ -0,0 +1,251 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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.view.DiagramScene; +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Composite; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Stroke; +import java.util.ArrayList; +import java.util.List; +import org.netbeans.api.visual.anchor.AnchorShape; +import org.netbeans.api.visual.model.ObjectState; +import org.netbeans.api.visual.widget.ConnectionWidget; +import org.netbeans.api.visual.widget.Scene; + +/** + * + * @author Thomas Wuerthinger + */ +public class DiagramConnectionWidget extends ConnectionWidget { + + private static Stroke DASHED_STROKE = new BasicStroke( + 1, + BasicStroke.CAP_BUTT, + BasicStroke.JOIN_ROUND, + 0, + new float[]{2}, + 0); + private static Stroke NORMAL_STROKE = new BasicStroke(1); + private static Stroke BOLD_STROKE = new BasicStroke(3); + public static int WHITE_FACTOR = 5; + private Connection connection; + private Color color; + private Point lastSourceAnchor; + private Point lastTargetAnchor; + private List controlPoints; + private Rectangle clientArea; + private boolean split; + private int[] xPoints; + private int[] yPoints; + private int pointCount; + + /** Creates a new instance of ConnectionWidget */ + public DiagramConnectionWidget(Connection connection, Scene scene) { + super(scene); + this.connection = connection; + color = connection.getColor(); + if (connection.getStyle() == Connection.ConnectionStyle.DASHED) { + this.setStroke(DASHED_STROKE); + } else if (connection.getStyle() == Connection.ConnectionStyle.BOLD) { + this.setStroke(BOLD_STROKE); + } else { + this.setStroke(NORMAL_STROKE); + } + this.setCheckClipping(true); + clientArea = new Rectangle(); + updateControlPoints(); + } + + public Connection getConnection() { + return connection; + } + + public void updateControlPoints() { + List newControlPoints = connection.getControlPoints(); + Connection c = connection; + Figure f = c.getInputSlot().getFigure(); + Point p = new Point(f.getPosition()); + p.translate(c.getInputSlot().getRelativePosition().x, f.getSize().height / 2); + Point p4 = new Point(f.getPosition()); + p4.translate(c.getInputSlot().getRelativePosition().x, c.getInputSlot().getRelativePosition().y); + + Figure f2 = c.getOutputSlot().getFigure(); + Point p2 = new Point(f2.getPosition()); + p2.translate(c.getOutputSlot().getRelativePosition().x, f2.getSize().height / 2); + Point p3 = new Point(f2.getPosition()); + p3.translate(c.getOutputSlot().getRelativePosition().x, c.getOutputSlot().getRelativePosition().y); + + /*if(controlPoints.size() >= 2) { + String className = Preferences.userNodeForPackage(PreferenceConstants.class).get(PreferenceConstants.KEY_LINE_GENERATOR, PreferenceConstants.DEFAULT_LINE_GENERATOR); + try { + LineGenerator lg = (LineGenerator)Class.forName(className).newInstance(); + controlPoints = lg.createLine(controlPoints, p2, p); + } catch (InstantiationException ex) { + } catch (IllegalAccessException ex) { + } catch (ClassNotFoundException ex) { + } + }*/ + + this.controlPoints = newControlPoints; + pointCount = newControlPoints.size(); + xPoints = new int[pointCount]; + yPoints = new int[pointCount]; + int minX = Integer.MAX_VALUE; + int maxX = Integer.MIN_VALUE; + int minY = Integer.MAX_VALUE; + int maxY = Integer.MIN_VALUE; + split = false; + for (int i = 0; i < pointCount; i++) { + if (newControlPoints.get(i) == null) { + split = true; + } else { + int curX = newControlPoints.get(i).x; + int curY = newControlPoints.get(i).y; + this.xPoints[i] = curX; + this.yPoints[i] = curY; + minX = Math.min(minX, curX); + maxX = Math.max(maxX, curX); + minY = Math.min(minY, curY); + maxY = Math.max(maxY, curY); + } + } + + this.clientArea = new Rectangle(minX, minY, maxX - minX, maxY - minY); + } + + @Override + protected void paintWidget() { + Graphics2D g = this.getGraphics(); + + if (xPoints.length == 0 || Math.abs(xPoints[0] - xPoints[xPoints.length - 1]) > 2000) { + return; + } + + //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); + //g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); + //g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); + + DiagramScene ds = (DiagramScene) this.getScene(); + boolean shouldHide = false;//ds.getShouldHide(this); + + Composite oldComposite = null; + if (shouldHide) { + Color c = new Color(255 - (255 - color.getRed()) / WHITE_FACTOR, 255 - (255 - color.getGreen()) / WHITE_FACTOR, 255 - (255 - color.getBlue()) / WHITE_FACTOR); + g.setPaint(c); + } else { + g.setPaint(color); + } + + if (split) { + for (int i = 1; i < controlPoints.size(); i++) { + Point prev = controlPoints.get(i - 1); + Point cur = controlPoints.get(i); + if (cur == null || prev == null) { + continue; + } + + g.drawLine(prev.x, prev.y, cur.x, cur.y); + } + } else { + g.drawPolyline(xPoints, yPoints, pointCount); + } + + /*for(int i=0; i= 2) { + Graphics2D g2 = (Graphics2D) g.create(); + int xOff = xPoints[xPoints.length - 2] - xPoints[xPoints.length - 1]; + int yOff = yPoints[yPoints.length - 2] - yPoints[yPoints.length - 1]; + if (xOff == 0 && yOff == 0 && yPoints.length >= 3) { + xOff = xPoints[xPoints.length - 3] - xPoints[xPoints.length - 1]; + yOff = yPoints[yPoints.length - 3] - yPoints[yPoints.length - 1]; + } + g2.translate(xPoints[xPoints.length - 1], yPoints[yPoints.length - 1]); + g2.rotate(Math.atan2(yOff, xOff)); + + g2.scale(0.55, 0.80); + AnchorShape.TRIANGLE_FILLED.paint(g2, false); + } + } + + @Override + public void notifyStateChanged(ObjectState previousState, ObjectState state) { + + if (previousState.isHovered() != state.isHovered()) { + color = connection.getColor(); + if (state.isHovered()) { + this.setStroke(BOLD_STROKE); + } else { + this.setStroke(NORMAL_STROKE); + } + + if (state.isHovered()) { + this.setStroke(BOLD_STROKE); + } else { + this.setStroke(NORMAL_STROKE); + } + + repaint(); + } + super.notifyStateChanged(previousState, state); + } + + @Override + public List getControlPoints() { + if (split) { + ArrayList result = new ArrayList(); + for (Point p : controlPoints) { + if (p != null) { + result.add(p); + } + } + return result; + } else { + return controlPoints; + } + } + + @Override + public String toString() { + return "ConnectionWidget[" + connection + "]"; + } + + @Override + protected Rectangle calculateClientArea() { + Rectangle result = new Rectangle(clientArea); + result.grow(10, 10); + return result; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/FigureWidget.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/FigureWidget.java new file mode 100644 index 0000000000000000000000000000000000000000..ea65e028262f60b74c151cc2bbcb167c6090bf6e --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/FigureWidget.java @@ -0,0 +1,358 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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.view.DiagramScene; +import com.sun.hotspot.igv.view.SlotLayout; +import com.sun.hotspot.igv.util.DoubleClickHandler; +import com.sun.hotspot.igv.data.Properties; +import com.sun.hotspot.igv.util.PropertiesSheet; +import java.awt.AlphaComposite; +import java.awt.Color; +import java.awt.Composite; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Graphics; +import java.awt.Point; +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 org.netbeans.api.visual.action.PopupMenuProvider; +import org.netbeans.api.visual.action.WidgetAction; +import org.netbeans.api.visual.model.ObjectState; +import org.netbeans.api.visual.widget.Widget; +import org.netbeans.api.visual.layout.LayoutFactory; +import org.netbeans.api.visual.widget.LabelWidget; +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 DEPTH = 5; + 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; + + public void setBoundary(boolean b) { + boundary = b; + } + + public boolean isBoundary() { + return boundary; + } + + public Node getNode() { + return node; + } + + private String shortenString(String string) { + if (string.length() > MAX_STRING_LENGTH) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < string.length(); i++) { + char c = string.charAt(i); + if (!Character.isLetter(c) || Character.isUpperCase(c)) { + sb.append(c); + } + } + string = sb.toString(); + } + return string; + } + + public FigureWidget(final Figure f, DiagramScene s, Widget parent) { + + super(s); + + + font = f.getDiagram().getFont(); + boldFont = f.getDiagram().getFont().deriveFont(Font.BOLD); + this.setCheckClipping(true); + this.diagramScene = s; + + parent.addChild(this); + this.figure = f; + this.resolveBounds(null, calculateClientArea()); + + leftWidget = new Widget(s); + this.addChild(leftWidget); + leftWidget.setLayout(new SlotLayout(SlotLayout.HorizontalAlignment.Right, VERTICAL_LAYOUT));//LayoutFactory.createVerticalFlowLayout(LayoutFactory.SerialAlignment.JUSTIFY, 0)); + + middleWidget = new Widget(s); + this.addChild(middleWidget); + + if (VERTICAL_LAYOUT) { + this.setLayout(LayoutFactory.createVerticalFlowLayout()); + } else { + this.setLayout(LayoutFactory.createHorizontalFlowLayout()); + } + + middleWidget.setLayout(LayoutFactory.createVerticalFlowLayout()); + + middleWidget.setBackground(f.getColor()); + middleWidget.setOpaque(true); + assert this.getScene() != null; + assert this.getScene().getView() != null; + middleWidget.setBorder(BorderFactory.createLineBorder(Color.BLACK)); + + + labelWidgets = new ArrayList(); + + String[] strings = figure.getLines(); + + for (String cur : strings) { + + String displayString = cur; + + LabelWidget lw = new LabelWidget(s); + 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.setMaximumSize(new Dimension(f.getWidth(), 20000)); + lw.setMinimumSize(new Dimension(f.getWidth(), 20)); + } + + rightWidget = new Widget(s); + this.addChild(rightWidget); + rightWidget.setLayout(new SlotLayout(SlotLayout.HorizontalAlignment.Left, VERTICAL_LAYOUT));//LayoutFactory.createVerticalLayout(LayoutFactory.SerialAlignment.JUSTIFY, 0)); + + // 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()); + } + private boolean firstTime = true; + + @Override + protected void paintWidget() { + if (firstTime) { + firstTime = false; + for (LabelWidget w : labelWidgets) { + String cur = w.getLabel(); + Graphics graphics = this.getGraphics(); + if (graphics.getFontMetrics().stringWidth(cur) > figure.getWidth()) { + w.setLabel(shortenString(cur)); + } + } + } + super.paintWidget(); + } + + 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; + int thickness = 1; + boolean repaint = false; + Font f = font; + if (state.isSelected()) { + thickness = 1; + f = boldFont; + } + + if (state.isHovered()) { + borderColor = Color.BLUE; + } + + if (state.isHovered() != previousState.isHovered()) { + repaint = true; + } + + if (state.isSelected() != previousState.isSelected()) { + repaint = true; + } + + if (repaint) { + middleWidget.setBorder(BorderFactory.createLineBorder(borderColor, thickness)); + for (LabelWidget labelWidget : labelWidgets) { + labelWidget.setFont(f); + } + repaint(); + } + } + + public String getName() { + return getProperties().get("name"); + } + + public Properties getProperties() { + return figure.getProperties(); + } + + public Figure getFigure() { + return figure; + } + + @Override + protected void paintChildren() { + + if (diagramScene.getRealZoomFactor() < ZOOM_FACTOR && diagramScene.getModel().getShowBlocks()) { + return; + } + + 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.getRealZoomFactor() < 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); + } + } + + public JPopupMenu getPopupMenu(Widget widget, Point point) { + JPopupMenu m = diagramScene.createPopupMenu(); + + JMenu predecessors = new JMenu("Predecessors"); + addFigureToSubMenu(predecessors, getFigure(), false, DEPTH); + + JMenu successors = new JMenu("Successors"); + addFigureToSubMenu(successors, getFigure(), true, DEPTH); + + m.addSeparator(); + m.add(predecessors); + m.add(successors); + return m; + } + + public void addFigureToSubMenu(JMenu subMenu, final Figure f, boolean successor, int depth) { + Set
set = f.getPredecessorSet(); + if (successor) { + set = f.getSuccessorSet(); + } + + int count = set.size(); + if (set.contains(f)) { + count--; + } + + for (Figure f2 : set) { + if (f2 == f) { + continue; + } + + count--; + addFigureToMenu(subMenu, f2, successor, depth - 1); + if (count > 0) { + subMenu.addSeparator(); + } + } + } + + public void addFigureToMenu(JMenu m, final Figure f, boolean successor, int depth) { + + Action a = diagramScene.createGotoAction(f); + + + m.add(a); + + if (depth > 0) { + String name = "Predecessors"; + if (successor) { + name = "Successors"; + } + + JMenu subMenu = new JMenu(name); + addFigureToSubMenu(subMenu, f, successor, depth); + m.add(subMenu); + } + + } + + public void handleDoubleClick(Widget w, WidgetAction.WidgetMouseEvent e) { + + if (diagramScene.isAllVisible()) { + Set hiddenNodes = new HashSet(diagramScene.getModel().getGraphToView().getGroup().getAllNodes()); + hiddenNodes.removeAll(this.getFigure().getSource().getSourceNodesAsSet()); + this.diagramScene.showNot(hiddenNodes); + } else if (isBoundary()) { + + Set hiddenNodes = new HashSet(diagramScene.getModel().getHiddenNodes()); + hiddenNodes.removeAll(this.getFigure().getSource().getSourceNodesAsSet()); + this.diagramScene.showNot(hiddenNodes); + } else { + Set hiddenNodes = new HashSet(diagramScene.getModel().getHiddenNodes()); + hiddenNodes.addAll(this.getFigure().getSource().getSourceNodesAsSet()); + this.diagramScene.showNot(hiddenNodes); + } + } +} diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/InputSlotWidget.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/InputSlotWidget.java new file mode 100644 index 0000000000000000000000000000000000000000..a6028aa71ee1e4d018e75fd018ab1c5848386d61 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/InputSlotWidget.java @@ -0,0 +1,61 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.view.widgets; + +import com.sun.hotspot.igv.graph.InputSlot; +import com.sun.hotspot.igv.view.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); + } + + public InputSlot getInputSlot() { + return inputSlot; + } + + 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 --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/LineWidget.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/LineWidget.java new file mode 100644 index 0000000000000000000000000000000000000000..902413eac87127d9447fde615bcae50934b4b9ad --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/LineWidget.java @@ -0,0 +1,293 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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.InputSlot; +import com.sun.hotspot.igv.graph.OutputSlot; +import com.sun.hotspot.igv.view.DiagramScene; +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Stroke; +import java.awt.geom.Line2D; +import java.util.ArrayList; +import java.util.List; +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.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 = 8; + 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.setCheckClipping(true); + + this.getActions().addAction(ActionFactory.createPopupMenuAction(this)); + if (animator == null) { + this.setBackground(color); + } else { + this.setBackground(Color.WHITE); + animator.animateBackgroundColor(this, color); + } + } + + 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.getRealZoomFactor() < ZOOM_FACTOR) { + return; + } + + Graphics2D g = getScene().getGraphics(); + g.setPaint(this.getBackground()); + ObjectState state = this.getState(); + 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; + 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); + } + } + + 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() { + + public void popupMenuWillBecomeVisible(PopupMenuEvent e) { + w.setRecursivePopupVisible(true); + } + + public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { + w.setRecursivePopupVisible(false); + } + + public void popupMenuCanceled(PopupMenuEvent e) { + } + }); + + return menu; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/MultiConnectionWidget.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/MultiConnectionWidget.java new file mode 100644 index 0000000000000000000000000000000000000000..b65c5eab1cf0e4e81ee21cd38b1bb216176b53b8 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/MultiConnectionWidget.java @@ -0,0 +1,281 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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.InputSlot; +import com.sun.hotspot.igv.graph.OutputSlot; +import com.sun.hotspot.igv.graph.Slot; +import com.sun.hotspot.igv.view.DiagramScene; +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Stroke; +import java.awt.geom.Line2D; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.SortedSet; +import java.util.TreeSet; +import javax.swing.JPopupMenu; +import javax.swing.event.PopupMenuEvent; +import javax.swing.event.PopupMenuListener; +import org.netbeans.api.visual.action.PopupMenuProvider; +import org.netbeans.api.visual.model.ObjectState; +import org.netbeans.api.visual.widget.Widget; + +/** + * + * @author Thomas Wuerthinger + */ +public class MultiConnectionWidget extends Widget implements PopupMenuProvider { + + public final int BORDER = 4; + public final int HOVER_STROKE_WIDTH = 3; + + private static class Route { + + public Point from; + public Point to; + public SortedSet inputSlots; + public boolean decorateStart; + public boolean decorateEnd; + + public Route(Point from, Point to) { + assert from != null; + assert to != null; + this.from = from; + this.to = to; + this.inputSlots = new TreeSet(); + } + + @Override + public boolean equals(Object obj) { + + if (obj instanceof Route) { + Route r = (Route) obj; + return r.from.equals(from) && r.to.equals(to); + } + + return super.equals(obj); + } + + @Override + public int hashCode() { + return ((((from.x * 1711) + from.y) * 1711 + to.x) * 1711 + to.y); + } + } + private Rectangle clientArea; + private OutputSlot outputSlot; + private Map> routeMap; + private List routeList; + private Color color; + private DiagramScene diagramScene; + private boolean popupVisible; + + /** Creates a new instance of MultiConnectionWidget */ + public MultiConnectionWidget(OutputSlot outputSlot, DiagramScene scene) { + super(scene); + + this.diagramScene = scene; + this.outputSlot = outputSlot; + this.setCheckClipping(true); + + routeMap = new HashMap>(); + routeList = new ArrayList(); + color = Color.BLACK; + + for (Connection c : outputSlot.getConnections()) { + List controlPoints = c.getControlPoints(); + InputSlot inputSlot = (InputSlot) c.getTo(); + color = c.getColor(); + + for (int i = 1; i < controlPoints.size(); i++) { + Point prev = controlPoints.get(i - 1); + Point cur = controlPoints.get(i); + + if (prev != null && cur != null) { + Route r = new Route(prev, cur); + if (routeMap.containsKey(r)) { + SortedSet set = routeMap.get(r); + set.add(inputSlot); + } else { + SortedSet set = new TreeSet(Slot.slotFigureComparator); + set.add(inputSlot); + routeMap.put(r, set); + routeList.add(r); + } + } + } + } + + if (routeList.size() == 0) { + clientArea = new Rectangle(); + } else { + for (Route r : routeList) { + + int x = r.from.x; + int y = r.from.y; + + int x2 = r.to.x; + int y2 = r.to.y; + + if (x > x2) { + int tmp = x; + x = x2; + x2 = tmp; + } + + if (y > y2) { + int tmp = y; + y = y2; + y2 = tmp; + } + + int width = x2 - x + 1; + int height = y2 - y + 1; + + Rectangle rect = new Rectangle(x, y, width, height); + if (clientArea == null) { + clientArea = rect; + } else { + clientArea = clientArea.union(rect); + } + } + + clientArea.grow(BORDER, BORDER); + } + } + + private void setHoverPosition(Point location) { + Route r = getNearest(location); + } + + private Route getNearest(Point localLocation) { + + double minDist = Double.MAX_VALUE; + Route result = null; + for (Route r : routeList) { + double dist = Line2D.ptSegDistSq((double) r.from.x, (double) r.from.y, (double) r.to.x, (double) r.to.y, (double) localLocation.x, (double) localLocation.y); + if (dist < minDist) { + result = r; + minDist = dist; + } + } + + assert result != null; + + return result; + } + + @Override + public boolean isHitAt(Point localLocation) { + if (!super.isHitAt(localLocation)) { + return false; + } + + for (Route r : routeList) { + double dist = Line2D.ptSegDistSq((double) r.from.x, (double) r.from.y, (double) r.to.x, (double) r.to.y, (double) localLocation.x, (double) localLocation.y); + if (dist < BORDER * BORDER) { + setHoverPosition(localLocation); + return true; + } + } + + return false; + } + + @Override + protected Rectangle calculateClientArea() { + return clientArea; + } + + @Override + protected void paintWidget() { + Graphics2D g = getScene().getGraphics(); + //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); + g.setColor(this.color); + ObjectState state = this.getState(); + float width = 1.0f; + if (state.isHovered() || this.popupVisible) { + width = HOVER_STROKE_WIDTH; + } + + Stroke oldStroke = g.getStroke(); + g.setStroke(new BasicStroke(width)); + for (Route r : routeList) { + g.drawLine(r.from.x, r.from.y, r.to.x, r.to.y); + } + g.setStroke(oldStroke); + } + + @Override + protected void notifyStateChanged(ObjectState previousState, ObjectState state) { + + boolean repaint = false; + + if (state.isHovered() != previousState.isHovered()) { + repaint = true; + } + + repaint(); + } + + public JPopupMenu getPopupMenu(Widget widget, Point localLocation) { + JPopupMenu menu = new JPopupMenu(); + Route r = getNearest(localLocation); + assert r != null; + assert routeMap.containsKey(r); + + menu.add(diagramScene.createGotoAction(outputSlot.getFigure())); + menu.addSeparator(); + + SortedSet set = this.routeMap.get(r); + for (InputSlot s : set) { + menu.add(diagramScene.createGotoAction(s.getFigure())); + } + + final MultiConnectionWidget w = this; + menu.addPopupMenuListener(new PopupMenuListener() { + + public void popupMenuWillBecomeVisible(PopupMenuEvent e) { + w.popupVisible = true; + w.repaint(); + } + + public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { + w.popupVisible = false; + w.repaint(); + } + + public void popupMenuCanceled(PopupMenuEvent e) { + } + }); + + return menu; + } +} diff --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/OutputSlotWidget.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/OutputSlotWidget.java new file mode 100644 index 0000000000000000000000000000000000000000..351e6ddd7b453c35e1b818699587951a53a17f1a --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/OutputSlotWidget.java @@ -0,0 +1,61 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ +package com.sun.hotspot.igv.view.widgets; + +import com.sun.hotspot.igv.graph.OutputSlot; +import com.sun.hotspot.igv.view.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); + } + + public OutputSlot getOutputSlot() { + return outputSlot; + } + + 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 --git a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/SlotWidget.java b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/SlotWidget.java new file mode 100644 index 0000000000000000000000000000000000000000..d5aac2f6feb20f71851033e0666677dd8b66c738 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/SlotWidget.java @@ -0,0 +1,126 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.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.view.*; +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.geom.Rectangle2D; +import org.netbeans.api.visual.widget.Widget; + +/** + * + * @author Thomas Wuerthinger + */ +public abstract class SlotWidget extends Widget { + + private Slot slot; + private FigureWidget figureWidget; + private Image bufferImage; + private static double TEXT_ZOOM_FACTOR = 0.9; + private static double ZOOM_FACTOR = 0.6; + private DiagramScene scene; + + public SlotWidget(Slot slot, DiagramScene scene, Widget parent, FigureWidget fw) { + super(scene); + this.scene = scene; + this.slot = slot; + figureWidget = fw; + this.setToolTipText("" + slot.getName() + ""); + this.setCheckClipping(true); + } + + public Point getAnchorPosition() { + Point p = new Point(figureWidget.getFigure().getPosition()); + Point p2 = slot.getRelativePosition(); + p.translate(p2.x, p2.y); + return p; + } + + protected void init() { + + Point p = calculateRelativeLocation(); + Rectangle r = calculateClientArea(); + p = new Point(p.x, p.y - r.height / 2); + this.setPreferredLocation(p); + } + + public Slot getSlot() { + return slot; + } + + public FigureWidget getFigureWidget() { + return figureWidget; + } + + @Override + protected void paintWidget() { + + if (scene.getRealZoomFactor() < ZOOM_FACTOR) { + return; + } + + if (bufferImage == null) { + Graphics2D g = this.getGraphics(); + g.setColor(Color.DARK_GRAY); + int w = this.getBounds().width; + int h = this.getBounds().height; + + if (getSlot().getShortName() != null && getSlot().getShortName().length() > 0 && scene.getRealZoomFactor() >= TEXT_ZOOM_FACTOR) { + Font f = new Font("Arial", Font.PLAIN, 8); + g.setFont(f.deriveFont(7.5f)); + Rectangle2D r1 = g.getFontMetrics().getStringBounds(getSlot().getShortName(), g); + g.drawString(getSlot().getShortName(), (int) (this.getBounds().width - r1.getWidth()) / 2, (int) (this.getBounds().height + r1.getHeight()) / 2); + } else { + + if (slot instanceof OutputSlot) { + g.fillArc(w / 4, -h / 4 - 1, w / 2, h / 2, 180, 180); + } else { + g.fillArc(w / 4, 3 * h / 4, w / 2, h / 2, 0, 180); + } + } + } + } + + @Override + protected Rectangle calculateClientArea() { + return new Rectangle(0, 0, Figure.SLOT_WIDTH, Figure.SLOT_WIDTH); + } + + protected abstract Point calculateRelativeLocation(); + + protected double calculateRelativeY(int size, int index) { + assert index >= 0 && index < size; + assert size > 0; + double height = getFigureWidget().getBounds().getHeight(); + return height * (index + 1) / (size + 1); + } +} diff --git a/src/share/tools/IdealGraphVisualizer/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties b/src/share/tools/IdealGraphVisualizer/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties new file mode 100644 index 0000000000000000000000000000000000000000..196dde416983813d3558b9be97491c320de952d0 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties @@ -0,0 +1,7 @@ +currentVersion=IdealGraphVisualizer {0} +LBL_splash_window_title=Starting IdealGraphVisualizer +SPLASH_WIDTH=475 +SplashProgressBarBounds=0,268,473,6 +SplashProgressBarColor=0xFFFFFF +SplashRunningTextBounds=269,253,205,12 +SplashRunningTextColor=0xFFFFFF diff --git a/src/share/tools/IdealGraphVisualizer/branding/core/core.jar/org/netbeans/core/startup/frame.gif b/src/share/tools/IdealGraphVisualizer/branding/core/core.jar/org/netbeans/core/startup/frame.gif new file mode 100644 index 0000000000000000000000000000000000000000..43353c9e2e1682ccd542b0f7cd2fab48c829d521 Binary files /dev/null and b/src/share/tools/IdealGraphVisualizer/branding/core/core.jar/org/netbeans/core/startup/frame.gif differ diff --git a/src/share/tools/IdealGraphVisualizer/branding/core/core.jar/org/netbeans/core/startup/splash.gif b/src/share/tools/IdealGraphVisualizer/branding/core/core.jar/org/netbeans/core/startup/splash.gif new file mode 100644 index 0000000000000000000000000000000000000000..949861e8fd7a79a51c4f3debec2fb78555a6fb54 Binary files /dev/null and b/src/share/tools/IdealGraphVisualizer/branding/core/core.jar/org/netbeans/core/startup/splash.gif differ diff --git a/src/share/tools/IdealGraphVisualizer/branding/modules/org-netbeans-core-windows.jar/org/netbeans/core/windows/view/ui/Bundle.properties b/src/share/tools/IdealGraphVisualizer/branding/modules/org-netbeans-core-windows.jar/org/netbeans/core/windows/view/ui/Bundle.properties new file mode 100644 index 0000000000000000000000000000000000000000..1263cad01ec034dc3b1eeeaeb2dd066a3378fb22 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/branding/modules/org-netbeans-core-windows.jar/org/netbeans/core/windows/view/ui/Bundle.properties @@ -0,0 +1,2 @@ +CTL_MainWindow_Title=IdealGraphVisualizer {0} +CTL_MainWindow_Title_No_Project=IdealGraphVisualizer {0} diff --git a/src/share/tools/IdealGraphVisualizer/build.xml b/src/share/tools/IdealGraphVisualizer/build.xml new file mode 100644 index 0000000000000000000000000000000000000000..fb95e5f39d5258b2145a969d93324ea43390875d --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/build.xml @@ -0,0 +1,8 @@ + + + + + + Builds the module suite IdealGraphVisualizer. + + diff --git a/src/share/tools/IdealGraphVisualizer/nbproject/build-impl.xml b/src/share/tools/IdealGraphVisualizer/nbproject/build-impl.xml new file mode 100644 index 0000000000000000000000000000000000000000..f056e104db431abd0256cc198055aef1fae4862c --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/nbproject/build-impl.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/share/tools/IdealGraphVisualizer/nbproject/genfiles.properties b/src/share/tools/IdealGraphVisualizer/nbproject/genfiles.properties new file mode 100644 index 0000000000000000000000000000000000000000..758cede014914e261acd795d8573d29ff04fcd7f --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=72833581 +build.xml.script.CRC32=e9c757c5 +build.xml.stylesheet.CRC32=531c622b +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=72833581 +nbproject/build-impl.xml.script.CRC32=1b6f3648 +nbproject/build-impl.xml.stylesheet.CRC32=196c7090 diff --git a/src/share/tools/IdealGraphVisualizer/nbproject/platform.properties b/src/share/tools/IdealGraphVisualizer/nbproject/platform.properties new file mode 100644 index 0000000000000000000000000000000000000000..4768730f1290b94722ec62dd1fefc788b0116633 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/nbproject/platform.properties @@ -0,0 +1,29 @@ +# Deprecated since 5.0u1; for compatibility with 5.0: +disabled.clusters=\ + apisupport1,\ + harness,\ + ide8,\ + java1,\ + nb6.0,\ + profiler2 +disabled.modules=\ + org.netbeans.core.execution,\ + org.netbeans.core.multiview,\ + org.netbeans.core.output2,\ + org.netbeans.modules.applemenu,\ + org.netbeans.modules.autoupdate.services,\ + org.netbeans.modules.autoupdate.ui,\ + org.netbeans.modules.core.kit,\ + org.netbeans.modules.favorites,\ + org.netbeans.modules.javahelp,\ + org.netbeans.modules.masterfs,\ + org.netbeans.modules.options.keymap,\ + org.netbeans.modules.sendopts,\ + org.netbeans.modules.templates,\ + org.openide.compat,\ + org.openide.execution,\ + org.openide.util.enumerations +enabled.clusters=\ + platform7 +nbjdk.active=default +nbplatform.active=default diff --git a/src/share/tools/IdealGraphVisualizer/nbproject/project.properties b/src/share/tools/IdealGraphVisualizer/nbproject/project.properties new file mode 100644 index 0000000000000000000000000000000000000000..1b524d231f391099af5f297fdb8bd74a6e808c75 --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/nbproject/project.properties @@ -0,0 +1,40 @@ +app.icon=branding/core/core.jar/org/netbeans/core/startup/frame48.gif +app.name=idealgraphvisualizer +app.title=IdealGraphVisualizer +branding.token=${app.name} +modules=\ + ${project.com.sun.hotspot.igv.graph}:\ + ${project.com.sun.hotspot.igv.coordinator}:\ + ${project.com.sun.hotspot.igv.filter}:\ + ${project.com.sun.hotspot.igv.hierarchicallayout}:\ + ${project.com.sun.hotspot.igv.layout}:\ + ${project.com.sun.hotspot.igv.controlflow}:\ + ${project.com.sun.hotspot.igv.data}:\ + ${project.com.sun.hotspot.igv.view}:\ + ${project.com.sun.hotspot.igv.bytecodes}:\ + ${project.com.sun.hotspot.igv.difference}:\ + ${project.com.sun.hotspot.igv.settings}:\ + ${project.com.sun.hotspot.igv.util}:\ + ${project.com.sun.hotspot.igv.rhino}:\ + ${project.com.sun.hotspot.igv.svg}:\ + ${project.com.sun.hotspot.connection}:\ + ${project.com.sun.hotspot.igv.servercompilerscheduler}:\ + ${project.com.sun.hotspot.igv.filterwindow} +project.com.sun.hotspot.connection=NetworkConnection +project.com.sun.hotspot.igv.bytecodes=Bytecodes +project.com.sun.hotspot.igv.controlflow=ControlFlow +project.com.sun.hotspot.igv.coordinator=Coordinator +project.com.sun.hotspot.igv.data=Data +project.com.sun.hotspot.igv.difference=Difference +project.com.sun.hotspot.igv.filter=Filter +project.com.sun.hotspot.igv.filterwindow=FilterWindow +project.com.sun.hotspot.igv.graph=Graph +project.com.sun.hotspot.igv.hierarchicallayout=HierarchicalLayout +project.com.sun.hotspot.igv.layout=Layout +project.com.sun.hotspot.igv.rhino=RhinoScriptEngineProxy +project.com.sun.hotspot.igv.servercompilerscheduler=ServerCompiler +project.com.sun.hotspot.igv.settings=Settings +project.com.sun.hotspot.igv.svg=BatikSVGProxy +project.com.sun.hotspot.igv.view=View +project.com.sun.hotspot.igv.util=Util +run.args = -server -J-Xms64m -J-Xmx512m -J-da diff --git a/src/share/tools/IdealGraphVisualizer/nbproject/project.xml b/src/share/tools/IdealGraphVisualizer/nbproject/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..47400216ae92e7c8786e4a6ca441634cd4033b4d --- /dev/null +++ b/src/share/tools/IdealGraphVisualizer/nbproject/project.xml @@ -0,0 +1,9 @@ + + + org.netbeans.modules.apisupport.project.suite + + + IdealGraphVisualizer + + +