1 19 20 21 package org.netbeans.modules.form.fakepeer; 22 23 import java.awt.*; 24 25 29 30 class FakePeerUtils 31 { 32 static void drawButton(Graphics g,int x,int y,int w,int h) { 33 g.fillRect(x,y,w,h); 34 35 g.setColor(SystemColor.controlHighlight); 37 g.drawLine(x,y+h-2,x,y); 38 g.drawLine(x,y,x+w-2,y); 39 g.setColor(SystemColor.controlDkShadow); 40 g.drawLine(x,y+h-1,x+w-1,y+h-1); 41 g.drawLine(x+w-1,y+h-1,x+w-1,y); 42 if (w >=4 && h >= 4) { 43 g.setColor(SystemColor.controlLtHighlight); 44 g.drawLine(x+1,y+h-3,x+1,y+1); 45 g.drawLine(x+1,y+1,x+w-3,y+1); 46 g.setColor(SystemColor.controlShadow); 47 g.drawLine(x+1,y+h-2,x+w-2,y+h-2); 48 g.drawLine(x+w-2,y+h-2,x+w-2,y+1); 49 } 50 } 51 52 static void drawArrowButton(Graphics g, 53 int x, int y, int w, int h, 54 int type, boolean enabled) { 55 g.setColor(SystemColor.control); 56 drawButton(g,x,y,w,h); 57 58 int minWH = w < h ? w : h, 59 size; if (minWH >= ABUT_SIZE) size = 4; 61 else if (minWH >= 12) size = 3; 62 else if (minWH >= 8) size = 2; 63 else if (minWH >= 6) size = 1; 64 else size = 0; 65 66 if (enabled) 67 g.setColor(SystemColor.controlText); 68 else { 69 g.setColor(SystemColor.controlLtHighlight); 70 x++; 71 y++; 72 } 73 74 while (true) { 76 if (type == 1) { int ax = x+w/2-size/2, 78 ay = y+h/2-1; 79 for (int i=0; i < size; i++) 80 g.drawLine(ax+i,ay-i,ax+i,ay+i); 81 } else if (type == 2) { int ax = x+w/2+size/2, 83 ay = y+h/2-1; 84 for (int i=0; i < size; i++) 85 g.drawLine(ax-i,ay-i,ax-i,ay+i); 86 } else if (type == 3) { int ax = x+w/2-1, 88 ay = y+h/2-size/2; 89 for (int i=0; i < size; i++) 90 g.drawLine(ax-i,ay+i,ax+i,ay+i); 91 } else if (type == 4) { int ax = x+w/2-1, 93 ay = y+h/2+size/2; 94 for (int i=0; i < size; i++) 95 g.drawLine(ax-i,ay-i,ax+i,ay-i); 96 } 97 98 if (enabled) break; 99 else { 100 enabled = true; 101 g.setColor(SystemColor.controlShadow); 102 x--; 103 y--; 104 } 105 } 106 } 107 108 static void drawChoiceButton(Graphics g,int x,int y,int w,int h,boolean enabled) { 109 drawArrowButton(g,x,y,w,h,4,enabled); 111 } 112 113 static void drawScrollThumb(Graphics g,int x,int y,int w,int h) { 114 drawButton(g,x,y,w,h); 116 } 117 118 static void drawLoweredBox(Graphics g,int x,int y,int w,int h) { 119 g.fillRect(x,y,w,h); 120 121 g.setColor(SystemColor.controlShadow); 122 g.drawLine(x,y+h-2,x,y); 123 g.drawLine(x,y,x+w-2,y); 124 g.setColor(SystemColor.controlLtHighlight); 125 g.drawLine(x,y+h-1,x+w-1,y+h-1); 126 g.drawLine(x+w-1,y+h-1,x+w-1,y); 127 if (w >=4 && h >= 4) { 128 g.setColor(SystemColor.controlDkShadow); 129 g.drawLine(x+1,y+h-3,x+1,y+1); 130 g.drawLine(x+1,y+1,x+w-3,y+1); 131 g.setColor(SystemColor.controlHighlight); 132 g.drawLine(x+1,y+h-2,x+w-2,y+h-2); 133 g.drawLine(x+w-2,y+h-2,x+w-2,y+1); 134 } 135 } 136 137 static void drawScrollbar(Graphics g, 138 int x,int y,int w,int h, 139 int orientation, 140 boolean enabled, 141 boolean border,int relValue,int amount,int range) { 142 g.fillRect(x, y, w, h); 144 if (border) { g.setColor(SystemColor.controlShadow); 146 g.drawRect(x,y,w-1,h-1); 147 g.setColor(SystemColor.control); 148 g.drawRect(x+1,y+1,w-3,h-3); 149 } else 150 g.setColor(SystemColor.control); 151 152 if (orientation == Scrollbar.HORIZONTAL) { 153 int butW; 154 if (w >= 2*SCROLL_W) { 155 butW = SCROLL_W; 156 int wFT = w - 2*butW; if (wFT >= 4 && enabled) { int thumbW = range > 0 ? wFT * amount / range : wFT; 159 if (thumbW < 6) thumbW = 6; 160 if (thumbW > wFT) thumbW = wFT; 161 range -= relValue; 162 int thumbX = (range > 0 ? relValue * (wFT - thumbW) / range : 0) + x + butW; 163 164 drawScrollThumb(g,thumbX,y,thumbW,h); 165 } 166 } else butW = w/2; 167 if (butW >= 4) { drawArrowButton(g,x,y,butW,h,1,enabled); drawArrowButton(g,x+w-butW,y,butW,h,2,enabled); } 171 } else { int butH; 173 if (h >= 2*SCROLL_H) { 174 butH = SCROLL_H; 175 int hFT = h - 2*butH; if (hFT >= 4 && enabled) { int thumbH = range > 0 ? hFT * amount / range : hFT; 178 if (thumbH < 6) thumbH = 6; 179 if (thumbH > hFT) thumbH = hFT; 180 range -= relValue; 181 int thumbY = (range > 0 ? relValue * (hFT - thumbH) / range : 0) + y + butH; 182 183 drawScrollThumb(g,x,thumbY,w,thumbH); 184 } 185 } else butH = h/2; 186 if (butH >= 4) { drawArrowButton(g,x,y,w,butH,3,enabled); drawArrowButton(g,x,y+h-butH,w,butH,4,enabled); } 190 } 191 } 192 193 private static int ABUT_SIZE = 16; static final int SCROLL_W = 16, SCROLL_H = 16; 195 } 196 | Popular Tags |