Last change
on this file since 4 was 4, checked in by davidb, 16 years ago |
Starting source code to Expeditee
|
File size:
1.1 KB
|
Line | |
---|
1 | package org.expeditee.io;
|
---|
2 |
|
---|
3 | import java.awt.Toolkit;
|
---|
4 | import java.awt.datatransfer.StringSelection;
|
---|
5 | import java.io.BufferedWriter;
|
---|
6 | import java.io.IOException;
|
---|
7 | import java.io.PipedWriter;
|
---|
8 | import java.io.Writer;
|
---|
9 |
|
---|
10 | public class ProxyWriter extends BufferedWriter {
|
---|
11 |
|
---|
12 | private StringBuffer _contents = null;
|
---|
13 |
|
---|
14 | public ProxyWriter(Writer out) {
|
---|
15 | super(out);
|
---|
16 | }
|
---|
17 |
|
---|
18 | public ProxyWriter(Writer out, int sz) {
|
---|
19 | super(out, sz);
|
---|
20 | }
|
---|
21 |
|
---|
22 | public ProxyWriter(boolean useClipboard) {
|
---|
23 | // create a writer that does nothing
|
---|
24 | super(new PipedWriter());
|
---|
25 | _contents = new StringBuffer("");
|
---|
26 | }
|
---|
27 |
|
---|
28 | @Override
|
---|
29 | public void write(String s) throws IOException {
|
---|
30 | if (_contents != null) {
|
---|
31 | _contents.append(s);
|
---|
32 | } else
|
---|
33 | super.write(s);
|
---|
34 | }
|
---|
35 |
|
---|
36 | @Override
|
---|
37 | public void flush() throws IOException {
|
---|
38 | if (_contents != null) {
|
---|
39 | StringSelection selection = new StringSelection(_contents
|
---|
40 | .toString());
|
---|
41 | Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
|
---|
42 | selection, null);
|
---|
43 | } else
|
---|
44 | super.flush();
|
---|
45 | }
|
---|
46 |
|
---|
47 | @Override
|
---|
48 | public void close() throws IOException {
|
---|
49 | if (_contents == null)
|
---|
50 | super.close();
|
---|
51 | }
|
---|
52 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.