source: trunk/src/org/expeditee/io/flowlayout/XOrderedLine.java@ 1102

Last change on this file since 1102 was 1102, checked in by davidb, 6 years ago

Reworking of the code-base to separate logic from graphics. This version of Expeditee now supports a JFX graphics as an alternative to SWING

  • Property svn:executable set to *
File size: 2.2 KB
Line 
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
19package org.expeditee.io.flowlayout;
20
21import java.util.ArrayList;
22import java.util.List;
23
24import org.expeditee.core.bounds.AxisAlignedBoxBounds;
25
26public 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
86 AxisAlignedBoxBounds rect = new_item.getBoundingRect();
87 int xl = rect.getMinX();
88 orderedMergeItem(xl,new_item);
89 }
90}
Note: See TracBrowser for help on using the repository browser.