1 7 8 package javax.swing.plaf.synth; 9 10 import java.awt.*; 11 import java.beans.*; 12 import javax.swing.*; 13 import javax.swing.plaf.basic.*; 14 import sun.swing.DefaultLookup; 15 16 22 class SynthSplitPaneDivider extends BasicSplitPaneDivider { 23 public SynthSplitPaneDivider(BasicSplitPaneUI ui) { 24 super(ui); 25 } 26 27 protected void setMouseOver(boolean mouseOver) { 28 if (isMouseOver() != mouseOver) { 29 repaint(); 30 } 31 super.setMouseOver(mouseOver); 32 } 33 34 public void propertyChange(PropertyChangeEvent e) { 35 super.propertyChange(e); 36 if (e.getSource() == splitPane) { 37 if (e.getPropertyName() == JSplitPane.ORIENTATION_PROPERTY) { 38 if (leftButton instanceof SynthArrowButton ) { 39 ((SynthArrowButton )leftButton).setDirection( 40 mapDirection(true)); 41 } 42 if (rightButton instanceof SynthArrowButton ) { 43 ((SynthArrowButton )rightButton).setDirection( 44 mapDirection(false)); 45 } 46 } 47 } 48 } 49 50 public void paint(Graphics g) { 51 Graphics g2 = g.create(); 52 53 SynthContext context = ((SynthSplitPaneUI )splitPaneUI).getContext( 54 splitPane, Region.SPLIT_PANE_DIVIDER); 55 Rectangle bounds = getBounds(); 56 bounds.x = bounds.y = 0; 57 SynthLookAndFeel.updateSubregion(context, g, bounds); 58 context.getPainter().paintSplitPaneDividerBackground(context, 59 g, 0, 0, bounds.width, bounds.height); 60 61 SynthPainter foreground = null; 62 63 context.getPainter().paintSplitPaneDividerForeground(context, g, 0, 0, 64 getWidth(), getHeight(), splitPane.getOrientation()); 65 context.dispose(); 66 67 for (int counter = 0; counter < getComponentCount(); counter++) { 69 Component child = getComponent(counter); 70 Rectangle childBounds = child.getBounds(); 71 Graphics childG = g.create(childBounds.x, childBounds.y, 72 childBounds.width, childBounds.height); 73 child.paint(childG); 74 childG.dispose(); 75 } 76 g2.dispose(); 77 } 78 79 private int mapDirection(boolean isLeft) { 80 if (isLeft) { 81 if (splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT){ 82 return SwingConstants.WEST; 83 } 84 return SwingConstants.NORTH; 85 } 86 if (splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT){ 87 return SwingConstants.EAST; 88 } 89 return SwingConstants.SOUTH; 90 } 91 92 93 97 protected JButton createLeftOneTouchButton() { 98 SynthArrowButton b = new SynthArrowButton (SwingConstants.NORTH); 99 int oneTouchSize = lookupOneTouchSize(); 100 101 b.setName("SplitPaneDivider.leftOneTouchButton"); 102 b.setMinimumSize(new Dimension(oneTouchSize, oneTouchSize)); 103 b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 104 b.setFocusPainted(false); 105 b.setBorderPainted(false); 106 b.setRequestFocusEnabled(false); 107 b.setDirection(mapDirection(true)); 108 return b; 109 } 110 111 private int lookupOneTouchSize() { 112 return DefaultLookup.getInt(splitPaneUI.getSplitPane(), splitPaneUI, 113 "SplitPaneDivider.oneTouchButtonSize", ONE_TOUCH_SIZE); 114 } 115 116 120 protected JButton createRightOneTouchButton() { 121 SynthArrowButton b = new SynthArrowButton (SwingConstants.NORTH); 122 int oneTouchSize = lookupOneTouchSize(); 123 124 b.setName("SplitPaneDivider.rightOneTouchButton"); 125 b.setMinimumSize(new Dimension(oneTouchSize, oneTouchSize)); 126 b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 127 b.setFocusPainted(false); 128 b.setBorderPainted(false); 129 b.setRequestFocusEnabled(false); 130 b.setDirection(mapDirection(false)); 131 return b; 132 } 133 } 134 | Popular Tags |