source: trunk/src/org/expeditee/setting/ListSetting.java@ 1242

Last change on this file since 1242 was 1242, checked in by bln4, 5 years ago

Support for new regime in the form of new fields and conditional setting of all paths fields.

Settings are now able to generate their own representation. This allows for the user to explicitly inspect the default values.

When profiles are created, an optional parameter may now be provided. If not null, the new map parameter can contain default values for settings to apply to this profile. This allows for the creation of profiles to that have (for example), their username set to an explicit value. Multiuser mode uses this functionality for usernames and key values among other things.

Frames can now be asked were they are located on the file system. Furthermore, frame indirection is now a thing. Rather than containing data to display, an exp file can contain a line in the format of "REDIRECT:<path>" to go looking for that data. Frames are able to return both their logical (their exp file) and real (the file actually containing the data) paths.

Frames can now store data.

Further fixes to how edits from other users are loaded in.

File size: 2.5 KB
Line 
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
19package org.expeditee.setting;
20
21import java.util.LinkedList;
22import java.util.List;
23
24import org.expeditee.core.Representable;
25import org.expeditee.gui.Frame;
26import org.expeditee.gui.FrameIO;
27import org.expeditee.items.Text;
28
29public 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}
Note: See TracBrowser for help on using the repository browser.