Source Code Cross Referenced for Clipboard.java in  » Testing » UISpec4J » org » uispec4j » 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 » Testing » UISpec4J » org.uispec4j 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.uispec4j;
002:
003:        import java.awt.*;
004:        import java.awt.datatransfer.*;
005:        import java.io.*;
006:        import java.nio.ByteBuffer;
007:        import java.nio.CharBuffer;
008:
009:        /**
010:         * Utility for changing and checking the contents of the system's clipboard.
011:         */
012:        public class Clipboard {
013:
014:            public static final TextType HTML = new TextType("text/html");
015:            public static final TextType PLAIN = new TextType("text/plain");
016:
017:            public static final Charset UTF8 = new Charset("UTF-8");
018:            public static final Charset UTF16 = new Charset("UTF-16");
019:            public static final Charset UNICODE = new Charset("unicode");
020:            public static final Charset US_ASCII = new Charset("US-ASCII");
021:
022:            public static final TransferType READER = new TransferType(
023:                    Reader.class);
024:            public static final TransferType INPUT_STREAM = new TransferType(
025:                    InputStream.class);
026:            public static final TransferType CHAR_BUFFER = new TransferType(
027:                    CharBuffer.class);
028:            public static final TransferType BYTE_BUFFER = new TransferType(
029:                    ByteBuffer.class);
030:
031:            private Clipboard() {
032:            }
033:
034:            /**
035:             * Dumps a given text (either String or StringBuffer) into the Clipboard, with a default MIME type
036:             */
037:            public static void putText(CharSequence data) {
038:                StringSelection copy = new StringSelection(data.toString());
039:                getSystemClipboard().setContents(copy, copy);
040:            }
041:
042:            /**
043:             * Dumps a given text (either String or StringBuffer) into the Clipboard with a specified MIME type
044:             */
045:            public static void putText(TextType type, Charset charset,
046:                    TransferType transferType, CharSequence data) {
047:                String mimeType = type + "; charset=" + charset + "; class="
048:                        + transferType;
049:                TextTransferable transferable = new TextTransferable(mimeType,
050:                        data.toString());
051:                getSystemClipboard().setContents(transferable, transferable);
052:            }
053:
054:            private static java.awt.datatransfer.Clipboard getSystemClipboard() {
055:                return Toolkit.getDefaultToolkit().getSystemClipboard();
056:            }
057:
058:            private static class TextTransferable implements  Transferable,
059:                    ClipboardOwner {
060:                private String data;
061:                private DataFlavor flavor;
062:
063:                public TextTransferable(String mimeType, String data) {
064:                    flavor = new DataFlavor(mimeType, "Text");
065:                    this .data = data;
066:                }
067:
068:                public DataFlavor[] getTransferDataFlavors() {
069:                    return new DataFlavor[] { flavor };
070:                }
071:
072:                public boolean isDataFlavorSupported(DataFlavor flavor) {
073:                    boolean b = this .flavor.getPrimaryType().equals(
074:                            flavor.getPrimaryType());
075:                    return b;
076:                }
077:
078:                public Object getTransferData(DataFlavor flavor)
079:                        throws UnsupportedFlavorException, IOException {
080:                    if (flavor.isRepresentationClassInputStream()) {
081:                        return new StringBufferInputStream(data);
082:                    } else if (flavor.isRepresentationClassReader()) {
083:                        return new StringReader(data);
084:                    } else if (flavor.isRepresentationClassCharBuffer()) {
085:                        return CharBuffer.wrap(data);
086:                    } else if (flavor.isRepresentationClassByteBuffer()) {
087:                        return ByteBuffer.wrap(data.getBytes());
088:                    }
089:                    throw new UnsupportedFlavorException(flavor);
090:                }
091:
092:                public void lostOwnership(
093:                        java.awt.datatransfer.Clipboard clipboard,
094:                        Transferable contents) {
095:                }
096:            }
097:
098:            /**
099:             * Enumeration for the text type property in MIME types
100:             */
101:            public static class TextType {
102:                private String type;
103:
104:                private TextType(String type) {
105:                    this .type = type;
106:                }
107:
108:                public String toString() {
109:                    return type;
110:                }
111:            }
112:
113:            /**
114:             * Enumeration for the charset property in MIME types (UTF-8, UTF-16, etc.)
115:             */
116:            public static class Charset {
117:                private String name;
118:
119:                private Charset(String name) {
120:                    this .name = name;
121:                }
122:
123:                public String toString() {
124:                    return name;
125:                }
126:            }
127:
128:            /**
129:             * Enumeration for the transfert type property in MIME types (InputStream, CharBuffer, etc.)
130:             */
131:            public static class TransferType {
132:                private Class dataClass;
133:
134:                private TransferType(Class streamClass) {
135:                    this .dataClass = streamClass;
136:                }
137:
138:                public Class getDataClass() {
139:                    return dataClass;
140:                }
141:
142:                public String toString() {
143:                    return dataClass.getName();
144:                }
145:            }
146:
147:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.