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 CheckBoxMenuItemPainter extends AbstractRegionPainter { 18 static final int BACKGROUND_DISABLED = 1; 23 static final int BACKGROUND_ENABLED = 2; 24 static final int BACKGROUND_MOUSEOVER = 3; 25 static final int BACKGROUND_SELECTED_MOUSEOVER = 4; 26 static final int CHECKICON_DISABLED_SELECTED = 5; 27 static final int CHECKICON_ENABLED_SELECTED = 6; 28 static final int CHECKICON_SELECTED_MOUSEOVER = 7; 29 30 31 private int state; private PaintContext ctx; 33 34 private Path2D path = new Path2D.Float(); 36 private Rectangle2D rect = new Rectangle2D.Float(0, 0, 0, 0); 37 private RoundRectangle2D roundRect = new RoundRectangle2D.Float(0, 0, 0, 0, 0, 0); 38 private Ellipse2D ellipse = new Ellipse2D.Float(0, 0, 0, 0); 39 40 private Color color1 = decodeColor("nimbusSelection", 0.0f, 0.0f, 0.0f, 0); 44 private Color color2 = decodeColor("nimbusBlueGrey", 0.0f, -0.08983666f, -0.17647058f, 0); 45 private Color color3 = decodeColor("nimbusBlueGrey", 0.055555582f, -0.096827686f, -0.45882353f, 0); 46 private Color color4 = decodeColor("nimbusBlueGrey", 0.0f, -0.110526316f, 0.25490195f, 0); 47 48 49 private Object [] componentColors; 51 52 public CheckBoxMenuItemPainter(PaintContext ctx, int state) { 53 super(); 54 this.state = state; 55 this.ctx = ctx; 56 } 57 58 @Override 59 protected void doPaint(Graphics2D g, JComponent c, int width, int height, Object [] extendedCacheKeys) { 60 componentColors = extendedCacheKeys; 62 switch(state) { 65 case BACKGROUND_MOUSEOVER: paintBackgroundMouseOver(g); break; 66 case BACKGROUND_SELECTED_MOUSEOVER: paintBackgroundSelectedAndMouseOver(g); break; 67 case CHECKICON_DISABLED_SELECTED: paintcheckIconDisabledAndSelected(g); break; 68 case CHECKICON_ENABLED_SELECTED: paintcheckIconEnabledAndSelected(g); break; 69 case CHECKICON_SELECTED_MOUSEOVER: paintcheckIconSelectedAndMouseOver(g); break; 70 71 } 72 } 73 74 75 76 @Override 77 protected final PaintContext getPaintContext() { 78 return ctx; 79 } 80 81 private void paintBackgroundMouseOver(Graphics2D g) { 82 rect = decodeRect1(); 83 g.setPaint(color1); 84 g.fill(rect); 85 86 } 87 88 private void paintBackgroundSelectedAndMouseOver(Graphics2D g) { 89 rect = decodeRect1(); 90 g.setPaint(color1); 91 g.fill(rect); 92 93 } 94 95 private void paintcheckIconDisabledAndSelected(Graphics2D g) { 96 path = decodePath1(); 97 g.setPaint(color2); 98 g.fill(path); 99 100 } 101 102 private void paintcheckIconEnabledAndSelected(Graphics2D g) { 103 path = decodePath1(); 104 g.setPaint(color3); 105 g.fill(path); 106 107 } 108 109 private void paintcheckIconSelectedAndMouseOver(Graphics2D g) { 110 path = decodePath1(); 111 g.setPaint(color4); 112 g.fill(path); 113 114 } 115 116 117 118 private Rectangle2D decodeRect1() { 119 rect.setRect(decodeX(1.0f), decodeY(1.0f), decodeX(2.0f) - decodeX(1.0f), decodeY(2.0f) - decodeY(1.0f)); return rect; 124 } 125 126 private Path2D decodePath1() { 127 path.reset(); 128 path.moveTo(decodeX(0.0f), decodeY(1.5f)); 129 path.lineTo(decodeX(0.4292683f), decodeY(1.5f)); 130 path.lineTo(decodeX(0.7121951f), decodeY(2.4780488f)); 131 path.lineTo(decodeX(2.5926828f), decodeY(0.0f)); 132 path.lineTo(decodeX(3.0f), decodeY(0.0f)); 133 path.lineTo(decodeX(3.0f), decodeY(0.2f)); 134 path.lineTo(decodeX(2.8317075f), decodeY(0.39512196f)); 135 path.lineTo(decodeX(0.8f), decodeY(3.0f)); 136 path.lineTo(decodeX(0.5731707f), decodeY(3.0f)); 137 path.lineTo(decodeX(0.0f), decodeY(1.5f)); 138 path.closePath(); 139 return path; 140 } 141 142 143 144 145 } 146 | Popular Tags |