1 25 26 package net.killingar.forum.actions.area; 27 28 import net.killingar.forum.internal.Area; 29 import net.killingar.forum.internal.Message; 30 import net.killingar.forum.internal.ParentIDItemTreeNode; 31 import net.killingar.forum.internal.TreeIterator; 32 import net.killingar.forum.internal.managers.AreaManager; 33 34 import java.sql.Timestamp ; 35 import java.util.ArrayList ; 36 import java.util.Iterator ; 37 38 public class AreaInfo 39 { 40 long maxIndent = 0; 41 int noMessages = 0; 42 int noVisibleMessages = 0; 43 long firstnewID = 0; 44 Timestamp areaTime, areaTime2; 45 ParentIDItemTreeNode node; 46 boolean showHidden = false; 47 int msgsPerPage, numberOfPages, firstPageLength; 48 AreaManager areamgr; 49 50 Message firstMessage; 51 Message lastMessage; 52 Area area; 53 54 ArrayList pages = new ArrayList (); 55 56 AreaInfo(AreaManager inAreamgr, long inAreaID, boolean inShowHidden, Timestamp inTime) throws java.lang.Exception 57 { 58 areamgr = inAreamgr; 59 showHidden = inShowHidden; 60 61 areaTime = areamgr.getTimeOnArea(inAreaID); 62 areaTime2 = inTime; 63 area = areamgr.getArea(inAreaID); 64 node = areamgr.getMessagesTree(inAreaID); 65 msgsPerPage = areamgr.getMessagesPerPage(); 66 67 calcAreaInfo(); 68 } 69 70 private void calcAreaInfo() 71 { 72 noMessages = 0; 74 noVisibleMessages = 0; 75 for (Iterator i = new TreeIterator(node); i.hasNext(); noMessages++) 76 { 77 ParentIDItemTreeNode foo = (ParentIDItemTreeNode)i.next(); 78 79 Message message = (Message)foo.item; 80 81 if (message.getVisible()) 82 noVisibleMessages++; 83 } 84 85 int index = 0, pageIndex = 0, visibleIndex = 0; Page page = new Page(), lastPage = null; 88 89 numberOfPages = noVisibleMessages/msgsPerPage+1; 90 firstPageLength = noVisibleMessages%msgsPerPage; 91 92 for (Iterator i = new TreeIterator(node); i.hasNext(); index++) 93 { 94 ParentIDItemTreeNode foo = (ParentIDItemTreeNode)i.next(); 95 Message message = (Message)foo.item; 96 97 if (firstMessage == null) 99 firstMessage = message; 100 101 if (message.getVisible()) 103 { 104 visibleIndex++; 105 106 lastMessage = message; 107 108 if (message.getTimecreated().after(areaTime)) 110 { 111 page.hasNewMessages = true; 112 113 if (firstnewID == 0) 114 firstnewID = message.getId(); 115 } 116 117 if (message.getLastChanged().after(areaTime2)) 118 page.hasNewMessages = true; 119 } 120 else 121 { 122 if (lastPage != null && lastPage.endIndex == index-1) 124 { 125 lastPage.endIndex = index; 127 page.startIndex = index+1; 128 } 129 130 if (showHidden) 132 { 133 lastMessage = message; 134 135 if (message.getTimecreated().after(areaTime)) 136 { 137 page.hasNewMessages = true; 138 139 if (firstnewID == 0) 140 firstnewID = message.getId(); 141 } 142 143 if (message.getLastChanged().after(areaTime2)) 144 page.hasNewMessages = true; 145 } 146 } 147 148 if ((pages.size() == 0 && visibleIndex == firstPageLength) || visibleIndex == msgsPerPage) 150 { 151 visibleIndex = 0; 152 153 page.endIndex = index; 154 lastPage = page; 155 pages.add(page); 156 page = new Page(index+1); 157 } 158 } 159 160 if (pages.size() == 0) 161 pages.add(page); 162 } 163 164 public int getMaxIndent() { return (int)maxIndent; } 165 public int getNoMessages() { return noMessages; } 166 public long getFirstnewID() { return firstnewID; } 167 public Timestamp getAreaTime() { return areaTime; } 168 public Message getFirstMessage() { return firstMessage; } 169 public Message getLastMessage() { return lastMessage; } 170 public ParentIDItemTreeNode getNode() { return node; } 171 public Area getArea() { return area; } 172 } | Popular Tags |