| 127 | | List<CalEvent> overlappingEvents = calcOverlappingEventsFor(event); |
|---|
| 128 | | xPos = layoutEvent(event, overlappingEvents, xPos); |
|---|
| | 131 | List<CalEvent> overlappingEvents = calcOverlappingEventsFor(calEvent); |
|---|
| | 132 | |
|---|
| | 133 | Rectangle bounds = _view.getBounds(calEvent); |
|---|
| | 134 | int numOverlapping = overlappingEvents.size(); |
|---|
| | 135 | int width = bounds.width / numOverlapping; |
|---|
| | 136 | if (xPos + width > bounds.width) |
|---|
| | 137 | { |
|---|
| | 138 | // first, correct x position of previous event (align right to avoid overlap conflict |
|---|
| | 139 | // with next overlapping items) |
|---|
| | 140 | if (prevEvt != null && overlappingEvents.contains(prevEvt)) |
|---|
| | 141 | { |
|---|
| | 142 | Component prevComp = _components.get(prevEvt); |
|---|
| | 143 | Point location = prevComp.getLocation(); |
|---|
| | 144 | int x = bounds.x + bounds.width - (prevComp.getWidth() + event_padding/2); |
|---|
| | 145 | prevComp.setLocation(x, location.y); |
|---|
| | 146 | } |
|---|
| | 147 | |
|---|
| | 148 | // second, carriage-return logic |
|---|
| | 149 | xPos = 0; |
|---|
| | 150 | for (CalEvent e : overlappingEvents) |
|---|
| | 151 | { |
|---|
| | 152 | if (e == calEvent) break; |
|---|
| | 153 | Rectangle ebounds = _components.get(e).getBounds(); |
|---|
| | 154 | int pos = xPos + (event_padding / 2); |
|---|
| | 155 | if (ebounds.getX() - bounds.x == pos) |
|---|
| | 156 | { |
|---|
| | 157 | xPos += _components.get(e).getWidth() + event_padding; |
|---|
| | 158 | } |
|---|
| | 159 | } |
|---|
| | 160 | } |
|---|
| | 161 | |
|---|
| | 162 | Rectangle eventBounds = new Rectangle(bounds.x + xPos + event_padding/2, bounds.y, width - event_padding, bounds.height); |
|---|
| | 163 | _components.get(calEvent).setBounds(eventBounds); |
|---|
| | 164 | |
|---|
| | 165 | xPos += xPos + width; |
|---|
| | 166 | |
|---|
| | 167 | prevEvt = calEvent; |
|---|
| 133 | | static int event_padding = 4; |
|---|
| 134 | | |
|---|
| 135 | | /** |
|---|
| 136 | | * @param event event to layout |
|---|
| 137 | | * @param overlappingEvents list of overlapping events for event |
|---|
| 138 | | * @param xPos current x position |
|---|
| 139 | | * @return next xPos |
|---|
| 140 | | */ |
|---|
| 141 | | private int layoutEvent(CalEvent event, List<CalEvent> overlappingEvents, int xPos) |
|---|
| 142 | | { |
|---|
| 143 | | Component comp = _components.get(event); |
|---|
| 144 | | Rectangle bounds = _view.getBounds(event); |
|---|
| 145 | | int numOverlapping = overlappingEvents.size(); |
|---|
| 146 | | int width = bounds.width / numOverlapping; |
|---|
| 147 | | if (xPos + width > bounds.getWidth()) |
|---|
| 148 | | { |
|---|
| 149 | | xPos = 0; |
|---|
| 150 | | for (CalEvent e : overlappingEvents) |
|---|
| 151 | | { |
|---|
| 152 | | if (e == event) break; |
|---|
| 153 | | Rectangle ebounds = _components.get(e).getBounds(); |
|---|
| 154 | | int pos = xPos + (event_padding / 2); |
|---|
| 155 | | if (ebounds.getX() - bounds.x == pos) |
|---|
| 156 | | { |
|---|
| 157 | | xPos += _components.get(e).getWidth() + event_padding; |
|---|
| 158 | | } |
|---|
| 159 | | } |
|---|
| 160 | | } |
|---|
| 161 | | comp.setBounds(new Rectangle(bounds.x + xPos + event_padding/2, bounds.y, width - event_padding, bounds.height)); |
|---|
| 162 | | return xPos + width; |
|---|
| 163 | | } |
|---|
| 164 | | |
|---|