01: /*
02: * LinkedPage.java - List of page viewed by the user
03: * Copyright (C) 2003 Alexandre THOMAS
04: * alexthomas@free.fr
05: * http://helpgui.sourceforge.net
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * as published by the Free Software Foundation; either version 2
10: * of the License, or any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20: */
21:
22: package salomeTMF_plug.helpgui.page;
23:
24: import java.util.LinkedList;
25:
26: /**
27: * List of page viewed by the user
28: *
29: * @author Alexandre THOMAS
30: */
31: public class LinkedPage {
32:
33: /** List of viewing page */
34: LinkedList pagesList = new LinkedList();
35:
36: /** Index of the current page */
37: int index = 0;
38:
39: /** Get the previous page */
40: public Page getPreviousPage() {
41: if (index < pagesList.size() - 1)
42: index++;
43: return getCurrentPage();
44: }
45:
46: /** Get the next page */
47: public Page getNextPage() {
48: if (index > 0)
49: index--;
50: return getCurrentPage();
51: }
52:
53: /** Return the current page */
54: public Page getCurrentPage() {
55: try {
56: return (Page) pagesList.get(index);
57: } catch (Exception e) {
58: }
59: return null;
60: }
61:
62: /** Insert a new page on the list */
63: public void addPage(Page page, boolean insert) {
64: if (!page.isLeaf())
65: return;
66:
67: if (index != 0 && insert) {
68: for (; index > 0; index--)
69: try {
70: pagesList.removeFirst();
71: } catch (Exception e) {
72: }
73: index = 0;
74: }
75:
76: Page p = null;
77: try {
78: p = getCurrentPage();
79: } catch (Exception e) {
80: }
81:
82: if (p != page)
83: pagesList.addFirst(page);
84: if (pagesList.size() > 10)
85: pagesList.removeLast();
86: }
87:
88: /** Return the string correcponding to the LinkedPage class */
89: public String toString() {
90: return "" + index + " --" + pagesList.toString();
91: }
92:
93: }
|