1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: CanvasCustomSprite.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 import com
.sun
.star
.rendering
.*;
33 import com
.sun
.star
.geometry
.*;
37 import java
.awt
.geom
.*;
39 public class CanvasCustomSprite
40 extends com
.sun
.star
.lib
.uno
.helper
.ComponentBase
41 implements com
.sun
.star
.rendering
.XCustomSprite
,
42 com
.sun
.star
.lang
.XServiceInfo
,
45 private JavaCanvas canvas
;
46 private RealSize2D spriteSize
;
47 private Graphics2D referenceGraphics
;
49 private java
.awt
.geom
.Point2D
.Double outputPosition
;
50 private SpriteRep spriteRep
;
52 //----------------------------------------------------------------------------------
54 public CanvasCustomSprite( RealSize2D _spriteSize
,
56 Graphics2D _referenceGraphics
)
58 CanvasUtils
.printLog( "CanvasCustomSprite constructor called, size is (" + _spriteSize
.Width
+ ", " + _spriteSize
.Height
+ ")" );
61 spriteSize
= _spriteSize
;
62 referenceGraphics
= _referenceGraphics
;
64 outputPosition
= new java
.awt
.geom
.Point2D
.Double(0.0,0.0);
67 //----------------------------------------------------------------------------------
73 public synchronized SpriteRep
getSpriteRep()
75 if( spriteRep
== null )
77 spriteRep
= new SpriteRep();
79 spriteRep
.setupBuffer(referenceGraphics
, (int)(spriteSize
.Width
+.5), (int)(spriteSize
.Height
+.5) );
81 spriteRep
.moveSprite( outputPosition
);
82 spriteRep
.setSpriteAlpha( alpha
);
87 //----------------------------------------------------------------------------------
95 if( spriteRep
!= null )
99 referenceGraphics
= null;
105 //----------------------------------------------------------------------------------
108 // XCustomSprite impl
109 // ==================
112 public synchronized void setPriority( double nPriority
)
117 public synchronized void setAlpha( double _alpha
)
119 CanvasUtils
.printLog( "CanvasCustomSprite.setAlpha() called" );
123 if( spriteRep
!= null )
125 spriteRep
.setSpriteAlpha( alpha
);
129 public synchronized void move( RealPoint2D _aNewPos
,
130 ViewState _viewState
,
131 RenderState _renderState
)
133 CanvasUtils
.printLog( "CanvasCustomSprite.move() called" );
135 // transform given point with concatenated transformation
136 AffineTransform transform
= CanvasUtils
.ViewConcatRenderTransform( _viewState
, _renderState
);
137 transform
.transform( new java
.awt
.geom
.Point2D
.Double(_aNewPos
.X
,
141 if( spriteRep
!= null )
143 spriteRep
.moveSprite( outputPosition
);
147 public synchronized void transform( AffineMatrix2D aTransformation
) throws com
.sun
.star
.lang
.IllegalArgumentException
152 public synchronized void clip( XPolyPolygon2D aClip
)
157 public synchronized void show()
159 CanvasUtils
.printLog( "CanvasCustomSprite.show() called" );
161 canvas
.showSprite( this );
162 canvas
.updateScreen( false );
165 public synchronized void hide()
167 CanvasUtils
.printLog( "CanvasCustomSprite.hide() called" );
169 canvas
.hideSprite( this );
171 // do _not_ dispose clear SpriteRep, since we cannot actively
175 public synchronized com
.sun
.star
.rendering
.XCanvas
getContentCanvas()
177 CanvasUtils
.printLog( "CanvasCustomSprite.getContentCanvas() called" );
179 return getSpriteRep().getContentCanvas();
182 //----------------------------------------------------------------------------------
184 private static final String s_implName
= "XCustomSprite.java.impl";
185 private static final String s_serviceName
= "com.sun.star.rendering.CustomSprite";
187 //----------------------------------------------------------------------------------
193 public String
getImplementationName()
198 public String
[] getSupportedServiceNames()
200 return new String
[] { s_serviceName
};
203 public boolean supportsService( String serviceName
)
205 return serviceName
.equals( s_serviceName
);