You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Colour.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Copyright (c) 2006-2017 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  5. * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
  6. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
  7. * permit persons to whom the Software is furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
  10. * Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  13. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  14. * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  15. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. */
  17. package com.dmdirc.util.colours;
  18. /**
  19. * A colour represented by an RGB triple. This implementation is immutable.
  20. */
  21. public class Colour {
  22. /** The colour white. */
  23. public static final Colour WHITE = new Colour(255, 255, 255);
  24. /** The colour light gray. */
  25. public static final Colour LIGHT_GRAY = new Colour(192, 192, 192);
  26. /** The colour gray. */
  27. public static final Colour GRAY = new Colour(128, 128, 128);
  28. /** The colour dark gray. */
  29. public static final Colour DARK_GRAY = new Colour(64, 64, 64);
  30. /** The colour black. */
  31. public static final Colour BLACK = new Colour(0, 0, 0);
  32. /** The colour red. */
  33. public static final Colour RED = new Colour(255, 0, 0);
  34. /** The colour pink. */
  35. public static final Colour PINK = new Colour(255, 175, 175);
  36. /** The colour orange. */
  37. public static final Colour ORANGE = new Colour(255, 200, 0);
  38. /** The colour yellow. */
  39. public static final Colour YELLOW = new Colour(255, 255, 0);
  40. /** The colour green. */
  41. public static final Colour GREEN = new Colour(0, 255, 0);
  42. /** The colour magenta. */
  43. public static final Colour MAGENTA = new Colour(255, 0, 255);
  44. /** The colour cyan. */
  45. public static final Colour CYAN = new Colour(0, 255, 255);
  46. /** The colour blue. */
  47. public static final Colour BLUE = new Colour(0, 0, 255);
  48. /** The intensity of the red component of this colour (0-255). */
  49. private final int red;
  50. /** The intensity of the green component of this colour (0-255). */
  51. private final int green;
  52. /** The intensity of the blue component of this colour (0-255). */
  53. private final int blue;
  54. /**
  55. * Creates a new Colour instance with the given RGB values.
  56. *
  57. * @param red The intensity of the red component of the colour (0-255).
  58. * @param green The intensity of the green component of the colour (0-255).
  59. * @param blue The intensity of the blue component of the colour (0-255).
  60. */
  61. public Colour(final int red, final int green, final int blue) {
  62. this.red = red;
  63. this.green = green;
  64. this.blue = blue;
  65. }
  66. /**
  67. * Gets the intensity of the blue component of this colour.
  68. *
  69. * @return The intensity on a scale of 0-255.
  70. */
  71. public int getBlue() {
  72. return blue;
  73. }
  74. /**
  75. * Gets the intensity of the green component of this colour.
  76. *
  77. * @return The intensity on a scale of 0-255.
  78. */
  79. public int getGreen() {
  80. return green;
  81. }
  82. /**
  83. * Gets the intensity of the red component of this colour.
  84. *
  85. * @return The intensity on a scale of 0-255.
  86. */
  87. public int getRed() {
  88. return red;
  89. }
  90. @Override
  91. public boolean equals(final Object obj) {
  92. if (obj == null || getClass() != obj.getClass()) {
  93. return false;
  94. }
  95. final Colour other = (Colour) obj;
  96. return red == other.getRed() && green == other.getGreen()
  97. && blue == other.getBlue();
  98. }
  99. @Override
  100. public int hashCode() {
  101. int hash = 7;
  102. hash = 37 * hash + red;
  103. hash = 37 * hash + green;
  104. hash = 37 * hash + blue;
  105. return hash;
  106. }
  107. }