KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > helloworld > renderer > HwTreeRenderer


1 /*******************************************************************************
2  * Copyright (c) 2004, Dirk von der Weiden.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * Dirk von der Weiden - initial API and implementation
10  *
11  * Created on 21.02.2005
12  *
13  * date: 21.02.2005
14  * project: WiSer-HelloWorld
15  *
16  * *******************************************************************************/

17
18 package helloworld.renderer;
19
20 import java.awt.*;
21 import javax.swing.tree.*;
22
23 import Jmc.commonGui.*;
24 import Jmc.commonGui.loader.*;
25 import Jmc.baseGui.gui_fixedSize;
26 import Jmc.baseTools.*;
27
28 /**
29  * @author Dirk
30  *
31  * date: 21.02.2005
32  *
33  * <p>
34  * Purpose: This example shows how the render mechanism of the WidgetServer framework
35  * works.
36  * </p>
37  */

38 public class HwTreeRenderer implements base_treeItemRenderer_if
39 {
40   /**
41      * <p>
42      * Renderes a list item
43      * </p><p>
44      *
45      * @return rendered widget
46      * </p><p>
47      * @param xToRender object wich has to be rendered
48      * @param xSelect selection state within the view
49      * @param xTree treeView widget
50      * </p>
51      */

52   public base_guiWidget_if pcmf_getRenderWidget(Object JavaDoc xToRender, boolean xSelected, base_treeView_if xTree)
53   {
54         // get all relevant widgets from the registry
55
base_appl_if l_appl = (base_appl_if)base_registredObject.pcmf_getObjByName(base_appl_if.MY_APPL);
56     base_image_if l_img = (base_image_if)base_registredObject.pcmf_getObjByName("root_icon");
57     
58     // create a textfield
59
base_text_if l_text = l_appl.pcmf_getGuiObjFactory().pcmf_createText(l_appl.pcmf_getApplType(), xToRender.toString(), "-" + xToRender.toString(), l_appl);
60
61     l_text.pcmf_setFont(new base_fontDesc("ARIAL", 12, Font.BOLD));
62     l_text.pcmf_setBorder(2);
63     
64     // separate nodes by pth length
65
if (((DefaultMutableTreeNode)xToRender).getPath().length % 2 == 0)
66       l_text.pcmf_setBgColor("#FFA000");
67     else
68       l_text.pcmf_setBgColor("#A0A000");
69     
70     l_text.pcmf_setFixedSize(150, 20, gui_fixedSize.FIX_SIZE);
71     l_text.pcmf_setIcon(l_img);
72     
73     // render the node independently from its hidden state
74
l_text.pcmf_setRenderIfHidden(true);
75     
76     return (l_text);
77   }
78 }
79
Popular Tags