1 30 31 package com.jgoodies.looks.windows; 32 33 import java.awt.Color ; 34 import java.awt.Dimension ; 35 import java.awt.Graphics ; 36 37 import javax.swing.JComponent ; 38 import javax.swing.JSeparator ; 39 import javax.swing.SwingConstants ; 40 import javax.swing.UIManager ; 41 import javax.swing.plaf.ComponentUI ; 42 import javax.swing.plaf.basic.BasicToolBarSeparatorUI ; 43 44 import com.jgoodies.looks.LookUtils; 45 46 54 public final class WindowsToolBarSeparatorUI 55 extends BasicToolBarSeparatorUI { 56 57 58 private static final int VERTICAL = LookUtils.IS_JAVA_1_4_2_OR_LATER 59 ? SwingConstants.VERTICAL 60 : SwingConstants.HORIZONTAL; 61 62 63 private static WindowsToolBarSeparatorUI toolBarSeparatorUI; 64 65 public static ComponentUI createUI(JComponent c) { 66 if (toolBarSeparatorUI == null) { 67 toolBarSeparatorUI = new WindowsToolBarSeparatorUI(); 68 } 69 return toolBarSeparatorUI; 70 } 71 72 public void paint(Graphics g, JComponent c) { 73 Color temp = g.getColor(); 74 75 Color shadowColor = UIManager.getColor("ToolBar.shadow"); 76 Color highlightColor = UIManager.getColor("ToolBar.highlight"); 77 78 Dimension size = c.getSize(); 79 80 if (((JSeparator ) c).getOrientation() == VERTICAL) { 81 int x = (size.width / 2) - 1; 82 g.setColor(shadowColor); 83 g.drawLine(x, 0, x, size.height - 1); 84 g.setColor(highlightColor); 85 g.drawLine(x + 1, 0, x + 1, size.height - 1); 86 } else { 87 int y = (size.height / 2) - 1; 88 g.setColor(shadowColor); 89 g.drawLine(0, y, size.width - 1, y); 90 g.setColor(highlightColor); 91 g.drawLine(0, y + 1, size.width - 1, y + 1); 92 } 93 g.setColor(temp); 94 } 95 } | Popular Tags |