1. /*
  2. * Copyright 2002,2004 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. */
  17. package org.apache.tools.ant.types.optional.image;
  18. import java.awt.Color;
  19. /**
  20. *
  21. * @see org.apache.tools.ant.taskdefs.optional.image.Image
  22. */
  23. public final class ColorMapper {
  24. public static final String COLOR_BLACK = "black";
  25. public static final String COLOR_BLUE = "blue";
  26. public static final String COLOR_CYAN = "cyan";
  27. public static final String COLOR_DARKGRAY = "darkgray";
  28. public static final String COLOR_GRAY = "gray";
  29. public static final String COLOR_LIGHTGRAY = "lightgray";
  30. // Gotta atleast put in the proper spelling :-P
  31. public static final String COLOR_DARKGREY = "darkgrey";
  32. public static final String COLOR_GREY = "grey";
  33. public static final String COLOR_LIGHTGREY = "lightgrey";
  34. public static final String COLOR_GREEN = "green";
  35. public static final String COLOR_MAGENTA = "magenta";
  36. public static final String COLOR_ORANGE = "orange";
  37. public static final String COLOR_PINK = "pink";
  38. public static final String COLOR_RED = "red";
  39. public static final String COLOR_WHITE = "white";
  40. public static final String COLOR_YELLOW = "yellow";
  41. /**
  42. * @todo refactor to use an EnumeratedAttribute (maybe?)
  43. */
  44. public static final Color getColorByName(String color_name) {
  45. color_name = color_name.toLowerCase();
  46. if (color_name.equals(COLOR_BLACK)) {
  47. return Color.black;
  48. } else if (color_name.equals(COLOR_BLUE)) {
  49. return Color.blue;
  50. } else if (color_name.equals(COLOR_CYAN)) {
  51. return Color.cyan;
  52. } else if (color_name.equals(COLOR_DARKGRAY) || color_name.equals(COLOR_DARKGREY)) {
  53. return Color.darkGray;
  54. } else if (color_name.equals(COLOR_GRAY) || color_name.equals(COLOR_GREY)) {
  55. return Color.gray;
  56. } else if (color_name.equals(COLOR_LIGHTGRAY) || color_name.equals(COLOR_LIGHTGREY)) {
  57. return Color.lightGray;
  58. } else if (color_name.equals(COLOR_GREEN)) {
  59. return Color.green;
  60. } else if (color_name.equals(COLOR_MAGENTA)) {
  61. return Color.magenta;
  62. } else if (color_name.equals(COLOR_ORANGE)) {
  63. return Color.orange;
  64. } else if (color_name.equals(COLOR_PINK)) {
  65. return Color.pink;
  66. } else if (color_name.equals(COLOR_RED)) {
  67. return Color.red;
  68. } else if (color_name.equals(COLOR_WHITE)) {
  69. return Color.white;
  70. } else if (color_name.equals(COLOR_YELLOW)) {
  71. return Color.yellow;
  72. }
  73. return Color.black;
  74. }
  75. }