1 | /**
|
---|
2 | * Help.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.actions;
|
---|
20 |
|
---|
21 | import java.util.Collection;
|
---|
22 | import java.util.Collections;
|
---|
23 | import java.util.Comparator;
|
---|
24 | import java.util.LinkedList;
|
---|
25 | import java.util.List;
|
---|
26 |
|
---|
27 | import org.expeditee.gio.EcosystemManager;
|
---|
28 | import org.expeditee.gui.DisplayController;
|
---|
29 | import org.expeditee.gui.Frame;
|
---|
30 | import org.expeditee.items.Item;
|
---|
31 | import org.expeditee.items.Text;
|
---|
32 |
|
---|
33 | public class Help {
|
---|
34 | /**
|
---|
35 | * Return a list of actions. TODO show the params they take. TODO link the
|
---|
36 | * actions to their help pages.
|
---|
37 | *
|
---|
38 | * @return
|
---|
39 | */
|
---|
40 | public static Collection<Item> getActions(String start, String end) {
|
---|
41 | return getItemList(Actions.getActions(), start, end);
|
---|
42 |
|
---|
43 | }
|
---|
44 |
|
---|
45 | public static Collection<Item> getActions(String start) {
|
---|
46 | return getItemList(Actions.getActions(), start, null);
|
---|
47 |
|
---|
48 | }
|
---|
49 |
|
---|
50 | public static Collection<Item> getActions() {
|
---|
51 | return getItemList(Actions.getActions(), null, null);
|
---|
52 |
|
---|
53 | }
|
---|
54 |
|
---|
55 | public static Collection<Item> getAgents(String start, String end) {
|
---|
56 | return getItemList(Actions.getAgents(), start, end);
|
---|
57 |
|
---|
58 | }
|
---|
59 |
|
---|
60 | public static Collection<Item> getAgents(String start) {
|
---|
61 | return getItemList(Actions.getAgents(), start, null);
|
---|
62 |
|
---|
63 | }
|
---|
64 |
|
---|
65 | public static Collection<Item> getAgents() {
|
---|
66 | return getItemList(Actions.getAgents(), null, null);
|
---|
67 | }
|
---|
68 |
|
---|
69 | private static Collection<Item> getItemList(List<String> stringList,
|
---|
70 | String start, String end) {
|
---|
71 | Collection<Item> actions = new LinkedList<Item>();
|
---|
72 |
|
---|
73 | Collections.sort(stringList, new Comparator<String>() {
|
---|
74 | public int compare(String a, String b) {
|
---|
75 | return String.CASE_INSENSITIVE_ORDER.compare(a, b);
|
---|
76 | }
|
---|
77 | });
|
---|
78 |
|
---|
79 | Frame current = DisplayController.getCurrentFrame();
|
---|
80 | float x = DisplayController.getFloatMouseX();
|
---|
81 | float y = DisplayController.getFloatMouseY();
|
---|
82 |
|
---|
83 | // Do case sensitive comparison
|
---|
84 | if (start != null)
|
---|
85 | start = start.toLowerCase();
|
---|
86 | if (end != null)
|
---|
87 | end = end.toLowerCase();
|
---|
88 |
|
---|
89 | for (String s : stringList) {
|
---|
90 | String lower = s.toLowerCase();
|
---|
91 | if (start != null) {
|
---|
92 | if (end != null) {
|
---|
93 | if (lower.compareToIgnoreCase(start) < 0)
|
---|
94 | continue;
|
---|
95 | if (lower.compareToIgnoreCase(end) > 0)
|
---|
96 | break;
|
---|
97 | } else if (!lower.matches(start) && !lower.startsWith(start)) {
|
---|
98 | continue;
|
---|
99 | }
|
---|
100 | }
|
---|
101 |
|
---|
102 | Text t = current.createNewText(s);
|
---|
103 | t.setWidth(1000);
|
---|
104 | t.setPosition(x, y);
|
---|
105 | y += t.getBoundsHeight();
|
---|
106 | actions.add(t);
|
---|
107 | }
|
---|
108 |
|
---|
109 | return actions;
|
---|
110 | }
|
---|
111 | }
|
---|