001: ///////////////////////////////////////////////////////////////////////////////
002: //
003: // This program is free software; you can redistribute it and/or modify
004: // it under the terms of the GNU General Public License and GNU Library
005: // General Public License as published by the Free Software Foundation;
006: // either version 2, or (at your option) any later version.
007: //
008: // This program is distributed in the hope that it will be useful,
009: // but WITHOUT ANY WARRANTY; without even the implied warranty of
010: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
011: // GNU General Public License and GNU Library General Public License
012: // for more details.
013: //
014: // You should have received a copy of the GNU General Public License
015: // and GNU Library General Public License along with this program; if
016: // not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
017: // MA 02139, USA.
018: //
019: //////////////////////////////////////////////////////////////////////////////
020:
021: package org.rdesktop.server.rdp.rdp5.cliprdr;
022:
023: import java.io.*;
024: import java.awt.datatransfer.*;
025:
026: import org.rdesktop.server.rdp.RdpPacket;
027:
028: public class MetafilepictHandler extends TypeHandler {
029: public static final int MM_TEXT = 1;
030: public static final int MM_LOMETRIC = 2;
031: public static final int MM_HIMETRIC = 3;
032: public static final int MM_LOENGLISH = 4;
033: public static final int MM_HIENGLISH = 5;
034: public static final int MM_TWIPS = 6;
035: public static final int MM_ISOTROPIC = 7;
036: public static final int MM_ANISOTROPIC = 8;
037:
038: public boolean formatValid(int format) {
039: return (format == CF_METAFILEPICT);
040: }
041:
042: public boolean mimeTypeValid(String mimeType) {
043: return mimeType.equals("image");
044: }
045:
046: public int preferredFormat() {
047: return CF_METAFILEPICT;
048: }
049:
050: public Transferable handleData(RdpPacket data, int length) {
051: String thingy = "";
052: OutputStream out = null;
053:
054: int mm = data.getLittleEndian32();
055: int width = data.getLittleEndian32();
056: int height = data.getLittleEndian32();
057:
058: try {
059: out = new FileOutputStream("test.wmf");
060:
061: for (int i = 0; i < (length - 12); i++) {
062: int aByte = data.get8();
063: out.write(aByte);
064: thingy += Integer.toHexString(aByte & 0xFF) + " ";
065: }
066:
067: } catch (FileNotFoundException e) {
068: e.printStackTrace();
069: } catch (IOException e) {
070: e.printStackTrace();
071: }
072:
073: return new StringSelection(thingy);
074: }
075:
076: public String name() {
077: return "CF_METAFILEPICT";
078: }
079:
080: public byte[] fromTransferable(Transferable in) {
081: return null;
082: }
083:
084: public void handleData(RdpPacket data, int length,
085: ClipInterface clipInterface) {
086: String thingy = "";
087: OutputStream out = null;
088:
089: int mm = data.getLittleEndian32();
090: int width = data.getLittleEndian32();
091: int height = data.getLittleEndian32();
092:
093: try {
094: out = new FileOutputStream("test.wmf");
095:
096: for (int i = 0; i < (length - 12); i++) {
097: int aByte = data.get8();
098: out.write(aByte);
099: thingy += Integer.toHexString(aByte & 0xFF) + " ";
100: }
101: } catch (FileNotFoundException e) {
102: e.printStackTrace();
103: } catch (IOException e) {
104: e.printStackTrace();
105: }
106: }
107:
108: public void send_data(Transferable in, ClipInterface clipInterface) {
109: clipInterface.send_null(ClipChannel.CLIPRDR_DATA_RESPONSE,
110: ClipChannel.CLIPRDR_ERROR);
111: }
112: }
|