Source code: org/altara/mars/swingui/FaultListRenderer.java
1 /* MARS Network Monitor Swing User Interface
2 Copyright (C) 1999 Brian H. Trammell
3 Copyright (C) 2002 Leapfrog Research & Development, LLC
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, it is available at
17 http:///www.gnu.org/copyleft/gpl.html, or by writing to the
18 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
20 */
21
22 package org.altara.mars.swingui;
23
24 import org.altara.util.*;
25 import org.altara.mars.*;
26 import org.altara.mars.engine.*;
27 import java.util.*;
28 import java.awt.*;
29 import java.awt.event.*;
30 import javax.swing.*;
31 import javax.swing.tree.*;
32 import javax.swing.event.*;
33
34 /** Renders faults in the faultList.
35 */
36
37 public class FaultListRenderer extends MarsAbstractRenderer {
38
39 private FaultListModel model;
40
41 public FaultListRenderer(FaultListModel model) {
42 super();
43 this.model = model;
44 }
45
46 protected Icon getIconForValue(Object value) {
47 if (value instanceof String) {
48 // string is either "no faults" or "not monitoring"
49 // select based upon controller status
50 if (Main.getMain().getController().isActive()) {
51 if (model.countHiddenFaults() == 0) {
52 return upIcon;
53 } else {
54 return timeoutIcon;
55 }
56 } else {
57 return unknownIcon;
58 }
59 } else {
60 // Fault list entries are faulted services. Cast the service and
61 // get its status to determine the icon.
62 return getIconForStatus(((Service)value).getStatus());
63 }
64 }
65
66 protected String getStringForValue(Object value) {
67 // check for all is well message.
68 if (value instanceof String) return (String)value;
69
70 // Fault list entries are faulted services. Get the service and
71 // its status.
72 Service service = (Service)value;
73 Status status = service.getStatus();
74 Host host = service.getHost();
75
76 return service.getName()+" on "+host.getName()+
77 ":"+service.getPort()+": "+status.toString();
78 }
79 }