1 7 8 package javax.swing.plaf.metal; 9 10 import java.awt.*; 11 import javax.swing.*; 12 import javax.swing.border.*; 13 import javax.swing.plaf.basic.*; 14 15 16 32 class MetalSplitPaneDivider extends BasicSplitPaneDivider 33 { 34 private MetalBumps bumps = new MetalBumps (10, 10, 35 MetalLookAndFeel.getControlHighlight(), 36 MetalLookAndFeel.getControlDarkShadow(), 37 MetalLookAndFeel.getControl() ); 38 39 private MetalBumps focusBumps = new MetalBumps (10, 10, 40 MetalLookAndFeel.getPrimaryControlHighlight(), 41 MetalLookAndFeel.getPrimaryControlDarkShadow(), 42 UIManager.getColor("SplitPane.dividerFocusColor")); 43 44 private int inset = 2; 45 46 private Color controlColor = MetalLookAndFeel.getControl(); 47 private Color primaryControlColor = UIManager.getColor( 48 "SplitPane.dividerFocusColor"); 49 50 public MetalSplitPaneDivider(BasicSplitPaneUI ui) { 51 super(ui); 52 } 53 54 public void paint(Graphics g) { 55 MetalBumps usedBumps; 56 if (splitPane.hasFocus()) { 57 usedBumps = focusBumps; 58 g.setColor(primaryControlColor); 59 } 60 else { 61 usedBumps = bumps; 62 g.setColor(controlColor); 63 } 64 Rectangle clip = g.getClipBounds(); 65 Insets insets = getInsets(); 66 g.fillRect(clip.x, clip.y, clip.width, clip.height); 67 Dimension size = getSize(); 68 size.width -= inset * 2; 69 size.height -= inset * 2; 70 int drawX = inset; 71 int drawY = inset; 72 if (insets != null) { 73 size.width -= (insets.left + insets.right); 74 size.height -= (insets.top + insets.bottom); 75 drawX += insets.left; 76 drawY += insets.top; 77 } 78 usedBumps.setBumpArea(size); 79 usedBumps.paintIcon(this, g, drawX, drawY); 80 super.paint(g); 81 } 82 83 87 protected JButton createLeftOneTouchButton() { 88 JButton b = new JButton() { 89 int[][] buffer = {{0, 0, 0, 2, 2, 0, 0, 0, 0}, 91 {0, 0, 2, 1, 1, 1, 0, 0, 0}, 92 {0, 2, 1, 1, 1, 1, 1, 0, 0}, 93 {2, 1, 1, 1, 1, 1, 1, 1, 0}, 94 {0, 3, 3, 3, 3, 3, 3, 3, 3}}; 95 96 public void setBorder(Border b) { 97 } 98 99 public void paint(Graphics g) { 100 JSplitPane splitPane = getSplitPaneFromSuper(); 101 if(splitPane != null) { 102 int oneTouchSize = getOneTouchSizeFromSuper(); 103 int orientation = getOrientationFromSuper(); 104 int blockSize = Math.min(getDividerSize(), 105 oneTouchSize); 106 107 Color[] colors = { 109 this.getBackground(), 110 MetalLookAndFeel.getPrimaryControlDarkShadow(), 111 MetalLookAndFeel.getPrimaryControlInfo(), 112 MetalLookAndFeel.getPrimaryControlHighlight()}; 113 114 g.setColor(this.getBackground()); 116 if (isOpaque()) { 117 g.fillRect(0, 0, this.getWidth(), 118 this.getHeight()); 119 } 120 121 if (getModel().isPressed()) { 123 colors[1] = colors[2]; 125 } 126 if(orientation == JSplitPane.VERTICAL_SPLIT) { 127 for (int i=1; i<=buffer[0].length; i++) { 129 for (int j=1; j<blockSize; j++) { 130 if (buffer[j-1][i-1] == 0) { 131 continue; 132 } 133 else { 134 g.setColor( 135 colors[buffer[j-1][i-1]]); 136 } 137 g.drawLine(i, j, i, j); 138 } 139 } 140 } 141 else { 142 for (int i=1; i<=buffer[0].length; i++) { 149 for (int j=1; j<blockSize; j++) { 150 if (buffer[j-1][i-1] == 0) { 151 continue; 154 } 155 else { 156 g.setColor( 159 colors[buffer[j-1][i-1]]); 160 } 161 g.drawLine(j, i, j, i); 163 } 164 } 165 } 166 } 167 } 168 169 public boolean isFocusTraversable() { 171 return false; 172 } 173 }; 174 b.setRequestFocusEnabled(false); 175 b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 176 b.setFocusPainted(false); 177 b.setBorderPainted(false); 178 maybeMakeButtonOpaque(b); 179 return b; 180 } 181 182 185 private void maybeMakeButtonOpaque(JComponent c) { 186 Object opaque = UIManager.get("SplitPane.oneTouchButtonsOpaque"); 187 if (opaque != null) { 188 c.setOpaque(((Boolean )opaque).booleanValue()); 189 } 190 } 191 192 196 protected JButton createRightOneTouchButton() { 197 JButton b = new JButton() { 198 int[][] buffer = {{2, 2, 2, 2, 2, 2, 2, 2}, 200 {0, 1, 1, 1, 1, 1, 1, 3}, 201 {0, 0, 1, 1, 1, 1, 3, 0}, 202 {0, 0, 0, 1, 1, 3, 0, 0}, 203 {0, 0, 0, 0, 3, 0, 0, 0}}; 204 205 public void setBorder(Border border) { 206 } 207 208 public void paint(Graphics g) { 209 JSplitPane splitPane = getSplitPaneFromSuper(); 210 if(splitPane != null) { 211 int oneTouchSize = getOneTouchSizeFromSuper(); 212 int orientation = getOrientationFromSuper(); 213 int blockSize = Math.min(getDividerSize(), 214 oneTouchSize); 215 216 Color[] colors = { 218 this.getBackground(), 219 MetalLookAndFeel.getPrimaryControlDarkShadow(), 220 MetalLookAndFeel.getPrimaryControlInfo(), 221 MetalLookAndFeel.getPrimaryControlHighlight()}; 222 223 g.setColor(this.getBackground()); 225 if (isOpaque()) { 226 g.fillRect(0, 0, this.getWidth(), 227 this.getHeight()); 228 } 229 230 if (getModel().isPressed()) { 232 colors[1] = colors[2]; 234 } 235 if(orientation == JSplitPane.VERTICAL_SPLIT) { 236 for (int i=1; i<=buffer[0].length; i++) { 238 for (int j=1; j<blockSize; j++) { 239 if (buffer[j-1][i-1] == 0) { 240 continue; 241 } 242 else { 243 g.setColor( 244 colors[buffer[j-1][i-1]]); 245 } 246 g.drawLine(i, j, i, j); 247 } 248 } 249 } 250 else { 251 for (int i=1; i<=buffer[0].length; i++) { 258 for (int j=1; j<blockSize; j++) { 259 if (buffer[j-1][i-1] == 0) { 260 continue; 263 } 264 else { 265 g.setColor( 268 colors[buffer[j-1][i-1]]); 269 } 270 g.drawLine(j, i, j, i); 272 } 273 } 274 } 275 } 276 } 277 278 public boolean isFocusTraversable() { 280 return false; 281 } 282 }; 283 b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 284 b.setFocusPainted(false); 285 b.setBorderPainted(false); 286 b.setRequestFocusEnabled(false); 287 maybeMakeButtonOpaque(b); 288 return b; 289 } 290 291 298 public class MetalDividerLayout implements LayoutManager { 299 300 305 public void layoutContainer(Container c) { 306 JButton leftButton = getLeftButtonFromSuper(); 307 JButton rightButton = getRightButtonFromSuper(); 308 JSplitPane splitPane = getSplitPaneFromSuper(); 309 int orientation = getOrientationFromSuper(); 310 int oneTouchSize = getOneTouchSizeFromSuper(); 311 int oneTouchOffset = getOneTouchOffsetFromSuper(); 312 Insets insets = getInsets(); 313 314 if (leftButton != null && rightButton != null && 319 c == MetalSplitPaneDivider.this) { 320 if (splitPane.isOneTouchExpandable()) { 321 if (orientation == JSplitPane.VERTICAL_SPLIT) { 322 int extraY = (insets != null) ? insets.top : 0; 323 int blockSize = getDividerSize(); 324 325 if (insets != null) { 326 blockSize -= (insets.top + insets.bottom); 327 } 328 blockSize = Math.min(blockSize, oneTouchSize); 329 leftButton.setBounds(oneTouchOffset, extraY, 330 blockSize * 2, blockSize); 331 rightButton.setBounds(oneTouchOffset + 332 oneTouchSize * 2, extraY, 333 blockSize * 2, blockSize); 334 } 335 else { 336 int blockSize = getDividerSize(); 337 int extraX = (insets != null) ? insets.left : 0; 338 339 if (insets != null) { 340 blockSize -= (insets.left + insets.right); 341 } 342 blockSize = Math.min(blockSize, oneTouchSize); 343 leftButton.setBounds(extraX, oneTouchOffset, 344 blockSize, blockSize * 2); 345 rightButton.setBounds(extraX, oneTouchOffset + 346 oneTouchSize * 2, blockSize, 347 blockSize * 2); 348 } 349 } 350 else { 351 leftButton.setBounds(-5, -5, 1, 1); 352 rightButton.setBounds(-5, -5, 1, 1); 353 } 354 } 355 } 356 357 public Dimension minimumLayoutSize(Container c) { 358 return new Dimension(0,0); 359 } 360 361 public Dimension preferredLayoutSize(Container c) { 362 return new Dimension(0, 0); 363 } 364 365 public void removeLayoutComponent(Component c) {} 366 367 public void addLayoutComponent(String string, Component c) {} 368 } 369 370 375 376 int getOneTouchSizeFromSuper() { 377 return super.ONE_TOUCH_SIZE; 378 } 379 380 int getOneTouchOffsetFromSuper() { 381 return super.ONE_TOUCH_OFFSET; 382 } 383 384 int getOrientationFromSuper() { 385 return super.orientation; 386 } 387 388 JSplitPane getSplitPaneFromSuper() { 389 return super.splitPane; 390 } 391 392 JButton getLeftButtonFromSuper() { 393 return super.leftButton; 394 } 395 396 JButton getRightButtonFromSuper() { 397 return super.rightButton; 398 } 399 } 400 | Popular Tags |