1 30 31 package com.jgoodies.looks.plastic; 32 33 import java.awt.Color ; 34 import java.awt.Graphics ; 35 36 import javax.swing.plaf.metal.MetalLookAndFeel ; 37 38 import com.jgoodies.looks.LookUtils; 39 40 41 47 48 public final class PlasticXPUtils { 49 50 53 static void drawPlainButtonBorder(Graphics g, int x, int y, int w, int h) { 54 drawButtonBorder(g, x, y, w, h, 55 PlasticLookAndFeel.getControl(), 56 PlasticLookAndFeel.getControlDarkShadow(), 57 LookUtils.getSlightlyBrighter( 58 PlasticLookAndFeel.getControlDarkShadow(), 59 1.25f) 60 ); 61 } 62 63 66 static void drawPressedButtonBorder(Graphics g, int x, int y, int w, int h) { 67 drawPlainButtonBorder(g, x, y, w, h); 68 Color darkColor = 69 translucentColor(PlasticLookAndFeel.getControlDarkShadow(), 70 128); 71 Color lightColor = 72 translucentColor(PlasticLookAndFeel.getControlHighlight(), 73 80); 74 g.translate(x, y); 75 g.setColor(darkColor); 76 g.fillRect(2, 1, w-4, 1); 77 78 g.setColor(lightColor); 79 g.fillRect(2, h-2, w-4, 1); 80 g.translate(-x, -y); 81 } 82 83 86 static void drawDefaultButtonBorder(Graphics g, int x, int y, int w, int h) { 87 drawPlainButtonBorder(g, x, y, w, h); 88 drawInnerButtonDecoration(g, x, y, w, h, 89 PlasticLookAndFeel.getPrimaryControlDarkShadow()); 90 } 91 92 95 static void drawFocusedButtonBorder(Graphics g, int x, int y, int w, int h) { 96 drawPlainButtonBorder(g, x, y, w, h); 97 drawInnerButtonDecoration(g, x, y, w, h, 98 PlasticLookAndFeel.getFocusColor()); 99 } 100 101 104 static void drawDisabledButtonBorder(Graphics g, int x, int y, int w, int h) { 105 drawButtonBorder(g, x, y, w, h, 106 PlasticLookAndFeel.getControl(), 107 MetalLookAndFeel.getControlShadow(), 108 LookUtils.getSlightlyBrighter( 109 MetalLookAndFeel.getControlShadow())); 110 } 111 112 113 116 public static void drawButtonBorder( 117 Graphics g, 118 int x, int y, int w, int h, 119 Color backgroundColor, 120 Color edgeColor, 121 Color cornerColor) { 122 123 g.translate(x, y); 124 g.setColor(edgeColor); 126 drawRect(g, 0, 0, w-1, h-1); 127 128 g.setColor(cornerColor); 130 g.fillRect(0, 0, 2, 2); 131 g.fillRect(0, h-2, 2, 2); 132 g.fillRect(w-2, 0, 2, 2); 133 g.fillRect(w-2, h-2, 2, 2); 134 135 g.setColor(backgroundColor); 137 g.fillRect(0, 0, 1, 1); 138 g.fillRect(0, h-1, 1, 1); 139 g.fillRect(w-1, 0, 1, 1); 140 g.fillRect(w-1, h-1, 1, 1); 141 142 g.translate(-x, -y); 143 } 144 145 148 private static void drawInnerButtonDecoration( 149 Graphics g, 150 int x, int y, int w, int h, 151 Color baseColor) { 152 153 Color lightColor = translucentColor(baseColor, 90); 154 Color mediumColor = translucentColor(baseColor, 120); 155 Color darkColor = translucentColor(baseColor, 200); 156 157 g.translate(x, y); 158 g.setColor(lightColor); 159 g.fillRect(2, 1, w-4, 1); 160 161 g.setColor(mediumColor); 162 g.fillRect (1, 2, 1, h-4); 163 g.fillRect (w-2, 2, 1, h-4); 164 drawRect(g, 2, 2, w-5, h-5); 165 166 g.setColor(darkColor); 167 g.fillRect(2, h-2, w-4, 1); 168 g.translate(-x, -y); 169 } 170 171 172 175 static void drawRect(Graphics g, int x, int y, int w, int h) { 176 g.fillRect(x, y, w+1, 1); 177 g.fillRect(x, y+1, 1, h); 178 g.fillRect(x+1, y+h, w, 1); 179 g.fillRect(x+w, y+1, 1, h); 180 } 181 182 183 190 private static Color translucentColor(Color baseColor, int alpha) { 191 return new Color (baseColor.getRed(), 192 baseColor.getGreen(), 193 baseColor.getBlue(), 194 alpha); 195 } 196 197 } | Popular Tags |