INTEGRATION: CWS mav21 (1.1.2); FILE ADDED
2007/05/03 15:19:18 mav 1.1.2.6: #i75252# fix size retrieving 2007/05/03 14:23:32 mav 1.1.2.5: #i75252# support resizing of the object 2007/03/28 14:13:33 mav 1.1.2.4: #i75252# support resizing of the object 2007/03/27 08:32:23 mav 1.1.2.3: #75252# fix windows problem 2007/03/09 10:28:09 mav 1.1.2.2: #75252# improve performance 2007/03/09 10:24:18 mav 1.1.2.1: #75252# an example of addon with new embedded object implementation
This commit is contained in:
parent
7bdf5b8984
commit
e9c42531a5
1 changed files with 121 additions and 0 deletions
121
odk/examples/java/EmbedDocument/EmbeddedObject/EditorFrame.java
Executable file
121
odk/examples/java/EmbedDocument/EmbeddedObject/EditorFrame.java
Executable file
|
@ -0,0 +1,121 @@
|
|||
package org.openoffice.examples.embedding;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.image.*;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JFrame;
|
||||
import java.io.*;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import org.openoffice.examples.embedding.OwnEmbeddedObject;
|
||||
|
||||
public class EditorFrame extends JFrame
|
||||
{
|
||||
OwnEmbeddedObject m_aEmbObj;
|
||||
JTextArea m_aTextArea;
|
||||
BufferedImage m_aBufImage;
|
||||
|
||||
WindowListener m_aCloser = new WindowAdapter()
|
||||
{
|
||||
public void windowClosing( WindowEvent e )
|
||||
{
|
||||
// m_aBufImage = m_aTextArea.getGraphicsConfiguration().createCompatibleImage( m_aTextArea.getWidth(), m_aTextArea.getHeight() );
|
||||
m_aBufImage = new BufferedImage( m_aTextArea.getWidth(), m_aTextArea.getHeight(), BufferedImage.TYPE_INT_RGB );
|
||||
Graphics2D aGr = m_aBufImage.createGraphics();
|
||||
m_aTextArea.paintAll( aGr );
|
||||
aGr.dispose();
|
||||
|
||||
hide();
|
||||
m_aEmbObj.CloseFrameRequest();
|
||||
}
|
||||
};
|
||||
|
||||
public EditorFrame( String sName, OwnEmbeddedObject aEmbObj, int nWidth, int nHeight )
|
||||
{
|
||||
super( sName );
|
||||
m_aEmbObj = aEmbObj;
|
||||
addWindowListener( m_aCloser );
|
||||
m_aTextArea = new JTextArea( "", nWidth, nHeight );
|
||||
|
||||
add( "Center", m_aTextArea );
|
||||
pack();
|
||||
// setResizable( false );
|
||||
}
|
||||
|
||||
public String getText()
|
||||
{
|
||||
return m_aTextArea.getText();
|
||||
}
|
||||
|
||||
public void setText( String aText )
|
||||
{
|
||||
m_aTextArea.setText( aText );
|
||||
}
|
||||
|
||||
public Dimension getAppSize()
|
||||
{
|
||||
return m_aTextArea.getSize();
|
||||
}
|
||||
|
||||
public void setAppSize( Dimension aSize )
|
||||
{
|
||||
Dimension aOwnSize = getSize();
|
||||
Dimension aAppSize = m_aTextArea.getSize();
|
||||
Dimension aToSet =
|
||||
new Dimension( (int)( aSize.getWidth() + aOwnSize.getWidth() - aAppSize.getWidth() ),
|
||||
(int)(aSize.getHeight() + aOwnSize.getHeight() - aAppSize.getHeight() ) );
|
||||
|
||||
setSize( aToSet );
|
||||
validate();
|
||||
|
||||
// pack();
|
||||
}
|
||||
|
||||
public byte[] getReplacementImage()
|
||||
{
|
||||
Dimension aDim = m_aTextArea.getSize();
|
||||
BufferedImage aBufImage = null;
|
||||
|
||||
if ( m_aBufImage != null )
|
||||
aBufImage = m_aBufImage;
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
int nWidth = (int)aDim.getWidth();
|
||||
int nHeight = (int)aDim.getHeight();
|
||||
aBufImage = new BufferedImage( nWidth, nHeight, BufferedImage.TYPE_INT_RGB );
|
||||
Graphics2D aGr = aBufImage.createGraphics();
|
||||
aGr.setBackground( Color.WHITE );
|
||||
aGr.clearRect( 0, 0, nWidth, nHeight );
|
||||
aGr.dispose();
|
||||
}
|
||||
catch ( java.lang.Exception e )
|
||||
{}
|
||||
}
|
||||
|
||||
if ( aBufImage != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
File aTmpFile = File.createTempFile( "temp", ".png" );
|
||||
ImageIO.write( aBufImage, "png", aTmpFile );
|
||||
|
||||
int nLen = (int)aTmpFile.length();
|
||||
byte[] aResult = new byte[nLen];
|
||||
FileInputStream aTmpStream = new FileInputStream( aTmpFile );
|
||||
aTmpStream.read( aResult );
|
||||
aTmpStream.close();
|
||||
aTmpFile.delete();
|
||||
|
||||
return aResult;
|
||||
}
|
||||
catch ( java.lang.Exception e )
|
||||
{}
|
||||
}
|
||||
|
||||
return new byte[0];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in a new issue