1 7 package com.sun.java.swing.plaf.nimbus; 8 9 import java.awt.*; 10 import java.awt.geom.*; 11 import java.awt.image.*; 12 import javax.swing.*; 13 import com.sun.java.swing.Painter; 14 15 17 public final class MenuPainter extends AbstractRegionPainter { 18 static final int BACKGROUND_DISABLED = 1; 23 static final int BACKGROUND_ENABLED = 2; 24 static final int BACKGROUND_ENABLED_SELECTED = 3; 25 static final int ARROWICON_DISABLED = 4; 26 static final int ARROWICON_ENABLED = 5; 27 static final int ARROWICON_ENABLED_SELECTED = 6; 28 29 30 private int state; private PaintContext ctx; 32 33 private Path2D path = new Path2D.Float(); 35 private Rectangle2D rect = new Rectangle2D.Float(0, 0, 0, 0); 36 private RoundRectangle2D roundRect = new RoundRectangle2D.Float(0, 0, 0, 0, 0, 0); 37 private Ellipse2D ellipse = new Ellipse2D.Float(0, 0, 0, 0); 38 39 private Color color1 = decodeColor("nimbusSelection", 0.0f, 0.0f, 0.0f, 0); 43 private Color color2 = decodeColor("nimbusBlueGrey", 0.0f, -0.08983666f, -0.17647058f, 0); 44 private Color color3 = decodeColor("nimbusBlueGrey", 0.055555582f, -0.09663743f, -0.4627451f, 0); 45 private Color color4 = new Color(255, 255, 255, 255); 46 47 48 private Object [] componentColors; 50 51 public MenuPainter(PaintContext ctx, int state) { 52 super(); 53 this.state = state; 54 this.ctx = ctx; 55 } 56 57 @Override 58 protected void doPaint(Graphics2D g, JComponent c, int width, int height, Object [] extendedCacheKeys) { 59 componentColors = extendedCacheKeys; 61 switch(state) { 64 case BACKGROUND_ENABLED_SELECTED: paintBackgroundEnabledAndSelected(g); break; 65 case ARROWICON_DISABLED: paintarrowIconDisabled(g); break; 66 case ARROWICON_ENABLED: paintarrowIconEnabled(g); break; 67 case ARROWICON_ENABLED_SELECTED: paintarrowIconEnabledAndSelected(g); break; 68 69 } 70 } 71 72 73 74 @Override 75 protected final PaintContext getPaintContext() { 76 return ctx; 77 } 78 79 private void paintBackgroundEnabledAndSelected(Graphics2D g) { 80 rect = decodeRect1(); 81 g.setPaint(color1); 82 g.fill(rect); 83 84 } 85 86 private void paintarrowIconDisabled(Graphics2D g) { 87 path = decodePath1(); 88 g.setPaint(color2); 89 g.fill(path); 90 91 } 92 93 private void paintarrowIconEnabled(Graphics2D g) { 94 path = decodePath1(); 95 g.setPaint(color3); 96 g.fill(path); 97 98 } 99 100 private void paintarrowIconEnabledAndSelected(Graphics2D g) { 101 path = decodePath2(); 102 g.setPaint(color4); 103 g.fill(path); 104 105 } 106 107 108 109 private Rectangle2D decodeRect1() { 110 rect.setRect(decodeX(1.0f), decodeY(1.0f), decodeX(2.0f) - decodeX(1.0f), decodeY(2.0f) - decodeY(1.0f)); return rect; 115 } 116 117 private Path2D decodePath1() { 118 path.reset(); 119 path.moveTo(decodeX(0.0f), decodeY(0.2f)); 120 path.lineTo(decodeX(2.7512195f), decodeY(2.102439f)); 121 path.lineTo(decodeX(0.0f), decodeY(3.0f)); 122 path.lineTo(decodeX(0.0f), decodeY(0.2f)); 123 path.closePath(); 124 return path; 125 } 126 127 private Path2D decodePath2() { 128 path.reset(); 129 path.moveTo(decodeX(0.0f), decodeY(1.0f)); 130 path.lineTo(decodeX(1.9529617f), decodeY(1.5625f)); 131 path.lineTo(decodeX(0.0f), decodeY(3.0f)); 132 path.lineTo(decodeX(0.0f), decodeY(1.0f)); 133 path.closePath(); 134 return path; 135 } 136 137 138 139 140 } 141 | Popular Tags |