import java.util.Collections;
import java.util.HashMap;
import java.util.List;
-import java.util.LinkedList;
import jexer.TImage;
import jexer.bits.Cell;
import jexer.bits.CellAttributes;
import jexer.bits.Color;
+import jexer.event.TCommandEvent;
import jexer.event.TInputEvent;
import jexer.event.TKeypressEvent;
import jexer.event.TMouseEvent;
import jexer.event.TResizeEvent;
+import static jexer.TCommand.*;
import static jexer.TKeypress.*;
/**
* 1024.
*/
private static final int MAX_COLOR_REGISTERS = 1024;
+ // Black-and-white is possible too.
+ // private static final int MAX_COLOR_REGISTERS = 2;
// ------------------------------------------------------------------------
// Variables --------------------------------------------------------------
int green = (color >>> 8) & 0xFF;
int blue = color & 0xFF;
+ if (MAX_COLOR_REGISTERS == 2) {
+ if (((red * red) + (green * green) + (blue * blue)) < 35568) {
+ // Black
+ return 0;
+ }
+ // White
+ return 1;
+ }
+
+
rgbToHsl(red, green, blue, hsl);
int hue = hsl[0];
int sat = hsl[1];
// map the BufferedImage colors to their nearest neighbor in RGB
// space.
+ if (MAX_COLOR_REGISTERS == 2) {
+ rgbColors.add(0);
+ rgbColors.add(0xFFFFFF);
+ rgbSortedIndex[0] = 0;
+ rgbSortedIndex[1] = 1;
+ return;
+ }
+
// We build a palette using the Hue-Saturation-Luminence model,
// with 5+ bits for Hue, 2+ bits for Saturation, and 1+ bit for
// Luminance. We convert these colors to 24-bit RGB, sort them
reloadOptions();
// Spin up the input reader
- eventQueue = new LinkedList<TInputEvent>();
+ eventQueue = new ArrayList<TInputEvent>();
readerThread = new Thread(this);
readerThread.start();
reloadOptions();
// Spin up the input reader
- eventQueue = new LinkedList<TInputEvent>();
+ eventQueue = new ArrayList<TInputEvent>();
readerThread = new Thread(this);
readerThread.start();
// available() will often return > 1, so we need to read in chunks to
// stay caught up.
char [] readBuffer = new char[128];
- List<TInputEvent> events = new LinkedList<TInputEvent>();
+ List<TInputEvent> events = new ArrayList<TInputEvent>();
while (!done && !stopReaderThread) {
try {
events.clear();
}
+ if (output.checkError()) {
+ // This is EOF.
+ done = true;
+ }
+
// Wait 20 millis for more data
Thread.sleep(20);
}
done = true;
}
} // while ((done == false) && (stopReaderThread == false))
+
+ // Pass an event up to TApplication to tell it this Backend is done.
+ synchronized (eventQueue) {
+ eventQueue.add(new TCommandEvent(cmBackendDisconnect));
+ }
+ if (listener != null) {
+ synchronized (listener) {
+ listener.notifyAll();
+ }
+ }
+
// System.err.println("*** run() exiting..."); System.err.flush();
}