73 |
import java.util.Timer; |
import java.util.Timer; |
74 |
import java.util.TimerTask; |
import java.util.TimerTask; |
75 |
|
|
76 |
|
import javax.swing.DebugGraphics; |
77 |
|
|
78 |
public class QtComponentPeer extends NativeWrapper implements ComponentPeer |
public class QtComponentPeer extends NativeWrapper implements ComponentPeer |
79 |
{ |
{ |
80 |
|
|
113 |
*/ |
*/ |
114 |
private QtImage backBuffer; |
private QtImage backBuffer; |
115 |
|
|
|
/** |
|
|
* Stores if the backBuffer is dirty or not |
|
|
*/ |
|
|
private boolean dirtyBackBuffer; |
|
|
|
|
116 |
protected long qtApp; |
protected long qtApp; |
117 |
|
|
118 |
private boolean settingUp; |
private boolean settingUp; |
119 |
|
|
120 |
|
private boolean ignoreResize = false; |
121 |
|
|
122 |
QtComponentPeer( QtToolkit kit, Component owner ) |
QtComponentPeer( QtToolkit kit, Component owner ) |
123 |
{ |
{ |
124 |
this.owner = owner; |
this.owner = owner; |
165 |
setEnabled( owner.isEnabled() ); |
setEnabled( owner.isEnabled() ); |
166 |
|
|
167 |
backBuffer = null; |
backBuffer = null; |
|
dirtyBackBuffer = true; |
|
168 |
updateBounds(); |
updateBounds(); |
169 |
|
|
170 |
setVisible( owner.isVisible() ); |
setVisible( owner.isVisible() ); |
171 |
|
QtToolkit.repaintThread.queueComponent(this); |
172 |
} |
} |
173 |
settingUp = false; |
settingUp = false; |
174 |
} |
} |
351 |
toolkit.eventQueue.postEvent(e); |
toolkit.eventQueue.postEvent(e); |
352 |
} |
} |
353 |
|
|
354 |
protected void moveEvent() |
protected void moveEvent(int x, int y, int oldx, int oldy) |
355 |
{ |
{ |
356 |
ComponentEvent e = new ComponentEvent(owner, |
if( !ignoreResize ) |
357 |
ComponentEvent.COMPONENT_MOVED); |
{ |
358 |
toolkit.eventQueue.postEvent(e); |
// Since Component.setLocation calls back to setBounds, |
359 |
|
// we need to ignore that. |
360 |
|
ignoreResize = true; |
361 |
|
owner.setLocation( x, y ); |
362 |
|
ignoreResize = false; |
363 |
|
} |
364 |
} |
} |
365 |
|
|
366 |
protected void resizeEvent(int oldWidth, int oldHeight, |
protected void resizeEvent(int oldWidth, int oldHeight, |
367 |
int width, int height) |
int width, int height) |
368 |
{ |
{ |
369 |
dirtyBackBuffer = true; |
if(!(owner instanceof Window)) |
370 |
if( drawableComponent() ) |
return; |
371 |
{ |
ignoreResize = true; |
|
// backBuffer.dispose(); |
|
|
backBuffer = new QtImage(width, height); |
|
|
} |
|
372 |
owner.setSize(width, height); |
owner.setSize(width, height); |
373 |
|
ignoreResize = false; |
374 |
ComponentEvent e = new ComponentEvent(owner, |
ComponentEvent e = new ComponentEvent(owner, |
375 |
ComponentEvent.COMPONENT_RESIZED); |
ComponentEvent.COMPONENT_RESIZED); |
376 |
toolkit.eventQueue.postEvent(e); |
toolkit.eventQueue.postEvent(e); |
377 |
} |
} |
378 |
|
|
497 |
|
|
498 |
public Graphics getGraphics() |
public Graphics getGraphics() |
499 |
{ |
{ |
500 |
if( backBuffer == null) |
if( backBuffer == null ) |
501 |
{ |
{ |
502 |
Rectangle r = owner.getBounds(); |
Rectangle r = owner.getBounds(); |
503 |
backBuffer = new QtImage( r.width, r.height ); |
backBuffer = new QtImage( r.width, r.height ); |
514 |
|
|
515 |
public native Point getLocationOnScreen(); |
public native Point getLocationOnScreen(); |
516 |
|
|
517 |
public Dimension getMinimumSize() |
public synchronized Dimension getMinimumSize() |
518 |
{ |
{ |
519 |
Dimension d = getMinimumSizeNative(); |
Dimension d = getMinimumSizeNative(); |
520 |
if(d == null) |
if(d == null) |
522 |
return d; |
return d; |
523 |
} |
} |
524 |
|
|
525 |
public Dimension getPreferredSize() |
public synchronized Dimension getPreferredSize() |
526 |
{ |
{ |
527 |
Dimension d = getPreferredSizeNative(); |
synchronized(toolkit) |
528 |
if(d == null) |
{ |
529 |
return owner.getSize(); |
Dimension d = getPreferredSizeNative(); |
530 |
return d; |
if(d == null) |
531 |
|
return owner.getSize(); |
532 |
|
return d; |
533 |
|
} |
534 |
} |
} |
535 |
|
|
536 |
public Toolkit getToolkit() |
public Toolkit getToolkit() |
579 |
int width, |
int width, |
580 |
int height) |
int height) |
581 |
{ |
{ |
|
dirtyBackBuffer = true; |
|
582 |
setBounds( x, y, width, height ); |
setBounds( x, y, width, height ); |
583 |
} |
} |
584 |
|
|
591 |
|
|
592 |
public void setBounds(int x, int y, int width, int height) |
public void setBounds(int x, int y, int width, int height) |
593 |
{ |
{ |
594 |
|
if( ignoreResize ) |
595 |
|
return; |
596 |
if(width > 0 && height > 0 && (drawableComponent() || backBuffer != null)) |
if(width > 0 && height > 0 && (drawableComponent() || backBuffer != null)) |
597 |
backBuffer = new QtImage(width, height); |
backBuffer = new QtImage(width, height); |
598 |
setBoundsNative(x, y, width, height); |
setBoundsNative(x, y, width, height); |
599 |
|
QtToolkit.repaintThread.queueComponent(this); |
600 |
} |
} |
601 |
|
|
602 |
public void setCursor(Cursor cursor) |
public void setCursor(Cursor cursor) |
636 |
case ComponentEvent.COMPONENT_SHOWN: |
case ComponentEvent.COMPONENT_SHOWN: |
637 |
case PaintEvent.PAINT: |
case PaintEvent.PAINT: |
638 |
case PaintEvent.UPDATE: |
case PaintEvent.UPDATE: |
639 |
dirtyBackBuffer = true; |
QtToolkit.repaintThread.queueComponent(this); |
|
QtUpdate(); |
|
640 |
break; |
break; |
641 |
case KeyEvent.KEY_PRESSED: |
case KeyEvent.KEY_PRESSED: |
642 |
break; |
break; |
646 |
} |
} |
647 |
|
|
648 |
/** |
/** |
649 |
* Paint() is called back from the native side in response to a native |
* paint() is called back from the native side in response to a native |
650 |
* repaint event. |
* repaint event. |
651 |
*/ |
*/ |
652 |
public void paint(Graphics g) |
public void paint(Graphics g) |
653 |
{ |
{ |
654 |
if (backBuffer != null) |
if (backBuffer != null) |
655 |
|
backBuffer.drawPixels((QtGraphics)g, 0, 0, 0, 0, 0, false ); |
656 |
|
} |
657 |
|
|
658 |
|
public void paintBackBuffer() |
659 |
|
{ |
660 |
|
if( backBuffer != null) |
661 |
{ |
{ |
662 |
if (dirtyBackBuffer) |
backBuffer.clear(); |
663 |
{ |
Graphics2D bbg = (Graphics2D)backBuffer.getGraphics(); |
664 |
backBuffer.clear(); |
owner.paint(bbg); |
665 |
Graphics2D bbg = (Graphics2D)backBuffer.getGraphics(); |
bbg.dispose(); |
|
owner.paint(bbg); |
|
|
bbg.dispose(); |
|
|
dirtyBackBuffer = false; |
|
|
} |
|
|
backBuffer.drawPixels((QtGraphics)g, 0, 0, 0, 0, 0, false ); |
|
666 |
} |
} |
667 |
} |
} |
668 |
|
|