Source code: org/altara/mars/swingui/ServiceTreeRenderer.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.mars.*;
25 import org.altara.mars.engine.*;
26 import java.util.*;
27 import java.awt.*;
28 import java.awt.event.*;
29 import javax.swing.*;
30 import javax.swing.tree.*;
31 import javax.swing.event.*;
32
33 /** Renders tree cells in the serviceTree.
34 */
35
36 public class ServiceTreeRenderer extends MarsAbstractRenderer {
37
38 public ServiceTreeRenderer() {
39 super();
40 }
41
42 protected Icon getIconForValue(Object value) {
43 // return a host icon if it's a MarsModel
44 // this should never be displayed.
45 if (value instanceof MarsModel) return okHostIcon;
46
47 boolean isActive = Main.getMain().getController().isActive();
48
49 if (value instanceof Host) {
50 if (isActive) {
51 return getIconForHost((Host)value);
52 } else {
53 return okHostIcon;
54 }
55 } else {
56 if (isActive) {
57 return getIconForStatus(((Service)value).getStatus());
58 } else {
59 return serviceIcon;
60 }
61 }
62 }
63
64 protected String getStringForValue(Object value) {
65 // return a root node label if it's a MarsModel
66 // this should never be displayed.
67 if (value instanceof MarsModel) return "<root>";
68
69 // return hostname if the node is a host
70 if (value instanceof Host) return ((Host)value).getName();
71
72 // it's a service. build a general service description no matter what
73 Service service = (Service)value;
74 // show status if running
75 String out = service.getName();
76 if (Main.getMain().getController().isActive()) {
77 out += ": "+service.getStatus().toString();
78 }
79 return out;
80 }
81 }