update dev300-m58
[ooovba.git] / canvas / source / java / CanvasCustomSprite.java
blob2567ba0b6ceb839d416efa58bc2ef2e1f8d03ebe
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: CanvasCustomSprite.java,v $
10 * $Revision: 1.7 $
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 ************************************************************************/
31 // Canvas
32 import com.sun.star.rendering.*;
33 import com.sun.star.geometry.*;
35 // Java AWT
36 import java.awt.*;
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,
43 SpriteBase
45 private JavaCanvas canvas;
46 private RealSize2D spriteSize;
47 private Graphics2D referenceGraphics;
48 private double alpha;
49 private java.awt.geom.Point2D.Double outputPosition;
50 private SpriteRep spriteRep;
52 //----------------------------------------------------------------------------------
54 public CanvasCustomSprite( RealSize2D _spriteSize,
55 JavaCanvas _canvas,
56 Graphics2D _referenceGraphics )
58 CanvasUtils.printLog( "CanvasCustomSprite constructor called, size is (" + _spriteSize.Width + ", " + _spriteSize.Height + ")" );
60 canvas = _canvas;
61 spriteSize = _spriteSize;
62 referenceGraphics = _referenceGraphics;
63 alpha = 0.0;
64 outputPosition = new java.awt.geom.Point2D.Double(0.0,0.0);
67 //----------------------------------------------------------------------------------
70 // SpriteBase
71 // ==========
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 );
84 return spriteRep;
87 //----------------------------------------------------------------------------------
90 // XComponent
91 // ==========
93 public void dispose()
95 if( spriteRep != null )
96 spriteRep.dispose();
98 canvas = null;
99 referenceGraphics = null;
100 spriteRep = null;
102 super.dispose();
105 //----------------------------------------------------------------------------------
108 // XCustomSprite impl
109 // ==================
112 public synchronized void setPriority( double nPriority )
114 // TODO
117 public synchronized void setAlpha( double _alpha )
119 CanvasUtils.printLog( "CanvasCustomSprite.setAlpha() called" );
121 alpha = _alpha;
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,
138 _aNewPos.Y),
139 outputPosition );
141 if( spriteRep != null )
143 spriteRep.moveSprite( outputPosition );
147 public synchronized void transform( AffineMatrix2D aTransformation ) throws com.sun.star.lang.IllegalArgumentException
149 // TODO
152 public synchronized void clip( XPolyPolygon2D aClip )
154 // TODO
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
172 // repaint ourselves
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 //----------------------------------------------------------------------------------
190 // XServiceInfo impl
191 // =================
193 public String getImplementationName()
195 return s_implName;
198 public String [] getSupportedServiceNames()
200 return new String [] { s_serviceName };
203 public boolean supportsService( String serviceName )
205 return serviceName.equals( s_serviceName );