1 14 package org.wings.tree; 15 16 import org.wings.SComponent; 17 import org.wings.SConstants; 18 import org.wings.SIcon; 19 import org.wings.SLabel; 20 import org.wings.STree; 21 22 27 public class SDefaultTreeCellRenderer 28 extends SLabel 29 implements STreeCellRenderer { 30 34 transient protected SIcon closedIcon; 35 36 39 transient protected SIcon leafIcon; 40 41 44 transient protected SIcon openIcon; 45 46 49 public SDefaultTreeCellRenderer() { 50 setHorizontalAlignment(SConstants.LEFT); 51 setLeafIcon(getDefaultLeafIcon()); 52 setClosedIcon(getDefaultClosedIcon()); 53 setOpenIcon(getDefaultOpenIcon()); 54 } 55 56 60 public SIcon getDefaultOpenIcon() { 61 return getSession().getCGManager().getIcon("TreeCG.openIcon"); 62 } 63 64 68 public SIcon getDefaultClosedIcon() { 69 return getSession().getCGManager().getIcon("TreeCG.closedIcon"); 70 } 71 72 76 public SIcon getDefaultLeafIcon() { 77 return getSession().getCGManager().getIcon("TreeCG.leafIcon"); 78 } 79 80 83 public void setOpenIcon(SIcon newIcon) { 84 openIcon = newIcon; 85 } 86 87 90 public SIcon getOpenIcon() { 91 return openIcon; 92 } 93 94 97 public void setClosedIcon(SIcon newIcon) { 98 closedIcon = newIcon; 99 } 100 101 105 public SIcon getClosedIcon() { 106 return closedIcon; 107 } 108 109 112 public void setLeafIcon(SIcon newIcon) { 113 leafIcon = newIcon; 114 } 115 116 119 public SIcon getLeafIcon() { 120 return leafIcon; 121 } 122 123 126 protected String selectionStyle = null; 127 128 131 protected String nonSelectionStyle = null; 132 133 public SComponent getTreeCellRendererComponent(STree tree, 134 Object value, 135 boolean selected, 136 boolean expanded, 137 boolean leaf, 138 int row, 139 boolean hasFocus) { 140 141 if (value == null || value.toString() == null || 142 value.toString().length() == 0) { 143 144 setText(" "); 145 } else { 146 setText(value.toString()); 147 setToolTipText(value.toString()); 148 } 149 150 if (!tree.isEnabled()) { 151 setEnabled(false); 152 if (leaf) { 153 setDisabledIcon(getLeafIcon()); 154 } else if (expanded) { 155 setDisabledIcon(getOpenIcon()); 156 } else { 157 setDisabledIcon(getClosedIcon()); 158 } 159 } else { 160 setEnabled(true); 161 if (leaf) { 162 setIcon(getLeafIcon()); 163 } else if (expanded) { 164 setIcon(getOpenIcon()); 165 } else { 166 setIcon(getClosedIcon()); 167 } 168 } 169 170 if (style == null) 171 setStyle(tree.getStyle()); 172 if (dynamicStyles == null) 173 setDynamicStyles(tree.getDynamicStyles()); 174 175 return this; 176 } 177 178 181 public void setSelectionStyle(String newStyle) { 182 selectionStyle = newStyle; 183 } 184 185 188 public String getSelectionStyle() { 189 return selectionStyle; 190 } 191 192 195 public void setNonSelectionStyle(String newStyle) { 196 nonSelectionStyle = newStyle; 197 } 198 199 202 public String getNonSelectionStyle() { 203 return nonSelectionStyle; 204 } 205 206 } 207 208 209 | Popular Tags |