Last change
on this file since 457 was 457, checked in by davidb, 11 years ago |
Classes that support a more sophisticated traversal of items on a frame, than the default: sort by 'y' and then by 'x' for any items with the same values of 'y'. Using these classes: i) items that spatially overlap in the y-dimension are treated as being part of the same line (and therefore ordered left to right, even it the second item's 'y' value is technically higher; ii) text items can be group by polygon shapes (typically a rectangle, other any polygon shape will do) and furthermore, enclosure can be nested arbitrarially deep; iii) arrows can be used to hook in 'out-of-flow' box/polygon area (specifically, drawing an arrow that ends in a box/polygon will cause the items in that box/polygon to be treated as if it was position at the (x,y) start position of the line
|
-
Property svn:executable
set to
*
|
File size:
1.4 KB
|
Rev | Line | |
---|
[457] | 1 | package org.expeditee.io.flowlayout;
|
---|
| 2 |
|
---|
| 3 | import java.awt.Rectangle;
|
---|
| 4 | import java.util.ArrayList;
|
---|
| 5 | import java.util.List;
|
---|
| 6 |
|
---|
| 7 | public class XOrderedLine
|
---|
| 8 | {
|
---|
| 9 | ArrayList<XItem> overlapping;
|
---|
| 10 |
|
---|
| 11 | public XOrderedLine()
|
---|
| 12 | {
|
---|
| 13 | overlapping = new ArrayList<XItem>();
|
---|
| 14 |
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | public XOrderedLine(XItem item)
|
---|
| 18 | {
|
---|
| 19 | this();
|
---|
| 20 | overlapping.add(item);
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | public boolean isEmpty()
|
---|
| 24 | {
|
---|
| 25 |
|
---|
| 26 | return overlapping.size()==0;
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | public List<XItem> getXItemList()
|
---|
| 30 | {
|
---|
| 31 | return overlapping;
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 |
|
---|
| 35 |
|
---|
| 36 |
|
---|
| 37 | public void orderedMergeItem(int new_xl, XItem new_item)
|
---|
| 38 | {
|
---|
| 39 | // More generate case for insert, when we *don't* want to
|
---|
| 40 | // insert based on the new_item's 'xl' position
|
---|
| 41 |
|
---|
| 42 | boolean added_item = false;
|
---|
| 43 |
|
---|
| 44 | for (int i=0; i<overlapping.size(); i++) {
|
---|
| 45 | XItem existing_item = overlapping.get(i);
|
---|
| 46 |
|
---|
| 47 |
|
---|
| 48 | int existing_xl = existing_item.getX();
|
---|
| 49 | if (new_xl<existing_xl) {
|
---|
| 50 | overlapping.add(i,new_item);
|
---|
| 51 | added_item = true;
|
---|
| 52 | break;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | if (!added_item) {
|
---|
| 58 |
|
---|
| 59 | // add to the end of the list
|
---|
| 60 | overlapping.add(new_item);
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | public void orderedMergeItem(XItem new_item)
|
---|
| 65 | {
|
---|
| 66 | // Simple case => want to insert based on the new_item's xl position
|
---|
| 67 | Rectangle rect = new_item.getBoundingRect();
|
---|
| 68 | int xl = rect.x;
|
---|
| 69 | orderedMergeItem(xl,new_item);
|
---|
| 70 | }
|
---|
| 71 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.