1 package embeddedobj
.test
;
5 import java
.awt
.event
.*;
8 import java
.lang
.Thread
;
10 import com
.sun
.star
.awt
.XBitmap
;
11 import com
.sun
.star
.awt
.XDevice
;
12 import com
.sun
.star
.awt
.XDisplayBitmap
;
13 import com
.sun
.star
.awt
.XGraphics
;
14 import com
.sun
.star
.awt
.XWindow
;
15 import com
.sun
.star
.awt
.XWindowPeer
;
16 import com
.sun
.star
.awt
.XToolkit
;
17 import com
.sun
.star
.awt
.XSystemChildFactory
;
18 import com
.sun
.star
.awt
.WindowDescriptor
;
19 import com
.sun
.star
.awt
.WindowClass
;
20 import com
.sun
.star
.awt
.WindowAttribute
;
22 import com
.sun
.star
.uno
.UnoRuntime
;
23 import com
.sun
.star
.lang
.XMultiServiceFactory
;
25 class PaintThread
extends java
.lang
.Thread
27 private XWindow m_xWindow
;
28 private XBitmap m_xBitmap
;
29 private com
.sun
.star
.awt
.Rectangle m_aRect
;
31 private Object m_oRequestsLock
;
32 private boolean m_bToPaint
= false;
34 private boolean m_bDisposed
= false;
36 public static boolean interceptedRects( com
.sun
.star
.awt
.Rectangle aRect1
, com
.sun
.star
.awt
.Rectangle aRect2
)
38 return ( ( aRect1
.X
<= aRect2
.X
&& aRect2
.X
<= aRect1
.X
+ aRect1
.Width
39 || aRect1
.X
<= aRect2
.X
+ aRect2
.Width
&& aRect2
.X
+ aRect2
.Width
<= aRect1
.X
+ aRect1
.Width
40 || aRect2
.X
<= aRect1
.X
&& aRect1
.X
<= aRect2
.X
+ aRect2
.Width
41 || aRect2
.X
<= aRect1
.X
+ aRect1
.Width
&& aRect1
.X
+ aRect1
.Width
<= aRect2
.X
+ aRect2
.Width
)
42 && ( aRect1
.Y
<= aRect2
.Y
&& aRect2
.Y
<= aRect1
.Y
+ aRect1
.Height
43 || aRect1
.Y
<= aRect2
.Y
+ aRect2
.Height
&& aRect2
.Y
+ aRect2
.Height
<= aRect1
.Y
+ aRect1
.Height
44 || aRect2
.Y
<= aRect1
.Y
&& aRect1
.Y
<= aRect2
.Y
+ aRect2
.Height
45 || aRect2
.Y
<= aRect1
.Y
+ aRect1
.Height
&& aRect1
.Y
+ aRect1
.Height
<= aRect2
.Y
+ aRect2
.Height
) );
48 public PaintThread( XWindow xWindow
)
50 m_oRequestsLock
= new Object();
54 public void setPaintRequest( XBitmap xBitmap
, com
.sun
.star
.awt
.Rectangle aRect
, com
.sun
.star
.awt
.Rectangle aClip
)
56 synchronized( m_oRequestsLock
)
59 System.out.println( "Paint request Pos( "
63 + aRect.Height + " ), Clip ( "
67 + aClip.Height + " )" );
70 if ( PaintThread
.interceptedRects( aRect
, aClip
) )
78 // System.out.println( "Paint request to paint thread is done! xBitmap = " + xBitmap );
81 public void disposeThread()
92 } catch( Exception e
) {}
94 XBitmap xBitmap
= null;
95 com
.sun
.star
.awt
.Rectangle aRect
= null;
96 boolean bPaint
= false;
98 synchronized( m_oRequestsLock
)
111 // System.out.println( "The bitmap is going to be painted!" );
112 XDevice xDevice
= (XDevice
)UnoRuntime
.queryInterface( XDevice
.class, m_xWindow
);
113 if ( xDevice
!= null )
115 // System.out.println( "Step1" );
116 XGraphics xGraphics
= xDevice
.createGraphics();
117 if ( xBitmap
!= null )
119 // System.out.println( "Step2" );
120 XDisplayBitmap xDisplayBitmap
= xDevice
.createDisplayBitmap( xBitmap
);
122 com
.sun
.star
.awt
.Size aSize
= xBitmap
.getSize();
123 xGraphics
.draw( xDisplayBitmap
, 0, 0, aSize
.Width
, aSize
.Height
,
124 aRect
.X
, aRect
.Y
, aRect
.Width
, aRect
.Height
);
127 // System.out.println( "Step3" );
128 // xGraphics.drawRect( aRect.X - 1, aRect.Y - 1, aRect.Width + 2, aRect.Height + 2 );
129 xGraphics
.drawLine( aRect
.X
- 1, aRect
.Y
- 1,
130 aRect
.X
+ aRect
.Width
+ 1, aRect
.Y
- 1 );
131 xGraphics
.drawLine( aRect
.X
+ aRect
.Width
+ 1, aRect
.Y
- 1,
132 aRect
.X
+ aRect
.Width
+ 1, aRect
.Y
+ aRect
.Height
+ 1 );
133 xGraphics
.drawLine( aRect
.X
+ aRect
.Width
+ 1, aRect
.Y
+ aRect
.Height
+ 1,
134 aRect
.X
- 1, aRect
.Y
+ aRect
.Height
+ 1 );
135 xGraphics
.drawLine( aRect
.X
- 1, aRect
.Y
+ aRect
.Height
+ 1,
136 aRect
.X
- 1, aRect
.Y
- 1 );
138 // draw resize squares
139 // System.out.println( "Step4" );
140 // xGraphics.drawRect( aRect.X - 2, aRect.Y - 2, 4, 4 );
141 // xGraphics.drawRect( aRect.X + aRect.Width - 2, aRect.Y - 2, 4, 4 );
142 // xGraphics.drawRect( aRect.X - 2, aRect.Y + aRect.Height - 2, 4, 4 );
143 // xGraphics.drawRect( aRect.X + aRect.Width - 2, aRect.Y + aRect.Height - 2, 4, 4 );
145 // System.out.println( "Step5" );
147 // System.out.println( "The bitmap is painted by paint thread!" );