1 7 8 package javax.swing.plaf.synth; 9 10 import javax.swing.*; 11 import javax.swing.plaf.*; 12 import javax.swing.plaf.basic.*; 13 import javax.swing.text.View ; 14 15 import java.awt.event.ActionEvent ; 16 import java.awt.event.ActionListener ; 17 import java.awt.Component ; 18 import java.awt.Container ; 19 import java.awt.Dimension ; 20 import java.awt.Rectangle ; 21 import java.awt.Insets ; 22 import java.awt.Color ; 23 import java.awt.Graphics ; 24 import java.awt.Font ; 25 import java.awt.FontMetrics ; 26 import java.beans.PropertyChangeEvent ; 27 import java.beans.PropertyChangeListener ; 28 import sun.swing.plaf.synth.SynthUI; 29 30 36 class SynthLabelUI extends BasicLabelUI implements SynthUI { 37 private SynthStyle style; 38 39 42 public static ComponentUI createUI(JComponent c){ 43 return new SynthLabelUI (); 44 } 45 46 47 protected void installDefaults(JLabel c) { 48 updateStyle(c); 49 } 50 51 void updateStyle(JLabel c) { 52 SynthContext context = getContext(c, ENABLED); 53 style = SynthLookAndFeel.updateStyle(context, this); 54 context.dispose(); 55 } 56 57 protected void uninstallDefaults(JLabel c){ 58 SynthContext context = getContext(c, ENABLED); 59 60 style.uninstallDefaults(context); 61 context.dispose(); 62 style = null; 63 } 64 65 public SynthContext getContext(JComponent c) { 66 return getContext(c, getComponentState(c)); 67 } 68 69 private SynthContext getContext(JComponent c, int state) { 70 return SynthContext.getContext(SynthContext .class, c, 71 SynthLookAndFeel.getRegion(c), style, state); 72 } 73 74 private Region getRegion(JComponent c) { 75 return SynthLookAndFeel.getRegion(c); 76 } 77 78 private int getComponentState(JComponent c) { 79 int state = SynthLookAndFeel.getComponentState(c); 80 if (SynthLookAndFeel.selectedUI == this && 81 state == SynthConstants.ENABLED) { 82 state = SynthLookAndFeel.selectedUIState | SynthConstants.ENABLED; 83 } 84 return state; 85 } 86 87 92 public void update(Graphics g, JComponent c) { 93 SynthContext context = getContext(c); 94 95 SynthLookAndFeel.update(context, g); 96 context.getPainter().paintLabelBackground(context, 97 g, 0, 0, c.getWidth(), c.getHeight()); 98 paint(context, g); 99 context.dispose(); 100 } 101 102 public void paint(Graphics g, JComponent c) { 103 SynthContext context = getContext(c); 104 105 paint(context, g); 106 context.dispose(); 107 } 108 109 protected void paint(SynthContext context, Graphics g) { 110 JLabel label = (JLabel)context.getComponent(); 111 Icon icon = (label.isEnabled()) ? label.getIcon() : 112 label.getDisabledIcon(); 113 114 g.setColor(context.getStyle().getColor(context, 115 ColorType.TEXT_FOREGROUND)); 116 g.setFont(style.getFont(context)); 117 context.getStyle().getGraphicsUtils(context).paintText( 118 context, g, label.getText(), icon, 119 label.getHorizontalAlignment(), label.getVerticalAlignment(), 120 label.getHorizontalTextPosition(), label.getVerticalTextPosition(), 121 label.getIconTextGap(), label.getDisplayedMnemonicIndex(), 0); 122 } 123 124 public void paintBorder(SynthContext context, Graphics g, int x, 125 int y, int w, int h) { 126 context.getPainter().paintLabelBorder(context, g, x, y, w, h); 127 } 128 129 public Dimension getPreferredSize(JComponent c) { 130 JLabel label = (JLabel)c; 131 Icon icon = (label.isEnabled()) ? label.getIcon() : 132 label.getDisabledIcon(); 133 SynthContext context = getContext(c); 134 Dimension size = context.getStyle().getGraphicsUtils(context). 135 getPreferredSize( 136 context, context.getStyle().getFont(context), label.getText(), 137 icon, label.getHorizontalAlignment(), 138 label.getVerticalAlignment(), label.getHorizontalTextPosition(), 139 label.getVerticalTextPosition(), label.getIconTextGap(), 140 label.getDisplayedMnemonicIndex()); 141 142 context.dispose(); 143 return size; 144 } 145 146 147 public Dimension getMinimumSize(JComponent c) { 148 JLabel label = (JLabel)c; 149 Icon icon = (label.isEnabled()) ? label.getIcon() : 150 label.getDisabledIcon(); 151 SynthContext context = getContext(c); 152 Dimension size = context.getStyle().getGraphicsUtils(context). 153 getMinimumSize( 154 context, context.getStyle().getFont(context), label.getText(), 155 icon, label.getHorizontalAlignment(), 156 label.getVerticalAlignment(), label.getHorizontalTextPosition(), 157 label.getVerticalTextPosition(), label.getIconTextGap(), 158 label.getDisplayedMnemonicIndex()); 159 160 context.dispose(); 161 return size; 162 } 163 164 public Dimension getMaximumSize(JComponent c) { 165 JLabel label = (JLabel)c; 166 Icon icon = (label.isEnabled()) ? label.getIcon() : 167 label.getDisabledIcon(); 168 SynthContext context = getContext(c); 169 Dimension size = context.getStyle().getGraphicsUtils(context). 170 getMaximumSize( 171 context, context.getStyle().getFont(context), label.getText(), 172 icon, label.getHorizontalAlignment(), 173 label.getVerticalAlignment(), label.getHorizontalTextPosition(), 174 label.getVerticalTextPosition(), label.getIconTextGap(), 175 label.getDisplayedMnemonicIndex()); 176 177 context.dispose(); 178 return size; 179 } 180 181 182 public void propertyChange(PropertyChangeEvent e) { 183 super.propertyChange(e); 184 if (SynthLookAndFeel.shouldUpdateStyle(e)) { 185 updateStyle((JLabel)e.getSource()); 186 } 187 } 188 } 189 | Popular Tags |