Author: koen.aers(a)jboss.com
Date: 2011-02-07 11:43:18 -0500 (Mon, 07 Feb 2011)
New Revision: 29055
Removed:
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/temp/
Modified:
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/ConsoleInputStream.java
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/InputReadJob.java
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/view/ConsoleViewer.java
Log:
unbuffered input is working
Modified:
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/ConsoleInputStream.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/ConsoleInputStream.java 2011-02-07
16:22:09 UTC (rev 29054)
+++
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/ConsoleInputStream.java 2011-02-07
16:43:18 UTC (rev 29055)
@@ -5,115 +5,27 @@
import java.io.UnsupportedEncodingException;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.ui.console.IConsoleConstants;
-/**
- * InputStream used to read input from an {@link Console}.
- * This stream will buffer input that it receives until it has been read.
- * An input stream is available from its {@link Console}.
- * @since 3.1
- * @noinstantiate This class is not intended to be instantiated by clients.
- * @noextend This class is not intended to be subclassed by clients.
- *
- */
-public class ConsoleInputStream extends InputStream implements KeyListener {
- /**
- * Buffer to hold data from console until it is read.
- */
+public class ConsoleInputStream extends InputStream {
+
private byte[] input = new byte[100];
-
- /**
- * Location in the buffer that the next byte of data from the
- * console should be stored.
- */
private int inPointer = 0;
-
- /**
- * Location in the buffer that the next byte of data read from
- * this stream should come from.
- */
private int outPointer = 0;
-
- /**
- * The number of bytes of real data currently in the buffer.
- */
private int size = 0;
-
- /**
- * Flag to indicate that EOF has been sent already.
- */
private boolean eofSent = false;
-
- /**
- * Flag to indicate that the stream has been closed.
- */
private boolean closed = false;
-
- /**
- * The console that this stream is connected to.
- */
private Console console;
-
- /**
- * The color used to display input in the console.
- */
private Color color;
-
- /**
- * The font style used to decorate input in the console.
- */
private int fontStyle = SWT.NORMAL;
+
+ private char c = (char)-1;
-
- /**
- * Constructs a new input stream on the given console.
- *
- * @param console I/O console
- */
ConsoleInputStream(Console console) {
this.console = console;
}
- /*
- * (non-Javadoc)
- * @see java.io.InputStream#read(byte[], int, int)
- */
- public synchronized int read(byte[] b, int off, int len) throws IOException {
- waitForData();
- if (available() == -1) {
- return -1;
- }
-
- int toCopy = Math.min(len, size);
- if(input.length-outPointer > toCopy) {
- System.arraycopy(input, outPointer, b, off, toCopy);
- outPointer += toCopy;
- size -= toCopy;
- } else {
- int bytesToEnd = input.length-outPointer;
- System.arraycopy(input, outPointer, b, off, bytesToEnd);
- System.arraycopy(input, 0, b, off+bytesToEnd, toCopy-bytesToEnd);
- outPointer = toCopy-bytesToEnd;
- size -=toCopy;
- }
- return toCopy;
- }
-
- /*
- * (non-Javadoc)
- * @see java.io.InputStream#read(byte[])
- */
- public int read(byte[] b) throws IOException {
- return read(b, 0, b.length);
- }
-
- /*
- * (non-Javadoc)
- * @see java.io.InputStream#read()
- */
public synchronized int read() throws IOException {
waitForData();
if (available() == -1) {
@@ -129,26 +41,15 @@
return b;
}
- /**
- * Blocks until data is available to be read.
- * Ensure that the monitor for this object is obtained before
- * calling this method.
- */
private void waitForData() {
while (size == 0 && !closed) {
+// while (c != -1 && !closed) {
try {
wait();
- } catch (InterruptedException e) {
- System.out.println("interrupted!");
- }
+ } catch (InterruptedException e) {}
}
}
-
- /**
- * Appends text to this input stream's buffer.
- *
- * @param text the text to append to the buffer.
- */
+
public synchronized void appendData(String text) {
String encoding = console.getEncoding();
byte[] newData;
@@ -187,9 +88,6 @@
notifyAll();
}
- /**
- * Enlarges the buffer.
- */
private void growArray() {
byte[] newInput = new byte[input.length+1024];
if (outPointer < inPointer) {
@@ -204,20 +102,10 @@
newInput = null;
}
- /**
- * Returns this stream's font style.
- *
- * @return the font style used to decorate input in the associated console
- */
public int getFontStyle() {
return fontStyle;
}
- /**
- * Sets this stream's font style.
- *
- * @param newFontStyle the font style to be used to decorate input in the associated
console
- */
public void setFontStyle(int newFontStyle) {
if (newFontStyle != fontStyle) {
int old = fontStyle;
@@ -226,11 +114,6 @@
}
}
- /**
- * Sets the color to used to decorate input in the associated console.
- *
- * @param newColor the color to used to decorate input in the associated console.
- */
public void setColor(Color newColor) {
Color old = color;
if (old == null || !old.equals(newColor)) {
@@ -239,18 +122,10 @@
}
}
- /**
- * Returns the color used to decorate input in the associated console
- *
- * @return the color used to decorate input in the associated console
- */
public Color getColor() {
return color;
}
- /* (non-Javadoc)
- * @see java.io.InputStream#available()
- */
public int available() throws IOException {
if (closed && eofSent) {
throw new IOException("Input Stream Closed"); //$NON-NLS-1$
@@ -265,9 +140,6 @@
return size;
}
- /* (non-Javadoc)
- * @see java.io.InputStream#close()
- */
public synchronized void close() throws IOException {
if(closed) {
throw new IOException("Input Stream Closed"); //$NON-NLS-1$
@@ -277,16 +149,4 @@
console.streamClosed(this);
}
- @Override
- public void keyPressed(KeyEvent e) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void keyReleased(KeyEvent e) {
- String data = new StringBuffer().append(e.character).toString();
- System.out.println("about to append data: " + data);
- appendData(data);
- }
}
Modified:
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/InputReadJob.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/InputReadJob.java 2011-02-07
16:22:09 UTC (rev 29054)
+++
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/InputReadJob.java 2011-02-07
16:43:18 UTC (rev 29055)
@@ -22,14 +22,12 @@
protected IStatus run(IProgressMonitor monitor) {
try {
- byte[] b = new byte[1024];
- int read = 0;
- while (input != null && read >= 0) {
- read = input.read(b);
- if (read > 0) {
- String s = new String(b, 0, read);
- streamsProxy.write(s);
- }
+ StringBuffer buffer = new StringBuffer();
+ int read;
+ while (input != null && (read = input.read()) != -1) {
+ buffer.append((char)read);
+ streamsProxy.write(buffer.toString());
+ buffer.setLength(0);
}
} catch (IOException e) {
Activator.log(e);
Modified:
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/view/ConsoleViewer.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/view/ConsoleViewer.java 2011-02-07
16:22:09 UTC (rev 29054)
+++
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/view/ConsoleViewer.java 2011-02-07
16:43:18 UTC (rev 29055)
@@ -1,115 +1,42 @@
package org.jboss.tools.seam.forge.view;
import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentListener;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.ui.console.ConsolePlugin;
+import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.console.TextConsoleViewer;
import org.jboss.tools.seam.forge.console.Console;
public class ConsoleViewer extends TextConsoleViewer {
- private boolean fAutoScroll = true;
private Console console = null;
- private IDocumentListener fDocumentListener;
-
public ConsoleViewer(Composite parent, Console console) {
super(parent, console);
this.console = console;
+ getDocument().addDocumentListener(new DocumentListener());
}
- public boolean isAutoScroll() {
- return fAutoScroll;
- }
-
- public void setAutoScroll(boolean scroll) {
- fAutoScroll = scroll;
- }
-
protected void handleVerifyEvent(VerifyEvent e) {
console.getInputStream().appendData(e.text);
e.doit = false;
-// IDocument doc = getDocument();
-// String[] legalLineDelimiters = doc.getLegalLineDelimiters();
-// String eventString = e.text;
-// try {
-// IConsoleDocumentPartitioner partitioner = (IConsoleDocumentPartitioner)
doc.getDocumentPartitioner();
-// if (!partitioner.isReadOnly(e.start)) {
-// boolean isCarriageReturn = false;
-// for (int i = 0; i < legalLineDelimiters.length; i++) {
-// if (e.text.equals(legalLineDelimiters[i])) {
-// isCarriageReturn = true;
-// break;
-// }
-// }
-//
-// if (!isCarriageReturn) {
-// super.handleVerifyEvent(e);
-// return;
-// }
-// }
-//
-// int length = doc.getLength();
-// if (e.start == length) {
-// super.handleVerifyEvent(e);
-// } else {
-// try {
-// doc.replace(length, 0, eventString);
-// } catch (BadLocationException e1) {
-// }
-// e.doit = false;
-// }
-// } finally {
-// StyledText text = (StyledText) e.widget;
-// text.setCaretOffset(text.getCharCount());
-// }
}
+
+ private class DocumentListener implements IDocumentListener {
+
+ public void documentAboutToBeChanged(DocumentEvent event) {
+ }
- public void setReadOnly() {
- ConsolePlugin.getStandardDisplay().asyncExec(new Runnable() {
- public void run() {
- StyledText text = getTextWidget();
- if (text != null && !text.isDisposed()) {
- text.setEditable(false);
- }
+ public void documentChanged(DocumentEvent event) {
+ revealEndOfDocument();
+ Control control = getControl();
+ if (control instanceof StyledText) {
+ StyledText text = (StyledText)control;
+ text.setCaretOffset(text.getCharCount());
}
- });
- }
-
- public boolean isReadOnly() {
- return !getTextWidget().getEditable();
- }
-
- public void setDocument(IDocument document) {
- IDocument oldDocument= getDocument();
-
- super.setDocument(document);
-
- if (oldDocument != null) {
- oldDocument.removeDocumentListener(getDocumentListener());
}
- if (document != null) {
- document.addDocumentListener(getDocumentListener());
- }
}
-
- private IDocumentListener getDocumentListener() {
- if (fDocumentListener == null) {
- fDocumentListener= new IDocumentListener() {
- public void documentAboutToBeChanged(DocumentEvent event) {
- }
-
- public void documentChanged(DocumentEvent event) {
- if (fAutoScroll) {
- revealEndOfDocument();
- }
- }
- };
- }
- return fDocumentListener;
- }
+
}