1 /* 2 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package javax.swing.plaf.synth; 27 28 import java.awt.*; 29 import java.beans.*; 30 import javax.swing.*; 31 import javax.swing.plaf.basic.*; 32 import sun.swing.DefaultLookup; 33 34 /** 35 * Synth's SplitPaneDivider. 36 * 37 * @author Scott Violet 38 */ 39 @SuppressWarnings("serial") // Superclass is not serializable across versions 40 class SynthSplitPaneDivider extends BasicSplitPaneDivider { 41 public SynthSplitPaneDivider(BasicSplitPaneUI ui) { 42 super(ui); 43 } 44 45 protected void setMouseOver(boolean mouseOver) { 46 if (isMouseOver() != mouseOver) { 47 repaint(); 48 } 49 super.setMouseOver(mouseOver); 50 } 51 52 public void propertyChange(PropertyChangeEvent e) { 53 super.propertyChange(e); 54 if (e.getSource() == splitPane) { 55 if (e.getPropertyName() == JSplitPane.ORIENTATION_PROPERTY) { 56 if (leftButton instanceof SynthArrowButton) { 57 ((SynthArrowButton)leftButton).setDirection( 58 mapDirection(true)); 59 } 60 if (rightButton instanceof SynthArrowButton) { 61 ((SynthArrowButton)rightButton).setDirection( 62 mapDirection(false)); 63 } 64 } 65 } 66 } 67 68 public void paint(Graphics g) { 69 Graphics g2 = g.create(); 70 71 SynthContext context = ((SynthSplitPaneUI)splitPaneUI).getContext( 72 splitPane, Region.SPLIT_PANE_DIVIDER); 73 Rectangle bounds = getBounds(); 74 bounds.x = bounds.y = 0; 75 SynthLookAndFeel.updateSubregion(context, g, bounds); 76 context.getPainter().paintSplitPaneDividerBackground(context, 77 g, 0, 0, bounds.width, bounds.height, 78 splitPane.getOrientation()); 79 80 SynthPainter foreground = null; 81 82 context.getPainter().paintSplitPaneDividerForeground(context, g, 0, 0, 83 getWidth(), getHeight(), splitPane.getOrientation()); 84 context.dispose(); 85 86 // super.paint(g2); 87 for (int counter = 0; counter < getComponentCount(); counter++) { 88 Component child = getComponent(counter); 89 Rectangle childBounds = child.getBounds(); 90 Graphics childG = g.create(childBounds.x, childBounds.y, 91 childBounds.width, childBounds.height); 92 child.paint(childG); 93 childG.dispose(); 94 } 95 g2.dispose(); 96 } 97 98 private int mapDirection(boolean isLeft) { 99 if (isLeft) { 100 if (splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT){ 101 return SwingConstants.WEST; 102 } 103 return SwingConstants.NORTH; 104 } 105 if (splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT){ 106 return SwingConstants.EAST; 107 } 108 return SwingConstants.SOUTH; 109 } 110 111 112 /** 113 * Creates and return an instance of JButton that can be used to 114 * collapse the left component in the split pane. 115 */ 116 protected JButton createLeftOneTouchButton() { 117 SynthArrowButton b = new SynthArrowButton(SwingConstants.NORTH); 118 int oneTouchSize = lookupOneTouchSize(); 119 120 b.setName("SplitPaneDivider.leftOneTouchButton"); 121 b.setMinimumSize(new Dimension(oneTouchSize, oneTouchSize)); 122 b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 123 b.setFocusPainted(false); 124 b.setBorderPainted(false); 125 b.setRequestFocusEnabled(false); 126 b.setDirection(mapDirection(true)); 127 return b; 128 } 129 130 private int lookupOneTouchSize() { 131 return DefaultLookup.getInt(splitPaneUI.getSplitPane(), splitPaneUI, 132 "SplitPaneDivider.oneTouchButtonSize", ONE_TOUCH_SIZE); 133 } 134 135 /** 136 * Creates and return an instance of JButton that can be used to 137 * collapse the right component in the split pane. 138 */ 139 protected JButton createRightOneTouchButton() { 140 SynthArrowButton b = new SynthArrowButton(SwingConstants.NORTH); 141 int oneTouchSize = lookupOneTouchSize(); 142 143 b.setName("SplitPaneDivider.rightOneTouchButton"); 144 b.setMinimumSize(new Dimension(oneTouchSize, oneTouchSize)); 145 b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 146 b.setFocusPainted(false); 147 b.setBorderPainted(false); 148 b.setRequestFocusEnabled(false); 149 b.setDirection(mapDirection(false)); 150 return b; 151 } 152 }