1 /* 2 * Copyright (c) 1998, 2004, 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.metal; 27 28 import java.awt.Component; 29 import java.awt.Container; 30 import java.awt.LayoutManager; 31 import java.awt.Adjustable; 32 import java.awt.event.AdjustmentListener; 33 import java.awt.event.AdjustmentEvent; 34 import java.awt.event.ActionListener; 35 import java.awt.event.ActionEvent; 36 import java.awt.event.MouseListener; 37 import java.awt.event.MouseMotionListener; 38 import java.awt.event.MouseAdapter; 39 import java.awt.event.MouseEvent; 40 import java.awt.Graphics; 41 import java.awt.Dimension; 42 import java.awt.Rectangle; 43 import java.awt.Point; 44 import java.awt.Insets; 45 import java.awt.Color; 46 import java.awt.IllegalComponentStateException; 47 48 import java.beans.*; 49 50 import javax.swing.*; 51 import javax.swing.event.*; 52 53 import javax.swing.plaf.*; 54 import javax.swing.plaf.basic.BasicScrollBarUI; 55 56 57 /** 58 * Implementation of ScrollBarUI for the Metal Look and Feel 59 * <p> 60 * 61 * @author Tom Santos 62 * @author Steve Wilson 63 */ 64 public class MetalScrollBarUI extends BasicScrollBarUI 65 { 66 private static Color shadowColor; 67 private static Color highlightColor; 68 private static Color darkShadowColor; 69 private static Color thumbColor; 70 private static Color thumbShadow; 71 private static Color thumbHighlightColor; 72 73 74 protected MetalBumps bumps; 75 142 return increaseButton; 143 } 144 145 protected void paintTrack( Graphics g, JComponent c, Rectangle trackBounds ) 146 { 147 g.translate( trackBounds.x, trackBounds.y ); 148 149 boolean leftToRight = MetalUtils.isLeftToRight(c); 150 151 if ( scrollbar.getOrientation() == JScrollBar.VERTICAL ) 152 { 153 if ( !isFreeStanding ) { 154 trackBounds.width += 2; 155 if ( !leftToRight ) { 156 g.translate( -1, 0 ); 157 } 158 } 159 160 if ( c.isEnabled() ) { 161 g.setColor( darkShadowColor ); 162 g.drawLine( 0, 0, 0, trackBounds.height - 1 ); 163 g.drawLine( trackBounds.width - 2, 0, trackBounds.width - 2, trackBounds.height - 1 ); 164 g.drawLine( 2, trackBounds.height - 1, trackBounds.width - 1, trackBounds.height - 1); 165 g.drawLine( 2, 0, trackBounds.width - 2, 0 ); 166 167 g.setColor( shadowColor ); 168 // g.setColor( Color.red); 169 g.drawLine( 1, 1, 1, trackBounds.height - 2 ); 170 g.drawLine( 1, 1, trackBounds.width - 3, 1 ); 171 if (scrollbar.getValue() != scrollbar.getMaximum()) { // thumb shadow 172 int y = thumbRect.y + thumbRect.height - trackBounds.y; 173 g.drawLine( 1, y, trackBounds.width-1, y); 174 } 175 g.setColor(highlightColor); 176 g.drawLine( trackBounds.width - 1, 0, trackBounds.width - 1, trackBounds.height - 1 ); 177 } else { 178 MetalUtils.drawDisabledBorder(g, 0, 0, trackBounds.width, trackBounds.height ); 179 } 180 181 if ( !isFreeStanding ) { 182 trackBounds.width -= 2; 183 if ( !leftToRight ) { 184 g.translate( 1, 0 ); 185 } 186 } 187 } 188 else // HORIZONTAL 189 { 190 if ( !isFreeStanding ) { 191 trackBounds.height += 2; 192 } 193 194 if ( c.isEnabled() ) { 195 g.setColor( darkShadowColor ); 196 g.drawLine( 0, 0, trackBounds.width - 1, 0 ); // top 197 g.drawLine( 0, 2, 0, trackBounds.height - 2 ); // left 198 g.drawLine( 0, trackBounds.height - 2, trackBounds.width - 1, trackBounds.height - 2 ); // bottom 199 g.drawLine( trackBounds.width - 1, 2, trackBounds.width - 1, trackBounds.height - 1 ); // right 200 201 g.setColor( shadowColor ); 202 // g.setColor( Color.red); 203 g.drawLine( 1, 1, trackBounds.width - 2, 1 ); // top 204 g.drawLine( 1, 1, 1, trackBounds.height - 3 ); // left 205 g.drawLine( 0, trackBounds.height - 1, trackBounds.width - 1, trackBounds.height - 1 ); // bottom 206 if (scrollbar.getValue() != scrollbar.getMaximum()) { // thumb shadow 207 int x = thumbRect.x + thumbRect.width - trackBounds.x; 208 g.drawLine( x, 1, x, trackBounds.height-1); 209 } 210 } else { 211 MetalUtils.drawDisabledBorder(g, 0, 0, trackBounds.width, trackBounds.height ); 212 } 213 214 if ( !isFreeStanding ) { 215 trackBounds.height -= 2; 216 } 217 } 218 219 g.translate( -trackBounds.x, -trackBounds.y ); 220 } 221 222 protected void paintThumb( Graphics g, JComponent c, Rectangle thumbBounds ) 223 { 224 if (!c.isEnabled()) { 225 return; 226 } 227 228 if (MetalLookAndFeel.usingOcean()) { 230 return; 231 } 232 233 boolean leftToRight = MetalUtils.isLeftToRight(c); 234 235 g.translate( thumbBounds.x, thumbBounds.y ); 236 237 if ( scrollbar.getOrientation() == JScrollBar.VERTICAL ) 238 { 239 if ( !isFreeStanding ) { 240 thumbBounds.width += 2; 241 if ( !leftToRight ) { 242 g.translate( -1, 0 ); 243 } 244 } 245 246 g.setColor( thumbColor ); 247 g.fillRect( 0, 0, thumbBounds.width - 2, thumbBounds.height - 1 ); 248 249 g.setColor( thumbShadow ); 250 g.drawRect( 0, 0, thumbBounds.width - 2, thumbBounds.height - 1 ); 251 252 g.setColor( thumbHighlightColor ); 253 g.drawLine( 1, 1, thumbBounds.width - 3, 1 ); 254 g.drawLine( 1, 1, 1, thumbBounds.height - 2 ); 255 256 bumps.setBumpArea( thumbBounds.width - 6, thumbBounds.height - 7 ); 257 bumps.paintIcon( c, g, 3, 4 ); 258 259 if ( !isFreeStanding ) { 260 thumbBounds.width -= 2; 261 if ( !leftToRight ) { 262 g.translate( 1, 0 ); 263 } 264 } 265 } 266 else // HORIZONTAL 267 { 268 if ( !isFreeStanding ) { 269 thumbBounds.height += 2; 270 } 271 272 g.setColor( thumbColor ); 273 g.fillRect( 0, 0, thumbBounds.width - 1, thumbBounds.height - 2 ); 274 275 g.setColor( thumbShadow ); 276 g.drawRect( 0, 0, thumbBounds.width - 1, thumbBounds.height - 2 ); 277 278 g.setColor( thumbHighlightColor ); 279 g.drawLine( 1, 1, thumbBounds.width - 3, 1 ); 280 g.drawLine( 1, 1, 1, thumbBounds.height - 3 ); 281 282 bumps.setBumpArea( thumbBounds.width - 7, thumbBounds.height - 6 ); 283 bumps.paintIcon( c, g, 4, 3 ); 284 285 if ( !isFreeStanding ) { 286 thumbBounds.height -= 2; 287 } 288 } 289 290 g.translate( -thumbBounds.x, -thumbBounds.y ); 291 } 292 293 private void oceanPaintThumb(Graphics g, JComponent c, 294 Rectangle thumbBounds) { 295 boolean leftToRight = MetalUtils.isLeftToRight(c); 296 297 g.translate(thumbBounds.x, thumbBounds.y); 298 299 if (scrollbar.getOrientation() == JScrollBar.VERTICAL) { 300 if (!isFreeStanding) { 301 thumbBounds.width += 2; 302 if (!leftToRight) { 303 g.translate(-1, 0); 304 } 305 } 306 307 if (thumbColor != null) { 308 g.setColor(thumbColor); 309 g.fillRect(0, 0, thumbBounds.width - 2,thumbBounds.height - 1); 310 } 311 312 g.setColor(thumbShadow); 313 g.drawRect(0, 0, thumbBounds.width - 2, thumbBounds.height - 1); 314 315 g.setColor(thumbHighlightColor); 316 g.drawLine(1, 1, thumbBounds.width - 3, 1); 317 g.drawLine(1, 1, 1, thumbBounds.height - 2); 318 319 MetalUtils.drawGradient(c, g, "ScrollBar.gradient", 2, 2, 320 thumbBounds.width - 4, 321 thumbBounds.height - 3, false); 322 323 int gripSize = thumbBounds.width - 8; 324 if (gripSize > 2 && thumbBounds.height >= 10) { 325 g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); 326 int gripY = thumbBounds.height / 2 - 2; 327 for (int counter = 0; counter < 6; counter += 2) { 328 g.fillRect(4, counter + gripY, gripSize, 1); 329 } 330 331 g.setColor(MetalLookAndFeel.getWhite()); 332 gripY++; 333 for (int counter = 0; counter < 6; counter += 2) { 334 g.fillRect(5, counter + gripY, gripSize, 1); 335 } 336 } 337 if (!isFreeStanding) { 338 thumbBounds.width -= 2; 339 if (!leftToRight) { 340 g.translate(1, 0); 341 } 342 } 343 } 344 else { // HORIZONTAL 345 if (!isFreeStanding) { 346 thumbBounds.height += 2; 347 } 348 349 if (thumbColor != null) { 350 g.setColor(thumbColor); 351 g.fillRect(0, 0, thumbBounds.width - 1,thumbBounds.height - 2); 352 } 353 354 g.setColor(thumbShadow); 355 g.drawRect(0, 0, thumbBounds.width - 1, thumbBounds.height - 2); 356 357 g.setColor(thumbHighlightColor); 358 g.drawLine(1, 1, thumbBounds.width - 2, 1); 359 g.drawLine(1, 1, 1, thumbBounds.height - 3); 360 361 MetalUtils.drawGradient(c, g, "ScrollBar.gradient", 2, 2, 362 thumbBounds.width - 3, 363 thumbBounds.height - 4, true); 364 365 int gripSize = thumbBounds.height - 8; 366 if (gripSize > 2 && thumbBounds.width >= 10) { 367 g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); 368 int gripX = thumbBounds.width / 2 - 2; 369 for (int counter = 0; counter < 6; counter += 2) { 370 g.fillRect(gripX + counter, 4, 1, gripSize); 371 } 372 373 g.setColor(MetalLookAndFeel.getWhite()); 374 gripX++; 375 for (int counter = 0; counter < 6; counter += 2) { 376 g.fillRect(gripX + counter, 5, 1, gripSize); 377 } 378 } 379 | 1 /* 2 * Copyright (c) 1998, 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.metal; 27 28 import java.awt.Color; 29 import java.awt.Dimension; 30 import java.awt.Graphics; 31 import java.awt.Rectangle; 32 import java.beans.PropertyChangeEvent; 33 import java.beans.PropertyChangeListener; 34 35 import javax.swing.JButton; 36 import javax.swing.JComponent; 37 import javax.swing.JScrollBar; 38 import javax.swing.UIManager; 39 import javax.swing.plaf.ComponentUI; 40 import javax.swing.plaf.basic.BasicScrollBarUI; 41 42 import static sun.swing.SwingUtilities2.drawHLine; 43 import static sun.swing.SwingUtilities2.drawRect; 44 import static sun.swing.SwingUtilities2.drawVLine; 45 46 47 /** 48 * Implementation of ScrollBarUI for the Metal Look and Feel 49 * <p> 50 * 51 * @author Tom Santos 52 * @author Steve Wilson 53 */ 54 public class MetalScrollBarUI extends BasicScrollBarUI 55 { 56 private static Color shadowColor; 57 private static Color highlightColor; 58 private static Color darkShadowColor; 59 private static Color thumbColor; 60 private static Color thumbShadow; 61 private static Color thumbHighlightColor; 62 63 64 protected MetalBumps bumps; 65 132 return increaseButton; 133 } 134 135 protected void paintTrack( Graphics g, JComponent c, Rectangle trackBounds ) 136 { 137 g.translate( trackBounds.x, trackBounds.y ); 138 139 boolean leftToRight = MetalUtils.isLeftToRight(c); 140 141 if ( scrollbar.getOrientation() == JScrollBar.VERTICAL ) 142 { 143 if ( !isFreeStanding ) { 144 trackBounds.width += 2; 145 if ( !leftToRight ) { 146 g.translate( -1, 0 ); 147 } 148 } 149 150 if ( c.isEnabled() ) { 151 g.setColor( darkShadowColor ); 152 drawVLine(g, 0, 0, trackBounds.height - 1); 153 drawVLine(g, trackBounds.width - 2, 0, trackBounds.height - 1); 154 drawHLine(g, 2, trackBounds.width - 1, trackBounds.height - 1); 155 drawHLine(g, 2, trackBounds.width - 2, 0); 156 157 g.setColor( shadowColor ); 158 // g.setColor( Color.red); 159 drawVLine(g, 1, 1, trackBounds.height - 2); 160 drawHLine(g, 1, trackBounds.width - 3, 1); 161 if (scrollbar.getValue() != scrollbar.getMaximum()) { // thumb shadow 162 int y = thumbRect.y + thumbRect.height - trackBounds.y; 163 drawHLine(g, 1, trackBounds.width - 1, y); 164 } 165 g.setColor(highlightColor); 166 drawVLine(g, trackBounds.width - 1, 0, trackBounds.height - 1); 167 } else { 168 MetalUtils.drawDisabledBorder(g, 0, 0, trackBounds.width, trackBounds.height ); 169 } 170 171 if ( !isFreeStanding ) { 172 trackBounds.width -= 2; 173 if ( !leftToRight ) { 174 g.translate( 1, 0 ); 175 } 176 } 177 } 178 else // HORIZONTAL 179 { 180 if ( !isFreeStanding ) { 181 trackBounds.height += 2; 182 } 183 184 if ( c.isEnabled() ) { 185 g.setColor( darkShadowColor ); 186 drawHLine(g, 0, trackBounds.width - 1, 0); // top 187 drawVLine(g, 0, 2, trackBounds.height - 2); // left 188 drawHLine(g, 0, trackBounds.width - 1, trackBounds.height - 2 ); // bottom 189 drawVLine(g, trackBounds.width - 1, 2, trackBounds.height - 1 ); // right 190 191 g.setColor( shadowColor ); 192 // g.setColor( Color.red); 193 drawHLine(g, 1, trackBounds.width - 2, 1 ); // top 194 drawVLine(g, 1, 1, trackBounds.height - 3 ); // left 195 drawHLine(g, 0, trackBounds.width - 1, trackBounds.height - 1 ); // bottom 196 if (scrollbar.getValue() != scrollbar.getMaximum()) { // thumb shadow 197 int x = thumbRect.x + thumbRect.width - trackBounds.x; 198 drawVLine(g, x, 1, trackBounds.height-1); 199 } 200 } else { 201 MetalUtils.drawDisabledBorder(g, 0, 0, trackBounds.width, trackBounds.height ); 202 } 203 204 if ( !isFreeStanding ) { 205 trackBounds.height -= 2; 206 } 207 } 208 209 g.translate( -trackBounds.x, -trackBounds.y ); 210 } 211 212 protected void paintThumb( Graphics g, JComponent c, Rectangle thumbBounds ) 213 { 214 if (!c.isEnabled()) { 215 return; 216 } 217 218 if (MetalLookAndFeel.usingOcean()) { 220 return; 221 } 222 223 boolean leftToRight = MetalUtils.isLeftToRight(c); 224 225 g.translate( thumbBounds.x, thumbBounds.y ); 226 227 if ( scrollbar.getOrientation() == JScrollBar.VERTICAL ) 228 { 229 if ( !isFreeStanding ) { 230 thumbBounds.width += 2; 231 if ( !leftToRight ) { 232 g.translate( -1, 0 ); 233 } 234 } 235 236 g.setColor( thumbColor ); 237 g.fillRect( 0, 0, thumbBounds.width - 2, thumbBounds.height - 1 ); 238 239 g.setColor( thumbShadow ); 240 drawRect(g, 0, 0, thumbBounds.width - 2, thumbBounds.height - 1); 241 242 g.setColor( thumbHighlightColor ); 243 drawHLine(g, 1, thumbBounds.width - 3, 1); 244 drawVLine(g, 1, 1, thumbBounds.height - 2); 245 246 bumps.setBumpArea( thumbBounds.width - 6, thumbBounds.height - 7 ); 247 bumps.paintIcon( c, g, 3, 4 ); 248 249 if ( !isFreeStanding ) { 250 thumbBounds.width -= 2; 251 if ( !leftToRight ) { 252 g.translate( 1, 0 ); 253 } 254 } 255 } 256 else // HORIZONTAL 257 { 258 if ( !isFreeStanding ) { 259 thumbBounds.height += 2; 260 } 261 262 g.setColor( thumbColor ); 263 g.fillRect( 0, 0, thumbBounds.width - 1, thumbBounds.height - 2 ); 264 265 g.setColor( thumbShadow ); 266 drawRect(g, 0, 0, thumbBounds.width - 1, thumbBounds.height - 2); 267 268 g.setColor( thumbHighlightColor ); 269 drawHLine(g, 1, thumbBounds.width - 3, 1); 270 drawVLine(g, 1, 1, thumbBounds.height - 3); 271 272 bumps.setBumpArea( thumbBounds.width - 7, thumbBounds.height - 6 ); 273 bumps.paintIcon( c, g, 4, 3 ); 274 275 if ( !isFreeStanding ) { 276 thumbBounds.height -= 2; 277 } 278 } 279 280 g.translate( -thumbBounds.x, -thumbBounds.y ); 281 } 282 283 private void oceanPaintThumb(Graphics g, JComponent c, 284 Rectangle thumbBounds) { 285 boolean leftToRight = MetalUtils.isLeftToRight(c); 286 287 g.translate(thumbBounds.x, thumbBounds.y); 288 289 if (scrollbar.getOrientation() == JScrollBar.VERTICAL) { 290 if (!isFreeStanding) { 291 thumbBounds.width += 2; 292 if (!leftToRight) { 293 g.translate(-1, 0); 294 } 295 } 296 297 if (thumbColor != null) { 298 g.setColor(thumbColor); 299 g.fillRect(0, 0, thumbBounds.width - 2,thumbBounds.height - 1); 300 } 301 302 g.setColor(thumbShadow); 303 drawRect(g, 0, 0, thumbBounds.width - 2, thumbBounds.height - 1); 304 305 g.setColor(thumbHighlightColor); 306 drawHLine(g, 1, thumbBounds.width - 3, 1); 307 drawVLine(g, 1, 1, thumbBounds.height - 2); 308 309 MetalUtils.drawGradient(c, g, "ScrollBar.gradient", 2, 2, 310 thumbBounds.width - 4, 311 thumbBounds.height - 3, false); 312 313 int gripSize = thumbBounds.width - 8; 314 if (gripSize > 2 && thumbBounds.height >= 10) { 315 g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); 316 int gripY = thumbBounds.height / 2 - 2; 317 for (int counter = 0; counter < 6; counter += 2) { 318 g.fillRect(4, counter + gripY, gripSize, 1); 319 } 320 321 g.setColor(MetalLookAndFeel.getWhite()); 322 gripY++; 323 for (int counter = 0; counter < 6; counter += 2) { 324 g.fillRect(5, counter + gripY, gripSize, 1); 325 } 326 } 327 if (!isFreeStanding) { 328 thumbBounds.width -= 2; 329 if (!leftToRight) { 330 g.translate(1, 0); 331 } 332 } 333 } 334 else { // HORIZONTAL 335 if (!isFreeStanding) { 336 thumbBounds.height += 2; 337 } 338 339 if (thumbColor != null) { 340 g.setColor(thumbColor); 341 g.fillRect(0, 0, thumbBounds.width - 1,thumbBounds.height - 2); 342 } 343 344 g.setColor(thumbShadow); 345 drawRect(g, 0, 0, thumbBounds.width - 1, thumbBounds.height - 2); 346 347 g.setColor(thumbHighlightColor); 348 drawHLine(g, 1, thumbBounds.width - 2, 1); 349 drawVLine(g, 1, 1, thumbBounds.height - 3); 350 351 MetalUtils.drawGradient(c, g, "ScrollBar.gradient", 2, 2, 352 thumbBounds.width - 3, 353 thumbBounds.height - 4, true); 354 355 int gripSize = thumbBounds.height - 8; 356 if (gripSize > 2 && thumbBounds.width >= 10) { 357 g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); 358 int gripX = thumbBounds.width / 2 - 2; 359 for (int counter = 0; counter < 6; counter += 2) { 360 g.fillRect(gripX + counter, 4, 1, gripSize); 361 } 362 363 g.setColor(MetalLookAndFeel.getWhite()); 364 gripX++; 365 for (int counter = 0; counter < 6; counter += 2) { 366 g.fillRect(gripX + counter, 5, 1, gripSize); 367 } 368 } 369 |