1 7 8 package javax.swing.plaf.synth; 9 10 import java.awt.*; 11 import javax.swing.*; 12 import javax.swing.text.*; 13 import javax.swing.plaf.*; 14 import javax.swing.plaf.basic.BasicEditorPaneUI ; 15 import java.beans.PropertyChangeEvent ; 16 import sun.swing.plaf.synth.SynthUI; 17 18 25 class SynthEditorPaneUI extends BasicEditorPaneUI implements SynthUI { 26 private SynthStyle style; 27 31 private Boolean localTrue = new Boolean (true); 32 private Boolean localFalse = new Boolean (false); 33 34 40 public static ComponentUI createUI(JComponent c) { 41 return new SynthEditorPaneUI (); 42 } 43 44 protected void installDefaults() { 45 JComponent c = getComponent(); 46 Object clientProperty = 47 c.getClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES); 48 if (clientProperty == null 49 || clientProperty == localFalse) { 50 c.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, 51 localTrue); 52 } 53 updateStyle((JTextComponent)getComponent()); 54 } 55 56 protected void uninstallDefaults() { 57 SynthContext context = getContext(getComponent(), ENABLED); 58 JComponent c = getComponent(); 59 c.putClientProperty("caretAspectRatio", null); 60 61 style.uninstallDefaults(context); 62 context.dispose(); 63 style = null; 64 65 Object clientProperty = 66 c.getClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES); 67 if (clientProperty == localTrue) { 68 getComponent().putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, 69 Boolean.FALSE); 70 } 71 super.uninstallDefaults(); 72 } 73 74 84 protected void propertyChange(PropertyChangeEvent evt) { 85 if (SynthLookAndFeel.shouldUpdateStyle(evt)) { 86 updateStyle((JTextComponent)evt.getSource()); 87 } 88 super.propertyChange(evt); 89 } 90 91 private void updateStyle(JTextComponent comp) { 92 SynthContext context = getContext(comp, ENABLED); 93 SynthStyle oldStyle = style; 94 95 style = SynthLookAndFeel.updateStyle(context, this); 96 97 if (style != oldStyle) { 98 SynthTextFieldUI.updateStyle(comp, context, getPropertyPrefix()); 99 100 if (oldStyle != null) { 101 uninstallKeyboardActions(); 102 installKeyboardActions(); 103 } 104 } 105 context.dispose(); 106 } 107 108 public SynthContext getContext(JComponent c) { 109 return getContext(c, getComponentState(c)); 110 } 111 112 private SynthContext getContext(JComponent c, int state) { 113 return SynthContext.getContext(SynthContext .class, c, 114 SynthLookAndFeel.getRegion(c), style, state); 115 } 116 117 private int getComponentState(JComponent c) { 118 return SynthLookAndFeel.getComponentState(c); 119 } 120 121 public void update(Graphics g, JComponent c) { 122 SynthContext context = getContext(c); 123 124 SynthLookAndFeel.update(context, g); 125 paintBackground(context, g, c); 126 paint(context, g); 127 context.dispose(); 128 } 129 130 protected void paint(SynthContext context, Graphics g) { 131 super.paint(g, getComponent()); 132 } 133 134 protected void paintBackground(Graphics g) { 135 } 137 138 void paintBackground(SynthContext context, Graphics g, JComponent c) { 139 context.getPainter().paintEditorPaneBackground(context, g, 0, 0, 140 c.getWidth(), c.getHeight()); 141 } 142 143 public void paintBorder(SynthContext context, Graphics g, int x, 144 int y, int w, int h) { 145 context.getPainter().paintEditorPaneBorder(context, g, x, y, w, h); 146 } 147 } 148 | Popular Tags |