01: ///////////////////////////////////////////////////////////////////////////////
02: //
03: // This program is free software; you can redistribute it and/or modify
04: // it under the terms of the GNU General Public License and GNU Library
05: // General Public License as published by the Free Software Foundation;
06: // either version 2, or (at your option) any later version.
07: //
08: // This program is distributed in the hope that it will be useful,
09: // but WITHOUT ANY WARRANTY; without even the implied warranty of
10: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11: // GNU General Public License and GNU Library General Public License
12: // for more details.
13: //
14: // You should have received a copy of the GNU General Public License
15: // and GNU Library General Public License along with this program; if
16: // not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
17: // MA 02139, USA.
18: //
19: //////////////////////////////////////////////////////////////////////////////
20:
21: package org.rdesktop.server.rdp.rdp5.cliprdr;
22:
23: import java.io.*;
24: import java.awt.*;
25: import java.awt.image.*;
26: import java.awt.datatransfer.*;
27:
28: import org.rdesktop.server.rdp.RdpPacket;
29:
30: public class DIBHandler extends TypeHandler implements ImageObserver {
31: public boolean formatValid(int format) {
32: return (format == CF_DIB);
33: }
34:
35: public boolean mimeTypeValid(String mimeType) {
36: return mimeType.equals("image");
37: }
38:
39: public int preferredFormat() {
40: return CF_DIB;
41: }
42:
43: public String name() {
44: return "CF_DIB";
45: }
46:
47: public void handleData(RdpPacket data, int length, ClipInterface c) {
48: BMPToImageThread thread = new BMPToImageThread(data, length, c);
49: thread.start();
50: }
51:
52: public void send_data(Transferable in, ClipInterface clipInterface) {
53: byte[] out = null;
54:
55: try {
56: if ((in != null)
57: && (in
58: .isDataFlavorSupported(ImageSelection.m_imageFlavor) == true)) {
59: Image img = (Image) in
60: .getTransferData(ImageSelection.m_imageFlavor);
61: ClipBMP clip = new ClipBMP();
62:
63: MediaTracker mediaTracker = new MediaTracker(
64: new Frame());
65: mediaTracker.addImage(img, 0);
66:
67: try {
68: mediaTracker.waitForID(0);
69: } catch (InterruptedException ie) {
70: System.err.println(ie);
71: }
72:
73: if (img == null) {
74: return;
75: }
76:
77: int width = img.getWidth(this );
78: int height = img.getHeight(this );
79: out = clip.getBitmapAsBytes(img, width, height);
80:
81: clipInterface.send_data(out, out.length);
82: }
83: } catch (UnsupportedFlavorException e) {
84: System.err
85: .println("Failed to send DIB: UnsupportedFlavorException");
86: } catch (IOException e) {
87: System.err.println("Failed to send DIB: IOException");
88: }
89: }
90:
91: public boolean imageUpdate(Image arg0, int arg1, int arg2,
92: int arg3, int arg4, int arg5) {
93: return false;
94: }
95: }
|