~ubuntu-branches/ubuntu/precise/classpath/precise

« back to all changes in this revision

Viewing changes to javax/swing/plaf/metal/MetalScrollBarUI.java

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2006-05-27 16:11:15 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060527161115-h6e39eposdt5snb6
Tags: 2:0.91-3
* Install header files to /usr/include/classpath.
* debian/control: classpath: Conflict with jamvm < 1.4.3 and
  cacao < 0.96 (Closes: #368172).

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
import java.awt.Color;
42
42
import java.awt.Dimension;
43
43
import java.awt.Graphics;
 
44
import java.awt.Insets;
44
45
import java.awt.Rectangle;
45
46
import java.beans.PropertyChangeEvent;
46
47
import java.beans.PropertyChangeListener;
48
49
import javax.swing.JButton;
49
50
import javax.swing.JComponent;
50
51
import javax.swing.JScrollBar;
51
 
import javax.swing.UIDefaults;
 
52
import javax.swing.SwingConstants;
52
53
import javax.swing.UIManager;
53
54
import javax.swing.plaf.ComponentUI;
54
55
import javax.swing.plaf.basic.BasicScrollBarUI;
195
196
   */
196
197
  protected JButton createDecreaseButton(int orientation)
197
198
  {
198
 
    UIDefaults defaults = UIManager.getLookAndFeelDefaults();
199
 
    scrollBarWidth = defaults.getInt("ScrollBar.width");
 
199
    scrollBarWidth = UIManager.getInt("ScrollBar.width");
200
200
    decreaseButton = new MetalScrollButton(orientation, scrollBarWidth, 
201
201
            isFreeStanding);
202
202
    return decreaseButton;
213
213
   */
214
214
  protected JButton createIncreaseButton(int orientation)
215
215
  {
216
 
    UIDefaults defaults = UIManager.getLookAndFeelDefaults();
217
 
    scrollBarWidth = defaults.getInt("ScrollBar.width");
 
216
    scrollBarWidth = UIManager.getInt("ScrollBar.width");
218
217
    increaseButton = new MetalScrollButton(orientation, scrollBarWidth, 
219
218
            isFreeStanding);
220
219
    return increaseButton;
350
349
    else 
351
350
      paintThumbVertical(g, c, thumbBounds);
352
351
 
353
 
    // draw the pattern
354
 
    MetalUtils.fillMetalPattern(c, g, thumbBounds.x + 3, thumbBounds.y + 3,
355
 
            thumbBounds.width - 6, thumbBounds.height - 6,
356
 
            thumbHighlightColor, thumbLightShadowColor);
 
352
    // Draw the pattern when the theme is not Ocean.
 
353
    if (! (MetalLookAndFeel.getCurrentTheme() instanceof OceanTheme))
 
354
      {
 
355
        MetalUtils.fillMetalPattern(c, g, thumbBounds.x + 3, thumbBounds.y + 3,
 
356
                                    thumbBounds.width - 6,
 
357
                                    thumbBounds.height - 6,
 
358
                                    thumbHighlightColor,
 
359
                                    thumbLightShadowColor);
 
360
      }
357
361
  }
358
362
 
359
363
  /**
371
375
    int w = thumbBounds.width;
372
376
    int h = thumbBounds.height;
373
377
    
374
 
    // first we fill the background
375
 
    g.setColor(thumbColor);
376
 
    if (isFreeStanding)
377
 
      g.fillRect(x, y, w, h - 1);
 
378
    // First we fill the background.
 
379
    MetalTheme theme = MetalLookAndFeel.getCurrentTheme();
 
380
    if (theme instanceof OceanTheme
 
381
        && UIManager.get("ScrollBar.gradient") != null)
 
382
      {
 
383
        MetalUtils.paintGradient(g, x + 2, y + 2, w - 4, h - 2,
 
384
                                 SwingConstants.VERTICAL,
 
385
                                 "ScrollBar.gradient");
 
386
      }
378
387
    else
379
 
      g.fillRect(x, y, w, h);
380
 
    
 
388
      {
 
389
        g.setColor(thumbColor);
 
390
        if (isFreeStanding)
 
391
          g.fillRect(x, y, w, h - 1);
 
392
        else
 
393
          g.fillRect(x, y, w, h);
 
394
      }
 
395
 
381
396
    // then draw the dark box
382
397
    g.setColor(thumbLightShadowColor);
383
398
    if (isFreeStanding)
403
418
      }
404
419
    
405
420
    // draw the shadow line
406
 
    UIDefaults def = UIManager.getLookAndFeelDefaults();
407
 
    g.setColor(def.getColor("ScrollBar.shadow"));
 
421
    g.setColor(UIManager.getColor("ScrollBar.shadow"));
408
422
    g.drawLine(x + w, y + 1, x + w, y + h - 1);
409
423
 
 
424
    // For the OceanTheme, draw the 3 lines in the middle.
 
425
    if (theme instanceof OceanTheme)
 
426
      {
 
427
        g.setColor(thumbLightShadowColor);
 
428
        int middle = x + w / 2;
 
429
        g.drawLine(middle - 2, y + 4, middle - 2, y + h - 5);
 
430
        g.drawLine(middle, y + 4, middle, y + h - 5);
 
431
        g.drawLine(middle + 2, y + 4, middle + 2, y + h - 5);
 
432
        g.setColor(UIManager.getColor("ScrollBar.highlight"));
 
433
        g.drawLine(middle - 1, y + 5, middle - 1, y + h - 4);
 
434
        g.drawLine(middle + 1, y + 5, middle + 1, y + h - 4);
 
435
        g.drawLine(middle + 3, y + 5, middle + 3, y + h - 4);
 
436
      }
410
437
  }
411
438
  
412
439
  /**
424
451
    int w = thumbBounds.width;
425
452
    int h = thumbBounds.height;
426
453
    
427
 
    // first we fill the background
428
 
    g.setColor(thumbColor);
429
 
    if (isFreeStanding)
430
 
      g.fillRect(x, y, w - 1, h);
 
454
    // First we fill the background.
 
455
    MetalTheme theme = MetalLookAndFeel.getCurrentTheme();
 
456
    if (theme instanceof OceanTheme
 
457
        && UIManager.get("ScrollBar.gradient") != null)
 
458
      {
 
459
        MetalUtils.paintGradient(g, x + 2, y + 2, w - 2, h - 4,
 
460
                                 SwingConstants.HORIZONTAL,
 
461
                                 "ScrollBar.gradient");
 
462
      }
431
463
    else
432
 
      g.fillRect(x, y, w, h);
433
 
     
 
464
      {
 
465
        g.setColor(thumbColor);
 
466
        if (isFreeStanding)
 
467
          g.fillRect(x, y, w - 1, h);
 
468
        else
 
469
          g.fillRect(x, y, w, h);
 
470
      }
 
471
 
434
472
    // then draw the dark box
435
473
    g.setColor(thumbLightShadowColor);
436
474
    if (isFreeStanding)
456
494
      }
457
495
    
458
496
    // draw the shadow line
459
 
    UIDefaults def = UIManager.getLookAndFeelDefaults();
460
 
    g.setColor(def.getColor("ScrollBar.shadow"));
 
497
    g.setColor(UIManager.getColor("ScrollBar.shadow"));
461
498
    g.drawLine(x + 1, y + h, x + w - 2, y + h);
 
499
 
 
500
    // For the OceanTheme, draw the 3 lines in the middle.
 
501
    if (theme instanceof OceanTheme)
 
502
      {
 
503
        g.setColor(thumbLightShadowColor);
 
504
        int middle = y + h / 2;
 
505
        g.drawLine(x + 4, middle - 2, x + w - 5, middle - 2);
 
506
        g.drawLine(x + 4, middle, x + w - 5, middle);
 
507
        g.drawLine(x + 4, middle + 2, x + w - 5, middle + 2);
 
508
        g.setColor(UIManager.getColor("ScrollBar.highlight"));
 
509
        g.drawLine(x + 5, middle - 1, x + w - 4, middle - 1);
 
510
        g.drawLine(x + 5, middle + 1, x + w - 4, middle + 1);
 
511
        g.drawLine(x + 5, middle + 3, x + w - 4, middle + 3);
 
512
      }
462
513
  }
463
514
  
464
515
  /**
470
521
   */
471
522
  protected Dimension getMinimumThumbSize()
472
523
  {
473
 
    if (isFreeStanding)
474
 
      return MIN_THUMB_SIZE_FREE_STANDING;
 
524
    Dimension retVal;
 
525
    if (scrollbar != null)
 
526
      {
 
527
        if (isFreeStanding)
 
528
          retVal = MIN_THUMB_SIZE_FREE_STANDING;
 
529
        else
 
530
          retVal = MIN_THUMB_SIZE;
 
531
      }
475
532
    else
476
 
      return MIN_THUMB_SIZE;
 
533
      retVal = new Dimension(0, 0);
 
534
    return retVal;
477
535
  }
478
 
  
 
536
 
 
537
  /**
 
538
   * Returns the <code>preferredSize</code> for the specified scroll bar.
 
539
   * For a vertical scrollbar the height is the sum of the preferred heights
 
540
   * of the buttons plus <code>30</code>. The width is fetched from the
 
541
   * <code>UIManager</code> property <code>ScrollBar.width</code>.
 
542
   *
 
543
   * For horizontal scrollbars the width is the sum of the preferred widths
 
544
   * of the buttons plus <code>30</code>. The height is fetched from the
 
545
   * <code>UIManager</code> property <code>ScrollBar.height</code>.
 
546
   *
 
547
   * @param c the scrollbar for which to calculate the preferred size
 
548
   *
 
549
   * @return the <code>preferredSize</code> for the specified scroll bar
 
550
   */
 
551
  public Dimension getPreferredSize(JComponent c)
 
552
  {
 
553
    int height;
 
554
    int width;
 
555
    height = width = 0;
 
556
 
 
557
    if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL)
 
558
      {
 
559
        width += incrButton.getPreferredSize().getWidth();
 
560
        width += decrButton.getPreferredSize().getWidth();
 
561
        width += 30;
 
562
        height = UIManager.getInt("ScrollBar.width");
 
563
      }
 
564
    else
 
565
      {
 
566
        height += incrButton.getPreferredSize().getHeight();
 
567
        height += decrButton.getPreferredSize().getHeight();
 
568
        height += 30;
 
569
        width = UIManager.getInt("ScrollBar.width");
 
570
      }
 
571
 
 
572
    Insets insets = scrollbar.getInsets();
 
573
 
 
574
    height += insets.top + insets.bottom;
 
575
    width += insets.left + insets.right;
 
576
 
 
577
    return new Dimension(width, height);
 
578
  } 
479
579
}
480
580