Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 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 | */ |
| 17 | |
| 18 | package org.onosproject.ui.topo; |
| 19 | |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 20 | import java.util.Collections; |
| 21 | import java.util.HashSet; |
| 22 | import java.util.Set; |
| 23 | |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame^] | 24 | import static com.google.common.base.Preconditions.checkNotNull; |
| 25 | |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 26 | /** |
| 27 | * Encapsulates highlights to be applied to the topology view, such as |
| 28 | * highlighting links, displaying link labels, perhaps even decorating |
| 29 | * nodes with badges, etc. |
| 30 | */ |
| 31 | public class Highlights { |
| 32 | |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame^] | 33 | private static final String EMPTY = ""; |
| 34 | private static final String MIN = "min"; |
| 35 | private static final String MAX = "max"; |
| 36 | |
| 37 | /** |
| 38 | * A notion of amount. |
| 39 | */ |
| 40 | public enum Amount { |
| 41 | ZERO(EMPTY), |
| 42 | MINIMALLY(MIN), |
| 43 | MAXIMALLY(MAX); |
| 44 | |
| 45 | private final String s; |
| 46 | Amount(String str) { |
| 47 | s = str; |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public String toString() { |
| 52 | return s; |
| 53 | } |
| 54 | } |
| 55 | |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 56 | private final Set<DeviceHighlight> devices = new HashSet<>(); |
| 57 | private final Set<HostHighlight> hosts = new HashSet<>(); |
| 58 | private final Set<LinkHighlight> links = new HashSet<>(); |
| 59 | |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame^] | 60 | private Amount subdueLevel = Amount.ZERO; |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 61 | |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame^] | 62 | |
| 63 | /** |
| 64 | * Adds highlighting information for a device. |
| 65 | * |
| 66 | * @param dh device highlight |
| 67 | * @return self, for chaining |
| 68 | */ |
| 69 | public Highlights add(DeviceHighlight dh) { |
| 70 | devices.add(dh); |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 71 | return this; |
| 72 | } |
| 73 | |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame^] | 74 | /** |
| 75 | * Adds highlighting information for a host. |
| 76 | * |
| 77 | * @param hh host highlight |
| 78 | * @return self, for chaining |
| 79 | */ |
| 80 | public Highlights add(HostHighlight hh) { |
| 81 | hosts.add(hh); |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 82 | return this; |
| 83 | } |
| 84 | |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame^] | 85 | /** |
| 86 | * Adds highlighting information for a link. |
| 87 | * |
| 88 | * @param lh link highlight |
| 89 | * @return self, for chaining |
| 90 | */ |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 91 | public Highlights add(LinkHighlight lh) { |
| 92 | links.add(lh); |
| 93 | return this; |
| 94 | } |
| 95 | |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame^] | 96 | /** |
| 97 | * Marks the amount by which all other elements (devices, hosts, links) |
| 98 | * not explicitly referenced here will be "subdued" visually. |
| 99 | * |
| 100 | * @param amount amount to subdue other elements |
| 101 | * @return self, for chaining |
| 102 | */ |
| 103 | public Highlights subdueAllElse(Amount amount) { |
| 104 | subdueLevel = checkNotNull(amount); |
| 105 | return this; |
| 106 | } |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 107 | |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame^] | 108 | /** |
| 109 | * Returns the set of device highlights. |
| 110 | * |
| 111 | * @return device highlights |
| 112 | */ |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 113 | public Set<DeviceHighlight> devices() { |
| 114 | return Collections.unmodifiableSet(devices); |
| 115 | } |
| 116 | |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame^] | 117 | /** |
| 118 | * Returns the set of host highlights. |
| 119 | * |
| 120 | * @return host highlights |
| 121 | */ |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 122 | public Set<HostHighlight> hosts() { |
| 123 | return Collections.unmodifiableSet(hosts); |
| 124 | } |
| 125 | |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame^] | 126 | /** |
| 127 | * Returns the set of link highlights. |
| 128 | * |
| 129 | * @return link highlights |
| 130 | */ |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 131 | public Set<LinkHighlight> links() { |
| 132 | return Collections.unmodifiableSet(links); |
| 133 | } |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame^] | 134 | |
| 135 | /** |
| 136 | * Returns the amount by which all other elements not explicitly |
| 137 | * referenced here should be "subdued". |
| 138 | * |
| 139 | * @return amount to subdue other elements |
| 140 | */ |
| 141 | public Amount subdueLevel() { |
| 142 | return subdueLevel; |
| 143 | } |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 144 | } |