001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package com.sun.rave.web.ui.component;
042:
043: import java.util.Comparator;
044:
045: /**
046: * <p>Defines a component for displaying an alarm icon based on the
047: * alarm seveirty.</p>
048: */
049: public class Alarm extends AlarmBase implements Comparator {
050:
051: /** Severity of an alarm. */
052: public static final String SEVERITY_DOWN = "down";
053: public static final String SEVERITY_CRITICAL = "critical";
054: public static final String SEVERITY_MAJOR = "major";
055: public static final String SEVERITY_MINOR = "minor";
056: public static final String SEVERITY_OK = "ok";
057:
058: public static final String DEFAULT_SEVERITY = SEVERITY_OK;
059:
060: // Severity level of an alarm.
061: private final int SEVERITY_LEVEL_DOWN = 1;
062: private final int SEVERITY_LEVEL_CRITICAL = 2;
063: private final int SEVERITY_LEVEL_MAJOR = 3;
064: private final int SEVERITY_LEVEL_MINOR = 4;
065: private final int SEVERITY_LEVEL_OK = 5;
066:
067: /** Default constructor. */
068: public Alarm() {
069: }
070:
071: /** Create an instance with the given severity. */
072: public Alarm(String severity) {
073: setSeverity(severity);
074: }
075:
076: /**
077: * Compare the given objects for severity order.
078: */
079: public int compare(Object o1, Object o2) throws ClassCastException {
080: int s1 = getSeverityLevel((Alarm) o1);
081: int s2 = getSeverityLevel((Alarm) o2);
082: return (s1 > s2) ? -1 : s1 == s2 ? 0 : 1;
083: }
084:
085: /**
086: * Indicates whether some other object is "equal to" this Comparator.
087: */
088: public boolean equals(Object o) throws ClassCastException {
089: int s1 = getSeverityLevel(this );
090: int s2 = getSeverityLevel((Alarm) o);
091: return (s1 == s2);
092: }
093:
094: /**
095: * Helper method to get the severity level of an alarm.
096: */
097: private int getSeverityLevel(Alarm alarm) {
098: int severity = SEVERITY_LEVEL_OK;
099: if (alarm.getSeverity().equals(SEVERITY_DOWN)) {
100: severity = SEVERITY_LEVEL_DOWN;
101: } else if (alarm.getSeverity().equals(SEVERITY_CRITICAL)) {
102: severity = SEVERITY_LEVEL_CRITICAL;
103: } else if (alarm.getSeverity().equals(SEVERITY_MAJOR)) {
104: severity = SEVERITY_LEVEL_MAJOR;
105: } else if (alarm.getSeverity().equals(SEVERITY_MINOR)) {
106: severity = SEVERITY_LEVEL_MINOR;
107: }
108: return severity;
109: }
110: }
|