1 30 31 package com.jgoodies.looks.windows; 32 33 import java.awt.Color ; 34 import java.awt.Dimension ; 35 import java.awt.Graphics ; 36 37 import javax.swing.UIManager ; 38 import javax.swing.plaf.basic.BasicArrowButton ; 39 40 52 final class WindowsArrowButton extends BasicArrowButton { 53 54 public WindowsArrowButton(int direction) { 55 super(direction); 56 } 57 58 public Dimension getPreferredSize() { 59 int width = Math.max(5, UIManager.getInt("ScrollBar.width")); 60 return new Dimension (width, width); 61 } 62 63 public void paintTriangle( 64 Graphics g, 65 int x, 66 int y, 67 int size, 68 int triangleDirection, 69 boolean isEnabled) { 70 Color oldColor = g.getColor(); 71 int mid, i, j; 72 73 j = 0; 74 size = Math.max(size, 2); 75 mid = (size - 1) / 2; 77 g.translate(x, y); 78 if (isEnabled) 79 g.setColor(Color.black); 80 else 81 g.setColor(UIManager.getColor("controlShadow")); 82 83 switch (triangleDirection) { 84 case NORTH : 85 for (i = 0; i < size; i++) { 86 g.drawLine(mid - i, i, mid + i, i); 87 } 88 if (!isEnabled) { 89 g.setColor(UIManager.getColor("controlLtHighlight")); 90 g.drawLine(mid - i + 2, i, mid + i, i); 91 } 92 break; 93 case SOUTH : 94 if (!isEnabled) { 95 g.translate(1, 1); 96 g.setColor(UIManager.getColor("controlLtHighlight")); 97 for (i = size - 1; i >= 0; i--) { 98 g.drawLine(mid - i, j, mid + i, j); 99 j++; 100 } 101 g.translate(-1, -1); 102 g.setColor(UIManager.getColor("controlShadow")); 103 } 104 105 j = 0; 106 for (i = size - 1; i >= 0; i--) { 107 g.drawLine(mid - i, j, mid + i, j); 108 j++; 109 } 110 break; 111 case WEST : 112 for (i = 0; i < size; i++) { 113 g.drawLine(i, mid - i, i, mid + i); 114 } 115 if (!isEnabled) { 116 g.setColor(UIManager.getColor("controlLtHighlight")); 117 g.drawLine(i, mid - i + 2, i, mid + i); 118 } 119 break; 120 case EAST : 121 if (!isEnabled) { 122 g.translate(1, 1); 123 g.setColor(UIManager.getColor("controlLtHighlight")); 124 for (i = size - 1; i >= 0; i--) { 125 g.drawLine(j, mid - i, j, mid + i); 126 j++; 127 } 128 g.translate(-1, -1); 129 g.setColor(UIManager.getColor("controlShadow")); 130 } 131 132 j = 0; 133 for (i = size - 1; i >= 0; i--) { 134 g.drawLine(j, mid - i, j, mid + i); 135 j++; 136 } 137 break; 138 } 139 g.translate(-x, -y); 140 g.setColor(oldColor); 141 } 142 } 143 | Popular Tags |