1 /*
2  * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  *
23  */
24 package com.sun.hotspot.igv.view;
25 
26 import com.sun.hotspot.igv.data.InputGraph;
27 import com.sun.hotspot.igv.data.services.GraphViewer;
28 import com.sun.hotspot.igv.graph.Diagram;
29 import com.sun.hotspot.igv.settings.Settings;
30 import org.openide.windows.Mode;
31 import org.openide.windows.TopComponent;
32 import org.openide.windows.WindowManager;
33 
34 /**
35  *
36  * @author Thomas Wuerthinger
37  */
38 public class GraphViewerImplementation implements GraphViewer {
39 
40     @Override
view(InputGraph graph, boolean clone)41     public void view(InputGraph graph, boolean clone) {
42 
43         if (!clone) {
44             WindowManager manager = WindowManager.getDefault();
45             for (Mode m : manager.getModes()) {
46                 for (TopComponent t : manager.getOpenedTopComponents(m)) {
47                     if (t instanceof EditorTopComponent) {
48                         EditorTopComponent etc = (EditorTopComponent) t;
49                         if (etc.getModel().getGroup().getGraphs().contains(graph)) {
50                             etc.getModel().selectGraph(graph);
51                             t.requestActive();
52                             return;
53                         }
54                     }
55                 }
56             }
57         }
58 
59         Diagram diagram = Diagram.createDiagram(graph, Settings.get().get(Settings.NODE_TEXT, Settings.NODE_TEXT_DEFAULT));
60         EditorTopComponent tc = new EditorTopComponent(diagram);
61         tc.open();
62         tc.requestActive();
63     }
64 }
65