1 /* ==================================================================== 2 * 3 * Skin Look And Feel 6.7 License. 4 * 5 * Copyright (c) 2000-2006 L2FProd.com. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in 16 * the documentation and/or other materials provided with the 17 * distribution. 18 * 19 * 3. The end-user documentation included with the redistribution, if 20 * any, must include the following acknowlegement: 21 * "This product includes software developed by L2FProd.com 22 * (http://www.L2FProd.com/)." 23 * Alternately, this acknowlegement may appear in the software itself, 24 * if and wherever such third-party acknowlegements normally appear. 25 * 26 * 4. The names "Skin Look And Feel", "SkinLF" and "L2FProd.com" must not 27 * be used to endorse or promote products derived from this software 28 * without prior written permission. For written permission, please 29 * contact info@L2FProd.com. 30 * 31 * 5. Products derived from this software may not be called "SkinLF" 32 * nor may "SkinLF" appear in their names without prior written 33 * permission of L2FProd.com. 34 * 35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 38 * DISCLAIMED. IN NO EVENT SHALL L2FPROD.COM OR ITS CONTRIBUTORS BE 39 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 40 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 41 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 42 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 43 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 44 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 45 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 * ==================================================================== 47 */ 48 package com.l2fprod.gui.plaf.skin; 49 50 import java.awt.Component; 51 import java.awt.Container; 52 import java.awt.Cursor; 53 import java.awt.Dimension; 54 import java.awt.Graphics; 55 import java.awt.Insets; 56 import java.awt.LayoutManager; 57 import java.awt.Rectangle; 58 59 import javax.swing.JButton; 60 import javax.swing.JSplitPane; 61 import javax.swing.plaf.basic.BasicSplitPaneDivider; 62 import javax.swing.plaf.basic.BasicSplitPaneUI; 63 64 /** 65 * Description of the Class 66 * 67 * @author fred 68 * @created 27 avril 2002 69 */ 70 public final class SkinSplitPaneDivider extends BasicSplitPaneDivider implements javax.swing.SwingConstants { 71 72 /** 73 * Description of the Field 74 */ 75 protected Skin skin = SkinLookAndFeel.getSkin(); 76 final static Cursor defaultCursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); 77 final static Insets NO_INSETS = new Insets(0, 0, 0, 0); 78 79 /** 80 * Constructor for the SkinSplitPaneDivider object 81 * 82 * @param ui Description of Parameter 83 */ SkinSplitPaneDivider(BasicSplitPaneUI ui)84 public SkinSplitPaneDivider(BasicSplitPaneUI ui) { 85 super(ui); 86 setLayout(new DividerLayout()); 87 } 88 89 /** 90 * Sets the size of the divider to <code>newSize</code>. That is the 91 * width if the splitpane is <code>HORIZONTAL_SPLIT</code>, or the 92 * height of <code>VERTICAL_SPLIT</code> . 93 * 94 * @param newSize The new DividerSize value 95 */ setDividerSize(int newSize)96 public void setDividerSize(int newSize) { 97 dividerSize = newSize; 98 splitPane.setDividerSize(newSize); 99 } 100 101 /** 102 * Paints the divider. 103 * 104 * @param g Description of Parameter 105 */ paint(Graphics g)106 public void paint(Graphics g) { 107 108 //Paint the border. 109 //Border border = getBorder(); 110 //if (border != null) { 111 Dimension size = getSize(); 112 //border.paintBorder(this, g, 0, 0, size.width, size.height); 113 skin.getSplitPane().paintGutter(g, splitPane, size); 114 115 if (leftButton != null) { 116 Rectangle bounds = leftButton.getBounds(); 117 Graphics glb = g.create(bounds.x, bounds.y, bounds.width, bounds.height); 118 leftButton.paint(glb); 119 } 120 121 if (rightButton != null) { 122 Rectangle bounds = rightButton.getBounds(); 123 Graphics grb = g.create(bounds.x, bounds.y, bounds.width, bounds.height); 124 rightButton.paint(grb); 125 } 126 127 skin.getSplitPane().paintThumb(g, splitPane, size); 128 } 129 130 /** 131 * Creates and return an instance of JButton that can be used to collapse the 132 * left component in the split pane. 133 * 134 * @return Description of the Returned Value 135 */ createLeftOneTouchButton()136 protected JButton createLeftOneTouchButton() { 137 int button_direction = SOUTH; 138 if (orientation == JSplitPane.HORIZONTAL_SPLIT) { 139 button_direction = WEST; 140 } 141 JButton b = new SkinSplitArrowButton(button_direction); 142 b.setCursor(defaultCursor); 143 b.setFocusPainted(false); 144 b.setBorderPainted(false); 145 updateDividerSize(b.getPreferredSize()); 146 return b; 147 } 148 149 150 /** 151 * Creates and return an instance of JButton that can be used to collapse the 152 * right component in the split pane. 153 * 154 * @return Description of the Returned Value 155 */ createRightOneTouchButton()156 protected JButton createRightOneTouchButton() { 157 int button_direction = NORTH; 158 if (orientation == JSplitPane.HORIZONTAL_SPLIT) { 159 button_direction = EAST; 160 } 161 JButton b = new SkinSplitArrowButton(button_direction); 162 b.setCursor(defaultCursor); 163 b.setFocusPainted(false); 164 b.setBorderPainted(false); 165 updateDividerSize(b.getPreferredSize()); 166 return b; 167 } 168 169 /** 170 * Update the divider size to contain the appropriate dimension. 171 * 172 * @param d Description of Parameter 173 */ updateDividerSize(Dimension d)174 protected void updateDividerSize(Dimension d) { 175 int buttonSize; 176 if (orientation == JSplitPane.HORIZONTAL_SPLIT) { 177 buttonSize = d.width; 178 } 179 else { 180 buttonSize = d.height; 181 } 182 183 int sbSize = splitPane.getDividerSize(); 184 if (sbSize < buttonSize) { 185 splitPane.setDividerSize(buttonSize); 186 } 187 } 188 189 190 /** 191 * Description of the Class 192 * 193 * @author fred 194 * @created 27 avril 2002 195 */ 196 protected class DividerLayout implements LayoutManager { 197 /** 198 * Description of the Method 199 * 200 * @param c Description of Parameter 201 */ layoutContainer(Container c)202 public void layoutContainer(Container c) { 203 if (leftButton != null && rightButton != null && 204 c == SkinSplitPaneDivider.this) { 205 206 Dimension leftSize = leftButton.getPreferredSize(); 207 Dimension rightSize = rightButton.getPreferredSize(); 208 209 if (splitPane.isOneTouchExpandable()) { 210 Insets insets = getInsets(); 211 if (insets == null) { 212 insets = NO_INSETS; 213 } 214 if (orientation == JSplitPane.VERTICAL_SPLIT) { 215 int blockSize = getDividerSize() - (insets.left + insets.right); 216 int y = (c.getSize().height - blockSize) / 2; 217 leftButton.setBounds(insets.left + leftSize.width, y, leftSize.width, leftSize.height); 218 rightButton.setBounds((insets.left * 2) + leftSize.width + 219 rightSize.width, y, rightSize.width, rightSize.height); 220 } 221 else { 222 int blockSize = getDividerSize() - (insets.top + insets.bottom); 223 int x = (c.getSize().width - blockSize) / 2; 224 leftButton.setBounds(x, insets.top + leftSize.height, leftSize.width, leftSize.height); 225 rightButton.setBounds(x, (insets.top * 2) + leftSize.height + 226 rightSize.height, rightSize.width, rightSize.height); 227 } 228 } 229 else { 230 leftButton.setBounds(-5, -5, 1, 1); 231 rightButton.setBounds(-5, -5, 1, 1); 232 } 233 } 234 } 235 minimumLayoutSize(Container c)236 public Dimension minimumLayoutSize(Container c) { 237 return new Dimension(0,0); 238 } 239 preferredLayoutSize(Container c)240 public Dimension preferredLayoutSize(Container c) { 241 return new Dimension(0, 0); 242 } 243 removeLayoutComponent(Component c)244 public void removeLayoutComponent(Component c) {} 245 addLayoutComponent(String string, Component c)246 public void addLayoutComponent(String string, Component c) {} 247 } 248 249 } 250