Mercurial > hg > truffle
comparison visualizer/Filter/src/com/sun/hotspot/igv/filter/RemoveInputsFilter.java @ 4512:015fb895586b
Moved visualizer to new directory.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Tue, 07 Feb 2012 22:41:09 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
4511:6cb549627941 | 4512:015fb895586b |
---|---|
1 /* | |
2 * Copyright (c) 2008, 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.filter; | |
25 | |
26 import com.sun.hotspot.igv.graph.*; | |
27 import java.util.ArrayList; | |
28 import java.util.List; | |
29 | |
30 /** | |
31 * | |
32 * @author Thomas Wuerthinger | |
33 */ | |
34 public class RemoveInputsFilter extends AbstractFilter { | |
35 | |
36 private List<RemoveInputsRule> rules; | |
37 private String name; | |
38 | |
39 public RemoveInputsFilter(String name) { | |
40 this.name = name; | |
41 rules = new ArrayList<>(); | |
42 } | |
43 | |
44 @Override | |
45 public String getName() { | |
46 return name; | |
47 } | |
48 | |
49 @Override | |
50 public void apply(Diagram diagram) { | |
51 | |
52 for (RemoveInputsRule r : rules) { | |
53 | |
54 List<Figure> list = r.getSelector().selected(diagram); | |
55 for (Figure f : list) { | |
56 int z = 0; | |
57 List<InputSlot> last = new ArrayList<>(); | |
58 for (InputSlot is : f.getInputSlots()) { | |
59 if (z >= r.getStartingIndex() && z <= r.getEndIndex() && is.getConnections().size() > 0) { | |
60 StringBuilder sb = new StringBuilder(); | |
61 List<Connection> conns = is.getConnections(); | |
62 for (int i = 0; i < conns.size(); i++) { | |
63 Connection c = conns.get(i); | |
64 OutputSlot os = c.getOutputSlot(); | |
65 Figure pred = os.getFigure(); | |
66 if (i != 0) { | |
67 sb.append("<BR>"); | |
68 } | |
69 sb.append(pred.getLines()[0]); | |
70 } | |
71 is.removeAllConnections(); | |
72 is.setShortName("X"); | |
73 is.setText(sb.toString()); | |
74 last.add(is); | |
75 } else { | |
76 last.clear(); | |
77 } | |
78 z++; | |
79 } | |
80 | |
81 if (last.size() > 3) { | |
82 InputSlot first = last.get(0); | |
83 first.setShortName("XX"); | |
84 | |
85 StringBuilder sb = new StringBuilder(); | |
86 for (int i = 0; i < last.size(); i++) { | |
87 InputSlot is2 = last.get(i); | |
88 if (i != 0) { | |
89 sb.append("<BR>"); | |
90 } | |
91 sb.append(is2.getText()); | |
92 } | |
93 | |
94 first.setText(sb.toString()); | |
95 | |
96 for (int i = 1; i < last.size(); i++) { | |
97 f.removeSlot(last.get(i)); | |
98 } | |
99 } | |
100 } | |
101 } | |
102 } | |
103 | |
104 public void addRule(RemoveInputsRule rule) { | |
105 rules.add(rule); | |
106 } | |
107 | |
108 public static class RemoveInputsRule { | |
109 | |
110 private Selector selector; | |
111 private int startingIndex; | |
112 private int endIndex; | |
113 | |
114 public RemoveInputsRule(Selector selector) { | |
115 this(selector, 0); | |
116 } | |
117 | |
118 public RemoveInputsRule(Selector selector, int startIndex) { | |
119 this(selector, startIndex, Integer.MAX_VALUE); | |
120 } | |
121 | |
122 public RemoveInputsRule(Selector selector, int startIndex, int endIndex) { | |
123 this.startingIndex = startIndex; | |
124 this.endIndex = endIndex; | |
125 this.selector = selector; | |
126 } | |
127 | |
128 public int getStartingIndex() { | |
129 return startingIndex; | |
130 } | |
131 | |
132 public int getEndIndex() { | |
133 return endIndex; | |
134 } | |
135 | |
136 public Selector getSelector() { | |
137 return selector; | |
138 } | |
139 } | |
140 } |