01: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
02: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
03: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
04: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
05: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
06: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
07: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
08: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
09: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
10: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
11: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
12: // POSSIBILITY OF SUCH DAMAGE.
13: //
14: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
15: package com.metaboss.applications.designstudio.designtree;
16:
17: import javax.swing.Icon;
18: import javax.swing.JTree;
19: import javax.swing.UIManager;
20: import javax.swing.tree.DefaultMutableTreeNode;
21: import javax.swing.tree.DefaultTreeCellRenderer;
22:
23: import com.metaboss.applications.designstudio.Application;
24: import com.metaboss.applications.designstudio.BaseUserObject;
25:
26: public class DesignTreeCellRenderer extends DefaultTreeCellRenderer {
27: public java.awt.Component getTreeCellRendererComponent(JTree tree,
28: Object value, boolean sel, boolean expanded, boolean leaf,
29: int row, boolean hasFocus)
30:
31: {
32: boolean lDoDefault = true;
33: BaseUserObject lUserObject = null;
34:
35: if (value instanceof DefaultMutableTreeNode) {
36: DefaultMutableTreeNode lTreeNode = (DefaultMutableTreeNode) value;
37: Object lObject = lTreeNode.getUserObject();
38: if (lObject instanceof BaseUserObject) {
39: lUserObject = (BaseUserObject) lObject;
40:
41: setLeafIcon(getRightIcon(lUserObject, lUserObject
42: .getIcon()));
43: setOpenIcon(getRightIcon(lUserObject, lUserObject
44: .getOpenIcon()));
45: setClosedIcon(getRightIcon(lUserObject, lUserObject
46: .getClosedIcon()));
47: lDoDefault = false;
48: }
49: }
50: if (lDoDefault) {
51: setLeafIcon(getRightIcon(lUserObject, UIManager
52: .getIcon("Tree.leafIcon")));
53: setOpenIcon(getRightIcon(lUserObject, UIManager
54: .getIcon("Tree.openIcon")));
55: setClosedIcon(getRightIcon(lUserObject, UIManager
56: .getIcon("Tree.closedIcon")));
57: }
58: setFont(Application.DEFAULT_FONT);
59: return super .getTreeCellRendererComponent(tree, value, sel,
60: expanded, leaf, row, hasFocus);
61: }
62:
63: private Icon getRightIcon(BaseUserObject pObject, Icon pIcon) {
64: Icon lResult = pIcon;
65: if (pObject != null) {
66: if (pObject.getMode() == 0
67: && Application.isErrorElementID(pObject.getID()))
68: lResult = Application.getErrorIcon(lResult);
69: else if (pObject.mWarningCount > 0)
70: lResult = Application.getWarningIcon(lResult);
71: }
72: return lResult;
73: }
74: }
|