commit - 0e73655202a58ddf97347184c6e94980a8031fa8
commit + 3afd356009ef29d454cc6e146ff38ec5ae73885b
blob - /dev/null
blob + e9c5d6b7289a1abf3d6d8d8e3a5950b7d6e94ac9 (mode 644)
--- /dev/null
+++ de/mud/jta/plugin/Sink.java
+/*
+ * This file is part of "The Java Telnet Application".
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * "The Java Telnet Application" is distributed in the hope that it will be
+ * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this software; see the file COPYING. If not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+package de.mud.jta.plugin;
+
+import de.mud.jta.Plugin;
+import de.mud.jta.PluginConfig;
+import de.mud.jta.FilterPlugin;
+import de.mud.jta.VisualTransferPlugin;
+import de.mud.jta.PluginBus;
+
+import de.mud.jta.event.ConfigurationListener;
+import de.mud.jta.event.OnlineStatusListener;
+import de.mud.jta.event.TerminalTypeListener;
+import de.mud.jta.event.WindowSizeListener;
+import de.mud.jta.event.LocalEchoListener;
+import de.mud.jta.event.FocusStatus;
+import de.mud.jta.event.ReturnFocusListener;
+import de.mud.jta.event.AppletListener;
+import de.mud.jta.event.SoundRequest;
+import de.mud.jta.event.TelnetCommandRequest;
+
+import java.awt.Component;
+import java.awt.Panel;
+import java.awt.BorderLayout;
+import java.awt.Menu;
+import java.awt.MenuItem;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.Color;
+import java.awt.Scrollbar;
+import java.awt.Cursor;
+
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+import java.awt.event.FocusListener;
+import java.awt.event.FocusEvent;
+
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.StringSelection;
+import java.awt.datatransfer.ClipboardOwner;
+import java.awt.datatransfer.Transferable;
+import java.awt.datatransfer.DataFlavor;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import java.net.URL;
+import java.net.MalformedURLException;
+
+import java.util.Properties;
+import java.util.Hashtable;
+import java.util.Enumeration;
+
+/**
+ * The terminal plugin represents the actual terminal where the
+ * data will be displayed and the gets the keyboard input to sent
+ * back to the remote host.
+ * <P>
+ * <B>Maintainer:</B> Matthias L. Jugel
+ *
+ * @version $Id$
+ * @author Matthias L. Jugel, Marcus Meißner
+ */
+public class Sink extends Plugin
+ implements FilterPlugin, Runnable {
+
+ private final static int debug = 0;
+
+ private Thread reader = null;
+
+ public Sink(final PluginBus bus, final String id) {
+ super(bus, id);
+ // register an online status listener
+ bus.registerPluginListener(new OnlineStatusListener() {
+ public void online() {
+ if(debug > 0) System.err.println("Terminal: online "+reader);
+ if(reader == null) {
+ reader = new Thread();
+ reader.start();
+ }
+ }
+
+ public void offline() {
+ if(debug > 0) System.err.println("Terminal: offline");
+ if(reader != null)
+ reader = null;
+ }
+ });
+ }
+
+ /**
+ * Continuously read from our back end and display the data on screen.
+ */
+ public void run() {
+ byte[] t, b = new byte[256];
+ int n = 0;
+ while(n >= 0) try {
+ n = read(b);
+ /* drop the bytes into the sink :) */
+ } catch(IOException e) {
+ reader = null;
+ break;
+ }
+ }
+
+ protected FilterPlugin source;
+
+ public void setFilterSource(FilterPlugin source) {
+ if(debug > 0) System.err.println("Terminal: connected to: "+source);
+ this.source = source;
+ }
+
+ public int read(byte[] b) throws IOException {
+ return source.read(b);
+ }
+
+ public void write(byte[] b) throws IOException {
+ source.write(b);
+ }
+}