1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import java
.awt
.event
.*;
22 import java
.awt
.image
.*;
23 import javax
.swing
.JTextArea
;
24 import javax
.swing
.JFrame
;
26 import javax
.imageio
.ImageIO
;
28 public class EditorFrame
extends JFrame
30 private final OwnEmbeddedObject m_aEmbObj
;
31 private final JTextArea m_aTextArea
;
32 private BufferedImage m_aBufImage
;
34 private final WindowListener m_aCloser
= new WindowAdapter()
37 public void windowClosing( WindowEvent e
)
39 m_aBufImage
= new BufferedImage( m_aTextArea
.getWidth(), m_aTextArea
.getHeight(), BufferedImage
.TYPE_INT_RGB
);
40 Graphics2D aGr
= m_aBufImage
.createGraphics();
41 m_aTextArea
.paintAll( aGr
);
45 m_aEmbObj
.CloseFrameRequest();
49 public EditorFrame( String sName
, OwnEmbeddedObject aEmbObj
, int nWidth
, int nHeight
)
53 addWindowListener( m_aCloser
);
54 m_aTextArea
= new JTextArea( "", nWidth
, nHeight
);
56 add( "Center", m_aTextArea
);
60 public String
getText()
62 return m_aTextArea
.getText();
65 public void setText( String aText
)
67 m_aTextArea
.setText( aText
);
70 public Dimension
getAppSize()
72 return m_aTextArea
.getSize();
75 public void setAppSize( Dimension aSize
)
77 Dimension aOwnSize
= getSize();
78 Dimension aAppSize
= m_aTextArea
.getSize();
80 new Dimension( (int)( aSize
.getWidth() + aOwnSize
.getWidth() - aAppSize
.getWidth() ),
81 (int)(aSize
.getHeight() + aOwnSize
.getHeight() - aAppSize
.getHeight() ) );
87 public byte[] getReplacementImage()
89 Dimension aDim
= m_aTextArea
.getSize();
90 BufferedImage aBufImage
= null;
92 if ( m_aBufImage
!= null )
93 aBufImage
= m_aBufImage
;
98 int nWidth
= (int)aDim
.getWidth();
99 int nHeight
= (int)aDim
.getHeight();
100 aBufImage
= new BufferedImage( nWidth
, nHeight
, BufferedImage
.TYPE_INT_RGB
);
101 Graphics2D aGr
= aBufImage
.createGraphics();
102 aGr
.setBackground( Color
.WHITE
);
103 aGr
.clearRect( 0, 0, nWidth
, nHeight
);
106 catch ( java
.lang
.Exception e
)
110 if ( aBufImage
!= null )
114 File aTmpFile
= File
.createTempFile( "temp", ".png" );
115 ImageIO
.write( aBufImage
, "png", aTmpFile
);
117 int nLen
= (int)aTmpFile
.length();
118 byte[] aResult
= new byte[nLen
];
119 FileInputStream aTmpStream
= new FileInputStream( aTmpFile
);
120 aTmpStream
.read( aResult
);
126 catch ( java
.lang
.Exception e
)
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */