Source Code Cross Referenced for RdpViewer.java in  » Net » Remote-desktop » org » rdesktop » server » rdp » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » Remote desktop » org.rdesktop.server.rdp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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;
022:
023:import java.io.*;
024:import java.net.*;
025:import java.awt.*;
026:import javax.swing.*;
027:
028:import org.rdesktop.server.*;
029:import org.rdesktop.server.rdp.rdp5.*;
030:import org.rdesktop.server.rdp.rdp5.cliprdr.ClipChannel;
031:import org.rdesktop.server.rdp.keymapping.KeyCode_FileBased;
032:
033:public class RdpViewer implements  Runnable
034:{
035:    private static final String keyMapPath = "keymaps/";
036:
037:    public static final int exDiscReasonNoInfo = 0x0000;
038:    public static final int exDiscReasonAPIInitiatedDisconnect = 0x0001;
039:    public static final int exDiscReasonAPIInitiatedLogoff = 0x0002;
040:    public static final int exDiscReasonServerIdleTimeout = 0x0003;
041:    public static final int exDiscReasonServerLogonTimeout = 0x0004;
042:    public static final int exDiscReasonReplacedByOtherConnection = 0x0005;
043:    public static final int exDiscReasonOutOfMemory = 0x0006;
044:    public static final int exDiscReasonServerDeniedConnection = 0x0007;
045:    public static final int exDiscReasonServerDeniedConnectionFips = 0x0008;
046:    public static final int exDiscReasonLicenseInternal = 0x0100;
047:    public static final int exDiscReasonLicenseNoLicenseServer = 0x0101;
048:    public static final int exDiscReasonLicenseNoLicense = 0x0102;
049:    public static final int exDiscReasonLicenseErrClientMsg = 0x0103;
050:    public static final int exDiscReasonLicenseHwidDoesntMatchLicense = 0x0104;
051:    public static final int exDiscReasonLicenseErrClientLicense = 0x0105;
052:    public static final int exDiscReasonLicenseCantFinishProtocol = 0x0106;
053:    public static final int exDiscReasonLicenseClientEndedProtocol = 0x0107;
054:    public static final int exDiscReasonLicenseErrClientEncryption = 0x0108;
055:    public static final int exDiscReasonLicenseCantUpgradeLicense = 0x0109;
056:    public static final int exDiscReasonLicenseNoRemoteConnections = 0x010a;
057:    
058:    private int m_width;
059:    private int m_height;
060:    private int m_bitsPerPixel;
061:    private String[] m_args;
062:
063:    private int m_port;
064:    private String m_host;
065:    private String m_mapFile;
066:
067:    private RdpClient m_rdpProto;
068:    private Thread m_rdpProtoThread;
069:    private RdpDesktopFrame m_desktop;
070:
071:    private RemoteDesktopApplet m_applet;
072:    private org.rdesktop.objects.RdpDesktopExchange m_exchange;
073:
074:    private static String textDisconnectReason(int reason)
075:    {
076:        String text;
077:
078:        switch (reason)
079:        {
080:            case exDiscReasonNoInfo:
081:            {
082:                text = "No information available";
083:                break;
084:            }
085:            case exDiscReasonAPIInitiatedDisconnect:
086:            {
087:                text = "Server initiated disconnect";
088:                break;
089:            }
090:            case exDiscReasonAPIInitiatedLogoff:
091:            {
092:                text = "Server initiated logoff";
093:                break;
094:            }
095:            case exDiscReasonServerIdleTimeout:
096:            {
097:                text = "Server idle timeout reached";
098:                break;
099:            }
100:            case exDiscReasonServerLogonTimeout:
101:            {
102:                text = "Server logon timeout reached";
103:                break;
104:            }
105:            case exDiscReasonReplacedByOtherConnection:
106:            {
107:                text = "Another user connected to the session";
108:                break;
109:            }
110:            case exDiscReasonOutOfMemory:
111:            {
112:                text = "The server is out of memory";
113:                break;
114:            }
115:            case exDiscReasonServerDeniedConnection:
116:            {
117:                text = "The server denied the connection";
118:                break;
119:            }
120:            case exDiscReasonServerDeniedConnectionFips:
121:            {
122:                text = "The server denied the connection for security reason";
123:                break;
124:            }
125:            case exDiscReasonLicenseInternal:
126:            {
127:                text = "Internal licensing error";
128:                break;
129:            }
130:            case exDiscReasonLicenseNoLicenseServer:
131:            {
132:                text = "No license server available";
133:                break;
134:            }
135:            case exDiscReasonLicenseNoLicense:
136:            {
137:                text = "No valid license available";
138:                break;
139:            }
140:            case exDiscReasonLicenseErrClientMsg:
141:            {
142:                text = "Invalid licensing message";
143:                break;
144:            }
145:            case exDiscReasonLicenseHwidDoesntMatchLicense:
146:            {
147:                text = "Hardware id doesn't match software license";
148:                break;
149:            }
150:            case exDiscReasonLicenseErrClientLicense:
151:            {
152:                text = "Client license error";
153:                break;
154:            }
155:            case exDiscReasonLicenseCantFinishProtocol:
156:            {
157:                text = "Network error during licensing protocol";
158:                break;
159:            }
160:            case exDiscReasonLicenseClientEndedProtocol:
161:            {
162:                text = "Licensing protocol was not completed";
163:                break;
164:            }
165:            case exDiscReasonLicenseErrClientEncryption:
166:            {
167:                text = "Incorrect client license enryption";
168:                break;
169:            }
170:            case exDiscReasonLicenseCantUpgradeLicense:
171:            {
172:                text = "Can't upgrade license";
173:                break;
174:            }
175:            case exDiscReasonLicenseNoRemoteConnections:
176:            {
177:                text = "The server is not licensed to accept remote connections";
178:                break;
179:            }
180:            default:
181:            {
182:                if (reason > 0x1000 && reason < 0x7fff)
183:                {
184:                    text = "Internal protocol error";
185:                }
186:                else
187:                {
188:                    text = "Unknown reason";
189:                }
190:            }
191:        }
192:
193:        return text;
194:    }
195:
196:    public static RdpViewer main(String[] args, org.rdesktop.objects.RdpDesktopExchange exchange, RemoteDesktopApplet applet)
197:    {
198:        RdpViewer viewer = new RdpViewer(args, exchange, applet);
199:        viewer.init();
200:
201:        return viewer;
202:    }
203:
204:    public RdpViewer(String[] args, org.rdesktop.objects.RdpDesktopExchange exchange, RemoteDesktopApplet applet)
205:    {
206:        m_args = args;
207:        m_exchange = exchange;
208:        m_applet = applet;
209:    }
210:
211:    public void init()
212:    {
213:        m_width = 1024;
214:        m_height = 768;
215:        m_mapFile = "en-gb";
216:
217:        readParameters();
218:
219:        m_desktop = new RdpDesktopFrame(this , m_width, m_height, m_applet);
220:
221:        /* REMOVE
222:        ClipChannel clipChannel = new ClipChannel();
223:        m_desktop.setClip(clipChannel);
224:
225:        VChannels channels = new VChannels();
226:        
227:        // Initialise all RDP5 channels
228:        if (RdpOptions.use_rdp5)
229:        {
230:            // TODO: implement all relevant channels
231:            if (RdpOptions.map_clipboard)
232:            {
233:                channels.register(clipChannel);
234:            }
235:        }
236:        */
237:
238:        KeyCode_FileBased keyMap = null;
239:        try
240:        {
241:            InputStream istr = RdpViewer.class.getResourceAsStream("/" + keyMapPath + m_mapFile);
242:            if (istr == null)
243:            {
244:                keyMap = new RdpKeyCodeFileBased(keyMapPath + m_mapFile);
245:            }
246:            else
247:            {
248:                keyMap = new RdpKeyCodeFileBased(istr);
249:            }
250:
251:            if (istr != null)
252:            {
253:                istr.close();
254:            }
255:
256:            RdpOptions.keylayout = keyMap.getMapCode();
257:        }
258:        catch (Exception e)
259:        {
260:            String[] msg = { (e.getClass() + ": " + e.getMessage()) };
261:            fatalError(msg[0], e);
262:            return;
263:        }
264:
265:        if (keyMap != null)
266:        {
267:            m_desktop.registerKeyboard(keyMap);
268:        }
269:
270:        m_rdpProto = new RdpClient(m_exchange);
271:        m_rdpProto.registerDrawingSurface(m_desktop);
272:        m_desktop.registerCommLayer(m_rdpProto);
273:
274:        m_rdpProtoThread = new Thread(this );
275:        m_rdpProtoThread.setPriority(Thread.NORM_PRIORITY - 1);
276:        m_rdpProtoThread.start();
277:    }
278:
279:    public void readParameters()
280:    {
281:        m_host = readParameter("HOST", true);
282:        m_port = Integer.parseInt(readParameter("PORT", true));
283:
284:        String dimension = readParameter("DIMENSION", false);;
285:        if (dimension != null)
286:        {
287:            String[] dim = dimension.split("x");
288:            m_width = Integer.parseInt(dim[0]);
289:            m_height = Integer.parseInt(dim[1]);
290:        }
291:
292:        String str = readParameter("BANDWIDTH", false);
293:        if ((str != null) && (str.equalsIgnoreCase("LOW") == true))
294:        {
295:            m_bitsPerPixel = 8;
296:        }
297:        else
298:        {
299:            m_bitsPerPixel = 24;
300:        }
301:    }
302:
303:    public String readParameter(String name, boolean required)
304:    {
305:        for (int i = 0; i < m_args.length; i += 2)
306:        {
307:            if (m_args[i].equalsIgnoreCase(name))
308:            {
309:                try
310:                {
311:                    return m_args[i+1];
312:                }
313:                catch (Exception e)
314:                {
315:                    if (required)
316:                    {
317:                        fatalError(name + " parameter not specified");
318:                    }
319:
320:                    return null;
321:                }
322:            }
323:        }
324:
325:        if (required == true)
326:        {
327:            fatalError(name + " parameter not specified");
328:        }
329:
330:        return null;
331:    }
332:
333:    protected int readIntParameter(String name, int defaultValue)
334:    {
335:        int result = defaultValue;
336:        String str = readParameter(name, false);
337:        if (str != null)
338:        {
339:            try
340:            {
341:                result = Integer.parseInt(str);
342:            }
343:            catch (NumberFormatException e)
344:            {
345:            }
346:        }
347:
348:        return result;
349:    }
350:
351:    public void run()
352:    {
353:        int[] ext_disc_reason = new int[1];
354:        int logonflags = RdpProto.RDP_LOGON_NORMAL; // |= RdpProto.RDP_LOGON_AUTO
355:
356:        // TODO: integrate into readParameter
357:        String m_username = "";
358:        String m_password = "";
359:        String m_domain = "";
360:
361:        // TODO: reconnect if connection fails
362:
363:        try
364:        {
365:            m_rdpProto.connect(m_host, m_port, m_username, m_password, logonflags, m_domain, m_width, m_height, m_bitsPerPixel);
366:            m_rdpProto.mainLoop(ext_disc_reason);
367:        }
368:        catch (Exception e)
369:        {
370:            String[] msg = { (e.getClass() + ": " + e.getMessage()) + " - " + textDisconnectReason(ext_disc_reason[0]) };
371:            fatalError(msg[0], e);
372:        }
373:
374:        Disconnect();
375:    }
376:
377:    public synchronized void Disconnect()
378:    {
379:        if ((m_rdpProto != null) && (m_rdpProto.isConnected() == true))
380:        {
381:            m_rdpProto.disconnect();
382:        }
383:    }
384:
385:    public boolean isConnected()
386:    {
387:        return (m_rdpProto != null) ? m_rdpProto.isConnected() : false;
388:    }
389:
390:    public synchronized void fatalError(String str)
391:    {
392:        fatalError(str, null);
393:    }
394:
395:    public synchronized void fatalError(String str, Exception e)
396:    {
397:        if ((m_rdpProto != null) && (m_rdpProto.isConnected() == false))
398:        {
399:            try
400:            {
401:                m_rdpProto.disconnect();
402:            }
403:            catch (Exception ee)
404:            {
405:                // ee.printStackTrace();
406:            }
407:        }
408:
409:        m_rdpProto = null;
410:        
411:        String message = "";
412:        if (e != null)
413:        {
414:            message = e.getMessage();
415:            e.printStackTrace();
416:        }
417:
418:        JOptionPane.showMessageDialog(null,
419:                                      "Message (" + message + ")",
420:                                      "Remote Desktop Failure",
421:                                      JOptionPane.ERROR_MESSAGE);
422:        System.exit(1);
423:    }
424:}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.