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 RadioButtonMenuItemPainter 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 static final int ICON_DISABLED = 8; 30 static final int ICON_ENABLED = 9; 31 static final int ICON_MOUSEOVER = 10; 32 33 34 private int state; private PaintContext ctx; 36 37 private Path2D path = new Path2D.Float(); 39 private Rectangle2D rect = new Rectangle2D.Float(0, 0, 0, 0); 40 private RoundRectangle2D roundRect = new RoundRectangle2D.Float(0, 0, 0, 0, 0, 0); 41 private Ellipse2D ellipse = new Ellipse2D.Float(0, 0, 0, 0); 42 43 private Color color1 = decodeColor("nimbusSelection", 0.0f, 0.0f, 0.0f, 0); 47 private Color color2 = decodeColor("nimbusBlueGrey", 0.0f, -0.08983666f, -0.17647058f, 0); 48 private Color color3 = decodeColor("nimbusBlueGrey", 0.055555582f, -0.09663743f, -0.4627451f, 0); 49 private Color color4 = decodeColor("nimbusBlueGrey", 0.0f, -0.110526316f, 0.25490195f, 0); 50 51 52 private Object [] componentColors; 54 55 public RadioButtonMenuItemPainter(PaintContext ctx, int state) { 56 super(); 57 this.state = state; 58 this.ctx = ctx; 59 } 60 61 @Override 62 protected void doPaint(Graphics2D g, JComponent c, int width, int height, Object [] extendedCacheKeys) { 63 componentColors = extendedCacheKeys; 65 switch(state) { 68 case BACKGROUND_MOUSEOVER: paintBackgroundMouseOver(g); break; 69 case BACKGROUND_SELECTED_MOUSEOVER: paintBackgroundSelectedAndMouseOver(g); break; 70 case CHECKICON_DISABLED_SELECTED: paintcheckIconDisabledAndSelected(g); break; 71 case CHECKICON_ENABLED_SELECTED: paintcheckIconEnabledAndSelected(g); break; 72 case CHECKICON_SELECTED_MOUSEOVER: paintcheckIconSelectedAndMouseOver(g); break; 73 74 } 75 } 76 77 78 79 @Override 80 protected final PaintContext getPaintContext() { 81 return ctx; 82 } 83 84 private void paintBackgroundMouseOver(Graphics2D g) { 85 rect = decodeRect1(); 86 g.setPaint(color1); 87 g.fill(rect); 88 89 } 90 91 private void paintBackgroundSelectedAndMouseOver(Graphics2D g) { 92 rect = decodeRect1(); 93 g.setPaint(color1); 94 g.fill(rect); 95 96 } 97 98 private void paintcheckIconDisabledAndSelected(Graphics2D g) { 99 path = decodePath1(); 100 g.setPaint(color2); 101 g.fill(path); 102 103 } 104 105 private void paintcheckIconEnabledAndSelected(Graphics2D g) { 106 path = decodePath2(); 107 g.setPaint(color3); 108 g.fill(path); 109 110 } 111 112 private void paintcheckIconSelectedAndMouseOver(Graphics2D g) { 113 path = decodePath2(); 114 g.setPaint(color4); 115 g.fill(path); 116 117 } 118 119 120 121 private Rectangle2D decodeRect1() { 122 rect.setRect(decodeX(1.0f), decodeY(1.0f), decodeX(2.0f) - decodeX(1.0f), decodeY(2.0f) - decodeY(1.0f)); return rect; 127 } 128 129 private Path2D decodePath1() { 130 path.reset(); 131 path.moveTo(decodeX(0.0f), decodeY(2.097561f)); 132 path.lineTo(decodeX(0.90975606f), decodeY(0.20243903f)); 133 path.lineTo(decodeX(3.0f), decodeY(2.102439f)); 134 path.lineTo(decodeX(0.90731704f), decodeY(3.0f)); 135 path.lineTo(decodeX(0.0f), decodeY(2.097561f)); 136 path.closePath(); 137 return path; 138 } 139 140 private Path2D decodePath2() { 141 path.reset(); 142 path.moveTo(decodeX(0.0024390244f), decodeY(2.097561f)); 143 path.lineTo(decodeX(0.90975606f), decodeY(0.20243903f)); 144 path.lineTo(decodeX(3.0f), decodeY(2.102439f)); 145 path.lineTo(decodeX(0.90731704f), decodeY(3.0f)); 146 path.lineTo(decodeX(0.0024390244f), decodeY(2.097561f)); 147 path.closePath(); 148 return path; 149 } 150 151 152 153 154 } 155 | Popular Tags |