|
1 /* |
|
2 * CDDL HEADER START |
|
3 * |
|
4 * The contents of this file are subject to the terms of the |
|
5 * Common Development and Distribution License (the "License"). |
|
6 * You may not use this file except in compliance with the License. |
|
7 * |
|
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 * or http://www.opensolaris.org/os/licensing. |
|
10 * See the License for the specific language governing permissions |
|
11 * and limitations under the License. |
|
12 * |
|
13 * When distributing Covered Code, include this CDDL HEADER in each |
|
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 * If applicable, add the following below this CDDL HEADER, with the |
|
16 * fields enclosed by brackets "[]" replaced with your own identifying |
|
17 * information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 * |
|
19 * CDDL HEADER END |
|
20 */ |
|
21 |
|
22 /* |
|
23 * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. |
|
24 */ |
|
25 |
|
26 package com.oracle.solaris.vp.panel.swing.view; |
|
27 |
|
28 import java.util.*; |
|
29 import javax.swing.*; |
|
30 import com.oracle.solaris.vp.panel.common.model.ManagedObjectStatus; |
|
31 import com.oracle.solaris.vp.util.misc.IconUtil; |
|
32 import com.oracle.solaris.vp.util.misc.finder.Finder; |
|
33 import com.oracle.solaris.vp.util.swing.*; |
|
34 |
|
35 public enum Health implements HasIcons, HasIcon { |
|
36 // |
|
37 // Values |
|
38 // |
|
39 |
|
40 HEALTHY, WARNING, ERROR, DISABLED; |
|
41 |
|
42 // |
|
43 // Instance data |
|
44 // |
|
45 |
|
46 private List<ImageIcon> icons; |
|
47 private List<ImageIcon> roIcons; |
|
48 |
|
49 // |
|
50 // Constructors |
|
51 // |
|
52 |
|
53 Health() { |
|
54 String name = toString().toLowerCase(); |
|
55 icons = Finder.getIcons( |
|
56 "images/health/" + name + "-16.png", |
|
57 "images/health/" + name + "-24.png", |
|
58 "images/health/" + name + "-32.png"); |
|
59 roIcons = Collections.unmodifiableList(icons); |
|
60 } |
|
61 |
|
62 // |
|
63 // HasIcon methods |
|
64 // |
|
65 |
|
66 @Override |
|
67 public Icon getIcon(int height) { |
|
68 return IconUtil.getClosestIcon(getIcons(), height); |
|
69 } |
|
70 |
|
71 // |
|
72 // HasIcons methods |
|
73 // |
|
74 |
|
75 @Override |
|
76 public List<? extends Icon> getIcons() { |
|
77 return roIcons; |
|
78 } |
|
79 |
|
80 // |
|
81 // Static methods |
|
82 // |
|
83 |
|
84 public static Health fromManagedObjectStatus(ManagedObjectStatus status, |
|
85 boolean enabled) { |
|
86 |
|
87 switch (status) { |
|
88 case HEALTHY: |
|
89 return (enabled ? HEALTHY : DISABLED); |
|
90 case WARNING: |
|
91 return (WARNING); |
|
92 case ERROR: |
|
93 return (ERROR); |
|
94 } |
|
95 /* Shouldn't happen */ |
|
96 return (ERROR); |
|
97 } |
|
98 } |