| 1 |
/** |
| 2 |
* libcaca Java bindings for libcaca |
| 3 |
* Copyright (c) 2009 Adrien Grand <[email protected]> |
| 4 |
* |
| 5 |
* This library is free software. It comes without any warranty, to |
| 6 |
* the extent permitted by applicable law. You can redistribute it |
| 7 |
* and/or modify it under the terms of the Do What the Fuck You Want |
| 8 |
* to Public License, Version 2, as published by Sam Hocevar. See |
| 9 |
* http://www.wtfpl.net/ for more details. |
| 10 |
*/ |
| 11 |
|
| 12 |
import org.zoy.caca.Canvas; |
| 13 |
import org.zoy.caca.Color; |
| 14 |
import org.zoy.caca.Display; |
| 15 |
import org.zoy.caca.Event; |
| 16 |
import org.zoy.caca.TimeoutException; |
| 17 |
|
| 18 |
public class Driver { |
| 19 |
|
| 20 |
public static void main(String[] args) { |
| 21 |
Canvas cv = new Canvas(32, 16); |
| 22 |
Display dp = new Display(cv); |
| 23 |
cv.setColor(Color.Ansi.WHITE, Color.Ansi.BLACK); |
| 24 |
Display.Driver driver; |
| 25 |
int i, cur = 0; |
| 26 |
while(true) { |
| 27 |
cv.put(1, 0, "Available drivers"); |
| 28 |
driver = dp.getDriver(); |
| 29 |
Display.Driver[] list = Display.getDriverList(); |
| 30 |
for (i = 0; i < list.length; i++) { |
| 31 |
if (driver.equals(list[i])) { |
| 32 |
cur = i; |
| 33 |
} |
| 34 |
cv.drawLine(0, 2*i+2, 9999, 2*i+2, ' '); |
| 35 |
cv.put(2, 2*i+2, (cur == i ? "* " : " ") + list[i].getCode() + " " + list[i].getDescription()); |
| 36 |
} |
| 37 |
cv.put(1, 2*i + 2, "Switching driver in 5 seconds"); |
| 38 |
dp.refresh(); |
| 39 |
try { |
| 40 |
dp.getEvent(Event.Type.KEY_PRESS, 5000000); |
| 41 |
break; |
| 42 |
} catch(TimeoutException e) { |
| 43 |
// Let's continue |
| 44 |
} |
| 45 |
cur++; |
| 46 |
if (list[cur].getCode().equals("raw")) cur++; |
| 47 |
if (cur >= list.length) cur = 0; |
| 48 |
dp.setDriver(list[cur]); |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
} |