1 106 107 108 package swingwtx.swing; 109 110 import java.beans.PropertyChangeListener ; 111 import java.util.Dictionary ; 112 import java.util.Hashtable ; 113 import java.util.Vector ; 114 115 import swingwt.awt.Component; 116 import swingwt.awt.Container; 117 import swingwt.awt.Dimension; 118 import swingwt.awt.Insets; 119 import swingwt.awt.Point; 120 import swingwt.awt.Rectangle; 121 import swingwtx.accessibility.AccessibleContext; 122 import swingwtx.swing.border.AbstractBorder; 123 import swingwtx.swing.border.Border; 124 125 public class JComponent extends swingwt.awt.Container implements JSWTScrollable { 126 127 128 protected swingwtx.swing.border.Border border = null; 129 130 protected AccessibleContext accessibleContext = null; 131 132 protected boolean showHorizontalScrollBar = false; 133 134 protected boolean showVerticalScrollBar = false; 135 136 protected JScrollPane scrollPaneContainer = null; 137 141 protected boolean descendantHasPeer = false; 142 143 protected Hashtable clientProperties; 144 145 protected boolean opaque = true; 146 147 protected InputMap focusInputMap = null; 148 protected InputMap ancestorInputMap = null; 149 protected InputMap windowInputMap = null; 150 151 protected Vector propertyChangeListeners = new Vector (); 152 153 public static final int WHEN_FOCUSED = 0; 154 public static final int WHEN_ANCESTOR_OF_FOCUSED_COMPONENT = 1; 155 public static final int WHEN_IN_FOCUSED_WINDOW = 2; 156 157 160 public JComponent() { } 161 162 163 public void addPropertyChangeListener(PropertyChangeListener l) { 164 propertyChangeListeners.add(l); 165 } 166 167 public void addPropertyChangeListener(String propertyName, PropertyChangeListener l) { 168 propertyChangeListeners.add(l); 169 } 170 171 public void removePropertyChangeListener(PropertyChangeListener l) { 172 propertyChangeListeners.remove(l); 173 } 174 175 public void removePropertyChangeListener(String propertyName, PropertyChangeListener l) { 176 propertyChangeListeners.remove(l); 177 } 178 179 180 public void paintImmediately(int x,int y,int w, int h) { 181 super.repaint(); 182 } 183 184 187 public void paintImmediately(swingwt.awt.Rectangle r) { 188 super.repaint(); 189 } 190 191 193 public void repaint(Rectangle r) { 194 repaint(r.x,r.y,r.width,r.height); 195 } 196 197 200 protected void paintComponent(swingwt.awt.Graphics g) { 201 paint(g); 202 } 203 204 207 protected void paintChildren(swingwt.awt.Graphics g) { 208 } 209 210 public void paintBackground(int x, int y, int width, int height) { 211 if (parent != null && !isOpaque()) { 212 Dimension size = getSize(); 213 Point location = getLocation(); 214 } 216 } 217 218 224 public void paint(swingwt.awt.Graphics g) { 225 super.paint(g); 226 if (border != null) { 227 border.paintBorder(this, g, 0, 0, getWidth(), getHeight()); 228 } 229 } 230 231 232 public Border getBorder() { if (border == null) return BorderFactory.createEmptyBorder(); else return border; } 233 234 public void setBorder(Border b) { border = b; invalidate(); } 235 236 237 public void setRequestFocusEnabled(boolean b) {} 238 239 public void setAutoscrolls(boolean b) {} 240 244 public String getToolTipText(swingwt.awt.event.MouseEvent e) { 245 return getToolTipText(); 246 } 247 251 public Point getToolTipLocation(swingwt.awt.event.MouseEvent e) { 252 return e.getPoint(); 253 } 254 256 public boolean getAutoscrolls() { return true; } 257 260 public boolean isOpaque() { return opaque; } 261 262 public void setOpaque(boolean b) { this.opaque = b; } 263 267 public boolean isDoubleBuffered() { return pDoubleBuffered; } 268 275 public void setDoubleBuffered(boolean b) { pDoubleBuffered = b; } 276 277 279 public void scrollRectToVisible(Rectangle aRect) { 280 } 281 282 283 private Dictionary getClientProperties() { 284 if (clientProperties == null) { 285 clientProperties = new Hashtable (2); 286 } 287 return clientProperties; 288 } 289 290 291 public void revalidate() { invalidate(); } 292 293 297 public final Object getClientProperty(Object key) { 298 if (clientProperties == null) { 299 return null; 300 } 301 else { 302 return getClientProperties().get(key); 303 } 304 } 305 306 311 public swingwt.awt.Rectangle getVisibleRect() { 312 return new swingwt.awt.Rectangle(0, 0, getWidth(), getHeight()); 313 } 314 315 316 public final void putClientProperty(Object key, Object value) { 317 if (value == null && clientProperties == null) { 318 return; 319 } 320 getClientProperties().put(key, value); 321 } 322 323 324 public void setMargin(swingwt.awt.Insets i) {} 325 326 327 public AccessibleContext getAccessibleContext() { 328 return accessibleContext; 329 } 330 331 336 public void setHorizontalScrollPane(boolean b) { 337 showHorizontalScrollBar = b; 338 } 339 340 345 public void setVerticalScrollPane(boolean b) { 346 showVerticalScrollBar = b; 347 } 348 349 352 public void setScrollPane(JScrollPane container) { 353 scrollPaneContainer = container; 354 } 355 356 361 public boolean isValidateRoot() { 362 return false; 363 } 364 365 366 public boolean isOptimizedDrawingEnabled() { 367 return true; 368 } 369 370 371 public void setNextFocusableComponent(Component acomponent) { 372 } 373 374 375 public Insets getInsets() { 376 final Insets insets = new Insets(); 377 378 SwingUtilities.invokeSync( new Runnable () { 379 public void run() { 380 if (border != null) { 381 if (border instanceof AbstractBorder) 382 ((AbstractBorder)border).getBorderInsets(JComponent.this, insets); 383 else { 384 Insets borderInsets = border.getBorderInsets(JComponent.this); 385 insets.left = borderInsets.left; 386 insets.top = borderInsets.top; 387 insets.right = borderInsets.right; 388 insets.bottom = borderInsets.bottom; 389 } 390 } 391 else { 392 393 if (!SwingWTUtils.isSWTControlAvailable(composite)) 395 return; 396 397 org.eclipse.swt.graphics.Rectangle rect = composite.getBounds(); 398 org.eclipse.swt.graphics.Rectangle client = composite.getClientArea(); 399 400 insets.left = client.x; 401 insets.top = client.y; 402 insets.right = rect.width - client.width - client.x; 403 insets.bottom = rect.height - client.height - client.y; 404 } 405 } 406 }); 407 408 return insets; 409 } 410 411 412 417 public void setPreferredSize(Dimension d) { 418 super.setPreferredSize(d); 419 if (scrollPaneContainer != null) 420 scrollPaneContainer.setPreferredSize(d); 421 } 422 423 424 public final void setInputMap(int condition, InputMap inputMap) { 425 if (condition == WHEN_FOCUSED) { focusInputMap = inputMap; } 426 else if (condition == WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) { ancestorInputMap = inputMap; } 427 else if (condition == WHEN_IN_FOCUSED_WINDOW) { windowInputMap = inputMap; } 428 else { throw new IllegalArgumentException ("Illegal InputMap type!"); } 429 } 430 431 432 public final InputMap getInputMap(int condition, boolean create) { 433 InputMap inputMap = null; 434 435 if (condition == WHEN_FOCUSED) 436 { 437 if (focusInputMap == null && create) focusInputMap = new InputMap(); 438 if (focusInputMap != null) { inputMap = focusInputMap; } 439 } 440 else if (condition == WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) 441 { 442 if (ancestorInputMap == null && create) ancestorInputMap = new InputMap(); 443 if (ancestorInputMap != null) { inputMap = ancestorInputMap; } 444 } 445 else if (condition == WHEN_IN_FOCUSED_WINDOW) 446 { 447 if (windowInputMap == null && create) windowInputMap = new InputMap(); 448 if (windowInputMap != null) { inputMap = windowInputMap; } 449 } 450 else 451 { 452 throw new IllegalArgumentException ("Illegal InputMap type!"); 453 } 454 455 return inputMap; 456 } 457 458 459 public void dispose() { 460 super.dispose(); 463 } 464 465 468 public void setSwingWTParent(Container parent) throws Exception { 469 470 super.setSwingWTParent(parent); 473 474 if (!descendantHasPeer) { 477 ppeer = new org.eclipse.swt.widgets.Composite(parent.getComposite(), 0); 478 peer = ppeer; 479 this.parent = parent; 480 } 481 } 482 483 } 484 | Popular Tags |