1 19 24 package org.openide.explorer.propertysheet; 25 26 import org.openide.awt.HtmlRenderer; 27 import org.openide.nodes.Node.*; 28 29 import java.awt.*; 30 31 import java.beans.FeatureDescriptor ; 32 33 import javax.swing.*; 34 import javax.swing.table.TableCellRenderer ; 35 36 37 42 final class SheetCellRenderer implements TableCellRenderer { 43 private RendererFactory factory = null; 44 private boolean tableUI; 45 boolean includeMargin = false; 46 private ReusablePropertyEnv reusableEnv; 47 private ReusablePropertyModel reusableModel; 48 boolean suppressButton = false; 49 int rbMax = 0; 50 private JLabel htmlLabel = HtmlRenderer.createLabel(); 51 52 SheetCellRenderer(boolean tableUI, ReusablePropertyEnv env, ReusablePropertyModel reusableModel) { 53 this.tableUI = tableUI; 54 this.reusableEnv = env; 55 this.reusableModel = reusableModel; 56 } 57 58 void setIncludeMargin(boolean val) { 59 includeMargin = val; 60 } 61 62 void setSuppressButton(boolean val) { 63 suppressButton = val; 64 } 65 66 void setRadioButtonMax(int i) { 67 rbMax = i; 68 } 69 70 public Component getTableCellRendererComponent( 71 JTable table, Object value, boolean selected, boolean hasFocus, int row, int column 72 ) { 73 FeatureDescriptor fd = (FeatureDescriptor ) value; 74 Component result; 75 76 selected |= (hasFocus && (table.getSelectedRow() == row)); 78 79 if (fd instanceof PropertySet) { 80 return null; 81 } else { 82 if (column == 0) { 83 String txt = ((Property) fd).getHtmlDisplayName(); 84 boolean isHtml = txt != null; 85 86 if (!isHtml) { 87 txt = fd.getDisplayName(); 88 } 89 90 JLabel lbl = htmlLabel; 91 92 HtmlRenderer.Renderer ren = (HtmlRenderer.Renderer) lbl; 93 94 ren.setHtml(isHtml); 95 96 lbl.setText(txt); 97 98 if (selected) { 99 lbl.setBackground(table.getSelectionBackground()); 100 lbl.setForeground(table.getSelectionForeground()); 101 } else { 102 lbl.setBackground(table.getBackground()); 103 lbl.setForeground(table.getForeground()); 104 } 105 106 lbl.setOpaque(selected); 107 108 if (includeMargin) { 109 lbl.setBorder( 110 BorderFactory.createMatteBorder(0, PropUtils.getMarginWidth() + 2, 0, 0, lbl.getBackground()) 111 ); 112 } else { 113 lbl.setBorder( 114 BorderFactory.createMatteBorder(0, PropUtils.getTextMargin(), 0, 0, lbl.getBackground()) 115 ); 116 } 117 118 Object o = fd.getValue("nameIcon"); 121 if (o instanceof Icon) { 122 lbl.setIcon((Icon) o); 123 } else if (o instanceof Image) { 124 lbl.setIcon(new ImageIcon((Image) o)); 125 } 126 127 result = lbl; 128 } else { 129 result = factory().getRenderer((Property) fd); 130 131 if (selected) { 132 result.setBackground(table.getSelectionBackground()); 133 result.setForeground(table.getSelectionForeground()); 134 } else { 135 result.setBackground(table.getBackground()); 136 result.setForeground(table.getForeground()); 137 } 138 139 ((JComponent) result).setOpaque(selected); 140 } 141 } 142 143 return result; 144 } 145 146 RendererFactory factory() { 147 if (factory == null) { 148 factory = new RendererFactory(true, reusableEnv, reusableModel); 149 } 150 151 return factory; 152 } 153 } 154 | Popular Tags |