1 14 package org.wings; 15 16 20 public class SDefaultListCellRenderer extends SLabel implements SListCellRenderer { 21 22 25 protected String selectionStyle = null; 26 27 30 protected String nonSelectionStyle = null; 31 32 35 public SDefaultListCellRenderer() { 36 } 37 38 39 42 public void setSelectionStyle(String newStyle) { 43 selectionStyle = newStyle; 44 } 45 46 49 public String getSelectionStyle() { 50 return selectionStyle; 51 } 52 53 56 public void setNonSelectionStyle(String newStyle) { 57 nonSelectionStyle = newStyle; 58 } 59 60 63 public String getNonSelectionStyle() { 64 return nonSelectionStyle; 65 } 66 67 68 public SComponent getListCellRendererComponent(SComponent list, Object value, boolean selected, int index) { 69 setText(null); 70 setIcon(null); 71 72 if (value == null) 73 setText(""); 74 else if (value instanceof SIcon) 75 setIcon((SIcon) value); 76 else if (value instanceof SComponent) { 77 SComponent result = (SComponent) value; 78 79 if (selected && selectionStyle != null) { 80 result.setStyle(selectionStyle); 81 } else { 82 result.setStyle(nonSelectionStyle); 83 } 84 85 return result; 86 } else { 87 setText(value.toString()); 88 } 89 90 if (selected && selectionStyle != null) { 91 setStyle(selectionStyle); 92 } else { 93 setStyle(nonSelectionStyle); 94 } 95 96 return this; 97 } 98 } 99 100 101 | Popular Tags |