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

Last change on this file since 919 was 919, checked in by jts21, 10 years ago

Added license headers to all files, added full GPL3 license file, moved license header generator script to dev/bin/scripts

  • Property svn:executable set to *
File size: 2.1 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.awt.Rectangle;
22import java.util.ArrayList;
23import java.util.List;
24
25public 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}
Note: See TracBrowser for help on using the repository browser.