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.

Direction.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.traits;
  19. import java.io.ObjectStreamException;
  20. import org.apache.fop.fo.Constants;
  21. /**
  22. * Enumeration class for direction traits, namely {inline,block}-progression-direction
  23. * and shift-direction.
  24. */
  25. public final class Direction extends TraitEnum {
  26. private static final long serialVersionUID = 1L;
  27. private static final String[] DIRECTION_NAMES = new String[]
  28. {"lr", "rl", "tb", "bt"};
  29. private static final int[] DIRECTION_VALUES = new int[]
  30. {Constants.EN_LR, Constants.EN_RL, Constants.EN_TB, Constants.EN_BT};
  31. /** direction: left-to-right */
  32. public static final Direction LR = new Direction(0);
  33. /** direction: right-to-left */
  34. public static final Direction RL = new Direction(1);
  35. /** direction: top-to-bottom */
  36. public static final Direction TB = new Direction(2);
  37. /** direction: bottom-to-top */
  38. public static final Direction BT = new Direction(3);
  39. private static final Direction[] DIRECTIONS = new Direction[] {LR, RL, TB, BT};
  40. private Direction(int index) {
  41. super(DIRECTION_NAMES[index], DIRECTION_VALUES[index]);
  42. }
  43. /**
  44. * Determine if direction is vertical or not.
  45. * @return true if vertical
  46. */
  47. public boolean isVertical() {
  48. return (getEnumValue() == Constants.EN_TB) || (getEnumValue() == Constants.EN_BT);
  49. }
  50. /**
  51. * Determine if direction is horizontal or not.
  52. * @return true if horizontal
  53. */
  54. public boolean isHorizontal() {
  55. return (getEnumValue() == Constants.EN_LR) || (getEnumValue() == Constants.EN_RL);
  56. }
  57. /**
  58. * Returns the enumeration/singleton object based on its name.
  59. * @param name the name of the enumeration value
  60. * @return the enumeration object
  61. */
  62. public static Direction valueOf(String name) {
  63. for (Direction direction : DIRECTIONS) {
  64. if (direction.getName().equalsIgnoreCase(name)) {
  65. return direction;
  66. }
  67. }
  68. throw new IllegalArgumentException("Illegal direction: " + name);
  69. }
  70. /**
  71. * Returns the enumeration/singleton object based on its name.
  72. * @param enumValue the enumeration value
  73. * @return the enumeration object
  74. */
  75. public static Direction valueOf(int enumValue) {
  76. for (Direction direction : DIRECTIONS) {
  77. if (direction.getEnumValue() == enumValue) {
  78. return direction;
  79. }
  80. }
  81. throw new IllegalArgumentException("Illegal direction: " + enumValue);
  82. }
  83. private Object readResolve() throws ObjectStreamException {
  84. return valueOf(getName());
  85. }
  86. /** {@inheritDoc} */
  87. public String toString() {
  88. return getName();
  89. }
  90. }