Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

AlignmentInfo.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * 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, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.shared.ui;
  17. import java.io.Serializable;
  18. public final class AlignmentInfo implements Serializable {
  19. /** Bitmask values for client server communication */
  20. public static class Bits implements Serializable {
  21. public static final int ALIGNMENT_LEFT = 1;
  22. public static final int ALIGNMENT_RIGHT = 2;
  23. public static final int ALIGNMENT_TOP = 4;
  24. public static final int ALIGNMENT_BOTTOM = 8;
  25. public static final int ALIGNMENT_HORIZONTAL_CENTER = 16;
  26. public static final int ALIGNMENT_VERTICAL_CENTER = 32;
  27. }
  28. public static final AlignmentInfo LEFT = new AlignmentInfo(
  29. Bits.ALIGNMENT_LEFT);
  30. public static final AlignmentInfo RIGHT = new AlignmentInfo(
  31. Bits.ALIGNMENT_RIGHT);
  32. public static final AlignmentInfo TOP = new AlignmentInfo(
  33. Bits.ALIGNMENT_TOP);
  34. public static final AlignmentInfo BOTTOM = new AlignmentInfo(
  35. Bits.ALIGNMENT_BOTTOM);
  36. public static final AlignmentInfo CENTER = new AlignmentInfo(
  37. Bits.ALIGNMENT_HORIZONTAL_CENTER);
  38. public static final AlignmentInfo MIDDLE = new AlignmentInfo(
  39. Bits.ALIGNMENT_VERTICAL_CENTER);
  40. public static final AlignmentInfo TOP_LEFT = new AlignmentInfo(
  41. Bits.ALIGNMENT_TOP + Bits.ALIGNMENT_LEFT);
  42. private final int bitMask;
  43. public AlignmentInfo(int bitMask) {
  44. this.bitMask = bitMask;
  45. }
  46. public AlignmentInfo(AlignmentInfo horizontal, AlignmentInfo vertical) {
  47. this(horizontal.getBitMask() + vertical.getBitMask());
  48. }
  49. public int getBitMask() {
  50. return bitMask;
  51. }
  52. public boolean isTop() {
  53. return (bitMask & Bits.ALIGNMENT_TOP) == Bits.ALIGNMENT_TOP;
  54. }
  55. public boolean isBottom() {
  56. return (bitMask & Bits.ALIGNMENT_BOTTOM) == Bits.ALIGNMENT_BOTTOM;
  57. }
  58. public boolean isLeft() {
  59. return (bitMask & Bits.ALIGNMENT_LEFT) == Bits.ALIGNMENT_LEFT;
  60. }
  61. public boolean isRight() {
  62. return (bitMask & Bits.ALIGNMENT_RIGHT) == Bits.ALIGNMENT_RIGHT;
  63. }
  64. public boolean isVerticalCenter() {
  65. return (bitMask
  66. & Bits.ALIGNMENT_VERTICAL_CENTER) == Bits.ALIGNMENT_VERTICAL_CENTER;
  67. }
  68. public boolean isHorizontalCenter() {
  69. return (bitMask
  70. & Bits.ALIGNMENT_HORIZONTAL_CENTER) == Bits.ALIGNMENT_HORIZONTAL_CENTER;
  71. }
  72. public String getVerticalAlignment() {
  73. if (isBottom()) {
  74. return "bottom";
  75. } else if (isVerticalCenter()) {
  76. return "middle";
  77. }
  78. return "top";
  79. }
  80. public String getHorizontalAlignment() {
  81. if (isRight()) {
  82. return "right";
  83. } else if (isHorizontalCenter()) {
  84. return "center";
  85. }
  86. return "left";
  87. }
  88. }