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.

AlignmentInfo.java 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.shared.ui;
  5. public final class AlignmentInfo {
  6. /** Bitmask values for client server communication */
  7. public static class Bits {
  8. public static final int ALIGNMENT_LEFT = 1;
  9. public static final int ALIGNMENT_RIGHT = 2;
  10. public static final int ALIGNMENT_TOP = 4;
  11. public static final int ALIGNMENT_BOTTOM = 8;
  12. public static final int ALIGNMENT_HORIZONTAL_CENTER = 16;
  13. public static final int ALIGNMENT_VERTICAL_CENTER = 32;
  14. }
  15. public static final AlignmentInfo LEFT = new AlignmentInfo(
  16. Bits.ALIGNMENT_LEFT);
  17. public static final AlignmentInfo RIGHT = new AlignmentInfo(
  18. Bits.ALIGNMENT_RIGHT);
  19. public static final AlignmentInfo TOP = new AlignmentInfo(
  20. Bits.ALIGNMENT_TOP);
  21. public static final AlignmentInfo BOTTOM = new AlignmentInfo(
  22. Bits.ALIGNMENT_BOTTOM);
  23. public static final AlignmentInfo CENTER = new AlignmentInfo(
  24. Bits.ALIGNMENT_HORIZONTAL_CENTER);
  25. public static final AlignmentInfo MIDDLE = new AlignmentInfo(
  26. Bits.ALIGNMENT_VERTICAL_CENTER);
  27. public static final AlignmentInfo TOP_LEFT = new AlignmentInfo(
  28. Bits.ALIGNMENT_TOP + Bits.ALIGNMENT_LEFT);
  29. private final int bitMask;
  30. public AlignmentInfo(int bitMask) {
  31. this.bitMask = bitMask;
  32. }
  33. public AlignmentInfo(AlignmentInfo horizontal, AlignmentInfo vertical) {
  34. this(horizontal.getBitMask() + vertical.getBitMask());
  35. }
  36. public int getBitMask() {
  37. return bitMask;
  38. }
  39. public boolean isTop() {
  40. return (bitMask & Bits.ALIGNMENT_TOP) == Bits.ALIGNMENT_TOP;
  41. }
  42. public boolean isBottom() {
  43. return (bitMask & Bits.ALIGNMENT_BOTTOM) == Bits.ALIGNMENT_BOTTOM;
  44. }
  45. public boolean isLeft() {
  46. return (bitMask & Bits.ALIGNMENT_LEFT) == Bits.ALIGNMENT_LEFT;
  47. }
  48. public boolean isRight() {
  49. return (bitMask & Bits.ALIGNMENT_RIGHT) == Bits.ALIGNMENT_RIGHT;
  50. }
  51. public boolean isVerticalCenter() {
  52. return (bitMask & Bits.ALIGNMENT_VERTICAL_CENTER) == Bits.ALIGNMENT_VERTICAL_CENTER;
  53. }
  54. public boolean isHorizontalCenter() {
  55. return (bitMask & Bits.ALIGNMENT_HORIZONTAL_CENTER) == Bits.ALIGNMENT_HORIZONTAL_CENTER;
  56. }
  57. public String getVerticalAlignment() {
  58. if (isBottom()) {
  59. return "bottom";
  60. } else if (isVerticalCenter()) {
  61. return "middle";
  62. }
  63. return "top";
  64. }
  65. public String getHorizontalAlignment() {
  66. if (isRight()) {
  67. return "right";
  68. } else if (isHorizontalCenter()) {
  69. return "center";
  70. }
  71. return "left";
  72. }
  73. }