[919] | 1 | /**
|
---|
| 2 | * XOrderedLine.java
|
---|
| 3 | * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
|
---|
| 4 | *
|
---|
| 5 | * This program is free software: you can redistribute it and/or modify
|
---|
| 6 | * it under the terms of the GNU General Public License as published by
|
---|
| 7 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 8 | * (at your option) any later version.
|
---|
| 9 | *
|
---|
| 10 | * This program is distributed in the hope that it will be useful,
|
---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 13 | * GNU General Public License for more details.
|
---|
| 14 | *
|
---|
| 15 | * You should have received a copy of the GNU General Public License
|
---|
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 17 | */
|
---|
| 18 |
|
---|
[457] | 19 | package org.expeditee.io.flowlayout;
|
---|
| 20 |
|
---|
| 21 | import java.util.ArrayList;
|
---|
[1102] | 22 | import java.util.List;
|
---|
| 23 |
|
---|
| 24 | import org.expeditee.core.bounds.AxisAlignedBoxBounds;
|
---|
[457] | 25 |
|
---|
| 26 | public class XOrderedLine
|
---|
| 27 | {
|
---|
| 28 | ArrayList<XItem> overlapping;
|
---|
| 29 |
|
---|
| 30 | public XOrderedLine()
|
---|
| 31 | {
|
---|
| 32 | overlapping = new ArrayList<XItem>();
|
---|
| 33 |
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | public XOrderedLine(XItem item)
|
---|
| 37 | {
|
---|
| 38 | this();
|
---|
| 39 | overlapping.add(item);
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | public boolean isEmpty()
|
---|
| 43 | {
|
---|
| 44 |
|
---|
| 45 | return overlapping.size()==0;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | public List<XItem> getXItemList()
|
---|
| 49 | {
|
---|
| 50 | return overlapping;
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 |
|
---|
| 54 |
|
---|
| 55 |
|
---|
| 56 | public void orderedMergeItem(int new_xl, XItem new_item)
|
---|
| 57 | {
|
---|
| 58 | // More generate case for insert, when we *don't* want to
|
---|
| 59 | // insert based on the new_item's 'xl' position
|
---|
| 60 |
|
---|
| 61 | boolean added_item = false;
|
---|
| 62 |
|
---|
| 63 | for (int i=0; i<overlapping.size(); i++) {
|
---|
| 64 | XItem existing_item = overlapping.get(i);
|
---|
| 65 |
|
---|
| 66 |
|
---|
| 67 | int existing_xl = existing_item.getX();
|
---|
| 68 | if (new_xl<existing_xl) {
|
---|
| 69 | overlapping.add(i,new_item);
|
---|
| 70 | added_item = true;
|
---|
| 71 | break;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | if (!added_item) {
|
---|
| 77 |
|
---|
| 78 | // add to the end of the list
|
---|
| 79 | overlapping.add(new_item);
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | public void orderedMergeItem(XItem new_item)
|
---|
| 84 | {
|
---|
| 85 | // Simple case => want to insert based on the new_item's xl position
|
---|
[1102] | 86 | AxisAlignedBoxBounds rect = new_item.getBoundingRect();
|
---|
| 87 | int xl = rect.getMinX();
|
---|
[457] | 88 | orderedMergeItem(xl,new_item);
|
---|
| 89 | }
|
---|
| 90 | }
|
---|