Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.pathpainter; |
| 17 | |
| 18 | import org.onosproject.net.Link; |
| 19 | import org.onosproject.net.LinkKey; |
| 20 | import org.onosproject.ui.topo.BiLink; |
| 21 | import org.onosproject.ui.topo.LinkHighlight; |
| 22 | import org.onosproject.ui.topo.LinkHighlight.Flavor; |
| 23 | |
| 24 | import java.util.Set; |
| 25 | |
| 26 | /** |
| 27 | * Bi-directional link capable of different hilights. |
| 28 | */ |
| 29 | public class PathLink extends BiLink { |
| 30 | |
| 31 | private boolean primary = false; |
| 32 | private boolean secondary = false; |
| 33 | |
| 34 | public PathLink(LinkKey key, Link link) { |
| 35 | super(key, link); |
| 36 | } |
| 37 | |
| 38 | public void computeHilight(Set<Link> selectedLinks, Set<Link> allLinks) { |
| 39 | primary = selectedLinks.contains(this.one()) || |
| 40 | (two() != null && selectedLinks.contains(two())); |
| 41 | secondary = allLinks.contains(this.one()) || |
| 42 | (two() != null && allLinks.contains(two())); |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | public LinkHighlight highlight(Enum<?> anEnum) { |
| 47 | Flavor flavor = primary ? Flavor.PRIMARY_HIGHLIGHT : |
| 48 | (secondary ? Flavor.SECONDARY_HIGHLIGHT : Flavor.NO_HIGHLIGHT); |
| 49 | return new LinkHighlight(this.linkId(), flavor); |
| 50 | } |
| 51 | } |