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.

AFPFontColor.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * Copyright 2006 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.render.afp;
  18. import java.awt.Color;
  19. import org.apache.fop.datatypes.ColorType;
  20. /**
  21. * AFP only supports very basic colours and this object provides a simple
  22. * bean for the colour attributes.
  23. *
  24. */
  25. public class AFPFontColor {
  26. /**
  27. * Red value.
  28. */
  29. private int _red = 0;
  30. /**
  31. * Green value.
  32. */
  33. private int _green = 0;
  34. /**
  35. * Blue value.
  36. */
  37. private int _blue = 0;
  38. /**
  39. * Constructor for the AFPColor Object
  40. * @param red The red color intensity (0-255)
  41. * @param green The green color intensity (0-255)
  42. * @param blue The blue color intensity (0-255)
  43. */
  44. public AFPFontColor(int red, int green, int blue) {
  45. _red = red;
  46. _green = green;
  47. _blue = blue;
  48. }
  49. /**
  50. * Constructor for the AFPColor Object
  51. * @param col the org.apache.fop.datatypes.ColorType object
  52. */
  53. public AFPFontColor(ColorType col) {
  54. _red = (int)(col.getRed() * 255);
  55. _green = (int)(col.getGreen() * 255);
  56. _blue = (int)(col.getBlue() * 255);
  57. }
  58. /**
  59. * Constructor for the AFPColor Object
  60. * @param col The java.awt.Color object
  61. */
  62. public AFPFontColor(Color col) {
  63. _red = col.getRed();
  64. _green = col.getGreen();
  65. _blue = col.getBlue();
  66. }
  67. /**
  68. * Returns the blue attribute
  69. * @return int
  70. */
  71. public int getBlue() {
  72. return _blue;
  73. }
  74. /**
  75. * Returns the green attribute
  76. * @return int
  77. */
  78. public int getGreen() {
  79. return _green;
  80. }
  81. /**
  82. * Returns the red attribute
  83. * @return int
  84. */
  85. public int getRed() {
  86. return _red;
  87. }
  88. /**
  89. * Sets the blue attribute
  90. * @param blue The blue value to set
  91. */
  92. public void setBlue(int blue) {
  93. _blue = blue;
  94. }
  95. /**
  96. * Sets the green attribute
  97. * @param green The green value to set
  98. */
  99. public void setGreen(int green) {
  100. _green = green;
  101. }
  102. /**
  103. * Sets the red attribute
  104. * @param red The red value to set
  105. */
  106. public void setRed(int red) {
  107. _red = red;
  108. }
  109. /**
  110. * Sets this color object to the same values
  111. * as the given object.
  112. * @param col the source color
  113. */
  114. public void setTo(AFPFontColor col) {
  115. _red = col.getRed();
  116. _green = col.getGreen();
  117. _blue = col.getBlue();
  118. }
  119. /**
  120. * Checks whether this object is equal to the parameter passed
  121. * as an argument. If the parameter is an instance of AFPColor
  122. * then the value are compared, otherwise the generalized equals
  123. * method is invoked on the parent class.
  124. *
  125. * @param obj the object to compare
  126. * @return boolean true if the object is equal
  127. */
  128. public boolean equals(Object obj) {
  129. if (obj instanceof AFPFontColor) {
  130. AFPFontColor c = (AFPFontColor) obj;
  131. if (c.getRed() == _red
  132. && c.getGreen() == _green
  133. && c.getBlue() == _blue) {
  134. return true;
  135. } else {
  136. return false;
  137. }
  138. } else {
  139. return super.equals(obj);
  140. }
  141. }
  142. }