1 19 20 package org.netbeans.modules.xml.schema.ui.nodes; 21 22 import java.awt.AlphaComposite ; 23 import java.awt.Color ; 24 import java.awt.Component ; 25 import java.awt.Dimension ; 26 import java.awt.Graphics ; 27 import java.awt.Graphics2D ; 28 import java.awt.Insets ; 29 import java.awt.Point ; 30 import java.awt.Rectangle ; 31 import java.awt.event.ComponentListener ; 32 import java.awt.event.ContainerListener ; 33 import java.awt.event.FocusListener ; 34 import java.awt.event.HierarchyBoundsListener ; 35 import java.awt.event.HierarchyListener ; 36 import java.awt.event.InputMethodListener ; 37 import java.awt.event.MouseListener ; 38 import java.awt.event.MouseMotionListener ; 39 import java.awt.event.MouseWheelListener ; 40 import java.beans.PropertyChangeListener ; 41 import java.beans.VetoableChangeListener ; 42 import javax.swing.JComponent ; 43 import javax.swing.JTree ; 44 import javax.swing.border.Border ; 45 import javax.swing.event.AncestorListener ; 46 import org.openide.explorer.view.NodeRenderer; 47 48 54 public class SchemaComponentNodeRenderer extends NodeRenderer 55 { 56 60 public SchemaComponentNodeRenderer() 61 { 62 super(); 63 } 64 65 66 70 public Component getTreeCellRendererComponent(JTree tree, Object value, 71 boolean selected, boolean expanded, boolean leaf, int row, 72 boolean hasFocus) 73 { 74 JComponent component=(JComponent ) 75 super.getTreeCellRendererComponent(tree,value, 76 selected,expanded,leaf,row,hasFocus); 77 return new WrapperComponent(tree,component,true); 78 } 79 80 81 82 83 87 91 protected class WrapperComponent extends JComponent  92 { 93 static final long serialVersionUID = 1L; 94 98 public WrapperComponent(JTree tree, JComponent target, 99 boolean hasDetail) 100 { 101 super(); 102 this.tree=tree; 103 this.target=target; 104 this.hasDetail=hasDetail; 105 } 106 107 108 112 public void paint(Graphics g) 113 { 114 target.paint(g); 115 116 Graphics2D g2d=(Graphics2D )g; 117 118 if (!hasDetail) 119 return; 120 121 Rectangle clip=g2d.getClipBounds(); 122 123 int newWidth = tree.getWidth() - (int) clip.getX(); 124 125 g2d.setClip(0 ,(int)clip.getY(), 126 newWidth ,(int)clip.getHeight()); 127 128 final int INSET=6; 130 final int WIDTH=newWidth; final int HEIGHT=getHeight(); 132 final int HEIGHT_CORRECTION=HEIGHT % 2 + 1; 133 final int SIZE=HEIGHT-2*INSET; 134 final int X=WIDTH-SIZE-INSET; 135 136 final int STEPS=HEIGHT - 2*INSET + HEIGHT_CORRECTION; 138 139 g2d.setComposite( 141 AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.33f)); 142 143 int right=0; 145 for (int i=0; i<STEPS+1; i++) 146 { 147 final int X_OFFSET=-1; 148 final int Y_OFFSET=-1; 149 150 if (i==0) 151 { 152 g.drawLine(X+X_OFFSET,INSET+i+Y_OFFSET-1, 153 X+right+X_OFFSET,INSET+i+Y_OFFSET-1); 154 } 155 156 right+=(i <= STEPS/2) ? 2 : -2; 157 g.drawLine(X+X_OFFSET,INSET+i+Y_OFFSET, 158 X+right+X_OFFSET,INSET+i+Y_OFFSET); 159 160 if (i==STEPS) 161 { 162 g.drawLine(X+X_OFFSET,INSET+i+Y_OFFSET+1, 163 X+right+X_OFFSET,INSET+i+Y_OFFSET+1); 164 } 165 } 166 167 g2d.setComposite( 169 AlphaComposite.getInstance(AlphaComposite.SRC_OVER,1.0f)); 170 171 int color=255; 172 final int COLOR_INC=color/6/STEPS; 173 174 right=-1; 176 for (int i=0; i<STEPS; i++) 177 { 178 g.setColor(new Color (color,color,color)); 179 color-=COLOR_INC; 180 181 right+=(i <= STEPS/2) ? 2 : -2; 182 g.drawLine(X,INSET+i,X+right,INSET+i); 183 } 184 } 185 186 public void addNotify() { 187 target.addNotify(); 188 } 189 190 public void removeNotify() { 191 target.removeNotify(); 192 } 193 194 public Dimension getPreferredSize() { 195 return target.getPreferredSize(); 196 } 197 198 202 public Border getBorder() { 203 return target.getBorder(); 204 } 205 206 public void setBorder(Border b) { 207 target.setBorder(b); 208 } 209 210 public Insets getInsets() { 211 return target.getInsets(); 212 } 213 214 public void setEnabled(boolean b) { 215 target.setEnabled(b); 216 } 217 218 public boolean isEnabled() { 219 return target.isEnabled(); 220 } 221 222 public void updateUI() { 223 target.updateUI(); 224 } 225 226 public Graphics getGraphics() { 227 return target.getGraphics(); 228 } 229 230 public Rectangle getBounds() { 231 return target.getBounds(); 232 } 233 234 public void setBounds(int x, int y, int w, int h) { 235 target.setBounds(x,y,w,h); 236 } 237 238 @SuppressWarnings ("deprecation") 239 public void reshape(int x, int y, int w, int h) { 240 target.reshape(x,y,w,h); 241 } 242 243 public int getWidth() { 244 return target.getWidth(); 245 } 246 247 public int getHeight() { 248 return target.getHeight(); 249 } 250 251 public Point getLocation() { 252 return target.getLocation(); 253 } 254 255 public void validate() { 256 target.validate(); 257 } 258 259 267 public void invalidate() { 268 target.invalidate(); 269 } 270 271 public void revalidate() { 272 target.revalidate(); 273 } 274 275 public void addAncestorListener(AncestorListener l) { 276 target.addAncestorListener(l); 277 } 278 279 public void addComponentListener(ComponentListener l) { 280 target.addComponentListener(l); 281 } 282 283 public void addContainerListener(ContainerListener l) { 284 target.addContainerListener(l); 285 } 286 287 public void addHierarchyListener(HierarchyListener l) { 288 target.addHierarchyListener(l); 289 } 290 291 public void addHierarchyBoundsListener(HierarchyBoundsListener l) { 292 target.addHierarchyBoundsListener(l); 293 } 294 295 public void addInputMethodListener(InputMethodListener l) { 296 target.addInputMethodListener(l); 297 } 298 299 public void addFocusListener(FocusListener fl) { 300 target.addFocusListener(fl); 301 } 302 303 public void addMouseListener(MouseListener ml) { 304 target.addMouseListener(ml); 305 } 306 307 public void addMouseWheelListener(MouseWheelListener ml) { 308 target.addMouseWheelListener(ml); 309 } 310 311 public void addMouseMotionListener(MouseMotionListener ml) { 312 target.addMouseMotionListener(ml); 313 } 314 315 public void addVetoableChangeListener(VetoableChangeListener vl) { 316 target.addVetoableChangeListener(vl); 317 } 318 319 public void addPropertyChangeListener(String s, PropertyChangeListener l) { 320 target.addPropertyChangeListener(s,l); 321 } 322 323 public void addPropertyChangeListener(PropertyChangeListener l) { 324 target.addPropertyChangeListener(l); 325 } 326 327 private JTree tree; 328 private JComponent target; 329 private boolean hasDetail; 330 } 331 } 332 | Popular Tags |