1 7 8 package com.sun.java.swing.plaf.motif; 9 10 import javax.swing.*; 11 import javax.swing.event.*; 12 import javax.swing.plaf.*; 13 import javax.swing.plaf.basic.BasicArrowButton ; 14 15 import java.awt.*; 16 import java.awt.event.*; 17 18 28 public class MotifScrollBarButton extends BasicArrowButton 29 { 30 private Color darkShadow = UIManager.getColor("controlShadow"); 31 private Color lightShadow = UIManager.getColor("controlLtHighlight"); 32 33 34 public MotifScrollBarButton(int direction) 35 { 36 super(direction); 37 38 switch (direction) { 39 case NORTH: 40 case SOUTH: 41 case EAST: 42 case WEST: 43 this.direction = direction; 44 break; 45 default: 46 throw new IllegalArgumentException ("invalid direction"); 47 } 48 49 setRequestFocusEnabled(false); 50 setOpaque(true); 51 setBackground(UIManager.getColor("ScrollBar.background")); 52 setForeground(UIManager.getColor("ScrollBar.foreground")); 53 } 54 55 56 public Dimension getPreferredSize() { 57 switch (direction) { 58 case NORTH: 59 case SOUTH: 60 return new Dimension(11, 12); 61 case EAST: 62 case WEST: 63 default: 64 return new Dimension(12, 11); 65 } 66 } 67 68 public Dimension getMinimumSize() { 69 return getPreferredSize(); 70 } 71 72 public Dimension getMaximumSize() { 73 return getPreferredSize(); 74 } 75 76 public boolean isFocusTraversable() { 77 return false; 78 } 79 80 public void paint(Graphics g) 81 { 82 int w = getWidth(); 83 int h = getHeight(); 84 85 if (isOpaque()) { 86 g.setColor(getBackground()); 87 g.fillRect(0, 0, w, h); 88 } 89 90 boolean isPressed = getModel().isPressed(); 91 Color lead = (isPressed) ? darkShadow : lightShadow; 92 Color trail = (isPressed) ? lightShadow : darkShadow; 93 Color fill = getBackground(); 94 95 int cx = w / 2; 96 int cy = h / 2; 97 int s = Math.min(w, h); 98 99 switch (direction) { 100 case NORTH: 101 g.setColor(lead); 102 g.drawLine(cx, 0, cx, 0); 103 for (int x = cx - 1, y = 1, dx = 1; y <= s - 2; y += 2) { 104 g.setColor(lead); 105 g.drawLine(x, y, x, y); 106 if (y >= (s - 2)) { 107 g.drawLine(x, y + 1, x, y + 1); 108 } 109 g.setColor(fill); 110 g.drawLine(x + 1, y, x + dx, y); 111 if (y < (s - 2)) { 112 g.drawLine(x, y + 1, x + dx + 1, y + 1); 113 } 114 g.setColor(trail); 115 g.drawLine(x + dx + 1, y, x + dx + 1, y); 116 if (y >= (s - 2)) { 117 g.drawLine(x + 1, y + 1, x + dx + 1, y + 1); 118 } 119 dx += 2; 120 x -= 1; 121 } 122 break; 123 124 case SOUTH: 125 g.setColor(trail); 126 g.drawLine(cx, s, cx, s); 127 for (int x = cx - 1, y = s - 1, dx = 1; y >= 1; y -= 2) { 128 g.setColor(lead); 129 g.drawLine(x, y, x, y); 130 if (y <= 2) { 131 g.drawLine(x, y - 1, x + dx + 1, y - 1); 132 } 133 g.setColor(fill); 134 g.drawLine(x + 1, y, x + dx, y); 135 if (y > 2) { 136 g.drawLine(x, y - 1, x + dx + 1, y - 1); 137 } 138 g.setColor(trail); 139 g.drawLine(x + dx + 1, y, x + dx + 1, y); 140 141 dx += 2; 142 x -= 1; 143 } 144 break; 145 146 case EAST: 147 g.setColor(lead); 148 g.drawLine(s, cy, s, cy); 149 for (int y = cy - 1, x = s - 1, dy = 1; x >= 1; x -= 2) { 150 g.setColor(lead); 151 g.drawLine(x, y, x, y); 152 if (x <= 2) { 153 g.drawLine(x - 1, y, x - 1, y + dy + 1); 154 } 155 g.setColor(fill); 156 g.drawLine(x, y + 1, x, y + dy); 157 if (x > 2) { 158 g.drawLine(x - 1, y, x - 1, y + dy + 1); 159 } 160 g.setColor(trail); 161 g.drawLine(x, y + dy + 1, x, y + dy + 1); 162 163 dy += 2; 164 y -= 1; 165 } 166 break; 167 168 case WEST: 169 g.setColor(trail); 170 g.drawLine(0, cy, 0, cy); 171 for (int y = cy - 1, x = 1, dy = 1; x <= s - 2; x += 2) { 172 g.setColor(lead); 173 g.drawLine(x, y, x, y); 174 if (x >= (s - 2)) { 175 g.drawLine(x + 1, y, x + 1, y); 176 } 177 g.setColor(fill); 178 g.drawLine(x, y + 1, x, y + dy); 179 if (x < (s - 2)) { 180 g.drawLine(x + 1, y, x + 1, y + dy + 1); 181 } 182 g.setColor(trail); 183 g.drawLine(x, y + dy + 1, x, y + dy + 1); 184 if (x >= (s - 2)) { 185 g.drawLine(x + 1, y + 1, x + 1, y + dy + 1); 186 } 187 dy += 2; 188 y -= 1; 189 } 190 break; 191 } 192 } 193 } 194 195 196 | Popular Tags |