Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

83 wiersze
2.3 KiB

  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. package org.zoy.caca;
  12. public abstract class Color {
  13. public static enum Ansi {
  14. BLACK((byte)0x00),
  15. BLUE((byte)0x01),
  16. GREEN((byte)0x02),
  17. CYAN((byte)0x03),
  18. RED((byte)0x04),
  19. MAGENTA((byte)0x05),
  20. BROWN((byte)0x06),
  21. LIGHTGREY((byte)0x07),
  22. DARKGREY((byte)0x08),
  23. LIGHTBLUE((byte)0x09),
  24. LIGHTGREEN((byte)0x0a),
  25. LIGHTCYAN((byte)0x0b),
  26. LIGHTRED((byte)0x0c),
  27. LIGHTMAGENTA((byte)0x0d),
  28. YELLOW((byte)0x0e),
  29. WHITE((byte)0x0f),
  30. DEFAULT((byte)0x10),
  31. TRANSPARENT((byte)0x20);
  32. private Ansi(byte code) {
  33. this.code = code;
  34. }
  35. protected byte code;
  36. public static Ansi forCode(byte code) {
  37. Ansi[] values = Ansi.values();
  38. for (Ansi color : values) {
  39. if (color.code == code) {
  40. return color;
  41. }
  42. }
  43. return null;
  44. }
  45. }
  46. // Use ints mostly because it is more convenient (no need to cast)
  47. public static class Argb {
  48. public Argb(int code) {
  49. if (code < 0 || code > Short.MAX_VALUE - Short.MIN_VALUE) {
  50. throw new IllegalArgumentException("Code should be a 16-bit unsigned integer");
  51. }
  52. this.code = (short)code;
  53. }
  54. public Argb(int alpha, int red, int green, int blue) {
  55. if (alpha < 0 || alpha >15) {
  56. throw new IllegalArgumentException("alpha should be a 4-bit unsigned integer");
  57. }
  58. if (red < 0 || red >15) {
  59. throw new IllegalArgumentException("red should be a 4-bit unsigned integer");
  60. }
  61. if (green < 0 || green >15) {
  62. throw new IllegalArgumentException("green should be a 4-bit unsigned integer");
  63. }
  64. if (blue < 0 || blue >15) {
  65. throw new IllegalArgumentException("blue should be a 4-bit unsigned integer");
  66. }
  67. this.code = (short)((alpha << 16) + (red << 8) + (green << 4) + blue);
  68. }
  69. public short getCode() {
  70. return code;
  71. }
  72. protected short code;
  73. }
  74. }