001: /*
002: * Copyright (C) 2005 Jeff Tassin
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package com.jeta.swingbuilder.gui.formmgr;
020:
021: import java.awt.Component;
022: import java.awt.FlowLayout;
023:
024: import javax.swing.ImageIcon;
025: import javax.swing.JLabel;
026: import javax.swing.JTree;
027: import javax.swing.UIManager;
028: import javax.swing.tree.DefaultMutableTreeNode;
029: import javax.swing.tree.TreeCellRenderer;
030:
031: import com.jeta.forms.gui.form.FormComponent;
032: import com.jeta.swingbuilder.gui.utils.FormDesignerUtils;
033:
034: /**
035: * This is the renderer for objects in the FormsTree. This is only used during
036: * debugging.
037: *
038: * @author Jeff Tassin
039: */
040: public class FormsTreeRenderer extends JLabel implements
041: TreeCellRenderer {
042: private static ImageIcon m_embedded_icon;
043: private static ImageIcon m_linked_icon;
044:
045: static {
046: m_embedded_icon = FormDesignerUtils
047: .loadImage("forms/form_control_embedded.gif");
048: m_linked_icon = FormDesignerUtils
049: .loadImage("forms/form_control_linked.gif");
050: }
051:
052: /**
053: * ctor
054: */
055: public FormsTreeRenderer() {
056: super ("");
057: initialize();
058: }
059:
060: public Component getTreeCellRendererComponent(JTree tree,
061: Object value, boolean sel, boolean expanded, boolean leaf,
062: int row, boolean hasFocus) {
063: DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
064: Object obj = node.getUserObject();
065: if (obj instanceof FormComponent) {
066: FormComponent fc = (FormComponent) obj;
067:
068: if (sel) {
069: setForeground(UIManager
070: .getColor("Tree.selectionForeground"));
071: setBackground(UIManager
072: .getColor("Tree.selectionBackground"));
073: setOpaque(true);
074: } else {
075: setBackground(UIManager.getColor("Tree.background"));
076: setForeground(UIManager.getColor("Tree.foreground"));
077: setOpaque(false);
078: }
079:
080: if (fc.isEmbedded())
081: setIcon(m_embedded_icon);
082: else
083: setIcon(m_linked_icon);
084:
085: setText(fc.getId());
086: } else {
087: if (obj == null)
088: setText("null");
089: else
090: setText(obj.toString());
091: }
092: return this ;
093: }
094:
095: public void initialize() {
096: setLayout(new FlowLayout());
097: setFont(UIManager.getFont("Tree.font"));
098: }
099:
100: public java.awt.Font getFont() {
101: return UIManager.getFont("Tree.font");
102: }
103:
104: }
|