1 7 8 package javax.swing.plaf.synth; 9 10 import java.beans.*; 11 import javax.swing.*; 12 import java.awt.Dimension ; 13 import java.awt.Graphics ; 14 import java.awt.Insets ; 15 import javax.swing.plaf.ComponentUI ; 16 import javax.swing.plaf.SeparatorUI ; 17 import javax.swing.plaf.UIResource ; 18 import javax.swing.plaf.DimensionUIResource ; 19 import sun.swing.plaf.synth.SynthUI; 20 21 29 class SynthSeparatorUI extends SeparatorUI implements PropertyChangeListener, 30 SynthUI { 31 private SynthStyle style; 32 33 public static ComponentUI createUI(JComponent c) { 34 return new SynthSeparatorUI (); 35 } 36 37 public void installUI(JComponent c) { 38 installDefaults((JSeparator)c); 39 installListeners((JSeparator)c); 40 } 41 42 public void uninstallDefaults(JComponent c) { 43 uninstallListeners((JSeparator)c); 44 uninstallDefaults((JSeparator)c); 45 } 46 47 public void installDefaults(JSeparator c) { 48 updateStyle(c); 49 } 50 51 private void updateStyle(JSeparator sep) { 52 SynthContext context = getContext(sep, ENABLED); 53 SynthStyle oldStyle = style; 54 55 style = SynthLookAndFeel.updateStyle(context, this); 56 57 if (style != oldStyle) { 58 if (sep instanceof JToolBar.Separator) { 59 Dimension size = ((JToolBar.Separator)sep).getSeparatorSize(); 60 if (size == null || size instanceof UIResource ) { 61 size = (DimensionUIResource )style.get( 62 context, "ToolBar.separatorSize"); 63 if (size == null) { 64 size = new DimensionUIResource (10, 10); 65 } 66 ((JToolBar.Separator)sep).setSeparatorSize(size); 67 } 68 } 69 } 70 71 context.dispose(); 72 } 73 74 public void uninstallDefaults(JSeparator c) { 75 SynthContext context = getContext(c, ENABLED); 76 77 style.uninstallDefaults(context); 78 context.dispose(); 79 style = null; 80 } 81 82 public void installListeners(JSeparator c) { 83 c.addPropertyChangeListener(this); 84 } 85 86 public void uninstallListeners(JSeparator c) { 87 c.removePropertyChangeListener(this); 88 } 89 90 public void update(Graphics g, JComponent c) { 91 SynthContext context = getContext(c); 92 93 SynthLookAndFeel.update(context, g); 94 context.getPainter().paintSeparatorBackground(context, 95 g, 0, 0, c.getWidth(), c.getHeight()); 96 paint(context, g); 97 context.dispose(); 98 } 99 100 public void paint(Graphics g, JComponent c) { 101 SynthContext context = getContext(c); 102 103 paint(context, g); 104 context.dispose(); 105 } 106 107 protected void paint(SynthContext context, Graphics g) { 108 JSeparator separator = (JSeparator)context.getComponent(); 109 context.getPainter().paintSeparatorForeground(context, g, 0, 0, 110 separator.getWidth(), separator.getHeight(), 111 separator.getOrientation()); 112 } 113 114 public void paintBorder(SynthContext context, Graphics g, int x, 115 int y, int w, int h) { 116 context.getPainter().paintSeparatorBorder(context, g, x, y, w, h); 117 } 118 119 public Dimension getPreferredSize(JComponent c) { 120 SynthContext context = getContext(c); 121 122 int thickness = style.getInt(context, "Separator.thickness", 2); 123 Insets insets = c.getInsets(); 124 Dimension size; 125 126 if (((JSeparator)c).getOrientation() == JSeparator.VERTICAL) { 127 size = new Dimension (insets.left + insets.right + thickness, 128 insets.top + insets.bottom); 129 } else { 130 size = new Dimension (insets.left + insets.right, 131 insets.top + insets.bottom + thickness); 132 } 133 context.dispose(); 134 return size; 135 } 136 137 public Dimension getMinimumSize(JComponent c) { 138 return getPreferredSize(c); 139 } 140 141 public Dimension getMaximumSize(JComponent c) { 142 return new Dimension (Short.MAX_VALUE, Short.MAX_VALUE); 143 } 144 145 public SynthContext getContext(JComponent c) { 146 return getContext(c, getComponentState(c)); 147 } 148 149 private SynthContext getContext(JComponent c, int state) { 150 return SynthContext.getContext(SynthContext .class, c, 151 SynthLookAndFeel.getRegion(c), style, state); 152 } 153 154 private Region getRegion(JComponent c) { 155 return SynthLookAndFeel.getRegion(c); 156 } 157 158 private int getComponentState(JComponent c) { 159 return SynthLookAndFeel.getComponentState(c); 160 } 161 162 public void propertyChange(PropertyChangeEvent evt) { 163 if (SynthLookAndFeel.shouldUpdateStyle(evt)) { 164 updateStyle((JSeparator)evt.getSource()); 165 } 166 } 167 } 168 | Popular Tags |