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

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