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 */ 24package com.sun.hotspot.igv.filter; 25 26import com.sun.hotspot.igv.data.Properties; 27import com.sun.hotspot.igv.graph.*; 28import java.awt.Color; 29import java.util.ArrayList; 30import java.util.List; 31 32/** 33 * 34 * @author Thomas Wuerthinger 35 */ 36public class ConnectionFilter extends AbstractFilter { 37 38 private List<ConnectionStyleRule> connectionStyleRules; 39 private String name; 40 41 public ConnectionFilter(String name) { 42 this.name = name; 43 connectionStyleRules = new ArrayList<>(); 44 } 45 46 @Override 47 public String getName() { 48 return name; 49 } 50 51 @Override 52 public void apply(Diagram diagram) { 53 54 Properties.PropertySelector<Figure> selector = new Properties.PropertySelector<>(diagram.getFigures()); 55 for (ConnectionStyleRule rule : connectionStyleRules) { 56 List<Figure> figures = null; 57 if (rule.getSelector() != null) { 58 figures = rule.getSelector().selected(diagram); 59 } else { 60 figures = diagram.getFigures(); 61 } 62 63 for (Figure f : figures) { 64 for (OutputSlot os : f.getOutputSlots()) { 65 for (Connection c : os.getConnections()) { 66 if (figures.contains(c.getInputSlot().getFigure())) { 67 c.setStyle(rule.getLineStyle()); 68 c.setColor(rule.getLineColor()); 69 } 70 } 71 } 72 } 73 } 74 } 75 76 public void addRule(ConnectionStyleRule r) { 77 connectionStyleRules.add(r); 78 } 79 80 public static class ConnectionStyleRule { 81 82 private Color lineColor; 83 private Connection.ConnectionStyle lineStyle; 84 private Selector selector; 85 86 public ConnectionStyleRule(Selector selector, Color lineColor, Connection.ConnectionStyle lineStyle) { 87 this.selector = selector; 88 this.lineColor = lineColor; 89 this.lineStyle = lineStyle; 90 } 91 92 public Selector getSelector() { 93 return selector; 94 } 95 96 public Color getLineColor() { 97 return lineColor; 98 } 99 100 public Connection.ConnectionStyle getLineStyle() { 101 return lineStyle; 102 } 103 } 104} 105