source: trunk/src/org/expeditee/items/MagneticConstraint/Utilities/BoxLogic.java@ 963

Last change on this file since 963 was 963, checked in by bln4, 9 years ago
File size: 3.6 KB
Line 
1package org.expeditee.items.MagneticConstraint.Utilities;
2
3import java.awt.Rectangle;
4import java.util.Collection;
5import java.util.LinkedList;
6import java.util.List;
7
8import org.expeditee.gui.Frame;
9import org.expeditee.items.Dot;
10import org.expeditee.items.Item;
11
12public class BoxLogic {
13 public static List<org.expeditee.items.Line> getVerticalLines(
14 final Frame frame) {
15 final List<org.expeditee.items.Line> ret = new LinkedList<org.expeditee.items.Line>();
16 final Collection<Item> allItems = frame.getAllItems();
17 final List<Dot> dots = new LinkedList<Dot>();
18 for (final Item canditate : allItems)
19 if (canditate instanceof Dot)
20 dots.add((Dot) canditate);
21 for (final Dot dot : dots) {
22 final List<org.expeditee.items.Line> lines = dot.getLines();
23 for (final org.expeditee.items.Line vertCanditate : lines) {
24 if (!ret.contains(vertCanditate)
25 && vertCanditate.getStartItem().getX() == vertCanditate
26 .getEndItem().getX())
27 ret.add(vertCanditate);
28 }
29 }
30 return ret;
31 }
32
33 public static boolean boxCollision(final Item item) {
34 if(item.getParent() == null) return false;
35 final List<org.expeditee.items.Line> verticalLines = BoxLogic
36 .getVerticalLines(item.getParent());
37 for (final org.expeditee.items.Line canditate : verticalLines) {
38 final int topPos = Math.min(canditate.getStartItem().getY(),
39 canditate.getEndItem().getY());
40 final int bottomPos = Math.max(canditate.getStartItem().getY(),
41 canditate.getEndItem().getY());
42 final Rectangle itemHitBox = item.getArea().getBounds();
43 if (topPos < itemHitBox.getY() && bottomPos > itemHitBox.getY()) {
44 if (itemHitBox.getX() + itemHitBox.getWidth() > canditate
45 .getStartItem().getX()
46 && itemHitBox.getX() < canditate.getStartItem().getX()) {
47 return true;
48 }
49 }
50 }
51 return false;
52 }
53
54// private static boolean lineShadowsItem(final org.expeditee.items.Line line, final Item item) {
55// final int topPos = Math.min(line.getStartItem().getY(),
56// line.getEndItem().getY());
57// final int bottomPos = Math.max(line.getStartItem().getY(),
58// line.getEndItem().getY());
59// final Rectangle itemHitBox = item.getArea().getBounds();
60// return topPos < itemHitBox.
61// }
62
63// public static void resolveCollision(final Item item, final MagneticConstraintAction remagnet) {
64// boolean updateCursor = FrameUtils.getCurrentItem() == item;
65// final Line currentLine = Line.getLineContainingToken(item);
66// final Paragraph currentParagraph = Paragraph.getParagraphFromLine(currentLine);
67// final Point newLineAt = currentParagraph.split(currentLine);
68// final Line lineFromToken = Line.getLineFromToken(item);
69// lineFromToken.deltaX((int) newLineAt.getX() - lineFromToken.getFirst().getX());
70// lineFromToken.deltaY((int) newLineAt.getY() - lineFromToken.getFirst().getY());
71// remagnet.callback(null);
72// final Line nextLine = lineFromToken.next();
73// if(nextLine != null && nextLine.getBoundingBox().getX() >= lineFromToken.getBoundingBox().getX()) {
74// final Paragraph paragraphFromNewLine = Paragraph.getParagraphFromLine(lineFromToken);
75// final Paragraph paragraphFromNextLine = Paragraph.getParagraphFromLine(nextLine);
76// if(paragraphFromNewLine.containsAll(paragraphFromNextLine)) {
77// final Rectangle newLineBoundingBox = lineFromToken.getBoundingBox();
78// nextLine.setX((int) newLineBoundingBox.getMaxX());
79// nextLine.setY((int) newLineBoundingBox.getY());
80// }
81// }
82// if(updateCursor) DisplayIO.MoveCursorToEndOfItem(item);
83// FrameIO.ForceSaveFrame(item.getParent());
84// }
85}
Note: See TracBrowser for help on using the repository browser.