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 |
|
---|
19 | package org.expeditee.io.flowlayout;
|
---|
20 |
|
---|
21 | import java.awt.Rectangle;
|
---|
22 | import java.util.ArrayList;
|
---|
23 | import java.util.List;
|
---|
24 |
|
---|
25 | public class XOrderedLine
|
---|
26 | {
|
---|
27 | ArrayList<XItem> overlapping;
|
---|
28 |
|
---|
29 | public XOrderedLine()
|
---|
30 | {
|
---|
31 | overlapping = new ArrayList<XItem>();
|
---|
32 |
|
---|
33 | }
|
---|
34 |
|
---|
35 | public XOrderedLine(XItem item)
|
---|
36 | {
|
---|
37 | this();
|
---|
38 | overlapping.add(item);
|
---|
39 | }
|
---|
40 |
|
---|
41 | public boolean isEmpty()
|
---|
42 | {
|
---|
43 |
|
---|
44 | return overlapping.size()==0;
|
---|
45 | }
|
---|
46 |
|
---|
47 | public List<XItem> getXItemList()
|
---|
48 | {
|
---|
49 | return overlapping;
|
---|
50 | }
|
---|
51 |
|
---|
52 |
|
---|
53 |
|
---|
54 |
|
---|
55 | public void orderedMergeItem(int new_xl, XItem new_item)
|
---|
56 | {
|
---|
57 | // More generate case for insert, when we *don't* want to
|
---|
58 | // insert based on the new_item's 'xl' position
|
---|
59 |
|
---|
60 | boolean added_item = false;
|
---|
61 |
|
---|
62 | for (int i=0; i<overlapping.size(); i++) {
|
---|
63 | XItem existing_item = overlapping.get(i);
|
---|
64 |
|
---|
65 |
|
---|
66 | int existing_xl = existing_item.getX();
|
---|
67 | if (new_xl<existing_xl) {
|
---|
68 | overlapping.add(i,new_item);
|
---|
69 | added_item = true;
|
---|
70 | break;
|
---|
71 | }
|
---|
72 |
|
---|
73 | }
|
---|
74 |
|
---|
75 | if (!added_item) {
|
---|
76 |
|
---|
77 | // add to the end of the list
|
---|
78 | overlapping.add(new_item);
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | public void orderedMergeItem(XItem new_item)
|
---|
83 | {
|
---|
84 | // Simple case => want to insert based on the new_item's xl position
|
---|
85 | Rectangle rect = new_item.getBoundingRect();
|
---|
86 | int xl = rect.x;
|
---|
87 | orderedMergeItem(xl,new_item);
|
---|
88 | }
|
---|
89 | }
|
---|