001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc;
005:
006: import com.tc.admin.common.XTreeCellRenderer;
007: import com.tc.admin.common.XTreeNode;
008:
009: import java.awt.Color;
010: import java.awt.FontMetrics;
011: import java.awt.Graphics;
012: import java.net.URL;
013:
014: import javax.swing.ImageIcon;
015: import javax.swing.SwingUtilities;
016:
017: public class WebAppLinkNode extends XTreeNode {
018: private static ImageIcon ICON;
019:
020: static {
021: String uri = "/com/tc/admin/icons/occ_match.gif";
022: URL url = WebAppLinkNode.class.getResource(uri);
023:
024: if (url != null) {
025: ICON = new ImageIcon(url);
026: }
027: }
028:
029: private boolean m_ready;
030: private boolean m_armed;
031:
032: public WebAppLinkNode(String path) {
033: super (path);
034:
035: setRenderer(new WebAppLinkNodeRenderer(this ));
036: setIcon(ICON);
037: setReady(false);
038: }
039:
040: public String getLink() {
041: return (String) getUserObject();
042: }
043:
044: public void setReady(boolean isReady) {
045: m_ready = isReady;
046:
047: WebAppLinkNodeRenderer walnr = (WebAppLinkNodeRenderer) getRenderer();
048: walnr.getComponent().setEnabled(isReady);
049: setArmed(m_armed);
050: }
051:
052: public boolean isReady() {
053: return m_ready;
054: }
055:
056: Color getColor() {
057: Color c = null;
058:
059: if (isReady()) {
060: c = isArmed() ? Color.red : Color.blue;
061: }
062:
063: return c;
064: }
065:
066: public void setArmed(boolean armed) {
067: m_armed = armed;
068: WebAppLinkNodeRenderer walnr = (WebAppLinkNodeRenderer) getRenderer();
069: Color fg = getColor();
070: walnr.setTextSelectionColor(fg);
071: walnr.setTextNonSelectionColor(fg);
072: nodeChanged();
073: }
074:
075: public boolean isArmed() {
076: return m_armed;
077: }
078: }
079:
080: class WebAppLinkNodeRenderer extends XTreeCellRenderer {
081: private WebAppLinkNode m_node;
082:
083: public WebAppLinkNodeRenderer(WebAppLinkNode node) {
084: super ();
085:
086: m_node = node;
087:
088: drawDashedFocusIndicator = false;
089: backgroundSelectionColor = getBackgroundNonSelectionColor();
090: borderSelectionColor = null;
091: textSelectionColor = node.getColor();
092: textNonSelectionColor = textSelectionColor;
093: }
094:
095: protected Renderer createRenderer() {
096: return new WebLinkRenderer();
097: }
098:
099: class WebLinkRenderer extends Renderer {
100: WebLinkRenderer() {
101: super ();
102: }
103:
104: public void paint(Graphics g) {
105: super .paint(g);
106:
107: if (m_node.isReady() && !m_node.isArmed()) {
108: FontMetrics fm = g.getFontMetrics();
109: String text = getText();
110: int x = getLabelStart();
111: int y = getHeight();
112: int w = SwingUtilities.computeStringWidth(fm, text);
113: int h = 1;
114:
115: g.fillRect(x, y - 1, w, h);
116: }
117: }
118: }
119: }
|