1 43 44 package org.jfree.ui; 45 46 import java.awt.geom.Rectangle2D ; 47 48 53 public final class Align { 54 55 56 public static final int CENTER = 0x00; 57 58 59 public static final int TOP = 0x01; 60 61 62 public static final int BOTTOM = 0x02; 63 64 65 public static final int LEFT = 0x04; 66 67 68 public static final int RIGHT = 0x08; 69 70 71 public static final int TOP_LEFT = TOP | LEFT; 72 73 74 public static final int TOP_RIGHT = TOP | RIGHT; 75 76 77 public static final int BOTTOM_LEFT = BOTTOM | LEFT; 78 79 80 public static final int BOTTOM_RIGHT = BOTTOM | RIGHT; 81 82 83 public static final int FIT_HORIZONTAL = LEFT | RIGHT; 84 85 86 public static final int FIT_VERTICAL = TOP | BOTTOM; 87 88 89 public static final int FIT = FIT_HORIZONTAL | FIT_VERTICAL; 90 91 92 public static final int NORTH = TOP; 93 94 95 public static final int SOUTH = BOTTOM; 96 97 98 public static final int WEST = LEFT; 99 100 101 public static final int EAST = RIGHT; 102 103 104 public static final int NORTH_WEST = NORTH | WEST; 105 106 107 public static final int NORTH_EAST = NORTH | EAST; 108 109 110 public static final int SOUTH_WEST = SOUTH | WEST; 111 112 113 public static final int SOUTH_EAST = SOUTH | EAST; 114 115 118 private Align() { 119 super(); 120 } 121 122 129 public static void align(final Rectangle2D rect, final Rectangle2D frame, final int align) { 130 131 double x = frame.getCenterX() - rect.getWidth() / 2.0; 132 double y = frame.getCenterY() - rect.getHeight() / 2.0; 133 double w = rect.getWidth(); 134 double h = rect.getHeight(); 135 136 if ((align & FIT_VERTICAL) == FIT_VERTICAL) { 137 h = frame.getHeight(); 138 } 139 140 if ((align & FIT_HORIZONTAL) == FIT_HORIZONTAL) { 141 w = frame.getWidth(); 142 } 143 144 if ((align & TOP) == TOP) { 145 y = frame.getMinY(); 146 } 147 148 if ((align & BOTTOM) == BOTTOM) { 149 y = frame.getMaxY() - h; 150 } 151 152 if ((align & LEFT) == LEFT) { 153 x = frame.getX(); 154 } 155 156 if ((align & RIGHT) == RIGHT) { 157 x = frame.getMaxX() - w; 158 } 159 160 rect.setRect(x, y, w, h); 161 162 } 163 164 } 165 | Popular Tags |