source: trunk/src/org/expeditee/io/ProxyWriter.java@ 1102

Last change on this file since 1102 was 1102, checked in by davidb, 6 years ago

Reworking of the code-base to separate logic from graphics. This version of Expeditee now supports a JFX graphics as an alternative to SWING

File size: 1.8 KB
Line 
1/**
2 * ProxyWriter.java
3 * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package org.expeditee.io;
20
21import java.io.BufferedWriter;
22import java.io.IOException;
23import java.io.PipedWriter;
24import java.io.Writer;
25
26import org.expeditee.gio.ClipboardManager.ClipboardData;
27import org.expeditee.gio.EcosystemManager;
28
29public class ProxyWriter extends BufferedWriter {
30
31 private StringBuffer _contents = null;
32
33 public ProxyWriter(Writer out) {
34 super(out);
35 }
36
37 public ProxyWriter(Writer out, int sz) {
38 super(out, sz);
39 }
40
41 public ProxyWriter(boolean useClipboard) {
42 // create a writer that does nothing
43 super(new PipedWriter());
44 _contents = new StringBuffer("");
45 }
46
47 @Override
48 public void write(String s) throws IOException {
49 if (_contents != null) {
50 _contents.append(s);
51 } else
52 super.write(s);
53 }
54
55 @Override
56 public void flush() throws IOException {
57 if (_contents != null) {
58 EcosystemManager.getClipboardManager().set(ClipboardData.fromString(_contents.toString()));
59 } else {
60 super.flush();
61 }
62 }
63
64 @Override
65 public void close() throws IOException {
66 if (_contents == null)
67 super.close();
68 }
69}
Note: See TracBrowser for help on using the repository browser.