Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

Driver.java 1.6 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * libcaca Java bindings for libcaca
  3. * Copyright (c) 2009 Adrien Grand <jpountz@dinauz.org>
  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://sam.zoy.org/wtfpl/COPYING for more details.
  10. */
  11. import org.zoy.caca.Canvas;
  12. import org.zoy.caca.Color;
  13. import org.zoy.caca.Display;
  14. import org.zoy.caca.Event;
  15. import org.zoy.caca.TimeoutException;
  16. public class Driver {
  17. public static void main(String[] args) {
  18. Canvas cv = new Canvas(32, 16);
  19. Display dp = new Display(cv);
  20. cv.setColor(Color.Ansi.WHITE, Color.Ansi.BLACK);
  21. Display.Driver driver;
  22. int i, cur = 0;
  23. while(true) {
  24. cv.put(1, 0, "Available drivers");
  25. driver = dp.getDriver();
  26. Display.Driver[] list = Display.getDriverList();
  27. for (i = 0; i < list.length; i++) {
  28. if (driver.equals(list[i])) {
  29. cur = i;
  30. }
  31. cv.drawLine(0, 2*i+2, 9999, 2*i+2, ' ');
  32. cv.put(2, 2*i+2, (cur == i ? "* " : " ") + list[i].getCode() + " " + list[i].getDescription());
  33. }
  34. cv.put(1, 2*i + 2, "Switching driver in 5 seconds");
  35. dp.refresh();
  36. try {
  37. dp.getEvent(Event.Type.KEY_PRESS, 5000000);
  38. break;
  39. } catch(TimeoutException e) {
  40. // Let's continue
  41. }
  42. cur++;
  43. if (list[cur].getCode().equals("raw")) cur++;
  44. if (cur >= list.length) cur = 0;
  45. dp.setDriver(list[cur]);
  46. }
  47. }
  48. }