1 30 31 package com.jgoodies.looks.windows; 32 33 import java.awt.Color ; 34 import java.awt.Component ; 35 import java.awt.Container ; 36 import java.awt.Dimension ; 37 import java.awt.Graphics ; 38 import java.awt.LayoutManager ; 39 40 import javax.swing.JButton ; 41 import javax.swing.JSplitPane ; 42 import javax.swing.UIManager ; 43 import javax.swing.border.Border ; 44 import javax.swing.plaf.basic.BasicSplitPaneUI ; 45 46 import com.jgoodies.looks.plastic.PlasticSplitPaneUI; 47 48 56 final class WindowsSplitPaneDivider extends com.sun.java.swing.plaf.windows.WindowsSplitPaneDivider { 57 58 private static final int EXT_ONE_TOUCH_SIZE = 5; 59 private static final int EXT_ONE_TOUCH_OFFSET = 2; 60 private static final int EXT_BLOCKSIZE = 6; 61 62 70 public final class ExtWindowsDividerLayout implements LayoutManager { 71 public void layoutContainer(Container c) { 72 JButton theLeftButton = getLeftButtonFromSuper(); 73 JButton theRightButton = getRightButtonFromSuper(); 74 JSplitPane theSplitPane = getSplitPaneFromSuper(); 75 int theOrientation = getOrientationFromSuper(); 76 int oneTouchSize = getOneTouchSize(); 77 int oneTouchOffset = getOneTouchOffset(); 78 int blockSize = 5; 79 81 if (theLeftButton != null 86 && theRightButton != null 87 && c == WindowsSplitPaneDivider.this) { 88 if (theSplitPane.isOneTouchExpandable()) { 89 if (theOrientation == JSplitPane.VERTICAL_SPLIT) { 90 theLeftButton.setBounds( 91 oneTouchOffset, 92 0, 93 blockSize * 2, 94 blockSize); 95 theRightButton.setBounds( 96 oneTouchOffset + oneTouchSize * 2, 97 0, 98 blockSize * 2, 99 blockSize); 100 } else { 101 theLeftButton.setBounds( 102 0, 103 oneTouchOffset, 104 blockSize, 105 blockSize * 2); 106 theRightButton.setBounds( 107 0, 108 oneTouchOffset + oneTouchSize * 2, 109 blockSize, 110 blockSize * 2); 111 } 112 } else { 113 theLeftButton.setBounds(-5, -5, 1, 1); 114 theRightButton.setBounds(-5, -5, 1, 1); 115 } 116 } 117 } 118 119 public Dimension minimumLayoutSize(Container c) { 120 return new Dimension (0, 0); 121 } 122 public Dimension preferredLayoutSize(Container c) { 123 return new Dimension (0, 0); 124 } 125 public void removeLayoutComponent(Component c) { 126 } 128 public void addLayoutComponent(String string, Component c) { 129 } 131 } 132 133 public WindowsSplitPaneDivider(BasicSplitPaneUI ui) { 134 super(ui); 135 setLayout(new ExtWindowsDividerLayout()); 136 } 137 138 142 protected JButton createLeftOneTouchButton() { 143 JButton b = new JButton () { 144 int[][] buffer = { { 0, 0, 0, 2, 2, 0, 0, 0, 0 }, { 146 0, 0, 2, 1, 1, 1, 0, 0, 0 }, { 147 0, 2, 1, 1, 1, 1, 1, 0, 0 }, { 148 2, 1, 1, 1, 1, 1, 1, 1, 0 }, { 149 0, 3, 3, 3, 3, 3, 3, 3, 3 } 150 }; 151 152 public void setBorder(Border border) { 153 } 155 156 public void paint(Graphics g) { 157 JSplitPane theSplitPane = getSplitPaneFromSuper(); 158 if (theSplitPane != null) { 159 int theOrientation = getOrientationFromSuper(); 160 int blockSize = buffer.length + 1; 161 163 Color [] colors = 165 { 166 this.getBackground(), 167 UIManager.getColor("controlDkShadow"), 168 Color.black, 169 UIManager.getColor("controlLtHighlight")}; 171 172 g.setColor(this.getBackground()); 174 g.fillRect(0, 0, this.getWidth(), this.getHeight()); 175 176 if (getModel().isPressed()) { 178 colors[1] = colors[2]; 180 } 181 if (theOrientation == JSplitPane.VERTICAL_SPLIT) { 182 for (int i = 1; i <= buffer[0].length; i++) { 184 for (int j = 1; j < blockSize; j++) { 185 if (buffer[j - 1][i - 1] == 0) { 186 continue; 187 } else { 188 g.setColor(colors[buffer[j - 1][i - 1]]); 189 } 190 g.drawLine(i - 1, j, i - 1, j); 191 } 192 } 193 } else { 194 for (int i = 1; i <= buffer[0].length; i++) { 201 for (int j = 1; j < blockSize; j++) { 202 if (buffer[j - 1][i - 1] == 0) { 203 continue; 206 } else { 207 g.setColor(colors[buffer[j - 1][i - 1]]); 210 } 211 g.drawLine(j - 1, i, j - 1, i); 213 } 214 } 215 } 216 } 217 } 218 219 }; 220 b.setFocusPainted(false); 221 b.setBorderPainted(false); 222 b.setFocusable(false); 223 return b; 224 } 225 226 230 protected JButton createRightOneTouchButton() { 231 JButton b = new JButton () { 232 int[][] buffer = { { 2, 2, 2, 2, 2, 2, 2, 2 }, { 234 0, 1, 1, 1, 1, 1, 1, 3 }, { 235 0, 0, 1, 1, 1, 1, 3, 0 }, { 236 0, 0, 0, 1, 1, 3, 0, 0 }, { 237 0, 0, 0, 0, 3, 0, 0, 0 } 238 }; 239 240 public void setBorder(Border border) { 241 } 243 244 public void paint(Graphics g) { 245 JSplitPane theSplitPane = getSplitPaneFromSuper(); 246 if (theSplitPane != null) { 247 int theOrientation = getOrientationFromSuper(); 248 int blockSize = buffer.length + 1; 249 251 Color [] colors = 253 { 254 this.getBackground(), 255 UIManager.getColor("controlDkShadow"), 256 Color.black, 257 UIManager.getColor("controlLtHighlight")}; 259 260 g.setColor(this.getBackground()); 262 g.fillRect(0, 0, this.getWidth(), this.getHeight()); 263 264 if (getModel().isPressed()) { 266 colors[1] = colors[2]; 268 } 269 if (theOrientation == JSplitPane.VERTICAL_SPLIT) { 270 for (int i = 1; i <= buffer[0].length; i++) { 272 for (int j = 1; j < blockSize; j++) { 273 if (buffer[j - 1][i - 1] == 0) { 274 continue; 275 } else { 276 g.setColor(colors[buffer[j - 1][i - 1]]); 277 } 278 g.drawLine(i, j, i, j); 279 } 280 } 281 } else { 282 for (int i = 1; i <= buffer[0].length; i++) { 289 for (int j = 1; j < blockSize; j++) { 290 if (buffer[j - 1][i - 1] == 0) { 291 continue; 294 } else { 295 g.setColor(colors[buffer[j - 1][i - 1]]); 298 } 299 g.drawLine(j - 1, i, j - 1, i); 301 } 302 } 303 } 304 } 305 } 306 }; 307 b.setFocusPainted(false); 308 b.setBorderPainted(false); 309 b.setFocusable(false); 310 return b; 311 } 312 313 int getBlockSize() { 314 return EXT_BLOCKSIZE; 315 } 316 317 int getOneTouchOffset() { 318 return EXT_ONE_TOUCH_OFFSET; 319 } 320 321 int getOneTouchSize() { 322 return EXT_ONE_TOUCH_SIZE; 323 } 324 325 int getOrientationFromSuper() { 326 return super.orientation; 327 } 328 329 JButton getLeftButtonFromSuper() { 330 return super.leftButton; 331 } 332 333 JButton getRightButtonFromSuper() { 334 return super.rightButton; 335 } 336 337 JSplitPane getSplitPaneFromSuper() { 338 return super.splitPane; 339 } 340 341 } | Popular Tags |