1 | /**
|
---|
2 | * ListSetting.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.setting;
|
---|
20 |
|
---|
21 | import java.util.LinkedList;
|
---|
22 | import java.util.List;
|
---|
23 |
|
---|
24 | import org.expeditee.core.Representable;
|
---|
25 | import org.expeditee.gui.Frame;
|
---|
26 | import org.expeditee.gui.FrameIO;
|
---|
27 | import org.expeditee.items.Text;
|
---|
28 |
|
---|
29 | public abstract class ListSetting<T> extends VariableSetting {
|
---|
30 |
|
---|
31 | protected List<T> _default;
|
---|
32 | protected List<T> _value;
|
---|
33 |
|
---|
34 | public ListSetting(String tooltip, String name, List<T> value) {
|
---|
35 | super(tooltip, name);
|
---|
36 | _default = new LinkedList<T>(value);
|
---|
37 | _value = value;
|
---|
38 | }
|
---|
39 |
|
---|
40 | public ListSetting(String tooltip, String name) {
|
---|
41 | this(tooltip, name, new LinkedList<T>());
|
---|
42 | }
|
---|
43 |
|
---|
44 | public List<T> get() {
|
---|
45 | return _value;
|
---|
46 | }
|
---|
47 |
|
---|
48 | public void set(List<T> value) {
|
---|
49 | _value = value;
|
---|
50 | }
|
---|
51 |
|
---|
52 | public abstract boolean setSetting(Text text);
|
---|
53 |
|
---|
54 | public void setDefault(List<T> value) {
|
---|
55 | _default = new LinkedList<T>(value);
|
---|
56 | }
|
---|
57 |
|
---|
58 | public void reset() {
|
---|
59 | _value = new LinkedList<T>(_default);
|
---|
60 | }
|
---|
61 |
|
---|
62 | @Override
|
---|
63 | public Text generateRepresentation(String label, String frameset) {
|
---|
64 | Text t = new Text(label);
|
---|
65 |
|
---|
66 | if (!_value.isEmpty()) {
|
---|
67 | Frame listFrame = FrameIO.CreateFrame(frameset, null, null);
|
---|
68 | listFrame.getTitleItem().delete();
|
---|
69 |
|
---|
70 | int x = 100;
|
---|
71 | int y = 100;
|
---|
72 | for (T v: _value) {
|
---|
73 | if (v == null) continue;
|
---|
74 | Text representation;
|
---|
75 | if (v instanceof Representable) {
|
---|
76 | representation = ((Representable) v).generateRepresentation("List Entry", "");
|
---|
77 | representation.setPosition(x, y);
|
---|
78 | representation.setID(listFrame.getNextItemID());
|
---|
79 | listFrame.addItem(representation);
|
---|
80 | } else {
|
---|
81 | representation = listFrame.addText(x, y, v.toString(), null);
|
---|
82 | }
|
---|
83 | y += representation.getBoundsHeight();
|
---|
84 | }
|
---|
85 | FrameIO.ForceSaveFrame(listFrame);
|
---|
86 | t.setLink(listFrame.getName());
|
---|
87 | }
|
---|
88 |
|
---|
89 | return t;
|
---|
90 | }
|
---|
91 | }
|
---|