1 21 24 package org.lobobrowser.html.renderer; 25 26 import java.awt.Color ; 27 import java.awt.Dimension ; 28 import java.awt.Graphics ; 29 import java.awt.Insets ; 30 import java.util.Iterator ; 31 import javax.swing.*; 32 33 import org.lobobrowser.html.domimpl.*; 34 import org.lobobrowser.html.*; 35 import org.lobobrowser.html.style.RenderState; 36 37 40 class RUIControl extends BaseElementRenderable implements RElement { 41 public final UIControl widget; 42 private final ModelNode modelNode; 43 private final FrameContext frameContext; 44 45 public RUIControl(ModelNode me, UIControl widget, RenderableContainer container, FrameContext frameContext, UserAgentContext ucontext) { 46 super(container, me, ucontext); 47 this.modelNode = me; 48 this.widget = widget; 49 this.frameContext = frameContext; 50 widget.setRUIControl(this); 51 } 52 53 public void focus() { 54 super.focus(); 55 java.awt.Component c = this.widget.getComponent(); 56 c.requestFocus(); 57 } 58 59 public final void invalidateLayoutLocal() { 60 super.invalidateLayoutLocal(); 62 this.widget.invalidate(); 63 this.lastAvailHeight = -1; 65 this.lastAvailWidth = -1; 66 } 67 68 public int getVAlign() { 69 return this.widget.getVAlign(); 70 } 71 72 public final void paint(Graphics g) { 73 this.widget.paint(g); 77 super.paint(g); 80 } 81 82 public boolean onMouseClick(java.awt.event.MouseEvent event, int x, int y) { 83 ModelNode me = this.modelNode; 84 if(me != null) { 85 return HtmlController.getInstance().onMouseClick(me, event, x, y); 86 } 87 else { 88 return true; 89 } 90 } 91 92 public boolean onDoubleClick(java.awt.event.MouseEvent event, int x, int y) { 93 ModelNode me = this.modelNode; 94 if(me != null) { 95 return HtmlController.getInstance().onDoubleClick(me, event, x, y); 96 } 97 else { 98 return true; 99 } 100 } 101 102 public boolean onMousePressed(java.awt.event.MouseEvent event, int x, int y) { 103 ModelNode me = this.modelNode; 104 if(me != null) { 105 return HtmlController.getInstance().onMouseDown(me, event, x, y); 106 } 107 else { 108 return true; 109 } 110 } 111 112 public boolean onMouseReleased(java.awt.event.MouseEvent event, int x, int y) { 113 ModelNode me = this.modelNode; 114 if(me != null) { 115 return HtmlController.getInstance().onMouseUp(me, event, x, y); 116 } 117 else { 118 return true; 119 } 120 } 121 122 public boolean onMouseDisarmed(java.awt.event.MouseEvent event) { 123 ModelNode me = this.modelNode; 124 if(me != null) { 125 return HtmlController.getInstance().onMouseDisarmed(me, event); 126 } 127 else { 128 return true; 129 } 130 } 131 132 135 public void invalidateRenderStyle() { 136 } 138 139 142 public void repaint(ModelNode modelNode) { 143 Object widget = this.widget; 144 if(widget instanceof UINode) { 145 ((UINode) widget).repaint(modelNode); 146 } 147 else { 148 this.repaint(); 149 } 150 } 151 152 public void updateWidgetBounds(int guiX, int guiY) { 153 super.updateWidgetBounds(guiX, guiY); 155 this.widget.setBounds(guiX, guiY, this.width, this.height); 156 } 157 158 public Color getBlockBackgroundColor() { 159 return this.widget.getBackgroundColor(); 160 } 161 162 165 public boolean paintSelection(Graphics g, boolean inSelection, RenderableSpot startPoint, RenderableSpot endPoint) { 166 inSelection = super.paintSelection(g, inSelection, startPoint, endPoint); 167 if(inSelection) { 168 Color over = new Color (0, 0, 255, 50); 169 if(over != null) { 170 Color oldColor = g.getColor(); 171 try { 172 g.setColor(over); 173 g.fillRect(0, 0, this.width, this.height); 174 } finally { 175 g.setColor(oldColor); 176 } 177 } 178 } 179 return inSelection; 180 } 181 182 public boolean extractSelectionText(StringBuffer buffer, boolean inSelection, RenderableSpot startPoint, RenderableSpot endPoint) { 183 return inSelection; 185 } 186 187 public RenderableSpot getLowestRenderableSpot(int x, int y) { 188 return new RenderableSpot(this, x, y); 190 } 191 192 private int lastAvailWidth = -1; 193 private int lastAvailHeight = -1; 194 private int declaredWidth = -1; 195 private int declaredHeight = -1; 196 197 public void doLayout(int availWidth, int availHeight, boolean expandWidth, boolean expandHeight) { 198 if(availWidth != this.lastAvailWidth || availHeight != this.lastAvailHeight) { 199 this.applyStyle(); 200 this.lastAvailWidth = availWidth; 201 this.lastAvailHeight = availHeight; 202 UIControl widget = this.widget; 203 widget.reset(availWidth, availHeight); 204 RenderState renderState = this.modelNode.getRenderState(); 205 int dw = this.getDeclaredWidth(renderState, availWidth); 206 int dh = this.getDeclaredHeight(renderState, availHeight); 207 this.declaredWidth = dw; 208 this.declaredHeight = dh; 209 if(dw == -1 || dh == -1) { 210 Dimension size = widget.getPreferredSize(); 211 if(dw == -1) { 212 dw = size.width; 213 } 214 if(dh == -1) { 215 dh = size.height; 216 } 217 } 218 this.width = dw; 219 this.height = dh; 220 } 221 } 222 223 230 public final void preferredSizeInvalidated() { 231 int dw = RUIControl.this.declaredWidth; 232 int dh = RUIControl.this.declaredHeight; 233 if(dw == -1 || dh == -1) { 234 this.frameContext.delayedRelayout((NodeImpl) this.modelNode); 235 } 236 else { 237 RUIControl.this.repaint(); 238 } 239 } 240 241 public Iterator getRenderables() { 242 return null; 244 } 245 246 public Color getPaintedBackgroundColor() { 247 return this.container.getPaintedBackgroundColor(); 248 } 249 250 public Insets getInsets() { 251 return RBlockViewport.ZERO_INSETS; 252 } 253 } 254 | Popular Tags |