1 7 8 package com.sun.java.swing.plaf.windows; 9 10 import java.awt.*; 11 12 import javax.swing.plaf.ComponentUI ; 13 import javax.swing.plaf.basic.*; 14 import javax.swing.*; 15 16 import com.sun.java.swing.plaf.windows.TMSchema.Part; 17 import com.sun.java.swing.plaf.windows.XPStyle.Skin; 18 19 20 27 public class WindowsToolBarSeparatorUI extends BasicToolBarSeparatorUI { 28 29 public static ComponentUI createUI( JComponent c ) { 30 return new WindowsToolBarSeparatorUI(); 31 } 32 33 public Dimension getPreferredSize(JComponent c) { 34 Dimension size = ((JToolBar.Separator)c).getSeparatorSize(); 35 36 if (size != null) { 37 size = size.getSize(); 38 } else { 39 size = new Dimension(6, 6); 40 XPStyle xp = XPStyle.getXP(); 41 if (xp != null) { 42 boolean vertical = ((JSeparator)c).getOrientation() == SwingConstants.VERTICAL; 43 Part part = vertical ? Part.TP_SEPARATOR : Part.TP_SEPARATORVERT; 44 Skin skin = xp.getSkin(c, part); 45 size.width = skin.getWidth(); 46 size.height = skin.getHeight(); 47 } 48 49 if (((JSeparator)c).getOrientation() == SwingConstants.VERTICAL) { 50 size.height = 0; 51 } else { 52 size.width = 0; 53 } 54 } 55 return size; 56 } 57 58 public Dimension getMaximumSize(JComponent c) { 59 Dimension pref = getPreferredSize(c); 60 if (((JSeparator)c).getOrientation() == SwingConstants.VERTICAL) { 61 return new Dimension(pref.width, Short.MAX_VALUE); 62 } else { 63 return new Dimension(Short.MAX_VALUE, pref.height); 64 } 65 } 66 67 public void paint( Graphics g, JComponent c ) { 68 boolean vertical = ((JSeparator)c).getOrientation() == SwingConstants.VERTICAL; 69 Dimension size = c.getSize(); 70 71 XPStyle xp = XPStyle.getXP(); 72 if (xp != null) { 73 Part part = vertical ? Part.TP_SEPARATOR : Part.TP_SEPARATORVERT; 74 Skin skin = xp.getSkin(c, part); 75 76 int dx = vertical ? (size.width - skin.getWidth()) / 2 : 0; 77 int dy = vertical ? 0 : (size.height - skin.getHeight()) / 2; 78 int dw = vertical ? skin.getWidth() : size.width; 79 int dh = vertical ? size.height : skin.getHeight(); 80 skin.paintSkin(g, dx, dy, dw, dh, null); 81 } else { 82 83 Color temp = g.getColor(); 84 85 UIDefaults table = UIManager.getLookAndFeelDefaults(); 86 87 Color shadow = table.getColor("ToolBar.shadow"); 88 Color highlight = table.getColor("ToolBar.highlight"); 89 90 if (vertical) { 91 int x = (size.width / 2) - 1; 92 g.setColor(shadow); 93 g.drawLine(x, 2, x, size.height - 2); 94 95 g.setColor(highlight); 96 g.drawLine(x + 1, 2, x + 1, size.height - 2); 97 } else { 98 int y = (size.height / 2) - 1; 99 g.setColor(shadow); 100 g.drawLine(2, y, size.width - 2, y); 101 g.setColor(highlight); 102 g.drawLine(2, y + 1, size.width - 2, y + 1); 103 } 104 g.setColor(temp); 105 } 106 } 107 } 108 109 | Popular Tags |