1 7 8 package com.sun.java.swing.plaf.motif; 9 10 import java.awt.*; 11 import java.awt.event.*; 12 13 import javax.swing.*; 14 import javax.swing.event.*; 15 import javax.swing.plaf.*; 16 17 import javax.swing.plaf.basic.BasicSliderUI ; 18 19 32 public class MotifSliderUI extends BasicSliderUI { 33 34 static final Dimension PREFERRED_HORIZONTAL_SIZE = new Dimension(164, 15); 35 static final Dimension PREFERRED_VERTICAL_SIZE = new Dimension(15, 164); 36 37 static final Dimension MINIMUM_HORIZONTAL_SIZE = new Dimension(43, 15); 38 static final Dimension MINIMUM_VERTICAL_SIZE = new Dimension(15, 43); 39 40 43 public MotifSliderUI(JSlider b) { 44 super(b); 45 } 46 47 50 public static ComponentUI createUI(JComponent b) { 51 return new MotifSliderUI((JSlider)b); 52 } 53 54 public Dimension getPreferredHorizontalSize() { 55 return PREFERRED_HORIZONTAL_SIZE; 56 } 57 58 public Dimension getPreferredVerticalSize() { 59 return PREFERRED_VERTICAL_SIZE; 60 } 61 62 public Dimension getMinimumHorizontalSize() { 63 return MINIMUM_HORIZONTAL_SIZE; 64 } 65 66 public Dimension getMinimumVerticalSize() { 67 return MINIMUM_VERTICAL_SIZE; 68 } 69 70 protected Dimension getThumbSize() { 71 if ( slider.getOrientation() == JSlider.HORIZONTAL ) { 72 return new Dimension( 30, 15 ); 73 } 74 else { 75 return new Dimension( 15, 30 ); 76 } 77 } 78 79 public void paintFocus(Graphics g) { 80 } 81 82 public void paintTrack(Graphics g) { 83 } 84 85 public void paintThumb(Graphics g) { 86 Rectangle knobBounds = thumbRect; 87 88 int x = knobBounds.x; 89 int y = knobBounds.y; 90 int w = knobBounds.width; 91 int h = knobBounds.height; 92 93 if ( slider.isEnabled() ) { 94 g.setColor(slider.getForeground()); 95 } 96 else { 97 g.setColor(slider.getForeground().darker()); 99 } 100 101 if ( slider.getOrientation() == JSlider.HORIZONTAL ) { 102 g.translate(x, knobBounds.y-1); 103 104 g.fillRect(0, 1, w, h - 1); 106 107 g.setColor(getHighlightColor()); 109 g.drawLine(0, 1, w - 1, 1); g.drawLine(0, 1, 0, h); g.drawLine(w/2, 2, w/2, h-1); 113 g.setColor(getShadowColor()); 115 g.drawLine(0, h, w - 1, h); g.drawLine(w - 1, 1, w - 1, h); g.drawLine(w/2 - 1, 2, w/2 - 1, h); 119 g.translate(-x, -(knobBounds.y-1)); 120 } 121 else { 122 g.translate(knobBounds.x-1, 0); 123 124 g.fillRect(1, y, w - 1, h); 126 127 g.setColor(getHighlightColor()); 129 g.drawLine(1, y, w, y); g.drawLine(1, y+1, 1, y+h-1); g.drawLine(2, y+h/2, w-1, y+h/2); 133 g.setColor(getShadowColor()); 135 g.drawLine(2, y+h-1, w, y+h-1); g.drawLine(w, y+h-1, w, y); g.drawLine(2, y+h/2-1, w-1, y+h/2-1); 139 g.translate(-(knobBounds.x-1), 0); 140 } 141 } 142 } 143 144 | Popular Tags |