blob: 070017377135053c37c104575ab831664cc87ab9 [file] [log] [blame]
Simon Hunta17fa672015-08-19 18:42:22 -07001/*
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
18package org.onosproject.ui.topo;
19
Simon Hunta17fa672015-08-19 18:42:22 -070020import java.util.Collections;
21import java.util.HashSet;
22import java.util.Set;
23
Simon Hunt743a8492015-08-25 16:18:19 -070024import static com.google.common.base.Preconditions.checkNotNull;
25
Simon Hunta17fa672015-08-19 18:42:22 -070026/**
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 */
31public class Highlights {
32
Simon Hunt743a8492015-08-25 16:18:19 -070033 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 Hunta17fa672015-08-19 18:42:22 -070056 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 Hunt743a8492015-08-25 16:18:19 -070060 private Amount subdueLevel = Amount.ZERO;
Simon Hunta17fa672015-08-19 18:42:22 -070061
Simon Hunt743a8492015-08-25 16:18:19 -070062
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 Hunta17fa672015-08-19 18:42:22 -070071 return this;
72 }
73
Simon Hunt743a8492015-08-25 16:18:19 -070074 /**
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 Hunta17fa672015-08-19 18:42:22 -070082 return this;
83 }
84
Simon Hunt743a8492015-08-25 16:18:19 -070085 /**
86 * Adds highlighting information for a link.
87 *
88 * @param lh link highlight
89 * @return self, for chaining
90 */
Simon Hunta17fa672015-08-19 18:42:22 -070091 public Highlights add(LinkHighlight lh) {
92 links.add(lh);
93 return this;
94 }
95
Simon Hunt743a8492015-08-25 16:18:19 -070096 /**
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 Hunta17fa672015-08-19 18:42:22 -0700107
Simon Hunt743a8492015-08-25 16:18:19 -0700108 /**
109 * Returns the set of device highlights.
110 *
111 * @return device highlights
112 */
Simon Hunta17fa672015-08-19 18:42:22 -0700113 public Set<DeviceHighlight> devices() {
114 return Collections.unmodifiableSet(devices);
115 }
116
Simon Hunt743a8492015-08-25 16:18:19 -0700117 /**
118 * Returns the set of host highlights.
119 *
120 * @return host highlights
121 */
Simon Hunta17fa672015-08-19 18:42:22 -0700122 public Set<HostHighlight> hosts() {
123 return Collections.unmodifiableSet(hosts);
124 }
125
Simon Hunt743a8492015-08-25 16:18:19 -0700126 /**
127 * Returns the set of link highlights.
128 *
129 * @return link highlights
130 */
Simon Hunta17fa672015-08-19 18:42:22 -0700131 public Set<LinkHighlight> links() {
132 return Collections.unmodifiableSet(links);
133 }
Simon Hunt743a8492015-08-25 16:18:19 -0700134
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 Hunta17fa672015-08-19 18:42:22 -0700144}